Skip to content

Commit

Permalink
units without items given to peasants on QUIT (#1020)
Browse files Browse the repository at this point in the history
Sehr schön, sogar mit Tests!
  • Loading branch information
stm2 authored and ennorehling committed Nov 27, 2023
1 parent 7d3892a commit 66b7b13
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/kernel/faction.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,21 +426,21 @@ void destroyfaction(faction ** fp)
}

while (u) {
region *r = u->region;
/* give away your stuff, to ghosts if you cannot (quest items) */
if (u->items) {
region *r = u->region;
int result = gift_items(u, GIFT_FRIENDS | GIFT_PEASANTS);
if (result != 0) {
save_special_items(u);
}
if (r->land && playerrace(u_race(u))) {
const race *rc = u_race(u);
/* Personen gehen nur an die Bauern, wenn sie auch von dort stammen */
if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) {
int p = rpeasants(u->region);
p += (int)(u->number / rc->recruit_multi);
rsetpeasants(r, p);
}
}
if (r->land && playerrace(u_race(u))) {
const race *rc = u_race(u);
/* Personen gehen nur an die Bauern, wenn sie auch von dort stammen */
if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) {
int p = rpeasants(u->region);
p += (int)(u->number / rc->recruit_multi);
rsetpeasants(r, p);
}
}
set_number(u, 0);
Expand Down
25 changes: 22 additions & 3 deletions src/kernel/faction.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,38 @@ static void test_destroyfaction(CuTest *tc) {
init_resources();

r = test_create_plain(0, 0);
rsethorses(r, 10);
rsetpeasants(r, 100);
f = test_create_faction();
u = test_create_unit(f, r);
scale_number(u, 100);
CuAssertPtrEquals(tc, f, factions);
CuAssertPtrEquals(tc, NULL, f->next);
destroyfaction(&factions);
CuAssertPtrEquals(tc, NULL, factions);
CuAssertIntEquals(tc, 200, rpeasants(r));
test_teardown();
}

static void test_destroyfaction_items(CuTest *tc) {
faction *f;
region *r;
unit* u;

test_setup();
init_resources();

r = test_create_plain(0, 0);
rsethorses(r, 10);
rsetmoney(r, 1000);
f = test_create_faction();
u = test_create_unit(f, r);
i_change(&u->items, it_find("horse"), 10);
i_change(&u->items, it_find("money"), 1000);
scale_number(u, 100);
CuAssertPtrEquals(tc, f, factions);
CuAssertPtrEquals(tc, NULL, f->next);
destroyfaction(&factions);
CuAssertPtrEquals(tc, NULL, factions);
CuAssertIntEquals(tc, 20, rhorses(r));
CuAssertIntEquals(tc, 200, rpeasants(r));
CuAssertIntEquals(tc, 2000, rmoney(r));
test_teardown();
}
Expand Down Expand Up @@ -563,6 +581,7 @@ CuSuite *get_faction_suite(void)
SUITE_ADD_TEST(suite, test_addfaction);
SUITE_ADD_TEST(suite, test_remove_empty_factions);
SUITE_ADD_TEST(suite, test_destroyfaction);
SUITE_ADD_TEST(suite, test_destroyfaction_items);
SUITE_ADD_TEST(suite, test_destroyfaction_undead);
SUITE_ADD_TEST(suite, test_destroyfaction_demon);
SUITE_ADD_TEST(suite, test_destroyfaction_orc);
Expand Down

0 comments on commit 66b7b13

Please sign in to comment.