2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2018, 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 * fallout.c: Nuclear fallout
29 * Known contributors to this file:
32 * Markus Armbruster, 2004-2016
42 #include "prototypes.h"
45 static void do_fallout(struct sctstr *, int);
46 static void meltitems(int, int, int, short *, int, int, int, int);
47 static void spread_fallout(struct sctstr *, int);
48 static void decay_fallout(struct sctstr *, int);
59 /* First, we determine which sectors to process fallout in */
60 for (n = 0; NULL != (sp = getsectid(n)); n++)
61 sp->sct_updated = sp->sct_fallout != 0;
62 /* Next, we process the fallout there */
63 for (n = 0; NULL != (sp = getsectid(n)); n++)
64 if (sp->sct_updated && sp->sct_type != SCT_SANCT)
66 /* Next, we spread the fallout */
67 for (n = 0; NULL != (sp = getsectid(n)); n++)
69 spread_fallout(sp, etu);
70 /* Next, we decay the fallout */
71 for (n = 0; NULL != (sp = getsectid(n)); n++) {
73 decay_fallout(sp, etu);
79 * Do fallout meltdown for sector @sp.
80 * @etus above 24 are treated as 24 to avoid *huge* kill offs in
84 do_fallout(struct sctstr *sp, int etus)
90 /* This check shouldn't be needed, but just in case. :) */
91 if (!sp->sct_fallout || !sp->sct_updated)
95 meltitems(etus, sp->sct_fallout, sp->sct_own, sp->sct_item,
96 EF_SECTOR, sp->sct_x, sp->sct_y, 0);
97 for (i = 0; NULL != (lp = getlandp(i)); i++) {
100 if (lp->lnd_x != sp->sct_x || lp->lnd_y != sp->sct_y)
102 meltitems(etus, sp->sct_fallout, lp->lnd_own, lp->lnd_item,
103 EF_LAND, lp->lnd_x, lp->lnd_y, lp->lnd_uid);
105 for (i = 0; NULL != (spp = getshipp(i)); i++) {
108 if (spp->shp_x != sp->sct_x || spp->shp_y != sp->sct_y)
110 if (mchr[(int)spp->shp_type].m_flags & M_SUB)
112 meltitems(etus, sp->sct_fallout, spp->shp_own, spp->shp_item,
113 EF_SHIP, spp->shp_x, spp->shp_y, spp->shp_uid);
118 meltitems(int etus, int fallout, int own, short *vec,
119 int type, int x, int y, int uid)
124 for (n = I_NONE + 1; n <= I_MAX; n++) {
125 melt = roundavg(vec[n] * etus * (double)fallout
126 / (1000.0 * ichr[n].i_melt_denom));
129 if (melt > 5 && own) {
130 if (type == EF_SECTOR)
131 wu(0, own, "Lost %d %s to radiation in %s.\n",
132 melt, ichr[n].i_name,
134 else if (type == EF_LAND)
135 wu(0, own, "Unit #%d lost %d %s to radiation in %s.\n",
136 uid, melt, ichr[n].i_name,
138 else if (type == EF_SHIP)
139 wu(0, own, "Ship #%d lost %d %s to radiation in %s.\n",
140 uid, melt, ichr[n].i_name,
148 spread_fallout(struct sctstr *sp, int etus)
156 for (n = DIR_FIRST; n <= DIR_LAST; n++) {
157 ap = getsectp(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1]);
158 if (ap->sct_type == SCT_SANCT)
160 inc = roundavg(etus * fallout_spread * (sp->sct_fallout)) - 1;
163 ap->sct_fallout = MIN(ap->sct_fallout + inc, FALLOUT_MAX);
168 decay_fallout(struct sctstr *sp, int etus)
174 decay = roundavg((decay_per_etu + 6.0) * fallout_spread *
175 (double)etus * (double)sp->sct_fallout);
177 sp->sct_fallout = decay < sp->sct_fallout ? sp->sct_fallout - decay : 0;