diff --git a/conf/e2/config.json b/conf/e2/config.json index 1ae7f77e5..fa8566eab 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 946572a5d..a8658aa4c 100644 --- a/src/economy.c +++ b/src/economy.c @@ -2919,7 +2919,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; @@ -2952,6 +2952,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); @@ -2977,6 +2982,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) { @@ -2986,7 +2997,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..d41031aff 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,79 @@ 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")); + /* 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)); + + 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 +253,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; }