]> 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-2005, 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 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.
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 "misc.h"
35 #include "player.h"
36 #include "file.h"
37 #include "sect.h"
38 #include "path.h"
39 #include "nat.h"
40 #include "xy.h"
41 #include "land.h"
42 #include "nsc.h"
43 #include "mission.h"
44 #include "ship.h"
45 #include "combat.h"
46 #include "retreat.h"
47 #include "commands.h"
48
49 int
50 boar(void)
51 {
52     struct combat off[1];       /* boarding ship or sector */
53     struct combat def[1];       /* defending ship */
54     struct emp_qelem olist;     /* boarding units */
55     struct emp_qelem dlist;     /* defending units */
56     int ototal;                 /* total boarding strength */
57     int a_engineer = 0;         /* boarder engineers are present */
58     int a_spy = 0;              /* the best boarder scout */
59     struct shpstr ship;         /* for retreating */
60     struct sctstr sect;
61     struct lndstr land;
62     struct nstr_item ni;
63     int foundland;
64     s_char *p;
65     s_char buf[1024];
66
67     att_combat_init(def, EF_SHIP);
68     /*
69      * Collect input from the boarder
70      */
71
72     /* What are we boarding? */
73
74     if (!(p = getstarg(player->argp[1], "Victim ship #?  ", buf)) ||
75         (def->shp_uid = atoi(p)) < 0)
76         return RET_SYN;
77
78     /*
79      * Ask the boarder what he wants to board with
80      */
81
82     if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
83         return RET_SYN;
84     if (issector(p)) {
85         att_combat_init(off, EF_SECTOR);
86         if (!sarg_xy(p, &off->x, &off->y))
87             return RET_SYN;
88         getsect(off->x, off->y, &sect);
89         if (sect.sct_own != player->cnum) {
90             pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
91             return RET_SYN;
92         }
93         if (sect.sct_mobil <= 0) {
94             /* Look for land units with mobility */
95             snxtitem_xy(&ni, EF_LAND, off->x, off->y);
96             foundland = 0;
97             while (nxtitem(&ni, (s_char *)&land)) {
98                 if (land.lnd_own != player->cnum)
99                     continue;
100                 if (land.lnd_ship >= 0)
101                     continue;
102                 if (land.lnd_mobil <= 0)
103                     continue;
104                 /* Only land units with assault can board */
105                 if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT))
106                     continue;
107                 foundland = 1;
108             }
109             if (!foundland) {
110                 pr("You don't have any mobility (sector or land units) in %s!\n", xyas(off->x, off->y, player->cnum));
111                 return RET_SYN;
112             }
113         }
114     } else {
115         att_combat_init(off, EF_SHIP);
116         if ((off->shp_uid = atoi(p)) < 0)
117             return RET_SYN;
118     }
119     if (att_abort(A_BOARD, off, def)) {
120         pr("Board aborted\n");
121         return RET_OK;
122     }
123
124     /* Fire at the attacking ship */
125
126     att_approach(off, def);
127     if (att_abort(A_BOARD, off, def)) {
128         pr("Board aborted\n");
129         att_empty_attack(A_BOARD, 0, def);
130         return RET_OK;
131     }
132
133     /* Show what we're boarding, and check treaties */
134
135     if (att_show(def))
136         return RET_FAIL;
137
138     /* Ask the player what he wants to board with */
139
140     att_ask_offense(A_BOARD, off, def, &olist, &a_spy, &a_engineer);
141     if (att_abort(A_BOARD, off, def)) {
142         pr("Board aborted\n");
143         att_empty_attack(A_BOARD, 0, def);
144         return att_free_lists(&olist, 0);
145     }
146
147     /*
148      * Estimate the defense strength and give the player a chance to abort
149      */
150
151     ototal = att_estimate_defense(A_BOARD, off, &olist, def, a_spy);
152     if (att_abort(A_BOARD, off, def)) {
153         pr("Board aborted\n");
154         att_empty_attack(A_BOARD, 0, def);
155         return att_free_lists(&olist, 0);
156     }
157
158     /*
159      * We have now got all the answers from the boarder.  From this point
160      * forward, we can assume that this battle is the _only_ thing
161      * happening in the game.
162      */
163
164     /* Get the real defense */
165
166     att_get_defense(&olist, def, &dlist, a_spy, ototal);
167
168     /*
169      * Death, carnage, and destruction.
170      */
171
172     if (!(att_fight(A_BOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
173         getship(def->shp_uid, &ship);
174         if (ship.shp_rflags & RET_BOARDED) {
175             retreat_ship(&ship, 'u');
176             putship(def->shp_uid, &ship);
177         }
178     }
179
180     return RET_OK;
181 }