2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * damage.c: Damage stuff.
30 * Known contributors to this file:
44 #include "prototypes.h"
49 item_damage(int pct, short *item)
54 for (i = I_NONE + 1; i <= I_MAX; ++i) {
55 if (opt_SUPER_BARS && i == I_BAR)
57 lose = roundavg((double)item[i] * pct * 0.01);
58 if (i == I_CIVIL || i == I_MILIT || i == I_UW)
59 lose = ldround(people_damage * lose, 1);
60 item[i] = item[i] >= lose ? item[i] - lose : 0;
65 ship_damage(struct shpstr *sp, int dam)
72 mpr(sp->shp_own, "\t%s takes %d\n", prship(sp), dam);
74 sp->shp_effic = damage((int)sp->shp_effic, dam);
75 if (sp->shp_mobil > 0)
76 sp->shp_mobil = damage((int)sp->shp_mobil, dam);
77 if (opt_FUEL && sp->shp_fuel)
78 sp->shp_fuel = damage((int)sp->shp_fuel, dam);
79 item_damage(dam, sp->shp_item);
83 shipdamage(struct shpstr *sp, int dam)
85 ship_damage(sp, (int)(dam / (1.0 + sp->shp_armor / 100.0)));
89 land_damage(struct lndstr *lp, int dam)
96 mpr(lp->lnd_own, "\t%s takes %d\n", prland(lp), dam);
97 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
101 lp->lnd_effic = damage((int)lp->lnd_effic, dam);
102 if (lp->lnd_mobil > 0)
103 lp->lnd_mobil = damage((int)lp->lnd_mobil, dam);
104 if (opt_FUEL && lp->lnd_fuel)
105 lp->lnd_fuel = damage((int)lp->lnd_fuel, dam);
106 item_damage(dam, lp->lnd_item);
111 landdamage(struct lndstr *lp, int dam)
113 double damage_factor, m;
117 /* fortification reduces damage */
118 damage_factor = m / (m + lp->lnd_harden);
120 /* vulnerable units take more damage */
121 damage_factor *= lp->lnd_vul / 100.0;
123 land_damage(lp, ldround(damage_factor * dam, 1));
127 planedamage(struct plnstr *pp, int dam)
134 mpr(pp->pln_own, "\t%s takes %d\n", prplane(pp), dam);
135 pp->pln_effic = damage((int)pp->pln_effic, dam);
136 if (pp->pln_mobil > 0)
137 pp->pln_mobil = damage((int)pp->pln_mobil, dam);
141 * nukedamage() actually just calculates damage
142 * rather than inflicting it.
145 nukedamage(struct nchrstr *ncp, int range, int airburst)
152 rad = (int)(rad * 1.5);
156 /* larger area, less center damage */
157 dam = (int)((ncp->n_dam * 0.75) - (range * 20));
159 /* smaller area, more center damage */
160 dam = (int)(ncp->n_dam / (range + 1.0));
168 damage(int amt, int pct)
177 if (random() % 100 < tmp % 100)
182 /* asymptotic damage to commodities, efficiency, and sectors */
184 effdamage(int amt, int dam)
186 return damage(amt, PERCENT_DAMAGE(dam));
190 commdamage(int amt, int dam, i_type vtype)
194 if (vtype == I_BAR && opt_SUPER_BARS)
197 lost = amt - effdamage(amt, dam);
199 if (vtype == I_MILIT || vtype == I_CIVIL || vtype == I_UW)
200 lost = ldround(people_damage * lost, 1);