From 0dd02dbf72b6902105377ad80997fb7f8b0e2ec5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 08:56:14 +0200 Subject: [PATCH 1/2] add a test for give_unit between two allied factions. --- src/give.test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/give.test.c b/src/give.test.c index f1b13011d..0e8760e7b 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -3,6 +3,7 @@ #include "give.h" #include "economy.h" +#include #include #include #include @@ -34,6 +35,10 @@ static void setup_give(struct give *env) { env->dst = env->f2 ? test_create_unit(env->f2, env->r) : 0; env->itype = it_get_or_create(rt_get_or_create("money")); env->itype->flags |= ITF_HERB; + if (env->f1 && env->f2) { + ally * al = ally_add(&env->f2->allies, env->f1); + al->status = HELP_GIVE; + } } static void test_give_unit_to_peasants(CuTest * tc) { @@ -49,6 +54,19 @@ static void test_give_unit_to_peasants(CuTest * tc) { test_cleanup(); } +static void test_give_unit(CuTest * tc) { + struct give env; + test_cleanup(); + env.f1 = test_create_faction(0); + env.f2 = test_create_faction(0); + setup_give(&env); + env.r->terrain = test_create_terrain("ocean", SEA_REGION); + give_unit(env.src, env.dst, NULL); + CuAssertPtrEquals(tc, env.f2, env.src->faction); + CuAssertPtrEquals(tc, 0, env.f1->units); + test_cleanup(); +} + static void test_give_unit_in_ocean(CuTest * tc) { struct give env; test_cleanup(); @@ -284,6 +302,7 @@ CuSuite *get_give_suite(void) SUITE_ADD_TEST(suite, test_give_men_other_faction); SUITE_ADD_TEST(suite, test_give_men_requires_contact); SUITE_ADD_TEST(suite, test_give_men_not_to_self); + SUITE_ADD_TEST(suite, test_give_unit); SUITE_ADD_TEST(suite, test_give_unit_in_ocean); SUITE_ADD_TEST(suite, test_give_unit_to_peasants); SUITE_ADD_TEST(suite, test_give_peasants); From 12946615e5036acc663021425dd04cfd8700e1a4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 09:06:20 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Bugfix=202109:=20Einheiten=20lassen=20sich?= =?UTF-8?q?=20nicht=20mehr=20zwischen=20Parteien=20=C3=BCbergeben=20https:?= =?UTF-8?q?//bugs.eressea.de/view.php=3Fid=3D2109=20Wenn=20max=5Ftransfers?= =?UTF-8?q?=20<=200=20war,=20wurde=20das=20nur=20in=20give=5Fmen=20richtig?= =?UTF-8?q?=20interpretiert,=20aber=20nicht=20in=20give=5Funit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/give.c | 14 ++++++++------ src/give.test.c | 6 ++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/give.c b/src/give.c index 3f8f62927..8affb0bc0 100644 --- a/src/give.c +++ b/src/give.c @@ -401,7 +401,7 @@ message * disband_men(int n, unit * u, struct order *ord) { void give_unit(unit * u, unit * u2, order * ord) { region *r = u->region; - int n = u->number; + int maxt = max_transfers(); if (!rule_transfermen() && u->faction != u2->faction) { cmistake(u, ord, 74, MSG_COMMERCE); @@ -472,9 +472,11 @@ void give_unit(unit * u, unit * u2, order * ord) cmistake(u, ord, 105, MSG_COMMERCE); return; } - if (u2->faction->newbies + n > max_transfers()) { - cmistake(u, ord, 129, MSG_COMMERCE); - return; + if (maxt >= 0 && u->faction != u2->faction) { + if (u2->faction->newbies + u->number > maxt) { + cmistake(u, ord, 129, MSG_COMMERCE); + return; + } } if (u_race(u) != u2->faction->race) { if (u2->faction->race != get_race(RC_HUMAN)) { @@ -510,9 +512,9 @@ void give_unit(unit * u, unit * u2, order * ord) cmistake(u, ord, 156, MSG_COMMERCE); return; } - add_give(u, u2, n, n, get_resourcetype(R_PERSON), ord, 0); + add_give(u, u2, u->number, u->number, get_resourcetype(R_PERSON), ord, 0); u_setfaction(u, u2->faction); - u2->faction->newbies += n; + u2->faction->newbies += u->number; } bool can_give_to(unit *u, unit *u2) { diff --git a/src/give.test.c b/src/give.test.c index 0e8760e7b..a5714f445 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -61,8 +61,14 @@ static void test_give_unit(CuTest * tc) { env.f2 = test_create_faction(0); setup_give(&env); env.r->terrain = test_create_terrain("ocean", SEA_REGION); + set_param(&global.parameters, "rules.give.max_men", "0"); + give_unit(env.src, env.dst, NULL); + CuAssertPtrEquals(tc, env.f1, env.src->faction); + CuAssertIntEquals(tc, 0, env.f2->newbies); + set_param(&global.parameters, "rules.give.max_men", "-1"); give_unit(env.src, env.dst, NULL); CuAssertPtrEquals(tc, env.f2, env.src->faction); + CuAssertIntEquals(tc, 1, env.f2->newbies); CuAssertPtrEquals(tc, 0, env.f1->units); test_cleanup(); }