]> git.pond.sub.org Git - empserver/blob - src/lib/subs/sectdamage.c
Update copyright notice
[empserver] / src / lib / subs / sectdamage.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2010, 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 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.
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 <config.h>
36
37 #include "combat.h"
38 #include "damage.h"
39 #include "file.h"
40 #include "land.h"
41 #include "misc.h"
42 #include "nat.h"
43 #include "nsc.h"
44 #include "optlist.h"
45 #include "plane.h"
46 #include "prototypes.h"
47 #include "sect.h"
48 #include "ship.h"
49 #include "xy.h"
50
51 int
52 sect_damage(struct sctstr *sp, int dam)
53 {
54     int eff;
55
56     if (dam <= 0)
57         return 0;
58     if (dam > 100)
59         dam = 100;
60
61     sp->sct_effic = damage(sp->sct_effic, dam);
62     sp->sct_avail = damage(sp->sct_avail, dam);
63     sp->sct_road = damage(sp->sct_road, dam);
64     sp->sct_rail = damage(sp->sct_rail, dam);
65     sp->sct_defense = damage(sp->sct_defense, dam);
66
67     eff = dam;
68
69     if (sp->sct_mobil > 0)
70         sp->sct_mobil = damage(sp->sct_mobil, dam);
71     item_damage(dam, sp->sct_item);
72     bridge_damaged(sp);
73     putsect(sp);
74     return eff;
75 }
76
77 int
78 sectdamage(struct sctstr *sp, int dam)
79 {
80     struct nstr_item ni;
81     struct lndstr land;
82     struct plnstr plane;
83     int eff;
84
85     /* Some sectors are harder/easier to kill..   */
86     /* Average sector has a dstr of 1, so adjust  */
87     /* the damage accordingly. Makes forts a pain */
88     dam = ldround(dam / sector_strength(sp), 1);
89
90     eff = sect_damage(sp, PERCENT_DAMAGE(dam));
91
92     /* Damage all the land units in the sector */
93     /* Units don't take full damage */
94     dam = ldround(DPERCENT_DAMAGE(dam * unit_damage), 1);
95     if (dam <= 0)
96         return eff;
97
98     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
99     while (nxtitem(&ni, &land)) {
100         if (!land.lnd_own)
101             continue;
102         landdamage(&land, dam);
103         putland(land.lnd_uid, &land);
104     }
105
106     dam = dam / 7;
107     if (dam <= 0)
108         return eff;
109     snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
110     while (nxtitem(&ni, &plane)) {
111         if (!plane.pln_own)
112             continue;
113         if (plane.pln_flags & PLN_LAUNCHED)
114             continue;
115         if (plane.pln_ship >= 0)
116             continue;
117         planedamage(&plane, dam);
118         putplane(plane.pln_uid, &plane);
119     }
120     return eff;
121 }