2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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:
58 int isfleet=0, rflags=(-2),zero;
63 if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
66 if (player->argp[1] != (s_char *)0)
67 if (isalpha(player->argp[1][0]))
69 if (player->argp[2] != (s_char *)0)
70 pq = getstarg(player->argp[2], "Retreat path? ", buf1);
74 if (pq != (s_char *)0){
75 fl = getstarg(player->argp[3], "Retreat conditions [i|t|s|h|b|d|u|c]? ", buf2);
80 for(x=0;x<strlen(fl);x++)
83 case 'i': rflags |= RET_INJURED ; break;
85 case 't': rflags |= RET_TORPED ; break;
87 case 's': rflags |= RET_SONARED ; break;
89 case 'h': rflags |= RET_HELPLESS ; break;
91 case 'b': rflags |= RET_BOMBED ; break;
93 case 'd': rflags |= RET_DCHRGED ; break;
95 case 'u': rflags |= RET_BOARDED ; break;
97 case 'c': rflags = -1; break;
98 default: pr("bad condition\n");
99 case '?': pr("i\tretreat when injured\n");
100 pr("t\tretreat when torped\n");
101 pr("s\tretreat when sonared\n");
102 pr("h\tretreat when helpless\n");
103 pr("b\tretreat when bombed\n");
104 pr("d\tretreat when depth-charged\n");
105 pr("u\tretreat when boarded\n");
107 if (rflags == isfleet){
108 pr("Must give retreat conditions!\n");
116 zero = (rflags == -1);
120 while (nxtitem(&ni, (s_char *)&ship)) {
121 if (!player->owner || ship.shp_own == 0)
123 if (ship.shp_type < 0 || ship.shp_type > shp_maxno) {
124 pr("bad ship type %d (#%d)\n",
125 ship.shp_type, ni.cur);
129 bzero(ship.shp_rpath,RET_LEN);
131 if (pq != (s_char *)0){
132 bzero(ship.shp_rpath,RET_LEN);
133 bcopy(pq,ship.shp_rpath,strlen(pq));
134 putship(ship.shp_uid,&ship);
137 ship.shp_rflags = rflags;
138 putship(ship.shp_uid,&ship);
143 pr("shp# ship type x,y fl path as flt? flags\n");
146 pr("%3d ", ship.shp_own);
148 pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
149 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
150 pr("%1c", ship.shp_fleet);
151 pr(" %-11s", ship.shp_rpath);
152 if (ship.shp_rflags & RET_GROUP)
156 if (ship.shp_rflags & RET_INJURED)
158 if (ship.shp_rflags & RET_TORPED)
160 if (ship.shp_rflags & RET_SONARED)
162 if (ship.shp_rflags & RET_HELPLESS)
164 if (ship.shp_rflags & RET_BOMBED)
166 if (ship.shp_rflags & RET_DCHRGED)
168 if (ship.shp_rflags & RET_BOARDED)
174 pr("%s: No ship(s)\n", player->argp[1]);
176 pr("%s: No ship(s)\n", "");
179 pr("%d ship%s\n", nships, splur(nships));
190 int isarmy=0, rflags=(-2),zero;
195 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
198 if (player->argp[1] != (s_char *)0)
199 if (isalpha(player->argp[1][0]))
201 if (player->argp[2] != (s_char *)0)
202 pq = getstarg(player->argp[2], "Retreat path? ", buf1);
205 if (pq != (s_char *)0){
206 fl = getstarg(player->argp[3], "Retreat conditions [i|h|b|c]? ", buf2);
211 for(x=0;x<strlen(fl);x++)
214 case 'i': rflags |= RET_INJURED ; break;
216 case 'h': rflags |= RET_HELPLESS ; break;
218 case 'b': rflags |= RET_BOMBED ; break;
220 case 'c': rflags = -1; break;
221 default: pr("bad condition\n");
222 case '?': pr("i\tretreat when injured\n");
223 pr("h\tretreat when helpless\n");
224 pr("b\tretreat when bombed\n");
226 if (rflags == isarmy){
227 pr("Must give retreat conditions!\n");
235 zero = (rflags == -1);
239 while (nxtitem(&ni, (s_char *)&land)) {
240 if (!player->owner || land.lnd_own == 0)
242 if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) {
243 pr("bad unit type %d (#%d)\n",
244 land.lnd_type, ni.cur);
248 bzero(land.lnd_rpath,RET_LEN);
250 if (pq != (s_char *)0){
251 bzero(land.lnd_rpath,RET_LEN);
252 bcopy(pq,land.lnd_rpath,strlen(pq));
253 putland(land.lnd_uid,&land);
256 land.lnd_rflags = rflags;
257 putland(land.lnd_uid,&land);
263 pr("lnd# unit type x,y ar path as army? flags\n");
266 pr("%3d ", land.lnd_own);
268 pr("%-16.16s ", lchr[(int)land.lnd_type].l_name);
269 prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum);
270 pr("%1c", land.lnd_army);
271 pr(" %-11s", land.lnd_rpath);
272 if (land.lnd_rflags & RET_GROUP)
276 if (land.lnd_rflags & RET_INJURED)
278 if (land.lnd_rflags & RET_TORPED)
280 if (land.lnd_rflags & RET_SONARED)
282 if (land.lnd_rflags & RET_HELPLESS)
284 if (land.lnd_rflags & RET_BOMBED)
286 if (land.lnd_rflags & RET_DCHRGED)
288 if (land.lnd_rflags & RET_BOARDED)
294 pr("%s: No unit(s)\n", player->argp[1]);
296 pr("%s: No unit(s)\n", "");
299 pr("%d unit%s\n", nunits, splur(nunits));