refactoring castorder, because it's a bit of a mess of units, fighters, familliars and casters.

This commit is contained in:
Enno Rehling 2012-05-09 13:46:10 -07:00
parent 6dcf6669c3
commit 02559f6869
3 changed files with 33 additions and 5 deletions

View File

@ -464,9 +464,10 @@ static void unit_castspell(unit * u, const char *name)
if (sp->sp_function == NULL) {
log_error(("spell '%s' has no function.\n", sp->sname));
} else {
castorder *co = new_castorder(u, 0, sp, u->region, sp->level, sp->level, 0, 0, 0);
sp->sp_function(co);
free(co);
castorder co;
create_castorder(&co, u, 0, sp, u->region, sp->level, sp->level, 0, 0, 0);
sp->sp_function(&co);
free_castorder(&co);
}
}
}

View File

@ -2102,7 +2102,7 @@ castorder *new_castorder(void *u, unit * u2, const spell * sp, region * r,
{
castorder *corder;
corder = calloc(1, sizeof(castorder));
corder = (castorder*)calloc(1, sizeof(castorder));
corder->magician.u = u;
corder->familiar = u2;
corder->sp = sp;
@ -2116,6 +2116,29 @@ castorder *new_castorder(void *u, unit * u2, const spell * sp, region * r,
return corder;
}
castorder *create_castorder(castorder * co, unit *caster, unit * familiar, const spell * sp, region * r,
int lev, double force, int range, struct order * ord, spellparameter * p)
{
if (!co) co = (castorder*)calloc(1, sizeof(castorder));
co->magician.u = caster;
co->familiar = familiar;
co->sp = sp;
co->level = lev;
co->force = force;
co->rt = r;
co->distance = range;
co->order = copy_order(ord);
co->par = p;
return co;
}
void free_castorder(struct castorder *co)
{
free_order(co->order);
}
/* Hänge c-order co an die letze c-order von cll an */
void add_castorder(spellrank * cll, castorder * co)
{

View File

@ -314,9 +314,13 @@ typedef struct sc_mage {
struct castorder **end;
} spellrank;
castorder *new_castorder(void *u, struct unit *familiar, const spell * sp,
struct castorder *new_castorder(void *u, struct unit *familiar, const spell * sp,
struct region *r, int lev, double force, int distance, struct order *ord,
spellparameter * p);
struct castorder *create_castorder(struct castorder * co, struct unit *caster,
struct unit * familiar, const struct spell * sp, struct region * r,
int lev, double force, int range, struct order * ord, struct spellparameter * p);
void free_castorder(struct castorder *co);
/* Zwischenspreicher für Zauberbefehle, notwendig für Prioritäten */
void add_castorder(struct spellrank *cll, struct castorder *co);
/* Hänge c-order co an die letze c-order von cll an */