2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * fortdef.c: Fort defends an area.
29 * 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.
45 #include "prototypes.h"
51 static int sb(natid, natid, struct sctstr *, coord, coord, int, int);
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,
80 snxtitem_dist(&ni, EF_SHIP, x, y, 8);
81 while (nxtitem(&ni, &ship) && eff > 0.30) {
82 if (!feels_like_helping(ship.shp_own, own, att))
85 if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && !usesubs)
87 range = roundrange(shp_fire_range(&ship));
88 if (range < ni.curdist)
90 dam = shp_fire(&ship);
91 putship(ship.shp_uid, &ship);
95 nreport(ship.shp_own, N_FIRE_BACK, att, 1);
97 nreport(ship.shp_own, N_FIRE_S_ATTACK, att, 1);
98 eff *= (1.0 - (0.01 * dam));
101 pr("Incoming shells do %d damage!\n", dam);
103 if (noisy || (ship.shp_own != own)) {
104 if (ship.shp_own == own)
105 wu(0, own, "%s fired on %s at %s doing %d damage.\n",
106 prship(&ship), cname(att), xyas(x, y, own), dam);
110 "%s fired on %s at %s in defense of %s, doing %d damage.\n",
111 prship(&ship), cname(att), xyas(x, y, ship.shp_own),
115 "%s supported %s attacks against %s at %s, doing %d damage.\n",
116 prship(&ship), cname(own), cname(att),
117 xyas(x, y, ship.shp_own), dam);
121 return (int)(100 - eff * 100);
125 dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
128 struct sctstr firing;
131 if (opt_NO_FORT_FIRE) /* Forts can't fire! */
138 snxtsct_dist(&ns, ax, ay, 8);
139 while (nxtsct(&ns, &firing) && dam < 80) {
140 if (!feels_like_helping(firing.sct_own, def_own, att))
142 /* XXX defdef damage is additive, but ship or land unit damage isn't */
143 dam += sb(att, def_own, &firing, ax, ay, noisy, defending);
149 * Shall CN attempt to help FRIEND against FOE?
152 feels_like_helping(natid cn, natid friend, natid foe)
155 return 0; /* never helps anybody */
157 return 0; /* don't help anybody against self */
159 return 1; /* help self against anybody else */
160 /* third party helps ally if at war with foe: */
161 return relations_with(cn, friend) == ALLIED
162 && relations_with(cn, foe) == AT_WAR;
167 * See if the sector being fired at will defend itself.
170 sb(natid att, natid def, struct sctstr *sp, coord tx, coord ty, int noisy,
182 range = roundrange(fortrange(sp));
183 range2 = mapdist(sp->sct_x, sp->sct_y, tx, ty);
186 damage = fort_fire(sp);
190 if (sp->sct_own != def)
192 "%s fired on %s in %s in defense of %s, doing %d damage!\n",
193 xyas(sp->sct_x, sp->sct_y, sp->sct_own), cname(att),
194 xyas(tx, ty, sp->sct_own), cname(def), damage);
196 nreport(sp->sct_own, N_FIRE_BACK, att, 1);
198 nreport(sp->sct_own, N_FIRE_F_ATTACK, att, 1);
200 pr("Incoming shell! %d damage done.\007\n", damage);