From 493b45c8320838196e6d2a8ed1853553fb13aed6 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Sat, 14 Nov 2015 15:32:31 +0100 Subject: [PATCH 1/2] taxing without skill does not fail silently any more http://bugs.eressea.de/view.php?id=2158 added configuration parameter for tax per level --- conf/e2/config.json | 1 + res/core/messages.xml | 10 ++++++ src/economy.c | 15 +++++++-- src/economy.h | 3 ++ src/economy.test.c | 73 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 2 deletions(-) diff --git a/conf/e2/config.json b/conf/e2/config.json index 6b11dceff..20c316ade 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -15,6 +15,7 @@ "modules.wormholes": true, "entertain.base": 0, "entertain.perlevel": 20, + "taxing.perlevel": 20, "nmr.timeout": 5, "nmr.removenewbie": 0, "GiveRestriction": 3, diff --git a/res/core/messages.xml b/res/core/messages.xml index a3d7ad6e8..be040f5db 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -6357,6 +6357,16 @@ "$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht der Eigentümer." "$unit($unit) in $region($region): '$order($command)' - The unit is not the owner." + + + + + + + "$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht geschult im Eintreiben von Steuern." + "$unit($unit) in $region($region): '$order($command)' - The unit does not now how to tax." + + diff --git a/src/economy.c b/src/economy.c index 19223daa1..85bb658d2 100644 --- a/src/economy.c +++ b/src/economy.c @@ -2924,7 +2924,7 @@ static void expandloot(region * r, request * lootorders) } } -static void expandtax(region * r, request * taxorders) +void expandtax(region * r, request * taxorders) { unit *u; unsigned int i; @@ -2957,6 +2957,11 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) request *o; int max; keyword_t kwd; + static int taxperlevel = 0; + + if (!taxperlevel) { + taxperlevel = get_param_int(global.parameters, "taxing.perlevel", 0); + } kwd = init_order(ord); assert(kwd == K_TAX); @@ -2982,6 +2987,12 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) return; } + if (effskill(u, SK_TAXING, 0) <= 0) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "error_no_tax_skill", "")); + return; + } + max = getint(); if (max <= 0) { @@ -2991,7 +3002,7 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) u->wants = _min(income(u), max); } else { - u->wants = _min(n * effskill(u, SK_TAXING, 0) * 20, max); + u->wants = _min(n * effskill(u, SK_TAXING, 0) * taxperlevel, max); } u2 = is_guarded(r, u, GUARD_TAX); diff --git a/src/economy.h b/src/economy.h index dce389556..7e399cc76 100644 --- a/src/economy.h +++ b/src/economy.h @@ -45,6 +45,7 @@ extern "C" { struct faction; struct order; struct message; + struct request; int income(const struct unit *u); @@ -59,6 +60,8 @@ extern "C" { int recruit_archetypes(void); int give_control_cmd(struct unit *u, struct order *ord); void give_control(struct unit * u, struct unit * u2); + void tax_cmd(struct unit * u, struct order *ord, struct request ** taxorders); + void expandtax(struct region * r, struct request * taxorders); struct message * check_steal(const struct unit * u, struct order *ord); diff --git a/src/economy.test.c b/src/economy.test.c index 09fa1157f..d446f1d65 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -19,6 +19,7 @@ #include #include +#include static void test_give_control_building(CuTest * tc) { @@ -169,6 +170,77 @@ static void test_normals_recruit(CuTest * tc) { test_cleanup(); } +typedef struct request { + struct request *next; + struct unit *unit; + struct order *ord; + int qty; + int no; + union { + bool goblin; /* stealing */ + const struct luxury_type *ltype; /* trading */ + } type; +} request; + +static void test_tax_cmd(CuTest *tc) { + order *ord; + faction *f; + region *r; + unit *u; + item_type *sword, *silver; + request *taxorders = 0; + + + test_cleanup(); + set_param(&global.parameters, "taxing.perlevel", "20"); + test_create_world(); + f = test_create_faction(NULL); + r = findregion(0, 0); + assert(r && f); + u = test_create_unit(f, r); + + ord = create_order(K_TAX, f->locale, ""); + assert(ord); + + tax_cmd(u, ord, &taxorders); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error48")); + test_clear_messages(u->faction); + + silver = get_resourcetype(R_SILVER)->itype; + + sword = it_get_or_create(rt_get_or_create("sword")); + new_weapontype(sword, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 1); + i_change(&u->items, sword, 1); + set_level(u, SK_MELEE, 1); + + tax_cmd(u, ord, &taxorders); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_no_tax_skill")); + test_clear_messages(u->faction); + + set_level(u, SK_TAXING, 1); + tax_cmd(u, ord, &taxorders); + CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "error_no_tax_skill")); + CuAssertPtrNotNull(tc, taxorders); + + + r->land->money = 11; + expandtax(r, taxorders); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "income")); + CuAssertTrue(tc, i_get(u->items, silver) > 0 && i_get(u->items, silver) <= 11); + test_clear_messages(u->faction); + i_change(&u->items, silver, -i_get(u->items, silver)); + + r->land->money = 1000; + taxorders = 0; + tax_cmd(u, ord, &taxorders); + expandtax(r, taxorders); + CuAssertIntEquals(tc, 20, i_get(u->items, silver)); + test_clear_messages(u->faction); + + free_order(ord); + test_cleanup(); +} + CuSuite *get_economy_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -179,5 +251,6 @@ CuSuite *get_economy_suite(void) SUITE_ADD_TEST(suite, test_steal_nosteal); SUITE_ADD_TEST(suite, test_normals_recruit); SUITE_ADD_TEST(suite, test_heroes_dont_recruit); + SUITE_ADD_TEST(suite, test_tax_cmd); return suite; } From 01f4ebd4cee8f672a4011fc0ba2f6d75ced5f584 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Sat, 14 Nov 2015 17:14:38 +0100 Subject: [PATCH 2/2] test for fixed value instead of range --- src/economy.test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/economy.test.c b/src/economy.test.c index d446f1d65..d41031aff 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -223,10 +223,12 @@ static void test_tax_cmd(CuTest *tc) { CuAssertPtrNotNull(tc, taxorders); + r->land->money = 11; expandtax(r, taxorders); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "income")); - CuAssertTrue(tc, i_get(u->items, silver) > 0 && i_get(u->items, silver) <= 11); + /* taxing is in multiples of 10 */ + CuAssertIntEquals(tc, 10, i_get(u->items, silver)); test_clear_messages(u->faction); i_change(&u->items, silver, -i_get(u->items, silver));