2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 * boar.c: Board an enemy ship
30 * Known contributors to this file:
47 struct combat off[1]; /* boarding ship or sector */
48 struct combat def[1]; /* defending ship */
49 struct emp_qelem olist; /* boarding units */
50 struct emp_qelem dlist; /* defending units */
51 int ototal; /* total boarding strength */
52 int a_engineer = 0; /* boarder engineers are present */
53 int a_spy = 0; /* the best boarder scout */
54 struct shpstr ship; /* for retreating */
62 att_combat_init(def, EF_SHIP);
64 * Collect input from the boarder
67 /* What are we boarding? */
68 p = getstarg(player->argp[1], "Victim ship #? ", buf);
69 if (!p || (def->shp_uid = atoi(p)) < 0)
73 * Ask the boarder what he wants to board with
76 if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
79 att_combat_init(off, EF_SECTOR);
80 if (!sarg_xy(p, &off->x, &off->y))
82 getsect(off->x, off->y, §);
83 if (sect.sct_own != player->cnum) {
84 pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
87 if (sect.sct_mobil <= 0) {
88 /* Look for land units with mobility */
89 snxtitem_xy(&ni, EF_LAND, off->x, off->y);
91 while (nxtitem(&ni, &land)) {
92 if (land.lnd_own != player->cnum)
94 if (land.lnd_ship >= 0)
96 if (land.lnd_mobil <= 0)
98 /* Only land units with assault can board */
99 if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT))
104 pr("You don't have any mobility (sector or land units) in %s!\n",
105 xyas(off->x, off->y, player->cnum));
110 att_combat_init(off, EF_SHIP);
111 if ((off->shp_uid = atoi(p)) < 0)
114 if (att_abort(A_BOARD, off, def)) {
115 pr("Board aborted\n");
119 /* Fire at the attacking ship */
121 att_approach(off, def);
122 if (att_abort(A_BOARD, off, def)) {
123 pr("Board aborted\n");
124 att_empty_attack(A_BOARD, 0, def);
128 /* Show what we're boarding, and check treaties */
133 /* Ask the player what he wants to board with */
135 att_ask_offense(A_BOARD, off, def, &olist, &a_spy, &a_engineer);
136 if (att_abort(A_BOARD, off, def)) {
137 pr("Board aborted\n");
138 att_empty_attack(A_BOARD, 0, def);
139 return att_free_lists(&olist, NULL);
142 ototal = att_get_offense(A_BOARD, off, &olist, def);
143 if (att_abort(A_BOARD, off, def)) {
144 pr("Board aborted\n");
145 att_empty_attack(A_BOARD, 0, def);
146 return att_free_lists(&olist, NULL);
150 * We have now got all the answers from the boarder. From this point
151 * forward, we can assume that this battle is the _only_ thing
152 * happening in the game.
155 /* Get the real defense */
157 att_get_defense(&olist, def, &dlist, a_spy, ototal);
160 * Death, carnage, and destruction.
163 if (!(att_fight(A_BOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
164 getship(def->shp_uid, &ship);
165 if (ship.shp_rflags & RET_BOARDED) {
166 retreat_ship(&ship, 'u');
167 putship(def->shp_uid, &ship);