forked from github/server
Merge pull request #232 from badgerman/develop
after combat, eject enemies only
This commit is contained in:
commit
d2037a5cd9
48
src/battle.c
48
src/battle.c
|
@ -4235,6 +4235,52 @@ static void battle_flee(battle * b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_enemy(battle *b, unit *u1, unit *u2) {
|
||||||
|
if (u1->faction != u2->faction) {
|
||||||
|
if (b) {
|
||||||
|
side *es, *s1 = 0, *s2 = 0;
|
||||||
|
for (es = b->sides; es != b->sides + b->nsides; ++es) {
|
||||||
|
if (!s1 && es->faction == u1->faction) s1 = es;
|
||||||
|
else if (!s2 && es->faction == u2->faction) s2 = es;
|
||||||
|
if (s1 && s2) break;
|
||||||
|
}
|
||||||
|
return enemy(s1, s2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return !help_enter(u1, u2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void force_leave(region *r, battle *b) {
|
||||||
|
unit *u;
|
||||||
|
|
||||||
|
for (u = r->units; u; u = u->next) {
|
||||||
|
unit *uo = NULL;
|
||||||
|
if (u->building) {
|
||||||
|
uo = building_owner(u->building);
|
||||||
|
}
|
||||||
|
if (u->ship && r->land) {
|
||||||
|
uo = ship_owner(u->ship);
|
||||||
|
}
|
||||||
|
if (uo && is_enemy(b, uo, u)) {
|
||||||
|
message *msg = NULL;
|
||||||
|
if (u->building) {
|
||||||
|
msg = msg_message("force_leave_building", "unit owner building", u, uo, u->building);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg = msg_message("force_leave_ship", "unit owner ship", u, uo, u->ship);
|
||||||
|
}
|
||||||
|
if (msg) {
|
||||||
|
ADDMSG(&u->faction->msgs, msg);
|
||||||
|
}
|
||||||
|
leave(u, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void do_battle(region * r)
|
void do_battle(region * r)
|
||||||
{
|
{
|
||||||
battle *b = NULL;
|
battle *b = NULL;
|
||||||
|
@ -4307,7 +4353,7 @@ void do_battle(region * r)
|
||||||
/* Auswirkungen berechnen: */
|
/* Auswirkungen berechnen: */
|
||||||
aftermath(b);
|
aftermath(b);
|
||||||
if (rule_force_leave(FORCE_LEAVE_POSTCOMBAT)) {
|
if (rule_force_leave(FORCE_LEAVE_POSTCOMBAT)) {
|
||||||
force_leave(b->region);
|
force_leave(b->region, b);
|
||||||
}
|
}
|
||||||
/* Hier ist das Gefecht beendet, und wir können die
|
/* Hier ist das Gefecht beendet, und wir können die
|
||||||
* Hilfsstrukturen * wieder löschen: */
|
* Hilfsstrukturen * wieder löschen: */
|
||||||
|
|
|
@ -270,6 +270,7 @@ extern "C" {
|
||||||
const struct group * g, unsigned int flags,
|
const struct group * g, unsigned int flags,
|
||||||
const struct faction * stealthfaction);
|
const struct faction * stealthfaction);
|
||||||
int skilldiff(troop at, troop dt, int dist);
|
int skilldiff(troop at, troop dt, int dist);
|
||||||
|
void force_leave(struct region *r, struct battle *b);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
30
src/laws.c
30
src/laws.c
|
@ -4307,34 +4307,12 @@ static void enter_2(region * r)
|
||||||
do_enter(r, 1);
|
do_enter(r, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool help_enter(unit *uo, unit *u) {
|
bool help_enter(unit *uo, unit *u) {
|
||||||
return uo->faction == u->faction || alliedunit(uo, u->faction, HELP_GUARD);
|
return uo->faction == u->faction || alliedunit(uo, u->faction, HELP_GUARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
void force_leave(region *r) {
|
static void do_force_leave(region *r) {
|
||||||
unit *u;
|
force_leave(r, NULL);
|
||||||
for (u = r->units; u; u = u->next) {
|
|
||||||
unit *uo = NULL;
|
|
||||||
if (u->building) {
|
|
||||||
uo = building_owner(u->building);
|
|
||||||
}
|
|
||||||
if (u->ship && r->land) {
|
|
||||||
uo = ship_owner(u->ship);
|
|
||||||
}
|
|
||||||
if (uo && !help_enter(uo, u)) {
|
|
||||||
message *msg = NULL;
|
|
||||||
if (u->building) {
|
|
||||||
msg = msg_message("force_leave_building", "unit owner building", u, uo, u->building);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
msg = msg_message("force_leave_ship", "unit owner ship", u, uo, u->ship);
|
|
||||||
}
|
|
||||||
if (msg) {
|
|
||||||
ADDMSG(&u->faction->msgs, msg);
|
|
||||||
}
|
|
||||||
leave(u, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rule_force_leave(int flags) {
|
bool rule_force_leave(int flags) {
|
||||||
|
@ -4450,7 +4428,7 @@ void init_processor(void)
|
||||||
|
|
||||||
p += 10; /* rest rng again before economics */
|
p += 10; /* rest rng again before economics */
|
||||||
if (rule_force_leave(FORCE_LEAVE_ALL)) {
|
if (rule_force_leave(FORCE_LEAVE_ALL)) {
|
||||||
add_proc_region(p, force_leave, "kick non-allies out of buildings/ships");
|
add_proc_region(p, do_force_leave, "kick non-allies out of buildings/ships");
|
||||||
}
|
}
|
||||||
add_proc_region(p, economics, "Zerstoeren, Geben, Rekrutieren, Vergessen");
|
add_proc_region(p, economics, "Zerstoeren, Geben, Rekrutieren, Vergessen");
|
||||||
add_proc_order(p, K_PROMOTION, promotion_cmd, 0, "Heldenbefoerderung");
|
add_proc_order(p, K_PROMOTION, promotion_cmd, 0, "Heldenbefoerderung");
|
||||||
|
|
|
@ -110,7 +110,7 @@ extern "C" {
|
||||||
#define FORCE_LEAVE_POSTCOMBAT 1
|
#define FORCE_LEAVE_POSTCOMBAT 1
|
||||||
#define FORCE_LEAVE_ALL 2
|
#define FORCE_LEAVE_ALL 2
|
||||||
bool rule_force_leave(int flag);
|
bool rule_force_leave(int flag);
|
||||||
void force_leave(struct region *r);
|
bool help_enter(struct unit *uo, struct unit *u);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
|
#include "battle.h"
|
||||||
|
|
||||||
#include <kernel/ally.h>
|
#include <kernel/ally.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
@ -261,8 +262,8 @@ static void test_force_leave_buildings(CuTest *tc) {
|
||||||
building_set_owner(u1);
|
building_set_owner(u1);
|
||||||
u_set_building(u2, b);
|
u_set_building(u2, b);
|
||||||
u_set_building(u3, b);
|
u_set_building(u3, b);
|
||||||
force_leave(r);
|
force_leave(r, NULL);
|
||||||
CuAssertPtrEquals_Msg(tc, "owner should not be forecd to leave", b, u1->building);
|
CuAssertPtrEquals_Msg(tc, "owner should not be forced to leave", b, u1->building);
|
||||||
CuAssertPtrEquals_Msg(tc, "same faction should not be forced to leave", b, u2->building);
|
CuAssertPtrEquals_Msg(tc, "same faction should not be forced to leave", b, u2->building);
|
||||||
CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u3->building);
|
CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u3->building);
|
||||||
msg = test_get_last_message(u3->faction->msgs);
|
msg = test_get_last_message(u3->faction->msgs);
|
||||||
|
@ -271,7 +272,7 @@ static void test_force_leave_buildings(CuTest *tc) {
|
||||||
u_set_building(u3, b);
|
u_set_building(u3, b);
|
||||||
al = ally_add(&u1->faction->allies, u3->faction);
|
al = ally_add(&u1->faction->allies, u3->faction);
|
||||||
al->status = HELP_GUARD;
|
al->status = HELP_GUARD;
|
||||||
force_leave(r);
|
force_leave(r, NULL);
|
||||||
CuAssertPtrEquals_Msg(tc, "allies should not be forced to leave", b, u3->building);
|
CuAssertPtrEquals_Msg(tc, "allies should not be forced to leave", b, u3->building);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -289,7 +290,7 @@ static void test_force_leave_ships(CuTest *tc) {
|
||||||
u_set_ship(u1, sh);
|
u_set_ship(u1, sh);
|
||||||
u_set_ship(u2, sh);
|
u_set_ship(u2, sh);
|
||||||
ship_set_owner(u1);
|
ship_set_owner(u1);
|
||||||
force_leave(r);
|
force_leave(r, NULL);
|
||||||
CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u2->ship);
|
CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u2->ship);
|
||||||
msg = test_get_last_message(u2->faction->msgs);
|
msg = test_get_last_message(u2->faction->msgs);
|
||||||
CuAssertStrEquals(tc, "force_leave_ship", test_get_messagetype(msg));
|
CuAssertStrEquals(tc, "force_leave_ship", test_get_messagetype(msg));
|
||||||
|
@ -308,7 +309,7 @@ static void test_force_leave_ships_on_ocean(CuTest *tc) {
|
||||||
u_set_ship(u1, sh);
|
u_set_ship(u1, sh);
|
||||||
u_set_ship(u2, sh);
|
u_set_ship(u2, sh);
|
||||||
ship_set_owner(u1);
|
ship_set_owner(u1);
|
||||||
force_leave(r);
|
force_leave(r, NULL);
|
||||||
CuAssertPtrEquals_Msg(tc, "no forcing out of ships on oceans", sh, u2->ship);
|
CuAssertPtrEquals_Msg(tc, "no forcing out of ships on oceans", sh, u2->ship);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue