transfer_faction respects magic schools.

This commit is contained in:
Enno Rehling 2019-11-18 19:33:37 +01:00
parent f5641b2787
commit 1bff7801ff
3 changed files with 60 additions and 1 deletions

2
clibs

@ -1 +1 @@
Subproject commit f8969f44de1ec413cfee82b23c9f4b3c32d49b56 Subproject commit abe774f70265de14ea7f5e530518ca130562a9c9

View File

@ -976,9 +976,17 @@ void transfer_faction(faction *fsrc, faction *fdst) {
for (i = 0; i != u->skill_size; ++i) { for (i = 0; i != u->skill_size; ++i) {
const skill *sv = u->skills + i; const skill *sv = u->skills + i;
skill_t sk = (skill_t)sv->id; skill_t sk = (skill_t)sv->id;
struct sc_mage *mage;
if (skill_count[sk] + u->number > skill_limit[sk]) { if (skill_count[sk] + u->number > skill_limit[sk]) {
break; break;
} }
mage = get_mage(u);
if (mage) {
if (fdst->magiegebiet != mage_get_type(mage)) {
break;
}
}
} }
if (i != u->skill_size) { if (i != u->skill_size) {
u = u->nextF; u = u->nextF;

View File

@ -2083,6 +2083,56 @@ static void test_quit_transfer_limited(CuTest *tc) {
test_teardown(); 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. * 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);
SUITE_ADD_TEST(suite, test_quit_transfer_limited); SUITE_ADD_TEST(suite, test_quit_transfer_limited);
SUITE_ADD_TEST(suite, test_quit_transfer_migrants); 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_quit_transfer_hero);
SUITE_ADD_TEST(suite, test_transfer_faction); SUITE_ADD_TEST(suite, test_transfer_faction);
#endif #endif