diff --git a/src/kernel/config.c b/src/kernel/config.c index cdc30618a..b154c2074 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1771,41 +1771,6 @@ bool has_horses(const struct unit * u) return false; } -void plagues(region * r, bool ismagic) -{ - int peasants; - int i; - int dead = 0; - - /* Seuchenwahrscheinlichkeit in % */ - - if (!ismagic) { - double mwp = _max(maxworkingpeasants(r), 1); - double prob = - pow(rpeasants(r) / (mwp * wage(r, NULL, NULL, turn) * 0.13), 4.0) - * PLAGUE_CHANCE; - - if (rng_double() >= prob) - return; - } - - peasants = rpeasants(r); - dead = (int)(0.5F + PLAGUE_VICTIMS * peasants); - for (i = dead; i != 0; i--) { - if (rng_double() < PLAGUE_HEALCHANCE && rmoney(r) >= PLAGUE_HEALCOST) { - rsetmoney(r, rmoney(r) - PLAGUE_HEALCOST); - --dead; - } - } - - if (dead > 0) { - message *msg = add_message(&r->msgs, msg_message("pest", "dead", dead)); - msg_release(msg); - deathcounts(r, dead); - rsetpeasants(r, peasants - dead); - } -} - /* Lohn bei den einzelnen Burgstufen für Normale Typen, Orks, Bauern, * Modifikation für Städter. */ diff --git a/src/kernel/config.h b/src/kernel/config.h index 0e00110a6..e7d8e4011 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -54,13 +54,6 @@ extern "C" { #define MAXMAGICIANS 3 #define MAXALCHEMISTS 3 - /** Plagues **/ -#define PLAGUE_CHANCE 0.1F /* Seuchenwahrscheinlichkeit (siehe plagues()) */ -#define PLAGUE_VICTIMS 0.2F /* % Betroffene */ -#define PLAGUE_HEALCHANCE 0.25F /* Wahrscheinlichkeit Heilung */ -#define PLAGUE_HEALCOST 30 /* Heilkosten */ - - /* getunit results: */ #define GET_UNIT 0 #define GET_NOTFOUND 1 @@ -352,7 +345,6 @@ extern "C" { struct order *default_order(const struct locale *lang); int entertainmoney(const struct region *r); - void plagues(struct region *r, bool ismagic); void free_gamedata(void); #define GIVE_SELF 1 diff --git a/src/laws.c b/src/laws.c index 2d04606dd..a83fb93a7 100755 --- a/src/laws.c +++ b/src/laws.c @@ -717,7 +717,14 @@ void demographics(void) calculate_emigration(r); peasants(r); if (r->age > 20) { - plagues(r, false); + double mwp = _max(maxworkingpeasants(r), 1); + double prob = + pow(rpeasants(r) / (mwp * wage(r, NULL, NULL, turn) * 0.13), 4.0) + * PLAGUE_CHANCE; + + if (rng_double() < prob) { + plagues(r); + } } horses(r); if (plant_rules == 0) { /* E1 */ diff --git a/src/randenc.c b/src/randenc.c index 0c024bd6c..0db285459 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -1181,3 +1181,26 @@ void randomevents(void) dissolve_units(); } + +void plagues(region * r) +{ + int peasants; + int i; + int dead = 0; + + peasants = rpeasants(r); + dead = (int)(0.5F + PLAGUE_VICTIMS * peasants); + for (i = dead; i != 0; i--) { + if (rng_double() < PLAGUE_HEALCHANCE && rmoney(r) >= PLAGUE_HEALCOST) { + rsetmoney(r, rmoney(r) - PLAGUE_HEALCOST); + --dead; + } + } + + if (dead > 0) { + message *msg = add_message(&r->msgs, msg_message("pest", "dead", dead)); + msg_release(msg); + deathcounts(r, dead); + rsetpeasants(r, peasants - dead); + } +} diff --git a/src/randenc.h b/src/randenc.h index 0f39d9c61..be3e9d9ca 100644 --- a/src/randenc.h +++ b/src/randenc.h @@ -1,7 +1,7 @@ /* Copyright (c) 1998-2010, Enno Rehling - Katja Zedel +Katja Zedel Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -22,8 +22,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif - extern void encounters(void); - extern void randomevents(void); + struct region; + + /** Plagues **/ +#define PLAGUE_CHANCE 0.1F /* Seuchenwahrscheinlichkeit (siehe plagues()) */ +#define PLAGUE_VICTIMS 0.2F /* % Betroffene */ +#define PLAGUE_HEALCHANCE 0.25F /* Wahrscheinlichkeit Heilung */ +#define PLAGUE_HEALCOST 30 /* Heilkosten */ + void plagues(struct region *r); + void encounters(void); + void randomevents(void); #ifdef __cplusplus } diff --git a/src/spells.c b/src/spells.c index 908b6fbec..913403341 100644 --- a/src/spells.c +++ b/src/spells.c @@ -20,6 +20,7 @@ #include "laws.h" #include "spells.h" #include "direction.h" +#include "randenc.h" #include "monster.h" #include @@ -2974,7 +2975,7 @@ static int sp_plague(castorder * co) unit *mage = co->magician.u; int cast_level = co->level; - plagues(r, true); + plagues(r); ADDMSG(&mage->faction->msgs, msg_message("plague_spell", "region mage", r, mage));