forked from github/server
fix and tests for otherfaction attributes in E2
https://bugs.eressea.de/view.php?id=2152
This commit is contained in:
parent
bf8cc4cb08
commit
ee02721c21
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
PROJECT(attributes C)
|
||||
SET(_TEST_FILES
|
||||
stealth.test.c
|
||||
otherfaction.test.c
|
||||
)
|
||||
|
||||
SET(_FILES
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -11,12 +11,11 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
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));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 <no>
|
||||
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);
|
||||
|
|
|
@ -402,21 +402,21 @@ 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);
|
||||
if (rule_stealth_anon()) {
|
||||
fset(u, UFL_ANON_FACTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int get_alliance(const faction * a, const faction * b)
|
||||
{
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
11
src/spy.c
11
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue