]> git.pond.sub.org Git - empserver/blob - src/lib/common/sectdamage.c
Import of Empire 4.2.12
[empserver] / src / lib / common / sectdamage.c
1 /*
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
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
53 int
54 sect_damage(struct sctstr *sp, int dam, struct emp_qelem *list)
55 {
56         int     eff;
57
58         if (dam <= 0)
59                 return 0;
60         if (dam > 100)
61                 dam = 100;
62
63         sp->sct_effic = damage((int)sp->sct_effic, dam);
64         sp->sct_road = damage((int)sp->sct_road, dam);
65         sp->sct_rail = damage((int)sp->sct_rail, dam);
66         sp->sct_defense = damage((int)sp->sct_defense, dam);
67         if (!opt_DEFENSE_INFRA)
68           sp->sct_defense = sp->sct_effic;
69
70         eff = dam;
71
72         if (sp->sct_mobil > 0)
73              sp->sct_mobil = damage((int)sp->sct_mobil, dam);
74         sp->sct_nv = vl_damage(dam,
75                                sp->sct_vtype, sp->sct_vamt,
76                                (int)sp->sct_nv);
77         if (opt_EASY_BRIDGES == 0) {
78           if (sp->sct_effic < 20 && sp->sct_type == SCT_BHEAD)
79             bridgefall(sp, list);
80         } else {
81           if (sp->sct_effic < 20 && 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         extern  double unit_damage;
92         struct  nstr_item ni;
93         struct  lndstr land;
94         struct  plnstr plane;
95         double  real_dam;
96         int     eff;
97         double  sector_strength();
98
99         /* Some sectors are harder/easier to kill..   */
100         /* Average sector has a dstr of 1, so adjust  */
101         /* the damage accordingly. Makes forts a pain */
102         
103 /*      real_dam = (double)dam * (1.0/((((double)(dchr[sp->sct_type].d_dstr - 1))*(sp->sct_effic/100.0)) + 1.0));*/
104         real_dam = (double)dam * (1.0/sector_strength(sp));
105         dam = ldround(real_dam,1);
106
107         eff = sect_damage(sp, PERCENT_DAMAGE(dam), list);
108
109         /* Damage all the land units in the sector */
110         /* Units don't take full damage */
111         dam = ldround(DPERCENT_DAMAGE(dam * unit_damage), 1);
112         if (dam <= 0)
113                 return eff;
114
115         snxtitem_xy(&ni,EF_LAND,sp->sct_x,sp->sct_y);   
116         while(nxtitem(&ni,(s_char *)&land)){
117                 if (!land.lnd_own)
118                         continue;
119                 landdamage(&land,dam);
120                 putland(land.lnd_uid,&land);
121         }
122
123         dam = dam / 7;
124         if (dam <= 0)
125             return eff;
126         snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
127         while (nxtitem(&ni, (s_char *)&plane)) {
128             if (!plane.pln_own)
129                 continue;
130             if (plane.pln_flags & PLN_LAUNCHED)
131                 continue;
132             if (plane.pln_ship >= 0)
133                 continue;
134             /* Is this plane flying in this list? */
135             if (ac_isflying(&plane, list))
136               continue;
137             planedamage(&plane, dam);
138             putplane(plane.pln_uid, &plane);
139         }
140         return eff;
141 }