- zauber sind mehrfach in der zauberliste
This commit is contained in:
Enno Rehling 2004-09-11 19:26:58 +00:00
parent 8dfe5ae9a1
commit e135dc7728
6 changed files with 85 additions and 78 deletions

View File

@ -202,7 +202,6 @@ read_mage(attrib * a, FILE * F)
{
int i, mtype;
sc_mage * mage = (sc_mage*)a->data.v;
spell_ptr ** sp = &mage->spellptr;
fscanf(F, "%d %d %d", &mtype, &mage->spellpoints, &mage->spchange);
mage->magietyp = (magic_t)mtype;
@ -213,15 +212,16 @@ read_mage(attrib * a, FILE * F)
mage->combatspell[i] = (spellid_t)spid;
}
for (;;) {
int spid;
int i;
fscanf (F, "%d", &spid);
if (spid < 0) break;
if (find_spellbyid((spellid_t)spid)==NULL) continue;
fscanf (F, "%d", &i);
if (i < 0) break;
else {
spellid_t spid = (spellid_t)i;
*sp = calloc (sizeof(spell_ptr), 1);
(*sp)->spellid = (spellid_t)spid;
sp = &(*sp)->next;
if (find_spellbyid(spid)==NULL) continue;
add_spell(mage, spid);
}
}
return AT_READ_OK;
}
@ -302,7 +302,7 @@ createspelllist(unit *u, magic_t mtyp)
spell * sp = slist->data;
if (sp->magietyp == mtyp && sp->level <= sk) {
if (!has_spell(u, sp)) {
addspell(u, sp->id);
add_spell(get_mage(u), sp->id);
}
}
}
@ -313,9 +313,9 @@ createspelllist(unit *u, magic_t mtyp)
sc_mage *
create_mage(unit * u, magic_t mtyp)
{
sc_mage *mage;
attrib *a;
int i;
sc_mage *mage;
attrib *a;
int i;
a = a_find(u->attribs, &at_mage);
if (a==NULL) {
@ -326,16 +326,16 @@ create_mage(unit * u, magic_t mtyp)
mage = a->data.v;
}
mage->magietyp = mtyp;
mage->spellpoints = 0;
mage->spchange = 0;
mage->spellcount = 0;
for (i=0;i<MAXCOMBATSPELLS;i++) {
mage->combatspell[i] = SPL_NOSPELL;
}
mage->spellptr = NULL;
createspelllist(u, mtyp);
return mage;
mage->magietyp = mtyp;
mage->spellpoints = 0;
mage->spchange = 0;
mage->spellcount = 0;
for (i=0;i<MAXCOMBATSPELLS;i++) {
mage->combatspell[i] = SPL_NOSPELL;
}
mage->spellptr = NULL;
createspelllist(u, mtyp);
return mage;
}
/* ------------------------------------------------------------- */
@ -366,19 +366,20 @@ updatespelllist(unit * u)
int sk = eff_skill(u, SK_MAGIC, u->region);
spell_list * slist;
spell * sp;
struct sc_mage * mage = get_mage(u);
magic_t gebiet = find_magetype(u);
boolean ismonster = u->faction->no==MONSTER_FACTION;
/* Nur Orkmagier bekommen den Keuschheitsamulettzauber */
sp = find_spellbyid(SPL_ARTEFAKT_CHASTITYBELT);
if (old_race(u->race)==RC_ORC && !has_spell(u, sp) && sp->level<=sk) {
addspell(u, SPL_ARTEFAKT_CHASTITYBELT);
add_spell(mage, SPL_ARTEFAKT_CHASTITYBELT);
}
/* Nur Wyrm-Magier bekommen den Wyrmtransformationszauber */
sp = find_spellbyid(SPL_BECOMEWYRM);
if (fspecial(u->faction, FS_WYRM) && !has_spell(u, sp) && sp->level<=sk) {
addspell(u, SPL_BECOMEWYRM);
add_spell(mage, SPL_BECOMEWYRM);
}
/* Transformierte Wyrm-Magier bekommen Drachenodem */
@ -389,17 +390,17 @@ updatespelllist(unit * u)
case RC_WYRM:
sp = find_spellbyid(SPL_WYRMODEM);
if (sp!=NULL && !has_spell(u, sp) && sp->level<=sk) {
addspell(u, sp->id);
add_spell(mage, sp->id);
}
case RC_DRAGON:
sp = find_spellbyid(SPL_DRAGONODEM);
if (sp!=NULL && !has_spell(u, sp) && sp->level<=sk) {
addspell(u, sp->id);
add_spell(mage, sp->id);
}
case RC_FIREDRAGON:
sp = find_spellbyid(SPL_FIREDRAGONODEM);
if (sp!=NULL && has_spell(u, sp) && sp->level<=sk) {
addspell(u, sp->id);
add_spell(mage, sp->id);
}
break;
}
@ -417,7 +418,7 @@ updatespelllist(unit * u)
if (know || (gebiet!=M_GRAU && sp->magietyp == gebiet)) {
faction * f = u->faction;
if (!know) addspell(u, sp->id);
if (!know) add_spell(mage, sp->id);
if (!ismonster && !already_seen(u->faction, sp->id)) {
a_add(&f->attribs, a_new(&at_reportspell))->data.i = sp->id;
a_add(&f->attribs, a_new(&at_seenspell))->data.i = sp->id;
@ -431,20 +432,25 @@ updatespelllist(unit * u)
/* Funktionen für die Bearbeitung der List-of-known-spells */
void
addspell(unit *u, spellid_t spellid)
add_spell(sc_mage* m, spellid_t spellid)
{
sc_mage *m;
spell_ptr *newsp;
m = get_mage(u);
if (!m) {
return;
}
newsp = calloc(1, sizeof(spell_ptr));
newsp->spellid = spellid;
addlist(&m->spellptr, newsp);
return;
if (m==NULL) {
log_error(("add_spell: unit is not a mage.\n"));
} else {
spell_ptr *newsp;
spell_ptr **spinsert = &m->spellptr;
while (*spinsert && (*spinsert)->spellid<spellid) spinsert=&(*spinsert)->next;
newsp = *spinsert;
if (newsp && newsp->spellid==spellid) {
log_error(("add_spell: unit already has spell %d.\n", spellid));
return;
}
newsp = calloc(1, sizeof(spell_ptr));
newsp->spellid = spellid;
newsp->next = *spinsert;
*spinsert = newsp;
}
return;
}
boolean
@ -455,9 +461,9 @@ has_spell(const unit *u, const spell * sp)
if (m==NULL) return false;
for (spt = m->spellptr; spt; spt = spt->next) {
if (spt->spellid == sp->id) return true;
}
spt = m->spellptr;
while (spt && spt->spellid<sp->id) spt = spt->next;
if (spt && spt->spellid==sp->id) return true;
return false;
}

View File

@ -111,15 +111,15 @@ typedef struct spell_ptr {
} spell_ptr;
typedef struct sc_mage {
magic_t magietyp;
int spellpoints;
int spchange;
int spellcount;
spellid_t combatspell[MAXCOMBATSPELLS];
int combatspelllevel[MAXCOMBATSPELLS];
int precombataura; /* Merker, wieviel Aura in den Präcombatzauber
gegangen ist. Nicht speichern. */
struct spell_ptr *spellptr;
magic_t magietyp;
int spellpoints;
int spchange;
int spellcount;
spellid_t combatspell[MAXCOMBATSPELLS];
int combatspelllevel[MAXCOMBATSPELLS];
int precombataura; /* Merker, wieviel Aura in den Präcombatzauber
gegangen ist. Nicht speichern. */
struct spell_ptr *spellptr;
} sc_mage;
/* ------------------------------------------------------------- */
@ -279,7 +279,7 @@ void set_combatspell(struct unit *u, spell *sp, struct order * ord, int level);
/* setzt Kampfzauber */
void unset_combatspell(struct unit *u, spell *sp);
/* löscht Kampfzauber */
void addspell(struct unit *u, spellid_t spellid);
void add_spell(struct sc_mage *mage, spellid_t spellid);
/* fügt den Spruch mit der Id spellid der Spruchliste der Einheit hinzu. */
boolean has_spell(const struct unit *u, const struct spell * sp);
/* prüft, ob der Spruch in der Spruchliste der Einheit steht. */

View File

@ -494,7 +494,7 @@ oldfamiliars(unit * familiar)
if (m!=NULL) {
spell_list * fspells = familiarspells(familiar->race);
while (fspells!=NULL) {
addspell(familiar, fspells->data->id);
add_spell(m, fspells->data->id);
fspells=fspells->next;
}
}

View File

@ -1160,7 +1160,7 @@ readunit(FILE * F)
csp++;
}
while ((i = ri(F)) != -1) {
addspell(u, (spellid_t) i);
add_spell(mage, (spellid_t) i);
}
mage->spellcount = 0;
a = a_add(&u->attribs, a_new(&at_mage));

View File

@ -7219,33 +7219,33 @@ sp_destroy_curse(castorder *co)
int
sp_becomewyrm(castorder *co)
{
unit *mage = (unit *)co->magician;
int wyrms_already_created = 0;
int wyrms_allowed;
attrib *a;
unit *u = (unit *)co->magician;
int wyrms_already_created = 0;
int wyrms_allowed;
attrib *a;
wyrms_allowed = fspecial(mage->faction, FS_WYRM);
a = a_find(mage->faction->attribs, &at_wyrm);
if(a) wyrms_already_created = a->data.i;
wyrms_allowed = fspecial(u->faction, FS_WYRM);
a = a_find(u->faction->attribs, &at_wyrm);
if(a) wyrms_already_created = a->data.i;
if(wyrms_already_created >= wyrms_allowed) {
cmistake(mage, co->order, 262, MSG_MAGIC);
return 0;
}
if(wyrms_already_created >= wyrms_allowed) {
cmistake(u, co->order, 262, MSG_MAGIC);
return 0;
}
if(!a) {
a_add(&mage->faction->attribs, a_new(&at_wyrm));
a->data.i = 1;
} else {
a->data.i++;
}
if(!a) {
a_add(&u->faction->attribs, a_new(&at_wyrm));
a->data.i = 1;
} else {
a->data.i++;
}
mage->race = new_race[RC_WYRM];
addspell(mage, SPL_WYRMODEM);
u->race = new_race[RC_WYRM];
add_spell(get_mage(u), SPL_WYRMODEM);
ADDMSG(&mage->faction->msgs, msg_message("becomewyrm", "mage", mage));
ADDMSG(&u->faction->msgs, msg_message("becomewyrm", "u", u));
return co->level;
return co->level;
}
#ifdef WDW_PYRAMIDSPELL

View File

@ -199,8 +199,9 @@ unit_addspell(unit& u, const char * name)
while (slist!=NULL) {
spell * sp = slist->data;
if (strcmp(name, sp->sname)==0) {
struct sc_mage * mage = get_mage(&u);
if (add) log_error(("two spells are called %s.\n", name));
addspell(&u, sp->id);
add_spell(mage, sp->id);
add = true;
}
slist=slist->next;