refactor siege property w. getter/setter

This commit is contained in:
Enno Rehling 2018-09-09 17:10:18 +02:00
parent 10c47d339e
commit 062abe8102
12 changed files with 49 additions and 33 deletions

View file

@ -100,9 +100,7 @@ typedef enum combatmagic {
#define MINSPELLRANGE 1 #define MINSPELLRANGE 1
#define MAXSPELLRANGE 7 #define MAXSPELLRANGE 7
#ifndef ROW_FACTOR #define ROW_FACTOR 3 /* factor for combat row advancement rule */
# define ROW_FACTOR 10
#endif
#define EFFECT_PANIC_SPELL 0.25 #define EFFECT_PANIC_SPELL 0.25
#define TROLL_REGENERATION 0.10 #define TROLL_REGENERATION 0.10
@ -161,7 +159,7 @@ static void init_rules(void)
skill_formula = config_get_int("rules.combat.skill_formula", skill_formula = config_get_int("rules.combat.skill_formula",
FORMULA_ORIG); FORMULA_ORIG);
/* maximum number of combat turns */ /* 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 */ /* damage calculation */
if (config_get_int("rules.combat.critical", 1)) { if (config_get_int("rules.combat.critical", 1)) {
rule_damage |= DAMAGE_CRITICAL; rule_damage |= DAMAGE_CRITICAL;

View file

@ -645,6 +645,7 @@ static void cr_output_building(struct stream *out, building *b,
const unit *owner, int fno, faction *f) const unit *owner, int fno, faction *f)
{ {
const char *bname, *billusion; const char *bname, *billusion;
int i;
stream_printf(out, "BURG %d\n", b->no); 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) { if (fno >= 0) {
stream_printf(out, "%d;Partei\n", fno); 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); cr_output_curses(out, f, b, TYP_BUILDING);
} }

View file

@ -103,6 +103,8 @@ static void recruit_init(void)
} }
} }
#define ENTERTAINFRACTION 20
int entertainmoney(const region * r) int entertainmoney(const region * r)
{ {
double n; double n;

View file

@ -870,3 +870,14 @@ int cmp_current_owner(const building * b, const building * a)
} }
return 0; 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;
}

View file

@ -118,7 +118,7 @@ extern "C" {
int no; int no;
int size; int size;
int sizeleft; /* is only used during battle. should be a temporary attribute */ 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; int flags;
} building; } building;
@ -134,6 +134,9 @@ extern "C" {
int id, int size, struct order *ord); int id, int size, struct order *ord);
bool building_finished(const struct building *b); 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, int wage(const struct region *r, const struct faction *f,
const struct race *rc, int in_turn); const struct race *rc, int in_turn);

View file

@ -1917,9 +1917,11 @@ int getunit(const region * r, const faction * f, unit **uresult)
int besieged(const unit * u) int besieged(const unit * u)
{ {
/* belagert kann man in schiffen und burgen werden */ /* belagert kann man in schiffen und burgen werden */
return (u && !keyword_disabled(K_BESIEGE) if (u && !keyword_disabled(K_BESIEGE) && u->building) {
&& u->building && u->building->besieged building * b = u->building;
&& u->building->besieged >= u->building->size * SIEGEFACTOR); return building_get_siege(b) >= b->size * SIEGEFACTOR;
}
return false;
} }
bool has_horses(const unit * u) bool has_horses(const unit * u)

View file

@ -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) 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; int n, o;
/* b ist die burg, in die man hinein oder aus der man heraus will. */ /* 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; return 1;
} }
@ -3857,7 +3862,7 @@ int siege_cmd(unit * u, order * ord)
usetsiege(u, b); usetsiege(u, b);
if (katapultiere < bewaffnete) katapultiere = bewaffnete; if (katapultiere < bewaffnete) katapultiere = bewaffnete;
b->besieged += katapultiere; building_add_siege(b, katapultiere);
/* definitiver schaden eingeschraenkt */ /* definitiver schaden eingeschraenkt */
if (d > b->size - 1) d = b->size - 1; if (d > b->size - 1) d = b->size - 1;

View file

@ -113,7 +113,8 @@ static void test_contact(CuTest * tc)
u3 = test_create_unit(test_create_faction(NULL), r); u3 = test_create_unit(test_create_faction(NULL), r);
set_level(u3, SK_PERCEPTION, 2); set_level(u3, SK_PERCEPTION, 2);
usetsiege(u3, b); 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)); CuAssertIntEquals(tc, 1, can_contact(r, u1, u2));
u_set_building(u1, b); u_set_building(u1, b);

View file

@ -1853,15 +1853,17 @@ nr_building(struct stream *out, const region *r, const building *b, const factio
sbs_strcat(&sbs, LOC(lang, "nr_building_inprogress")); sbs_strcat(&sbs, LOC(lang, "nr_building_inprogress"));
} }
if (b->besieged > 0 && r->seen.mode >= seen_lighthouse) { if (!keyword_disabled(K_BESIEGE) && r->seen.mode >= seen_lighthouse) {
msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged, int s = building_get_siege(b);
b->besieged - b->size * SIEGEFACTOR); 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); size = nr_render(msg, lang, sbs.end, sbs.size - (sbs.end - sbs.begin), f);
sbs.end += size; sbs.end += size;
msg_release(msg); msg_release(msg);
} }
}
i = 0; i = 0;
if (b->display && b->display[0]) { if (b->display && b->display[0]) {
sbs_strcat(&sbs, "; "); sbs_strcat(&sbs, "; ");

View file

@ -10,23 +10,11 @@
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#define ENTERTAINFRACTION 20
#define TEACHDIFFERENCE 2
#define RESOURCE_QUANTITY 0.5 #define RESOURCE_QUANTITY 0.5
#define RECRUITFRACTION 40 /* 100/RECRUITFRACTION% */ #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 */ /* TODO: move these settings to settings.h or into configuration files */
#define TREESIZE (8) /* space used by trees (in #peasants) */ #define TREESIZE (8) /* space used by trees (in #peasants) */
#define PEASANTFORCE 0.75 /* Chance einer Vermehrung trotz 90% Auslastung */
/* Gebaeudegroesse = Minimalbelagerer */ /* Gebaeudegroesse = Minimalbelagerer */
#define SIEGEFACTOR 2 #define SIEGEFACTOR 2

View file

@ -31,6 +31,7 @@ extern "C" {
#define STUDYDAYS 30 #define STUDYDAYS 30
#define TEACHNUMBER 10 #define TEACHNUMBER 10
#define TEACHDIFFERENCE 2
typedef struct teaching_info { typedef struct teaching_info {
struct selist *teachers; struct selist *teachers;

View file

@ -12,7 +12,6 @@
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
#include "settings.h"
#include "wormhole.h" #include "wormhole.h"