kill curse cache logic, it was a bad idea.

ct_find is almost never what we want to do.
This commit is contained in:
Enno Rehling 2017-08-21 19:43:35 +02:00
parent 134ff982ba
commit c99e92db20
19 changed files with 137 additions and 177 deletions

View File

@ -55,6 +55,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <attributes/otherfaction.h> #include <attributes/otherfaction.h>
#include <attributes/moved.h> #include <attributes/moved.h>
#include <spells/buildingcurse.h> #include <spells/buildingcurse.h>
#include <spells/regioncurse.h>
#include <spells/unitcurse.h>
/* util includes */ /* util includes */
#include <util/assert.h> #include <util/assert.h>
@ -138,15 +140,10 @@ static int rule_nat_armor;
static int rule_cavalry_mode; static int rule_cavalry_mode;
static int rule_vampire; static int rule_vampire;
static const curse_type *peace_ct, *slave_ct, *calm_ct;
/** initialize rules from configuration. /** initialize rules from configuration.
*/ */
static void init_rules(void) static void init_rules(void)
{ {
peace_ct = ct_find("peacezone");
slave_ct = ct_find("slavery");
calm_ct = ct_find("calmmonster");
rule_nat_armor = config_get_int("rules.combat.nat_armor", 0); rule_nat_armor = config_get_int("rules.combat.nat_armor", 0);
rule_tactics_formula = config_get_int("rules.tactics.formula", 0); rule_tactics_formula = config_get_int("rules.tactics.formula", 0);
rule_goblin_bonus = config_get_int("rules.combat.goblinbonus", 10); rule_goblin_bonus = config_get_int("rules.combat.goblinbonus", 10);
@ -1889,16 +1886,13 @@ int skilldiff(troop at, troop dt, int dist)
if (df->building) { if (df->building) {
building *b = df->building; building *b = df->building;
if (b->attribs) { if (b->attribs) {
const curse_type *strongwall_ct = ct_find("strongwall"); curse *c = get_curse(b->attribs, &ct_strongwall);
if (strongwall_ct) {
curse *c = get_curse(b->attribs, strongwall_ct);
if (curse_active(c)) { if (curse_active(c)) {
/* wirkt auf alle Geb<65>ude */ /* wirkt auf alle Geb<65>ude */
skdiff -= curse_geteffect_int(c); skdiff -= curse_geteffect_int(c);
is_protected = 2; is_protected = 2;
} }
} }
}
if (b->type->flags & BTF_FORTIFICATION) { if (b->type->flags & BTF_FORTIFICATION) {
int stage = buildingeffsize(b, false); int stage = buildingeffsize(b, false);
int beff = building_protection(b->type, stage); int beff = building_protection(b->type, stage);
@ -3173,16 +3167,12 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
/* Effekte von Spr<70>chen */ /* Effekte von Spr<70>chen */
if (u->attribs) { if (u->attribs) {
const curse_type *speed_ct; curse *c = get_curse(u->attribs, &ct_speed);
speed_ct = ct_find("speed");
if (speed_ct) {
curse *c = get_curse(u->attribs, speed_ct);
if (c) { if (c) {
speeded = get_cursedmen(u, c); speeded = get_cursedmen(u, c);
speed = curse_geteffect_int(c); speed = curse_geteffect_int(c);
} }
} }
}
/* Effekte von Alchemie */ /* Effekte von Alchemie */
berserk = get_effect(u, oldpotiontype[P_BERSERK]); berserk = get_effect(u, oldpotiontype[P_BERSERK]);
@ -3748,6 +3738,21 @@ static void flee(const troop dt)
kill_troop(dt); kill_troop(dt);
} }
static bool is_calmed(const unit *u, const faction *f) {
attrib *a = a_find(u->attribs, &at_curse);
while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v;
if (c->type == &ct_calmmonster && curse_geteffect_int(c) == f->subscription) {
if (curse_active(c)) {
return true;
}
}
a = a->next;
}
return false;
}
static bool start_battle(region * r, battle ** bp) static bool start_battle(region * r, battle ** bp)
{ {
battle *b = NULL; battle *b = NULL;
@ -3794,12 +3799,12 @@ static bool start_battle(region * r, battle ** bp)
if (fval(u, UFL_LONGACTION)) if (fval(u, UFL_LONGACTION))
continue; continue;
if (peace_ct && curse_active(get_curse(r->attribs, peace_ct))) { if (curse_active(get_curse(r->attribs, &ct_peacezone))) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "peace_active", "")); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "peace_active", ""));
continue; continue;
} }
if (slave_ct && curse_active(get_curse(u->attribs, slave_ct))) { if (curse_active(get_curse(u->attribs, &ct_slavery))) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "slave_active", "")); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "slave_active", ""));
continue; continue;
} }
@ -3847,27 +3852,12 @@ static bool start_battle(region * r, battle ** bp)
NewbieImmunity())); NewbieImmunity()));
continue; continue;
} }
/* Fehler: "Die Einheit ist mit uns alliert" */
if (calm_ct) { /* Fehler: "Die Einheit ist mit uns alliert" */
attrib *a = a_find(u->attribs, &at_curse); if (is_calmed(u, u2->faction)) {
bool calm = false;
while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v;
if (c->type == calm_ct
&& curse_geteffect_int(c) == u2->faction->subscription) {
if (curse_active(c)) {
calm = true;
break;
}
}
a = a->next;
}
if (calm) {
cmistake(u, ord, 47, MSG_BATTLE); cmistake(u, ord, 47, MSG_BATTLE);
continue; continue;
} }
}
/* Ende Fehlerbehandlung */ /* Ende Fehlerbehandlung */
if (b == NULL) { if (b == NULL) {
unit *utmp; unit *utmp;

View File

@ -466,11 +466,9 @@ static void test_battle_skilldiff_building(CuTest *tc)
unit *ua, *ud; unit *ua, *ud;
battle *b = NULL; battle *b = NULL;
building_type *btype; building_type *btype;
const curse_type *strongwall_ct;
test_setup(); test_setup();
btype = setup_castle(); btype = setup_castle();
strongwall_ct = ct_find("strongwall");
r = test_create_region(0, 0, 0); r = test_create_region(0, 0, 0);
ud = test_create_unit(test_create_faction(0), r); ud = test_create_unit(test_create_faction(0), r);
@ -489,7 +487,7 @@ static void test_battle_skilldiff_building(CuTest *tc)
create_curse(NULL, &ud->building->attribs, &ct_magicwalls, 1, 1, 1, 1); create_curse(NULL, &ud->building->attribs, &ct_magicwalls, 1, 1, 1, 1);
CuAssertIntEquals(tc, -2, skilldiff(ta, td, 0)); CuAssertIntEquals(tc, -2, skilldiff(ta, td, 0));
create_curse(NULL, &ud->building->attribs, strongwall_ct, 1, 1, 2, 1); create_curse(NULL, &ud->building->attribs, &ct_strongwall, 1, 1, 2, 1);
CuAssertIntEquals(tc, -4, skilldiff(ta, td, 0)); CuAssertIntEquals(tc, -4, skilldiff(ta, td, 0));
free_battle(b); free_battle(b);

View File

@ -69,6 +69,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <attributes/reduceproduction.h> #include <attributes/reduceproduction.h>
#include <attributes/racename.h> #include <attributes/racename.h>
#include <spells/buildingcurse.h>
/* libs includes */ /* libs includes */
#include <math.h> #include <math.h>
@ -728,13 +729,12 @@ static int maintain(building * b)
void maintain_buildings(region * r) void maintain_buildings(region * r)
{ {
const curse_type *nocost_ct = ct_find("nocostbuilding");
building **bp = &r->buildings; building **bp = &r->buildings;
while (*bp) { while (*bp) {
building *b = *bp; building *b = *bp;
int flags = BLD_MAINTAINED; int flags = BLD_MAINTAINED;
if (!curse_active(get_curse(b->attribs, nocost_ct))) { if (!curse_active(get_curse(b->attribs, &ct_nocostbuilding))) {
flags = maintain(b); flags = maintain(b);
} }
fset(b, flags); fset(b, flags);

View File

@ -56,6 +56,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* attributes includes */ /* attributes includes */
#include <attributes/reduceproduction.h> #include <attributes/reduceproduction.h>
#include <spells/regioncurse.h>
typedef struct building_typelist { typedef struct building_typelist {
struct building_typelist *next; struct building_typelist *next;
@ -679,12 +680,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn)
building *b = largestbuilding(r, cmp_wage, false); building *b = largestbuilding(r, cmp_wage, false);
int esize = 0; int esize = 0;
double wage; double wage;
static int ct_cache;
static const struct curse_type *drought_ct;
if (ct_changed(&ct_cache)) {
drought_ct = ct_find("drought");
}
if (b != NULL) { if (b != NULL) {
/* TODO: this reveals imaginary castles */ /* TODO: this reveals imaginary castles */
esize = buildingeffsize(b, false); esize = buildingeffsize(b, false);
@ -709,23 +705,23 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn)
} }
if (r->attribs && rule_blessed_harvest() == HARVEST_WORK) { if (r->attribs && rule_blessed_harvest() == HARVEST_WORK) {
/* E1 rules */ /* E1 rules */
wage += curse_geteffect(get_curse(r->attribs, ct_find("blessedharvest"))); wage += curse_geteffect(get_curse(r->attribs, &ct_blessedharvest));
} }
} }
if (r->attribs) { if (r->attribs) {
attrib *a; attrib *a;
const struct curse_type *ctype; curse *c;
/* Godcurse: Income -10 */ /* Godcurse: Income -10 */
ctype = ct_find("godcursezone"); c = get_curse(r->attribs, &ct_godcursezone);
if (ctype && curse_active(get_curse(r->attribs, ctype))) { if (c && curse_active(c)) {
wage = MAX(0, wage - 10); wage = MAX(0, wage - 10);
} }
/* Bei einer D<>rre verdient man nur noch ein Viertel */ /* Bei einer D<>rre verdient man nur noch ein Viertel */
if (drought_ct) { c = get_curse(r->attribs, &ct_drought);
curse *c = get_curse(r->attribs, drought_ct); if (c && curse_active(c)) {
if (curse_active(c))
wage /= curse_geteffect(c); wage /= curse_geteffect(c);
} }

View File

@ -284,17 +284,6 @@ attrib_type at_curse = {
#define MAXCTHASH 128 #define MAXCTHASH 128
static selist *cursetypes[MAXCTHASH]; static selist *cursetypes[MAXCTHASH];
static int ct_changes = 1;
bool ct_changed(int *cache)
{
assert(cache);
if (*cache != ct_changes) {
*cache = ct_changes;
return true;
}
return false;
}
void ct_register(const curse_type * ct) void ct_register(const curse_type * ct)
{ {
@ -304,7 +293,6 @@ void ct_register(const curse_type * ct)
assert(ct->age==NULL || (ct->flags&CURSE_NOAGE) == 0); assert(ct->age==NULL || (ct->flags&CURSE_NOAGE) == 0);
assert((ct->flags&CURSE_ISNEW) == 0); assert((ct->flags&CURSE_ISNEW) == 0);
selist_set_insert(ctlp, (void *)ct, NULL); selist_set_insert(ctlp, (void *)ct, NULL);
++ct_changes;
} }
void ct_remove(const char *c) void ct_remove(const char *c)
@ -320,7 +308,6 @@ void ct_remove(const char *c)
if (strcmp(c, type->cname) == 0) { if (strcmp(c, type->cname) == 0) {
selist_delete(&ctl, qi); selist_delete(&ctl, qi);
++ct_changes;
break; break;
} }
} }
@ -845,5 +832,4 @@ void curses_done(void) {
selist_free(cursetypes[i]); selist_free(cursetypes[i]);
cursetypes[i] = 0; cursetypes[i] = 0;
} }
++ct_changes;
} }

View File

@ -285,7 +285,6 @@ extern "C" {
struct curse *get_curse(struct attrib *ap, const curse_type * ctype); struct curse *get_curse(struct attrib *ap, const curse_type * ctype);
const curse_type *ct_find(const char *c); const curse_type *ct_find(const char *c);
bool ct_changed(int *cache);
void ct_register(const curse_type *); void ct_register(const curse_type *);
void ct_remove(const char *c); void ct_remove(const char *c);
void ct_checknames(void); void ct_checknames(void);

View File

@ -159,24 +159,6 @@ static void test_write_flag(CuTest *tc) {
cleanup_curse(&fix); cleanup_curse(&fix);
} }
static void test_curse_cache(CuTest *tc)
{
int cache = 0;
const curse_type ct_dummy = { "dummy", CURSETYP_NORM, 0, M_SUMEFFECT, NULL };
test_setup();
CuAssertIntEquals(tc, true, ct_changed(&cache));
CuAssertIntEquals(tc, false, ct_changed(&cache));
CuAssertPtrEquals(tc, NULL, (void *)ct_find(ct_dummy.cname));
ct_register(&ct_dummy);
CuAssertIntEquals(tc, true, ct_changed(&cache));
CuAssertPtrEquals(tc, (void *)&ct_dummy, (void *)ct_find(ct_dummy.cname));
ct_remove(ct_dummy.cname);
CuAssertIntEquals(tc, true, ct_changed(&cache));
CuAssertIntEquals(tc, false, ct_changed(&cache));
CuAssertPtrEquals(tc, NULL, (void *)ct_find(ct_dummy.cname));
test_cleanup();
}
static void test_curse_ids(CuTest *tc) { static void test_curse_ids(CuTest *tc) {
const curse_type ct_dummy = { "dummy", CURSETYP_NORM, 0, M_SUMEFFECT, NULL }; const curse_type ct_dummy = { "dummy", CURSETYP_NORM, 0, M_SUMEFFECT, NULL };
curse *c1, *c2; curse *c1, *c2;
@ -218,7 +200,6 @@ CuSuite *get_curse_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_curse); SUITE_ADD_TEST(suite, test_curse);
SUITE_ADD_TEST(suite, test_curse_cache);
SUITE_ADD_TEST(suite, test_magicstreet); SUITE_ADD_TEST(suite, test_magicstreet);
SUITE_ADD_TEST(suite, test_magicstreet_warning); SUITE_ADD_TEST(suite, test_magicstreet_warning);
SUITE_ADD_TEST(suite, test_good_dreams); SUITE_ADD_TEST(suite, test_good_dreams);

View File

@ -37,6 +37,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "terrainid.h" #include "terrainid.h"
#include "unit.h" #include "unit.h"
#include <spells/regioncurse.h>
/* util includes */ /* util includes */
#include <util/assert.h> #include <util/assert.h>
#include <util/attrib.h> #include <util/attrib.h>
@ -1241,8 +1243,9 @@ int production(const region * r)
{ {
/* muß rterrain(r) sein, nicht rterrain() wegen rekursion */ /* muß rterrain(r) sein, nicht rterrain() wegen rekursion */
int p = r->terrain->size; int p = r->terrain->size;
if (curse_active(get_curse(r->attribs, ct_find("drought")))) if (curse_active(get_curse(r->attribs, &ct_drought))) {
p /= 2; p /= 2;
}
return p; return p;
} }

View File

@ -43,6 +43,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <attributes/racename.h> #include <attributes/racename.h>
#include <attributes/stealth.h> #include <attributes/stealth.h>
#include <spells/unitcurse.h>
#include <spells/regioncurse.h>
#include "guard.h" #include "guard.h"
/* util includes */ /* util includes */
@ -1268,39 +1271,33 @@ static int att_modification(const unit * u, skill_t sk)
if (u->attribs) { if (u->attribs) {
curse *c; curse *c;
static int cache; attrib *a;
static const curse_type *skillmod_ct, *worse_ct;
if (ct_changed(&cache)) { c = get_curse(u->attribs, &ct_worse);
skillmod_ct = ct_find("skillmod"); if (c != NULL) {
worse_ct = ct_find("worse");
}
c = get_curse(u->attribs, worse_ct);
if (c != NULL)
result += curse_geteffect(c); result += curse_geteffect(c);
if (skillmod_ct) { }
attrib *a = a_find(u->attribs, &at_curse);
a = a_find(u->attribs, &at_curse);
while (a && a->type == &at_curse) { while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v; c = (curse *)a->data.v;
if (c->type == skillmod_ct && c->data.i == sk) { if (c->type == &ct_skillmod && c->data.i == sk) {
result += curse_geteffect(c); result += curse_geteffect(c);
break; break;
} }
a = a->next; a = a->next;
} }
} }
}
/* TODO hier kann nicht mit get/iscursed gearbeitet werden, da nur der /* TODO hier kann nicht mit get/iscursed gearbeitet werden, da nur der
* jeweils erste vom Typ C_GBDREAM zurueckgegen wird, wir aber alle * jeweils erste vom Typ C_GBDREAM zurueckgegen wird, wir aber alle
* durchsuchen und aufaddieren muessen */ * durchsuchen und aufaddieren muessen */
if (u->region && u->region->attribs) { if (u->region && u->region->attribs) {
const curse_type *gbdream_ct = ct_find("gbdream");
if (gbdream_ct) {
int bonus = 0, malus = 0; int bonus = 0, malus = 0;
attrib *a = a_find(u->region->attribs, &at_curse); attrib *a = a_find(u->region->attribs, &at_curse);
while (a && a->type == &at_curse) { while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v; curse *c = (curse *)a->data.v;
if (c->magician && curse_active(c) && c->type == gbdream_ct) { if (c->magician && curse_active(c) && c->type == &ct_gbdream) {
int effect = curse_geteffect_int(c); int effect = curse_geteffect_int(c);
bool allied = alliedunit(c->magician, u->faction, HELP_GUARD); bool allied = alliedunit(c->magician, u->faction, HELP_GUARD);
if (allied) { if (allied) {
@ -1314,7 +1311,6 @@ static int att_modification(const unit * u, skill_t sk)
} }
result = result + bonus + malus; result = result + bonus + malus;
} }
}
return (int)result; return (int)result;
} }
@ -1738,18 +1734,11 @@ int unit_max_hp(const unit * u)
/* der healing curse veraendert die maximalen hp */ /* der healing curse veraendert die maximalen hp */
if (u->region && u->region->attribs) { if (u->region && u->region->attribs) {
static int cache; curse *c = get_curse(u->region->attribs, &ct_healing);
static const curse_type *heal_ct;
if (ct_changed(&cache)) {
heal_ct = ct_find("healingzone");
}
if (heal_ct) {
curse *c = get_curse(u->region->attribs, heal_ct);
if (c) { if (c) {
h = (int)(h * (1.0 + (curse_geteffect(c) / 100))); h = (int)(h * (1.0 + (curse_geteffect(c) / 100)));
} }
} }
}
return h; return h;
} }

View File

@ -50,6 +50,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h> #include <kernel/unit.h>
#include <spells/flyingship.h> #include <spells/flyingship.h>
#include <spells/unitcurse.h>
#include "teleport.h" #include "teleport.h"
#include "direction.h" #include "direction.h"
@ -1415,15 +1416,12 @@ static int movement_speed(unit * u)
} }
if (u->attribs) { if (u->attribs) {
const curse_type *speed_ct = ct_find("speed"); curse *c = get_curse(u->attribs, &ct_speed);
if (speed_ct) {
curse *c = get_curse(u->attribs, speed_ct);
if (c != NULL) { if (c != NULL) {
int men = get_cursedmen(u, c); int men = get_cursedmen(u, c);
dk *= 1.0 + (double)men / (double)u->number; dk *= 1.0 + (double)men / (double)u->number;
} }
} }
}
switch (canride(u)) { switch (canride(u)) {
case 1: /* Pferd */ case 1: /* Pferd */

View File

@ -72,6 +72,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/alliance.h> #include <kernel/alliance.h>
#include <spells/buildingcurse.h>
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h> #include <util/base36.h>
@ -1390,7 +1392,6 @@ report_template(const char *filename, report_context * ctx, const char *bom)
char buf[8192], *bufp; char buf[8192], *bufp;
size_t size; size_t size;
int bytes; int bytes;
const curse_type *nocost_ct = ct_find("nocostbuilding");
if (F == NULL) { if (F == NULL) {
perror(filename); perror(filename);
@ -1459,7 +1460,7 @@ report_template(const char *filename, report_context * ctx, const char *bom)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (u->building && building_owner(u->building) == u) { if (u->building && building_owner(u->building) == u) {
building *b = u->building; building *b = u->building;
if (!curse_active(get_curse(b->attribs, nocost_ct))) { if (!curse_active(get_curse(b->attribs, &ct_nocostbuilding))) {
int cost = buildingmaintenance(b, rsilver); int cost = buildingmaintenance(b, rsilver);
if (cost > 0) { if (cost > 0) {
bytes = (int)strlcpy(bufp, ",U", size); bytes = (int)strlcpy(bufp, ",U", size);

View File

@ -1659,7 +1659,7 @@ static int sp_great_drought(castorder * co)
/* Arbeitslohn = 1/4 */ /* Arbeitslohn = 1/4 */
effect = 4.0; /* curses: higher is stronger */ effect = 4.0; /* curses: higher is stronger */
create_curse(mage, &r->attribs, ct_find("drought"), force, duration, effect, create_curse(mage, &r->attribs, &ct_drought, force, duration, effect,
0); 0);
/* terraforming */ /* terraforming */
@ -2141,7 +2141,7 @@ static int sp_drought(castorder * co)
* hoch (evtl dauert dann die Duerre laenger). Ansonsten volle * hoch (evtl dauert dann die Duerre laenger). Ansonsten volle
* Auswirkungen. * Auswirkungen.
*/ */
c = get_curse(r->attribs, ct_find("drought")); c = get_curse(r->attribs, &ct_drought);
if (c) { if (c) {
c->vigour = MAX(c->vigour, power); c->vigour = MAX(c->vigour, power);
c->duration = MAX(c->duration, (int)power); c->duration = MAX(c->duration, (int)power);
@ -2154,7 +2154,7 @@ static int sp_drought(castorder * co)
rsettrees(r, 0, rtrees(r, 0) / 2); rsettrees(r, 0, rtrees(r, 0) / 2);
rsethorses(r, rhorses(r) / 2); rsethorses(r, rhorses(r) / 2);
create_curse(mage, &r->attribs, ct_find("drought"), power, duration, effect, create_curse(mage, &r->attribs, &ct_drought, power, duration, effect,
0); 0);
} }
return cast_level; return cast_level;
@ -3647,7 +3647,7 @@ static int sp_charmingsong(castorder * co)
add_trigger(&mage->faction->attribs, "destroy", trigger_killunit(target)); add_trigger(&mage->faction->attribs, "destroy", trigger_killunit(target));
} }
/* sperre ATTACKIERE, GIB PERSON und ueberspringe Migranten */ /* sperre ATTACKIERE, GIB PERSON und ueberspringe Migranten */
create_curse(mage, &target->attribs, ct_find("slavery"), force, duration, zero_effect, 0); create_curse(mage, &target->attribs, &ct_slavery, force, duration, zero_effect, 0);
/* setze Partei um und loesche langen Befehl aus Sicherheitsgruenden */ /* setze Partei um und loesche langen Befehl aus Sicherheitsgruenden */
u_setfaction(target, mage->faction); u_setfaction(target, mage->faction);
@ -3921,7 +3921,7 @@ static int sp_song_of_peace(castorder * co)
int duration = 2 + lovar(force / 2); int duration = 2 + lovar(force / 2);
message *msg[2] = { NULL, NULL }; message *msg[2] = { NULL, NULL };
create_curse(mage, &r->attribs, ct_find("peacezone"), force, duration, create_curse(mage, &r->attribs, &ct_peacezone, force, duration,
zero_effect, 0); zero_effect, 0);
for (u = r->units; u; u = u->next) for (u = r->units; u; u = u->next)
@ -4295,7 +4295,7 @@ static int sp_calm_monster(castorder * co)
} }
effect = mage->faction->subscription; effect = mage->faction->subscription;
c = create_curse(mage, &target->attribs, ct_find("calmmonster"), force, c = create_curse(mage, &target->attribs, &ct_calmmonster, force,
(int)force, effect, 0); (int)force, effect, 0);
if (c == NULL) { if (c == NULL) {
report_failure(mage, co->order); report_failure(mage, co->order);
@ -5829,7 +5829,7 @@ static int sp_eternizewall(castorder * co)
return 0; return 0;
b = pa->param[0]->data.b; b = pa->param[0]->data.b;
c = create_curse(mage, &b->attribs, ct_find("nocostbuilding"), c = create_curse(mage, &b->attribs, &ct_nocostbuilding,
power * power, 1, zero_effect, 0); power * power, 1, zero_effect, 0);
if (c == NULL) { /* ist bereits verzaubert */ if (c == NULL) { /* ist bereits verzaubert */
@ -6167,7 +6167,7 @@ static int sp_magicrunes(castorder * co)
b = pa->param[0]->data.b; b = pa->param[0]->data.b;
/* Magieresistenz der Burg erhoeht sich um 20% */ /* Magieresistenz der Burg erhoeht sich um 20% */
create_curse(mage, &b->attribs, ct_find("magicrunes"), force, create_curse(mage, &b->attribs, &ct_magicrunes, force,
duration, effect, 0); duration, effect, 0);
/* Erfolg melden */ /* Erfolg melden */
@ -6181,7 +6181,7 @@ static int sp_magicrunes(castorder * co)
ship *sh; ship *sh;
sh = pa->param[0]->data.sh; sh = pa->param[0]->data.sh;
/* Magieresistenz des Schiffs erhoeht sich um 20% */ /* Magieresistenz des Schiffs erhoeht sich um 20% */
create_curse(mage, &sh->attribs, ct_find("magicrunes"), force, create_curse(mage, &sh->attribs, &ct_magicrunes, force,
duration, effect, 0); duration, effect, 0);
/* Erfolg melden */ /* Erfolg melden */
@ -6233,7 +6233,7 @@ int sp_speed2(castorder * co)
men = MIN(maxmen, u->number); men = MIN(maxmen, u->number);
effect = 2; effect = 2;
create_curse(mage, &u->attribs, ct_find("speed"), force, dur, effect, men); create_curse(mage, &u->attribs, &ct_speed, force, dur, effect, men);
maxmen -= men; maxmen -= men;
used += men; used += men;
} }

View File

@ -70,7 +70,7 @@ static message *cinfo_magicrunes(const void *obj, objtype_t typ, const curse * c
return msg; return msg;
} }
static struct curse_type ct_magicrunes = { "magicrunes", const struct curse_type ct_magicrunes = { "magicrunes",
CURSETYP_NORM, 0, M_SUMEFFECT, cinfo_magicrunes CURSETYP_NORM, 0, M_SUMEFFECT, cinfo_magicrunes
}; };
@ -80,12 +80,12 @@ CURSETYP_NORM, CURSE_ONLYONE|CURSE_NOAGE, NO_MERGE, cinfo_building
}; };
/* Feste Mauer - Präkampfzauber, wirkt nur 1 Runde */ /* Feste Mauer - Präkampfzauber, wirkt nur 1 Runde */
static struct curse_type ct_strongwall = { "strongwall", const struct curse_type ct_strongwall = { "strongwall",
CURSETYP_NORM, 0, NO_MERGE, NULL CURSETYP_NORM, 0, NO_MERGE, NULL
}; };
/* Ewige Mauern-Zauber */ /* Ewige Mauern-Zauber */
static struct curse_type ct_nocostbuilding = { "nocostbuilding", const struct curse_type ct_nocostbuilding = { "nocostbuilding",
CURSETYP_NORM, CURSE_NOAGE | CURSE_ONLYONE, NO_MERGE, cinfo_building CURSETYP_NORM, CURSE_NOAGE | CURSE_ONLYONE, NO_MERGE, cinfo_building
}; };

View File

@ -24,6 +24,9 @@ extern "C" {
struct curse_type; struct curse_type;
extern const struct curse_type ct_magicwalls; extern const struct curse_type ct_magicwalls;
extern const struct curse_type ct_strongwall;
extern const struct curse_type ct_magicrunes;
extern const struct curse_type ct_nocostbuilding;
extern void register_buildingcurse(void); extern void register_buildingcurse(void);
struct message *cinfo_building(const void *obj, objtype_t typ, const struct curse * c, int self); struct message *cinfo_building(const void *obj, objtype_t typ, const struct curse * c, int self);

View File

@ -27,6 +27,8 @@
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/terrain.h> #include <kernel/terrain.h>
#include <spells/buildingcurse.h>
#include <guard.h> #include <guard.h>
#include <battle.h> #include <battle.h>
#include <move.h> #include <move.h>
@ -879,7 +881,7 @@ int sp_strong_wall(struct castorder * co)
burg = mage->building; burg = mage->building;
effect = power / 4; effect = power / 4;
create_curse(mage, &burg->attribs, ct_find("strongwall"), power, 1, effect, 0); create_curse(mage, &burg->attribs, &ct_strongwall, power, 1, effect, 0);
msg = msg =
msg_message("sp_strongwalls_effect", "mage building", mage, mage->building); msg_message("sp_strongwalls_effect", "mage building", mage, mage->building);

View File

@ -55,7 +55,7 @@ static message *cinfo_cursed_by_the_gods(const void *obj, objtype_t typ,
return msg_message("curseinfo::godcurse", "id", c->no); return msg_message("curseinfo::godcurse", "id", c->no);
} }
static struct curse_type ct_godcursezone = { const struct curse_type ct_godcursezone = {
"godcursezone", "godcursezone",
CURSETYP_NORM, CURSE_IMMUNE, (NO_MERGE), CURSETYP_NORM, CURSE_IMMUNE, (NO_MERGE),
cinfo_cursed_by_the_gods, cinfo_cursed_by_the_gods,
@ -81,7 +81,7 @@ static message *cinfo_dreamcurse(const void *obj, objtype_t typ, const curse * c
} }
} }
static struct curse_type ct_gbdream = { const struct curse_type ct_gbdream = {
"gbdream", "gbdream",
CURSETYP_NORM, 0, (NO_MERGE), cinfo_dreamcurse CURSETYP_NORM, 0, (NO_MERGE), cinfo_dreamcurse
}; };
@ -200,13 +200,13 @@ static struct curse_type ct_maelstrom = {
cinfo_simple cinfo_simple
}; };
static struct curse_type ct_blessedharvest = { const struct curse_type ct_blessedharvest = {
"blessedharvest", "blessedharvest",
CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR),
cinfo_simple cinfo_simple
}; };
static struct curse_type ct_drought = { const struct curse_type ct_drought = {
"drought", "drought",
CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR),
cinfo_simple cinfo_simple
@ -240,7 +240,7 @@ static struct curse_type ct_generous = {
}; };
/* verhindert Attackiere regional */ /* verhindert Attackiere regional */
static struct curse_type ct_peacezone = { const struct curse_type ct_peacezone = {
"peacezone", "peacezone",
CURSETYP_NORM, 0, NO_MERGE, CURSETYP_NORM, 0, NO_MERGE,
cinfo_simple cinfo_simple
@ -274,7 +274,7 @@ static struct curse_type ct_holyground = {
cinfo_simple cinfo_simple
}; };
static struct curse_type ct_healing = { const struct curse_type ct_healing = {
"healingzone", "healingzone",
CURSETYP_NORM, 0, (M_VIGOUR | M_DURATION), CURSETYP_NORM, 0, (M_VIGOUR | M_DURATION),
cinfo_simple cinfo_simple

View File

@ -17,10 +17,16 @@
extern "C" { extern "C" {
#endif #endif
struct curse; struct curse_type;
struct locale;
extern void register_regioncurse(void); extern const struct curse_type ct_peacezone;
extern const struct curse_type ct_drought;
extern const struct curse_type ct_blessedharvest;
extern const struct curse_type ct_godcursezone;
extern const struct curse_type ct_gbdream;
extern const struct curse_type ct_healing;
void register_regioncurse(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -92,7 +92,7 @@ static message *cinfo_slave(const void *obj, objtype_t typ, const curse * c,
return NULL; return NULL;
} }
static struct curse_type ct_slavery = { "slavery", const struct curse_type ct_slavery = { "slavery",
CURSETYP_NORM, 0, NO_MERGE, CURSETYP_NORM, 0, NO_MERGE,
cinfo_slave cinfo_slave
}; };
@ -120,7 +120,7 @@ static message *cinfo_calm(const void *obj, objtype_t typ, const curse * c,
return NULL; return NULL;
} }
static struct curse_type ct_calmmonster = { const struct curse_type ct_calmmonster = {
"calmmonster", "calmmonster",
CURSETYP_NORM, CURSE_SPREADNEVER | CURSE_ONLYONE, NO_MERGE, CURSETYP_NORM, CURSE_SPREADNEVER | CURSE_ONLYONE, NO_MERGE,
cinfo_calm cinfo_calm
@ -144,7 +144,7 @@ static message *cinfo_speed(const void *obj, objtype_t typ, const curse * c,
return NULL; return NULL;
} }
static struct curse_type ct_speed = { const struct curse_type ct_speed = {
"speed", "speed",
CURSETYP_UNIT, CURSE_SPREADNEVER, M_MEN, CURSETYP_UNIT, CURSE_SPREADNEVER, M_MEN,
cinfo_speed cinfo_speed
@ -275,7 +275,7 @@ CURSETYP_UNIT, CURSE_SPREADMODULO, M_MEN, cinfo_simple
/* /*
* C_ALLSKILLS (Alp) * C_ALLSKILLS (Alp)
*/ */
static struct curse_type ct_worse = { const struct curse_type ct_worse = {
"worse", CURSETYP_UNIT, CURSE_SPREADMODULO | CURSE_NOAGE, M_MEN, cinfo_unit "worse", CURSETYP_UNIT, CURSE_SPREADMODULO | CURSE_NOAGE, M_MEN, cinfo_unit
}; };
@ -339,7 +339,7 @@ static message *cinfo_skillmod(const void *obj, objtype_t typ, const curse * c,
return NULL; return NULL;
} }
static struct curse_type ct_skillmod = { const struct curse_type ct_skillmod = {
"skillmod", CURSETYP_NORM, CURSE_SPREADMODULO, M_MEN, cinfo_skillmod, "skillmod", CURSETYP_NORM, CURSE_SPREADMODULO, M_MEN, cinfo_skillmod,
NULL, read_skill, write_skill NULL, read_skill, write_skill
}; };

View File

@ -20,8 +20,16 @@ extern "C" {
#endif #endif
struct curse; struct curse;
struct curse_type;
struct message; struct message;
extern struct message *cinfo_unit(const void *obj, objtype_t typ,
extern const struct curse_type ct_slavery;
extern const struct curse_type ct_calmmonster;
extern const struct curse_type ct_speed;
extern const struct curse_type ct_worse;
extern const struct curse_type ct_skillmod;
struct message *cinfo_unit(const void *obj, objtype_t typ,
const struct curse *c, int self); const struct curse *c, int self);
extern void register_unitcurse(void); extern void register_unitcurse(void);