2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 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.
28 * assa.c: Hit the beaches!
30 * Known contributors to this file:
53 struct combat off[1]; /* assaulting ship */
54 struct combat def[1]; /* defending sector */
55 int fort_sup, ship_sup, land_sup, plane_sup;
56 struct emp_qelem olist; /* assaulting units */
57 struct emp_qelem dlist; /* defending units */
58 int ototal; /* total assaulting strength */
59 int a_engineer = 0; /* assaulter engineers are present */
60 int a_spy = 0; /* the best assaulter scout */
61 double osupport = 1.0; /* assault support */
62 double dsupport = 1.0; /* defense support */
67 struct emp_qelem *qp, *next;
71 att_combat_init(off, EF_SHIP);
72 att_combat_init(def, EF_SECTOR);
74 * Collect input from the assaulter
77 /* What are we assaulting? */
79 if (!(p = getstarg(player->argp[1], "Sector : ", buf)))
81 if (!sarg_xy(p, &def->x, &def->y))
83 if (att_abort(A_ASSAULT, 0, def))
87 * Ask the assaulter what he wants to assault with
91 onearg(player->argp[2], "Assault from ship #")) < 0) {
92 pr("You may only assault from one ship!\n");
95 if (att_abort(A_ASSAULT, off, def)) {
96 pr("Assault aborted\n");
100 /* Show what we're assaulting, and check treaties */
105 /* Ask about offensive support */
107 att_ask_support(3, &fort_sup, &ship_sup, &land_sup, &plane_sup);
108 if (att_abort(A_ASSAULT, off, def)) {
109 att_empty_attack(A_ASSAULT, 0, def);
113 /* Ask the player what he wants to assault with */
115 att_ask_offense(A_ASSAULT, off, def, &olist, &a_spy, &a_engineer);
116 if (att_abort(A_ASSAULT, off, def)) {
117 pr("Assault aborted\n");
118 att_empty_attack(A_ASSAULT, 0, def);
119 return att_free_lists(&olist, 0);
122 /* If we're assaulting our own sector, end here */
123 if (def->own == player->cnum) {
125 pr("You reinforce %s with %d troops\n",
126 xyas(def->x, def->y, player->cnum), off->troops);
127 if (off->troops || !QEMPTY(&olist))
128 att_move_in_off(A_ASSAULT, off, &olist, def);
133 * Estimate the defense strength and give the player a chance to abort
136 ototal = att_estimate_defense(A_ASSAULT, off, &olist, def, a_spy);
137 if (att_abort(A_ASSAULT, off, def)) {
138 pr("Assault aborted\n");
139 att_empty_attack(A_ASSAULT, 0, def);
140 return att_free_lists(&olist, 0);
144 * We have now got all the answers from the assaulter. From this point
145 * forward, we can assume that this battle is the _only_ thing
146 * happening in the game.
149 /* First, we check to see if the only thing we have are spies
150 * assaulting. If so, we try to sneak them on land. If they
151 * make it, the defenders don't see a thing. If they fail, well,
152 * the spies die, and the defenders see them. */
155 for (n = 0; n <= off->last; n++) {
156 if (off[n].type == EF_BAD)
158 ourtotal += off[n].troops * att_combat_eff(off + n);
160 for (qp = olist.q_forw; qp != &olist; qp = next) {
162 llp = (struct llist *)qp;
163 if (lchr[(int)llp->land.lnd_type].l_flags & L_SPY)
168 /* If no attacking forces (i.e. we got here with only spies)
169 * then try to sneak on-land. */
172 pr("Trying to sneak on shore...\n");
174 for (qp = olist.q_forw; qp != &olist; qp = next) {
176 llp = (struct llist *)qp;
177 rel = getrel(getnatp(def->own), player->cnum);
178 if (chance(0.10) || rel == ALLIED || !def->own) {
179 pr("%s made it on shore safely.\n", prland(&llp->land));
180 llp->land.lnd_x = def->x;
181 llp->land.lnd_y = def->y;
182 llp->land.lnd_ship = -1;
183 putland(llp->land.lnd_uid, &llp->land);
185 pr("%s was spotted", prland(&llp->land));
186 if (rel == HOSTILE || rel == AT_WAR || rel == SITZKRIEG ||
187 rel == MOBILIZATION) {
188 wu(0, def->own, "%s spy shot and killed in %s.\n",
189 cname(player->cnum), xyas(def->x, def->y,
191 pr(" and was killed in the attempt.\n");
192 llp->land.lnd_effic = 0;
193 putland(llp->land.lnd_uid, &llp->land);
196 wu(0, def->own, "%s spy spotted in %s.\n",
197 cname(player->cnum), xyas(def->x, def->y,
199 pr(" but made it ok.\n");
200 llp->land.lnd_x = def->x;
201 llp->land.lnd_y = def->y;
202 llp->land.lnd_ship = -1;
203 putland(llp->land.lnd_uid, &llp->land);
210 /* Get the real defense */
212 att_get_defense(&olist, def, &dlist, a_spy, ototal);
214 /* Get assaulter and defender support */
216 att_get_support(A_ASSAULT, fort_sup, ship_sup, land_sup, plane_sup,
217 &olist, off, &dlist, def, &osupport, &dsupport,
219 if (att_abort(A_ASSAULT, off, def)) {
220 pr("Assault aborted\n");
221 att_empty_attack(A_ASSAULT, 0, def);
222 return att_free_lists(&olist, &dlist);
226 * Death, carnage, and destruction.
229 att_fight(A_ASSAULT, off, &olist, osupport, def, &dlist, dsupport);