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
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:
53 int isfleet = 0, rflags = (-2), zero;
58 if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
61 if (player->argp[1] != (s_char *)0)
62 if (isalpha(player->argp[1][0]))
64 if (player->argp[2] != (s_char *)0)
65 pq = getstarg(player->argp[2], "Retreat path? ", buf1);
69 if (pq != (s_char *)0) {
70 fl = getstarg(player->argp[3],
71 "Retreat conditions [i|t|s|h|b|d|u|c]? ", buf2);
76 for (x = 0; x < strlen(fl); x++)
80 rflags |= RET_INJURED;
88 rflags |= RET_SONARED;
92 rflags |= RET_HELPLESS;
100 rflags |= RET_DCHRGED;
104 rflags |= RET_BOARDED;
111 pr("bad condition\n");
114 pr("i\tretreat when injured\n");
115 pr("t\tretreat when torped\n");
116 pr("s\tretreat when sonared\n");
117 pr("h\tretreat when helpless\n");
118 pr("b\tretreat when bombed\n");
119 pr("d\tretreat when depth-charged\n");
120 pr("u\tretreat when boarded\n");
122 if (rflags == isfleet) {
123 pr("Must give retreat conditions!\n");
131 zero = (rflags == -1);
135 while (nxtitem(&ni, (s_char *)&ship)) {
136 if (!player->owner || ship.shp_own == 0)
138 if (ship.shp_type < 0 || ship.shp_type > shp_maxno) {
139 pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur);
143 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
145 if (pq != (s_char *)0) {
146 strncpy(ship.shp_rpath, pq, sizeof(ship.shp_rpath));
147 putship(ship.shp_uid, &ship);
150 ship.shp_rflags = rflags;
151 putship(ship.shp_uid, &ship);
156 pr("shp# ship type x,y fl path as flt? flags\n");
159 pr("%3d ", ship.shp_own);
161 pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
162 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
163 pr("%1c", ship.shp_fleet);
164 pr(" %-11s", ship.shp_rpath);
165 if (ship.shp_rflags & RET_GROUP)
169 if (ship.shp_rflags & RET_INJURED)
171 if (ship.shp_rflags & RET_TORPED)
173 if (ship.shp_rflags & RET_SONARED)
175 if (ship.shp_rflags & RET_HELPLESS)
177 if (ship.shp_rflags & RET_BOMBED)
179 if (ship.shp_rflags & RET_DCHRGED)
181 if (ship.shp_rflags & RET_BOARDED)
187 pr("%s: No ship(s)\n", player->argp[1]);
189 pr("%s: No ship(s)\n", "");
192 pr("%d ship%s\n", nships, splur(nships));
203 int isarmy = 0, rflags = (-2), zero;
208 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
211 if (player->argp[1] != (s_char *)0)
212 if (isalpha(player->argp[1][0]))
214 if (player->argp[2] != (s_char *)0)
215 pq = getstarg(player->argp[2], "Retreat path? ", buf1);
218 if (pq != (s_char *)0) {
219 fl = getstarg(player->argp[3], "Retreat conditions [i|h|b|c]? ",
225 for (x = 0; x < strlen(fl); x++)
229 rflags |= RET_INJURED;
233 rflags |= RET_HELPLESS;
237 rflags |= RET_BOMBED;
244 pr("bad condition\n");
247 pr("i\tretreat when injured\n");
248 pr("h\tretreat when helpless\n");
249 pr("b\tretreat when bombed\n");
251 if (rflags == isarmy) {
252 pr("Must give retreat conditions!\n");
260 zero = (rflags == -1);
264 while (nxtitem(&ni, (s_char *)&land)) {
265 if (!player->owner || land.lnd_own == 0)
267 if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) {
268 pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur);
272 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
274 if (pq != (s_char *)0) {
275 strncpy(land.lnd_rpath, pq, sizeof(land.lnd_rpath));
276 putland(land.lnd_uid, &land);
279 land.lnd_rflags = rflags;
280 putland(land.lnd_uid, &land);
286 pr("lnd# unit type x,y ar path as army? flags\n");
289 pr("%3d ", land.lnd_own);
291 pr("%-16.16s ", lchr[(int)land.lnd_type].l_name);
292 prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum);
293 pr("%1c", land.lnd_army);
294 pr(" %-11s", land.lnd_rpath);
295 if (land.lnd_rflags & RET_GROUP)
299 if (land.lnd_rflags & RET_INJURED)
301 if (land.lnd_rflags & RET_TORPED)
303 if (land.lnd_rflags & RET_SONARED)
305 if (land.lnd_rflags & RET_HELPLESS)
307 if (land.lnd_rflags & RET_BOMBED)
309 if (land.lnd_rflags & RET_DCHRGED)
311 if (land.lnd_rflags & RET_BOARDED)
317 pr("%s: No unit(s)\n", player->argp[1]);
319 pr("%s: No unit(s)\n", "");
322 pr("%d unit%s\n", nunits, splur(nunits));