STIRB PARTEI hat immer nur eine Einheit übergeben.

This commit is contained in:
Enno Rehling 2019-07-04 20:44:11 +02:00
parent 4ea0e8b723
commit 05b8477b8a
3 changed files with 37 additions and 5 deletions

View File

@ -963,7 +963,10 @@ void transfer_faction(faction *fsrc, faction *fdst) {
} }
} }
for (u = fsrc->units; u != NULL; u = u->nextF) { u = fsrc->units;
while (u) {
unit *unext = u->nextF;
if (u_race(u) == fdst->race) { if (u_race(u) == fdst->race) {
u->flags &= ~UFL_HERO; u->flags &= ~UFL_HERO;
if (give_unit_allowed(u) == 0) { if (give_unit_allowed(u) == 0) {
@ -978,12 +981,14 @@ void transfer_faction(faction *fsrc, faction *fdst) {
} }
} }
if (i != u->skill_size) { if (i != u->skill_size) {
u = u->nextF;
continue; continue;
} }
} }
u_setfaction(u, fdst); u_setfaction(u, fdst);
} }
} }
u = unext;
} }
} }
@ -1015,14 +1020,16 @@ int quit_cmd(unit * u, struct order *ord)
else { else {
unit *u2; unit *u2;
for (u2 = u->region->units; u2; u2 = u2->next) { for (u2 = u->region->units; u2; u2 = u2->next) {
if (u2->faction == f2 && ucontact(u2, u)) { if (u2->faction == f2) {
transfer_faction(u->faction, u2->faction); if (ucontact(u2, u)) {
break; transfer_faction(u->faction, u2->faction);
break;
}
} }
} }
if (u2 == NULL) { if (u2 == NULL) {
/* no target unit found */ /* no target unit found */
cmistake(u, ord, 0, MSG_EVENT); cmistake(u, ord, 40, MSG_EVENT);
flags = 0; flags = 0;
} }
} }

View File

@ -93,6 +93,7 @@ extern "C" {
int reserve_cmd(struct unit *u, struct order *ord); int reserve_cmd(struct unit *u, struct order *ord);
int reserve_self(struct unit *u, struct order *ord); int reserve_self(struct unit *u, struct order *ord);
int claim_cmd(struct unit *u, struct order *ord); int claim_cmd(struct unit *u, struct order *ord);
void transfer_faction(struct faction *fsrc, struct faction *fdst);
void nmr_warnings(void); void nmr_warnings(void);
bool nmr_death(const struct faction * f, int turn, int timeout); bool nmr_death(const struct faction * f, int turn, int timeout);

View File

@ -2012,6 +2012,29 @@ static void test_quit_transfer_hero(CuTest *tc) {
test_teardown(); test_teardown();
} }
static void test_transfer_faction(CuTest *tc) {
faction *f1, *f2;
unit *u1, *u2, *u3, *u4;
region *r;
test_setup();
r = test_create_plain(0, 0);
f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL);
u1 = test_create_unit(f1, r);
u2 = test_create_unit(f1, r);
u_setrace(u2, test_create_race("smurf"));
u3 = test_create_unit(f2, r);
u4 = test_create_unit(f1, r);
transfer_faction(f1, f2);
CuAssertPtrEquals(tc, f2, u1->faction);
CuAssertPtrEquals(tc, f1, u2->faction);
CuAssertPtrEquals(tc, f2, u3->faction);
CuAssertPtrEquals(tc, f2, u4->faction);
test_teardown();
}
CuSuite *get_laws_suite(void) CuSuite *get_laws_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -2092,6 +2115,7 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_quit_transfer_limited); SUITE_ADD_TEST(suite, test_quit_transfer_limited);
SUITE_ADD_TEST(suite, test_quit_transfer_migrants); SUITE_ADD_TEST(suite, test_quit_transfer_migrants);
SUITE_ADD_TEST(suite, test_quit_transfer_hero); SUITE_ADD_TEST(suite, test_quit_transfer_hero);
SUITE_ADD_TEST(suite, test_transfer_faction);
return suite; return suite;
} }