Merge pull request #397 from stm2/taxing_message

taxing without skill does not fail silently any more
This commit is contained in:
Enno Rehling 2015-11-26 18:43:57 +01:00
commit 6ad5db8e22
5 changed files with 102 additions and 2 deletions

View File

@ -15,6 +15,7 @@
"modules.wormholes": true,
"entertain.base": 0,
"entertain.perlevel": 20,
"taxing.perlevel": 20,
"nmr.timeout": 5,
"nmr.removenewbie": 0,
"GiveRestriction": 3,

View File

@ -6357,6 +6357,16 @@
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht der Eigentümer."</text>
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit is not the owner."</text>
</message>
<message name="error_no_tax_skill" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht geschult im Eintreiben von Steuern."</text>
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit does not now how to tax."</text>
</message>
<message name="error48" section="errors">
<type>
<arg name="unit" type="unit"/>

View File

@ -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);

View File

@ -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);

View File

@ -19,6 +19,7 @@
#include <CuTest.h>
#include <tests.h>
#include <assert.h>
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;
}