forked from github/server
introducing config_set and config_get so we don't have to refer to globals.parameters everywhere
This commit is contained in:
parent
66dd1b8172
commit
b05fe9316a
|
@ -73,7 +73,7 @@ TOLUA_BINDING(config.pkg bind_config.h)
|
||||||
TOLUA_BINDING(process.pkg bind_process.h)
|
TOLUA_BINDING(process.pkg bind_process.h)
|
||||||
TOLUA_BINDING(game.pkg bind_eressea.h config.h)
|
TOLUA_BINDING(game.pkg bind_eressea.h config.h)
|
||||||
TOLUA_BINDING(eressea.pkg bind_eressea.h)
|
TOLUA_BINDING(eressea.pkg bind_eressea.h)
|
||||||
TOLUA_BINDING(settings.pkg bind_settings.h)
|
TOLUA_BINDING(settings.pkg kenel/config.h)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
set (ERESSEA_SRC
|
set (ERESSEA_SRC
|
||||||
|
@ -144,7 +144,6 @@ set(SERVER_SRC
|
||||||
bind_monsters.c
|
bind_monsters.c
|
||||||
bind_process.c
|
bind_process.c
|
||||||
bind_region.c
|
bind_region.c
|
||||||
bind_settings.c
|
|
||||||
bind_ship.c
|
bind_ship.c
|
||||||
bind_storage.c
|
bind_storage.c
|
||||||
bind_unit.c
|
bind_unit.c
|
||||||
|
|
|
@ -98,8 +98,7 @@ static int begin_potion(unit * u, const potion_type * ptype, struct order *ord)
|
||||||
|
|
||||||
if (rule_multipotion < 0) {
|
if (rule_multipotion < 0) {
|
||||||
/* should we allow multiple different potions to be used the same turn? */
|
/* should we allow multiple different potions to be used the same turn? */
|
||||||
rule_multipotion =
|
rule_multipotion = config_get_int("rules.magic.multipotion", 0);
|
||||||
get_param_int(global.parameters, "rules.magic.multipotion", 0);
|
|
||||||
}
|
}
|
||||||
if (!rule_multipotion) {
|
if (!rule_multipotion) {
|
||||||
const potion_type *use = ugetpotionuse(u);
|
const potion_type *use = ugetpotionuse(u);
|
||||||
|
@ -130,9 +129,9 @@ static int do_potion(unit * u, region *r, const potion_type * ptype, int amount)
|
||||||
static int tree_type = -1;
|
static int tree_type = -1;
|
||||||
static int tree_count = -1;
|
static int tree_count = -1;
|
||||||
if (tree_type < 0) {
|
if (tree_type < 0) {
|
||||||
tree_type = get_param_int(global.parameters, "rules.magic.wol_type", 1);
|
tree_type = config_get_int("rules.magic.wol_type", 1);
|
||||||
tree_count =
|
tree_count =
|
||||||
get_param_int(global.parameters, "rules.magic.wol_effect", 10);
|
config_get_int("rules.magic.wol_effect", 10);
|
||||||
}
|
}
|
||||||
/* mallorn is required to make mallorn forests, wood for regular ones */
|
/* mallorn is required to make mallorn forests, wood for regular ones */
|
||||||
if (fval(r, RF_MALLORN)) {
|
if (fval(r, RF_MALLORN)) {
|
||||||
|
|
|
@ -17,18 +17,18 @@
|
||||||
|
|
||||||
static void test_rules(CuTest *tc) {
|
static void test_rules(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
set_param(&global.parameters, "stealth.faction.other", NULL);
|
config_set("stealth.faction.other", NULL);
|
||||||
CuAssertIntEquals(tc, true, rule_stealth_other());
|
CuAssertIntEquals(tc, true, rule_stealth_other());
|
||||||
set_param(&global.parameters, "stealth.faction.other", "0");
|
config_set("stealth.faction.other", "0");
|
||||||
CuAssertIntEquals(tc, false, rule_stealth_other());
|
CuAssertIntEquals(tc, false, rule_stealth_other());
|
||||||
set_param(&global.parameters, "stealth.faction.other", "1");
|
config_set("stealth.faction.other", "1");
|
||||||
CuAssertIntEquals(tc, true, rule_stealth_other());
|
CuAssertIntEquals(tc, true, rule_stealth_other());
|
||||||
|
|
||||||
set_param(&global.parameters, "stealth.faction.anon", NULL);
|
config_set("stealth.faction.anon", NULL);
|
||||||
CuAssertIntEquals(tc, true, rule_stealth_anon());
|
CuAssertIntEquals(tc, true, rule_stealth_anon());
|
||||||
set_param(&global.parameters, "stealth.faction.anon", "0");
|
config_set("stealth.faction.anon", "0");
|
||||||
CuAssertIntEquals(tc, false, rule_stealth_anon());
|
CuAssertIntEquals(tc, false, rule_stealth_anon());
|
||||||
set_param(&global.parameters, "stealth.faction.anon", "1");
|
config_set("stealth.faction.anon", "1");
|
||||||
CuAssertIntEquals(tc, true, rule_stealth_anon());
|
CuAssertIntEquals(tc, true, rule_stealth_anon());
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ static void test_otherfaction(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
f = test_create_faction(0);
|
f = test_create_faction(0);
|
||||||
set_param(&global.parameters, "stealth.faction.other", "1");
|
config_set("stealth.faction.other", "1");
|
||||||
CuAssertIntEquals(tc, true, rule_stealth_other());
|
CuAssertIntEquals(tc, true, rule_stealth_other());
|
||||||
CuAssertPtrEquals(tc, u->faction, visible_faction(f, u));
|
CuAssertPtrEquals(tc, u->faction, visible_faction(f, u));
|
||||||
a_add(&u->attribs, make_otherfaction(f));
|
a_add(&u->attribs, make_otherfaction(f));
|
||||||
|
|
|
@ -223,7 +223,7 @@ void process_explain(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_reserve(void) {
|
void process_reserve(void) {
|
||||||
int rule = get_param_int(global.parameters, "rules.reserve.twophase", 0);
|
int rule = config_get_int("rules.reserve.twophase", 0);
|
||||||
if (rule) {
|
if (rule) {
|
||||||
process_cmd(K_RESERVE, reserve_self, 0);
|
process_cmd(K_RESERVE, reserve_self, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
#include "bind_settings.h"
|
|
||||||
|
|
||||||
#include <platform.h>
|
|
||||||
#include <kernel/config.h>
|
|
||||||
|
|
||||||
const char * settings_get(const char *key)
|
|
||||||
{
|
|
||||||
return get_param(global.parameters, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void settings_set(const char *key, const char *value)
|
|
||||||
{
|
|
||||||
set_param(&global.parameters, key, value);
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
#ifndef BIND_ERESSEA_SETTINGS_H
|
|
||||||
#define BIND_ERESSEA_SETTINGS_H
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char * settings_get(const char *key);
|
|
||||||
void settings_set(const char *key, const char *value);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -75,11 +75,11 @@ static void test_give_unit(CuTest * tc) {
|
||||||
env.f2 = test_create_faction(0);
|
env.f2 = test_create_faction(0);
|
||||||
setup_give(&env);
|
setup_give(&env);
|
||||||
env.r->terrain = test_create_terrain("ocean", SEA_REGION);
|
env.r->terrain = test_create_terrain("ocean", SEA_REGION);
|
||||||
set_param(&global.parameters, "rules.give.max_men", "0");
|
config_set("rules.give.max_men", "0");
|
||||||
give_unit(env.src, env.dst, NULL);
|
give_unit(env.src, env.dst, NULL);
|
||||||
CuAssertPtrEquals(tc, env.f1, env.src->faction);
|
CuAssertPtrEquals(tc, env.f1, env.src->faction);
|
||||||
CuAssertIntEquals(tc, 0, env.f2->newbies);
|
CuAssertIntEquals(tc, 0, env.f2->newbies);
|
||||||
set_param(&global.parameters, "rules.give.max_men", "-1");
|
config_set("rules.give.max_men", "-1");
|
||||||
give_unit(env.src, env.dst, NULL);
|
give_unit(env.src, env.dst, NULL);
|
||||||
CuAssertPtrEquals(tc, env.f2, env.src->faction);
|
CuAssertPtrEquals(tc, env.f2, env.src->faction);
|
||||||
CuAssertIntEquals(tc, 1, env.f2->newbies);
|
CuAssertIntEquals(tc, 1, env.f2->newbies);
|
||||||
|
@ -117,7 +117,7 @@ static void test_give_men_limit(CuTest * tc) {
|
||||||
env.f2 = test_create_faction(0);
|
env.f2 = test_create_faction(0);
|
||||||
env.f1 = test_create_faction(0);
|
env.f1 = test_create_faction(0);
|
||||||
setup_give(&env);
|
setup_give(&env);
|
||||||
set_param(&global.parameters, "rules.give.max_men", "1");
|
config_set("rules.give.max_men", "1");
|
||||||
|
|
||||||
/* below the limit, give men, increase newbies counter */
|
/* below the limit, give men, increase newbies counter */
|
||||||
usetcontact(env.dst, env.src);
|
usetcontact(env.dst, env.src);
|
||||||
|
@ -308,7 +308,7 @@ static void test_give_okay(CuTest * tc) {
|
||||||
env.f2 = env.f1 = test_create_faction(0);
|
env.f2 = env.f1 = test_create_faction(0);
|
||||||
setup_give(&env);
|
setup_give(&env);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.give.flags", "0");
|
config_set("rules.give.flags", "0");
|
||||||
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
|
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ static void test_give_denied_by_rules(CuTest * tc) {
|
||||||
env.f2 = test_create_faction(0);
|
env.f2 = test_create_faction(0);
|
||||||
setup_give(&env);
|
setup_give(&env);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.give.flags", "0");
|
config_set("rules.give.flags", "0");
|
||||||
CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, 0));
|
CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, 0));
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
|
@ -853,8 +853,8 @@ static void handlekey(state * st, int c)
|
||||||
new_players = read_newfactions(sbuffer);
|
new_players = read_newfactions(sbuffer);
|
||||||
}
|
}
|
||||||
cnormalize(&st->cursor, &nx, &ny);
|
cnormalize(&st->cursor, &nx, &ny);
|
||||||
minpop = get_param_int(global.parameters, "seed.population.min", 8);
|
minpop = config_get_int("seed.population.min", 8);
|
||||||
maxpop = get_param_int(global.parameters, "seed.population.max", minpop);
|
maxpop = config_get_int("seed.population.max", minpop);
|
||||||
if (maxpop > minpop) {
|
if (maxpop > minpop) {
|
||||||
n = rng_int() % (maxpop - minpop) + minpop;
|
n = rng_int() % (maxpop - minpop) + minpop;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1572,6 +1572,22 @@ bool markets_module(void)
|
||||||
return get_param_int(global.parameters, "modules.markets", 0);
|
return get_param_int(global.parameters, "modules.markets", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void config_set(const char *key, const char *value) {
|
||||||
|
set_param(&global.parameters, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *config_get(const char *key) {
|
||||||
|
return get_param(global.parameters, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
int config_get_int(const char *key, int def) {
|
||||||
|
return get_param_int(global.parameters, key, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
double config_get_flt(const char *key, double def) {
|
||||||
|
return get_param_flt(global.parameters, key, def);
|
||||||
|
}
|
||||||
|
|
||||||
/** releases all memory associated with the game state.
|
/** releases all memory associated with the game state.
|
||||||
* call this function before calling read_game() to load a new game
|
* call this function before calling read_game() to load a new game
|
||||||
* if you have a previously loaded state in memory.
|
* if you have a previously loaded state in memory.
|
||||||
|
|
|
@ -268,13 +268,18 @@ extern "C" {
|
||||||
|
|
||||||
const char *dbrace(const struct race *rc);
|
const char *dbrace(const struct race *rc);
|
||||||
|
|
||||||
void set_param(struct param **p, const char *key, const char *data);
|
void set_param(struct param **p, const char *key, const char *value);
|
||||||
const char *get_param(const struct param *p, const char *key);
|
const char *get_param(const struct param *p, const char *key);
|
||||||
int get_param_int(const struct param *p, const char *key, int def);
|
int get_param_int(const struct param *p, const char *key, int def);
|
||||||
int check_param(const struct param *p, const char *key, const char *searchvalue);
|
int check_param(const struct param *p, const char *key, const char *searchvalue);
|
||||||
double get_param_flt(const struct param *p, const char *key, double def);
|
double get_param_flt(const struct param *p, const char *key, double def);
|
||||||
void free_params(struct param **pp);
|
void free_params(struct param **pp);
|
||||||
|
|
||||||
|
void config_set(const char *key, const char *value);
|
||||||
|
const char *config_get(const char *key);
|
||||||
|
int config_get_int(const char *key, int def);
|
||||||
|
double config_get_flt(const char *key, double def);
|
||||||
|
|
||||||
bool ExpensiveMigrants(void);
|
bool ExpensiveMigrants(void);
|
||||||
int NMRTimeout(void);
|
int NMRTimeout(void);
|
||||||
int LongHunger(const struct unit *u);
|
int LongHunger(const struct unit *u);
|
||||||
|
|
|
@ -533,7 +533,7 @@ static void disable_feature(const char *str) {
|
||||||
}
|
}
|
||||||
_snprintf(name, sizeof(name), "%s.enabled", str);
|
_snprintf(name, sizeof(name), "%s.enabled", str);
|
||||||
log_info("disable feature %s\n", name);
|
log_info("disable feature %s\n", name);
|
||||||
set_param(&global.parameters, name, "0");
|
config_set(name, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void json_disable_features(cJSON *json) {
|
static void json_disable_features(cJSON *json) {
|
||||||
|
@ -788,7 +788,7 @@ static void json_settings(cJSON *json) {
|
||||||
}
|
}
|
||||||
for (child = json->child; child; child = child->next) {
|
for (child = json->child; child; child = child->next) {
|
||||||
if (child->valuestring) {
|
if (child->valuestring) {
|
||||||
set_param(&global.parameters, child->string, child->valuestring);
|
config_set(child->string, child->valuestring);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char value[32];
|
char value[32];
|
||||||
|
@ -798,7 +798,7 @@ static void json_settings(cJSON *json) {
|
||||||
else {
|
else {
|
||||||
_snprintf(value, sizeof(value), "%d", child->valueint);
|
_snprintf(value, sizeof(value), "%d", child->valueint);
|
||||||
}
|
}
|
||||||
set_param(&global.parameters, child->string, value);
|
config_set(child->string, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,7 +399,7 @@ static ship *setup_ship(void) {
|
||||||
region *r;
|
region *r;
|
||||||
ship_type *stype;
|
ship_type *stype;
|
||||||
|
|
||||||
set_param(&global.parameters, "movement.shipspeed.skillbonus", "0");
|
config_set("movement.shipspeed.skillbonus", "0");
|
||||||
r = test_create_region(0, 0, test_create_terrain("ocean", 0));
|
r = test_create_region(0, 0, test_create_terrain("ocean", 0));
|
||||||
stype = test_create_shiptype("longboat");
|
stype = test_create_shiptype("longboat");
|
||||||
stype->cptskill = 1;
|
stype->cptskill = 1;
|
||||||
|
@ -558,7 +558,7 @@ static void test_shipspeed_max_range(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
sh = setup_ship();
|
sh = setup_ship();
|
||||||
setup_crew(sh, 0, &cap, &crew);
|
setup_crew(sh, 0, &cap, &crew);
|
||||||
set_param(&global.parameters, "movement.shipspeed.skillbonus", "5");
|
config_set("movement.shipspeed.skillbonus", "5");
|
||||||
r = sh->region;
|
r = sh->region;
|
||||||
f = test_create_faction(0);
|
f = test_create_faction(0);
|
||||||
assert(r && f);
|
assert(r && f);
|
||||||
|
|
|
@ -284,15 +284,15 @@ static void test_skill_hunger(CuTest *tc) {
|
||||||
set_level(u, SK_SAILING, 6);
|
set_level(u, SK_SAILING, 6);
|
||||||
fset(u, UFL_HUNGER);
|
fset(u, UFL_HUNGER);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.hunger.reduces_skill", "0");
|
config_set("rules.hunger.reduces_skill", "0");
|
||||||
CuAssertIntEquals(tc, 6, effskill(u, SK_ARMORER, 0));
|
CuAssertIntEquals(tc, 6, effskill(u, SK_ARMORER, 0));
|
||||||
CuAssertIntEquals(tc, 6, effskill(u, SK_SAILING, 0));
|
CuAssertIntEquals(tc, 6, effskill(u, SK_SAILING, 0));
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.hunger.reduces_skill", "1");
|
config_set("rules.hunger.reduces_skill", "1");
|
||||||
CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER, 0));
|
CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER, 0));
|
||||||
CuAssertIntEquals(tc, 3, effskill(u, SK_SAILING, 0));
|
CuAssertIntEquals(tc, 3, effskill(u, SK_SAILING, 0));
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.hunger.reduces_skill", "2");
|
config_set("rules.hunger.reduces_skill", "2");
|
||||||
CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER, 0));
|
CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER, 0));
|
||||||
CuAssertIntEquals(tc, 5, effskill(u, SK_SAILING, 0));
|
CuAssertIntEquals(tc, 5, effskill(u, SK_SAILING, 0));
|
||||||
set_level(u, SK_SAILING, 2);
|
set_level(u, SK_SAILING, 2);
|
||||||
|
@ -371,7 +371,7 @@ static void test_produceexp(CuTest *tc) {
|
||||||
g_tc = tc;
|
g_tc = tc;
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
set_param(&global.parameters, "study.from_use", "0.5");
|
config_set("study.from_use", "0.5");
|
||||||
produceexp_ex(u, SK_ALCHEMY, 1, cb_learn_one);
|
produceexp_ex(u, SK_ALCHEMY, 1, cb_learn_one);
|
||||||
produceexp_ex(u, SK_ALCHEMY, 2, cb_learn_two);
|
produceexp_ex(u, SK_ALCHEMY, 2, cb_learn_two);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
|
@ -233,16 +233,16 @@ static void test_display_cmd(CuTest *tc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_rule_force_leave(CuTest *tc) {
|
static void test_rule_force_leave(CuTest *tc) {
|
||||||
set_param(&global.parameters, "rules.owners.force_leave", "0");
|
config_set("rules.owners.force_leave", "0");
|
||||||
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL));
|
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL));
|
||||||
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
||||||
set_param(&global.parameters, "rules.owners.force_leave", "1");
|
config_set("rules.owners.force_leave", "1");
|
||||||
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL));
|
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL));
|
||||||
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
||||||
set_param(&global.parameters, "rules.owners.force_leave", "2");
|
config_set("rules.owners.force_leave", "2");
|
||||||
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL));
|
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL));
|
||||||
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
||||||
set_param(&global.parameters, "rules.owners.force_leave", "3");
|
config_set("rules.owners.force_leave", "3");
|
||||||
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL));
|
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL));
|
||||||
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
||||||
}
|
}
|
||||||
|
@ -413,13 +413,13 @@ static void test_fishing_gets_reset(CuTest * tc)
|
||||||
|
|
||||||
static void test_unit_limit(CuTest * tc)
|
static void test_unit_limit(CuTest * tc)
|
||||||
{
|
{
|
||||||
set_param(&global.parameters, "rules.limit.faction", "250");
|
config_set("rules.limit.faction", "250");
|
||||||
CuAssertIntEquals(tc, 250, rule_faction_limit());
|
CuAssertIntEquals(tc, 250, rule_faction_limit());
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.limit.faction", "200");
|
config_set("rules.limit.faction", "200");
|
||||||
CuAssertIntEquals(tc, 200, rule_faction_limit());
|
CuAssertIntEquals(tc, 200, rule_faction_limit());
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.limit.alliance", "250");
|
config_set("rules.limit.alliance", "250");
|
||||||
CuAssertIntEquals(tc, 250, rule_alliance_limit());
|
CuAssertIntEquals(tc, 250, rule_alliance_limit());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -432,12 +432,12 @@ static void test_cannot_create_unit_above_limit(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
set_param(&global.parameters, "rules.limit.faction", "4");
|
config_set("rules.limit.faction", "4");
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 0, checkunitnumber(f, 4));
|
CuAssertIntEquals(tc, 0, checkunitnumber(f, 4));
|
||||||
CuAssertIntEquals(tc, 2, checkunitnumber(f, 5));
|
CuAssertIntEquals(tc, 2, checkunitnumber(f, 5));
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.limit.alliance", "3");
|
config_set("rules.limit.alliance", "3");
|
||||||
CuAssertIntEquals(tc, 0, checkunitnumber(f, 3));
|
CuAssertIntEquals(tc, 0, checkunitnumber(f, 3));
|
||||||
CuAssertIntEquals(tc, 1, checkunitnumber(f, 4));
|
CuAssertIntEquals(tc, 1, checkunitnumber(f, 4));
|
||||||
}
|
}
|
||||||
|
@ -533,8 +533,8 @@ static void test_pay_cmd_other_building(CuTest *tc) {
|
||||||
setup_pay_cmd(&fix);
|
setup_pay_cmd(&fix);
|
||||||
f = fix.u1->faction;
|
f = fix.u1->faction;
|
||||||
b = test_create_building(fix.u1->region, bt_get_or_create("lighthouse"));
|
b = test_create_building(fix.u1->region, bt_get_or_create("lighthouse"));
|
||||||
set_param(&global.parameters, "rules.region_owners", "1");
|
config_set("rules.region_owners", "1");
|
||||||
set_param(&global.parameters, "rules.region_owner_pay_building", "lighthouse");
|
config_set("rules.region_owner_pay_building", "lighthouse");
|
||||||
update_owners(b->region);
|
update_owners(b->region);
|
||||||
|
|
||||||
_snprintf(cmd, sizeof(cmd), "NOT %s", itoa36(b->no));
|
_snprintf(cmd, sizeof(cmd), "NOT %s", itoa36(b->no));
|
||||||
|
@ -633,7 +633,7 @@ static void test_newbie_cannot_guard(CuTest *tc) {
|
||||||
guard_fixture fix;
|
guard_fixture fix;
|
||||||
|
|
||||||
setup_guard(&fix, true);
|
setup_guard(&fix, true);
|
||||||
set_param(&global.parameters, "NewbieImmunity", "4");
|
config_set("NewbieImmunity", "4");
|
||||||
CuAssertTrue(tc, IsImmune(fix.u->faction));
|
CuAssertTrue(tc, IsImmune(fix.u->faction));
|
||||||
update_guards();
|
update_guards();
|
||||||
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
||||||
|
@ -726,15 +726,15 @@ static void statistic_test(CuTest *tc, int peasants, int luck, int maxp,
|
||||||
static void test_peasant_luck_effect(CuTest *tc) {
|
static void test_peasant_luck_effect(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.peasants.peasantluck.factor", "10");
|
config_set("rules.peasants.peasantluck.factor", "10");
|
||||||
set_param(&global.parameters, "rules.peasants.growth.factor", "0.001");
|
config_set("rules.peasants.growth.factor", "0.001");
|
||||||
|
|
||||||
statistic_test(tc, 100, 0, 1000, 0, 0, 0);
|
statistic_test(tc, 100, 0, 1000, 0, 0, 0);
|
||||||
statistic_test(tc, 100, 2, 1000, 0, 1, 1);
|
statistic_test(tc, 100, 2, 1000, 0, 1, 1);
|
||||||
statistic_test(tc, 1000, 400, 1000, 0, 3, 3);
|
statistic_test(tc, 1000, 400, 1000, 0, 3, 3);
|
||||||
statistic_test(tc, 1000, 1000, 2000, .5, 1, 501);
|
statistic_test(tc, 1000, 1000, 2000, .5, 1, 501);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.peasants.growth.factor", "1");
|
config_set("rules.peasants.growth.factor", "1");
|
||||||
statistic_test(tc, 1000, 1000, 1000, 0, 501, 501);
|
statistic_test(tc, 1000, 1000, 1000, 0, 501, 501);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
@ -1003,7 +1003,7 @@ static void test_long_order_hungry(CuTest *tc) {
|
||||||
// see also default_order
|
// see also default_order
|
||||||
unit *u;
|
unit *u;
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
set_param(&global.parameters, "hunger.long", "1");
|
config_set("hunger.long", "1");
|
||||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
fset(u, UFL_HUNGER);
|
fset(u, UFL_HUNGER);
|
||||||
u->faction->locale = get_or_create_locale("de");
|
u->faction->locale = get_or_create_locale("de");
|
||||||
|
@ -1081,7 +1081,7 @@ static void test_ally_cmd(CuTest *tc) {
|
||||||
static void test_nmr_warnings(CuTest *tc) {
|
static void test_nmr_warnings(CuTest *tc) {
|
||||||
faction *f1, *f2;
|
faction *f1, *f2;
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
set_param(&global.parameters, "nmr.timeout", "3");
|
config_set("nmr.timeout", "3");
|
||||||
f1 = test_create_faction(0);
|
f1 = test_create_faction(0);
|
||||||
f2 = test_create_faction(0);
|
f2 = test_create_faction(0);
|
||||||
f2->age = 2;
|
f2->age = 2;
|
||||||
|
|
|
@ -162,7 +162,7 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
||||||
switch (argi[1]) {
|
switch (argi[1]) {
|
||||||
case 'r':
|
case 'r':
|
||||||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||||
set_param(&global.parameters, "config.rules", arg);
|
config_set("config.rules", arg);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
i = get_arg(argc, argv, 2, i, &luafile, 0);
|
i = get_arg(argc, argv, 2, i, &luafile, 0);
|
||||||
|
|
|
@ -43,7 +43,7 @@ static void test_market_curse(CuTest * tc)
|
||||||
ltype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
|
ltype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
|
||||||
lux = new_luxurytype(ltype, 0);
|
lux = new_luxurytype(ltype, 0);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.region_owners", "1");
|
config_set("rules.region_owners", "1");
|
||||||
|
|
||||||
btype = (building_type *)calloc(1, sizeof(building_type));
|
btype = (building_type *)calloc(1, sizeof(building_type));
|
||||||
btype->_name = _strdup("market");
|
btype->_name = _strdup("market");
|
||||||
|
|
|
@ -212,7 +212,7 @@ static void test_walkingcapacity(CuTest *tc) {
|
||||||
assert(itype);
|
assert(itype);
|
||||||
i_change(&u->items, itype, 1);
|
i_change(&u->items, itype, 1);
|
||||||
CuAssertIntEquals(tc, cap + (STRENGTHMULTIPLIER-1) * u->_race->capacity, walkingcapacity(u));
|
CuAssertIntEquals(tc, cap + (STRENGTHMULTIPLIER-1) * u->_race->capacity, walkingcapacity(u));
|
||||||
set_param(&global.parameters, "rules.trollbelt.multiplier", "5");
|
config_set("rules.trollbelt.multiplier", "5");
|
||||||
CuAssertIntEquals(tc, cap + 4 * u->_race->capacity, walkingcapacity(u));
|
CuAssertIntEquals(tc, cap + 4 * u->_race->capacity, walkingcapacity(u));
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
|
@ -21,7 +21,7 @@ static void setup_piracy(void) {
|
||||||
ship_type *st_boat;
|
ship_type *st_boat;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
set_param(&global.parameters, "rules.ship.storms", "0");
|
config_set("rules.ship.storms", "0");
|
||||||
lang = get_or_create_locale("de");
|
lang = get_or_create_locale("de");
|
||||||
locale_setstring(lang, directions[D_EAST], "OSTEN");
|
locale_setstring(lang, directions[D_EAST], "OSTEN");
|
||||||
init_directions(lang);
|
init_directions(lang);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
$#undef tolua_reg_types
|
$#undef tolua_reg_types
|
||||||
$#define tolua_reg_types tolua_reg_types_config
|
$#define tolua_reg_types tolua_reg_types_config
|
||||||
$#include "bind_settings.h"
|
$#include <kernel/config.h>
|
||||||
|
|
||||||
module eressea {
|
module eressea {
|
||||||
module settings {
|
module settings {
|
||||||
void settings_set @ set(const char *key, const char *value);
|
void config_set @ set(const char *key, const char *value);
|
||||||
const char * settings_get @ get(const char *key);
|
const char * config_get @ get(const char *key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ LUALIB_API int luaopen_settings (lua_State* tolua_S);
|
||||||
|
|
||||||
#undef tolua_reg_types
|
#undef tolua_reg_types
|
||||||
#define tolua_reg_types tolua_reg_types_settings
|
#define tolua_reg_types tolua_reg_types_settings
|
||||||
#include "bind_settings.h"
|
#include <kernel/config.h>
|
||||||
|
|
||||||
/* function to register type */
|
/* function to register type */
|
||||||
static void tolua_reg_types (lua_State* tolua_S)
|
static void tolua_reg_types (lua_State* tolua_S)
|
||||||
|
@ -44,7 +44,7 @@ static int tolua_settings_eressea_settings_set00(lua_State* tolua_S)
|
||||||
const char* key = ((const char*) tolua_tostring(tolua_S,1,0));
|
const char* key = ((const char*) tolua_tostring(tolua_S,1,0));
|
||||||
const char* value = ((const char*) tolua_tostring(tolua_S,2,0));
|
const char* value = ((const char*) tolua_tostring(tolua_S,2,0));
|
||||||
{
|
{
|
||||||
settings_set(key,value);
|
config_set(key,value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -70,7 +70,7 @@ static int tolua_settings_eressea_settings_get00(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
const char* key = ((const char*) tolua_tostring(tolua_S,1,0));
|
const char* key = ((const char*) tolua_tostring(tolua_S,1,0));
|
||||||
{
|
{
|
||||||
const char* tolua_ret = (const char*) settings_get(key);
|
const char* tolua_ret = (const char*) config_get(key);
|
||||||
tolua_pushstring(tolua_S,(const char*)tolua_ret);
|
tolua_pushstring(tolua_S,(const char*)tolua_ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ static void setup_study(study_fixture *fix, skill_t sk) {
|
||||||
|
|
||||||
assert(fix);
|
assert(fix);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
set_param(&global.parameters, "study.random_progress", "0");
|
config_set("study.random_progress", "0");
|
||||||
test_create_world();
|
test_create_world();
|
||||||
r = test_create_region(0, 0, 0);
|
r = test_create_region(0, 0, 0);
|
||||||
f = test_create_faction(0);
|
f = test_create_faction(0);
|
||||||
|
|
|
@ -32,7 +32,7 @@ void test_upkeep_default(CuTest * tc)
|
||||||
u2 = test_create_unit(f2, r);
|
u2 = test_create_unit(f2, r);
|
||||||
assert(r && u1 && u2);
|
assert(r && u1 && u2);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.food.flags", "0");
|
config_set("rules.food.flags", "0");
|
||||||
i_change(&u1->items, i_silver, 20);
|
i_change(&u1->items, i_silver, 20);
|
||||||
get_food(r);
|
get_food(r);
|
||||||
// since u1 and u2 are not allied, u1 should not help u2 with upkeep
|
// since u1 and u2 are not allied, u1 should not help u2 with upkeep
|
||||||
|
@ -60,7 +60,7 @@ void test_upkeep_hunger_damage(CuTest * tc)
|
||||||
u1 = test_create_unit(f1, r);
|
u1 = test_create_unit(f1, r);
|
||||||
assert(r && u1);
|
assert(r && u1);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.food.flags", "0");
|
config_set("rules.food.flags", "0");
|
||||||
u1->hp = 100;
|
u1->hp = 100;
|
||||||
get_food(r);
|
get_food(r);
|
||||||
// since u1 and u2 are not allied, u1 should not help u2 with upkeep
|
// since u1 and u2 are not allied, u1 should not help u2 with upkeep
|
||||||
|
@ -86,7 +86,7 @@ void test_upkeep_from_pool(CuTest * tc)
|
||||||
u2 = test_create_unit(u1->faction, r);
|
u2 = test_create_unit(u1->faction, r);
|
||||||
assert(r && u1 && u2);
|
assert(r && u1 && u2);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.food.flags", "0");
|
config_set("rules.food.flags", "0");
|
||||||
i_change(&u1->items, i_silver, 30);
|
i_change(&u1->items, i_silver, 30);
|
||||||
get_food(r);
|
get_food(r);
|
||||||
CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
|
CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
|
||||||
|
@ -122,7 +122,7 @@ void test_upkeep_from_friend(CuTest * tc)
|
||||||
u2 = test_create_unit(f2, r);
|
u2 = test_create_unit(f2, r);
|
||||||
assert(r && u1 && u2);
|
assert(r && u1 && u2);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.food.flags", "0");
|
config_set("rules.food.flags", "0");
|
||||||
i_change(&u1->items, i_silver, 30);
|
i_change(&u1->items, i_silver, 30);
|
||||||
get_food(r);
|
get_food(r);
|
||||||
CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
|
CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
|
||||||
|
@ -151,7 +151,7 @@ void test_upkeep_free(CuTest * tc)
|
||||||
u = test_create_unit(test_create_faction(test_create_race("human")), r);
|
u = test_create_unit(test_create_faction(test_create_race("human")), r);
|
||||||
assert(r && u);
|
assert(r && u);
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.food.flags", "4"); // FOOD_IS_FREE
|
config_set("rules.food.flags", "4"); // FOOD_IS_FREE
|
||||||
get_food(r);
|
get_food(r);
|
||||||
CuAssertIntEquals(tc, 0, i_get(u->items, i_silver));
|
CuAssertIntEquals(tc, 0, i_get(u->items, i_silver));
|
||||||
CuAssertIntEquals(tc, 0, fval(u, UFL_HUNGER));
|
CuAssertIntEquals(tc, 0, fval(u, UFL_HUNGER));
|
||||||
|
|
Loading…
Reference in New Issue