From ee02721c21def677cfbd5ef805f39f921628a25d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 9 Nov 2015 13:36:52 +0100 Subject: [PATCH] fix and tests for otherfaction attributes in E2 https://bugs.eressea.de/view.php?id=2152 --- conf/e3/config.json | 2 +- conf/e4/config.json | 2 +- src/attributes/CMakeLists.txt | 1 + src/attributes/otherfaction.c | 6 +----- src/attributes/stealth.test.c | 5 ++--- src/give.test.c | 4 ++-- src/kernel/config.c | 24 ++++++++++++++++++------ src/kernel/config.h | 9 ++++----- src/kernel/faction.c | 10 +++++----- src/kernel/save.c | 2 +- src/spells.c | 6 +++--- src/spy.c | 11 +++-------- src/test_eressea.c | 1 + 13 files changed, 43 insertions(+), 40 deletions(-) diff --git a/conf/e3/config.json b/conf/e3/config.json index 421a962a7..a6685a06f 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -57,7 +57,7 @@ "rules.owners.force_leave": false, "rules.monsters.attack_chance": 0.1, "rules.transfermen": false, - "rules.stealth.faction": true, + "stealth.faction.other": false, "rules.stealth.anon_battle": false, "rules.check_overload": false, "rules.combat.goblinbonus": 3, diff --git a/conf/e4/config.json b/conf/e4/config.json index ffa11443c..90c60d72b 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -55,7 +55,7 @@ "rules.reserve.twophase": true, "rules.owners.force_leave": false, "rules.transfermen": false, - "rules.stealth.faction": true, + "stealth.faction.other": false, "rules.stealth.anon_battle": false, "rules.check_overload": false, "rules.combat.goblinbonus": 3, diff --git a/src/attributes/CMakeLists.txt b/src/attributes/CMakeLists.txt index b095f2abb..954f55443 100644 --- a/src/attributes/CMakeLists.txt +++ b/src/attributes/CMakeLists.txt @@ -1,6 +1,7 @@ PROJECT(attributes C) SET(_TEST_FILES stealth.test.c +otherfaction.test.c ) SET(_FILES diff --git a/src/attributes/otherfaction.c b/src/attributes/otherfaction.c index 0c225b256..76d035dd1 100644 --- a/src/attributes/otherfaction.c +++ b/src/attributes/otherfaction.c @@ -40,13 +40,9 @@ void write_of(const struct attrib *a, const void *owner, struct storage *store) int read_of(struct attrib *a, void *owner, struct storage *store) { /* return 1 on success, 0 if attrib needs removal */ int of; - static int rule = -1; - if (rule < 0) { - rule = rule_stealth_faction(); - } READ_INT(store, &of); - if (rule & 2) { + if (rule_stealth_other()) { a->data.v = findfaction(of); if (a->data.v) { return AT_READ_OK; diff --git a/src/attributes/stealth.test.c b/src/attributes/stealth.test.c index 90ee66872..818633d06 100644 --- a/src/attributes/stealth.test.c +++ b/src/attributes/stealth.test.c @@ -11,12 +11,11 @@ #include #include -void test_stealth(CuTest *tc) { +static void test_stealth(CuTest *tc) { unit *u; test_cleanup(); - test_create_world(); - u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); + u = test_create_unit(test_create_faction(test_create_race("human")), test_create_region(0, 0, 0)); set_level(u, SK_STEALTH, 2); CuAssertIntEquals(tc, -1, u_geteffstealth(u)); CuAssertIntEquals(tc, 2, eff_stealth(u, u->region)); diff --git a/src/give.test.c b/src/give.test.c index 517411c4c..76726c044 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -308,7 +308,7 @@ static void test_give_okay(CuTest * tc) { env.f2 = env.f1 = test_create_faction(0); setup_give(&env); - set_param(&global.parameters, "rules.give", "0"); + set_param(&global.parameters, "rules.give.flags", "0"); CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0)); test_cleanup(); } @@ -322,7 +322,7 @@ static void test_give_denied_by_rules(CuTest * tc) { env.f2 = test_create_faction(0); setup_give(&env); - set_param(&global.parameters, "rules.give", "0"); + set_param(&global.parameters, "rules.give.flags", "0"); CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, 0)); msg_release(msg); test_cleanup(); diff --git a/src/kernel/config.c b/src/kernel/config.c index 69d09b040..60e2cf0f7 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1327,12 +1327,24 @@ int cmp_current_owner(const building * b, const building * a) return -1; } -bool rule_stealth_faction(void) +bool rule_stealth_other(void) { static int gamecookie = -1; static int rule = -1; if (rule < 0 || gamecookie != global.cookie) { - rule = get_param_int(global.parameters, "rules.stealth.faction", 1); + rule = get_param_int(global.parameters, "stealth.faction.other", 1); + gamecookie = global.cookie; + assert(rule >= 0); + } + return rule != 0; +} + +bool rule_stealth_anon(void) +{ + static int gamecookie = -1; + static int rule = -1; + if (rule < 0 || gamecookie != global.cookie) { + rule = get_param_int(global.parameters, "stealth.faction.anon", 1); gamecookie = global.cookie; assert(rule >= 0); } @@ -1351,13 +1363,13 @@ bool rule_region_owners(void) return rule!=0; } -int rule_auto_taxation(void) +bool rule_auto_taxation(void) { static int gamecookie = -1; static int rule = -1; if (rule < 0 || gamecookie != global.cookie) { rule = - get_param_int(global.parameters, "rules.economy.taxation", TAX_ORDER); + get_param_int(global.parameters, "rules.economy.taxation", 0); gamecookie = global.cookie; assert(rule >= 0); } @@ -1659,10 +1671,10 @@ int entertainmoney(const region * r) int rule_give(void) { - return get_param_int(global.parameters, "rules.give", GIVE_DEFAULT); + return get_param_int(global.parameters, "rules.give.flags", GIVE_DEFAULT); } -int markets_module(void) +bool markets_module(void) { return get_param_int(global.parameters, "modules.markets", 0); } diff --git a/src/kernel/config.h b/src/kernel/config.h index 9449744ef..5eddd1ff3 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -153,15 +153,14 @@ extern "C" { bool rule_transfermen(void); bool rule_region_owners(void); - bool rule_stealth_faction(void); + bool rule_stealth_other(void); // units can pretend to be another faction, TARNE PARTEI + bool rule_stealth_anon(void); // units can anonymize their faction, TARNE PARTEI [NICHT] int rule_alliance_limit(void); int rule_faction_limit(void); #define HARVEST_WORK 0x00 #define HARVEST_TAXES 0x01 int rule_blessed_harvest(void); -#define TAX_ORDER 0x00 -#define TAX_OWNER 0x01 - int rule_auto_taxation(void); + bool rule_auto_taxation(void); #define GIVE_SELF 1 #define GIVE_PEASANTS 2 #define GIVE_LUXURIES 4 @@ -227,7 +226,7 @@ extern "C" { int besieged(const struct unit *u); int maxworkingpeasants(const struct region *r); bool has_horses(const struct unit *u); - int markets_module(void); + bool markets_module(void); int wage(const struct region *r, const struct faction *f, const struct race *rc, int in_turn); int maintenance_cost(const struct unit *u); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index fe4a7ad38..c5ecbcb43 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -402,16 +402,16 @@ void destroyfaction(faction * f) /* units of other factions that were disguised as this faction * have their disguise replaced by ordinary faction hiding. */ - if (rule_stealth_faction()) { + if (rule_stealth_other()) { region *rc; for (rc = regions; rc; rc = rc->next) { for (u = rc->units; u; u = u->next) { attrib *a = a_find(u->attribs, &at_otherfaction); - if (!a) - continue; - if (get_otherfaction(a) == f) { + if (a && get_otherfaction(a) == f) { a_removeall(&u->attribs, &at_otherfaction); - fset(u, UFL_ANON_FACTION); + if (rule_stealth_anon()) { + fset(u, UFL_ANON_FACTION); + } } } } diff --git a/src/kernel/save.c b/src/kernel/save.c index 3074e9d36..201b710aa 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -687,7 +687,7 @@ unit *read_unit(struct gamedata *data) setstatus(u, n); READ_INT(data->store, &u->flags); u->flags &= UFL_SAVEMASK; - if ((u->flags & UFL_ANON_FACTION) && !rule_stealth_faction()) { + if ((u->flags & UFL_ANON_FACTION) && !rule_stealth_anon()) { /* if this rule is broken, then fix broken units */ u->flags -= UFL_ANON_FACTION; log_warning("%s was anonymous.\n", unitname(u)); diff --git a/src/spells.c b/src/spells.c index 48b86a9b4..4a3b81d7a 100644 --- a/src/spells.c +++ b/src/spells.c @@ -2188,7 +2188,7 @@ static int sp_ironkeeper(castorder * co) guard(keeper, GUARD_MINING); fset(keeper, UFL_ISNEW); /* Parteitarnen, damit man nicht sofort weiß, wer dahinter steckt */ - if (rule_stealth_faction()) { + if (rule_stealth_anon()) { fset(keeper, UFL_ANON_FACTION); } @@ -3630,7 +3630,7 @@ static int sp_charmingsong(castorder * co) /* setze Parteitarnung, damit nicht sofort klar ist, wer dahinter * steckt */ - if (rule_stealth_faction()) { + if (rule_stealth_anon()) { fset(target, UFL_ANON_FACTION); } @@ -4377,7 +4377,7 @@ static int sp_raisepeasants(castorder * co) LOC(mage->faction->locale, "furious_mob"), mage); fset(u2, UFL_LOCKED); - if (rule_stealth_faction()) { + if (rule_stealth_anon()) { fset(u2, UFL_ANON_FACTION); } diff --git a/src/spy.c b/src/spy.c index 6249ab6b8..e25ff1e85 100644 --- a/src/spy.c +++ b/src/spy.c @@ -215,7 +215,7 @@ int setstealth_cmd(unit * u, struct order *ord) { char token[64]; const char *s; - int level, rule; + int level; init_order(ord); s = gettoken(token, sizeof(token)); @@ -288,13 +288,8 @@ int setstealth_cmd(unit * u, struct order *ord) switch (findparam(s, u->faction->locale)) { case P_FACTION: /* TARNE PARTEI [NICHT|NUMMER abcd] */ - rule = rule_stealth_faction(); - if (!rule) { - /* TARNE PARTEI is disabled */ - break; - } s = gettoken(token, sizeof(token)); - if (rule & 1) { + if (rule_stealth_anon()) { if (!s || *s == 0) { fset(u, UFL_ANON_FACTION); break; @@ -304,7 +299,7 @@ int setstealth_cmd(unit * u, struct order *ord) break; } } - if (rule & 2) { + if (rule_stealth_other()) { if (get_keyword(s, u->faction->locale) == K_NUMBER) { s = gettoken(token, sizeof(token)); int nr = -1; diff --git a/src/test_eressea.c b/src/test_eressea.c index 2a0bf04eb..c04764992 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -121,6 +121,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(move); ADD_SUITE(piracy); ADD_SUITE(stealth); + ADD_SUITE(otherfaction); ADD_SUITE(upkeep); ADD_SUITE(vortex); ADD_SUITE(wormhole);