forked from github/server
clean up and test various race.parameters
This commit is contained in:
parent
2be1868ff0
commit
2ecbf89f1a
|
@ -1014,17 +1014,13 @@ static void vampirism(troop at, int damage)
|
|||
|
||||
#define MAXRACES 128
|
||||
|
||||
static int armor_bonus(const race *rc) {
|
||||
return get_param_int(rc->parameters, "armor.stamina", -1);
|
||||
}
|
||||
|
||||
int natural_armor(unit * du)
|
||||
{
|
||||
const race *rc = u_race(du);
|
||||
int an;
|
||||
|
||||
assert(rc);
|
||||
an = armor_bonus(rc);
|
||||
an = rc_armor_bonus(rc);
|
||||
if (an > 0) {
|
||||
int sk = effskill(du, SK_STAMINA, 0);
|
||||
return rc->armor + sk / an;
|
||||
|
|
|
@ -223,10 +223,13 @@ static void test_natural_armor(CuTest * tc)
|
|||
rc = test_create_race("human");
|
||||
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
|
||||
set_level(u, SK_STAMINA, 2);
|
||||
CuAssertIntEquals(tc, 0, rc_armor_bonus(rc));
|
||||
CuAssertIntEquals(tc, 0, natural_armor(u));
|
||||
set_param(&rc->parameters, "armor.stamina", "1");
|
||||
CuAssertIntEquals(tc, 1, rc_armor_bonus(rc));
|
||||
CuAssertIntEquals(tc, 2, natural_armor(u));
|
||||
set_param(&rc->parameters, "armor.stamina", "2");
|
||||
CuAssertIntEquals(tc, 2, rc_armor_bonus(rc));
|
||||
CuAssertIntEquals(tc, 1, natural_armor(u));
|
||||
test_cleanup();
|
||||
}
|
||||
|
|
|
@ -753,12 +753,9 @@ int count_migrants(const faction * f)
|
|||
return count_faction(f, COUNT_MIGRANTS);
|
||||
}
|
||||
|
||||
#define MIGRANTS_NONE 0
|
||||
#define MIGRANTS_LOG10 1
|
||||
|
||||
int count_maxmigrants(const faction * f)
|
||||
{
|
||||
int formula = f->race->parameters ? get_param_int(f->race->parameters, "migrants.formula", MIGRANTS_NONE) : MIGRANTS_NONE;
|
||||
int formula = rc_migrants_formula(f->race);
|
||||
|
||||
if (formula == MIGRANTS_LOG10) {
|
||||
int nsize = count_all(f);
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
#include <kernel/ally.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/config.h>
|
||||
#include <util/language.h>
|
||||
#include <util/password.h>
|
||||
|
@ -191,9 +192,27 @@ static void test_set_origin_bug(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_max_migrants(CuTest *tc) {
|
||||
faction *f;
|
||||
unit *u;
|
||||
race *rc;
|
||||
|
||||
test_setup();
|
||||
rc = test_create_race("human");
|
||||
f = test_create_faction(rc);
|
||||
u = test_create_unit(f, test_create_region(0, 0, 0));
|
||||
CuAssertIntEquals(tc, 0, count_maxmigrants(f));
|
||||
set_param(&rc->parameters, "migrants.formula", "1");
|
||||
CuAssertIntEquals(tc, 0, count_maxmigrants(f));
|
||||
scale_number(u, 250);
|
||||
CuAssertIntEquals(tc, 13, count_maxmigrants(f));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_faction_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_max_migrants);
|
||||
SUITE_ADD_TEST(suite, test_addfaction);
|
||||
SUITE_ADD_TEST(suite, test_remove_empty_factions);
|
||||
SUITE_ADD_TEST(suite, test_destroyfaction_allies);
|
||||
|
|
|
@ -290,6 +290,15 @@ double rc_maxaura(const race *rc) {
|
|||
return rc->maxaura / 100.0;
|
||||
}
|
||||
|
||||
int rc_armor_bonus(const race *rc) {
|
||||
return get_param_int(rc->parameters, "armor.stamina", 0);
|
||||
}
|
||||
|
||||
int rc_migrants_formula(const race *rc)
|
||||
{
|
||||
return rc->parameters ? get_param_int(rc->parameters, "migrants.formula", MIGRANTS_NONE) : MIGRANTS_NONE;
|
||||
}
|
||||
|
||||
const char* rc_name(const race * rc, name_t n, char *name, size_t size) {
|
||||
const char * postfix = 0;
|
||||
if (!rc) {
|
||||
|
|
|
@ -186,6 +186,12 @@ extern "C" {
|
|||
|
||||
double rc_magres(const struct race *rc);
|
||||
double rc_maxaura(const struct race *rc);
|
||||
int rc_armor_bonus(const struct race *rc);
|
||||
|
||||
#define MIGRANTS_NONE 0
|
||||
#define MIGRANTS_LOG10 1
|
||||
int rc_migrants_formula(const race *rc);
|
||||
|
||||
/* Flags. Do not reorder these without changing json_race() in jsonconf.c */
|
||||
#define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */
|
||||
#define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */
|
||||
|
|
|
@ -23,6 +23,7 @@ static void test_rc_defaults(CuTest *tc) {
|
|||
test_setup();
|
||||
rc = rc_get_or_create("human");
|
||||
CuAssertStrEquals(tc, "human", rc->_name);
|
||||
CuAssertIntEquals(tc, 0, rc_armor_bonus(rc));
|
||||
CuAssertIntEquals(tc, 0, rc->magres);
|
||||
CuAssertDblEquals(tc, 0.0, rc_magres(rc), 0.0);
|
||||
CuAssertIntEquals(tc, 0, rc->healing);
|
||||
|
|
|
@ -66,7 +66,7 @@ attrib_type at_market = {
|
|||
NULL, NULL, NULL, ATF_UNIQUE
|
||||
};
|
||||
|
||||
static int rc_luxury_trade(const struct race *rc)
|
||||
int rc_luxury_trade(const struct race *rc)
|
||||
{
|
||||
if (rc) {
|
||||
return get_param_int(rc->parameters, "luxury_trade", 1000);
|
||||
|
@ -74,7 +74,7 @@ static int rc_luxury_trade(const struct race *rc)
|
|||
return 1000;
|
||||
}
|
||||
|
||||
static int rc_herb_trade(const struct race *rc)
|
||||
int rc_herb_trade(const struct race *rc)
|
||||
{
|
||||
if (rc) {
|
||||
return get_param_int(rc->parameters, "herb_trade", 500);
|
||||
|
|
|
@ -19,10 +19,14 @@ without prior permission by the authors of Eressea.
|
|||
extern "C" {
|
||||
#endif
|
||||
struct building;
|
||||
struct race;
|
||||
|
||||
bool markets_module(void);
|
||||
void do_markets(void);
|
||||
|
||||
int rc_luxury_trade(const struct race *rc);
|
||||
int rc_herb_trade(const struct race *rc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -80,9 +80,23 @@ static void test_market_curse(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 35, i_get(u->items, ltype));
|
||||
}
|
||||
|
||||
static void test_rc_trade(CuTest *tc) {
|
||||
race *rc;
|
||||
test_setup();
|
||||
rc = test_create_race("human");
|
||||
CuAssertIntEquals(tc, 1000, rc_luxury_trade(rc));
|
||||
CuAssertIntEquals(tc, 500, rc_herb_trade(rc));
|
||||
set_param(&rc->parameters, "luxury_trade", "100");
|
||||
set_param(&rc->parameters, "herb_trade", "50");
|
||||
CuAssertIntEquals(tc, 100, rc_luxury_trade(rc));
|
||||
CuAssertIntEquals(tc, 50, rc_herb_trade(rc));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_market_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_market_curse);
|
||||
SUITE_ADD_TEST(suite, test_rc_trade);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue