diff --git a/conf/e3/config.json b/conf/e3/config.json index 1cecc89d2..a42961e03 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -56,6 +56,7 @@ "seed.population.max": 8, "rules.reserve.twophase": true, "rules.owners.force_leave": false, + "rules.wage.function": 2, "rules.monsters.attack_chance": 0.1, "rules.transfermen": false, "stealth.faction.other": false, diff --git a/conf/e3/rules.xml b/conf/e3/rules.xml index 421b54d7a..d59787551 100644 --- a/conf/e3/rules.xml +++ b/conf/e3/rules.xml @@ -28,7 +28,4 @@ - - - diff --git a/src/kernel/building.c b/src/kernel/building.c index 1a9e826e6..64b616fdc 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -811,10 +811,18 @@ minimum_wage(const region * r, const faction * f, const race * rc, int in_turn) * die Bauern wenn f == NULL. */ int wage(const region * r, const faction * f, const race * rc, int in_turn) { - if (global.wage) { - return global.wage(r, f, rc, in_turn); + static int config; + static int rule_wage; + if (config_changed(&config)) { + rule_wage = config_get_int("rules.wage.function", 1); } - return default_wage(r, f, rc, in_turn); + if (rule_wage==0) { + return 0; + } + if (rule_wage==1) { + return default_wage(r, f, rc, in_turn); + } + return minimum_wage(r, f, rc, in_turn); } int cmp_wage(const struct building *b, const building * a) @@ -913,7 +921,6 @@ int cmp_current_owner(const building * b, const building * a) void register_buildings(void) { - register_function((pf_generic)minimum_wage, "minimum_wage"); register_function((pf_generic)init_smithy, "init_smithy"); register_function((pf_generic)castle_name, "castle_name"); register_function((pf_generic)castle_name_2, "castle_name_2"); diff --git a/src/kernel/config.c b/src/kernel/config.c index 6d84a7c73..4b3ab5a91 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -796,7 +796,6 @@ bool config_token(const char *key, const char *tok) { } void free_config(void) { - global.wage = NULL; free_params(&configuration); ++config_cache_key; } diff --git a/src/kernel/config.h b/src/kernel/config.h index c8c2e4be9..a4378332d 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -110,8 +110,6 @@ extern "C" { typedef struct settings { struct attrib *attribs; void *vm_state; - int(*wage) (const struct region * r, const struct faction * f, - const struct race * rc, int in_turn); } settings; void set_param(struct param **p, const char *key, const char *value); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index dcaf97580..7cb871785 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -883,44 +883,6 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) return itype; } -static int parse_rules(xmlDocPtr doc) -{ - xmlXPathContextPtr xpath = xmlXPathNewContext(doc); - xmlXPathObjectPtr functions; - xmlNodeSetPtr nodes; - int i; - - /* reading eressea/resources/resource */ - functions = xmlXPathEvalExpression(BAD_CAST "/eressea/rules/function", xpath); - nodes = functions->nodesetval; - for (i = 0; i != nodes->nodeNr; ++i) { - xmlNodePtr node = nodes->nodeTab[i]; - xmlChar *propValue; - pf_generic fun; - - parse_function(node, &fun, &propValue); - - if (fun == NULL) { - log_error("unknown function for rule '%s' %s\n", (const char *)propValue); - xmlFree(propValue); - continue; - } - assert(propValue != NULL); - if (strcmp((const char *)propValue, "wage") == 0) { - global.wage = - (int(*)(const struct region *, const struct faction *, - const struct race *, int))fun; - } - else { - log_error("unknown function for rule '%s'\n", (const char *)propValue); - } - xmlFree(propValue); - } - xmlXPathFreeObject(functions); - xmlXPathFreeContext(xpath); - return 0; -} - static int parse_resources(xmlDocPtr doc) { xmlXPathContextPtr xpath = xmlXPathNewContext(doc); @@ -1960,8 +1922,6 @@ static int parse_strings(xmlDocPtr doc) void register_xmlreader(void) { - xml_register_callback(parse_rules); - xml_register_callback(parse_races); xml_register_callback(parse_calendar); xml_register_callback(parse_resources); diff --git a/src/laws.test.c b/src/laws.test.c index 9ed457af7..ce8ca2c19 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1444,15 +1444,10 @@ static void test_show_race(CuTest *tc) { test_cleanup(); } -static int low_wage(const region * r, const faction * f, const race * rc, int in_turn) { - return 1; -} - static void test_immigration(CuTest * tc) { region *r; double inject[] = { 1 }; - int (*old_wage)(const region*, const faction*, const race*, int) = global.wage; test_setup(); r = test_create_region(0, 0, 0); @@ -1472,10 +1467,9 @@ static void test_immigration(CuTest * tc) random_source_inject_array(inject, 2); - global.wage = low_wage; + config_set("rules.wage.function", "0"); immigration(); CuAssertIntEquals(tc, 2, rpeasants(r)); - global.wage = old_wage; test_cleanup(); }