From eabf72e60e0e360cddaff12aee87ea04327bb86b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 Sep 2017 22:04:36 +0200 Subject: [PATCH] BUG 2362: clone_men hitpoint calculation was wrong. --- src/kernel/unit.c | 2 +- src/kernel/unit.test.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 9c08f9dc1..44e9445b7 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1060,7 +1060,7 @@ void clone_men(const unit * u, unit * dst, int n) transfer_curse(u, dst, n); } set_number(dst, dst->number + n); - dst->hp += u->hp * dst->number / u->number; + dst->hp += u->hp * n / u->number; assert(dst->hp >= dst->number); /* TODO: Das ist schnarchlahm! und gehoert nicht hierhin */ a = a_find(dst->attribs, &at_effect); diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 6ab8ee21a..2abb8c85c 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -548,6 +548,27 @@ static void test_clone_men(CuTest *tc) { test_cleanup(); } +static void test_transfermen(CuTest *tc) { + unit *u1, *u2; + region *r; + faction *f; + test_setup(); + r = test_create_region(0, 0, NULL); + f = test_create_faction(NULL); + u1 = test_create_unit(f, r); + scale_number(u1, 3500); + u2 = test_create_unit(f, r); + scale_number(u2, 3500); + CuAssertIntEquals(tc, 70000, u1->hp); + CuAssertIntEquals(tc, 70000, u2->hp); + transfermen(u1, u2, u1->number); + CuAssertIntEquals(tc, 7000, u2->number); + CuAssertIntEquals(tc, 140000, u2->hp); + CuAssertIntEquals(tc, 0, u1->number); + CuAssertIntEquals(tc, 0, u1->hp); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -557,6 +578,7 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_unit_name_from_race); SUITE_ADD_TEST(suite, test_update_monster_name); SUITE_ADD_TEST(suite, test_clone_men); + SUITE_ADD_TEST(suite, test_transfermen); SUITE_ADD_TEST(suite, test_remove_unit); SUITE_ADD_TEST(suite, test_remove_empty_units); SUITE_ADD_TEST(suite, test_remove_units_without_faction);