From a88bfa7a9a4aa8f3c18a302bf627fde23307460d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 16 Nov 2016 22:46:01 +0100 Subject: [PATCH] decluttering config.c (rules go into laws.c) --- s/build | 2 +- src/kernel/config.c | 31 ------------------------------- src/kernel/config.h | 5 ----- src/laws.c | 26 ++++++++++++++++++++++++++ src/laws.h | 4 ++++ src/study.c | 13 ++++++++++++- 6 files changed, 43 insertions(+), 38 deletions(-) diff --git a/s/build b/s/build index b59804626..363e3e5a6 100755 --- a/s/build +++ b/s/build @@ -39,5 +39,5 @@ echo "build eressea" cd $ROOT/$BUILD VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') cmake -DERESSEA_VERSION="$VERSION" .. -make $MAKEOPTS && make test +make -k $MAKEOPTS && make test cd $OLDPWD diff --git a/src/kernel/config.c b/src/kernel/config.c index d8be01ed9..7ca8a5ba7 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -105,37 +105,6 @@ FILE *logfile; bool battledebug = false; int turn = -1; -int NewbieImmunity(void) -{ - return config_get_int("NewbieImmunity", 0); -} - -bool IsImmune(const faction * f) -{ - return !fval(f, FFL_NPC) && f->age < NewbieImmunity(); -} - -bool ExpensiveMigrants(void) -{ - return config_get_int("study.expensivemigrants", 0) != 0; -} - -int LongHunger(const struct unit *u) -{ - if (u != NULL) { - if (!fval(u, UFL_HUNGER)) - return false; - if (u_race(u) == get_race(RC_DAEMON)) - return false; - } - return config_get_int("hunger.long", 0); -} - -int NMRTimeout(void) -{ - return config_get_int("nmr.timeout", 0); -} - helpmode helpmodes[] = { { "all", HELP_ALL } , diff --git a/src/kernel/config.h b/src/kernel/config.h index 9a0d1d1fb..84bc1ba75 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -164,11 +164,6 @@ struct param; bool config_changed(int *cache_key); char * join_path(const char *p1, const char *p2, char *dst, size_t len); - bool ExpensiveMigrants(void); - int NMRTimeout(void); - int LongHunger(const struct unit *u); - int NewbieImmunity(void); - bool IsImmune(const struct faction *f); struct order *default_order(const struct locale *lang); diff --git a/src/laws.c b/src/laws.c index cf365fc7a..0ba3f4077 100644 --- a/src/laws.c +++ b/src/laws.c @@ -117,6 +117,32 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* - exported global symbols ----------------------------------- */ +int NewbieImmunity(void) +{ + return config_get_int("NewbieImmunity", 0); +} + +bool IsImmune(const faction * f) +{ + return !fval(f, FFL_NPC) && f->age < NewbieImmunity(); +} + +int NMRTimeout(void) +{ + return config_get_int("nmr.timeout", 0); +} + +bool LongHunger(const struct unit *u) +{ + if (u != NULL) { + if (!fval(u, UFL_HUNGER)) + return false; + if (u_race(u) == get_race(RC_DAEMON)) + return false; + } + return config_get_int("hunger.long", 0) != 0; +} + static bool RemoveNMRNewbie(void) { int value = config_get_int("nmr.removenewbie", 0); diff --git a/src/laws.h b/src/laws.h index 5406a50d4..0adb010d2 100755 --- a/src/laws.h +++ b/src/laws.h @@ -108,6 +108,10 @@ extern "C" { #define FORCE_LEAVE_POSTCOMBAT 1 #define FORCE_LEAVE_ALL 2 bool rule_force_leave(int flag); + bool LongHunger(const struct unit *u); + int NMRTimeout(void); + int NewbieImmunity(void); + bool IsImmune(const struct faction *f); bool help_enter(struct unit *uo, struct unit *u); #ifdef __cplusplus diff --git a/src/study.c b/src/study.c index 59f1130ea..1cd8847be 100644 --- a/src/study.c +++ b/src/study.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "study.h" +#include "laws.h" #include "move.h" #include "monster.h" #include "alchemy.h" @@ -531,6 +532,16 @@ static double study_speedup(unit * u, skill_t s, study_rule_t rule) return 1.0; } +static bool ExpensiveMigrants(void) +{ + static bool rule; + static int cache; + if (config_changed(&cache)) { + rule = config_get_int("study.expensivemigrants", 0) != 0; + } + return rule; +} + int study_cmd(unit * u, order * ord) { region *r = u->region; @@ -772,7 +783,7 @@ int study_cmd(unit * u, order * ord) a_remove(&u->attribs, a); a = NULL; } - fset(u, UFL_LONGACTION | UFL_NOTMOVING); + u->flags |= (UFL_LONGACTION | UFL_NOTMOVING); /* Anzeigen neuer Traenke */ /* Spruchlistenaktualiesierung ist in Regeneration */