From 3f3cdad3904a6c6e50b27fe727804b60812196a7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 7 Nov 2017 19:42:00 +0100 Subject: [PATCH 1/5] BUG 2383: Delete an invalid assertion. https://bugs.eressea.de/view.php?id=2383 --- src/creport.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/creport.c b/src/creport.c index 15e1791f6..30f045b3f 100644 --- a/src/creport.c +++ b/src/creport.c @@ -853,8 +853,6 @@ void cr_output_unit(stream *out, const region * r, const faction * f, stream_printf(out, "\"%s\";Typ\n", translate(zRace, LOC(f->locale, zRace))); if (u->faction == f && irace != u_race(u)) { - assert(skill_enabled(SK_STEALTH) - || !"we're resetting this on load, so.. ircase should never be used"); zRace = rc_name_s(u_race(u), NAME_PLURAL); stream_printf(out, "\"%s\";wahrerTyp\n", translate(zRace, LOC(f->locale, zRace))); From 2f449e686b97856f784c9c2f3def3cc8ff8ba378 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Sat, 18 Nov 2017 17:57:30 +0100 Subject: [PATCH 2/5] addendum to BUG 2383 (5a0a1f): read irace correctly --- src/kernel/save.c | 2 +- src/kernel/save.test.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index aa09a27be..926de1bb1 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -509,7 +509,7 @@ unit *read_unit(gamedata *data) u_setrace(u, rc); READ_TOK(data->store, rname, sizeof(rname)); - if (rname[0] && skill_enabled(SK_STEALTH)) + if (rname[0]) u->irace = rc_find(rname); else u->irace = NULL; diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 81d5a507d..82cd8662c 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -51,6 +52,7 @@ static void test_readwrite_unit(CuTest * tc) struct unit *u; struct region *r; struct faction *f; + struct race *irace; int fno; test_setup(); @@ -60,6 +62,12 @@ static void test_readwrite_unit(CuTest * tc) u = test_create_unit(f, r); unit_setname(u, " Hodor "); CuAssertStrEquals(tc, " Hodor ", u->_name); + enable_skill(SK_STEALTH, false); + irace = test_create_race("halfling"); + CuAssertTrue(tc, playerrace(irace)); + u->irace = irace; + CuAssertTrue(tc, irace == u_irace(u)); + mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); write_unit(&data, u); @@ -74,6 +82,7 @@ static void test_readwrite_unit(CuTest * tc) CuAssertPtrNotNull(tc, u); CuAssertPtrEquals(tc, f, u->faction); CuAssertStrEquals(tc, "Hodor", u->_name); + CuAssertTrue(tc, irace == u_irace(u)); CuAssertPtrEquals(tc, 0, u->region); mstream_done(&data.strm); From 7e1f3dbdc55aacef01fa2345eab02b6b44ad2a8b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Nov 2017 02:44:13 +0100 Subject: [PATCH 3/5] fix bug 2386, int overflow --- src/kernel/unit.c | 2 +- src/kernel/unit.test.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 9c08f9dc1..09e8d75e0 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 += (long)u->hp * dst->number / 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..1d74336c9 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -525,6 +525,25 @@ static void test_unlimited_units(CuTest *tc) { test_cleanup(); } +static void test_clone_men_bug_2386(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, 8237); + u1->hp = 39 * u1->number; + u2 = test_create_unit(f, r); + scale_number(u2, 0); + clone_men(u1, u2, 8100); + CuAssertIntEquals(tc, 8100, u2->number); + CuAssertIntEquals(tc, u2->number * 39, u2->hp); + test_cleanup(); +} + static void test_clone_men(CuTest *tc) { unit *u1, *u2; region *r; @@ -557,6 +576,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_clone_men_bug_2386); SUITE_ADD_TEST(suite, test_remove_unit); SUITE_ADD_TEST(suite, test_remove_empty_units); SUITE_ADD_TEST(suite, test_remove_units_without_faction); From 1c24628d625412280bcfc7810f49f354a79ad38d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 Sep 2017 22:04:36 +0200 Subject: [PATCH 4/5] 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 09e8d75e0..ba19ebe93 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 += (long)u->hp * dst->number / u->number; + dst->hp += (long)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 1d74336c9..5661d3f2f 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -567,6 +567,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(); @@ -577,6 +598,7 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_update_monster_name); SUITE_ADD_TEST(suite, test_clone_men); SUITE_ADD_TEST(suite, test_clone_men_bug_2386); + 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); From 29a6c0ae8658b2953fc4f2c1f7865276bf64533c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 21 Nov 2017 08:47:35 +0100 Subject: [PATCH 5/5] gmtool, highlight and clear chaos --- src/gmtool.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/gmtool.c b/src/gmtool.c index db556bb0a..6806a3056 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -720,6 +720,22 @@ static void select_regions(state * st, int selectmode) } } } + else if (findmode == 'c') { + region *r; + sprintf(sbuffer, "%schaos", status); + statusline(st->wnd_status->handle, sbuffer); + for (r = regions; r; r = r->next) { + if (fval(r, RF_CHAOTIC)) { + if (selectmode & MODE_SELECT) { + select_coordinate(st->selected, r->x, r->y, + selectmode == MODE_SELECT); + } + else { + highlight_region(r, selectmode == MODE_MARK); + } + } + } + } else if (findmode == 'm') { region *r; sprintf(sbuffer, "%smonsters", status); @@ -991,9 +1007,13 @@ static void handlekey(state * st, int c) break; case 'c': /* clear/reset */ reset_cursor(st); + st->modified = 1; + st->wnd_map->update |= 1; break; case 'C': /* clear/reset */ reset_rect(st); + st->modified = 1; + st->wnd_map->update |= 1; break; case 0x09: /* tab = next selected */ if (regions != NULL) {