implement post-combat forced leave from ship/building

This commit is contained in:
Enno Rehling 2015-06-19 07:53:11 +02:00
parent b630c9ee45
commit e7bffb7533
4 changed files with 30 additions and 2 deletions

View File

@ -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: */

View File

@ -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");

View File

@ -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

View File

@ -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);