2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, 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 * damage.c: Damage stuff.
29 * Known contributors to this file:
43 #include "prototypes.h"
47 item_damage(int pct, short *item)
52 for (i = I_NONE + 1; i <= I_MAX; ++i) {
53 if (opt_SUPER_BARS && i == I_BAR)
55 lose = roundavg((double)item[i] * pct * 0.01);
56 if (i == I_CIVIL || i == I_MILIT || i == I_UW)
57 lose = ldround(people_damage * lose, 1);
58 item[i] = item[i] >= lose ? item[i] - lose : 0;
63 ship_damage(struct shpstr *sp, int dam)
70 mpr(sp->shp_own, "\t%s takes %d\n", prship(sp), dam);
72 sp->shp_effic = damage((int)sp->shp_effic, dam);
73 if (sp->shp_mobil > 0)
74 sp->shp_mobil = damage((int)sp->shp_mobil, dam);
75 item_damage(dam, sp->shp_item);
79 shipdamage(struct shpstr *sp, int dam)
81 ship_damage(sp, (int)(dam / (1.0 + shp_armor(sp) / 100.0)));
85 land_damage(struct lndstr *lp, int dam)
92 mpr(lp->lnd_own, "\t%s takes %d\n", prland(lp), dam);
93 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
97 lp->lnd_effic = damage((int)lp->lnd_effic, dam);
98 if (lp->lnd_mobil > 0)
99 lp->lnd_mobil = damage((int)lp->lnd_mobil, dam);
100 item_damage(dam, lp->lnd_item);
105 landdamage(struct lndstr *lp, int dam)
107 double damage_factor, m;
111 /* fortification reduces damage */
112 damage_factor = m / (m + lp->lnd_harden);
114 /* vulnerable units take more damage */
115 damage_factor *= lnd_vul(lp) / 100.0;
117 land_damage(lp, ldround(damage_factor * dam, 1));
121 planedamage(struct plnstr *pp, int dam)
128 mpr(pp->pln_own, "\t%s takes %d\n", prplane(pp), dam);
129 pp->pln_effic = damage((int)pp->pln_effic, dam);
130 if (pp->pln_mobil > 0)
131 pp->pln_mobil = damage((int)pp->pln_mobil, dam);
135 * nukedamage() actually just calculates damage
136 * rather than inflicting it.
139 nukedamage(struct nchrstr *ncp, int range, int airburst)
146 rad = (int)(rad * 1.5);
150 /* larger area, less center damage */
151 dam = (int)((ncp->n_dam * 0.75) - (range * 20));
153 /* smaller area, more center damage */
154 dam = (int)(ncp->n_dam / (range + 1.0));
162 damage(int amt, int pct)
171 if (random() % 100 < tmp % 100)
176 /* asymptotic damage to commodities, efficiency, and sectors */
178 effdamage(int amt, int dam)
180 return damage(amt, PERCENT_DAMAGE(dam));
184 commdamage(int amt, int dam, i_type vtype)
188 if (vtype == I_BAR && opt_SUPER_BARS)
191 lost = amt - effdamage(amt, dam);
193 if (vtype == I_MILIT || vtype == I_CIVIL || vtype == I_UW)
194 lost = ldround(people_damage * lost, 1);