Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

units without items given to peasants on QUIT #1020

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/kernel/faction.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,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