forked from github/server
WIP: remove GUARD_* flags.
TODO: does not compile TODO: write new guard.test.c tests
This commit is contained in:
parent
182cecf31b
commit
754ad78db7
|
@ -61,7 +61,7 @@ void herbsearch(unit * u, int max)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_guarded(r, u, GUARD_PRODUCE)) {
|
if (is_guarded(r, u)) {
|
||||||
cmistake(u, u->thisorder, 70, MSG_EVENT);
|
cmistake(u, u->thisorder, 70, MSG_EVENT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ static void test_herbsearch(CuTest * tc)
|
||||||
rc = rc_get_or_create("dragon");
|
rc = rc_get_or_create("dragon");
|
||||||
rc->flags |= RCF_UNARMEDGUARD;
|
rc->flags |= RCF_UNARMEDGUARD;
|
||||||
u2 = test_create_unit(test_create_faction(rc), r);
|
u2 = test_create_unit(test_create_faction(rc), r);
|
||||||
guard(u2, GUARD_PRODUCE);
|
setguard(u2, true);
|
||||||
|
|
||||||
f = test_create_faction(0);
|
f = test_create_faction(0);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
|
@ -41,14 +41,14 @@ static void test_herbsearch(CuTest * tc)
|
||||||
test_clear_messages(f);
|
test_clear_messages(f);
|
||||||
|
|
||||||
set_level(u, SK_HERBALISM, 1);
|
set_level(u, SK_HERBALISM, 1);
|
||||||
CuAssertPtrEquals(tc, u2, is_guarded(r, u, GUARD_PRODUCE));
|
CuAssertPtrEquals(tc, u2, is_guarded(r, u));
|
||||||
herbsearch(u, INT_MAX);
|
herbsearch(u, INT_MAX);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||||
test_clear_messages(f);
|
test_clear_messages(f);
|
||||||
|
|
||||||
guard(u2, GUARD_NONE);
|
setguard(u2, false);
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u, GUARD_PRODUCE));
|
CuAssertPtrEquals(tc, 0, is_guarded(r, u));
|
||||||
CuAssertPtrEquals(tc, 0, (void *)rherbtype(r));
|
CuAssertPtrEquals(tc, 0, (void *)rherbtype(r));
|
||||||
herbsearch(u, INT_MAX);
|
herbsearch(u, INT_MAX);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error108"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error108"));
|
||||||
|
|
10
src/battle.c
10
src/battle.c
|
@ -2425,7 +2425,7 @@ side *make_side(battle * b, const faction * f, const group * g,
|
||||||
else {
|
else {
|
||||||
unit *u;
|
unit *u;
|
||||||
for (u = b->region->units; u; u = u->next) {
|
for (u = b->region->units; u; u = u->next) {
|
||||||
if (is_guard(u, HELP_ALL)) {
|
if (is_guard(u)) {
|
||||||
if (alliedunit(u, f, HELP_GUARD)) {
|
if (alliedunit(u, f, HELP_GUARD)) {
|
||||||
flags |= SIDE_HASGUARDS;
|
flags |= SIDE_HASGUARDS;
|
||||||
break;
|
break;
|
||||||
|
@ -2726,7 +2726,7 @@ static void aftermath(battle * b)
|
||||||
}
|
}
|
||||||
scale_number(du, df->run.number);
|
scale_number(du, df->run.number);
|
||||||
du->hp = df->run.hp;
|
du->hp = df->run.hp;
|
||||||
setguard(du, GUARD_NONE);
|
setguard(du, false);
|
||||||
/* must leave ships or buildings, or a stealthy hobbit
|
/* must leave ships or buildings, or a stealthy hobbit
|
||||||
* can hold castles indefinitely */
|
* can hold castles indefinitely */
|
||||||
if (!fval(r->terrain, SEA_REGION)) {
|
if (!fval(r->terrain, SEA_REGION)) {
|
||||||
|
@ -2763,7 +2763,7 @@ static void aftermath(battle * b)
|
||||||
/* Distribute Loot */
|
/* Distribute Loot */
|
||||||
loot_items(df);
|
loot_items(df);
|
||||||
|
|
||||||
setguard(du, GUARD_NONE);
|
setguard(du, true);
|
||||||
scale_number(du, 0);
|
scale_number(du, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3878,7 +3878,7 @@ static void flee(const troop dt)
|
||||||
fig->run.hp += fig->person[dt.index].hp;
|
fig->run.hp += fig->person[dt.index].hp;
|
||||||
++fig->run.number;
|
++fig->run.number;
|
||||||
|
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
|
|
||||||
kill_troop(dt);
|
kill_troop(dt);
|
||||||
}
|
}
|
||||||
|
@ -3941,7 +3941,7 @@ static bool start_battle(region * r, battle ** bp)
|
||||||
|
|
||||||
if ((u->ship != NULL && !fval(r->terrain, SEA_REGION))
|
if ((u->ship != NULL && !fval(r->terrain, SEA_REGION))
|
||||||
|| (lsh = leftship(u)) != NULL) {
|
|| (lsh = leftship(u)) != NULL) {
|
||||||
if (is_guarded(r, u, GUARD_TRAVELTHRU)) {
|
if (is_guarded(r, u)) {
|
||||||
if (lsh) {
|
if (lsh) {
|
||||||
cmistake(u, ord, 234, MSG_BATTLE);
|
cmistake(u, ord, 234, MSG_BATTLE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,18 +258,15 @@ static int tolua_unit_set_flags(lua_State * L)
|
||||||
static int tolua_unit_get_guard(lua_State * L)
|
static int tolua_unit_get_guard(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
if (is_guard(self, GUARD_ALL)) {
|
lua_pushboolean(L, is_guard(self));
|
||||||
lua_pushinteger(L, getguard(self));
|
return 1;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_guard(lua_State * L)
|
static int tolua_unit_set_guard(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unsigned int flags = (unsigned int)tolua_tonumber(L, 2, 0);
|
unsigned int flags = (unsigned int)tolua_tonumber(L, 2, 0);
|
||||||
setguard(self, flags);
|
setguard(self, flags!=0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -849,7 +849,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
|
||||||
assert(u->ship->region);
|
assert(u->ship->region);
|
||||||
stream_printf(out, "%d;Schiff\n", u->ship->no);
|
stream_printf(out, "%d;Schiff\n", u->ship->no);
|
||||||
}
|
}
|
||||||
if (is_guard(u, GUARD_ALL) != 0) {
|
if (is_guard(u)) {
|
||||||
stream_printf(out, "%d;bewacht\n", 1);
|
stream_printf(out, "%d;bewacht\n", 1);
|
||||||
}
|
}
|
||||||
if ((b = usiege(u)) != NULL) {
|
if ((b = usiege(u)) != NULL) {
|
||||||
|
|
|
@ -459,7 +459,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
|
||||||
/* this is a very special case because the recruiting unit may be empty
|
/* this is a very special case because the recruiting unit may be empty
|
||||||
* at this point and we have to look at the creating unit instead. This
|
* at this point and we have to look at the creating unit instead. This
|
||||||
* is done in cansee, which is called indirectly by is_guarded(). */
|
* is done in cansee, which is called indirectly by is_guarded(). */
|
||||||
if (is_guarded(r, u, GUARD_RECRUIT)) {
|
if (is_guarded(r, u)) {
|
||||||
cmistake(u, ord, 70, MSG_EVENT);
|
cmistake(u, ord, 70, MSG_EVENT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -929,7 +929,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_ALL)
|
if (is_guard(u)
|
||||||
&& !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,
|
||||||
|
@ -1246,7 +1246,7 @@ static void create_item(unit * u, const item_type * itype, int want)
|
||||||
{
|
{
|
||||||
if (itype->construction && fval(itype->rtype, RTF_LIMITED)) {
|
if (itype->construction && fval(itype->rtype, RTF_LIMITED)) {
|
||||||
#if GUARD_DISABLES_PRODUCTION == 1
|
#if GUARD_DISABLES_PRODUCTION == 1
|
||||||
if (is_guarded(u->region, u, GUARD_PRODUCE)) {
|
if (is_guarded(u->region, u)) {
|
||||||
cmistake(u, u->thisorder, 70, MSG_EVENT);
|
cmistake(u, u->thisorder, 70, MSG_EVENT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1548,11 +1548,11 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
|
||||||
keyword_t kwd;
|
keyword_t kwd;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
if (u->ship && is_guarded(r, u)) {
|
||||||
cmistake(u, ord, 69, MSG_INCOME);
|
cmistake(u, ord, 69, MSG_INCOME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
if (u->ship && is_guarded(r, u)) {
|
||||||
cmistake(u, ord, 69, MSG_INCOME);
|
cmistake(u, ord, 69, MSG_INCOME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1866,7 +1866,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
||||||
caravan_bt = bt_find("caravan");
|
caravan_bt = bt_find("caravan");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
if (u->ship && is_guarded(r, u)) {
|
||||||
cmistake(u, ord, 69, MSG_INCOME);
|
cmistake(u, ord, 69, MSG_INCOME);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2581,7 +2581,7 @@ void entertain_cmd(unit * u, struct order *ord)
|
||||||
cmistake(u, ord, 60, MSG_INCOME);
|
cmistake(u, ord, 60, MSG_INCOME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
if (u->ship && is_guarded(r, u)) {
|
||||||
cmistake(u, ord, 69, MSG_INCOME);
|
cmistake(u, ord, 69, MSG_INCOME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2678,7 +2678,7 @@ static int do_work(unit * u, order * ord, request * o)
|
||||||
cmistake(u, ord, 60, MSG_INCOME);
|
cmistake(u, ord, 60, MSG_INCOME);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
if (u->ship && is_guarded(r, u)) {
|
||||||
if (ord)
|
if (ord)
|
||||||
cmistake(u, ord, 69, MSG_INCOME);
|
cmistake(u, ord, 69, MSG_INCOME);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2815,7 +2815,7 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
|
||||||
u->wants = _min(n * effskill(u, SK_TAXING, 0) * taxperlevel, max);
|
u->wants = _min(n * effskill(u, SK_TAXING, 0) * taxperlevel, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
u2 = is_guarded(r, u, GUARD_TAX);
|
u2 = is_guarded(r, u);
|
||||||
if (u2) {
|
if (u2) {
|
||||||
ADDMSG(&u->faction->msgs,
|
ADDMSG(&u->faction->msgs,
|
||||||
msg_feedback(u, ord, "region_guarded", "guard", u2));
|
msg_feedback(u, ord, "region_guarded", "guard", u2));
|
||||||
|
@ -2870,7 +2870,7 @@ void loot_cmd(unit * u, struct order *ord, request ** lootorders)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u2 = is_guarded(r, u, GUARD_TAX);
|
u2 = is_guarded(r, u);
|
||||||
if (u2) {
|
if (u2) {
|
||||||
ADDMSG(&u->faction->msgs,
|
ADDMSG(&u->faction->msgs,
|
||||||
msg_feedback(u, ord, "region_guarded", "guard", u2));
|
msg_feedback(u, ord, "region_guarded", "guard", u2));
|
||||||
|
|
44
src/guard.c
44
src/guard.c
|
@ -56,31 +56,15 @@ void update_guards(void)
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
if (fval(u, UFL_GUARD)) {
|
if (fval(u, UFL_GUARD)) {
|
||||||
if (can_start_guarding(u) != E_GUARD_OK) {
|
if (can_start_guarding(u) != E_GUARD_OK) {
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int guard_flags(const unit * u)
|
void setguard(unit * u, bool enabled)
|
||||||
{
|
{
|
||||||
// TODO: this should be a property of the race, like race.guard_flags
|
|
||||||
unsigned int flags =
|
|
||||||
GUARD_CREWS | GUARD_LANDING | GUARD_TRAVELTHRU | GUARD_TAX;
|
|
||||||
// TODO: configuration, not define
|
|
||||||
#if GUARD_DISABLES_PRODUCTION == 1
|
|
||||||
flags |= GUARD_PRODUCE;
|
|
||||||
#endif
|
|
||||||
#if GUARD_DISABLES_RECRUIT == 1
|
|
||||||
flags |= GUARD_RECRUIT;
|
|
||||||
#endif
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setguard(unit * u, unsigned int flags)
|
|
||||||
{
|
|
||||||
bool enabled = (flags!=GUARD_NONE);
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
freset(u, UFL_GUARD);
|
freset(u, UFL_GUARD);
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,24 +75,16 @@ void setguard(unit * u, unsigned int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getguard(const unit * u)
|
void guard(unit * u)
|
||||||
{
|
{
|
||||||
assert(fval(u, UFL_GUARD) || (u->building && u == building_owner(u->building))
|
setguard(u, true);
|
||||||
|| !"you're doing it wrong! check is_guard first");
|
|
||||||
return guard_flags(u);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void guard(unit * u, unsigned int mask)
|
static bool is_guardian_u(const unit * guard, unit * u)
|
||||||
{
|
|
||||||
unsigned int flags = guard_flags(u);
|
|
||||||
setguard(u, flags & mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool is_guardian_u(const unit * guard, unit * u, unsigned int mask)
|
|
||||||
{
|
{
|
||||||
if (guard->faction == u->faction)
|
if (guard->faction == u->faction)
|
||||||
return false;
|
return false;
|
||||||
if (is_guard(guard, mask) == 0)
|
if (is_guard(guard) == 0)
|
||||||
return false;
|
return false;
|
||||||
if (alliedunit(guard, u->faction, HELP_GUARD))
|
if (alliedunit(guard, u->faction, HELP_GUARD))
|
||||||
return false;
|
return false;
|
||||||
|
@ -145,12 +121,12 @@ static bool is_guardian_r(const unit * guard)
|
||||||
return fval(u_race(guard), RCF_UNARMEDGUARD) || is_monsters(guard->faction) || (armedmen(guard, true) > 0);
|
return fval(u_race(guard), RCF_UNARMEDGUARD) || is_monsters(guard->faction) || (armedmen(guard, true) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_guard(const struct unit * u, unsigned int mask)
|
bool is_guard(const struct unit * u)
|
||||||
{
|
{
|
||||||
return is_guardian_r(u) && (getguard(u) & mask) != 0;
|
return is_guardian_r(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
unit *is_guarded(region * r, unit * u, unsigned int mask)
|
unit *is_guarded(region * r, unit * u)
|
||||||
{
|
{
|
||||||
unit *u2;
|
unit *u2;
|
||||||
int noguards = 1;
|
int noguards = 1;
|
||||||
|
@ -166,7 +142,7 @@ unit *is_guarded(region * r, unit * u, unsigned int mask)
|
||||||
for (u2 = r->units; u2; u2 = u2->next) {
|
for (u2 = r->units; u2; u2 = u2->next) {
|
||||||
if (is_guardian_r(u2)) {
|
if (is_guardian_r(u2)) {
|
||||||
noguards = 0;
|
noguards = 0;
|
||||||
if (is_guardian_u(u2, u, mask)) {
|
if (is_guardian_u(u2, u)) {
|
||||||
/* u2 is our guard. stop processing (we might have to go further next time) */
|
/* u2 is our guard. stop processing (we might have to go further next time) */
|
||||||
return u2;
|
return u2;
|
||||||
}
|
}
|
||||||
|
|
24
src/guard.h
24
src/guard.h
|
@ -11,29 +11,13 @@ extern "C" {
|
||||||
|
|
||||||
typedef enum { E_GUARD_OK, E_GUARD_UNARMED, E_GUARD_NEWBIE, E_GUARD_FLEEING } guard_t;
|
typedef enum { E_GUARD_OK, E_GUARD_UNARMED, E_GUARD_NEWBIE, E_GUARD_FLEEING } guard_t;
|
||||||
|
|
||||||
#define GUARD_NONE 0
|
|
||||||
#define GUARD_TAX 1
|
|
||||||
/* Verhindert Steuereintreiben */
|
|
||||||
#define GUARD_TRAVELTHRU 8
|
|
||||||
/* Blockiert Durchreisende */
|
|
||||||
#define GUARD_LANDING 16
|
|
||||||
/* Verhindert Ausstieg + Weiterreise */
|
|
||||||
#define GUARD_CREWS 32
|
|
||||||
/* Verhindert Unterhaltung auf Schiffen */
|
|
||||||
#define GUARD_RECRUIT 64
|
|
||||||
/* Verhindert Rekrutieren */
|
|
||||||
#define GUARD_PRODUCE 128
|
|
||||||
/* Verhindert Abbau von Resourcen mit RTF_LIMITED */
|
|
||||||
#define GUARD_ALL 0xFFFF
|
|
||||||
|
|
||||||
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 getguard(const struct unit * u);
|
void setguard(struct unit * u, bool enabled);
|
||||||
void setguard(struct unit * u, unsigned int flags);
|
void guard(struct unit *u);
|
||||||
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);
|
||||||
bool is_guard(const struct unit *u, unsigned int mask);
|
bool is_guard(const struct unit *u);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ static void test_guard_unskilled(CuTest * tc)
|
||||||
ug = test_create_unit(test_create_faction(0), r);
|
ug = test_create_unit(test_create_faction(0), r);
|
||||||
i_change(&ug->items, itype, 1);
|
i_change(&ug->items, itype, 1);
|
||||||
set_level(ug, SK_MELEE, 1);
|
set_level(ug, SK_MELEE, 1);
|
||||||
setguard(ug, GUARD_ALL);
|
setguard(ug, true);
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u, GUARD_PRODUCE));
|
CuAssertPtrEquals(tc, 0, is_guarded(r, u, GUARD_PRODUCE));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ static void test_guard_armed(CuTest * tc)
|
||||||
ug = test_create_unit(test_create_faction(0), r);
|
ug = test_create_unit(test_create_faction(0), r);
|
||||||
i_change(&ug->items, itype, 1);
|
i_change(&ug->items, itype, 1);
|
||||||
set_level(ug, SK_MELEE, 2);
|
set_level(ug, SK_MELEE, 2);
|
||||||
setguard(ug, GUARD_ALL);
|
setguard(ug, true);
|
||||||
CuAssertPtrEquals(tc, ug, is_guarded(r, u, GUARD_PRODUCE));
|
CuAssertPtrEquals(tc, ug, is_guarded(r, u, GUARD_PRODUCE));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ static void test_is_guard(CuTest * tc)
|
||||||
ug = test_create_unit(test_create_faction(0), r);
|
ug = test_create_unit(test_create_faction(0), r);
|
||||||
i_change(&ug->items, itype, 1);
|
i_change(&ug->items, itype, 1);
|
||||||
set_level(ug, SK_MELEE, 2);
|
set_level(ug, SK_MELEE, 2);
|
||||||
setguard(ug, GUARD_ALL);
|
setguard(ug, true);
|
||||||
CuAssertIntEquals(tc, 1, armedmen(ug, false));
|
CuAssertIntEquals(tc, 1, armedmen(ug, false));
|
||||||
CuAssertTrue(tc, is_guard(ug, GUARD_RECRUIT));
|
CuAssertTrue(tc, is_guard(ug, GUARD_RECRUIT));
|
||||||
set_level(ug, SK_MELEE, 1);
|
set_level(ug, SK_MELEE, 1);
|
||||||
|
@ -109,7 +109,7 @@ static void test_guard_unarmed(CuTest * tc)
|
||||||
r = test_create_region(0, 0, 0);
|
r = test_create_region(0, 0, 0);
|
||||||
u = test_create_unit(test_create_faction(0), r);
|
u = test_create_unit(test_create_faction(0), r);
|
||||||
ug = test_create_unit(test_create_faction(rc), r);
|
ug = test_create_unit(test_create_faction(rc), r);
|
||||||
setguard(ug, GUARD_ALL);
|
setguard(ug, true);
|
||||||
CuAssertPtrEquals(tc, ug, is_guarded(r, u, GUARD_PRODUCE));
|
CuAssertPtrEquals(tc, ug, is_guarded(r, u, GUARD_PRODUCE));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ static void test_guard_monsters(CuTest * tc)
|
||||||
r = test_create_region(0, 0, 0);
|
r = test_create_region(0, 0, 0);
|
||||||
u = test_create_unit(test_create_faction(0), r);
|
u = test_create_unit(test_create_faction(0), r);
|
||||||
ug = test_create_unit(get_monsters(), r);
|
ug = test_create_unit(get_monsters(), r);
|
||||||
setguard(ug, GUARD_ALL);
|
setguard(ug, true);
|
||||||
CuAssertPtrEquals(tc, ug, is_guarded(r, u, GUARD_PRODUCE));
|
CuAssertPtrEquals(tc, ug, is_guarded(r, u, GUARD_PRODUCE));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ static void destroy_road(unit * u, int nmax, struct order *ord)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u2 = r->units; u2; u2 = u2->next) {
|
for (u2 = r->units; u2; u2 = u2->next) {
|
||||||
if (u2->faction != u->faction && is_guard(u2, GUARD_TAX)
|
if (u2->faction != u->faction && is_guard(u2)
|
||||||
&& cansee(u2->faction, u->region, u, 0)
|
&& cansee(u2->faction, u->region, u, 0)
|
||||||
&& !alliedunit(u, u2->faction, HELP_GUARD)) {
|
&& !alliedunit(u, u2->faction, HELP_GUARD)) {
|
||||||
cmistake(u, ord, 70, MSG_EVENT);
|
cmistake(u, ord, 70, MSG_EVENT);
|
||||||
|
|
|
@ -948,7 +948,7 @@ void move_unit(unit * u, region * r, unit ** ulist)
|
||||||
if (!ulist)
|
if (!ulist)
|
||||||
ulist = (&r->units);
|
ulist = (&r->units);
|
||||||
if (u->region) {
|
if (u->region) {
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
fset(u, UFL_MOVED);
|
fset(u, UFL_MOVED);
|
||||||
if (u->ship || u->building) {
|
if (u->ship || u->building) {
|
||||||
/* can_leave must be checked in travel_i */
|
/* can_leave must be checked in travel_i */
|
||||||
|
|
12
src/laws.c
12
src/laws.c
|
@ -2556,7 +2556,7 @@ int guard_off_cmd(unit * u, struct order *ord)
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
|
|
||||||
if (getparam(u->faction->locale) == P_NOT) {
|
if (getparam(u->faction->locale) == P_NOT) {
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2698,7 +2698,7 @@ int guard_on_cmd(unit * u, struct order *ord)
|
||||||
else {
|
else {
|
||||||
int err = can_start_guarding(u);
|
int err = can_start_guarding(u);
|
||||||
if (err == E_GUARD_OK) {
|
if (err == E_GUARD_OK) {
|
||||||
guard(u, GUARD_ALL);
|
setguard(u, true);
|
||||||
}
|
}
|
||||||
else if (err == E_GUARD_UNARMED) {
|
else if (err == E_GUARD_UNARMED) {
|
||||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", ""));
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", ""));
|
||||||
|
@ -4171,7 +4171,7 @@ int siege_cmd(unit * u, order * ord)
|
||||||
return 80;
|
return 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_guard(u, GUARD_TRAVELTHRU)) {
|
if (!is_guard(u)) {
|
||||||
/* abbruch, wenn die einheit nicht vorher die region bewacht - als
|
/* abbruch, wenn die einheit nicht vorher die region bewacht - als
|
||||||
* warnung fuer alle anderen! */
|
* warnung fuer alle anderen! */
|
||||||
cmistake(u, ord, 81, MSG_EVENT);
|
cmistake(u, ord, 81, MSG_EVENT);
|
||||||
|
@ -4485,7 +4485,7 @@ cansee(const faction * f, const region * r, const unit * u, int modifier)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* simple visibility, just gotta have a unit in the region to see 'em */
|
/* simple visibility, just gotta have a unit in the region to see 'em */
|
||||||
if (is_guard(u, GUARD_ALL) != 0 || usiege(u) || u->building || u->ship) {
|
if (is_guard(u) || usiege(u) || u->building || u->ship) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4524,7 +4524,7 @@ bool cansee_unit(const unit * u, const unit * target, int modifier)
|
||||||
else {
|
else {
|
||||||
int n, rings, o;
|
int n, rings, o;
|
||||||
|
|
||||||
if (is_guard(target, GUARD_ALL) != 0 || usiege(target) || target->building
|
if (is_guard(target) || usiege(target) || target->building
|
||||||
|| target->ship) {
|
|| target->ship) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4568,7 +4568,7 @@ cansee_durchgezogen(const faction * f, const region * r, const unit * u,
|
||||||
else {
|
else {
|
||||||
int rings;
|
int rings;
|
||||||
|
|
||||||
if (is_guard(u, GUARD_ALL) != 0 || usiege(u) || u->building || u->ship) {
|
if (is_guard(u) || usiege(u) || u->building || u->ship) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,7 @@ static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
|
||||||
/* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an
|
/* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an
|
||||||
* und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */
|
* und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */
|
||||||
money = 0;
|
money = 0;
|
||||||
if (attacks && is_guard(udragon, GUARD_TAX)) {
|
if (attacks && is_guard(udragon)) {
|
||||||
money += monster_attacks(udragon, true, true);
|
money += monster_attacks(udragon, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,7 +735,7 @@ void plan_monsters(faction * f)
|
||||||
setstatus(u, ST_FIGHT);
|
setstatus(u, ST_FIGHT);
|
||||||
/* all monsters fight */
|
/* all monsters fight */
|
||||||
}
|
}
|
||||||
if (attacking && (!r->land || is_guard(u, GUARD_TAX))) {
|
if (attacking && (!r->land || is_guard(u))) {
|
||||||
monster_attacks(u, true, false);
|
monster_attacks(u, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ static void test_monsters_attack(CuTest * tc)
|
||||||
|
|
||||||
create_monsters(&f, &f2, &u, &m);
|
create_monsters(&f, &f2, &u, &m);
|
||||||
|
|
||||||
guard(m, GUARD_TAX);
|
setguard(m, true);
|
||||||
|
|
||||||
config_set("rules.monsters.attack_chance", "1");
|
config_set("rules.monsters.attack_chance", "1");
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ static void test_monsters_waiting(CuTest * tc)
|
||||||
unit *u, *m;
|
unit *u, *m;
|
||||||
|
|
||||||
create_monsters(&f, &f2, &u, &m);
|
create_monsters(&f, &f2, &u, &m);
|
||||||
guard(m, GUARD_TAX);
|
setguard(m, true);
|
||||||
fset(m, UFL_ISNEW);
|
fset(m, UFL_ISNEW);
|
||||||
monster_attacks(m, false, false);
|
monster_attacks(m, false, false);
|
||||||
CuAssertPtrEquals(tc, 0, find_order("attack 1", m));
|
CuAssertPtrEquals(tc, 0, find_order("attack 1", m));
|
||||||
|
@ -150,8 +150,8 @@ static void test_monsters_attack_not(CuTest * tc)
|
||||||
|
|
||||||
create_monsters(&f, &f2, &u, &m);
|
create_monsters(&f, &f2, &u, &m);
|
||||||
|
|
||||||
guard(m, GUARD_TAX);
|
setguard(m, true);
|
||||||
guard(u, GUARD_TAX);
|
setguard(u, true);
|
||||||
|
|
||||||
config_set("rules.monsters.attack_chance", "0");
|
config_set("rules.monsters.attack_chance", "0");
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ static void test_dragon_attacks_the_rich(CuTest * tc)
|
||||||
create_monsters(&f, &f2, &u, &m);
|
create_monsters(&f, &f2, &u, &m);
|
||||||
init_resources();
|
init_resources();
|
||||||
|
|
||||||
guard(m, GUARD_TAX);
|
setguard(m, true);
|
||||||
set_level(m, SK_WEAPONLESS, 10);
|
set_level(m, SK_WEAPONLESS, 10);
|
||||||
|
|
||||||
rsetmoney(findregion(0, 0), 1);
|
rsetmoney(findregion(0, 0), 1);
|
||||||
|
|
|
@ -934,7 +934,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r)
|
||||||
if (fval(u_race(reisender), RCF_ILLUSIONARY))
|
if (fval(u_race(reisender), RCF_ILLUSIONARY))
|
||||||
return NULL;
|
return NULL;
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
if (is_guard(u, GUARD_TRAVELTHRU)) {
|
if (is_guard(u)) {
|
||||||
int sk = effskill(u, SK_PERCEPTION, r);
|
int sk = effskill(u, SK_PERCEPTION, r);
|
||||||
if (invisible(reisender, u) >= reisender->number)
|
if (invisible(reisender, u) >= reisender->number)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1615,7 +1615,7 @@ static const region_list *travel_route(unit * u,
|
||||||
/* the unit has moved at least one region */
|
/* the unit has moved at least one region */
|
||||||
int walkmode;
|
int walkmode;
|
||||||
|
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
cycle_route(ord, u, steps);
|
cycle_route(ord, u, steps);
|
||||||
|
|
||||||
if (mode == TRAVEL_RUNNING) {
|
if (mode == TRAVEL_RUNNING) {
|
||||||
|
@ -1643,7 +1643,7 @@ static const region_list *travel_route(unit * u,
|
||||||
/* make orders for the followers */
|
/* make orders for the followers */
|
||||||
}
|
}
|
||||||
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
assert(u->region == current);
|
assert(u->region == current);
|
||||||
return iroute;
|
return iroute;
|
||||||
}
|
}
|
||||||
|
@ -2141,7 +2141,7 @@ static void travel(unit * u, region_list ** routep)
|
||||||
sh = NULL;
|
sh = NULL;
|
||||||
}
|
}
|
||||||
if (sh) {
|
if (sh) {
|
||||||
unit *guard = is_guarded(r, u, GUARD_LANDING);
|
unit *guard = is_guarded(r, u);
|
||||||
if (guard) {
|
if (guard) {
|
||||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
|
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
|
||||||
"region_guarded", "guard", guard));
|
"region_guarded", "guard", guard));
|
||||||
|
|
|
@ -1671,7 +1671,7 @@ static void guards(stream *out, const region * r, const faction * see)
|
||||||
/* Bewachung */
|
/* Bewachung */
|
||||||
|
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
if (is_guard(u, GUARD_ALL) != 0) {
|
if (is_guard(u) != 0) {
|
||||||
faction *f = u->faction;
|
faction *f = u->faction;
|
||||||
faction *fv = visible_faction(see, u);
|
faction *fv = visible_faction(see, u);
|
||||||
|
|
||||||
|
|
|
@ -582,7 +582,7 @@ size_t size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_guard(u, GUARD_ALL) != 0) {
|
if (is_guard(u)) {
|
||||||
bufp = STRLCPY(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
bufp = STRLCPY(bufp, LOC(f->locale, "unit_guards"), size);
|
bufp = STRLCPY(bufp, LOC(f->locale, "unit_guards"), size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 */
|
||||||
setguard(keeper, GUARD_ALL);
|
setguard(keeper, true);
|
||||||
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()) {
|
||||||
|
@ -2386,7 +2386,6 @@ void patzer_peasantmob(const castorder * co)
|
||||||
create_unit(r, f, n, get_race(RC_PEASANT), 0, LOC(f->locale, "angry_mob"),
|
create_unit(r, f, n, get_race(RC_PEASANT), 0, LOC(f->locale, "angry_mob"),
|
||||||
NULL);
|
NULL);
|
||||||
fset(u, UFL_ISNEW);
|
fset(u, UFL_ISNEW);
|
||||||
/* guard(u, GUARD_ALL); hier zu frueh! Befehl BEWACHE setzten */
|
|
||||||
addlist(&u->orders, create_order(K_GUARD, lang, NULL));
|
addlist(&u->orders, create_order(K_GUARD, lang, NULL));
|
||||||
set_order(&u->thisorder, default_order(lang));
|
set_order(&u->thisorder, default_order(lang));
|
||||||
a = a_new(&at_unitdissolve);
|
a = a_new(&at_unitdissolve);
|
||||||
|
@ -3746,7 +3745,7 @@ static int sp_rallypeasantmob(castorder * co)
|
||||||
rsetpeasants(r, rpeasants(r) + u->number);
|
rsetpeasants(r, rpeasants(r) + u->number);
|
||||||
rsetmoney(r, rmoney(r) + get_money(u));
|
rsetmoney(r, rmoney(r) + get_money(u));
|
||||||
set_money(u, 0);
|
set_money(u, 0);
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
set_number(u, 0);
|
set_number(u, 0);
|
||||||
erfolg = cast_level;
|
erfolg = cast_level;
|
||||||
}
|
}
|
||||||
|
@ -3813,7 +3812,7 @@ static int sp_raisepeasantmob(castorder * co)
|
||||||
create_unit(r, monsters, n, get_race(RC_PEASANT), 0, LOC(monsters->locale,
|
create_unit(r, monsters, n, get_race(RC_PEASANT), 0, LOC(monsters->locale,
|
||||||
"furious_mob"), NULL);
|
"furious_mob"), NULL);
|
||||||
fset(u, UFL_ISNEW);
|
fset(u, UFL_ISNEW);
|
||||||
guard(u, GUARD_ALL);
|
setguard(u, true);
|
||||||
a = a_new(&at_unitdissolve);
|
a = a_new(&at_unitdissolve);
|
||||||
a->data.ca[0] = 1; /* An rpeasants(r). */
|
a->data.ca[0] = 1; /* An rpeasants(r). */
|
||||||
a->data.ca[1] = 15; /* 15% */
|
a->data.ca[1] = 15; /* 15% */
|
||||||
|
|
|
@ -1437,7 +1437,7 @@ int sp_denyattack(struct castorder * co)
|
||||||
leave(mage, false);
|
leave(mage, false);
|
||||||
}
|
}
|
||||||
/* und bewachen nicht */
|
/* und bewachen nicht */
|
||||||
setguard(mage, GUARD_NONE);
|
setguard(mage, false);
|
||||||
/* irgendwie den langen befehl sperren */
|
/* irgendwie den langen befehl sperren */
|
||||||
/* fset(fi, FIG_ATTACKED); */
|
/* fset(fi, FIG_ATTACKED); */
|
||||||
|
|
||||||
|
@ -1800,7 +1800,7 @@ int sp_undeadhero(struct castorder * co)
|
||||||
unit_setinfo(u, NULL);
|
unit_setinfo(u, NULL);
|
||||||
}
|
}
|
||||||
setstatus(u, du->status);
|
setstatus(u, du->status);
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
for (ilist = &du->items; *ilist;) {
|
for (ilist = &du->items; *ilist;) {
|
||||||
item *itm = *ilist;
|
item *itm = *ilist;
|
||||||
int loot = itm->number * j / du->number;
|
int loot = itm->number * j / du->number;
|
||||||
|
|
|
@ -463,7 +463,7 @@ static void sink_ship(region * r, ship * sh, unit * saboteur)
|
||||||
}
|
}
|
||||||
leave_ship(u);
|
leave_ship(u);
|
||||||
if (r != safety) {
|
if (r != safety) {
|
||||||
setguard(u, GUARD_NONE);
|
setguard(u, false);
|
||||||
}
|
}
|
||||||
while (u->items) {
|
while (u->items) {
|
||||||
i_remove(&u->items, u->items);
|
i_remove(&u->items, u->items);
|
||||||
|
|
Loading…
Reference in New Issue