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.owners.force_leave": false,
|
||||||
"rules.monsters.attack_chance": 0.1,
|
"rules.monsters.attack_chance": 0.1,
|
||||||
"rules.transfermen": false,
|
"rules.transfermen": false,
|
||||||
"rules.stealth.faction": true,
|
"stealth.faction.other": false,
|
||||||
"rules.stealth.anon_battle": false,
|
"rules.stealth.anon_battle": false,
|
||||||
"rules.check_overload": false,
|
"rules.check_overload": false,
|
||||||
"rules.combat.goblinbonus": 3,
|
"rules.combat.goblinbonus": 3,
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
"rules.reserve.twophase": true,
|
"rules.reserve.twophase": true,
|
||||||
"rules.owners.force_leave": false,
|
"rules.owners.force_leave": false,
|
||||||
"rules.transfermen": false,
|
"rules.transfermen": false,
|
||||||
"rules.stealth.faction": true,
|
"stealth.faction.other": false,
|
||||||
"rules.stealth.anon_battle": false,
|
"rules.stealth.anon_battle": false,
|
||||||
"rules.check_overload": false,
|
"rules.check_overload": false,
|
||||||
"rules.combat.goblinbonus": 3,
|
"rules.combat.goblinbonus": 3,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
PROJECT(attributes C)
|
PROJECT(attributes C)
|
||||||
SET(_TEST_FILES
|
SET(_TEST_FILES
|
||||||
stealth.test.c
|
stealth.test.c
|
||||||
|
otherfaction.test.c
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(_FILES
|
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)
|
int read_of(struct attrib *a, void *owner, struct storage *store)
|
||||||
{ /* return 1 on success, 0 if attrib needs removal */
|
{ /* return 1 on success, 0 if attrib needs removal */
|
||||||
int of;
|
int of;
|
||||||
static int rule = -1;
|
|
||||||
if (rule < 0) {
|
|
||||||
rule = rule_stealth_faction();
|
|
||||||
}
|
|
||||||
|
|
||||||
READ_INT(store, &of);
|
READ_INT(store, &of);
|
||||||
if (rule & 2) {
|
if (rule_stealth_other()) {
|
||||||
a->data.v = findfaction(of);
|
a->data.v = findfaction(of);
|
||||||
if (a->data.v) {
|
if (a->data.v) {
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
|
|
|
@ -11,12 +11,11 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void test_stealth(CuTest *tc) {
|
static void test_stealth(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
u = test_create_unit(test_create_faction(test_create_race("human")), test_create_region(0, 0, 0));
|
||||||
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
||||||
set_level(u, SK_STEALTH, 2);
|
set_level(u, SK_STEALTH, 2);
|
||||||
CuAssertIntEquals(tc, -1, u_geteffstealth(u));
|
CuAssertIntEquals(tc, -1, u_geteffstealth(u));
|
||||||
CuAssertIntEquals(tc, 2, eff_stealth(u, u->region));
|
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);
|
env.f2 = env.f1 = test_create_faction(0);
|
||||||
setup_give(&env);
|
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));
|
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ static void test_give_denied_by_rules(CuTest * tc) {
|
||||||
env.f2 = test_create_faction(0);
|
env.f2 = test_create_faction(0);
|
||||||
setup_give(&env);
|
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));
|
CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, 0));
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
|
@ -1327,12 +1327,24 @@ int cmp_current_owner(const building * b, const building * a)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rule_stealth_faction(void)
|
bool rule_stealth_other(void)
|
||||||
{
|
{
|
||||||
static int gamecookie = -1;
|
static int gamecookie = -1;
|
||||||
static int rule = -1;
|
static int rule = -1;
|
||||||
if (rule < 0 || gamecookie != global.cookie) {
|
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;
|
gamecookie = global.cookie;
|
||||||
assert(rule >= 0);
|
assert(rule >= 0);
|
||||||
}
|
}
|
||||||
|
@ -1351,13 +1363,13 @@ bool rule_region_owners(void)
|
||||||
return rule!=0;
|
return rule!=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rule_auto_taxation(void)
|
bool rule_auto_taxation(void)
|
||||||
{
|
{
|
||||||
static int gamecookie = -1;
|
static int gamecookie = -1;
|
||||||
static int rule = -1;
|
static int rule = -1;
|
||||||
if (rule < 0 || gamecookie != global.cookie) {
|
if (rule < 0 || gamecookie != global.cookie) {
|
||||||
rule =
|
rule =
|
||||||
get_param_int(global.parameters, "rules.economy.taxation", TAX_ORDER);
|
get_param_int(global.parameters, "rules.economy.taxation", 0);
|
||||||
gamecookie = global.cookie;
|
gamecookie = global.cookie;
|
||||||
assert(rule >= 0);
|
assert(rule >= 0);
|
||||||
}
|
}
|
||||||
|
@ -1659,10 +1671,10 @@ int entertainmoney(const region * r)
|
||||||
|
|
||||||
int rule_give(void)
|
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);
|
return get_param_int(global.parameters, "modules.markets", 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,15 +153,14 @@ extern "C" {
|
||||||
|
|
||||||
bool rule_transfermen(void);
|
bool rule_transfermen(void);
|
||||||
bool rule_region_owners(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_alliance_limit(void);
|
||||||
int rule_faction_limit(void);
|
int rule_faction_limit(void);
|
||||||
#define HARVEST_WORK 0x00
|
#define HARVEST_WORK 0x00
|
||||||
#define HARVEST_TAXES 0x01
|
#define HARVEST_TAXES 0x01
|
||||||
int rule_blessed_harvest(void);
|
int rule_blessed_harvest(void);
|
||||||
#define TAX_ORDER 0x00
|
bool rule_auto_taxation(void);
|
||||||
#define TAX_OWNER 0x01
|
|
||||||
int rule_auto_taxation(void);
|
|
||||||
#define GIVE_SELF 1
|
#define GIVE_SELF 1
|
||||||
#define GIVE_PEASANTS 2
|
#define GIVE_PEASANTS 2
|
||||||
#define GIVE_LUXURIES 4
|
#define GIVE_LUXURIES 4
|
||||||
|
@ -227,7 +226,7 @@ extern "C" {
|
||||||
int besieged(const struct unit *u);
|
int besieged(const struct unit *u);
|
||||||
int maxworkingpeasants(const struct region *r);
|
int maxworkingpeasants(const struct region *r);
|
||||||
bool has_horses(const struct unit *u);
|
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,
|
int wage(const struct region *r, const struct faction *f,
|
||||||
const struct race *rc, int in_turn);
|
const struct race *rc, int in_turn);
|
||||||
int maintenance_cost(const struct unit *u);
|
int maintenance_cost(const struct unit *u);
|
||||||
|
|
|
@ -402,16 +402,16 @@ void destroyfaction(faction * f)
|
||||||
|
|
||||||
/* units of other factions that were disguised as this faction
|
/* units of other factions that were disguised as this faction
|
||||||
* have their disguise replaced by ordinary faction hiding. */
|
* have their disguise replaced by ordinary faction hiding. */
|
||||||
if (rule_stealth_faction()) {
|
if (rule_stealth_other()) {
|
||||||
region *rc;
|
region *rc;
|
||||||
for (rc = regions; rc; rc = rc->next) {
|
for (rc = regions; rc; rc = rc->next) {
|
||||||
for (u = rc->units; u; u = u->next) {
|
for (u = rc->units; u; u = u->next) {
|
||||||
attrib *a = a_find(u->attribs, &at_otherfaction);
|
attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||||
if (!a)
|
if (a && get_otherfaction(a) == f) {
|
||||||
continue;
|
|
||||||
if (get_otherfaction(a) == f) {
|
|
||||||
a_removeall(&u->attribs, &at_otherfaction);
|
a_removeall(&u->attribs, &at_otherfaction);
|
||||||
fset(u, UFL_ANON_FACTION);
|
if (rule_stealth_anon()) {
|
||||||
|
fset(u, UFL_ANON_FACTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -687,7 +687,7 @@ unit *read_unit(struct gamedata *data)
|
||||||
setstatus(u, n);
|
setstatus(u, n);
|
||||||
READ_INT(data->store, &u->flags);
|
READ_INT(data->store, &u->flags);
|
||||||
u->flags &= UFL_SAVEMASK;
|
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 */
|
/* if this rule is broken, then fix broken units */
|
||||||
u->flags -= UFL_ANON_FACTION;
|
u->flags -= UFL_ANON_FACTION;
|
||||||
log_warning("%s was anonymous.\n", unitname(u));
|
log_warning("%s was anonymous.\n", unitname(u));
|
||||||
|
|
|
@ -2188,7 +2188,7 @@ static int sp_ironkeeper(castorder * co)
|
||||||
guard(keeper, GUARD_MINING);
|
guard(keeper, GUARD_MINING);
|
||||||
fset(keeper, UFL_ISNEW);
|
fset(keeper, UFL_ISNEW);
|
||||||
/* Parteitarnen, damit man nicht sofort weiß, wer dahinter steckt */
|
/* Parteitarnen, damit man nicht sofort weiß, wer dahinter steckt */
|
||||||
if (rule_stealth_faction()) {
|
if (rule_stealth_anon()) {
|
||||||
fset(keeper, UFL_ANON_FACTION);
|
fset(keeper, UFL_ANON_FACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3630,7 +3630,7 @@ static int sp_charmingsong(castorder * co)
|
||||||
|
|
||||||
/* setze Parteitarnung, damit nicht sofort klar ist, wer dahinter
|
/* setze Parteitarnung, damit nicht sofort klar ist, wer dahinter
|
||||||
* steckt */
|
* steckt */
|
||||||
if (rule_stealth_faction()) {
|
if (rule_stealth_anon()) {
|
||||||
fset(target, UFL_ANON_FACTION);
|
fset(target, UFL_ANON_FACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4377,7 +4377,7 @@ static int sp_raisepeasants(castorder * co)
|
||||||
LOC(mage->faction->locale, "furious_mob"), mage);
|
LOC(mage->faction->locale, "furious_mob"), mage);
|
||||||
|
|
||||||
fset(u2, UFL_LOCKED);
|
fset(u2, UFL_LOCKED);
|
||||||
if (rule_stealth_faction()) {
|
if (rule_stealth_anon()) {
|
||||||
fset(u2, UFL_ANON_FACTION);
|
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];
|
char token[64];
|
||||||
const char *s;
|
const char *s;
|
||||||
int level, rule;
|
int level;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = gettoken(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
|
@ -288,13 +288,8 @@ int setstealth_cmd(unit * u, struct order *ord)
|
||||||
switch (findparam(s, u->faction->locale)) {
|
switch (findparam(s, u->faction->locale)) {
|
||||||
case P_FACTION:
|
case P_FACTION:
|
||||||
/* TARNE PARTEI [NICHT|NUMMER abcd] */
|
/* TARNE PARTEI [NICHT|NUMMER abcd] */
|
||||||
rule = rule_stealth_faction();
|
|
||||||
if (!rule) {
|
|
||||||
/* TARNE PARTEI is disabled */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s = gettoken(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
if (rule & 1) {
|
if (rule_stealth_anon()) {
|
||||||
if (!s || *s == 0) {
|
if (!s || *s == 0) {
|
||||||
fset(u, UFL_ANON_FACTION);
|
fset(u, UFL_ANON_FACTION);
|
||||||
break;
|
break;
|
||||||
|
@ -304,7 +299,7 @@ int setstealth_cmd(unit * u, struct order *ord)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rule & 2) {
|
if (rule_stealth_other()) {
|
||||||
if (get_keyword(s, u->faction->locale) == K_NUMBER) {
|
if (get_keyword(s, u->faction->locale) == K_NUMBER) {
|
||||||
s = gettoken(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
int nr = -1;
|
int nr = -1;
|
||||||
|
|
|
@ -121,6 +121,7 @@ int RunAllTests(int argc, char *argv[])
|
||||||
ADD_SUITE(move);
|
ADD_SUITE(move);
|
||||||
ADD_SUITE(piracy);
|
ADD_SUITE(piracy);
|
||||||
ADD_SUITE(stealth);
|
ADD_SUITE(stealth);
|
||||||
|
ADD_SUITE(otherfaction);
|
||||||
ADD_SUITE(upkeep);
|
ADD_SUITE(upkeep);
|
||||||
ADD_SUITE(vortex);
|
ADD_SUITE(vortex);
|
||||||
ADD_SUITE(wormhole);
|
ADD_SUITE(wormhole);
|
||||||
|
|
Loading…
Reference in New Issue