diff --git a/src/battle.c b/src/battle.c index 9fb58751d..18e506192 100644 --- a/src/battle.c +++ b/src/battle.c @@ -4307,6 +4307,9 @@ void do_battle(region * r) /* Auswirkungen berechnen: */ aftermath(b); + if (rule_force_leave(FORCE_LEAVE_POSTCOMBAT)) { + force_leave(b->region); + } /* Hier ist das Gefecht beendet, und wir können die * Hilfsstrukturen * wieder löschen: */ diff --git a/src/laws.c b/src/laws.c index fcb7b10ca..b93482716 100755 --- a/src/laws.c +++ b/src/laws.c @@ -4337,6 +4337,11 @@ void force_leave(region *r) { } } +bool rule_force_leave(int flags) { + int rules = get_param_int(global.parameters, "rules.owners.force_leave", 0); + return (rules&flags) == flags; +} + static void maintain_buildings_1(region * r) { maintain_buildings(r, false); @@ -4438,7 +4443,7 @@ void init_processor(void) add_proc_unit(p, follow_unit, "Folge auf Einheiten setzen"); p += 10; /* rest rng again before economics */ - if (get_param_int(global.parameters, "rules.owners.force_leave", 0)) { + if (rule_force_leave(FORCE_LEAVE_ALL)) { add_proc_region(p, force_leave, "kick non-allies out of buildings/ships"); } add_proc_region(p, economics, "Zerstoeren, Geben, Rekrutieren, Vergessen"); diff --git a/src/laws.h b/src/laws.h index 4f4188448..6da5ed5de 100755 --- a/src/laws.h +++ b/src/laws.h @@ -105,9 +105,13 @@ extern "C" { bool seefaction(const struct faction *f, const struct region *r, const struct unit *u, int modifier); int armedmen(const struct unit *u, bool siege_weapons); - void force_leave(struct region *r); int peasant_luck_effect(int peasants, int luck, int maxp, double variance); + #define FORCE_LEAVE_POSTCOMBAT 1 + #define FORCE_LEAVE_ALL 2 + bool rule_force_leave(int flag); + void force_leave(struct region *r); + #ifdef __cplusplus } #endif diff --git a/src/laws.test.c b/src/laws.test.c index 609b93d03..4c9f43ba5 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -230,6 +230,21 @@ static void test_display_cmd(CuTest *tc) { test_cleanup(); } +static void test_rule_force_leave(CuTest *tc) { + set_param(&global.parameters, "rules.owners.force_leave", "0"); + CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL)); + CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT)); + set_param(&global.parameters, "rules.owners.force_leave", "1"); + CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL)); + CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT)); + set_param(&global.parameters, "rules.owners.force_leave", "2"); + CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL)); + CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT)); + set_param(&global.parameters, "rules.owners.force_leave", "3"); + CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL)); + CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT)); +} + static void test_force_leave_buildings(CuTest *tc) { ally *al; region *r; @@ -779,6 +794,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_enter_building); SUITE_ADD_TEST(suite, test_enter_ship); SUITE_ADD_TEST(suite, test_display_cmd); + SUITE_ADD_TEST(suite, test_rule_force_leave); SUITE_ADD_TEST(suite, test_force_leave_buildings); SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean);