unit tests walkingcapacity, configurable trollbelt effect

This commit is contained in:
Enno Rehling 2015-04-14 02:32:01 +02:00
parent a5da77c376
commit ae9fb399f3
5 changed files with 60 additions and 3 deletions

View File

@ -85,7 +85,6 @@ extern "C" {
* von struct unitname, etc. zurückgegeben werden. ohne die 0 */
#define BAGCAPACITY 20000 /* soviel paßt in einen Bag of Holding */
#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */
/* ----------------- Befehle ----------------------------------- */

View File

@ -314,8 +314,11 @@ int walkingcapacity(const struct unit *u)
}
}
if (rbelt) {
int tmp = i_get(u->items, rbelt->itype);
n += _min(people, tmp) * (STRENGTHMULTIPLIER - 1) * u_race(u)->capacity;
int belts = i_get(u->items, rbelt->itype);
if (belts) {
int multi = get_param_flt(global.parameters, "rules.trollbelt.multiplier", STRENGTHMULTIPLIER);
n += _min(people, belts) * (multi - 1) * u_race(u)->capacity;
}
}
return n;

View File

@ -40,6 +40,7 @@ extern "C" {
#define MV_WALK (1<<9) /* kann über Land gehen */
#define HORSESNEEDED 2
#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */
/* ein mensch wiegt 10, traegt also 5, ein pferd wiegt 50, traegt also 20. ein
** wagen wird von zwei pferden gezogen und traegt total 140, davon 40 die

View File

@ -2,18 +2,22 @@
#include <stdlib.h>
#include "move.h"
#include <kernel/config.h>
#include <kernel/ally.h>
#include <kernel/building.h>
#include <kernel/faction.h>
#include <kernel/region.h>
#include <kernel/ship.h>
#include <kernel/terrain.h>
#include <kernel/item.h>
#include <kernel/unit.h>
#include <kernel/race.h>
#include <util/language.h>
#include <CuTest.h>
#include <tests.h>
#include <assert.h>
static void test_ship_not_allowed_in_coast(CuTest * tc)
{
@ -167,9 +171,54 @@ static void test_building_type_exists(CuTest * tc)
CuAssertTrue(tc, !buildingtype_exists(r, btype2, false));
}
static void test_walkingcapacity(CuTest *tc) {
region *r;
unit *u;
int cap;
const struct item_type *itype;
test_cleanup();
test_create_world();
r = findregion(0, 0);
u = test_create_unit(test_create_faction(0), r);
cap = u->number * (u->_race->capacity + u->_race->weight);
CuAssertIntEquals(tc, cap, walkingcapacity(u));
scale_number(u, 2);
cap = u->number * (u->_race->capacity + u->_race->weight);
CuAssertIntEquals(tc, cap, walkingcapacity(u));
itype = it_find("horse");
assert(itype);
i_change(&u->items, itype, 1);
cap += itype->capacity;
CuAssertIntEquals(tc, cap, walkingcapacity(u));
i_change(&u->items, itype, 1);
cap += itype->capacity;
CuAssertIntEquals(tc, cap, walkingcapacity(u));
itype = it_find("cart");
assert(itype);
i_change(&u->items, itype, 1);
CuAssertIntEquals(tc, cap, walkingcapacity(u));
set_level(u, SK_RIDING, 1);
cap += itype->capacity;
CuAssertIntEquals(tc, cap, walkingcapacity(u));
itype = test_create_itemtype("trollbelt");
assert(itype);
i_change(&u->items, itype, 1);
CuAssertIntEquals(tc, cap + (STRENGTHMULTIPLIER-1) * u->_race->capacity, walkingcapacity(u));
set_param(&global.parameters, "rules.trollbelt.multiplier", "5");
CuAssertIntEquals(tc, cap + 4 * u->_race->capacity, walkingcapacity(u));
test_cleanup();
}
CuSuite *get_move_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_walkingcapacity);
SUITE_ADD_TEST(suite, test_building_type_exists);
SUITE_ADD_TEST(suite, test_ship_not_allowed_in_coast);
SUITE_ADD_TEST(suite, test_ship_allowed_without_harbormaster);

View File

@ -175,6 +175,11 @@ void test_create_world(void)
itype->weight = 5000;
itype->capacity = 7000;
itype = test_create_itemtype("cart");
itype->flags |= ITF_BIG | ITF_VEHICLE;
itype->weight = 4000;
itype->capacity = 14000;
test_create_itemtype("iron");
test_create_itemtype("stone");