2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * retr.c: Set retreat conditionals for ships and land units
29 * Known contributors to this file:
32 * Markus Armbruster, 2008-2014
46 * Retreat flag characters
47 * 'X' means flag is not available
48 * Must agree with RET_ defines.
50 static char shp_rflagsc[] = "Xitshbdu";
51 static char lnd_rflagsc[] = "XiXXhbXX";
53 static int retreat(int);
58 return retreat(EF_SHIP);
64 return retreat(EF_LAND);
73 union empobj_storage unit;
75 char *rflagsc, *p, *name, *rpath, *what;
80 if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
82 rflagsc = type == EF_SHIP ? shp_rflagsc : lnd_rflagsc;
84 if (!snxtitem(&ni, type, player->argp[1], NULL))
87 if (player->argp[2] != NULL) {
88 pq = getstarg(player->argp[2], "Retreat path? ", buf1);
91 for (i = 0; i < RET_LEN - 1 && pq[i]; i++) {
92 if (chkdir(pq[i], DIR_STOP, DIR_LAST) < 0) {
93 pr("'%c' is not a valid direction...\n", pq[i]);
94 direrr(NULL, NULL, NULL);
98 for (i--; i >= 0 && pq[i] == dirch[DIR_STOP]; i--)
106 fl = getstarg(player->argp[3],
107 "Retreat conditions ('?' to list available ones)? ",
112 for (i = 0; fl[i]; i++) {
118 if (ch == '?' && !player->argp[3]) {
119 for (j = 1; rflagsc[j]; j++) {
120 if (rflagsc[j] != 'X')
121 pr("%c\tretreat when %s\n",
123 symbol_by_value(1 << j, retreat_flags));
125 pr("c\tcancel retreat order\n");
128 p = strchr(rflagsc, ch);
130 pr("Bad retreat condition '%c'\n", fl[i]);
133 rflags |= 1 << (p - rflagsc);
137 if (ni.sel == NS_GROUP && ni.group)
143 while (nxtitem(&ni, &unit)) {
144 if (!player->owner || unit.gen.own == 0)
146 if (type == EF_SHIP) {
150 pr("shp# ship type x,y fl path as flt? flags\n");
152 name = mchr[unit.ship.shp_type].m_name;
153 rpath = unit.ship.shp_rpath;
154 rflagsp = &unit.ship.shp_rflags;
159 pr("lnd# unit type x,y ar path as army? flags\n");
161 name = lchr[unit.land.lnd_type].l_name;
162 rpath = unit.land.lnd_rpath;
163 rflagsp = &unit.land.lnd_rflags;
166 strncpy(rpath, pq, RET_LEN - 1);
168 put_empobj(type, unit.gen.uid, &unit);
171 pr("%3d ", unit.gen.own);
173 pr("%-16.16s ", name);
174 prxy("%4d,%-4d ", unit.gen.x, unit.gen.y);
175 pr("%1.1s", &unit.gen.group);
178 if (rflags & RET_GROUP)
182 for (j = 1; rflagsc[j]; j++) {
183 if ((1 << j) & rflags) {
184 if (CANT_HAPPEN(rflagsc[j] == 'X'))
186 pr("%c", rflagsc[j]);
191 what = type == EF_SHIP ? "ship" : "unit";
194 pr("%s: No %s(s)\n", player->argp[1], what);
196 pr("%s: No %s(s)\n", "", what);
199 pr("%d %s%s\n", nunits, what, splur(nunits));