]> git.pond.sub.org Git - empserver/blob - src/lib/commands/boar.c
Update copyright notice
[empserver] / src / lib / commands / boar.c
1 /*
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
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  boar.c: Board an enemy ship
29  *
30  *  Known contributors to this file:
31  *     Ken Stevens, 1995
32  */
33
34 #include <config.h>
35
36 #include "combat.h"
37 #include "commands.h"
38 #include "land.h"
39 #include "mission.h"
40 #include "path.h"
41 #include "retreat.h"
42 #include "ship.h"
43
44 int
45 boar(void)
46 {
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 */
55     struct sctstr sect;
56     struct lndstr land;
57     struct nstr_item ni;
58     int foundland;
59     char *p;
60     char buf[1024];
61
62     att_combat_init(def, EF_SHIP);
63     /*
64      * Collect input from the boarder
65      */
66
67     /* What are we boarding? */
68
69     if (!(p = getstarg(player->argp[1], "Victim ship #?  ", buf)) ||
70         (def->shp_uid = atoi(p)) < 0)
71         return RET_SYN;
72
73     /*
74      * Ask the boarder what he wants to board with
75      */
76
77     if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
78         return RET_SYN;
79     if (issector(p)) {
80         att_combat_init(off, EF_SECTOR);
81         if (!sarg_xy(p, &off->x, &off->y))
82             return RET_SYN;
83         getsect(off->x, off->y, &sect);
84         if (sect.sct_own != player->cnum) {
85             pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
86             return RET_SYN;
87         }
88         if (sect.sct_mobil <= 0) {
89             /* Look for land units with mobility */
90             snxtitem_xy(&ni, EF_LAND, off->x, off->y);
91             foundland = 0;
92             while (nxtitem(&ni, &land)) {
93                 if (land.lnd_own != player->cnum)
94                     continue;
95                 if (land.lnd_ship >= 0)
96                     continue;
97                 if (land.lnd_mobil <= 0)
98                     continue;
99                 /* Only land units with assault can board */
100                 if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT))
101                     continue;
102                 foundland = 1;
103             }
104             if (!foundland) {
105                 pr("You don't have any mobility (sector or land units) in %s!\n",
106                    xyas(off->x, off->y, player->cnum));
107                 return RET_SYN;
108             }
109         }
110     } else {
111         att_combat_init(off, EF_SHIP);
112         if ((off->shp_uid = atoi(p)) < 0)
113             return RET_SYN;
114     }
115     if (att_abort(A_BOARD, off, def)) {
116         pr("Board aborted\n");
117         return RET_OK;
118     }
119
120     /* Fire at the attacking ship */
121
122     att_approach(off, def);
123     if (att_abort(A_BOARD, off, def)) {
124         pr("Board aborted\n");
125         att_empty_attack(A_BOARD, 0, def);
126         return RET_OK;
127     }
128
129     /* Show what we're boarding, and check treaties */
130
131     if (att_show(def))
132         return RET_FAIL;
133
134     /* Ask the player what he wants to board with */
135
136     att_ask_offense(A_BOARD, off, def, &olist, &a_spy, &a_engineer);
137     if (att_abort(A_BOARD, off, def)) {
138         pr("Board aborted\n");
139         att_empty_attack(A_BOARD, 0, def);
140         return att_free_lists(&olist, 0);
141     }
142
143     ototal = att_get_offense(A_BOARD, off, &olist, def);
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);
148     }
149
150     /*
151      * We have now got all the answers from the boarder.  From this point
152      * forward, we can assume that this battle is the _only_ thing
153      * happening in the game.
154      */
155
156     /* Get the real defense */
157
158     att_get_defense(&olist, def, &dlist, a_spy, ototal);
159
160     /*
161      * Death, carnage, and destruction.
162      */
163
164     if (!(att_fight(A_BOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
165         getship(def->shp_uid, &ship);
166         if (ship.shp_rflags & RET_BOARDED) {
167             retreat_ship(&ship, 'u');
168             putship(def->shp_uid, &ship);
169         }
170     }
171
172     return RET_OK;
173 }