From 2602a8db67f5351ef16f3629300d27107db6ed74 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 8 Oct 2005 15:44:40 +0000 Subject: [PATCH] =?UTF-8?q?Mehr=20const,=20weniger=20Warnungen.=20Bugfix?= =?UTF-8?q?=20f=C3=BCr=20spelllist=5Fadd=20(aufsteigend=20sortiert)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/kernel/battle.c | 8 +++---- src/common/kernel/magic.c | 45 ++++++++++++++++++++++++-------------- src/common/kernel/magic.h | 18 +++++++-------- src/common/kernel/spell.c | 21 ++++++++---------- 4 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index e06225299..3b31d7143 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -1403,7 +1403,7 @@ fighters(battle *b, fighter *af, int minrow, int maxrow, int mask) } static void -report_failed_spell(battle * b, unit * mage, spell * sp) +report_failed_spell(battle * b, unit * mage, const spell * sp) { message * m = msg_message("battle::spell_failed", "unit spell", mage, sp); message_all(b, m); @@ -1414,7 +1414,6 @@ void do_combatmagic(battle *b, combatmagic_t was) { void **fi; - spell *sp; region *r = b->region; castorder *co; castorder *cll[MAX_SPELLRANK]; @@ -1435,6 +1434,7 @@ do_combatmagic(battle *b, combatmagic_t was) level = eff_skill(mage, SK_MAGIC, r); if (level > 0) { double power; + const spell *sp; const struct locale * lang = mage->faction->locale; char cmd[128]; order * ord; @@ -1489,7 +1489,7 @@ do_combatmagic(battle *b, combatmagic_t was) for (spellrank = 0; spellrank < MAX_SPELLRANK; spellrank++) { for (co = cll[spellrank]; co; co = co->next) { fighter * fig = (fighter*)co->magician; - spell * sp = co->sp; + const spell * sp = co->sp; int level = co->level; double power = co->force; @@ -1508,7 +1508,7 @@ do_combatmagic(battle *b, combatmagic_t was) static void do_combatspell(troop at, int row) { - spell *sp; + const spell *sp; fighter *fi = at.fighter; unit *mage = fi->unit; battle *b = fi->side->battle; diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index e1509f744..e6ba65bd2 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -717,12 +717,10 @@ countspells(unit *u, int step) * Parameter count ist dabei die Anzahl der bereits gezauberten Sprüche */ int -spellcost(unit *u, spell * sp) +spellcost(unit *u, const spell * sp) { int k, aura = 0; - int count; - - count = countspells(u,0); + int count = countspells(u, 0); for (k = 0; k < MAXINGREDIENT; k++) { if (sp->komponenten[k][0] == R_AURA) { @@ -741,7 +739,7 @@ spellcost(unit *u, spell * sp) * niedrigstwertigen und sollte von den beiden anderen Typen * überschrieben werden */ static int -spl_costtyp(spell * sp) +spl_costtyp(const spell * sp) { int k; int costtyp = SPC_FIX; @@ -769,7 +767,7 @@ spl_costtyp(spell * sp) * generiert werden. * */ int -eff_spelllevel(unit *u, spell * sp, int cast_level, int range) +eff_spelllevel(unit *u, const spell * sp, int cast_level, int range) { int k; int maxlevel; @@ -824,7 +822,7 @@ eff_spelllevel(unit *u, spell * sp, int cast_level, int range) * multipliziert. */ void -pay_spell(unit * u, spell * sp, int cast_level, int range) +pay_spell(unit * u, const spell * sp, int cast_level, int range) { int k; int resuse; @@ -891,7 +889,7 @@ knowsspell(const region * r, const unit * u, const spell * sp) */ boolean -cancast(unit * u, spell * sp, int level, int range, struct order * ord) +cancast(unit * u, const spell * sp, int level, int range, struct order * ord) { int k; resource_t res; @@ -968,7 +966,7 @@ cancast(unit * u, spell * sp, int level, int range, struct order * ord) */ double -spellpower(region * r, unit * u, spell * sp, int cast_level, struct order * ord) +spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order * ord) { curse * c; double force = cast_level; @@ -1202,7 +1200,7 @@ is_magic_resistant(unit *magician, unit *target, int resist_bonus) */ boolean -fumble(region * r, unit * u, spell * sp, int cast_grade) +fumble(region * r, unit * u, const spell * sp, int cast_grade) { /* X ergibt Zahl zwischen 1 und 0, je kleiner, desto besser der Magier. * 0,5*40-20=0, dh wenn der Magier doppelt so gut ist, wie der Spruch @@ -1261,7 +1259,7 @@ do_fumble(castorder *co) curse * c; region * r = co->rt; unit * u = (unit*)co->magician; - spell * sp = co->sp; + const spell *sp = co->sp; int level = co->level; int duration; variant effect; @@ -1523,7 +1521,7 @@ static int verify_targets(castorder *co) { unit *mage = (unit *)co->magician; - spell *sp = co->sp; + const spell *sp = co->sp; region *target_r = co->rt; spellparameter *sa = co->par; int failed = 0; @@ -1969,7 +1967,7 @@ add_spellparameter(region *target_r, unit *u, const char *syntax, char ** param, /* ------------------------------------------------------------- */ castorder * -new_castorder(void *u, unit *u2, spell *sp, region *r, int lev, +new_castorder(void *u, unit *u2, const spell *sp, region *r, int lev, double force, int range, struct order * ord, spellparameter *p) { castorder *corder; @@ -2646,7 +2644,7 @@ magic(void) int verify, cast_level = co->level; boolean fumbled = false; unit * u = (unit *)co->magician; - spell * sp = co->sp; + const spell *sp = co->sp; region * target_r = co->rt; /* reichen die Komponenten nicht, wird der Level reduziert. */ @@ -2746,7 +2744,7 @@ magic(void) } const char * -spell_info(const struct spell * sp, const struct locale * lang) +spell_info(const spell * sp, const struct locale * lang) { if (sp->info==NULL) { return LOC(lang, mkname("spellinfo", sp->sname)); @@ -2755,7 +2753,7 @@ spell_info(const struct spell * sp, const struct locale * lang) } const char * -spell_name(const struct spell * sp, const struct locale * lang) +spell_name(const spell * sp, const struct locale * lang) { if (sp->info==NULL) { return LOC(lang, mkname("spell", sp->sname)); @@ -2766,7 +2764,20 @@ spell_name(const struct spell * sp, const struct locale * lang) void spelllist_add(spell_list ** lspells, spell * sp) { - spell_list * entry = malloc(sizeof(spell_list)); + spell_list * entry; + + while (*lspells) { + spell_list * slist = *lspells; + if (slist->data->id==sp->id) { + if (slist->data==sp) { + log_error(("trying to add spell '%s' to a list twice.\n", sp->sname)); + return; + } + } + if (slist->data->id>sp->id) break; + lspells = &slist->next; + } + entry = malloc(sizeof(spell_list)); entry->data = sp; entry->next = *lspells; *lspells = entry; diff --git a/src/common/kernel/magic.h b/src/common/kernel/magic.h index 5cf3e6334..1faadb39d 100644 --- a/src/common/kernel/magic.h +++ b/src/common/kernel/magic.h @@ -127,7 +127,7 @@ typedef struct castorder { void *magician; /* Magier (kann vom Typ struct unit oder fighter sein) */ struct unit *familiar; /* Vertrauter, gesetzt, wenn der Spruch durch den Vertrauten gezaubert wird */ - struct spell *sp; /* Spruch */ + const struct spell *sp; /* Spruch */ int level; /* gewünschte Stufe oder Stufe des Magiers */ double force; /* Stärke des Zaubers */ struct region *rt; /* Zielregion des Spruchs */ @@ -141,7 +141,7 @@ typedef void (*spell_f) (void*); /* normale zauber: */ typedef int (*nspell_f)(castorder*); /* kampfzauber: */ -typedef int (*cspell_f) (struct fighter*, int, double, struct spell * sp); +typedef int (*cspell_f) (struct fighter*, int, double, const struct spell * sp); /* zauber-patzer: */ typedef void (*pspell_f) (castorder *); @@ -306,13 +306,13 @@ int change_maxspellpoints(struct unit * u, int csp); /* verändert die maximalen Magiepunkte einer Einheit */ /* Zaubern */ -extern double spellpower(struct region *r, struct unit *u, spell *spruch, int cast_level, struct order * ord); +extern double spellpower(struct region *r, struct unit *u, const spell *sp, int cast_level, struct order * ord); /* ermittelt die Stärke eines Spruchs */ -boolean fumble (struct region *r, struct unit *u, spell *spruch, int cast_level); +boolean fumble (struct region *r, struct unit *u, const spell *sp, int cast_level); /* true, wenn der Zauber misslingt, bei false gelingt der Zauber */ /* */ -castorder *new_castorder(void *u, struct unit *familiar, spell *sp, struct region *r, +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); /* Zwischenspreicher für Zauberbefehle, notwendig für Prioritäten */ void add_castorder(castorder **cll, castorder *co); @@ -324,18 +324,18 @@ void free_castorders(castorder *co); int countspells(struct unit *u, int step); /* erhöht den Counter für Zaubersprüche um 'step' und gibt die neue * Anzahl der gezauberten Sprüche zurück. */ -int spellcost(struct unit *u, spell *spruch); +int spellcost(struct unit *u, const spell *sp); /* gibt die für diesen Spruch derzeit notwendigen Magiepunkte auf der * geringstmöglichen Stufe zurück, schon um den Faktor der bereits * zuvor gezauberten Sprüche erhöht */ -boolean cancast (struct unit *u, spell *spruch, int eff_stufe, int distance, struct order * ord); +boolean cancast (struct unit *u, const spell *spruch, int eff_stufe, int distance, struct order * ord); /* true, wenn Einheit alle Komponenten des Zaubers (incl. MP) für die * geringstmögliche Stufe hat und den Spruch beherrscht */ -void pay_spell(struct unit *u, spell *spruch, int eff_stufe, int distance); +void pay_spell(struct unit *u, const spell *sp, int eff_stufe, int distance); /* zieht die Komponenten des Zaubers aus dem Inventory der Einheit * ab. Die effektive Stufe des gezauberten Spruchs ist wichtig für * die korrekte Bestimmung der Magiepunktkosten */ -int eff_spelllevel(struct unit *u, spell * sp, int cast_level, int distance); +int eff_spelllevel(struct unit *u, const spell * sp, int cast_level, int distance); /* ermittelt die effektive Stufe des Zaubers. Dabei ist cast_level * die gewünschte maximale Stufe (im Normalfall Stufe des Magiers, * bei Farcasting Stufe*2^Entfernung) */ diff --git a/src/common/kernel/spell.c b/src/common/kernel/spell.c index 9600613b0..b6f31e4f2 100644 --- a/src/common/kernel/spell.c +++ b/src/common/kernel/spell.c @@ -4248,7 +4248,7 @@ sp_migranten(castorder *co) unit *mage = (unit *)co->magician; int cast_level = co->level; spellparameter *pa = co->par; - spell *sp = co->sp; + const spell *sp = co->sp; /* wenn kein Ziel gefunden, Zauber abbrechen */ if(pa->param[0]->flag == TARGET_NOTFOUND) return 0; @@ -4553,7 +4553,7 @@ sp_pump(castorder *co) unit *mage = (unit *)co->magician; spellparameter *pa = co->par; int cast_level = co->level; - spell *sp = co->sp; + const spell *sp = co->sp; /* wenn kein Ziel gefunden, Zauber abbrechen */ if(pa->param[0]->flag == TARGET_NOTFOUND) return 0; @@ -4623,7 +4623,7 @@ sp_seduce(castorder *co) unit *mage = (unit *)co->magician; spellparameter *pa = co->par; int cast_level = co->level; - spell *sp = co->sp; + const spell *sp = co->sp; double force = co->force; /* wenn kein Ziel gefunden, Zauber abbrechen */ @@ -4706,7 +4706,7 @@ sp_calm_monster(castorder *co) spellparameter *pa = co->par; int cast_level = co->level; double force = co->force; - spell *sp = co->sp; + const spell *sp = co->sp; variant effect; /* wenn kein Ziel gefunden, Zauber abbrechen */ @@ -5700,7 +5700,7 @@ sp_enterastral(castorder *co) int cast_level = co->level; double power = co->force; spellparameter *pa = co->par; - spell *sp = co->sp; + const spell *sp = co->sp; switch(getplaneid(r)) { case 0: @@ -5815,7 +5815,7 @@ sp_pullastral(castorder *co) int cast_level = co->level; double power = co->force; spellparameter *pa = co->par; - spell *sp = co->sp; + const spell *sp = co->sp; switch (getplaneid(r)) { case 1: @@ -6483,7 +6483,7 @@ sp_permtransfer(castorder *co) unit *mage = (unit *)co->magician; int cast_level = co->level; spellparameter *pa = co->par; - spell *sp = co->sp; + const spell *sp = co->sp; /* wenn kein Ziel gefunden, Zauber abbrechen */ if(pa->param[0]->flag == TARGET_NOTFOUND) return 0; @@ -6533,7 +6533,7 @@ sp_movecastle(castorder *co) unit *mage = (unit *)co->magician; int cast_level = co->level; spellparameter *pa = co->par; - spell *sp = co->sp; + const spell *sp = co->sp; /* wenn kein Ziel gefunden, Zauber abbrechen */ if(pa->param[0]->flag == TARGET_NOTFOUND) return 0; @@ -7492,13 +7492,10 @@ spell_list * spells = NULL; void register_spell(spell * sp) { - spell_list * slist = malloc(sizeof(spell_list)); - slist->next = spells; - slist->data = sp; if (sp->id==0) { sp->id = hashstring(sp->sname); } - spells = slist; + spelllist_add(&spells, sp); } /** versucht einen Spruch über gebiet + bame zu identifizieren.