forked from github/server
WIP: remove at_guard, GUARD_TREES and GUARD_MINING
TODO: fix tests TODO: write new guard coverage
This commit is contained in:
parent
8597e8b16a
commit
2c0f708d1b
|
@ -7,6 +7,5 @@
|
||||||
<modifier building="mine" type="skill" value="1"/>
|
<modifier building="mine" type="skill" value="1"/>
|
||||||
<modifier building="mine" type="material" value="0.5"/>
|
<modifier building="mine" type="material" value="0.5"/>
|
||||||
<modifier race="dwarf" type="material" value="0.60"/>
|
<modifier race="dwarf" type="material" value="0.60"/>
|
||||||
<guard flag="mining"/>
|
|
||||||
</resourcelimit>
|
</resourcelimit>
|
||||||
</resource>
|
</resource>
|
||||||
|
|
|
@ -5,6 +5,5 @@
|
||||||
</item>
|
</item>
|
||||||
<resourcelimit>
|
<resourcelimit>
|
||||||
<modifier type="require" building="mine"/>
|
<modifier type="require" building="mine"/>
|
||||||
<guard flag="mining"/>
|
|
||||||
</resourcelimit>
|
</resourcelimit>
|
||||||
</resource>
|
</resource>
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
<resourcelimit>
|
<resourcelimit>
|
||||||
<modifier building="sawmill" type="skill" value="1"/>
|
<modifier building="sawmill" type="skill" value="1"/>
|
||||||
<modifier building="sawmill" type="material" value="0.5"/>
|
<modifier building="sawmill" type="material" value="0.5"/>
|
||||||
<guard flag="logging"/>
|
|
||||||
<function name="produce" value="lua_produceresource"/>
|
<function name="produce" value="lua_produceresource"/>
|
||||||
<function name="limit" value="lua_limitresource"/>
|
<function name="limit" value="lua_limitresource"/>
|
||||||
</resourcelimit>
|
</resourcelimit>
|
||||||
|
|
|
@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "guard.h"
|
|
||||||
|
|
||||||
/* attributes includes */
|
/* attributes includes */
|
||||||
#include "follow.h"
|
#include "follow.h"
|
||||||
|
@ -105,7 +104,6 @@ void register_attributes(void)
|
||||||
at_register(&at_private);
|
at_register(&at_private);
|
||||||
|
|
||||||
at_register(&at_icastle);
|
at_register(&at_icastle);
|
||||||
at_register(&at_guard);
|
|
||||||
at_register(&at_group);
|
at_register(&at_group);
|
||||||
|
|
||||||
at_register(&at_building_generic_type);
|
at_register(&at_building_generic_type);
|
||||||
|
@ -124,6 +122,7 @@ void register_attributes(void)
|
||||||
at_deprecate("xontormiaexpress", a_readint); /* required for old datafiles */
|
at_deprecate("xontormiaexpress", a_readint); /* required for old datafiles */
|
||||||
at_deprecate("lua", read_ext); /* required for old datafiles */
|
at_deprecate("lua", read_ext); /* required for old datafiles */
|
||||||
at_deprecate("gm", a_readint);
|
at_deprecate("gm", a_readint);
|
||||||
|
at_deprecate("guard", a_readint); /* used to contain guard-flags (v3.10.0-259-g8597e8b) */
|
||||||
at_register(&at_stealth);
|
at_register(&at_stealth);
|
||||||
at_register(&at_dict);
|
at_register(&at_dict);
|
||||||
at_register(&at_unitdissolve);
|
at_register(&at_unitdissolve);
|
||||||
|
|
|
@ -935,17 +935,6 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdata->guard != 0) {
|
|
||||||
unit *u2;
|
|
||||||
for (u2 = r->units; u2; u2 = u2->next) {
|
|
||||||
if (is_guard(u2, rdata->guard) != 0 && can_guard(u2, u)) {
|
|
||||||
ADDMSG(&u->faction->msgs,
|
|
||||||
msg_feedback(u, u->thisorder, "region_guarded", "guard", u2));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bergwächter können Abbau von Eisen/Laen durch Bewachen verhindern.
|
/* Bergwächter können Abbau von Eisen/Laen durch Bewachen verhindern.
|
||||||
* Als magische Wesen 'sehen' Bergwächter alles und werden durch
|
* Als magische Wesen 'sehen' Bergwächter alles und werden durch
|
||||||
* Belagerung nicht aufgehalten. (Ansonsten wie oben bei Elfen anpassen).
|
* Belagerung nicht aufgehalten. (Ansonsten wie oben bei Elfen anpassen).
|
||||||
|
@ -953,7 +942,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
||||||
if (itype->rtype && (itype->rtype == get_resourcetype(R_IRON) || itype->rtype == rt_find("laen"))) {
|
if (itype->rtype && (itype->rtype == get_resourcetype(R_IRON) || itype->rtype == rt_find("laen"))) {
|
||||||
unit *u2;
|
unit *u2;
|
||||||
for (u2 = r->units; u2; u2 = u2->next) {
|
for (u2 = r->units; u2; u2 = u2->next) {
|
||||||
if (is_guard(u, GUARD_MINING)
|
if (is_guard(u, GUARD_ALL)
|
||||||
&& !fval(u2, UFL_ISNEW)
|
&& !fval(u2, UFL_ISNEW)
|
||||||
&& u2->number && !alliedunit(u2, u->faction, HELP_GUARD)) {
|
&& u2->number && !alliedunit(u2, u->faction, HELP_GUARD)) {
|
||||||
ADDMSG(&u->faction->msgs,
|
ADDMSG(&u->faction->msgs,
|
||||||
|
|
58
src/guard.c
58
src/guard.c
|
@ -39,7 +39,7 @@ attrib_type at_guard = {
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
DEFAULT_FINALIZE,
|
DEFAULT_FINALIZE,
|
||||||
DEFAULT_AGE,
|
DEFAULT_AGE,
|
||||||
a_writeint,
|
NULL,
|
||||||
a_readint,
|
a_readint,
|
||||||
NULL,
|
NULL,
|
||||||
ATF_UNIQUE
|
ATF_UNIQUE
|
||||||
|
@ -70,13 +70,6 @@ void update_guards(void)
|
||||||
if (can_start_guarding(u) != E_GUARD_OK) {
|
if (can_start_guarding(u) != E_GUARD_OK) {
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, GUARD_NONE);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
attrib *a = a_find(u->attribs, &at_guard);
|
|
||||||
if (a && a->data.i == (int)guard_flags(u)) {
|
|
||||||
/* this is really rather not necessary */
|
|
||||||
a_remove(&u->attribs, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,50 +90,19 @@ unsigned int guard_flags(const unit * u)
|
||||||
#if GUARD_DISABLES_RECRUIT == 1
|
#if GUARD_DISABLES_RECRUIT == 1
|
||||||
flags |= GUARD_RECRUIT;
|
flags |= GUARD_RECRUIT;
|
||||||
#endif
|
#endif
|
||||||
if (rc_changed(&rc_cache)) {
|
|
||||||
rc_elf = get_race(RC_ELF);
|
|
||||||
rc_ent = get_race(RC_TREEMAN);
|
|
||||||
rc_ironkeeper = get_race(RC_IRONKEEPER);
|
|
||||||
}
|
|
||||||
if (rc == rc_elf) {
|
|
||||||
if (u->faction->race == u_race(u)) {
|
|
||||||
flags |= GUARD_TREES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (rc == rc_ent) {
|
|
||||||
flags |= GUARD_TREES;
|
|
||||||
}
|
|
||||||
else if (rc == rc_ironkeeper) {
|
|
||||||
flags = GUARD_MINING;
|
|
||||||
}
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setguard(unit * u, unsigned int flags)
|
void setguard(unit * u, unsigned int flags)
|
||||||
{
|
{
|
||||||
/* setzt die guard-flags der Einheit */
|
bool enabled = (flags!=GUARD_NONE);
|
||||||
attrib *a = NULL;
|
if (!enabled) {
|
||||||
assert(flags == 0 || !fval(u, UFL_MOVED));
|
assert(!fval(u, UFL_MOVED));
|
||||||
assert(flags == 0 || u->status < ST_FLEE);
|
assert(u->status < ST_FLEE);
|
||||||
if (fval(u, UFL_GUARD)) {
|
|
||||||
a = a_find(u->attribs, &at_guard);
|
|
||||||
}
|
|
||||||
if (flags == GUARD_NONE) {
|
|
||||||
freset(u, UFL_GUARD);
|
freset(u, UFL_GUARD);
|
||||||
if (a)
|
} else {
|
||||||
a_remove(&u->attribs, a);
|
fset(u, UFL_GUARD);
|
||||||
return;
|
fset(u->region, RF_GUARDED);
|
||||||
}
|
|
||||||
fset(u, UFL_GUARD);
|
|
||||||
fset(u->region, RF_GUARDED);
|
|
||||||
if (flags == guard_flags(u)) {
|
|
||||||
if (a)
|
|
||||||
a_remove(&u->attribs, a);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!a)
|
|
||||||
a = a_add(&u->attribs, a_new(&at_guard));
|
|
||||||
a->data.i = (int)flags;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,10 +112,6 @@ unsigned int getguard(const unit * u)
|
||||||
|
|
||||||
assert(fval(u, UFL_GUARD) || (u->building && u == building_owner(u->building))
|
assert(fval(u, UFL_GUARD) || (u->building && u == building_owner(u->building))
|
||||||
|| !"you're doing it wrong! check is_guard first");
|
|| !"you're doing it wrong! check is_guard first");
|
||||||
a = a_find(u->attribs, &at_guard);
|
|
||||||
if (a) {
|
|
||||||
return (unsigned int)a->data.i;
|
|
||||||
}
|
|
||||||
return guard_flags(u);
|
return guard_flags(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,6 @@ extern "C" {
|
||||||
#define GUARD_NONE 0
|
#define GUARD_NONE 0
|
||||||
#define GUARD_TAX 1
|
#define GUARD_TAX 1
|
||||||
/* Verhindert Steuereintreiben */
|
/* Verhindert Steuereintreiben */
|
||||||
#define GUARD_MINING 2
|
|
||||||
/* Verhindert Bergbau */
|
|
||||||
#define GUARD_TREES 4
|
|
||||||
/* Verhindert Waldarbeiten */
|
|
||||||
#define GUARD_TRAVELTHRU 8
|
#define GUARD_TRAVELTHRU 8
|
||||||
/* Blockiert Durchreisende */
|
/* Blockiert Durchreisende */
|
||||||
#define GUARD_LANDING 16
|
#define GUARD_LANDING 16
|
||||||
|
@ -30,14 +26,10 @@ extern "C" {
|
||||||
/* Verhindert Abbau von Resourcen mit RTF_LIMITED */
|
/* Verhindert Abbau von Resourcen mit RTF_LIMITED */
|
||||||
#define GUARD_ALL 0xFFFF
|
#define GUARD_ALL 0xFFFF
|
||||||
|
|
||||||
extern struct attrib_type at_guard;
|
|
||||||
|
|
||||||
guard_t can_start_guarding(const struct unit * u);
|
guard_t can_start_guarding(const struct unit * u);
|
||||||
void update_guards(void);
|
void update_guards(void);
|
||||||
unsigned int guard_flags(const struct unit * u);
|
|
||||||
unsigned int getguard(const struct unit * u);
|
unsigned int getguard(const struct unit * u);
|
||||||
void setguard(struct unit * u, unsigned int flags);
|
void setguard(struct unit * u, unsigned int flags);
|
||||||
|
|
||||||
void guard(struct unit * u, unsigned int mask);
|
void guard(struct unit * u, unsigned int mask);
|
||||||
|
|
||||||
struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask);
|
struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask);
|
||||||
|
|
|
@ -27,16 +27,9 @@ static void test_is_guarded(CuTest *tc) {
|
||||||
r = test_create_region(0, 0, 0);
|
r = test_create_region(0, 0, 0);
|
||||||
u1 = test_create_unit(test_create_faction(0), r);
|
u1 = test_create_unit(test_create_faction(0), r);
|
||||||
u2 = test_create_unit(test_create_faction(rc), r);
|
u2 = test_create_unit(test_create_faction(rc), r);
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_TRAVELTHRU));
|
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_ALL));
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_PRODUCE));
|
guard(u2, GUARD_ALL);
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_TREES));
|
CuAssertPtrEquals(tc, u2, is_guarded(r, u1, GUARD_ALL));
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_MINING));
|
|
||||||
guard(u2, GUARD_MINING | GUARD_PRODUCE);
|
|
||||||
CuAssertIntEquals(tc, GUARD_CREWS | GUARD_LANDING | GUARD_TRAVELTHRU | GUARD_TAX | GUARD_PRODUCE | GUARD_RECRUIT, guard_flags(u2));
|
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_TRAVELTHRU));
|
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_TREES));
|
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_MINING));
|
|
||||||
CuAssertPtrEquals(tc, u2, is_guarded(r, u1, GUARD_PRODUCE));
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,6 @@ extern "C" {
|
||||||
typedef struct resource_limit {
|
typedef struct resource_limit {
|
||||||
rlimit_limit limit;
|
rlimit_limit limit;
|
||||||
rlimit_produce produce;
|
rlimit_produce produce;
|
||||||
unsigned int guard; /* how to guard against theft */
|
|
||||||
int value;
|
int value;
|
||||||
resource_mod *modifiers;
|
resource_mod *modifiers;
|
||||||
} resource_limit;
|
} resource_limit;
|
||||||
|
|
|
@ -1053,24 +1053,6 @@ static int parse_resources(xmlDocPtr doc)
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(result);
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "guard", xpath);
|
|
||||||
if (result->nodesetval != NULL)
|
|
||||||
for (k = 0; k != result->nodesetval->nodeNr; ++k) {
|
|
||||||
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
|
||||||
xmlChar *propFlag = xmlGetProp(node, BAD_CAST "flag");
|
|
||||||
|
|
||||||
if (propFlag != NULL) {
|
|
||||||
if (strcmp((const char *)propFlag, "logging") == 0) {
|
|
||||||
rdata->guard |= GUARD_TREES;
|
|
||||||
}
|
|
||||||
else if (strcmp((const char *)propFlag, "mining") == 0) {
|
|
||||||
rdata->guard |= GUARD_MINING;
|
|
||||||
}
|
|
||||||
xmlFree(propFlag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
|
|
||||||
/* reading eressea/resources/resource/resourcelimit/function */
|
/* reading eressea/resources/resource/resourcelimit/function */
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
|
||||||
if (result->nodesetval != NULL)
|
if (result->nodesetval != NULL)
|
||||||
|
|
|
@ -2196,7 +2196,7 @@ static int sp_ironkeeper(castorder * co)
|
||||||
|
|
||||||
/*keeper->age = cast_level + 2; */
|
/*keeper->age = cast_level + 2; */
|
||||||
setstatus(keeper, ST_AVOID); /* kaempft nicht */
|
setstatus(keeper, ST_AVOID); /* kaempft nicht */
|
||||||
guard(keeper, GUARD_MINING);
|
setguard(keeper, GUARD_ALL);
|
||||||
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_anon()) {
|
if (rule_stealth_anon()) {
|
||||||
|
|
Loading…
Reference in New Issue