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 * retr.c: Set retreat conditionals for ships
30 * Known contributors to this file:
57 int isfleet = 0, rflags = (-2), zero;
62 if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
65 if (player->argp[1] != (s_char *)0)
66 if (isalpha(player->argp[1][0]))
68 if (player->argp[2] != (s_char *)0)
69 pq = getstarg(player->argp[2], "Retreat path? ", buf1);
73 if (pq != (s_char *)0) {
74 fl = getstarg(player->argp[3],
75 "Retreat conditions [i|t|s|h|b|d|u|c]? ", buf2);
80 for (x = 0; x < strlen(fl); x++)
84 rflags |= RET_INJURED;
92 rflags |= RET_SONARED;
96 rflags |= RET_HELPLESS;
100 rflags |= RET_BOMBED;
104 rflags |= RET_DCHRGED;
108 rflags |= RET_BOARDED;
115 pr("bad condition\n");
118 pr("i\tretreat when injured\n");
119 pr("t\tretreat when torped\n");
120 pr("s\tretreat when sonared\n");
121 pr("h\tretreat when helpless\n");
122 pr("b\tretreat when bombed\n");
123 pr("d\tretreat when depth-charged\n");
124 pr("u\tretreat when boarded\n");
126 if (rflags == isfleet) {
127 pr("Must give retreat conditions!\n");
135 zero = (rflags == -1);
139 while (nxtitem(&ni, (s_char *)&ship)) {
140 if (!player->owner || ship.shp_own == 0)
142 if (ship.shp_type < 0 || ship.shp_type > shp_maxno) {
143 pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur);
147 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
149 if (pq != (s_char *)0) {
150 strncpy(ship.shp_rpath, pq, sizeof(ship.shp_rpath));
151 putship(ship.shp_uid, &ship);
154 ship.shp_rflags = rflags;
155 putship(ship.shp_uid, &ship);
160 pr("shp# ship type x,y fl path as flt? flags\n");
163 pr("%3d ", ship.shp_own);
165 pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
166 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
167 pr("%1c", ship.shp_fleet);
168 pr(" %-11s", ship.shp_rpath);
169 if (ship.shp_rflags & RET_GROUP)
173 if (ship.shp_rflags & RET_INJURED)
175 if (ship.shp_rflags & RET_TORPED)
177 if (ship.shp_rflags & RET_SONARED)
179 if (ship.shp_rflags & RET_HELPLESS)
181 if (ship.shp_rflags & RET_BOMBED)
183 if (ship.shp_rflags & RET_DCHRGED)
185 if (ship.shp_rflags & RET_BOARDED)
191 pr("%s: No ship(s)\n", player->argp[1]);
193 pr("%s: No ship(s)\n", "");
196 pr("%d ship%s\n", nships, splur(nships));
207 int isarmy = 0, rflags = (-2), zero;
212 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
215 if (player->argp[1] != (s_char *)0)
216 if (isalpha(player->argp[1][0]))
218 if (player->argp[2] != (s_char *)0)
219 pq = getstarg(player->argp[2], "Retreat path? ", buf1);
222 if (pq != (s_char *)0) {
223 fl = getstarg(player->argp[3], "Retreat conditions [i|h|b|c]? ",
229 for (x = 0; x < strlen(fl); x++)
233 rflags |= RET_INJURED;
237 rflags |= RET_HELPLESS;
241 rflags |= RET_BOMBED;
248 pr("bad condition\n");
251 pr("i\tretreat when injured\n");
252 pr("h\tretreat when helpless\n");
253 pr("b\tretreat when bombed\n");
255 if (rflags == isarmy) {
256 pr("Must give retreat conditions!\n");
264 zero = (rflags == -1);
268 while (nxtitem(&ni, (s_char *)&land)) {
269 if (!player->owner || land.lnd_own == 0)
271 if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) {
272 pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur);
276 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
278 if (pq != (s_char *)0) {
279 strncpy(land.lnd_rpath, pq, sizeof(land.lnd_rpath));
280 putland(land.lnd_uid, &land);
283 land.lnd_rflags = rflags;
284 putland(land.lnd_uid, &land);
290 pr("lnd# unit type x,y ar path as army? flags\n");
293 pr("%3d ", land.lnd_own);
295 pr("%-16.16s ", lchr[(int)land.lnd_type].l_name);
296 prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum);
297 pr("%1c", land.lnd_army);
298 pr(" %-11s", land.lnd_rpath);
299 if (land.lnd_rflags & RET_GROUP)
303 if (land.lnd_rflags & RET_INJURED)
305 if (land.lnd_rflags & RET_TORPED)
307 if (land.lnd_rflags & RET_SONARED)
309 if (land.lnd_rflags & RET_HELPLESS)
311 if (land.lnd_rflags & RET_BOMBED)
313 if (land.lnd_rflags & RET_DCHRGED)
315 if (land.lnd_rflags & RET_BOARDED)
321 pr("%s: No unit(s)\n", player->argp[1]);
323 pr("%s: No unit(s)\n", "");
326 pr("%d unit%s\n", nunits, splur(nunits));