forked from github/server
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:
parent
d770eec549
commit
fb0eb4dce6
6 changed files with 45 additions and 49 deletions
|
@ -1771,41 +1771,6 @@ bool has_horses(const struct unit * u)
|
||||||
return false;
|
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,
|
/* Lohn bei den einzelnen Burgstufen für Normale Typen, Orks, Bauern,
|
||||||
* Modifikation für Städter. */
|
* Modifikation für Städter. */
|
||||||
|
|
||||||
|
|
|
@ -54,13 +54,6 @@ extern "C" {
|
||||||
#define MAXMAGICIANS 3
|
#define MAXMAGICIANS 3
|
||||||
#define MAXALCHEMISTS 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: */
|
/* getunit results: */
|
||||||
#define GET_UNIT 0
|
#define GET_UNIT 0
|
||||||
#define GET_NOTFOUND 1
|
#define GET_NOTFOUND 1
|
||||||
|
@ -352,7 +345,6 @@ extern "C" {
|
||||||
struct order *default_order(const struct locale *lang);
|
struct order *default_order(const struct locale *lang);
|
||||||
int entertainmoney(const struct region *r);
|
int entertainmoney(const struct region *r);
|
||||||
|
|
||||||
void plagues(struct region *r, bool ismagic);
|
|
||||||
void free_gamedata(void);
|
void free_gamedata(void);
|
||||||
|
|
||||||
#define GIVE_SELF 1
|
#define GIVE_SELF 1
|
||||||
|
|
|
@ -717,7 +717,14 @@ void demographics(void)
|
||||||
calculate_emigration(r);
|
calculate_emigration(r);
|
||||||
peasants(r);
|
peasants(r);
|
||||||
if (r->age > 20) {
|
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);
|
horses(r);
|
||||||
if (plant_rules == 0) { /* E1 */
|
if (plant_rules == 0) { /* E1 */
|
||||||
|
|
|
@ -1181,3 +1181,26 @@ void randomevents(void)
|
||||||
|
|
||||||
dissolve_units();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
Katja Zedel <katze@felidae.kn-bremen.de
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
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" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void encounters(void);
|
struct region;
|
||||||
extern void randomevents(void);
|
|
||||||
|
/** 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "spells.h"
|
#include "spells.h"
|
||||||
#include "direction.h"
|
#include "direction.h"
|
||||||
|
#include "randenc.h"
|
||||||
#include "monster.h"
|
#include "monster.h"
|
||||||
|
|
||||||
#include <spells/borders.h>
|
#include <spells/borders.h>
|
||||||
|
@ -2974,7 +2975,7 @@ static int sp_plague(castorder * co)
|
||||||
unit *mage = co->magician.u;
|
unit *mage = co->magician.u;
|
||||||
int cast_level = co->level;
|
int cast_level = co->level;
|
||||||
|
|
||||||
plagues(r, true);
|
plagues(r);
|
||||||
|
|
||||||
ADDMSG(&mage->faction->msgs, msg_message("plague_spell",
|
ADDMSG(&mage->faction->msgs, msg_message("plague_spell",
|
||||||
"region mage", r, mage));
|
"region mage", r, mage));
|
||||||
|
|
Loading…
Reference in a new issue