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 * boar.c: Board an enemy ship
30 * Known contributors to this file:
55 struct combat off[1]; /* boarding ship or sector */
56 struct combat def[1]; /* defending ship */
57 struct emp_qelem olist; /* boarding units */
58 struct emp_qelem dlist; /* defending units */
59 int ototal; /* total boarding strength */
60 int a_engineer = 0; /* boarder engineers are present */
61 int a_spy = 0; /* the best boarder scout */
62 struct shpstr ship; /* for retreating */
70 att_combat_init(def, EF_SHIP);
72 * Collect input from the boarder
75 /* What are we boarding? */
77 if (!(p = getstarg(player->argp[1], "Victim ship #? ", buf)) ||
78 (def->shp_uid = atoi(p)) < 0)
82 * Ask the boarder what he wants to board with
85 if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
88 att_combat_init(off, EF_SECTOR);
89 if (!sarg_xy(p, &off->x, &off->y))
91 getsect(off->x, off->y, §);
92 if (sect.sct_own != player->cnum) {
93 pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
96 if (sect.sct_mobil <= 0) {
97 /* Look for land units with mobility */
98 snxtitem_xy(&ni, EF_LAND, off->x, off->y);
100 while (nxtitem(&ni, (s_char *)&land)) {
101 if (land.lnd_own != player->cnum)
103 if (land.lnd_ship >= 0)
105 if (land.lnd_mobil <= 0)
107 /* Only land units with assault can board */
108 if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT))
113 pr("You don't have any mobility (sector or land units) in %s!\n", xyas(off->x, off->y, player->cnum));
118 att_combat_init(off, EF_SHIP);
119 if ((off->shp_uid = atoi(p)) < 0)
122 if (att_abort(A_BOARD, off, def)) {
123 pr("Board aborted\n");
127 /* Fire at the attacking ship */
129 att_approach(off, def);
130 if (att_abort(A_BOARD, off, def)) {
131 pr("Board aborted\n");
132 att_empty_attack(A_BOARD, 0, def);
136 /* Show what we're boarding, and check treaties */
141 /* Ask the player what he wants to board with */
143 att_ask_offense(A_BOARD, off, def, &olist, &a_spy, &a_engineer);
144 if (att_abort(A_BOARD, off, def)) {
145 pr("Board aborted\n");
146 att_empty_attack(A_BOARD, 0, def);
147 return att_free_lists(&olist, 0);
151 * Estimate the defense strength and give the player a chance to abort
154 ototal = att_estimate_defense(A_BOARD, off, &olist, def, a_spy);
155 if (att_abort(A_BOARD, off, def)) {
156 pr("Board aborted\n");
157 att_empty_attack(A_BOARD, 0, def);
158 return att_free_lists(&olist, 0);
162 * We have now got all the answers from the boarder. From this point
163 * forward, we can assume that this battle is the _only_ thing
164 * happening in the game.
167 /* Get the real defense */
169 att_get_defense(&olist, def, &dlist, a_spy, ototal);
172 * Death, carnage, and destruction.
175 if (!(att_fight(A_BOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
176 getship(def->shp_uid, &ship);
177 if (ship.shp_rflags & RET_BOARDED) {
178 retreat_ship(&ship, 'u');
179 putship(def->shp_uid, &ship);