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 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;

View File

@ -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);
}

View File

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

View File

@ -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;
}

View File

@ -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);

View File

@ -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)

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)
{
@ -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;

View File

@ -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);

View File

@ -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]) {

View File

@ -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

View File

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

View File

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