diff --git a/conf/e4/config.json b/conf/e4/config.json index 654213ede..027e4c655 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -77,7 +77,7 @@ "rules.blessed_harvest.flags": 1, "rules.magic.elfpower": true, "rules.magic.playerschools": "gwyrrd illaun draig cerddor", - "rules.build.other_buildings": 1, + "rules.build.other_buildings": true, "rules.economy.taxation": 1, "rules.food.flags": 2, "rules.economy.roqf": 5, diff --git a/src/economy.c b/src/economy.c index 26eb5251b..e4e52e0ce 100644 --- a/src/economy.c +++ b/src/economy.c @@ -3136,8 +3136,11 @@ static void peasant_taxes(region * r) static bool rule_auto_taxation(void) { - int rule = config_get_int("rules.economy.taxation", 0); - return rule != 0; + return config_get_int("rules.economy.taxation", 0) != 0; +} + +static bool rule_autowork(void) { + return config_get_int("work.auto", 0) != 0; } void produce(struct region *r) @@ -3145,7 +3148,6 @@ void produce(struct region *r) request workers[MAX_WORKERS]; request *taxorders, *lootorders, *sellorders, *stealorders, *buyorders; unit *u; - static int rule_autowork = -1; bool limited = true; request *nextworker = workers; assert(r); @@ -3160,10 +3162,6 @@ void produce(struct region *r) * * lehren vor lernen. */ - if (rule_autowork < 0) { - rule_autowork = config_get_int("work.auto", 0); - } - assert(rmoney(r) >= 0); assert(rpeasants(r) >= 0); @@ -3237,7 +3235,7 @@ void produce(struct region *r) break; case K_WORK: - if (!rule_autowork && do_work(u, u->thisorder, nextworker) == 0) { + if (!rule_autowork() && do_work(u, u->thisorder, nextworker) == 0) { assert(nextworker - workers < MAX_WORKERS); ++nextworker; } @@ -3282,7 +3280,7 @@ void produce(struct region *r) * auszugeben bereit sind. */ if (entertaining) expandentertainment(r); - if (!rule_autowork) { + if (!rule_autowork()) { expandwork(r, workers, nextworker, maxworkingpeasants(r)); } if (taxorders) diff --git a/src/kernel/build.c b/src/kernel/build.c index 20f70800f..7c387cb10 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -685,7 +685,6 @@ build_building(unit * u, const building_type * btype, int id, int want, order * const char *btname; order *new_order = NULL; const struct locale *lang = u->faction->locale; - static int rule_other = -1; assert(u->number); assert(btype->construction); @@ -749,10 +748,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order * n = 1; } if (b) { - if (rule_other < 0) { - rule_other = - config_get_int("rules.build.other_buildings", 1); - } + bool rule_other = config_get_int("rules.build.other_buildings", 1) != 0; if (!rule_other) { unit *owner = building_owner(b); if (!owner || owner->faction != u->faction) { diff --git a/src/kernel/resources.c b/src/kernel/resources.c index 9db74a99f..3ffad7491 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -82,10 +82,7 @@ void terraform_resources(region * r) { int i; const terrain_type *terrain = r->terrain; - static int terraform_all = -1; - if (terraform_all < 0) { - terraform_all = config_get_int("rules.terraform.all", 0); - } + bool terraform_all = config_get_int("rules.terraform.all", 0) != 0; if (terrain->production == NULL) return; diff --git a/src/kernel/unit.c b/src/kernel/unit.c index b328b748b..14e064b05 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1721,17 +1721,13 @@ void unit_addorder(unit * u, order * ord) int unit_max_hp(const unit * u) { - static int rules_stamina = -1; int h; double p; static const curse_type *heal_ct = NULL; - - if (rules_stamina < 0) { - rules_stamina = config_get_int("rules.stamina", STAMINA_AFFECTS_HP); - } + int rule_stamina = config_get_int("rules.stamina", STAMINA_AFFECTS_HP); h = u_race(u)->hitpoints; - if (rules_stamina & 1) { + if (rule_stamina & 1) { p = pow(effskill(u, SK_STAMINA, u->region) / 2.0, 1.5) * 0.2; h += (int)(h * p + 0.5); } diff --git a/src/laws.c b/src/laws.c index a904aa2a1..a53dfe31b 100755 --- a/src/laws.c +++ b/src/laws.c @@ -118,7 +118,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static bool RemoveNMRNewbie(void) { int value = config_get_int("nmr.removenewbie", 0); - return value!=0; + return value != 0; } static void age_unit(region * r, unit * u) @@ -250,7 +250,7 @@ static double peasant_growth_factor(void) #ifdef SLOWLUCK int peasant_luck_effect(int peasants, int luck, int maxp, double variance) { - int n, births=0; + int n, births = 0; double factor = peasant_growth_factor(); for (n = peasants; n && luck; --n) { int chances = 0; @@ -330,7 +330,7 @@ static void peasants(region * r) * Großteil. dead kann nie größer als rpeasants(r) - satiated werden, * so dass rpeasants(r) >= 0 bleiben muß. */ - /* Es verhungert maximal die unterernährten Bevölkerung. */ + /* Es verhungert maximal die unterernährten Bevölkerung. */ n = _min(peasants - satiated, rpeasants(r)); dead += (int)(0.5 + n * PEASANT_STARVATION_CHANCE); @@ -423,7 +423,7 @@ static void horses(region * r) int i; double growth = (RESOURCE_QUANTITY * HORSEGROWTH * 200 * (maxhorses - - horses)) / maxhorses; + horses)) / maxhorses; if (growth > 0) { if (a_find(r->attribs, &at_horseluck)) @@ -482,7 +482,7 @@ extern struct attrib_type at_germs; static void growing_trees_e3(region * r, const int current_season, -const int last_weeks_season) + const int last_weeks_season) { static const int transform[4][3] = { { -1, -1, 0 }, @@ -751,7 +751,7 @@ void nmr_warnings(void) if (msg == NULL) { msg = msg_message("warn_dropout", "faction turns", f, - turn - f->lastorders); + turn - f->lastorders); } add_message(&fa->msgs, msg); } @@ -785,12 +785,7 @@ void demographics(void) /* die Nachfrage nach Produkten steigt. */ struct demand *dmd; if (r->land) { - static int plant_rules = -1; - - if (plant_rules < 0) { - plant_rules = - config_get_int("rules.grow.formula", 0); - } + int plant_rules = config_get_int("rules.grow.formula", 0); for (dmd = r->land->demands; dmd; dmd = dmd->next) { if (dmd->value > 0 && dmd->value < MAXDEMAND) { float rise = DMRISE; @@ -988,11 +983,7 @@ static int mayboard(const unit * u, ship * sh) static bool CheckOverload(void) { - static int value = -1; - if (value < 0) { - value = config_get_int("rules.check_overload", 0); - } - return value != 0; + return config_get_int("rules.check_overload", 0) != 0; } int enter_ship(unit * u, struct order *ord, int id, bool report) @@ -1209,9 +1200,7 @@ int *age = NULL; static void nmr_death(faction * f) { - static int rule = -1; - if (rule < 0) - rule = config_get_int("rules.nmr.destroy", 0); + int rule = config_get_int("rules.nmr.destroy", 0) != 0; if (rule) { unit *u; for (u = f->units; u; u = u->nextF) { @@ -1311,7 +1300,7 @@ int ally_cmd(unit * u, struct order *ord) if (!s || !s[0]) { keyword = P_ANY; - } + } else { keyword = findparam(s, u->faction->locale); } @@ -1492,9 +1481,9 @@ int prefix_cmd(unit * u, struct order *ord) if (fval(u, UFL_GROUP)) { attrib *a = a_find(u->attribs, &at_group); if (a) { - group *g = (group *)a->data.v; + group *g = (group *)a->data.v; ap = &g->attribs; - } + } } set_prefix(ap, race_prefixes[var.i]); } @@ -1920,7 +1909,7 @@ deliverMail(faction * f, region * r, unit * u, const char *s, unit * receiver) else { /* BOTSCHAFT an EINHEIT */ ADDMSG(&f->msgs, msg_message("unitmessage", "region unit sender string", r, - receiver, u, s)); + receiver, u, s)); } } @@ -2304,7 +2293,7 @@ static bool display_race(faction * f, unit * u, const race * rc) /* hp_p : Trefferpunkte */ bytes = slprintf(bufp, size, " %d %s", rc->hitpoints, LOC(f->locale, - "stat_hitpoints")); + "stat_hitpoints")); assert(bytes <= INT_MAX); if (wrptr(&bufp, &size, (int)bytes) != 0) WARN_STATIC_BUFFER(); @@ -2312,7 +2301,7 @@ static bool display_race(faction * f, unit * u, const race * rc) /* b_attacke : Angriff */ bytes = slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_attack"), - (rc->at_default + rc->at_bonus)); + (rc->at_default + rc->at_bonus)); assert(bytes <= INT_MAX); if (wrptr(&bufp, &size, (int)bytes) != 0) WARN_STATIC_BUFFER(); @@ -2320,7 +2309,7 @@ static bool display_race(faction * f, unit * u, const race * rc) /* b_defense : Verteidigung */ bytes = slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_defense"), - (rc->df_default + rc->df_bonus)); + (rc->df_default + rc->df_bonus)); assert(bytes <= INT_MAX); if (wrptr(&bufp, &size, (int)bytes) != 0) WARN_STATIC_BUFFER(); @@ -2379,12 +2368,12 @@ static bool display_race(faction * f, unit * u, const race * rc) case AT_STANDARD: bytes = (size_t)_snprintf(bufp, size, "%s (%s)", - LOC(f->locale, "attack_standard"), rc->def_damage); + LOC(f->locale, "attack_standard"), rc->def_damage); break; case AT_NATURAL: bytes = (size_t)_snprintf(bufp, size, "%s (%s)", - LOC(f->locale, "attack_natural"), rc->attack[a].data.dice); + LOC(f->locale, "attack_natural"), rc->attack[a].data.dice); break; case AT_SPELL: case AT_COMBATSPELL: @@ -2396,7 +2385,7 @@ static bool display_race(faction * f, unit * u, const race * rc) case AT_STRUCTURAL: bytes = (size_t)_snprintf(bufp, size, "%s (%s)", - LOC(f->locale, "attack_structural"), rc->attack[a].data.dice); + LOC(f->locale, "attack_structural"), rc->attack[a].data.dice); break; default: bytes = 0; @@ -2500,7 +2489,7 @@ int promotion_cmd(unit * u, struct order *ord) if (maxheroes(u->faction) < countheroes(u->faction) + u->number) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "heroes_maxed", "max count", - maxheroes(u->faction), countheroes(u->faction))); + maxheroes(u->faction), countheroes(u->faction))); return 0; } if (!valid_race(u->faction, u_race(u))) { @@ -2745,7 +2734,8 @@ void sinkships(struct region * r) double dmg = config_get_flt("rules.ship.damage.nocrewocean", 0.3); damage_ship(sh, dmg); } - } else if (!ship_owner(sh)) { + } + else if (!ship_owner(sh)) { // any ship lying around without an owner slowly rots double dmg = config_get_flt("rules.ship.damage.nocrew", 0.05); damage_ship(sh, dmg); @@ -3280,14 +3270,14 @@ void new_units(void) if (err == 1) { ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, - "too_many_units_in_alliance", - "allowed", maxunits(u->faction))); + "too_many_units_in_alliance", + "allowed", maxunits(u->faction))); } else { ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, - "too_many_units_in_faction", - "allowed", maxunits(u->faction))); + "too_many_units_in_faction", + "allowed", maxunits(u->faction))); } ordp = &makeord->next; @@ -3360,7 +3350,7 @@ void update_long_order(unit * u) } // hungry units do not get long orders: - if (hunger) { + if (hunger) { if (u->old_orders) { // keep looking for repeated orders that might clear the old_orders continue; @@ -3432,7 +3422,8 @@ void update_long_order(unit * u) if (hunger) { // Hungernde Einheiten führen NUR den default-Befehl aus set_order(&u->thisorder, default_order(u->faction->locale)); - } else if (!exclusive) { + } + else if (!exclusive) { // Wenn die Einheit handelt oder zaubert, muss der Default-Befehl gelöscht werden. set_order(&u->thisorder, NULL); } @@ -3459,7 +3450,7 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order return EUNUSABLE; } result = itype->use ? itype->use(u, itype, amount, ord) : EUNUSABLE; - if (result>0) { + if (result > 0) { use_pooled(u, itype->rtype, GET_DEFAULT, result); } return result; @@ -4543,7 +4534,7 @@ void update_subscriptions(void) bool cansee(const faction * f, const region * r, const unit * u, int modifier) -/* r kann != u->region sein, wenn es um Durchreisen geht, +/* r kann != u->region sein, wenn es um Durchreisen geht, * oder Zauber (sp_generous, sp_fetchastral). * Es muss auch niemand aus f in der region sein, wenn sie vom Turm * erblickt wird */ @@ -4645,10 +4636,10 @@ bool cansee_unit(const unit * u, const unit * target, int modifier) bool cansee_durchgezogen(const faction * f, const region * r, const unit * u, -int modifier) -/* r kann != u->region sein, wenn es um durchreisen geht */ -/* und es muss niemand aus f in der region sein, wenn sie vom Turm -* erblickt wird */ + int modifier) + /* r kann != u->region sein, wenn es um durchreisen geht */ + /* und es muss niemand aus f in der region sein, wenn sie vom Turm + * erblickt wird */ { int n; unit *u2; diff --git a/src/magic.c b/src/magic.c index 1c6acda94..e1eccbe05 100644 --- a/src/magic.c +++ b/src/magic.c @@ -215,15 +215,11 @@ static void free_mage(attrib * a) bool FactionSpells(void) { - static int rules_factionspells = -1; - if (rules_factionspells < 0) { - rules_factionspells = config_get_int("rules.magic.factionlist", 0); - } - return rules_factionspells!=0; + return config_get_int("rules.magic.factionlist", 0) != 0; } -void read_spells(struct quicklist **slistp, magic_t mtype, -struct storage *store) +void read_spells(struct quicklist **slistp, magic_t mtype, + struct storage *store) { for (;;) { spell *sp; diff --git a/src/randenc.c b/src/randenc.c index 80ff498aa..7f27fed4d 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -962,10 +962,7 @@ static void demon_skillchanges(void) if (fval(u, UFL_HUNGER)) { /* hungry demons only go down, never up in skill */ - static int rule_hunger = -1; - if (rule_hunger < 0) { - rule_hunger = config_get_int("hunger.demon.skill", 0); - } + int rule_hunger = config_get_int("hunger.demon.skill", 0) != 0; if (rule_hunger) { upchance = 0; downchance = 15; @@ -1009,15 +1006,13 @@ static void icebergs(void) } } +#define HERBS_ROT /* herbs owned by units have a chance to rot. */ +#define HERBROTCHANCE 5 /* Verrottchance für Kräuter (ifdef HERBS_ROT) */ #ifdef HERBS_ROT static void rotting_herbs(void) { - static int rule_rot = -1; region *r; - - if (rule_rot < 0) { - rule_rot = config_get_int("rules.economy.herbrot", HERBROTCHANCE); - } + int rule_rot = config_get_int("rules.economy.herbrot", HERBROTCHANCE); if (rule_rot == 0) return; for (r = regions; r; r = r->next) { diff --git a/src/settings.h b/src/settings.h index 5cd5e1a80..c44bc0f2a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -42,14 +42,12 @@ /* experimental gameplay features (that don't affect the savefile) */ /* TODO: move these settings to settings.h or into configuration files */ #define GOBLINKILL /* Goblin-Spezialklau kann tödlich enden */ -#define HERBS_ROT /* herbs owned by units have a chance to rot. */ #define INSECT_POTION /* Spezialtrank für Insekten */ #define ORCIFICATION /* giving snotlings to the peasants gets counted */ #define TREESIZE (8) /* space used by trees (in #peasants) */ #define PEASANTFORCE 0.75 /* Chance einer Vermehrung trotz 90% Auslastung */ -#define HERBROTCHANCE 5 /* Verrottchance für Kräuter (ifdef HERBS_ROT) */ /* Gebäudegröße = Minimalbelagerer */ #define SIEGEFACTOR 2 diff --git a/src/study.c b/src/study.c index 79adf2847..db722fff8 100644 --- a/src/study.c +++ b/src/study.c @@ -546,17 +546,10 @@ int study_cmd(unit * u, order * ord) skill_t sk; int maxalchemy = 0; int speed_rule = (study_rule_t)config_get_int("study.speedup", 0); - static int learn_newskills = -1; struct building *b = inside_building(u); const struct building_type *btype = building_is_active(b) ? b->type : NULL; + bool learn_newskills = config_get_int("study.newskills", 1) != 0; - if (learn_newskills < 0) { - const char *str = config_get("study.newskills"); - if (str && strcmp(str, "false") == 0) - learn_newskills = 0; - else - learn_newskills = 1; - } if (!unit_can_study(u)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_race_nolearn", "race", u_race(u))); @@ -580,7 +573,7 @@ int study_cmd(unit * u, order * ord) cmistake(u, ord, 771, MSG_EVENT); return 0; } - if (learn_newskills == 0) { + if (!learn_newskills) { skill *sv = unit_skill(u, sk); if (sv == NULL) { /* we can only learn skills we already have */ diff --git a/src/upkeep.c b/src/upkeep.c index d83abbe86..da9cbff74 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -270,11 +270,8 @@ void get_food(region * r) peasantfood = 0; } if (hungry > 0) { - static int demon_hunger = -1; - if (demon_hunger < 0) { - demon_hunger = config_get_int("hunger.demons", 0); - } - if (demon_hunger == 0) { + bool demon_hunger = config_get_int("hunger.demons", 0) != 0; + if (demon_hunger) { /* demons who don't feed are hungry */ if (hunger(hungry, u)) fset(u, UFL_HUNGER);