2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2018, 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 * miss.c: set missions for ships/planes/units
29 * Known contributors to this file:
30 * Thomas Ruschak, 1992
32 * Markus Armbruster, 2005-2016
41 static int clear_mission(struct nstr_item *);
42 static int show_mission(struct nstr_item *);
45 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
50 static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
56 union empobj_storage item;
62 p = getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
66 type = ef_byname_from(p, ef_with_missions);
68 pr("Ships, land units or planes only! (s, l, p)\n");
71 if (!snxtitem(&ni, type, player->argp[2], NULL))
74 p = getstarg(player->argp[3],
75 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
84 * 'd' support defenders
86 * 'r' defensive reserve
87 * 'a' air defense (intercepts)
92 mission = MI_INTERDICT;
96 mission = MI_OSUPPORT;
100 mission = MI_DSUPPORT;
104 mission = MI_SUPPORT;
108 return clear_mission(&ni);
115 mission = MI_RESERVE;
119 mission = MI_AIR_DEFENSE;
122 return show_mission(&ni);
124 pr("bad condition\n");
125 pr("i\tinterdiction (any)\n");
126 pr("s\tsupport (tactical planes only)\n");
127 pr("o\toffensive support (tactical planes only)\n");
128 pr("d\tdefensive support (tactical planes only)\n");
129 pr("r\treserve (land units only)\n");
130 pr("e\tescort (tactical or escort planes only)\n");
131 pr("a\tair defense (intercept planes only)\n");
132 pr("c\tclear mission\n");
137 if (!cando(mission, type)) {
138 pr("A %s cannot do that mission!\n", ef_nameof(type));
139 pr("i\tinterdiction (any)\n");
140 pr("s\tsupport (planes only)\n");
141 pr("o\toffensive support (planes only)\n");
142 pr("d\tdefensive support (planes only)\n");
143 pr("r\treserve (land units only)\n");
144 pr("e\tescort (planes only)\n");
145 pr("a\tair defense (planes only)\n");
149 p = getstarg(player->argp[4], "operations point? ", buf);
154 if (!sarg_xy(p, &x, &y))
158 if (player->argp[5] != NULL) {
159 radius = atoi(player->argp[5]);
161 pr("Radius can't be negative!\n");
167 while (nxtitem(&ni, &item)) {
170 if (!player->owner || gp->own == 0)
173 if (mission == MI_RESERVE) {
174 if (!lnd_can_attack((struct lndstr *)gp)) {
175 pr("%s is not designed to fight ground troops\n",
179 if (!lchr[gp->type].l_rad) {
180 pr("%s cannot react anywhere!\n", unit_nameof(gp));
185 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
186 if (mchr[(int)gp->type].m_glim == 0) {
187 pr("%s: cannot fire at range!\n", unit_nameof(gp));
191 if ((mission == MI_INTERDICT) && (type == EF_LAND))
192 if (lchr[(int)gp->type].l_dam == 0) {
193 pr("%s: cannot fire at range!\n", unit_nameof(gp));
197 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
198 struct plchrstr *pcp;
200 pcp = &plchr[(int)gp->type];
201 if (!(pcp->pl_flags & P_T)) {
202 pr("Only planes with the tactical ability can interdict.\n"
203 "%s #%d is ineligible\n",
204 pcp->pl_name, gp->uid);
209 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
210 struct plchrstr *pcp;
212 pcp = &plchr[(int)gp->type];
213 if (!(pcp->pl_flags & P_F)) {
214 pr("Only planes with the intercept abilities can perform air defense.\n"
215 "%s #%d is ineligible\n",
216 pcp->pl_name, gp->uid);
221 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
222 struct plchrstr *pcp;
224 pcp = &plchr[(int)gp->type];
225 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
226 pr("Only planes with the escort or intercept abilities can escort.\n"
227 "%s #%d is ineligible\n",
228 pcp->pl_name, gp->uid);
233 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
234 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
235 struct plchrstr *pcp;
237 pcp = &plchr[(int)gp->type];
238 if (!(pcp->pl_flags & P_T)) {
239 pr("Only planes with the tactical ability can support.\n"
240 "%s #%d is ineligible\n",
241 pcp->pl_name, gp->uid);
246 if (type == EF_PLANE && nuk_on_plane((struct plnstr *)gp) >= 0) {
247 pr("%s can't perform a mission"
248 " while it is carrying a nuclear weapon\n",
258 gp->mission = mission;
260 if (range < mapdist(gp->x, gp->y, x, y)) {
261 pr("%s: out of range! (range %d)\n",
262 unit_nameof(gp), range);
267 gp->radius = MIN(range, radius);
268 put_empobj(type, gp->uid, gp);
271 pr("%s on %s mission, centered on %s, radius %d\n",
272 unit_nameof(gp), mission_name(mission),
273 xyas(x, y, player->cnum), gp->radius);
276 pr("No %s%s\n", ef_nameof(type), splur(num));
279 pr("%d %s%s\n", num, ef_nameof(type), splur(num));
284 clear_mission(struct nstr_item *np)
286 union empobj_storage item;
288 while (nxtitem(np, &item)) {
289 item.gen.mission = 0;
290 put_empobj(item.gen.ef_type, item.gen.uid, &item);
297 show_mission(struct nstr_item *np)
300 union empobj_storage item;
303 while (nxtitem(np, &item)) {
305 if (!player->owner || gp->own == 0)
309 pr("Thing x,y op-sect rad mission\n");
312 pr("%-25s", unit_nameof(gp));
313 prxy(" %4d,%-4d", gp->x, gp->y);
314 switch (gp->mission) {
322 prxy(" %4d,%-4d", gp->opx, gp->opy);
323 pr(" %3d", gp->radius);
332 pr(" is on %s mission\n", mission_name(gp->mission));
334 pr(" has no mission.\n");