refactoring: moving plagues out of config.c

cleaning up the code, moving chance into the random event code, it is not used by the plague spell (reduce signature by one argument)
This commit is contained in:
Enno Rehling 2014-12-16 14:18:29 +01:00
parent d770eec549
commit fb0eb4dce6
6 changed files with 45 additions and 49 deletions

View File

@ -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. */

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
/*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
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
}

View File

@ -20,6 +20,7 @@
#include "laws.h"
#include "spells.h"
#include "direction.h"
#include "randenc.h"
#include "monster.h"
#include <spells/borders.h>
@ -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));