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
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 * assa.c: Hit the beaches!
30 * Known contributors to this file:
56 struct combat off[1]; /* assaulting ship */
57 struct combat def[1]; /* defending sector */
58 int fort_sup, ship_sup, land_sup, plane_sup;
59 struct emp_qelem olist; /* assaulting units */
60 struct emp_qelem dlist; /* defending units */
61 int ototal; /* total assaulting strength */
62 int a_engineer = 0; /* assaulter engineers are present */
63 int a_spy = 0; /* the best assaulter scout */
64 double osupport = 1.0; /* assault support */
65 double dsupport = 1.0; /* defense support */
70 struct emp_qelem *qp, *next;
74 att_combat_init(off, EF_SHIP);
75 att_combat_init(def, EF_SECTOR);
77 * Collect input from the assaulter
80 /* What are we assaulting? */
82 if (!(p = getstarg(player->argp[1], "Sector : ", buf)))
84 if (!sarg_xy(p, &def->x, &def->y))
86 if (att_abort(A_ASSAULT, 0, def))
90 * Ask the assaulter what he wants to assault with
94 onearg(player->argp[2], "Assault from ship #")) < 0) {
95 pr("You may only assault from one ship!\n");
98 if (att_abort(A_ASSAULT, off, def)) {
99 pr("Assault aborted\n");
103 /* Show what we're assaulting, and check treaties */
108 /* Ask about offensive support */
110 att_ask_support(3, &fort_sup, &ship_sup, &land_sup, &plane_sup);
111 if (att_abort(A_ASSAULT, off, def)) {
112 att_empty_attack(A_ASSAULT, 0, def);
116 /* Ask the player what he wants to assault with */
118 att_ask_offense(A_ASSAULT, off, def, &olist, &a_spy, &a_engineer);
119 if (att_abort(A_ASSAULT, off, def)) {
120 pr("Assault aborted\n");
121 att_empty_attack(A_ASSAULT, 0, def);
122 return att_free_lists(&olist, 0);
125 /* If we're assaulting our own sector, end here */
126 if (def->own == player->cnum) {
128 pr("You reinforce %s with %d troops\n",
129 xyas(def->x, def->y, player->cnum), off->troops);
130 if (off->troops || !QEMPTY(&olist))
131 att_move_in_off(A_ASSAULT, off, &olist, def);
136 * Estimate the defense strength and give the player a chance to abort
139 ototal = att_estimate_defense(A_ASSAULT, off, &olist, def, a_spy);
140 if (att_abort(A_ASSAULT, off, def)) {
141 pr("Assault aborted\n");
142 att_empty_attack(A_ASSAULT, 0, def);
143 return att_free_lists(&olist, 0);
147 * We have now got all the answers from the assaulter. From this point
148 * forward, we can assume that this battle is the _only_ thing
149 * happening in the game.
152 /* First, we check to see if the only thing we have are spies
153 * assaulting. If so, we try to sneak them on land. If they
154 * make it, the defenders don't see a thing. If they fail, well,
155 * the spies die, and the defenders see them. */
158 for (n = 0; n <= off->last; n++) {
159 if (off[n].type == EF_BAD)
161 ourtotal += off[n].troops * att_combat_eff(off + n);
163 for (qp = olist.q_forw; qp != &olist; qp = next) {
165 llp = (struct llist *)qp;
166 if (lchr[(int)llp->land.lnd_type].l_flags & L_SPY)
171 /* If no attacking forces (i.e. we got here with only spies)
172 * then try to sneak on-land. */
175 pr("Trying to sneak on shore...\n");
177 for (qp = olist.q_forw; qp != &olist; qp = next) {
179 llp = (struct llist *)qp;
180 rel = getrel(getnatp(def->own), player->cnum);
181 if (chance(0.10) || rel == ALLIED || !def->own) {
182 pr("%s made it on shore safely.\n", prland(&llp->land));
183 llp->land.lnd_x = def->x;
184 llp->land.lnd_y = def->y;
185 llp->land.lnd_ship = -1;
186 putland(llp->land.lnd_uid, &llp->land);
188 pr("%s was spotted", prland(&llp->land));
189 if (rel == HOSTILE || rel == AT_WAR || rel == SITZKRIEG ||
190 rel == MOBILIZATION) {
191 wu(0, def->own, "%s spy shot and killed in %s.\n",
192 cname(player->cnum), xyas(def->x, def->y,
194 pr(" and was killed in the attempt.\n");
195 llp->land.lnd_effic = 0;
196 putland(llp->land.lnd_uid, &llp->land);
199 wu(0, def->own, "%s spy spotted in %s.\n",
200 cname(player->cnum), xyas(def->x, def->y,
202 pr(" but made it ok.\n");
203 llp->land.lnd_x = def->x;
204 llp->land.lnd_y = def->y;
205 llp->land.lnd_ship = -1;
206 putland(llp->land.lnd_uid, &llp->land);
213 /* Get the real defense */
215 att_get_defense(&olist, def, &dlist, a_spy, ototal);
217 /* Get assaulter and defender support */
219 att_get_support(A_ASSAULT, fort_sup, ship_sup, land_sup, plane_sup,
220 &olist, off, &dlist, def, &osupport, &dsupport,
222 if (att_abort(A_ASSAULT, off, def)) {
223 pr("Assault aborted\n");
224 att_empty_attack(A_ASSAULT, 0, def);
225 return att_free_lists(&olist, &dlist);
229 * Death, carnage, and destruction.
232 att_fight(A_ASSAULT, off, &olist, osupport, def, &dlist, dsupport);