From fc4bde47f6546b8eb09e229bb8305b92e8680fbd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 21 Aug 2017 20:48:00 +0200 Subject: [PATCH] kill the old curses enum and oldcursename. --- src/creport.c | 6 ++- src/economy.c | 15 +++---- src/give.c | 14 ++++--- src/kernel/curse.c | 60 ++++---------------------- src/kernel/curse.h | 9 ++-- src/kernel/faction.c | 7 ++-- src/laws.c | 20 +++++---- src/magic.c | 14 +++---- src/morale.c | 4 +- src/move.c | 14 ++++--- src/randenc.c | 7 ++-- src/report.c | 7 ++-- src/spells.c | 93 ++++++++++++++++++++--------------------- src/spells/flyingship.c | 8 ++-- src/spells/flyingship.h | 3 ++ src/study.c | 2 +- 16 files changed, 127 insertions(+), 156 deletions(-) diff --git a/src/creport.c b/src/creport.c index 10dc4c323..1c18f675a 100644 --- a/src/creport.c +++ b/src/creport.c @@ -20,6 +20,8 @@ without prior permission by the authors of Eressea. #define BUFFERSIZE 32768 #define RESOURCECOMPAT +#include + /* modules include */ #include @@ -1361,7 +1363,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) if (skill_enabled(SK_ENTERTAINMENT)) { fprintf(F, "%d;Unterh\n", entertainmoney(r)); } - if (is_cursed(r->attribs, C_RIOT, 0)) { + if (is_cursed(r->attribs, &ct_riotzone)) { fputs("0;Rekruten\n", F); } else { @@ -1419,7 +1421,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) cr_output_curses_compat(F, f, r, TYP_REGION); cr_borders(r, f, r->seen.mode, F); if (r->seen.mode == seen_unit && is_astral(r) - && !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { + && !is_cursed(r->attribs, &ct_astralblock)) { /* Sonderbehandlung Teleport-Ebene */ region_list *rl = astralregions(r, inhabitable); diff --git a/src/economy.c b/src/economy.c index 8cd87c407..c84645b02 100644 --- a/src/economy.c +++ b/src/economy.c @@ -40,6 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include /* kernel includes */ #include @@ -118,14 +119,14 @@ int entertainmoney(const region * r) { double n; - if (is_cursed(r->attribs, C_DEPRESSION, 0)) { + if (is_cursed(r->attribs, &ct_depression)) { return 0; } n = rmoney(r) / (double)ENTERTAINFRACTION; - if (is_cursed(r->attribs, C_GENEROUS, 0)) { - n *= get_curseeffect(r->attribs, C_GENEROUS, 0); + if (is_cursed(r->attribs, &ct_generous)) { + n *= get_curseeffect(r->attribs, &ct_generous); } return (int)n; @@ -502,7 +503,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders) return; } } - if (is_cursed(r->attribs, C_RIOT, 0)) { + if (is_cursed(r->attribs, &ct_riotzone)) { /* Die Region befindet sich in Aufruhr */ cmistake(u, ord, 237, MSG_EVENT); return; @@ -652,7 +653,7 @@ static int forget_cmd(unit * u, order * ord) skill_t sk; const char *s; - if (is_cursed(u->attribs, C_SLAVE, 0)) { + if (is_cursed(u->attribs, &ct_slavery)) { /* charmed units shouldn't be losing their skills */ return 0; } @@ -2589,7 +2590,7 @@ void entertain_cmd(unit * u, struct order *ord) cmistake(u, ord, 69, MSG_INCOME); return; } - if (is_cursed(r->attribs, C_DEPRESSION, 0)) { + if (is_cursed(r->attribs, &ct_depression)) { cmistake(u, ord, 28, MSG_INCOME); return; } @@ -3028,7 +3029,7 @@ void produce(struct region *r) continue; if (u_race(u) == rc_insect && r_insectstalled(r) && - !is_cursed(u->attribs, C_KAELTESCHUTZ, 0)) + !is_cursed(u->attribs, &ct_insectfur)) continue; if (fval(u, UFL_LONGACTION) && u->thisorder == NULL) { diff --git a/src/give.c b/src/give.c index 060ecbbb9..28f47acd7 100644 --- a/src/give.c +++ b/src/give.c @@ -17,7 +17,12 @@ #include "economy.h" #include "laws.h" -/* kernel includes */ +#include + + /* attributes includes */ +#include + + /* kernel includes */ #include #include #include @@ -33,9 +38,6 @@ #include #include -/* attributes includes */ -#include - /* util includes */ #include #include @@ -286,7 +288,7 @@ static bool can_give_men(const unit *u, const unit *dst, order *ord, message **m /* hungry people cannot be given away */ if (msg) *msg = msg_error(u, ord, 73); } - else if (fval(u, UFL_LOCKED) || is_cursed(u->attribs, C_SLAVE, 0)) { + else if (fval(u, UFL_LOCKED) || is_cursed(u->attribs, &ct_slavery)) { if (msg) *msg = msg_error(u, ord, 74); } else { @@ -329,7 +331,7 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) else if (unit_has_cursed_item(u2)) { error = 78; } - else if (fval(u2, UFL_LOCKED) || is_cursed(u2->attribs, C_SLAVE, 0)) { + else if (fval(u2, UFL_LOCKED) || is_cursed(u2->attribs, &ct_slavery)) { error = 75; } else if (!ucontact(u2, u)) { diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 919ff2ef8..968269962 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -141,10 +141,11 @@ static int read_ccompat(const char *cursename, struct storage *store) struct compat { const char *name; const char *tokens; - } *seek, old_curses[] = { { - "disorientationzone", "" }, { - "shipdisorientation", "" }, { - NULL, NULL } }; + } *seek, old_curses[] = { + { "disorientationzone", "" }, + { "shipdisorientation", "" }, + { NULL, NULL } + }; for (seek = old_curses; seek->name; ++seek) { if (strcmp(seek->tokens, cursename) == 0) { const char *p; @@ -232,7 +233,7 @@ int curse_read(attrib * a, void *owner, gamedata *data) if (c->type->typ == CURSETYP_REGION) { int rr = read_reference(&c->data.v, data, read_region_reference, - RESOLVE_REGION(data->version)); + RESOLVE_REGION(data->version)); if (ur == 0 && rr == 0 && !c->data.v) { return AT_READ_FAIL; } @@ -290,7 +291,7 @@ void ct_register(const curse_type * ct) unsigned int hash = tolower(ct->cname[0]) & 0xFF; selist **ctlp = cursetypes + hash; - assert(ct->age==NULL || (ct->flags&CURSE_NOAGE) == 0); + assert(ct->age == NULL || (ct->flags&CURSE_NOAGE) == 0); assert((ct->flags&CURSE_ISNEW) == 0); selist_set_insert(ctlp, (void *)ct, NULL); } @@ -466,7 +467,7 @@ int curse_geteffect_int(const curse * c) /* ------------------------------------------------------------- */ static void set_curseingmagician(struct unit *magician, struct attrib *ap_target, -const curse_type * ct) + const curse_type * ct) { curse *c = get_curse(ap_target, ct); if (c) { @@ -723,51 +724,6 @@ bool is_cursed_with(const attrib * ap, const curse * c) return false; } -/* ------------------------------------------------------------- */ -/* cursedata */ -/* ------------------------------------------------------------- */ - -static const char *oldnames[MAXCURSE] = { - /* OBS: when removing curses, remember to update read_ccompat() */ - "fogtrap", - "antimagiczone", - "farvision", - "gbdream", - "auraboost", - "maelstrom", - "blessedharvest", - "drought", - "badlearn", - "stormwind", - "flyingship", - "nodrift", - "depression", - "magicwalls", - "strongwall", - "astralblock", - "generous", - "peacezone", - "magicstreet", - "magicrunes", - "badmagicresistancezone", - "goodmagicresistancezone", - "slavery", - "calmmonster", - "oldrace", - "fumble", - "riotzone", - "godcursezone", - "speed", - "orcish", - "magicboost", - "insectfur" -}; - -const char *oldcursename(int id) -{ - return oldnames[id]; -} - /* ------------------------------------------------------------- */ message *cinfo_simple(const void *obj, objtype_t typ, const struct curse * c, int self) diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 5ea08fb28..9f330fdd6 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -303,14 +303,13 @@ extern "C" { bool curse_active(const struct curse *c); /*** COMPATIBILITY MACROS. DO NOT USE FOR NEW CODE, REPLACE IN OLD CODE: */ - const char *oldcursename(int id); struct message *cinfo_simple(const void *obj, objtype_t typ, const struct curse *c, int self); int curse_cansee(const struct curse *c, const struct faction *viewer, objtype_t typ, const void *obj, int self); -#define is_cursed(a, id, id2) \ - (a && curse_active(get_curse(a, ct_find(oldcursename(id))))) -#define get_curseeffect(a, id, id2) \ - curse_geteffect(get_curse(a, ct_find(oldcursename(id)))) +#define is_cursed(a, ctype) \ + (a && curse_active(get_curse(a, ctype))) +#define get_curseeffect(a, ctype) \ + curse_geteffect(get_curse(a, ctype)) /* eressea-defined attribute-type flags */ #define ATF_CURSE ATF_USER_DEFINED diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 0b099df0f..16788c3b5 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -33,6 +33,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "terrain.h" #include "unit.h" +#include +#include + /* util includes */ #include #include @@ -49,8 +52,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include - #include #include @@ -730,7 +731,7 @@ int count_faction(const faction * f, int flags) } } else if (flags&COUNT_MIGRANTS) { - if (!is_cursed(u->attribs, C_SLAVE, 0)) { + if (!is_cursed(u->attribs, &ct_slavery)) { n += x; } } diff --git a/src/laws.c b/src/laws.c index 0d78e6d6c..47f1dd9e9 100644 --- a/src/laws.c +++ b/src/laws.c @@ -430,7 +430,7 @@ static void horses(region * r) maxhorses = MAX(0, maxhorses); horses = rhorses(r); if (horses > 0) { - if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) { + if (is_cursed(r->attribs, &ct_godcursezone)) { rsethorses(r, (int)(horses * 0.9)); } else if (maxhorses) { @@ -583,7 +583,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) a_removeall(&r->attribs, &at_germs); } - if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) { + if (is_cursed(r->attribs, &ct_godcursezone)) { rsettrees(r, 1, (int)(rtrees(r, 1) * 0.9)); rsettrees(r, 2, (int)(rtrees(r, 2) * 0.9)); return; @@ -640,7 +640,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) } else if (current_season == SEASON_SPRING) { - if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) + if (is_cursed(r->attribs, &ct_godcursezone)) return; /* in at_germs merken uns die Zahl der Samen und Sprößlinge, die @@ -2924,11 +2924,13 @@ static void ageing(void) change_effect(u, oldpotiontype[P_BERSERK], -1 * MIN(u->number, i)); } - if (is_cursed(u->attribs, C_OLDRACE, 0)) { - 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; + if (u->attribs) { + curse * c = get_curse(u->attribs, &ct_oldrace); + if (c && curse_active(c)) { + if (c->duration == 1 && !(c_flags(c) & CURSE_NOAGE)) { + u_setrace(u, get_race(curse_geteffect_int(c))); + u->irace = NULL; + } } } } @@ -3789,7 +3791,7 @@ void process(void) } else if (u_race(u) == get_race(RC_INSECT) && r_insectstalled(r) - && !is_cursed(u->attribs, C_KAELTESCHUTZ, 0)) { + && !is_cursed(u->attribs, &ct_insectfur)) { ord = NULL; } else if (LongHunger(u)) { diff --git a/src/magic.c b/src/magic.c index 58222b6e7..dde298ed0 100644 --- a/src/magic.c +++ b/src/magic.c @@ -35,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include #include @@ -699,7 +700,7 @@ int max_spellpoints(const region * r, const unit * u) if (rtype && i_get(u->items, rtype->itype) > 0) { msp += use_item_aura(r, u); } - n = get_curseeffect(u->attribs, C_AURA, 0); + n = get_curseeffect(u->attribs, &ct_auraboost); if (n > 0) { msp = (msp * n) / 100; } @@ -1251,8 +1252,7 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus) } if (a) { - const struct curse_type *ct_resist = ct_find(oldcursename(C_RESIST_MAGIC)); - curse * c = get_curse(a, ct_resist); + curse * c = get_curse(a, &ct_magicrunes); int effect = curse_geteffect_int(c); prob = frac_add(prob, frac_make(effect, 100)); } @@ -1320,10 +1320,10 @@ bool fumble(region * r, unit * u, const spell * sp, int cast_grade) if (mage->magietyp == M_DRAIG) { fumble_chance += CHAOSPATZERCHANCE; } - if (is_cursed(u->attribs, C_MBOOST, 0)) { + if (is_cursed(u->attribs, &ct_magicboost)) { fumble_chance += CHAOSPATZERCHANCE; } - if (is_cursed(u->attribs, C_FUMBLE, 0)) { + if (is_cursed(u->attribs, &ct_fumble)) { fumble_chance += CHAOSPATZERCHANCE; } @@ -1503,7 +1503,7 @@ void regenerate_aura(void) reg_aura *= btype->auraregen; /* Bonus/Malus durch Zauber */ - mod = get_curseeffect(u->attribs, C_AURA, 0); + mod = get_curseeffect(u->attribs, &ct_auraboost); if (mod > 0) { reg_aura = (reg_aura * mod) / 100.0; } @@ -2795,7 +2795,7 @@ void magic(void) continue; if (u_race(u) == rc_insect && r_insectstalled(r) && - !is_cursed(u->attribs, C_KAELTESCHUTZ, 0)) + !is_cursed(u->attribs, &ct_insectfur)) continue; if (fval(u, UFL_WERE | UFL_LONGACTION)) { diff --git a/src/morale.c b/src/morale.c index 8b0a8c6ee..a8a7cc9d9 100644 --- a/src/morale.c +++ b/src/morale.c @@ -20,6 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "morale.h" +#include + #include #include #include @@ -53,7 +55,7 @@ void morale_update(region *r) { if (stability > MORALE_COOLDOWN && r->land->ownership->owner && morale < MORALE_MAX) { double ch = popularity(); - if (is_cursed(r->attribs, C_GENEROUS, 0)) { + if (is_cursed(r->attribs, &ct_generous)) { ch *= 1.2; /* 20% improvement */ } if (stability >= MORALE_AVERAGE * 2 || chance(ch)) { diff --git a/src/move.c b/src/move.c index de2aae7ae..33ed38126 100644 --- a/src/move.c +++ b/src/move.c @@ -34,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include /* attributes includes */ #include @@ -673,7 +674,7 @@ static bool is_freezing(const unit * u) { if (u_race(u) != get_race(RC_INSECT)) return false; - if (is_cursed(u->attribs, C_KAELTESCHUTZ, 0)) + if (is_cursed(u->attribs, &ct_insectfur)) return false; return true; } @@ -832,7 +833,7 @@ static void drifting_ships(region * r) } /* Schiff schon abgetrieben oder durch Zauber geschützt? */ - if (!drift || fval(sh, SF_DRIFTED) || is_cursed(sh->attribs, C_SHIP_NODRIFT, 0)) { + if (!drift || fval(sh, SF_DRIFTED) || is_cursed(sh->attribs, &ct_nodrift)) { shp = &sh->next; continue; } @@ -1803,7 +1804,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) } if (rng_int() % 10000 < stormchance * sh->type->storm && fval(current_point->terrain, SEA_REGION)) { - if (!is_cursed(sh->attribs, C_SHIP_NODRIFT, 0)) { + if (!is_cursed(sh->attribs, &ct_nodrift)) { region *rnext = NULL; bool storm = true; int d_offset = rng_int() % MAXDIRECTIONS; @@ -1920,9 +1921,10 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) last_point = current_point; current_point = next_point; - if (!fval(current_point->terrain, SEA_REGION) - && !is_cursed(sh->attribs, C_SHIP_FLYING, 0)) + if (!fval(next_point->terrain, SEA_REGION) + && !is_cursed(sh->attribs, &ct_flyingship)) { break; + } token = getstrtoken(); error = movewhere(u, token, current_point, &next_point); if (error || next_point == NULL) { @@ -1958,7 +1960,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) set_order(&u->thisorder, NULL); set_coast(sh, last_point, current_point); - if (is_cursed(sh->attribs, C_SHIP_FLYING, 0)) { + if (is_cursed(sh->attribs, &ct_flyingship)) { ADDMSG(&f->msgs, msg_message("shipfly", "ship from to", sh, starting_point, current_point)); } diff --git a/src/randenc.c b/src/randenc.c index c0daec72c..ba986ffe1 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -27,12 +27,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "chaos.h" #include "study.h" +#include +#include + /* attributes includes */ #include #include -#include - /* kernel includes */ #include #include @@ -651,7 +652,7 @@ static void godcurse(void) region *r; for (r = regions; r; r = r->next) { - if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) { + if (is_cursed(r->attribs, &ct_godcursezone)) { unit *u; for (u = r->units; u; u = u->next) { skill *sv = u->skills; diff --git a/src/report.c b/src/report.c index b86304ffc..4b462d9ff 100644 --- a/src/report.c +++ b/src/report.c @@ -29,6 +29,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "monsters.h" #include "travelthru.h" +#include +#include + /* modules includes */ #include @@ -46,8 +49,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "calendar.h" #include "teleport.h" -#include - /* kernel includes */ #include #include @@ -1187,7 +1188,7 @@ void report_region(struct stream *out, const region * r, faction * f) paragraph(out, buf, 0, 0, 0); if (r->seen.mode == seen_unit && is_astral(r) && - !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { + !is_cursed(r->attribs, &ct_astralblock)) { /* Sonderbehandlung Teleport-Ebene */ region_list *rl = astralregions(r, inhabitable); region_list *rl2; diff --git a/src/spells.c b/src/spells.c index 254546baa..734648204 100644 --- a/src/spells.c +++ b/src/spells.c @@ -1785,7 +1785,7 @@ static int sp_treewalkenter(castorder * co) } rt = r_standard_to_astral(r); - if (rt == NULL || is_cursed(rt->attribs, C_ASTRALBLOCK, 0) + if (rt == NULL || is_cursed(rt->attribs, &ct_astralblock) || fval(rt->terrain, FORBIDDEN_REGION)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_astralblock", "")); @@ -1901,7 +1901,7 @@ static int sp_treewalkexit(castorder * co) "spellfail_astralonly", "")); return 0; } - if (is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { + if (is_cursed(r->attribs, &ct_astralblock)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_astralblock", "")); return 0; @@ -2264,12 +2264,12 @@ static int sp_stormwinds(castorder * co) sh = pa->param[n]->data.sh; /* mit C_SHIP_NODRIFT haben wir kein Problem */ - if (is_cursed(sh->attribs, C_SHIP_FLYING, 0)) { + if (is_cursed(sh->attribs, &ct_flyingship)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "error_spell_on_flying_ship", "ship", sh)) continue; } - if (is_cursed(sh->attribs, C_SHIP_SPEEDUP, 0)) { + if (is_cursed(sh->attribs, &ct_shipspeedup)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "error_spell_on_ship_already", "ship", sh)) continue; @@ -2338,7 +2338,7 @@ static int sp_earthquake(castorder * co) while (*blist) { building *burg = *blist; - if (burg->size != 0 && !is_cursed(burg->attribs, C_MAGICWALLS, 0)) { + if (burg->size != 0 && !is_cursed(burg->attribs, &ct_magicwalls)) { /* Magieresistenz */ if (!target_resists_magic(mage, burg, TYP_BUILDING, 0)) { kaputt = MIN(10 * cast_level, burg->size / 4); @@ -2798,7 +2798,7 @@ static int sp_unholypower(castorder * co) * korrekt abgefangen wird. Besser (aber nicht gerade einfach) * waere es, eine solche Konstruktion irgendwie zu kapseln. */ if (fval(u, UFL_LOCKED) || fval(u, UFL_HUNGER) - || is_cursed(u->attribs, C_SLAVE, 0)) { + || is_cursed(u->attribs, &ct_slavery)) { cmistake(mage, co->order, 74, MSG_MAGIC); continue; } @@ -3186,7 +3186,7 @@ static int sp_chaossuction(castorder * co) cmistake(mage, co->order, 216, MSG_MAGIC); return 0; } - else if (is_cursed(rt->attribs, C_ASTRALBLOCK, 0)) { + else if (is_cursed(rt->attribs, &ct_astralblock)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_astralblock", "")); return 0; @@ -3233,7 +3233,7 @@ static int sp_magicboost(castorder * co) trigger *tsummon; /* fehler, wenn schon ein boost */ - if (is_cursed(mage->attribs, C_MBOOST, 0)) { + if (is_cursed(mage->attribs, &ct_magicboost)) { report_failure(mage, co->order); return 0; } @@ -3748,7 +3748,7 @@ static int sp_rallypeasantmob(castorder * co) } } - c = get_curse(r->attribs, ct_find(oldcursename(C_RIOT))); + c = get_curse(r->attribs, &ct_riotzone); if (c != NULL) { remove_curse(&r->attribs, c); } @@ -3964,7 +3964,7 @@ static int sp_generous(castorder * co) double effect; message *msg[2] = { NULL, NULL }; - if (is_cursed(r->attribs, C_DEPRESSION, 0)) { + if (is_cursed(r->attribs, &ct_depression)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_generous", "")); return 0; @@ -4662,7 +4662,29 @@ int sp_analysedream(castorder * co) return cast_level; } -static int sp_gbdreams(castorder * co, const char *curse_name, int effect); +static int sp_gbdreams(castorder * co, int effect) +{ + int duration; + unit *mage = co->magician.u; + int cast_level = co->level; + double power = co->force; + region *r = co_get_region(co); + + /* wirkt erst in der Folgerunde, soll mindestens eine Runde wirken, + * also duration+2 */ + duration = (int)MAX(1, power / 2); /* Stufe 1 macht sonst mist */ + duration = 2 + rng_int() % duration; + + /* Nichts machen als ein entsprechendes Attribut in die Region legen. */ + create_curse(mage, &r->attribs, &ct_gbdream, power, duration, effect, 0); + + /* Erfolg melden */ + ADDMSG(&mage->faction->msgs, msg_message("regionmagic_effect", + "unit region command", mage, mage->region, co->order)); + + return cast_level; +} + /* ------------------------------------------------------------- */ /* Name: Schlechte Traeume @@ -4679,7 +4701,7 @@ static int sp_gbdreams(castorder * co, const char *curse_name, int effect); * */ int sp_baddreams(castorder * co) { - return sp_gbdreams(co, "gbdream", -1); + return sp_gbdreams(co, -1); } /* ------------------------------------------------------------- */ @@ -4696,30 +4718,7 @@ int sp_baddreams(castorder * co) */ int sp_gooddreams(castorder * co) { - return sp_gbdreams(co, "gbdream", 1); -} - -static int sp_gbdreams(castorder * co, const char *curse_name, int effect) -{ - int duration; - unit *mage = co->magician.u; - int cast_level = co->level; - double power = co->force; - region *r = co_get_region(co); - - /* wirkt erst in der Folgerunde, soll mindestens eine Runde wirken, - * also duration+2 */ - duration = (int)MAX(1, power / 2); /* Stufe 1 macht sonst mist */ - duration = 2 + rng_int() % duration; - - /* Nichts machen als ein entsprechendes Attribut in die Region legen. */ - create_curse(mage, &r->attribs, ct_find(curse_name), power, duration, effect, 0); - - /* Erfolg melden */ - ADDMSG(&mage->faction->msgs, msg_message("regionmagic_effect", - "unit region command", mage, mage->region, co->order)); - - return cast_level; + return sp_gbdreams(co, 1); } /* ------------------------------------------------------------- */ @@ -5075,8 +5074,8 @@ int sp_enterastral(castorder * co) return 0; } - if (is_cursed(rt->attribs, C_ASTRALBLOCK, 0) - || is_cursed(ro->attribs, C_ASTRALBLOCK, 0)) { + if (is_cursed(rt->attribs, &ct_astralblock) + || is_cursed(ro->attribs, &ct_astralblock)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_astralblock", "")); return 0; @@ -5202,8 +5201,8 @@ int sp_pullastral(castorder * co) return 0; } - if (is_cursed(rt->attribs, C_ASTRALBLOCK, 0) - || is_cursed(ro->attribs, C_ASTRALBLOCK, 0)) { + if (is_cursed(rt->attribs, &ct_astralblock) + || is_cursed(ro->attribs, &ct_astralblock)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_astralblock", "")); return 0; @@ -5346,8 +5345,8 @@ int sp_leaveastral(castorder * co) return 0; } - if (ro == NULL || is_cursed(ro->attribs, C_ASTRALBLOCK, 0) - || is_cursed(rt->attribs, C_ASTRALBLOCK, 0)) { + if (ro == NULL || is_cursed(ro->attribs, &ct_astralblock) + || is_cursed(rt->attribs, &ct_astralblock)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_astralblock", "")); return 0; @@ -5486,7 +5485,7 @@ int sp_fetchastral(castorder * co) ro = u->region; } - if (is_cursed(ro->attribs, C_ASTRALBLOCK, 0)) { + if (is_cursed(ro->attribs, &ct_astralblock)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_astralblock", "")); continue; @@ -5599,7 +5598,7 @@ int sp_showastral(castorder * co) for (rl2 = rl; rl2; rl2 = rl2->next) { region *r2 = rl2->data; - if (!is_cursed(r2->attribs, C_ASTRALBLOCK, 0)) { + if (!is_cursed(r2->attribs, &ct_astralblock)) { for (u = r2->units; u; u = u->next) { if (u_race(u) != get_race(RC_SPECIAL) && u_race(u) != get_race(RC_SPELL)) n++; @@ -5619,7 +5618,7 @@ int sp_showastral(castorder * co) "Nebel zu erkennen sind ", unitname(mage)); for (rl2 = rl; rl2; rl2 = rl2->next) { - if (!is_cursed(rl2->data->attribs, C_ASTRALBLOCK, 0)) { + if (!is_cursed(rl2->data->attribs, &ct_astralblock)) { for (u = rl2->data->units; u; u = u->next) { if (u_race(u) != get_race(RC_SPECIAL) && u_race(u) != get_race(RC_SPELL)) { c++; @@ -5677,7 +5676,7 @@ int sp_viewreality(castorder * co) /* Irgendwann mal auf Curses u/o Attribut umstellen. */ for (rl2 = rl; rl2; rl2 = rl2->next) { region *rt = rl2->data; - if (!is_cursed(rt->attribs, C_ASTRALBLOCK, 0)) { + if (!is_cursed(rt->attribs, &ct_astralblock)) { u = create_unit(rt, mage->faction, 1, get_race(RC_SPELL), 0, "spell/viewreality", NULL); @@ -5735,7 +5734,7 @@ int sp_disruptastral(castorder * co) int inhab_regions = 0; region_list *trl = NULL; - if (is_cursed(r2->attribs, C_ASTRALBLOCK, 0)) + if (is_cursed(r2->attribs, &ct_astralblock)) continue; if (r2->units != NULL) { diff --git a/src/spells/flyingship.c b/src/spells/flyingship.c index c3fe63e73..e23f6906b 100644 --- a/src/spells/flyingship.c +++ b/src/spells/flyingship.c @@ -66,11 +66,11 @@ int sp_flying_ship(castorder * co) cno = levitate_ship(sh, mage, power, 1); if (cno == 0) { - if (is_cursed(sh->attribs, C_SHIP_FLYING, 0)) { + if (is_cursed(sh->attribs, &ct_flyingship)) { /* Auf dem Schiff befindet liegt bereits so ein Zauber. */ cmistake(mage, co->order, 211, MSG_MAGIC); } - else if (is_cursed(sh->attribs, C_SHIP_SPEEDUP, 0)) { + else if (is_cursed(sh->attribs, &ct_shipspeedup)) { /* Es ist zu gefaehrlich, ein sturmgepeitschtes Schiff fliegen zu lassen. */ cmistake(mage, co->order, 210, MSG_MAGIC); } @@ -127,7 +127,7 @@ static int flyingship_age(curse * c) return 0; } -static struct curse_type ct_flyingship = { "flyingship", +const struct curse_type ct_flyingship = { "flyingship", CURSETYP_NORM, 0, NO_MERGE, cinfo_ship, NULL, flyingship_read, flyingship_write, NULL, flyingship_age }; @@ -153,7 +153,7 @@ static curse *shipcurse_flyingship(ship * sh, unit * mage, double power, int dur if (curse_active(get_curse(sh->attribs, &ct_flyingship))) { return NULL; } - if (is_cursed(sh->attribs, C_SHIP_SPEEDUP, 0)) { + if (is_cursed(sh->attribs, &ct_shipspeedup)) { return NULL; } } diff --git a/src/spells/flyingship.h b/src/spells/flyingship.h index 52013ac13..4a03e6b71 100644 --- a/src/spells/flyingship.h +++ b/src/spells/flyingship.h @@ -12,6 +12,9 @@ extern "C" { struct castorder; struct ship; struct unit; + struct curse_type; + + extern const struct curse_type ct_flyingship; int sp_flying_ship(struct castorder * co); diff --git a/src/study.c b/src/study.c index 55bcd9b34..882a3040b 100644 --- a/src/study.c +++ b/src/study.c @@ -764,7 +764,7 @@ int study_cmd(unit * u, order * ord) teach->value += u->number * 10; } - if (is_cursed(r->attribs, C_BADLEARN, 0)) { + if (is_cursed(r->attribs, &ct_badlearn)) { teach->value -= u->number * 10; }