From 062abe81026a6afd03950980764dda45184eb023 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 9 Sep 2018 17:10:18 +0200 Subject: [PATCH] refactor siege property w. getter/setter --- src/battle.c | 6 ++---- src/creport.c | 8 ++++++-- src/economy.c | 2 ++ src/kernel/building.c | 11 +++++++++++ src/kernel/building.h | 5 ++++- src/kernel/unit.c | 8 +++++--- src/laws.c | 9 +++++++-- src/laws.test.c | 3 ++- src/report.c | 16 +++++++++------- src/settings.h | 12 ------------ src/study.h | 1 + src/wormhole.c | 1 - 12 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/battle.c b/src/battle.c index 9e2f841c0..3f61269a0 100644 --- a/src/battle.c +++ b/src/battle.c @@ -100,9 +100,7 @@ typedef enum combatmagic { #define MINSPELLRANGE 1 #define MAXSPELLRANGE 7 -#ifndef ROW_FACTOR -# define ROW_FACTOR 10 -#endif +#define ROW_FACTOR 3 /* factor for combat row advancement rule */ #define EFFECT_PANIC_SPELL 0.25 #define TROLL_REGENERATION 0.10 @@ -161,7 +159,7 @@ static void init_rules(void) skill_formula = config_get_int("rules.combat.skill_formula", FORMULA_ORIG); /* maximum number of combat turns */ - max_turns = config_get_int("rules.combat.turns", COMBAT_TURNS); + max_turns = config_get_int("rules.combat.turns", 5); /* damage calculation */ if (config_get_int("rules.combat.critical", 1)) { rule_damage |= DAMAGE_CRITICAL; diff --git a/src/creport.c b/src/creport.c index 91d56ca3b..137259083 100644 --- a/src/creport.c +++ b/src/creport.c @@ -645,6 +645,7 @@ static void cr_output_building(struct stream *out, building *b, const unit *owner, int fno, faction *f) { const char *bname, *billusion; + int i; stream_printf(out, "BURG %d\n", b->no); @@ -673,9 +674,12 @@ static void cr_output_building(struct stream *out, building *b, if (fno >= 0) { stream_printf(out, "%d;Partei\n", fno); } - if (b->besieged) { - stream_printf(out, "%d;Belagerer\n", b->besieged); + + i = building_get_siege(b); + if (i) { + stream_printf(out, "%d;Belagerer\n", i); } + cr_output_curses(out, f, b, TYP_BUILDING); } diff --git a/src/economy.c b/src/economy.c index baba6c1ac..cc611d49d 100644 --- a/src/economy.c +++ b/src/economy.c @@ -103,6 +103,8 @@ static void recruit_init(void) } } +#define ENTERTAINFRACTION 20 + int entertainmoney(const region * r) { double n; diff --git a/src/kernel/building.c b/src/kernel/building.c index 75cad30f7..9dfc7db35 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -870,3 +870,14 @@ int cmp_current_owner(const building * b, const building * a) } return 0; } + +int building_get_siege(const struct building *b) +{ + return b->_besieged; +} + +int building_add_siege(struct building *b, int delta) +{ + b->_besieged += delta; + return b->_besieged; +} diff --git a/src/kernel/building.h b/src/kernel/building.h index eacf42942..319304d79 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -118,7 +118,7 @@ extern "C" { int no; int size; int sizeleft; /* is only used during battle. should be a temporary attribute */ - int besieged; /* should be an attribute */ + int _besieged; /* should be an attribute */ int flags; } building; @@ -134,6 +134,9 @@ extern "C" { int id, int size, struct order *ord); bool building_finished(const struct building *b); + int building_get_siege(const struct building *b); + int building_add_siege(struct building *b, int delta); + int wage(const struct region *r, const struct faction *f, const struct race *rc, int in_turn); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 770723bea..146761f05 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1917,9 +1917,11 @@ int getunit(const region * r, const faction * f, unit **uresult) int besieged(const unit * u) { /* belagert kann man in schiffen und burgen werden */ - return (u && !keyword_disabled(K_BESIEGE) - && u->building && u->building->besieged - && u->building->besieged >= u->building->size * SIEGEFACTOR); + if (u && !keyword_disabled(K_BESIEGE) && u->building) { + building * b = u->building; + return building_get_siege(b) >= b->size * SIEGEFACTOR; + } + return false; } bool has_horses(const unit * u) diff --git a/src/laws.c b/src/laws.c index 68f2894b3..67a44c673 100644 --- a/src/laws.c +++ b/src/laws.c @@ -306,6 +306,11 @@ static void calculate_emigration(region * r) } } +/* Vermehrungsrate Bauern in 1/10000. +* TODO: Evt. Berechnungsfehler, reale Vermehrungsraten scheinen hoeher. */ +#define PEASANTGROWTH 10 +#define PEASANTLUCK 10 +#define PEASANTFORCE 0.75 /* Chance einer Vermehrung trotz 90% Auslastung */ static double peasant_growth_factor(void) { @@ -908,7 +913,7 @@ static int slipthru(const region * r, const unit * u, const building * b) int n, o; /* b ist die burg, in die man hinein oder aus der man heraus will. */ - if (b == NULL || b->besieged < b->size * SIEGEFACTOR) { + if (b == NULL || building_get_siege(b) < b->size * SIEGEFACTOR) { return 1; } @@ -3857,7 +3862,7 @@ int siege_cmd(unit * u, order * ord) usetsiege(u, b); if (katapultiere < bewaffnete) katapultiere = bewaffnete; - b->besieged += katapultiere; + building_add_siege(b, katapultiere); /* definitiver schaden eingeschraenkt */ if (d > b->size - 1) d = b->size - 1; diff --git a/src/laws.test.c b/src/laws.test.c index c7c7a6682..fb644dc90 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -113,7 +113,8 @@ static void test_contact(CuTest * tc) u3 = test_create_unit(test_create_faction(NULL), r); set_level(u3, SK_PERCEPTION, 2); usetsiege(u3, b); - b->besieged = 1; + building_add_siege(b, 1); + CuAssertIntEquals(tc, 1, building_get_siege(b)); CuAssertIntEquals(tc, 1, can_contact(r, u1, u2)); u_set_building(u1, b); diff --git a/src/report.c b/src/report.c index 9f1bfa4bd..7de2550a4 100644 --- a/src/report.c +++ b/src/report.c @@ -1853,14 +1853,16 @@ nr_building(struct stream *out, const region *r, const building *b, const factio sbs_strcat(&sbs, LOC(lang, "nr_building_inprogress")); } - if (b->besieged > 0 && r->seen.mode >= seen_lighthouse) { - msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged, - b->besieged - b->size * SIEGEFACTOR); + if (!keyword_disabled(K_BESIEGE) && r->seen.mode >= seen_lighthouse) { + int s = building_get_siege(b); + if (s > 0) { + msg = msg_message("nr_building_besieged", "soldiers diff", s, + s - b->size * SIEGEFACTOR); + size = nr_render(msg, lang, sbs.end, sbs.size - (sbs.end - sbs.begin), f); + sbs.end += size; - size = nr_render(msg, lang, sbs.end, sbs.size - (sbs.end - sbs.begin), f); - sbs.end += size; - - msg_release(msg); + msg_release(msg); + } } i = 0; if (b->display && b->display[0]) { diff --git a/src/settings.h b/src/settings.h index 57edb1566..498786be9 100644 --- a/src/settings.h +++ b/src/settings.h @@ -10,23 +10,11 @@ without prior permission by the authors of Eressea. */ -#define ENTERTAINFRACTION 20 -#define TEACHDIFFERENCE 2 #define RESOURCE_QUANTITY 0.5 #define RECRUITFRACTION 40 /* 100/RECRUITFRACTION% */ -#define COMBAT_TURNS 5 -#undef NEWATSROI - -/* Vermehrungsrate Bauern in 1/10000. -* TODO: Evt. Berechnungsfehler, reale Vermehrungsraten scheinen hoeher. */ -#define PEASANTGROWTH 10 -#define PEASANTLUCK 10 - -#define ROW_FACTOR 3 /* factor for combat row advancement rule */ /* TODO: move these settings to settings.h or into configuration files */ #define TREESIZE (8) /* space used by trees (in #peasants) */ -#define PEASANTFORCE 0.75 /* Chance einer Vermehrung trotz 90% Auslastung */ /* Gebaeudegroesse = Minimalbelagerer */ #define SIEGEFACTOR 2 diff --git a/src/study.h b/src/study.h index cca0428b7..686677064 100644 --- a/src/study.h +++ b/src/study.h @@ -31,6 +31,7 @@ extern "C" { #define STUDYDAYS 30 #define TEACHNUMBER 10 +#define TEACHDIFFERENCE 2 typedef struct teaching_info { struct selist *teachers; diff --git a/src/wormhole.c b/src/wormhole.c index 197fc346d..2000018ab 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -12,7 +12,6 @@ #include #include -#include "settings.h" #include "wormhole.h"