produceexp uses a json-configurable constant

make get_param_flt return a double, floats are for wimps.
This commit is contained in:
Enno Rehling 2015-09-12 16:38:39 +02:00
parent 68c448b3fb
commit 9bdc811582
10 changed files with 19 additions and 19 deletions

View File

@ -2895,10 +2895,10 @@ static void aftermath(battle * b)
if (sh && fval(sh, SF_DAMAGED)) {
int n = b->turn - 2;
if (n > 0) {
float dmg =
double dmg =
get_param_flt(global.parameters, "rules.ship.damage.battleround",
0.05F);
damage_ship(sh, dmg * (float)n);
damage_ship(sh, dmg * n);
freset(sh, SF_DAMAGED);
}
}

View File

@ -191,7 +191,7 @@ static void chaos(region * r)
while (sh) {
ship *nsh = sh->next;
float dmg =
double dmg =
get_param_flt(global.parameters, "rules.ship.damage.atlantis",
0.50);
damage_ship(sh, dmg);

View File

@ -1123,10 +1123,10 @@ void set_basepath(const char *path)
g_basedir = path;
}
float get_param_flt(const struct param *p, const char *key, float def)
double get_param_flt(const struct param *p, const char *key, double def)
{
const char *str = get_param(p, key);
return str ? (float)atof(str) : def;
return str ? atof(str) : def;
}
void set_param(struct param **p, const char *key, const char *data)

View File

@ -284,7 +284,7 @@ extern "C" {
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 check_param(const struct param *p, const char *key, const char *searchvalue);
float get_param_flt(const struct param *p, const char *key, float def);
double get_param_flt(const struct param *p, const char *key, double def);
void free_params(struct param **pp);
bool ExpensiveMigrants(void);

View File

@ -1935,7 +1935,7 @@ bool unit_can_study(const unit *u) {
}
static double produceexp_chance(void) {
return global.producexpchance;
return get_param_flt(global.parameters, "study.from_use", 1.0 / 3);
}
void produceexp_ex(struct unit *u, skill_t sk, int n, bool (*learn)(unit *, skill_t, double))

View File

@ -354,13 +354,13 @@ static CuTest *g_tc;
static bool cb_learn_one(unit *u, skill_t sk, double chance) {
CuAssertIntEquals(g_tc, SK_ALCHEMY, sk);
CuAssertDblEquals(g_tc, global.producexpchance / u->number, chance, 0.01);
CuAssertDblEquals(g_tc, 0.5 / u->number, chance, 0.01);
return false;
}
static bool cb_learn_two(unit *u, skill_t sk, double chance) {
CuAssertIntEquals(g_tc, SK_ALCHEMY, sk);
CuAssertDblEquals(g_tc, 2 * global.producexpchance / u->number, chance, 0.01);
CuAssertDblEquals(g_tc, 2 * 0.5 / u->number, chance, 0.01);
return false;
}
@ -370,7 +370,7 @@ static void test_produceexp(CuTest *tc) {
g_tc = tc;
test_cleanup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
global.producexpchance = 1.0;
set_param(&global.parameters, "study.from_use", "0.5");
produceexp_ex(u, SK_ALCHEMY, 1, cb_learn_one);
produceexp_ex(u, SK_ALCHEMY, 2, cb_learn_two);
test_cleanup();

View File

@ -2762,14 +2762,14 @@ void sinkships(struct region * r)
if (fval(r->terrain, SEA_REGION)) {
if (!enoughsailors(sh, crew_skill(sh))) {
// ship is at sea, but not enough people to control it
float dmg = get_param_flt(global.parameters,
double dmg = get_param_flt(global.parameters,
"rules.ship.damage.nocrewocean",
0.30F);
damage_ship(sh, dmg);
}
} else if (!ship_owner(sh)) {
// any ship lying around without an owner slowly rots
float dmg = get_param_flt(global.parameters, "rules.ship.damage.nocrew", 0.05F);
double dmg = get_param_flt(global.parameters, "rules.ship.damage.nocrew", 0.05F);
damage_ship(sh, dmg);
}
}
@ -3496,7 +3496,7 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order
static double heal_factor(const unit * u)
{
static float elf_regen = -1;
static double elf_regen = -1;
switch (old_race(u_race(u))) {
case RC_TROLL:
case RC_DAEMON:

View File

@ -80,7 +80,7 @@ static void give_peasants(unit *u, const item_type *itype, int reduce) {
unit_addorder(u, parse_order(buf, u->faction->locale));
}
static float monster_attack_chance(void) {
static double monster_attack_chance(void) {
return get_param_flt(global.parameters, "rules.monsters.attack_chance", 0.4f);
}

View File

@ -704,7 +704,7 @@ static float damage_drift(void)
{
static float value = -1.0F;
if (value < 0) {
value = get_param_flt(global.parameters, "rules.ship.damage_drift", 0.02F);
value = (float)get_param_flt(global.parameters, "rules.ship.damage_drift", 0.02F);
}
return value;
}
@ -1955,7 +1955,7 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
ADDMSG(&f->msgs, msg_message("sailnolandingstorm", "ship region", sh, next_point));
}
else {
float dmg =
double dmg =
get_param_flt(global.parameters, "rules.ship.damage.nolanding",
0.10F);
ADDMSG(&f->msgs, msg_message("sailnolanding", "ship region", sh,

View File

@ -746,7 +746,7 @@ static void move_iceberg(region * r)
for (sh = r->ships; sh; sh = sh->next) {
/* Meldung an Kapitän */
float dmg =
double dmg =
get_param_flt(global.parameters, "rules.ship.damage.intoiceberg",
0.10F);
damage_ship(sh, dmg);
@ -759,7 +759,7 @@ static void move_iceberg(region * r)
translist(&rc->buildings, &r->buildings, rc->buildings);
}
while (rc->ships) {
float dmg =
double dmg =
get_param_flt(global.parameters, "rules.ship.damage.withiceberg",
0.10F);
fset(rc->ships, SF_SELECT);
@ -893,7 +893,7 @@ static void godcurse(void)
ship *sh;
for (sh = r->ships; sh;) {
ship *shn = sh->next;
float dmg =
double dmg =
get_param_flt(global.parameters, "rules.ship.damage.godcurse",
0.10F);
damage_ship(sh, dmg);