forked from github/server
Merge pull request #296 from ennorehling/feature/config-producexpchance
Bug 2137: calculating produceexp correctly
This commit is contained in:
commit
32ff7c89bc
|
@ -53,7 +53,7 @@
|
|||
<xi:include href="config://default/names-ghouls.xml"/>
|
||||
<xi:include href="config://default/names-dragons.xml"/>
|
||||
|
||||
<game name="Eressea">
|
||||
<game>
|
||||
<!-- Game specific settings -->
|
||||
|
||||
<order name="pay" disable="yes"/>
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<xi:include href="config://default/names-ghouls.xml"/>
|
||||
<xi:include href="config://default/names-dragons.xml"/>
|
||||
|
||||
<game name="E3">
|
||||
<game>
|
||||
<!-- Game specific settings -->
|
||||
<order name="besiege" disable="yes"/>
|
||||
<order name="steal" disable="yes"/>
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
"recruit.allow_merge": true,
|
||||
"study.expensivemigrants": true,
|
||||
"study.speedup": 2,
|
||||
"study.from_use": 0.4,
|
||||
"world.era": 3,
|
||||
"rules.migrants.max": 0,
|
||||
"rules.reserve.twophase": true,
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<xi:include href="config://default/names-ghouls.xml"/>
|
||||
<xi:include href="config://default/names-dragons.xml"/>
|
||||
|
||||
<game name="Deveron">
|
||||
<game>
|
||||
<order name="besiege" disable="yes"/>
|
||||
<order name="steal" disable="yes"/>
|
||||
<order name="buy" disable="yes"/>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
@ -1599,16 +1599,6 @@ int maintenance_cost(const struct unit *u)
|
|||
return u_race(u)->maintenance * u->number;
|
||||
}
|
||||
|
||||
int produceexp(struct unit *u, skill_t sk, int n)
|
||||
{
|
||||
if (global.producexpchance > 0.0F) {
|
||||
if (n == 0 || !playerrace(u_race(u)))
|
||||
return 0;
|
||||
learn_skill(u, sk, global.producexpchance);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lovar(double xpct_x2)
|
||||
{
|
||||
int n = (int)(xpct_x2 * 500) + 1;
|
||||
|
|
|
@ -261,8 +261,6 @@ extern "C" {
|
|||
unsigned int data_turn;
|
||||
struct param *parameters;
|
||||
void *vm_state;
|
||||
float producexpchance;
|
||||
int cookie;
|
||||
int data_version; /* TODO: eliminate in favor of gamedata.version */
|
||||
struct _dictionary_ *inifile;
|
||||
|
||||
|
@ -271,6 +269,10 @@ extern "C" {
|
|||
const struct race * rc, int in_turn);
|
||||
int(*maintenance) (const struct unit * u);
|
||||
} functions;
|
||||
/* the following are some cached values, because get_param can be slow.
|
||||
* you should almost never need to touch them */
|
||||
int cookie;
|
||||
double producexpchance_;
|
||||
} settings;
|
||||
|
||||
typedef struct helpmode {
|
||||
|
@ -284,7 +286,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);
|
||||
|
|
|
@ -1933,3 +1933,27 @@ bool unit_name_equals_race(const unit *u) {
|
|||
bool unit_can_study(const unit *u) {
|
||||
return !((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE));
|
||||
}
|
||||
|
||||
static double produceexp_chance(void) {
|
||||
static int update = 0;
|
||||
if (update != global.cookie) {
|
||||
global.producexpchance_ = get_param_flt(global.parameters, "study.from_use", 1.0 / 3);
|
||||
update = global.cookie;
|
||||
}
|
||||
return global.producexpchance_;
|
||||
}
|
||||
|
||||
void produceexp_ex(struct unit *u, skill_t sk, int n, bool (*learn)(unit *, skill_t, double))
|
||||
{
|
||||
if (n != 0 && playerrace(u_race(u))) {
|
||||
double chance = produceexp_chance();
|
||||
if (chance > 0.0F) {
|
||||
learn(u, sk, (n * chance) / u->number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void produceexp(struct unit *u, skill_t sk, int n)
|
||||
{
|
||||
produceexp_ex(u, sk, n, learn_skill);
|
||||
}
|
||||
|
|
|
@ -161,8 +161,9 @@ extern "C" {
|
|||
struct skill *unit_skill(const struct unit *u, skill_t id);
|
||||
bool has_skill(const unit * u, skill_t sk);
|
||||
int effskill(const struct unit *u, skill_t sk, const struct region *r);
|
||||
int produceexp(struct unit *u, skill_t sk, int n);
|
||||
int SkillCap(skill_t sk);
|
||||
void produceexp(struct unit *u, skill_t sk, int n);
|
||||
void produceexp_ex(struct unit *u, skill_t sk, int n, bool (*learn)(unit *, skill_t, double));
|
||||
|
||||
void set_level(struct unit *u, skill_t id, int level);
|
||||
int get_level(const struct unit *u, skill_t id);
|
||||
|
|
|
@ -350,6 +350,32 @@ static void test_age_familiar(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
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, 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 * 0.5 / u->number, chance, 0.01);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void test_produceexp(CuTest *tc) {
|
||||
unit *u;
|
||||
|
||||
g_tc = tc;
|
||||
test_cleanup();
|
||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 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();
|
||||
}
|
||||
|
||||
CuSuite *get_unit_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -368,5 +394,6 @@ CuSuite *get_unit_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_skill_hunger);
|
||||
SUITE_ADD_TEST(suite, test_skill_familiar);
|
||||
SUITE_ADD_TEST(suite, test_age_familiar);
|
||||
SUITE_ADD_TEST(suite, test_produceexp);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -2060,19 +2060,9 @@ static int parse_main(xmlDocPtr doc)
|
|||
xmlNodeSetPtr nodes = result->nodesetval;
|
||||
int i;
|
||||
|
||||
xmlChar *propValue;
|
||||
if (nodes->nodeNr > 0) {
|
||||
xmlNodePtr node = nodes->nodeTab[0];
|
||||
|
||||
global.producexpchance =
|
||||
(float)xml_fvalue(node, "learningbydoing", 1.0 / 3);
|
||||
|
||||
propValue = xmlGetProp(node, BAD_CAST "name");
|
||||
if (propValue != NULL) {
|
||||
global.gamename = _strdup((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
||||
xmlXPathFreeObject(result);
|
||||
|
||||
xpath->node = node;
|
||||
|
@ -2082,9 +2072,8 @@ static int parse_main(xmlDocPtr doc)
|
|||
for (i = 0; i != nodes->nodeNr; ++i) {
|
||||
xmlNodePtr node = nodes->nodeTab[i];
|
||||
xmlChar *propName = xmlGetProp(node, BAD_CAST "name");
|
||||
bool disable = xml_bvalue(node, "disable", false);
|
||||
|
||||
if (disable) {
|
||||
if (xml_bvalue(node, "disable", false)) {
|
||||
int k;
|
||||
for (k = 0; k != MAXKEYWORDS; ++k) {
|
||||
if (strcmp(keywords[k], (const char *)propName) == 0) {
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue