2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 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.
28 * fortdef.c: Fort defends an area.
30 * Known contributors to this file:
34 * The base routines can also be used for general purposes.
35 * Noisy tells whther to send teles, print things, etc.
36 * Defending tells whether they are being defensive, or offensive.
49 #include "prototypes.h"
54 * See if any nearby ships will open up on the attacker
55 * Return damage done to attacker, if any.
56 * Subtracts shells used for firing. Responding ships
57 * require military, shells, and guns.
60 shipdef(natid att, natid own, coord x, coord y)
62 return sd(att, own, x, y, NOISY, 1, 1);
66 sd(natid att, natid own, coord x, coord y, int noisy, int defending,
82 snxtitem_dist(&ni, EF_SHIP, x, y, 8);
83 while (nxtitem(&ni, &ship) && eff > 0.30) {
84 if (ship.shp_own == att)
86 if (ship.shp_own == 0)
89 rel = getrel(getnatp(ship.shp_own), own);
90 rel2 = getrel(getnatp(ship.shp_own), att);
91 if ((ship.shp_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
93 if (ship.shp_effic < 60)
95 if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && (!usesubs))
97 range = techfact(ship.shp_tech,
98 ship.shp_frnge * ship.shp_effic / 200.0);
99 range = (double)roundrange(range);
100 if (range < ni.curdist)
102 /* must have gun, shell, and milit to fire */
103 shell = ship.shp_item[I_SHELL];
104 if (shell < ship.shp_glim)
105 shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
106 I_SHELL, shell - ship.shp_glim);
107 nshot = min(min(ship.shp_item[I_GUN], shell), ship.shp_item[I_MILIT]);
108 nshot = min(nshot, ship.shp_glim);
111 ship.shp_item[I_SHELL] = shell - nshot;
112 putship(ship.shp_uid, &ship);
114 nreport(ship.shp_own, N_FIRE_BACK, att, 1);
116 nreport(ship.shp_own, N_FIRE_S_ATTACK, att, 1);
117 dam = seagun(ship.shp_effic, nshot);
118 eff *= (1.0 - (0.01 * dam));
121 pr("Incoming shell%s %d damage!\n",
122 nshot == 1 ? " does" : "s do", dam);
124 if (noisy || (ship.shp_own != own)) {
125 if (ship.shp_own == own)
126 wu(0, own, "%s fired on %s at %s doing %d damage.\n",
127 prship(&ship), cname(att), xyas(x, y, own), dam);
131 "%s fired on %s at %s in defense of %s, doing %d damage.\n",
132 prship(&ship), cname(att), xyas(x, y, ship.shp_own),
136 "%s supported %s attacks against %s at %s, doing %d damage.\n",
137 prship(&ship), cname(own), cname(att), xyas(x, y,
144 return (int)100 - (eff * 100);
148 dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
153 struct sctstr firing;
156 if (opt_NO_FORT_FIRE) /* Forts can't fire! */
162 tech = tfactfire(def_own, 1.0);
164 snxtsct_dist(&ns, ax, ay, 8);
165 while (nxtsct(&ns, &firing) && dam < 80) {
166 if (firing.sct_own == att)
168 if (firing.sct_own == 0)
170 if (firing.sct_effic < FORTEFF)
172 rel = getrel(getnatp(firing.sct_own), def_own);
173 rel2 = getrel(getnatp(firing.sct_own), att);
174 if ((firing.sct_own != def_own) &&
175 ((rel != ALLIED) || (rel2 != AT_WAR)))
178 range = tfactfire(def_own, 7.0);
179 if (firing.sct_effic > 59)
181 /* Here we round down the range, and then add 1 to it
182 to determine if we could possibly hit the sector. If
183 we do, we call sb where the range is re-calculated and
184 the percentages are checked. */
185 range = (double)((int)(range) + 1);
186 if (range < ns.curdist)
188 /* XXX defdef damage is additive, but ship or land unit damage isn't */
189 dam += sb(att, def_own, &firing, ax, ay, noisy, defending);
196 * See if the sector being fired at will defend itself.
199 sb(natid att, natid def, struct sctstr *sp, coord tx, coord ty, int noisy,
208 if (sp->sct_type != SCT_FORTR) {
209 /* XXX I don't like this restriction */
213 if (sp->sct_effic < FORTEFF)
221 range = tfactfire(own, 7.0);
222 if (sp->sct_effic > 59)
224 range = (double)roundrange(range);
225 range2 = mapdist((int)sp->sct_x, (int)sp->sct_y, tx, ty);
228 gun = sp->sct_item[I_GUN];
231 shell = sp->sct_item[I_SHELL];
233 shell += supply_commod(sp->sct_own, sp->sct_x, sp->sct_y, I_SHELL,
237 sp->sct_item[I_SHELL] = shell - 1;
239 damage = landgun((int)sp->sct_effic, gun);
240 if (sp->sct_own != def)
242 "%s fired on %s in %s in defense of %s, doing %d damage!\n",
243 xyas(sp->sct_x, sp->sct_y, sp->sct_own), cname(att), xyas(tx,
249 nreport(sp->sct_own, N_FIRE_BACK, att, 1);
251 nreport(sp->sct_own, N_FIRE_F_ATTACK, att, 1);
253 pr("Incoming shell! %d damage done.\007\n", damage);