Skip to content

Commit

Permalink
Test für "gerechte" Verteilung bei UNTERHALTE Limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Mar 9, 2024
1 parent f231142 commit afebb27
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
16 changes: 6 additions & 10 deletions src/economy.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ static struct econ_request econ_requests[MAX_REQUESTS];

static econ_request **g_requests; /* TODO: no need for this to be module-global */

#define ENTERTAINFRACTION 20

/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
static int max_trades(const unit *u)
{
Expand Down Expand Up @@ -2090,17 +2088,15 @@ static int entertain_cmd(unit * u, struct order *ord, econ_request **io_req)
region *r = u->region;
int wants, max_e;
econ_request *req = *io_req;
static int entertainbase = 0;
static int entertainperlevel = 0;
static int entertainbase = -1;
static int entertainperlevel = -1;

init_order(ord, NULL);
if (!entertainbase) {
const char *str = config_get("entertain.base");
entertainbase = str ? atoi(str) : 0;
if (entertainbase < 0) {
entertainbase = config_get_int("entertain.base", 0);
}
if (!entertainperlevel) {
const char *str = config_get("entertain.perlevel");
entertainperlevel = str ? atoi(str) : 0;
if (entertainperlevel < 0) {
entertainperlevel = config_get_int("entertain.perlevel", 20);
}
if (fval(u, UFL_WERE)) {
cmistake(u, ord, 58, MSG_INCOME);
Expand Down
4 changes: 2 additions & 2 deletions src/economy.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ extern "C" {
* wiviel Silber ein Unterhalter pro Talentpunkt bekommt. */

/* Wieviele Silbermuenzen jeweils auf einmal "getaxed" werden. */

#define TAXFRACTION 10
#define TAXFRACTION 10
#define ENTERTAINFRACTION 20

/* Wieviel Silber pro Talentpunkt geklaut wird. */

Expand Down
28 changes: 28 additions & 0 deletions src/economy.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,33 @@ static void test_make_zero(CuTest* tc) {
test_teardown();
}

static void test_entertain_fair(CuTest *tc) {
unit *u1, *u2;
region *r;
faction *f;
const item_type *itype;

test_setup();
init_resources();
itype = it_find("money");
f = test_create_faction();
r = test_create_plain(0, 0);
rsetmoney(r, ENTERTAINFRACTION * 1800);
u1 = test_create_unit(f, r);
scale_number(u1, 90);
test_set_skill(u1, SK_ENTERTAINMENT, 1, 1);
u1->thisorder = create_order(K_ENTERTAIN, f->locale, "1000", 0);
u2 = test_create_unit(f, r);
scale_number(u2, 10);
test_set_skill(u2, SK_ENTERTAINMENT, 9, 1);
u2->thisorder = create_order(K_ENTERTAIN, f->locale, "1000", 0);
produce(r);
CuAssertIntEquals(tc, 1800, i_get(u1->items, itype) + i_get(u2->items, itype));
CuAssertIntEquals(tc, 900, i_get(u2->items, itype));
CuAssertIntEquals(tc, 900, i_get(u1->items, itype));
test_teardown();
}

CuSuite *get_economy_suite(void)
{
CuSuite *suite = CuSuiteNew();
Expand Down Expand Up @@ -1714,5 +1741,6 @@ CuSuite *get_economy_suite(void)
SUITE_ADD_TEST(suite, test_destroy_road_limit);
SUITE_ADD_TEST(suite, test_destroy_road_guard);
SUITE_ADD_TEST(suite, test_make_zero);
SUITE_ADD_TEST(suite, test_entertain_fair);
return suite;
}

0 comments on commit afebb27

Please sign in to comment.