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
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 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.
28 * retr.c: Set retreat conditionals for ships and land units
30 * Known contributors to this file:
33 * Markus Armbruster, 2008
47 * Retreat flag characters
48 * 'X' means flag is not available
49 * Must agree with RET_ defines.
51 static char shp_rflagsc[] = "Xitshbdu";
52 static char lnd_rflagsc[] = "XiXXhbXX";
54 static int retreat(short);
59 return retreat(EF_SHIP);
65 return retreat(EF_LAND);
74 union empobj_storage unit;
77 char *rflagsc, *p, *name, *rpath, *what;
82 if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
84 rflagsc = type == EF_SHIP ? shp_rflagsc : lnd_rflagsc;
86 if (!snxtitem(&ni, type, player->argp[1], NULL))
89 if (player->argp[2] != NULL)
90 pq = getstarg(player->argp[2], "Retreat path? ", buf1);
97 fl = getstarg(player->argp[3],
98 "Retreat conditions ('?' to list available ones)? ",
103 for (i = 0; fl[i]; i++) {
110 for (j = 1; rflagsc[j]; j++) {
111 if (rflagsc[j] != 'X')
112 pr("%c\tretreat when %s\n",
114 symbol_by_value(1 << j, retreat_flags));
116 pr("c\tcancel retreat order\n");
119 p = strchr(rflagsc, ch);
121 pr("Bad retreat condition '%c'\n", fl[i]);
124 rflags |= 1 << (p - rflagsc);
126 if (*pq && !rflags) {
127 pr("Must give retreat conditions!\n");
130 if (ni.sel == NS_GROUP && ni.group)
136 while (nxtitem(&ni, &unit)) {
137 if (!player->owner || unit.gen.own == 0)
139 if (type == EF_SHIP) {
143 pr("shp# ship type x,y fl path as flt? flags\n");
145 name = mchr[unit.ship.shp_type].m_name;
146 rpath = unit.ship.shp_rpath;
147 rflagsp = &unit.ship.shp_rflags;
152 pr("lnd# unit type x,y ar path as army? flags\n");
154 name = lchr[unit.land.lnd_type].l_name;
155 rpath = unit.land.lnd_rpath;
156 rflagsp = &unit.land.lnd_rflags;
159 strncpy(rpath, pq, RET_LEN - 1);
161 put_empobj(type, unit.gen.uid, &unit);
164 pr("%3d ", unit.gen.own);
166 pr("%-16.16s ", name);
167 prxy("%4d,%-4d ", unit.gen.x, unit.gen.y, player->cnum);
168 pr("%1.1s", &unit.gen.group);
171 if (rflags & RET_GROUP)
175 for (j = 1; rflagsc[j]; j++) {
176 if ((1 << j) & rflags) {
177 if (CANT_HAPPEN(rflagsc[j] == 'X'))
179 pr("%c", rflagsc[j]);
184 what = type == EF_SHIP ? "ship" : "unit";
187 pr("%s: No %s(s)\n", player->argp[1], what);
189 pr("%s: No %s(s)\n", "", what);
192 pr("%d %s%s\n", nunits, what, splur(nunits));