From 9bdc811582394fc5389b205cf54a3f905ac9adff Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 16:38:39 +0200 Subject: [PATCH] produceexp uses a json-configurable constant make get_param_flt return a double, floats are for wimps. --- src/battle.c | 4 ++-- src/chaos.c | 2 +- src/kernel/config.c | 4 ++-- src/kernel/config.h | 2 +- src/kernel/unit.c | 2 +- src/kernel/unit.test.c | 6 +++--- src/laws.c | 6 +++--- src/monsters.c | 2 +- src/move.c | 4 ++-- src/randenc.c | 6 +++--- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/battle.c b/src/battle.c index 075e2327c..3770199f6 100644 --- a/src/battle.c +++ b/src/battle.c @@ -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); } } diff --git a/src/chaos.c b/src/chaos.c index df478e0f4..5b6f9c89b 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -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); diff --git a/src/kernel/config.c b/src/kernel/config.c index dbc2d5c10..1bd2e6c21 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -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) diff --git a/src/kernel/config.h b/src/kernel/config.h index 23d887b99..c8fc106e6 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -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); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index e44c024dd..5fb841d9a 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -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)) diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 93c1cb95d..91333aa74 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -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(); diff --git a/src/laws.c b/src/laws.c index fce556ec7..41a0e72f3 100755 --- a/src/laws.c +++ b/src/laws.c @@ -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: diff --git a/src/monsters.c b/src/monsters.c index e010ee7ff..8de81c4c0 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -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); } diff --git a/src/move.c b/src/move.c index e1207f0fa..f5da898cc 100644 --- a/src/move.c +++ b/src/move.c @@ -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, diff --git a/src/randenc.c b/src/randenc.c index cdf7b9380..801aac4c4 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -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);