From 7985ebe51155afffaeb69547c27111283c2b1306 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 21 Aug 2017 20:18:19 +0200 Subject: [PATCH] replace ct_find calls with constants. reorder a lot of includes. --- src/battle.c | 7 ++-- src/bind_monsters.c | 4 +-- src/economy.c | 18 +++++----- src/items.c | 17 ++++++---- src/kernel/building.c | 7 ++-- src/kernel/region.c | 2 +- src/kernel/ship.c | 8 ++--- src/kernel/ship.test.c | 2 +- src/kernel/terrain.c | 8 +++-- src/kernel/unit.c | 3 +- src/laws.c | 27 +++++++-------- src/magic.c | 43 ++++++++++++------------ src/monsters.c | 7 ++-- src/move.c | 28 ++++++++-------- src/randenc.c | 54 +++++++++++++++--------------- src/report.c | 4 +-- src/reports.c | 22 ++++++------- src/spells.c | 55 ++++++++++++++----------------- src/spells.h | 7 ++-- src/spells.test.c | 4 +-- src/spells/combatspells.c | 6 ++-- src/spells/flyingship.c | 4 +-- src/spells/magicresistance.c | 2 +- src/spells/magicresistance.test.c | 4 +-- src/spells/regioncurse.c | 24 +++++++------- src/spells/regioncurse.h | 12 +++++++ src/spells/shipcurse.c | 2 +- src/spells/shipcurse.h | 2 ++ src/spells/unitcurse.c | 16 ++++----- src/spells/unitcurse.h | 8 +++++ src/study.c | 12 +++---- 31 files changed, 220 insertions(+), 199 deletions(-) diff --git a/src/battle.c b/src/battle.c index 7d6df8697..54ff2e399 100644 --- a/src/battle.c +++ b/src/battle.c @@ -27,6 +27,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "move.h" #include "skill.h" +#include +#include +#include + #include #include #include @@ -54,9 +58,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include -#include -#include /* util includes */ #include diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 4ac15aa24..082d940ae 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -2,6 +2,8 @@ #include "spells/shipcurse.h" #include "monsters.h" +#include + #include #include #include @@ -9,8 +11,6 @@ #include #include -#include - #include #include diff --git a/src/economy.c b/src/economy.c index c64734c0a..8cd87c407 100644 --- a/src/economy.c +++ b/src/economy.c @@ -36,6 +36,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "reports.h" #include "calendar.h" +#include +#include +#include +#include + /* kernel includes */ #include #include @@ -67,10 +72,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include -#include -#include - /* libs includes */ #include #include @@ -2655,12 +2656,9 @@ expandwork(region * r, request * work_begin, request * work_end, int maxwork) earnings = jobs * p_wage; if (r->attribs && rule_blessed_harvest() == HARVEST_TAXES) { /* E3 rules */ - const curse_type *blessedharvest_ct = ct_find("blessedharvest"); - if (blessedharvest_ct) { - int happy = - (int)(jobs * curse_geteffect(get_curse(r->attribs, blessedharvest_ct))); - earnings += happy; - } + int happy = + (int)(jobs * curse_geteffect(get_curse(r->attribs, &ct_blessedharvest))); + earnings += happy; } rsetmoney(r, money + earnings); } diff --git a/src/items.c b/src/items.c index e33aed1bc..dd4abe1ac 100644 --- a/src/items.c +++ b/src/items.c @@ -7,6 +7,12 @@ #include "move.h" #include "magic.h" +#include + +#include +#include +#include + #include #include #include @@ -21,9 +27,6 @@ #include #include -#include -#include - /* triggers includes */ #include #include @@ -167,7 +170,7 @@ struct order *ord) } if (force > 0) { - create_curse(u, &r->attribs, ct_find("antimagiczone"), force, duration, + create_curse(u, &r->attribs, &ct_antimagiczone, force, duration, effect, 0); } } @@ -185,7 +188,7 @@ int amount, struct order *ord) { int money; - if (get_curse(u->region->attribs, ct_find("depression"))) { + if (get_curse(u->region->attribs, &ct_depression)) { cmistake(u, ord, 58, MSG_MAGIC); return -1; } @@ -194,7 +197,7 @@ int amount, struct order *ord) change_money(u, money); rsetmoney(u->region, rmoney(u->region) - money); - create_curse(u, &u->region->attribs, ct_find("depression"), + create_curse(u, &u->region->attribs, &ct_depression, 20, BAGPIPEDURATION, 0.0, 0); ADDMSG(&u->faction->msgs, msg_message("bagpipeoffear_faction", @@ -354,7 +357,7 @@ use_tacticcrystal(unit * u, const struct item_type *itype, int amount, der vor den Antimagiezaubern passiert */ effect = (float)(rng_int() % 6 - 1); - c = create_curse(u, &u->attribs, ct_find("skillmod"), power, + c = create_curse(u, &u->attribs, &ct_skillmod, power, duration, effect, u->number); c->data.i = SK_TACTICS; UNUSED_ARG(ord); diff --git a/src/kernel/building.c b/src/kernel/building.c index 2a0a19dce..45245c53e 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -21,6 +21,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "building.h" +#include +#include + /* kernel includes */ #include "curse.h" #include "item.h" @@ -54,10 +57,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -/* attributes includes */ -#include -#include - typedef struct building_typelist { struct building_typelist *next; building_type *type; diff --git a/src/kernel/region.c b/src/kernel/region.c index 1758927d2..1fc51fce0 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -159,7 +159,7 @@ void deathcounts(region * r, int fallen) if (fallen == 0) return; if (r->attribs) { - const curse_type *ctype = ct_find("holyground"); + const curse_type *ctype = &ct_holyground; if (ctype && curse_active(get_curse(r->attribs, ctype))) return; a = a_find(r->attribs, &at_deathcount); diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 79918806d..764500b50 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -20,6 +20,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "ship.h" +#include +#include + /* kernel includes */ #include "build.h" #include "curse.h" @@ -41,9 +44,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include -#include - #include #include #include @@ -335,7 +335,7 @@ int shipspeed(const ship * sh, const unit * u) if (curse_active(get_curse(sh->attribs, &ct_stormwind))) { k *= 2; } - if (curse_active(get_curse(sh->attribs, ct_find("nodrift")))) { + if (curse_active(get_curse(sh->attribs, &ct_nodrift))) { k += 1; } } diff --git a/src/kernel/ship.test.c b/src/kernel/ship.test.c index ea1474e56..ce55f55af 100644 --- a/src/kernel/ship.test.c +++ b/src/kernel/ship.test.c @@ -450,7 +450,7 @@ static void test_shipspeed_nodrift(CuTest *tc) { register_shipcurse(); assert(sh && cap && crew); - create_curse(0, &sh->attribs, ct_find("nodrift"), 1, 1, 1, 0); + create_curse(0, &sh->attribs, &ct_nodrift, 1, 1, 1, 0); CuAssertIntEquals_Msg(tc, "nodrift adds +1 to range", sh->type->range + 1, shipspeed(sh, cap)); test_cleanup(); } diff --git a/src/kernel/terrain.c b/src/kernel/terrain.c index 3d6f4c313..e9f448f97 100644 --- a/src/kernel/terrain.c +++ b/src/kernel/terrain.c @@ -18,14 +18,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include #include "terrain.h" -#include "terrainid.h" + +#include +#include /* kernel includes */ #include "curse.h" #include "region.h" #include "resources.h" +#include "terrainid.h" #include #include @@ -160,7 +162,7 @@ const char *terrain_name(const struct region *r) return r->terrain->name(r); } else if (fval(r->terrain, SEA_REGION)) { - if (curse_active(get_curse(r->attribs, ct_find("maelstrom")))) { + if (curse_active(get_curse(r->attribs, &ct_maelstrom))) { return "maelstrom"; } } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 50ebfdd5c..84e4eb06e 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -941,8 +941,7 @@ bool can_survive(const unit * u, const region * r) return false; if (r->attribs) { - const curse_type *ctype = ct_find("holyground"); - if (fval(u_race(u), RCF_UNDEAD) && curse_active(get_curse(r->attribs, ctype))) + if (fval(u_race(u), RCF_UNDEAD) && curse_active(get_curse(r->attribs, &ct_holyground))) return false; } return true; diff --git a/src/laws.c b/src/laws.c index 5c7d36b51..0d78e6d6c 100644 --- a/src/laws.c +++ b/src/laws.c @@ -42,6 +42,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "calendar.h" #include "guard.h" +/* attributes includes */ +#include +#include +#include + +#include +#include +#include + /* kernel includes */ #include #include @@ -66,12 +75,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* for volcanoes in emigration (needs a flag) */ #include -/* attributes includes */ -#include -#include -#include -#include - /* util includes */ #include #include @@ -2859,13 +2862,12 @@ static void age_stonecircle(building *b) { if (get_astralplane()) { region *rt = r_standard_to_astral(r); if (mage && rt && !fval(rt->terrain, FORBIDDEN_REGION)) { - const struct curse_type *ct_astralblock = ct_find("astralblock"); - curse *c = get_curse(rt->attribs, ct_astralblock); + curse *c = get_curse(rt->attribs, &ct_astralblock); if (!c) { int sk = effskill(mage, SK_MAGIC, 0); float effect = 100; /* the mage reactivates the circle */ - c = create_curse(mage, &rt->attribs, ct_astralblock, + c = create_curse(mage, &rt->attribs, &ct_astralblock, (float)MAX(1, sk), MAX(1, sk / 2), effect, 0); ADDMSG(&r->msgs, msg_message("astralshield_activate", "region unit", r, mage)); @@ -2923,7 +2925,7 @@ static void ageing(void) } if (is_cursed(u->attribs, C_OLDRACE, 0)) { - curse *c = get_curse(u->attribs, ct_find("oldrace")); + curse *c = get_curse(u->attribs, &ct_oldrace); if (c->duration == 1 && !(c_flags(c) & CURSE_NOAGE)) { u_setrace(u, get_race(curse_geteffect_int(c))); u->irace = NULL; @@ -3234,15 +3236,14 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order void monthly_healing(void) { region *r; - const curse_type *heal_ct = ct_find("healingzone"); for (r = regions; r; r = r->next) { unit *u; double healingcurse = 0; - if (r->attribs && heal_ct) { + if (r->attribs) { /* bonus zurücksetzen */ - curse *c = get_curse(r->attribs, heal_ct); + curse *c = get_curse(r->attribs, &ct_healing); if (c != NULL) { healingcurse = curse_geteffect(c); } diff --git a/src/magic.c b/src/magic.c index 883bddffa..58222b6e7 100644 --- a/src/magic.c +++ b/src/magic.c @@ -25,6 +25,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "study.h" #include "helpers.h" #include "laws.h" +#include "spells.h" + +#include +#include +#include +#include +#include +#include + +#include +#include #include #include @@ -46,13 +57,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include -#include -#include -#include -#include -#include - /* util includes */ #include #include @@ -1024,7 +1028,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order curse *c; /* Antimagie in der Zielregion */ - c = get_curse(r->attribs, ct_find("antimagiczone")); + c = get_curse(r->attribs, &ct_antimagiczone); if (curse_active(c)) { unit *mage = c->magician; force -= curse_geteffect(c); @@ -1043,7 +1047,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order } /* Patzerfluch-Effekt: */ - c = get_curse(r->attribs, ct_find("fumble")); + c = get_curse(r->attribs, &ct_fumble); if (curse_active(c)) { unit *mage = c->magician; force -= curse_geteffect(c); @@ -1100,21 +1104,22 @@ variant magic_resistance(unit * target) { attrib *a; curse *c; - const curse_type * ct_goodresist = 0, *ct_badresist = 0; const resource_type *rtype; const race *rc = u_race(target); variant v, prob = rc_magres(rc); const plane *pl = rplane(target->region); + bool good_resist = true; + bool bad_resist = true; if (rc == get_race(RC_HIRNTOETER) && !pl) { - prob = frac_mul(prob, frac_make(1, 2)); + prob = frac_mul(prob, frac_make(1, 2)); } assert(target->number > 0); /* Magier haben einen Resistenzbonus vom Magietalent * 5% */ prob = frac_add(prob, frac_make(effskill(target, SK_MAGIC, 0), 20)); /* Auswirkungen von Zaubern auf der Einheit */ - c = get_curse(target->attribs, ct_find("magicresistance")); + c = get_curse(target->attribs, &ct_magicresistance); if (c) { /* TODO: legacy. magicresistance-effect is an integer-percentage stored in a double */ int effect = curse_geteffect_int(c) * get_cursedmen(target, c); @@ -1132,27 +1137,23 @@ variant magic_resistance(unit * target) /* Auswirkungen von Zaubern auf der Region */ a = a_find(target->region->attribs, &at_curse); - if (a) { - ct_badresist = ct_find("badmagicresistancezone"); - ct_goodresist = ct_find("goodmagicresistancezone"); - } while (a && a->type == &at_curse) { curse *c = (curse *)a->data.v; unit *mage = c->magician; if (mage != NULL) { - if (ct_goodresist && c->type == ct_goodresist) { + if (good_resist && c->type == &ct_goodmagicresistancezone) { if (alliedunit(mage, target->faction, HELP_GUARD)) { /* TODO: legacy. magicresistance-effect is an integer-percentage stored in a double */ prob = frac_add(prob, frac_make(curse_geteffect_int(c), 100)); - ct_goodresist = 0; /* only one effect per region */ + good_resist = false; /* only one effect per region */ } } - else if (ct_badresist && c->type == ct_badresist) { + else if (bad_resist && c->type == &ct_badmagicresistancezone) { if (!alliedunit(mage, target->faction, HELP_GUARD)) { /* TODO: legacy. magicresistance-effect is an integer-percentage stored in a double */ prob = frac_sub(prob, frac_make(curse_geteffect_int(c), 100)); - ct_badresist = 0; /* only one effect per region */ + bad_resist = false; /* only one effect per region */ } } } @@ -1410,7 +1411,7 @@ static void do_fumble(castorder * co) /* temporary skill loss */ duration = MAX(rng_int() % level / 2, 2); effect = level / -2.0; - c = create_curse(u, &u->attribs, ct_find("skillmod"), level, + c = create_curse(u, &u->attribs, &ct_skillmod, level, duration, effect, 1); c->data.i = SK_MAGIC; ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r)); diff --git a/src/monsters.c b/src/monsters.c index ffc04b52e..57b557999 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -34,6 +34,8 @@ #include #include +#include + /* kernel includes */ #include #include @@ -904,13 +906,12 @@ void spawn_undead(void) { region *r; faction *monsters = get_monsters(); - const curse_type *ctype = ct_find("holyground"); for (r = regions; r; r = r->next) { int unburied = deathcount(r); - if (r->attribs && ctype) { - if (curse_active(get_curse(r->attribs, ctype))) { + if (r->attribs) { + if (curse_active(get_curse(r->attribs, &ct_holyground))) { continue; } } diff --git a/src/move.c b/src/move.c index 28d0fbbbe..de2aae7ae 100644 --- a/src/move.c +++ b/src/move.c @@ -31,6 +31,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "lighthouse.h" #include "piracy.h" +#include +#include +#include + +/* attributes includes */ +#include +#include +#include +#include + +/* kernel includes */ #include #include #include @@ -49,9 +60,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include -#include - #include "teleport.h" #include "direction.h" #include "calendar.h" @@ -72,12 +80,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -/* attributes includes */ -#include -#include -#include -#include - /* libc includes */ #include #include @@ -1002,7 +1004,7 @@ bool move_blocked(const unit * u, const region * r, const region * r2) } if (r->attribs) { - const curse_type *fogtrap_ct = ct_find("fogtrap"); + const curse_type *fogtrap_ct = &ct_fogtrap; curse *c = get_curse(r->attribs, fogtrap_ct); return curse_active(c); } @@ -1254,7 +1256,7 @@ static bool roadto(const region * r, direction_t dir) return false; } if (r->attribs || r2->attribs) { - const curse_type *roads_ct = ct_find("magicstreet"); + const curse_type *roads_ct = &ct_magicstreet; if (roads_ct != NULL) { if (get_curse(r->attribs, roads_ct) != NULL) return true; @@ -1578,7 +1580,7 @@ static const region_list *travel_route(unit * u, /* illusionary units disappear in antimagic zones */ if (fval(u_race(u), RCF_ILLUSIONARY)) { - curse *c = get_curse(next->attribs, ct_find("antimagiczone")); + curse *c = get_curse(next->attribs, &ct_antimagiczone); if (curse_active(c)) { curse_changevigour(&next->attribs, c, (float)-u->number); ADDMSG(&u->faction->msgs, msg_message("illusionantimagic", "unit", u)); @@ -1892,7 +1894,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) break; } - if (curse_active(get_curse(next_point->attribs, ct_find("maelstrom")))) { + if (curse_active(get_curse(next_point->attribs, &ct_maelstrom))) { if (do_maelstrom(next_point, u) == NULL) break; } diff --git a/src/randenc.c b/src/randenc.c index ab51d64b1..c0daec72c 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -27,6 +27,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "chaos.h" #include "study.h" +/* attributes includes */ +#include +#include + +#include + /* kernel includes */ #include #include @@ -44,10 +50,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -/* attributes includes */ -#include -#include - /* util includes */ #include #include @@ -692,32 +694,28 @@ static void orc_growth(void) for (u = r->units; u; u = u->next) { if (u->attribs && !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY) && !fval(u, UFL_HERO)) { - const curse_type *ct_orcish = ct_find("orcish"); + curse *c = get_curse(u->attribs, &ct_orcish); + if (c) { + int n; + int increase = 0; + int num = get_cursedmen(u, c); + double prob = curse_geteffect(c); + const item_type * it_chastity = it_find("ao_chastity"); - if (ct_orcish) { - curse *c = get_curse(u->attribs, ct_orcish); - if (c) { - int n; - int increase = 0; - int num = get_cursedmen(u, c); - double prob = curse_geteffect(c); - const item_type * it_chastity = it_find("ao_chastity"); + if (it_chastity) { + num -= i_get(u->items, it_chastity); + } + for (n = num; n > 0; n--) { + if (chance(prob)) { + ++increase; + } + } + if (increase) { + unit *u2 = create_unit(r, u->faction, increase, u_race(u), 0, NULL, u); + transfermen(u2, u, u2->number); - if (it_chastity) { - num -= i_get(u->items, it_chastity); - } - for (n = num; n > 0; n--) { - if (chance(prob)) { - ++increase; - } - } - if (increase) { - unit *u2 = create_unit(r, u->faction, increase, u_race(u), 0, NULL, u); - transfermen(u2, u, u2->number); - - ADDMSG(&u->faction->msgs, msg_message("orcgrowth", - "unit amount race", u, increase, u_race(u))); - } + ADDMSG(&u->faction->msgs, msg_message("orcgrowth", + "unit amount race", u, increase, u_race(u))); } } } diff --git a/src/report.c b/src/report.c index 1b180d8c2..b86304ffc 100644 --- a/src/report.c +++ b/src/report.c @@ -46,6 +46,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "calendar.h" #include "teleport.h" +#include + /* kernel includes */ #include #include @@ -72,8 +74,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include - /* util includes */ #include #include diff --git a/src/reports.c b/src/reports.c index 6448fa58b..0a04b7497 100644 --- a/src/reports.c +++ b/src/reports.c @@ -25,6 +25,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "lighthouse.h" #include "donations.h" +/* attributes includes */ +#include +#include +#include +#include + +#include + /* kernel includes */ #include #include @@ -68,11 +76,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -/* attributes includes */ -#include -#include -#include -#include #include "move.h" @@ -303,12 +306,9 @@ report_items(const unit *u, item * result, int size, const unit * owner, assert(size); if (u->attribs) { - const curse_type *itemcloak_ct = ct_find("itemcloak"); - if (itemcloak_ct) { - curse * cu = get_curse(u->attribs, itemcloak_ct); - if (cu && curse_active(cu)) { - return 0; - } + curse * cu = get_curse(u->attribs, &ct_itemcloak); + if (cu && curse_active(cu)) { + return 0; } } for (itm = items; itm; itm = itm->next) { diff --git a/src/spells.c b/src/spells.c index efda37d22..254546baa 100644 --- a/src/spells.c +++ b/src/spells.c @@ -825,7 +825,7 @@ static int sp_goodwinds(castorder * co) /* keine Probleme mit C_SHIP_SPEEDUP und C_SHIP_FLYING */ /* NODRIFT bewirkt auch +1 Geschwindigkeit */ - create_curse(mage, &sh->attribs, ct_find("nodrift"), power, duration, + create_curse(mage, &sh->attribs, &ct_nodrift, power, duration, zero_effect, 0); /* melden, 1x pro Partei */ @@ -872,7 +872,7 @@ static int sp_magicstreet(castorder * co) } /* wirkt schon in der Zauberrunde! */ - create_curse(mage, &r->attribs, ct_find("magicstreet"), co->force, + create_curse(mage, &r->attribs, &ct_magicstreet, co->force, co->level + 1, zero_effect, 0); /* melden, 1x pro Partei */ @@ -1022,7 +1022,7 @@ static int sp_maelstrom(castorder * co) /* Attribut auf Region. * Existiert schon ein curse, so wird dieser verstaerkt * (Max(Dauer), Max(Staerke))*/ - c = create_curse(mage, &r->attribs, ct_find("maelstrom"), co->force, duration, co->force, 0); + c = create_curse(mage, &r->attribs, &ct_maelstrom, co->force, duration, co->force, 0); /* melden, 1x pro Partei */ if (c) { @@ -1102,7 +1102,7 @@ static int sp_blessedharvest(castorder * co) * Existiert schon ein curse, so wird dieser verstaerkt * (Max(Dauer), Max(Staerke))*/ - if (create_curse(mage, &r->attribs, ct_find("blessedharvest"), co->force, + if (create_curse(mage, &r->attribs, &ct_blessedharvest, co->force, duration, 1.0, 0)) { const char * effect = co->sp->sname[0]=='b' ? "harvest_effect" : "raindance_effect"; message *seen = msg_message(effect, "mage", mage); @@ -1405,7 +1405,7 @@ static int sp_kaelteschutz(castorder * co) } effect = 1; - create_curse(mage, &u->attribs, ct_find("insectfur"), (float)cast_level, + create_curse(mage, &u->attribs, &ct_insectfur, (float)cast_level, duration, effect, men); force -= u->number; @@ -1455,7 +1455,7 @@ static int sp_sparkle(castorder * co) u = pa->param[0]->data.u; effect = (float)(rng_int() % 0xffffff); - create_curse(mage, &u->attribs, ct_find("sparkle"), (float)cast_level, + create_curse(mage, &u->attribs, &ct_sparkle, (float)cast_level, duration, effect, u->number); ADDMSG(&mage->faction->msgs, msg_message("sparkle_effect", "mage target", @@ -2036,7 +2036,7 @@ static int sp_holyground(castorder * co) report_spell(mage, r, msg); msg_release(msg); - ctype = ct_find("holyground"); + ctype = &ct_holyground; create_curse(mage, &r->attribs, ctype, power * power, 1, zero_effect, 0); a_removeall(&r->attribs, &at_deathcount); @@ -2083,7 +2083,7 @@ static int sp_homestone(castorder * co) /* Magieresistenz der Burg erhoeht sich um 50% */ effect = 50.0F; c = create_curse(mage, &mage->building->attribs, - ct_find("magicresistance"), force * force, 1, effect, 0); + &ct_magicresistance, force * force, 1, effect, 0); c_setflag(c, CURSE_NOAGE); /* melden, 1x pro Partei in der Burg */ @@ -2538,7 +2538,7 @@ static int sp_fumblecurse(castorder * co) duration = MAX(sx, rx) + 1; effect = force / 2; - c = create_curse(mage, &target->attribs, ct_find("fumble"), + c = create_curse(mage, &target->attribs, &ct_fumble, force, duration, effect, 0); if (c == NULL) { report_failure(mage, co->order); @@ -2561,7 +2561,7 @@ void patzer_fumblecurse(const castorder * co) curse *c; effect = force / 2; - c = create_curse(mage, &mage->attribs, ct_find("fumble"), force, + c = create_curse(mage, &mage->attribs, &ct_fumble, force, duration, effect, 0); if (c != NULL) { ADDMSG(&mage->faction->msgs, msg_message("magic_fumble", @@ -3231,13 +3231,6 @@ static int sp_magicboost(castorder * co) double power = co->force; double effect; trigger *tsummon; - const curse_type *ct_auraboost; - const curse_type *ct_magicboost; - - ct_auraboost = ct_find("auraboost"); - ct_magicboost = ct_find("magicboost"); - assert(ct_auraboost != NULL); - assert(ct_magicboost != NULL); /* fehler, wenn schon ein boost */ if (is_cursed(mage->attribs, C_MBOOST, 0)) { @@ -3246,13 +3239,13 @@ static int sp_magicboost(castorder * co) } effect = 6; - create_curse(mage, &mage->attribs, ct_magicboost, power, 10, effect, 1); + create_curse(mage, &mage->attribs, &ct_magicboost, power, 10, effect, 1); /* one aura boost with 200% aura now: */ effect = 200; - c = create_curse(mage, &mage->attribs, ct_auraboost, power, 4, effect, 1); + c = create_curse(mage, &mage->attribs, &ct_auraboost, power, 4, effect, 1); /* and one aura boost with 50% aura in 5 weeks: */ - tsummon = trigger_createcurse(mage, mage, ct_auraboost, power, 6, 50, 1); + tsummon = trigger_createcurse(mage, mage, &ct_auraboost, power, 6, 50, 1); add_trigger(&mage->attribs, "timer", trigger_timeout(5, tsummon)); ADDMSG(&mage->faction->msgs, msg_message("magicboost_effect", @@ -3685,7 +3678,7 @@ static int sp_song_resistmagic(castorder * co) double force = co->force; int duration = (int)force + 1; - create_curse(mage, &r->attribs, ct_find("goodmagicresistancezone"), + create_curse(mage, &r->attribs, &ct_goodmagicresistancezone, force, duration, 15, 0); /* Erfolg melden */ @@ -3714,7 +3707,7 @@ static int sp_song_susceptmagic(castorder * co) double force = co->force; int duration = (int)force + 1; - create_curse(mage, &r->attribs, ct_find("badmagicresistancezone"), + create_curse(mage, &r->attribs, &ct_badmagicresistancezone, force, duration, 15, 0); ADDMSG(&mage->faction->msgs, msg_message("regionmagic_effect", @@ -3822,7 +3815,7 @@ static int sp_raisepeasantmob(castorder * co) a->data.ca[1] = 15; /* 15% */ a_add(&u->attribs, a); - create_curse(mage, &r->attribs, ct_find("riotzone"), (float)cast_level, duration, + create_curse(mage, &r->attribs, &ct_riotzone, (float)cast_level, duration, (float)anteil, 0); msg = msg_message("sp_raisepeasantmob_effect", "mage region", mage, r); @@ -3978,7 +3971,7 @@ static int sp_generous(castorder * co) } effect = 2; - create_curse(mage, &r->attribs, ct_find("generous"), force, duration, effect, + create_curse(mage, &r->attribs, &ct_generous, force, duration, effect, 0); for (u = r->units; u; u = u->next) @@ -4443,7 +4436,7 @@ static int sp_depression(castorder * co) int duration = (int)force + 1; message *msg; - create_curse(mage, &r->attribs, ct_find("depression"), force, duration, + create_curse(mage, &r->attribs, &ct_depression, force, duration, zero_effect, 0); msg = msg_message("sp_depression_effect", "mage region", mage, r); @@ -4862,7 +4855,7 @@ int sp_sweetdreams(castorder * co) /* Nichts machen als ein entsprechendes Attribut an die Einheit legen. */ effect = 0.05f; - create_curse(mage, &u->attribs, ct_find("orcish"), power, duration, effect, men); + create_curse(mage, &u->attribs, &ct_orcish, power, duration, effect, men); msg = msg_message("sp_sweetdreams_effect", "mage unit region", mage, u, r); r_addmessage(r, mage->faction, msg); @@ -4885,7 +4878,7 @@ int sp_disturbingdreams(castorder * co) double effect; effect = 10; - create_curse(mage, &r->attribs, ct_find("badlearn"), power, duration, effect, 0); + create_curse(mage, &r->attribs, &ct_badlearn, power, duration, effect, 0); ADDMSG(&mage->faction->msgs, msg_message("sp_disturbingdreams_effect", "mage region", mage, r)); @@ -4979,7 +4972,7 @@ int sp_itemcloak(castorder * co) /* Zieleinheit */ target = pa->param[0]->data.u; - create_curse(mage, &target->attribs, ct_find("itemcloak"), power, duration, + create_curse(mage, &target->attribs, &ct_itemcloak, power, duration, zero_effect, 0); ADDMSG(&mage->faction->msgs, msg_message("itemcloak", "mage target", mage, target)); @@ -5031,7 +5024,7 @@ int sp_resist_magic_bonus(castorder * co) m = MIN(u->number, victims); victims -= m; - create_curse(mage, &u->attribs, ct_find("magicresistance"), + create_curse(mage, &u->attribs, &ct_magicresistance, power, duration, 20, m); msg = msg_message("magicresistance_effect", "unit", u); @@ -5793,7 +5786,7 @@ int sp_disruptastral(castorder * co) /* Kontakt unterbinden */ effect = 100; - create_curse(mage, &rl2->data->attribs, ct_find("astralblock"), + create_curse(mage, &rl2->data->attribs, &ct_astralblock, power, duration, effect, 0); } @@ -6107,7 +6100,7 @@ int sp_antimagiczone(castorder * co) /* Reduziert die Staerke jedes Spruchs um effect */ effect = cast_level; - create_curse(mage, &r->attribs, ct_find("antimagiczone"), power, duration, + create_curse(mage, &r->attribs, &ct_antimagiczone, power, duration, effect, 0); /* Erfolg melden */ diff --git a/src/spells.h b/src/spells.h index 275f41f7a..a2f59f231 100644 --- a/src/spells.h +++ b/src/spells.h @@ -22,14 +22,15 @@ extern "C" { #endif - struct ship; - struct curse; + struct curse_type; + struct region; struct unit; struct message; + extern const struct curse_type ct_magicresistance; + void register_magicresistance(void); void register_spells(void); - void set_spelldata(struct spell *sp); int sp_baddreams(castorder * co); int sp_gooddreams(castorder * co); diff --git a/src/spells.test.c b/src/spells.test.c index 07a980e03..075ea6da6 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -39,7 +39,7 @@ static void test_good_dreams(CuTest *tc) { level = sp_gooddreams(&co); CuAssertIntEquals(tc, 10, level); - curse = get_curse(r->attribs, ct_find("gbdream")); + curse = get_curse(r->attribs, &ct_gbdream); CuAssertTrue(tc, curse && curse->duration > 1); CuAssertTrue(tc, curse->effect == 1); @@ -96,7 +96,7 @@ static void test_bad_dreams(CuTest *tc) { level = sp_baddreams(&co); CuAssertIntEquals(tc, 10, level); - curse = get_curse(r->attribs, ct_find("gbdream")); + curse = get_curse(r->attribs, &ct_gbdream); CuAssertTrue(tc, curse && curse->duration > 1); CuAssertTrue(tc, curse->effect == -1); diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 8f62686d6..0f2b2ea3a 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -12,7 +12,9 @@ #include #include "combatspells.h" -/* kernel includes */ +#include + + /* kernel includes */ #include #include #include @@ -27,8 +29,6 @@ #include #include -#include - #include #include #include diff --git a/src/spells/flyingship.c b/src/spells/flyingship.c index eac2043dd..c3fe63e73 100644 --- a/src/spells/flyingship.c +++ b/src/spells/flyingship.c @@ -1,6 +1,8 @@ #include #include "flyingship.h" +#include + #include #include #include @@ -13,8 +15,6 @@ #include -#include - #include /* libc includes */ diff --git a/src/spells/magicresistance.c b/src/spells/magicresistance.c index 7b0c1413d..6f2ec49ec 100644 --- a/src/spells/magicresistance.c +++ b/src/spells/magicresistance.c @@ -22,7 +22,7 @@ static struct message *cinfo_magicresistance(const void *obj, objtype_t typ, con return 0; } -static struct curse_type ct_magicresistance = { +const struct curse_type ct_magicresistance = { "magicresistance", CURSETYP_UNIT, CURSE_SPREADMODULO, M_MEN, cinfo_magicresistance }; diff --git a/src/spells/magicresistance.test.c b/src/spells/magicresistance.test.c index 621d2c3b4..7576911af 100644 --- a/src/spells/magicresistance.test.c +++ b/src/spells/magicresistance.test.c @@ -36,7 +36,7 @@ static void test_magicresistance_unit(CuTest *tc) { f2 = test_create_faction(NULL); u2 = test_create_unit(f2, r); - c = create_curse(u1, &u2->attribs, ct_find("magicresistance"), 10, 20, 30, u2->number); + c = create_curse(u1, &u2->attribs, &ct_magicresistance, 10, 20, 30, u2->number); CuAssertPtrNotNull(tc, u2->attribs); CuAssertPtrEquals(tc, (void *)&at_curse, (void *)u2->attribs->type); msg = c->type->curseinfo(u2, TYP_UNIT, c, 1); @@ -62,7 +62,7 @@ static void test_magicresistance_building(CuTest *tc) { b1 = test_create_building(r, NULL); - c = create_curse(u1, &b1->attribs, ct_find("magicresistance"), 10, 20, 30, 0); + c = create_curse(u1, &b1->attribs, &ct_magicresistance, 10, 20, 30, 0); CuAssertPtrNotNull(tc, b1->attribs); CuAssertPtrEquals(tc, (void *)&at_curse, (void *)b1->attribs->type); msg = c->type->curseinfo(b1, TYP_BUILDING, c, 1); diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index aafc3ed4c..fa49826d9 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -106,7 +106,7 @@ static message *cinfo_magicstreet(const void *obj, objtype_t typ, const curse * return msg_message("curseinfo::magicstreetwarn", "id", c->no); } -static struct curse_type ct_magicstreet = { +const struct curse_type ct_magicstreet = { "magicstreet", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_magicstreet @@ -157,7 +157,7 @@ const curse * c, int self) return self; } -static struct curse_type ct_antimagiczone = { +const struct curse_type ct_antimagiczone = { "antimagiczone", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_antimagiczone, NULL, NULL, NULL, cansee_antimagiczone @@ -188,13 +188,13 @@ static struct curse_type ct_farvision = { /* --------------------------------------------------------------------- */ -static struct curse_type ct_fogtrap = { +const struct curse_type ct_fogtrap = { "fogtrap", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_simple }; -static struct curse_type ct_maelstrom = { +const struct curse_type ct_maelstrom = { "maelstrom", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_simple @@ -212,28 +212,28 @@ const struct curse_type ct_drought = { cinfo_simple }; -static struct curse_type ct_badlearn = { +const struct curse_type ct_badlearn = { "badlearn", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_simple }; /* Trübsal-Zauber */ -static struct curse_type ct_depression = { +const struct curse_type ct_depression = { "depression", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_simple }; /* Astralblock, auf Astralregion */ -static struct curse_type ct_astralblock = { +const struct curse_type ct_astralblock = { "astralblock", CURSETYP_NORM, 0, NO_MERGE, cinfo_simple }; /* Unterhaltungsanteil vermehren */ -static struct curse_type ct_generous = { +const struct curse_type ct_generous = { "generous", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR | M_MAXEFFECT), cinfo_simple @@ -248,7 +248,7 @@ const struct curse_type ct_peacezone = { /* erniedigt Magieresistenz von nicht-aliierten Einheiten, wirkt nur 1x * pro Einheit */ -static struct curse_type ct_badmagicresistancezone = { +const struct curse_type ct_badmagicresistancezone = { "badmagicresistancezone", CURSETYP_NORM, 0, NO_MERGE, cinfo_simple @@ -256,19 +256,19 @@ static struct curse_type ct_badmagicresistancezone = { /* erhöht Magieresistenz von aliierten Einheiten, wirkt nur 1x pro * Einheit */ -static struct curse_type ct_goodmagicresistancezone = { +const struct curse_type ct_goodmagicresistancezone = { "goodmagicresistancezone", CURSETYP_NORM, 0, NO_MERGE, cinfo_simple }; -static struct curse_type ct_riotzone = { +const struct curse_type ct_riotzone = { "riotzone", CURSETYP_NORM, 0, (M_DURATION), cinfo_simple }; -static struct curse_type ct_holyground = { +const struct curse_type ct_holyground = { "holyground", CURSETYP_NORM, CURSE_NOAGE, (M_VIGOUR_ADD), cinfo_simple diff --git a/src/spells/regioncurse.h b/src/spells/regioncurse.h index c3816b25f..86d9b024c 100644 --- a/src/spells/regioncurse.h +++ b/src/spells/regioncurse.h @@ -25,6 +25,18 @@ extern "C" { extern const struct curse_type ct_godcursezone; extern const struct curse_type ct_gbdream; extern const struct curse_type ct_healing; + extern const struct curse_type ct_antimagiczone; + extern const struct curse_type ct_depression; + extern const struct curse_type ct_astralblock; + extern const struct curse_type ct_badmagicresistancezone; + extern const struct curse_type ct_goodmagicresistancezone; + extern const struct curse_type ct_holyground; + extern const struct curse_type ct_fogtrap; + extern const struct curse_type ct_magicstreet; + extern const struct curse_type ct_maelstrom; + extern const struct curse_type ct_riotzone; + extern const struct curse_type ct_generous; + extern const struct curse_type ct_badlearn; void register_regioncurse(void); diff --git a/src/spells/shipcurse.c b/src/spells/shipcurse.c index a6e52f3a3..180c84eea 100644 --- a/src/spells/shipcurse.c +++ b/src/spells/shipcurse.c @@ -76,7 +76,7 @@ const struct curse_type ct_stormwind = { "stormwind", CURSETYP_NORM, 0, NO_MERGE, cinfo_ship }; -static struct curse_type ct_nodrift = { "nodrift", +const struct curse_type ct_nodrift = { "nodrift", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_shipnodrift }; diff --git a/src/spells/shipcurse.h b/src/spells/shipcurse.h index 928b76771..8bb98bcbe 100644 --- a/src/spells/shipcurse.h +++ b/src/spells/shipcurse.h @@ -21,9 +21,11 @@ extern "C" { struct message; struct curse; + struct curse_type; extern const struct curse_type ct_shipspeedup; extern const struct curse_type ct_stormwind; + extern const struct curse_type ct_nodrift; struct message *cinfo_ship(const void *obj, objtype_t typ, const struct curse *c, int self); diff --git a/src/spells/unitcurse.c b/src/spells/unitcurse.c index d959d9635..4f8d69f64 100644 --- a/src/spells/unitcurse.c +++ b/src/spells/unitcurse.c @@ -60,14 +60,14 @@ static message *cinfo_auraboost(const void *obj, objtype_t typ, const curse * c, return NULL; } -static struct curse_type ct_auraboost = { +const struct curse_type ct_auraboost = { "auraboost", CURSETYP_NORM, CURSE_SPREADMODULO, (NO_MERGE), cinfo_auraboost }; /* Magic Boost - Gabe des Chaos */ -static struct curse_type ct_magicboost = { +const struct curse_type ct_magicboost = { "magicboost", CURSETYP_UNIT, CURSE_SPREADMODULO | CURSE_IMMUNE, M_MEN, cinfo_simple }; @@ -168,7 +168,7 @@ message *cinfo_unit(const void *obj, objtype_t typ, const curse * c, int self) return NULL; } -static struct curse_type ct_orcish = { +const struct curse_type ct_orcish = { "orcish", CURSETYP_UNIT, CURSE_SPREADMODULO, M_MEN, cinfo_unit @@ -192,7 +192,7 @@ static message *cinfo_kaelteschutz(const void *obj, objtype_t typ, const curse * return NULL; } -static struct curse_type ct_insectfur = { +const struct curse_type ct_insectfur = { "insectfur", CURSETYP_UNIT, CURSE_SPREADMODULO, (M_MEN | M_DURATION), cinfo_kaelteschutz @@ -259,7 +259,7 @@ static message *cinfo_sparkle(const void *obj, objtype_t typ, const curse * c, } } -static struct curse_type ct_sparkle = { "sparkle", +const struct curse_type ct_sparkle = { "sparkle", CURSETYP_UNIT, CURSE_SPREADMODULO, (M_MEN | M_DURATION), cinfo_sparkle }; @@ -284,20 +284,20 @@ const struct curse_type ct_worse = { /* * C_ITEMCLOAK */ -static struct curse_type ct_itemcloak = { +const struct curse_type ct_itemcloak = { "itemcloak", CURSETYP_UNIT, CURSE_SPREADNEVER, M_DURATION, cinfo_unit }; /* ------------------------------------------------------------- */ -static struct curse_type ct_fumble = { +const struct curse_type ct_fumble = { "fumble", CURSETYP_NORM, CURSE_SPREADNEVER | CURSE_ONLYONE, NO_MERGE, cinfo_unit }; /* ------------------------------------------------------------- */ -static struct curse_type ct_oldrace = { +const struct curse_type ct_oldrace = { "oldrace", CURSETYP_NORM, CURSE_SPREADALWAYS, NO_MERGE, NULL }; diff --git a/src/spells/unitcurse.h b/src/spells/unitcurse.h index 2102b41e3..681fa32de 100644 --- a/src/spells/unitcurse.h +++ b/src/spells/unitcurse.h @@ -28,6 +28,14 @@ extern "C" { extern const struct curse_type ct_speed; extern const struct curse_type ct_worse; extern const struct curse_type ct_skillmod; + extern const struct curse_type ct_oldrace; + extern const struct curse_type ct_fumble; + extern const struct curse_type ct_orcish; + extern const struct curse_type ct_itemcloak; + extern const struct curse_type ct_insectfur; + extern const struct curse_type ct_sparkle; + extern const struct curse_type ct_magicboost; + extern const struct curse_type ct_auraboost; struct message *cinfo_unit(const void *obj, objtype_t typ, const struct curse *c, int self); diff --git a/src/study.c b/src/study.c index 9ea0a860e..55bcd9b34 100644 --- a/src/study.c +++ b/src/study.c @@ -28,6 +28,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alchemy.h" #include "academy.h" +#include + #include #include #include @@ -52,6 +54,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include + #include /* libc includes */ @@ -282,12 +285,9 @@ int teach_cmd(unit * u, struct order *ord) int teaching, i, j, count, academy = 0; if (u->region->attribs) { - const curse_type *gbdream_ct = ct_find("gbdream"); - if (gbdream_ct) { - if (get_curse(u->region->attribs, gbdream_ct)) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "gbdream_noteach", "")); - return 0; - } + if (get_curse(u->region->attribs, &ct_gbdream)) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "gbdream_noteach", "")); + return 0; } } if ((u_race(u)->flags & RCF_NOTEACH) || fval(u, UFL_WERE)) {