2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * plague.c: Plague related functions
30 * Known contributors to this file:
31 * Steve McClure, 1998-2000
50 static int infect_people(struct natstr *, register int *, u_int, int,
54 do_plague(struct sctstr *sp, struct natstr *np, int etu)
57 u_short pstage, ptime;
60 if (opt_NO_PLAGUE) /* no plague nothing to do */
63 if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
65 pstage = sp->sct_pstage;
66 ptime = sp->sct_ptime;
68 if (pstage == PLG_HEALTHY) {
69 pstage = infect_people(np, vec, sp->sct_effic, (int)sp->sct_mobil, sp);
72 n = plague_people(np, vec, &pstage, &ptime, etu);
75 wu(0, sp->sct_own, "PLAGUE deaths reported in %s.\n",
77 nreport(sp->sct_own, N_DIE_PLAGUE, 0, 1);
80 wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp));
83 /* Are we still incubating? */
85 /* Yes. Will it turn "infectious" next time? */
87 /* Yes. Report an outbreak. */
89 "Outbreak of PLAGUE in %s!\n", ownxy(sp));
90 nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1);
93 /* It has already moved on to "infectious" */
94 wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp));
98 /* Has the plague moved to "incubation" yet? */
100 /* Yes. Will it turn "infectious" next time? */
102 /* Yes. Report an outbreak. */
104 "Outbreak of PLAGUE in %s!\n", ownxy(sp));
105 nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1);
113 if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 &&
114 !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) {
115 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
119 putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
120 sp->sct_pstage = pstage;
121 sp->sct_ptime = ptime;
126 infect_people(struct natstr *np, register int *vec, u_int eff, int mobil,
132 double civvies = 999.0;
134 if (opt_NO_PLAGUE) /* no plague nothing to do */
137 if (np->nat_level[NAT_TLEV] <= 10.0)
140 if (opt_BIG_CITY && (sp->sct_type == SCT_CAPIT))
144 * make plague where there was none before...
146 plg_num = ((vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]) / civvies) *
147 ((vec[I_IRON] + vec[I_OIL] + (vec[I_RAD] * 2)) / 10.0 +
148 np->nat_level[NAT_TLEV] + 100.0);
149 plg_denom = eff + mobil + 100 + np->nat_level[NAT_RLEV];
150 plg_chance = ((plg_num / plg_denom) - 1.0) * 0.01;
151 if (chance(plg_chance))
157 * Given the fact that plague exists, kill off
158 * people if in plague state DYING. Increment
159 * the plague time. Return "current" plague
160 * stage. No reports generated here anymore.
163 plague_people(struct natstr *np, register int *vec,
164 u_short *pstage, u_short *ptime,
172 if (opt_NO_PLAGUE) /* no plague nothing to do */
178 plg_num = 100.0 * etus;
179 plg_denom = (np->nat_level[NAT_RLEV] + 100.0) *
180 (*ptime + etus + 1.0);
181 pct_left = 1.0 - (double)(plg_num / plg_denom);
184 vec[I_CIVIL] = vec[I_CIVIL] * pct_left;
185 vec[I_MILIT] = vec[I_MILIT] * pct_left;
186 vec[I_UW] = vec[I_UW] * pct_left;
196 logerror("plague_people: bad pstage %d", stage);
197 *pstage = PLG_HEALTHY;
203 *ptime = (etus / 2) + (random() % etus);