From dd667aa7528b7aa164cb17b07f0a0bb4c531ddf3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 22 Aug 2015 17:56:36 +0200 Subject: [PATCH 1/5] cursed factions get to fight a wolfhowl if they attack (WIP) --- src/battle.c | 35 +++++++++++++++++++++++++++++++++++ src/kernel/faction.h | 4 ++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/battle.c b/src/battle.c index ebfde1548..bf1b0aa88 100644 --- a/src/battle.c +++ b/src/battle.c @@ -194,6 +194,7 @@ static void message_faction(battle * b, faction * f, struct message *m) { region *r = b->region; + assert(f); if (f->battles == NULL || f->battles->r != r) { struct bmsg *bm = (struct bmsg *)calloc(1, sizeof(struct bmsg)); bm->next = f->battles; @@ -210,6 +211,7 @@ void message_all(battle * b, message * m) watcher *w; for (bf = b->factions; bf; bf = bf->next) { + assert(bf->faction); message_faction(b, bf->faction, m); } if (p) @@ -1687,6 +1689,39 @@ void do_combatmagic(battle * b, combatmagic_t was) memset(spellranks, 0, sizeof(spellranks)); +#ifdef FFL_CURSED + for (s = b->sides; s != b->sides + b->nsides; ++s) { + fighter *fig = 0; + if (s->bf->attacker) { + spell *sp = find_spell("wolfhowl"); + if (sp && fval(s->faction, FFL_CURSED)) { + int si; + for (si = 0; s->enemies[si]; ++si) { + side *se = s->enemies[si]; + if (se && !fval(se->faction, FFL_NPC)) { + fighter *fi; + for (fi = se->fighters; fi; fi = fi->next) { + if (fi && (!fig || fig->unit->number > fi->unit->number)) { + fig = fi; + if (fig->unit->number == 1) { + break; + } + } + } + if (fig && fig->unit->number == 1) { + break; + } + } + } + if (fig) { + co = create_castorder(0, fig->unit, 0, sp, r, 10, 10, 0, 0, 0); + add_castorder(&spellranks[sp->rank], co); + break; + } + } + } + } +#endif for (s = b->sides; s != b->sides + b->nsides; ++s) { fighter *fig; for (fig = s->fighters; fig; fig = fig->next) { diff --git a/src/kernel/faction.h b/src/kernel/faction.h index db8ce4389..614b50d75 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -39,6 +39,7 @@ extern "C" { #define FFL_ISNEW (1<<1) #define FFL_RESTART (1<<2) #define FFL_QUIT (1<<3) +#define FFL_CURSED (1<<4) /* you're going to have a bad time */ #define FFL_DEFENDER (1<<10) #define FFL_SELECT (1<<18) /* ehemals f->dh, u->dh, r->dh, etc... */ #define FFL_NOAID (1<<21) /* Hilfsflag Kampf */ @@ -49,8 +50,7 @@ extern "C" { #define FFL_NOIDLEOUT (1<<24) /* Partei stirbt nicht an NMRs */ #define FFL_NPC (1<<25) /* eine Partei mit Monstern */ #define FFL_DBENTRY (1<<28) /* Partei ist in Datenbank eingetragen */ - -#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_NPC|FFL_DBENTRY|FFL_NOIDLEOUT) +#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_NPC|FFL_DBENTRY|FFL_NOIDLEOUT|FFL_CURSED) typedef struct faction { struct faction *next; From 9586d970e85840e6b9201087533bc4ba694a0340 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 22 Aug 2015 18:51:10 +0200 Subject: [PATCH 2/5] fix bad castorder creation for combat spell (some unions are the WORST) --- src/battle.c | 15 ++++++++++----- src/triggers/triggers.c | 2 -- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/battle.c b/src/battle.c index bf1b0aa88..b2b14a785 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1679,6 +1679,12 @@ static void report_failed_spell(struct battle * b, struct unit * mage, const str msg_release(m); } +static castorder * create_castorder_combat(castorder *co, fighter *fig, const spell * sp, int level, double force) { + co = create_castorder(co, fig->unit, 0, sp, fig->unit->region, level, force, 0, 0, 0); + co->magician.fig = fig; + return co; +} + void do_combatmagic(battle * b, combatmagic_t was) { side *s; @@ -1714,7 +1720,8 @@ void do_combatmagic(battle * b, combatmagic_t was) } } if (fig) { - co = create_castorder(0, fig->unit, 0, sp, r, 10, 10, 0, 0, 0); + co = create_castorder_combat(0, fig, sp, 10, 10); + co->magician.fig = fig; add_castorder(&spellranks[sp->rank], co); break; } @@ -1779,8 +1786,7 @@ void do_combatmagic(battle * b, combatmagic_t was) pay_spell(mage, sp, level, 1); } else { - co = create_castorder(0, fig->unit, 0, sp, r, level, power, 0, 0, 0); - co->magician.fig = fig; + co = create_castorder_combat(0, fig, sp, level, power); add_castorder(&spellranks[sp->rank], co); } } @@ -1812,8 +1818,7 @@ static int cast_combatspell(troop at, const spell * sp, int level, double force) { castorder co; - create_castorder(&co, at.fighter->unit, 0, sp, at.fighter->unit->region, level, force, 0, 0, 0); - co.magician.fig = at.fighter; + create_castorder_combat(&co, at.fighter, sp, level, force); level = sp->cast(&co); free_castorder(&co); if (level > 0) { diff --git a/src/triggers/triggers.c b/src/triggers/triggers.c index a459f16bf..6a4bb780d 100644 --- a/src/triggers/triggers.c +++ b/src/triggers/triggers.c @@ -42,8 +42,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. void register_triggers(void) { - if (verbosity >= 2) - printf("- registering triggers\n"); tt_register(&tt_changefaction); tt_register(&tt_changerace); tt_register(&tt_createcurse); From 7bb882b15be08133631f0f0d1402d916c3fbe254 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 30 Aug 2015 10:57:08 +0200 Subject: [PATCH 3/5] add a spell for igjarjuk (WIP) --- res/eressea/spells.xml | 3 ++ src/battle.c | 2 +- src/spells.c | 1 + src/spells/combatspells.c | 64 +++++++++++++++++++++++++-------------- src/spells/combatspells.h | 1 + 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/res/eressea/spells.xml b/res/eressea/spells.xml index 345541298..6bd5fc9c4 100644 --- a/res/eressea/spells.xml +++ b/res/eressea/spells.xml @@ -304,6 +304,9 @@ + + + diff --git a/src/battle.c b/src/battle.c index b2b14a785..bc3ed9cbd 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1699,7 +1699,7 @@ void do_combatmagic(battle * b, combatmagic_t was) for (s = b->sides; s != b->sides + b->nsides; ++s) { fighter *fig = 0; if (s->bf->attacker) { - spell *sp = find_spell("wolfhowl"); + spell *sp = find_spell("igjarjuk"); if (sp && fval(s->faction, FFL_CURSED)) { int si; for (si = 0; s->enemies[si]; ++si) { diff --git a/src/spells.c b/src/spells.c index 8833497d5..436a1bc43 100644 --- a/src/spells.c +++ b/src/spells.c @@ -6516,6 +6516,7 @@ static spelldata spell_functions[] = { { "stormwinds", sp_stormwinds, 0 }, { "homestone", sp_homestone, 0 }, { "wolfhowl", sp_wolfhowl, 0 }, + { "igjarjuk", sp_igjarjuk, 0 }, { "versteinern", sp_petrify, 0 }, { "strongwall", sp_strong_wall, 0 }, { "gwyrrddestroymagic", sp_destroy_magic, 0 }, diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 26d8d8b6d..9fc41f18a 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -848,41 +848,59 @@ int sp_shadowcall(struct castorder * co) return level; } -int sp_wolfhowl(struct castorder * co) +static fighter *summon_allies(const fighter *fi, const race *rc, int number) { + attrib *a; + unit *mage = fi->unit; + side *si = fi->side; + battle *b = si->battle; + region *r = b->region; + unit *u = + create_unit(r, mage->faction, number, rc, 0, NULL, mage); + leave(u, true); + setstatus(u, ST_FIGHT); + + u->hp = u->number * unit_max_hp(u); + + if (fval(mage, UFL_ANON_FACTION)) { + fset(u, UFL_ANON_FACTION); + } + + a = a_new(&at_unitdissolve); + a->data.ca[0] = 0; + a->data.ca[1] = 100; + a_add(&u->attribs, a); + + return make_fighter(b, u, si, is_attacker(fi)); +} + +int sp_igjarjuk(castorder *co) { + fighter * fi = co->magician.fig; + const race *rc = get_race(RC_WYRM); + fi = summon_allies(fi, rc, 1); + return 1; +} + +int sp_wolfhowl(castorder * co) { fighter * fi = co->magician.fig; int level = co->level; double power = co->force; battle *b = fi->side->battle; - region *r = b->region; unit *mage = fi->unit; - attrib *a; message *msg; int force = (int)(get_force(power, 3) / 2); const race * rc = get_race(RC_WOLF); if (force > 0) { - unit *u = - create_unit(r, mage->faction, force, rc, 0, NULL, mage); - leave(u, true); - setstatus(u, ST_FIGHT); - - set_level(u, SK_WEAPONLESS, (int)(power / 3)); - set_level(u, SK_STAMINA, (int)(power / 3)); - u->hp = u->number * unit_max_hp(u); - - if (fval(mage, UFL_ANON_FACTION)) { - fset(u, UFL_ANON_FACTION); - } - - a = a_new(&at_unitdissolve); - a->data.ca[0] = 0; - a->data.ca[1] = 100; - a_add(&u->attribs, a); - - make_fighter(b, u, fi->side, is_attacker(fi)); + unit *u; + int skills = (int)(power/3); + fi = summon_allies(fi, rc, force); + u = fi->unit; + set_level(u, SK_WEAPONLESS, skills); + set_level(u, SK_STAMINA, skills); } msg = - msg_message("sp_wolfhowl_effect", "mage amount race", mage, force, rc); + msg_message("sp_wolfhowl_effect", "mage amount race", + mage, force, rc); message_all(b, msg); msg_release(msg); diff --git a/src/spells/combatspells.h b/src/spells/combatspells.h index 2683c55e6..8b06fabb1 100644 --- a/src/spells/combatspells.h +++ b/src/spells/combatspells.h @@ -43,6 +43,7 @@ extern "C" { extern int sp_mindblast_temp(struct castorder * co); extern int sp_speed(struct castorder * co); extern int sp_wolfhowl(struct castorder * co); + extern int sp_igjarjuk(struct castorder * co); extern int sp_dragonodem(struct castorder * co); extern int sp_reduceshield(struct castorder * co); extern int sp_armorshield(struct castorder * co); From acb2aed30fab2c655f2f98bee2f118c1cc59dda4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 30 Aug 2015 11:01:53 +0200 Subject: [PATCH 4/5] add message for igjarjuk effect --- src/spells/combatspells.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 9fc41f18a..ed71e17bf 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -854,6 +854,7 @@ static fighter *summon_allies(const fighter *fi, const race *rc, int number) { side *si = fi->side; battle *b = si->battle; region *r = b->region; + message *msg; unit *u = create_unit(r, mage->faction, number, rc, 0, NULL, mage); leave(u, true); @@ -870,14 +871,23 @@ static fighter *summon_allies(const fighter *fi, const race *rc, int number) { a->data.ca[1] = 100; a_add(&u->attribs, a); + msg = + msg_message("sp_wolfhowl_effect", "mage amount race", + mage, u->number, rc); + message_all(b, msg); + msg_release(msg); + return make_fighter(b, u, si, is_attacker(fi)); } int sp_igjarjuk(castorder *co) { + unit *u; fighter * fi = co->magician.fig; const race *rc = get_race(RC_WYRM); fi = summon_allies(fi, rc, 1); - return 1; + u = fi->unit; + unit_setname(u, "Igjarjuk"); + return co->level; } int sp_wolfhowl(castorder * co) @@ -885,9 +895,6 @@ int sp_wolfhowl(castorder * co) fighter * fi = co->magician.fig; int level = co->level; double power = co->force; - battle *b = fi->side->battle; - unit *mage = fi->unit; - message *msg; int force = (int)(get_force(power, 3) / 2); const race * rc = get_race(RC_WOLF); if (force > 0) { @@ -898,12 +905,6 @@ int sp_wolfhowl(castorder * co) set_level(u, SK_WEAPONLESS, skills); set_level(u, SK_STAMINA, skills); } - msg = - msg_message("sp_wolfhowl_effect", "mage amount race", - mage, force, rc); - message_all(b, msg); - msg_release(msg); - return level; } From 8c860811e2d8b08ffa51cf5e67842a51aff8f733 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 30 Aug 2015 23:15:04 +0200 Subject: [PATCH 5/5] Summon Igjarjuk only at the start of a battle, not after. --- src/battle.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/battle.c b/src/battle.c index bc3ed9cbd..f9bfa0770 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1696,34 +1696,36 @@ void do_combatmagic(battle * b, combatmagic_t was) memset(spellranks, 0, sizeof(spellranks)); #ifdef FFL_CURSED - for (s = b->sides; s != b->sides + b->nsides; ++s) { - fighter *fig = 0; - if (s->bf->attacker) { - spell *sp = find_spell("igjarjuk"); - if (sp && fval(s->faction, FFL_CURSED)) { - int si; - for (si = 0; s->enemies[si]; ++si) { - side *se = s->enemies[si]; - if (se && !fval(se->faction, FFL_NPC)) { - fighter *fi; - for (fi = se->fighters; fi; fi = fi->next) { - if (fi && (!fig || fig->unit->number > fi->unit->number)) { - fig = fi; - if (fig->unit->number == 1) { - break; + if (was == DO_PRECOMBATSPELL) { + for (s = b->sides; s != b->sides + b->nsides; ++s) { + fighter *fig = 0; + if (s->bf->attacker) { + spell *sp = find_spell("igjarjuk"); + if (sp && fval(s->faction, FFL_CURSED)) { + int si; + for (si = 0; s->enemies[si]; ++si) { + side *se = s->enemies[si]; + if (se && !fval(se->faction, FFL_NPC)) { + fighter *fi; + for (fi = se->fighters; fi; fi = fi->next) { + if (fi && (!fig || fig->unit->number > fi->unit->number)) { + fig = fi; + if (fig->unit->number == 1) { + break; + } } } - } - if (fig && fig->unit->number == 1) { - break; + if (fig && fig->unit->number == 1) { + break; + } } } - } - if (fig) { - co = create_castorder_combat(0, fig, sp, 10, 10); - co->magician.fig = fig; - add_castorder(&spellranks[sp->rank], co); - break; + if (fig) { + co = create_castorder_combat(0, fig, sp, 10, 10); + co->magician.fig = fig; + add_castorder(&spellranks[sp->rank], co); + break; + } } } }