2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * plague.c: Plague related functions
29 * Known contributors to this file:
30 * Steve McClure, 1998-2000
31 * Markus Armbruster, 2004-2016
43 static int infect_people(struct natstr *, struct sctstr *);
46 do_plague(struct sctstr *sp, int etu)
48 struct natstr *np = getnatp(sp->sct_own);
52 if (opt_NO_PLAGUE) /* no plague nothing to do */
55 pstage = sp->sct_pstage;
56 ptime = sp->sct_ptime;
58 if (pstage == PLG_HEALTHY) {
59 pstage = infect_people(np, sp);
62 n = plague_people(np, sp->sct_item, &pstage, &ptime, etu);
65 wu(0, sp->sct_own, "PLAGUE deaths reported in %s.\n",
67 nreport(sp->sct_own, N_DIE_PLAGUE, 0, 1);
70 wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp));
73 /* Are we still incubating? */
75 /* Yes. Will it turn "infectious" next time? */
77 /* Yes. Report an outbreak. */
79 "Outbreak of PLAGUE in %s!\n", ownxy(sp));
80 nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1);
83 /* It has already moved on to "infectious" */
84 wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp));
88 /* Has the plague moved to "incubation" yet? */
90 /* Yes. Will it turn "infectious" next time? */
92 /* Yes. Report an outbreak. */
94 "Outbreak of PLAGUE in %s!\n", ownxy(sp));
95 nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1);
103 sp->sct_pstage = pstage;
104 sp->sct_ptime = ptime;
109 infect_people(struct natstr *np, struct sctstr *sp)
111 double pop, pop_space, bad_stuff, pollution, cleanup;
114 if (opt_NO_PLAGUE) /* no plague nothing to do */
117 if (np->nat_level[NAT_TLEV] <= 10.0)
121 * make plague where there was none before...
123 pop = sp->sct_item[I_CIVIL] + sp->sct_item[I_MILIT] + sp->sct_item[I_UW];
124 pop_space = max_pop(np->nat_level[NAT_RLEV], sp);
126 = sp->sct_item[I_IRON] + sp->sct_item[I_OIL] + sp->sct_item[I_RAD] * 2;
127 pollution = bad_stuff / 10.0 + np->nat_level[NAT_TLEV] + 100.0;
128 cleanup = sp->sct_effic + sp->sct_mobil + 100 + np->nat_level[NAT_RLEV];
129 plg_chance = ((pop / pop_space) * (pollution / cleanup) - 1.0) * 0.01;
130 if (chance(plg_chance))
136 * Given the fact that plague exists, kill off
137 * people if in plague state DYING. Increment
138 * the plague time. Return "current" plague
139 * stage. No reports generated here anymore.
142 plague_people(struct natstr *np, short *vec,
143 int *pstage, int *ptime, int etus)
150 if (opt_NO_PLAGUE) /* no plague nothing to do */
156 plg_num = 100.0 * etus;
157 plg_denom = (np->nat_level[NAT_RLEV] + 100.0) *
158 (*ptime + etus + 1.0);
159 pct_left = 1.0 - plg_num / plg_denom;
162 vec[I_CIVIL] = vec[I_CIVIL] * pct_left;
163 vec[I_MILIT] = vec[I_MILIT] * pct_left;
164 vec[I_UW] = vec[I_UW] * pct_left;
174 logerror("plague_people: bad pstage %d", stage);
175 *pstage = PLG_HEALTHY;
181 *ptime = etus / 2 + roll0(etus);