diff --git a/src/economy.c b/src/economy.c index 6fc1fea60..1cae19b1c 100644 --- a/src/economy.c +++ b/src/economy.c @@ -69,6 +69,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include /* libs includes */ #include @@ -2653,14 +2654,10 @@ expandwork(region * r, request * work_begin, request * work_end, int maxwork) jobs = rpeasants(r); } earnings = jobs * p_wage; - if (r->attribs && rule_blessed_harvest() == HARVEST_TAXES) { + if (jobs > 0 && r->attribs && rule_blessed_harvest() == HARVEST_TAXES) { /* E3 rules */ - const curse_type *blessedharvest_ct = ct_find("blessedharvest"); - if (blessedharvest_ct) { - int happy = - (int)(jobs * curse_geteffect(get_curse(r->attribs, blessedharvest_ct))); - earnings += happy; - } + int happy = harvest_effect(r); + earnings += happy * jobs; } rsetmoney(r, money + earnings); } diff --git a/src/kernel/building.c b/src/kernel/building.c index 14e4a3e07..520807933 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -55,6 +55,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* attributes includes */ +#include #include typedef struct building_typelist { @@ -710,7 +711,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn) } if (r->attribs && rule_blessed_harvest() == HARVEST_WORK) { /* E1 rules */ - wage += curse_geteffect(get_curse(r->attribs, ct_find("blessedharvest"))); + wage += harvest_effect(r); } } diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 4a3e1c045..336316159 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -596,28 +596,23 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, if (ct->mergeflags & M_DURATION) { c->duration = MAX(c->duration, duration); } - if (ct->mergeflags & M_SUMDURATION) { + else if (ct->mergeflags & M_SUMDURATION) { c->duration += duration; } - if (ct->mergeflags & M_SUMEFFECT) { - c->effect += effect; - } if (ct->mergeflags & M_MAXEFFECT) { c->effect = MAX(c->effect, effect); } + else if (ct->mergeflags & M_SUMEFFECT) { + c->effect += effect; + } if (ct->mergeflags & M_VIGOUR) { c->vigour = MAX(vigour, c->vigour); } - if (ct->mergeflags & M_VIGOUR_ADD) { + else if (ct->mergeflags & M_VIGOUR_ADD) { c->vigour = vigour + c->vigour; } - if (ct->mergeflags & M_MEN) { - switch (ct->typ) { - case CURSETYP_UNIT: - { - c->data.i += men; - } - } + if (ct->mergeflags & M_MEN && ct->typ == CURSETYP_UNIT) { + c->data.i += men; } set_curseingmagician(magician, *ap, ct); } diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index b10f3046f..dc9256538 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -24,6 +24,7 @@ #include /* util includes */ +#include #include #include #include @@ -33,10 +34,6 @@ #include #include -/* --------------------------------------------------------------------- */ -/* CurseInfo mit Spezialabfragen - */ - /* * godcursezone */ @@ -206,6 +203,22 @@ static struct curse_type ct_blessedharvest = { cinfo_simple }; +int harvest_effect(const struct region *r) { + if (r->attribs) { + curse *c = get_curse(r->attribs, &ct_blessedharvest); + if (c) { + int happy = curse_geteffect_int(c); + if (happy != 1) { + /* https://bugs.eressea.de/view.php?id=2353 detect and fix bad harvest */ + log_error("blessedharvest curse %d has effect=%d, duration=%d", c->no, happy, c->duration); + c->effect = 1.0; + } + return happy; + } + } + return 0; +} + static struct curse_type ct_drought = { "drought", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), diff --git a/src/spells/regioncurse.h b/src/spells/regioncurse.h index c261ade41..a1ee182c1 100644 --- a/src/spells/regioncurse.h +++ b/src/spells/regioncurse.h @@ -17,10 +17,10 @@ extern "C" { #endif - struct curse; - struct locale; + struct region; - extern void register_regioncurse(void); + int harvest_effect(const struct region *r); + void register_regioncurse(void); #ifdef __cplusplus }