From 1bff7801ff579d1daa55e1241fd59c8f166b244e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 18 Nov 2019 19:33:37 +0100 Subject: [PATCH 1/2] transfer_faction respects magic schools. --- clibs | 2 +- src/laws.c | 8 ++++++++ src/laws.test.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/clibs b/clibs index f8969f44d..abe774f70 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f8969f44de1ec413cfee82b23c9f4b3c32d49b56 +Subproject commit abe774f70265de14ea7f5e530518ca130562a9c9 diff --git a/src/laws.c b/src/laws.c index eb483aae7..42230e338 100644 --- a/src/laws.c +++ b/src/laws.c @@ -976,9 +976,17 @@ void transfer_faction(faction *fsrc, faction *fdst) { for (i = 0; i != u->skill_size; ++i) { const skill *sv = u->skills + i; skill_t sk = (skill_t)sv->id; + struct sc_mage *mage; + if (skill_count[sk] + u->number > skill_limit[sk]) { break; } + mage = get_mage(u); + if (mage) { + if (fdst->magiegebiet != mage_get_type(mage)) { + break; + } + } } if (i != u->skill_size) { u = u->nextF; diff --git a/src/laws.test.c b/src/laws.test.c index 5dff45a92..ea273d017 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -2083,6 +2083,56 @@ static void test_quit_transfer_limited(CuTest *tc) { test_teardown(); } +/** + * Gifting units with same magic schools. + */ +static void test_quit_transfer_mages(CuTest *tc) { + faction *f1, *f2; + unit *u1, *u2; + region *r; + + test_setup(); + config_set_int("rules.maxskills.magic", 2); + r = test_create_plain(0, 0); + f1 = test_create_faction(NULL); + faction_setpassword(f1, "password"); + u1 = test_create_unit(f1, r); + f2 = test_create_faction(NULL); + u2 = test_create_unit(f2, r); + contact_unit(u2, u1); + u1->thisorder = create_order(K_QUIT, f1->locale, "password %s %s", + LOC(f1->locale, parameters[P_FACTION]), itoa36(f2->no)); + + f1->magiegebiet = M_GWYRRD; + set_level(u1, SK_MAGIC, 1); + create_mage(u1, M_GWYRRD); + + f2->magiegebiet = M_CERDDOR; + set_level(u2, SK_MAGIC, 1); + create_mage(u2, M_CERDDOR); + + quit_cmd(u1, u1->thisorder); + CuAssertPtrEquals(tc, f1, u1->faction); + CuAssertIntEquals(tc, FFL_QUIT, f1->flags & FFL_QUIT); + f1->flags -= FFL_QUIT; + + unit_set_magic(u1, M_CERDDOR); + scale_number(u1, 2); + f1->magiegebiet = M_CERDDOR; + quit_cmd(u1, u1->thisorder); + CuAssertPtrEquals(tc, f1, u1->faction); + CuAssertIntEquals(tc, FFL_QUIT, f1->flags & FFL_QUIT); + f1->flags -= FFL_QUIT; + + unit_set_magic(u1, M_CERDDOR); + scale_number(u1, 1); + f1->magiegebiet = M_CERDDOR; + quit_cmd(u1, u1->thisorder); + CuAssertPtrEquals(tc, f2, u1->faction); + + test_teardown(); +} + /** * Only units of the same race can be gifted to another faction. */ @@ -2248,6 +2298,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_quit_transfer); SUITE_ADD_TEST(suite, test_quit_transfer_limited); SUITE_ADD_TEST(suite, test_quit_transfer_migrants); + SUITE_ADD_TEST(suite, test_quit_transfer_mages); SUITE_ADD_TEST(suite, test_quit_transfer_hero); SUITE_ADD_TEST(suite, test_transfer_faction); #endif From cd165d94ec083a2a7f31a2f34545e2242a8e264c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 18 Nov 2019 19:44:24 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Magier=20d=C3=BCrfen=20bei=20STIRB=20nicht?= =?UTF-8?q?=20=C3=BCbergeben=20werden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/laws.c | 10 +--------- src/laws.test.c | 21 +++------------------ 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/laws.c b/src/laws.c index 42230e338..ddda26f27 100644 --- a/src/laws.c +++ b/src/laws.c @@ -969,24 +969,16 @@ void transfer_faction(faction *fsrc, faction *fdst) { if (u_race(u) == fdst->race) { u->flags &= ~UFL_HERO; - if (give_unit_allowed(u) == 0) { + if (give_unit_allowed(u) == 0 && !get_mage(u)) { if (u->skills) { int i; - for (i = 0; i != u->skill_size; ++i) { const skill *sv = u->skills + i; skill_t sk = (skill_t)sv->id; - struct sc_mage *mage; if (skill_count[sk] + u->number > skill_limit[sk]) { break; } - mage = get_mage(u); - if (mage) { - if (fdst->magiegebiet != mage_get_type(mage)) { - break; - } - } } if (i != u->skill_size) { u = u->nextF; diff --git a/src/laws.test.c b/src/laws.test.c index ea273d017..f6e1ef585 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -2084,7 +2084,7 @@ static void test_quit_transfer_limited(CuTest *tc) { } /** - * Gifting units with same magic schools. + * Mages cannot be transfered. At all. */ static void test_quit_transfer_mages(CuTest *tc) { faction *f1, *f2; @@ -2107,28 +2107,13 @@ static void test_quit_transfer_mages(CuTest *tc) { set_level(u1, SK_MAGIC, 1); create_mage(u1, M_GWYRRD); - f2->magiegebiet = M_CERDDOR; + f2->magiegebiet = M_GWYRRD; set_level(u2, SK_MAGIC, 1); - create_mage(u2, M_CERDDOR); + create_mage(u2, M_GWYRRD); quit_cmd(u1, u1->thisorder); CuAssertPtrEquals(tc, f1, u1->faction); CuAssertIntEquals(tc, FFL_QUIT, f1->flags & FFL_QUIT); - f1->flags -= FFL_QUIT; - - unit_set_magic(u1, M_CERDDOR); - scale_number(u1, 2); - f1->magiegebiet = M_CERDDOR; - quit_cmd(u1, u1->thisorder); - CuAssertPtrEquals(tc, f1, u1->faction); - CuAssertIntEquals(tc, FFL_QUIT, f1->flags & FFL_QUIT); - f1->flags -= FFL_QUIT; - - unit_set_magic(u1, M_CERDDOR); - scale_number(u1, 1); - f1->magiegebiet = M_CERDDOR; - quit_cmd(u1, u1->thisorder); - CuAssertPtrEquals(tc, f2, u1->faction); test_teardown(); }