]> git.pond.sub.org Git - empserver/blob - src/lib/common/sectdamage.c
Update copyright notice.
[empserver] / src / lib / common / sectdamage.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  sectdamage.c: Damage a sector
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1989
32  *     Steve McClure, 1996
33  */
34
35 #include "misc.h"
36 #include "var.h"
37 #include "sect.h"
38 #include "ship.h"
39 #include "land.h"
40 #include "plane.h"
41 #include "nuke.h"
42 #include "xy.h"
43 #include "nsc.h"
44 #include "file.h"
45 #include "nat.h"
46 #include "optlist.h"
47 #include "damage.h"
48 #include "common.h"
49 #include "gen.h"
50 #include "subs.h"
51 #include "lost.h"
52 #include "combat.h"
53
54 int
55 sect_damage(struct sctstr *sp, int dam, struct emp_qelem *list)
56 {
57     int eff;
58
59     if (dam <= 0)
60         return 0;
61     if (dam > 100)
62         dam = 100;
63
64     sp->sct_effic = damage(sp->sct_effic, dam);
65     sp->sct_avail = damage(sp->sct_avail, dam);
66     sp->sct_road = damage(sp->sct_road, dam);
67     sp->sct_rail = damage(sp->sct_rail, dam);
68     sp->sct_defense = damage(sp->sct_defense, dam);
69     if (!opt_DEFENSE_INFRA)
70         sp->sct_defense = sp->sct_effic;
71
72     eff = dam;
73
74     if (sp->sct_mobil > 0)
75         sp->sct_mobil = damage(sp->sct_mobil, dam);
76     item_damage(dam, sp->sct_item);
77     if (opt_EASY_BRIDGES == 0) {
78         if (sp->sct_effic < SCT_MINEFF && sp->sct_type == SCT_BHEAD)
79             bridgefall(sp, list);
80     } else {
81         if (sp->sct_effic < SCT_MINEFF && sp->sct_type == SCT_BSPAN)
82             knockdown(sp, list);
83     }
84     putsect(sp);
85     return eff;
86 }
87
88 int
89 sectdamage(struct sctstr *sp, int dam, struct emp_qelem *list)
90 {
91     struct nstr_item ni;
92     struct lndstr land;
93     struct plnstr plane;
94     double real_dam;
95     int eff;
96
97     /* Some sectors are harder/easier to kill..   */
98     /* Average sector has a dstr of 1, so adjust  */
99     /* the damage accordingly. Makes forts a pain */
100
101 /*      real_dam = (double)dam * (1.0/((((double)(dchr[sp->sct_type].d_dstr - 1))*(sp->sct_effic/100.0)) + 1.0));*/
102     real_dam = (double)dam *(1.0 / sector_strength(sp));
103     dam = ldround(real_dam, 1);
104
105     eff = sect_damage(sp, PERCENT_DAMAGE(dam), list);
106
107     /* Damage all the land units in the sector */
108     /* Units don't take full damage */
109     dam = ldround(DPERCENT_DAMAGE(dam * unit_damage), 1);
110     if (dam <= 0)
111         return eff;
112
113     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
114     while (nxtitem(&ni, (s_char *)&land)) {
115         if (!land.lnd_own)
116             continue;
117         landdamage(&land, dam);
118         putland(land.lnd_uid, &land);
119     }
120
121     dam = dam / 7;
122     if (dam <= 0)
123         return eff;
124     snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
125     while (nxtitem(&ni, (s_char *)&plane)) {
126         if (!plane.pln_own)
127             continue;
128         if (plane.pln_flags & PLN_LAUNCHED)
129             continue;
130         if (plane.pln_ship >= 0)
131             continue;
132         /* Is this plane flying in this list? */
133         if (ac_isflying(&plane, list))
134             continue;
135         planedamage(&plane, dam);
136         putplane(plane.pln_uid, &plane);
137     }
138     return eff;
139 }