paused factions do not execute orders, do not join battles.

lots of change, didn't write any tests for this yet.
This commit is contained in:
Enno Rehling 2021-05-21 04:14:39 +02:00
parent 0fcc1b8d29
commit 48fd0bd4af
13 changed files with 75 additions and 37 deletions

View File

@ -39,7 +39,7 @@ int autostudy_init(scholar scholars[], int max_scholars, unit **units, skill_t *
if (kwd == K_AUTOSTUDY) {
if (f == u->faction) {
unext = u->next;
if (long_order_allowed(u)) {
if (long_order_allowed(u, false)) {
scholar * st = scholars + nscholars;
skill_t sk = getskill(u->faction->locale);
if (skill == NOSKILL && sk != NOSKILL) {
@ -198,6 +198,7 @@ void do_autostudy(region *r)
assert(batchsize <= MAXSCHOLARS);
}
for (u = r->units; u; u = u->next) {
if (is_paused(u->faction)) continue;
if (!fval(u, UFL_MARK)) {
unit *ulist = u;
int sum_scholars = 0;

View File

@ -3524,6 +3524,8 @@ static void join_allies(battle * b)
faction *f = u->faction;
fighter *c = NULL;
if (is_paused(u->faction)) continue;
for (s = b->sides; s != s_end; ++s) {
side *se;
/* Wenn alle attackierten noch FFL_NOAID haben, dann kaempfe nicht mit. */
@ -3648,8 +3650,7 @@ static bool start_battle(region * r, battle ** bp)
bool fighting = false;
for (u = r->units; u != NULL; u = u->next) {
if (fval(u, UFL_LONGACTION))
continue;
if (!long_order_allowed(u, true)) continue;
if (u->number > 0) {
order *ord;
@ -3683,10 +3684,6 @@ static bool start_battle(region * r, battle ** bp)
continue;
}
/* ist ein Fluechtling aus einem andern Kampf */
if (fval(u, UFL_LONGACTION))
continue;
if (curse_active(get_curse(r->attribs, &ct_peacezone))) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "peace_active", ""));
continue;
@ -3922,6 +3919,9 @@ void force_leave(region *r, battle *b) {
for (u = r->units; u; u = u->next) {
unit *uo = NULL;
if (is_paused(u->faction)) continue;
if (u->building) {
uo = building_owner(u->building);
}

View File

@ -392,6 +392,9 @@ void economics(region * r)
for (u = r->units; u; u = u->next) {
order *ord;
if (is_paused(u->faction)) continue;
if (u->number > 0) {
order* transfer = NULL;
for (ord = u->orders; ord; ord = ord->next) {
@ -428,6 +431,8 @@ void destroy(region *r) {
for (u = r->units; u; u = u->next) {
order *ord = u->thisorder;
keyword_t kwd = getkeyword(ord);
if (is_paused(u->faction)) continue;
if (kwd == K_DESTROY) {
if (destroy_cmd(u, ord) == 0) {
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
@ -2299,7 +2304,7 @@ void auto_work(region * r)
long total = 0;
for (u = r->units; u; u = u->next) {
if (!(u->flags & UFL_LONGACTION) && !is_monsters(u->faction)) {
if (long_order_allowed(u, false) && !is_monsters(u->faction)) {
int work = work_cmd(u, NULL, &nextrequest);
if (work) {
total += work;
@ -2403,12 +2408,7 @@ void produce(struct region *r)
bool trader = false;
keyword_t todo;
if (fval(u, UFL_LONGACTION))
continue;
if (u_race(u) == rc_insect && r_insectstalled(r) &&
!is_cursed(u->attribs, &ct_insectfur))
continue;
if (!long_order_allowed(u, false)) continue;
if (fval(u, UFL_LONGACTION) && u->thisorder == NULL) {
/* this message was already given in laws.c:update_long_order
@ -2417,6 +2417,11 @@ void produce(struct region *r)
continue;
}
if (u_race(u) == rc_insect && r_insectstalled(r) &&
!is_cursed(u->attribs, &ct_insectfur)) {
continue;
}
for (ord = u->orders; ord; ord = ord->next) {
keyword_t kwd = getkeyword(ord);
if (kwd == K_BUY) {

View File

@ -327,7 +327,7 @@ static void execute(keyword_t kwd)
unit **up = &r->units;
while (*up) {
unit *u = *up;
if (u->number) {
if (u->number > 0 && !is_paused(u->faction)) {
const struct locale *lang = u->faction->locale;
order *ord;
for (ord = u->orders; ord; ord = ord->next) {

View File

@ -789,7 +789,7 @@ void nmr_warnings(void)
faction *f, *fa;
#define HELP_NMR (HELP_GUARD|HELP_MONEY)
for (f = factions; f; f = f->next) {
if (!fval(f, FFL_NOIDLEOUT) && turn > f->lastorders) {
if (!fval(f, FFL_NOIDLEOUT|FFL_PAUSED) && turn > f->lastorders) {
ADDMSG(&f->msgs, msg_message("nmr_warning", ""));
if (turn - f->lastorders == NMRTimeout() - 1) {
ADDMSG(&f->msgs, msg_message("nmr_warning_final", ""));
@ -1188,6 +1188,9 @@ static void do_contact(region * r)
unit * u;
for (u = r->units; u; u = u->next) {
order *ord;
if (is_paused(u->faction)) continue;
for (ord = u->orders; ord; ord = ord->next) {
keyword_t kwd = getkeyword(ord);
if (kwd == K_CONTACT) {
@ -1205,6 +1208,8 @@ void do_enter(struct region *r, bool is_final_attempt)
unit *u = *uptr;
order **ordp = &u->orders;
if (is_paused(u->faction)) continue;
while (*ordp) {
order *ord = *ordp;
if (getkeyword(ord) == K_ENTER) {
@ -1349,7 +1354,7 @@ void quit(void)
faction **fptr = &factions;
while (*fptr) {
faction *f = *fptr;
if (f->flags & FFL_QUIT) {
if ((f->flags & FFL_QUIT) && !is_paused(f)) {
destroyfaction(fptr);
}
else {
@ -2939,6 +2944,8 @@ void new_units(void)
for (u = r->units; u; u = u->next) {
order **ordp = &u->orders;
if (is_paused(u->faction)) continue;
/* this needs to happen very early in the game somewhere. since this is
** pretty much the first function called per turn, and I am lazy, I
** decree that it goes here */
@ -3588,20 +3595,23 @@ void add_proc_unit(int priority, void(*process) (unit *), const char *name)
}
}
bool long_order_allowed(const unit *u)
bool long_order_allowed(const unit *u, bool flags_only)
{
const region *r = u->region;
if (is_paused(u->faction)) return false;
if (fval(u, UFL_LONGACTION)) {
/* this message was already given in laws.update_long_order
cmistake(u, ord, 52, MSG_PRODUCE);
*/
return false;
}
else if (fval(r->terrain, SEA_REGION)
&& u_race(u) != get_race(RC_AQUARIAN)
&& !(u_race(u)->flags & RCF_SWIM)) {
/* error message disabled by popular demand */
return false;
if (fval(r->terrain, SEA_REGION) && !(u_race(u)->flags & RCF_SWIM)) {
if (flags_only) return false;
else if (u_race(u) != get_race(RC_AQUARIAN)) {
/* error message disabled by popular demand */
return false;
}
}
return true;
}
@ -3650,6 +3660,8 @@ void process(void)
for (u = r->units; u; u = u->next) {
processor *porder, *punit = pregion;
if (is_paused(u->faction)) continue;
while (punit && punit->priority == prio && punit->type == PR_UNIT) {
punit->data.per_unit.process(u);
punit = punit->next;
@ -3680,7 +3692,7 @@ void process(void)
cmistake(u, ord, 224, MSG_MAGIC);
ord = NULL;
}
else if (!long_order_allowed(u)) {
else if (!long_order_allowed(u, false)) {
ord = NULL;
}
}

View File

@ -47,7 +47,7 @@ extern "C" {
void update_long_order(struct unit *u);
void sinkships(struct region * r);
void do_enter(struct region *r, bool is_final_attempt);
bool long_order_allowed(const struct unit *u);
bool long_order_allowed(const struct unit *u, bool flags_only);
bool password_wellformed(const char *password);
int locale_cmd(struct unit *u, struct order *ord);

View File

@ -1892,9 +1892,12 @@ static void test_long_orders(CuTest *tc) {
test_setup();
u = test_create_unit(test_create_faction(), test_create_plain(0, 0));
CuAssertTrue(tc, long_order_allowed(u));
CuAssertTrue(tc, long_order_allowed(u, true));
u->flags |= UFL_LONGACTION;
CuAssertTrue(tc, !long_order_allowed(u));
CuAssertTrue(tc, !long_order_allowed(u, true));
u->flags -= UFL_LONGACTION;
u->faction->flags |= FFL_PAUSED;
CuAssertTrue(tc, !long_order_allowed(u, true));
test_teardown();
}
@ -1905,13 +1908,21 @@ static void test_long_order_on_ocean(CuTest *tc) {
test_setup();
rc = test_create_race("pikachu");
u = test_create_unit(test_create_faction_ex(rc, NULL), test_create_ocean(0, 0));
CuAssertTrue(tc, !long_order_allowed(u));
CuAssertTrue(tc, !long_order_allowed(u, false));
rc->flags |= RCF_SWIM;
CuAssertTrue(tc, long_order_allowed(u));
CuAssertTrue(tc, long_order_allowed(u, false));
u->faction->flags |= FFL_PAUSED;
CuAssertTrue(tc, !long_order_allowed(u, false));
u->faction->flags -= FFL_PAUSED;
rc = test_create_race("aquarian");
u = test_create_unit(test_create_faction_ex(rc, NULL), u->region);
CuAssertTrue(tc, long_order_allowed(u));
CuAssertTrue(tc, long_order_allowed(u, false));
CuAssertTrue(tc, !long_order_allowed(u, true));
u->faction->flags |= FFL_PAUSED;
CuAssertTrue(tc, !long_order_allowed(u, true));
CuAssertTrue(tc, !long_order_allowed(u, false));
u->faction->flags -= FFL_PAUSED;
test_teardown();
}

View File

@ -2760,7 +2760,7 @@ void magic(void)
!is_cursed(u->attribs, &ct_insectfur))
continue;
if (fval(u, UFL_WERE | UFL_LONGACTION)) {
if (fval(u, UFL_WERE | UFL_LONGACTION) || is_paused(u->faction)) {
continue;
}

View File

@ -1184,6 +1184,7 @@ static bool transport(unit * ut, unit * u)
static bool can_move(const unit * u)
{
if (is_paused(u->faction)) return false;
if (u_race(u)->flags & RCF_CANNOTMOVE)
return false;
if (get_movement(&u->attribs, MV_CANNOTMOVE))
@ -2366,7 +2367,7 @@ static void move_followers(void)
while (*up != NULL) {
unit *u = *up;
if (!fval(u, UFL_MOVED | UFL_NOTMOVING)) {
if (!fval(u, UFL_MOVED | UFL_NOTMOVING) && !is_paused(u->faction)) {
order *ord;
for (ord = u->orders; ord; ord = ord->next) {
@ -2419,7 +2420,7 @@ static void move_pirates(void)
while (*up) {
unit *u = *up;
if (!fval(u, UFL_NOTMOVING) && getkeyword(u->thisorder) == K_PIRACY) {
if (!fval(u, UFL_NOTMOVING) && !is_paused(u->faction) && getkeyword(u->thisorder) == K_PIRACY) {
piracy_cmd(u);
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
}
@ -2450,6 +2451,7 @@ void move_units(void)
while (*up) {
unit* u = *up;
up = &u->next;
if (is_paused(u->faction)) continue;
if (!u->ship || ship_owner(u->ship) != u) {
keyword_t kword = getkeyword(u->thisorder);
@ -2503,6 +2505,7 @@ void move_ships(void) {
unit* u = *up;
up = &u->next;
if (is_paused(u->faction)) continue;
if (u->ship && !fval(u->ship, SF_DRIFTED)) {
keyword_t kword = getkeyword(u->thisorder);

View File

@ -431,6 +431,7 @@ static void demon_skillchanges(void)
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
if (is_paused(u->faction)) continue;
if (u_race(u) == rc_demon) {
demon_skillchange(u);
}

View File

@ -479,6 +479,8 @@ void recruit(region * r)
for (u = r->units; u; u = u->next) {
order *ord;
if (is_paused(u->faction)) continue;
if ((rules_recruit & RECRUIT_MERGE) || u->number == 0) {
for (ord = u->orders; ord; ord = ord->next) {
if (getkeyword(ord) == K_RECRUIT) {

View File

@ -36,12 +36,15 @@ void renumber_factions(void)
} *renum = NULL, *rp;
faction *f;
for (f = factions; f; f = f->next) {
attrib *a = a_find(f->attribs, &at_number);
attrib *a;
int want;
struct renum **rn;
if (!a)
continue;
if (is_paused(f)) continue;
a = a_find(f->attribs, &at_number);
if (!a) continue;
want = a->data.i;
if (!faction_id_is_unused(want)) {
a_remove(&f->attribs, a);

View File

@ -21,7 +21,7 @@ void restack_units(void)
bool sorted = false;
while (*up) {
unit *u = *up;
if (!fval(u, UFL_MARK)) {
if (!fval(u, UFL_MARK) && !is_paused(u->faction)) {
struct order *ord;
for (ord = u->orders; ord; ord = ord->next) {
if (getkeyword(ord) == K_SORT) {