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 * miss.c: set missions for ships/planes/units
30 * Known contributors to this file:
31 * Thomas Ruschak, 1992
33 * Markus Armbruster, 2005-2009
44 static int clear_mission(struct nstr_item *);
45 static int show_mission(struct nstr_item *);
48 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
53 static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
59 union empobj_storage item;
65 p = getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
69 type = ef_byname_from(p, ef_with_missions);
71 pr("Ships, land units or planes only! (s, l, p)\n");
74 if (!snxtitem(&ni, type, player->argp[2], NULL))
77 p = getstarg(player->argp[3],
78 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
87 * 'd' support defenders
89 * 'r' defensive reserve
90 * 'a' air defense (intercepts)
95 mission = MI_INTERDICT;
99 mission = MI_OSUPPORT;
103 mission = MI_DSUPPORT;
107 mission = MI_SUPPORT;
111 return clear_mission(&ni);
118 mission = MI_RESERVE;
122 mission = MI_AIR_DEFENSE;
125 return show_mission(&ni);
127 pr("bad condition\n");
128 pr("i\tinterdiction (any)\n");
129 pr("s\tsupport (tactical planes only)\n");
130 pr("o\toffensive support (tactical planes only)\n");
131 pr("d\tdefensive support (tactical planes only)\n");
132 pr("r\treserve (land units only)\n");
133 pr("e\tescort (tactical or escort planes only)\n");
134 pr("a\tair defense (intercept planes only)\n");
135 pr("c\tclear mission\n");
140 if (!cando(mission, type)) {
141 pr("A %s cannot do that mission!\n", ef_nameof(type));
142 pr("i\tinterdiction (any)\n");
143 pr("s\tsupport (planes only)\n");
144 pr("o\toffensive support (planes only)\n");
145 pr("d\tdefensive support (planes only)\n");
146 pr("r\treserve (land units only)\n");
147 pr("e\tescort (planes only)\n");
148 pr("a\tair defense (planes only)\n");
152 p = getstarg(player->argp[4], "operations point? ", buf);
157 if (!sarg_xy(p, &x, &y))
161 if (player->argp[5] != NULL) {
162 radius = atoi(player->argp[5]);
164 pr("Radius can't be negative!\n");
170 while (nxtitem(&ni, &item)) {
171 gp = (struct empobj *)&item;
173 if (!player->owner || gp->own == 0)
176 if (mission == MI_RESERVE) {
177 if (!lnd_can_attack((struct lndstr *)gp)) {
178 pr("%s is not designed to fight ground troops\n",
182 if (!lchr[gp->type].l_rad) {
183 pr("%s cannot react anywhere!\n", obj_nameof(gp));
188 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
189 if (mchr[(int)gp->type].m_glim == 0) {
190 pr("%s: cannot fire at range!\n", obj_nameof(gp));
194 if ((mission == MI_INTERDICT) && (type == EF_LAND))
195 if (lchr[(int)gp->type].l_dam == 0) {
196 pr("%s: cannot fire at range!\n", obj_nameof(gp));
200 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
201 struct plchrstr *pcp;
203 pcp = &plchr[(int)gp->type];
204 if (!(pcp->pl_flags & P_T)) {
205 pr("Only planes with the tactical ability can interdict.\n"
206 "%s #%d is ineligible\n",
207 pcp->pl_name, gp->uid);
212 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
213 struct plchrstr *pcp;
215 pcp = &plchr[(int)gp->type];
216 if (!(pcp->pl_flags & P_F)) {
217 pr("Only planes with the intercept abilities can perform air defense.\n"
218 "%s #%d is ineligible\n",
219 pcp->pl_name, gp->uid);
224 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
225 struct plchrstr *pcp;
227 pcp = &plchr[(int)gp->type];
228 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
229 pr("Only planes with the escort or intercept abilities can escort.\n"
230 "%s #%d is ineligible\n",
231 pcp->pl_name, gp->uid);
236 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
237 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
238 struct plchrstr *pcp;
240 pcp = &plchr[(int)gp->type];
241 if (!(pcp->pl_flags & P_T)) {
242 pr("Only planes with the tactical ability can support.\n"
243 "%s #%d is ineligible\n",
244 pcp->pl_name, gp->uid);
249 if (type == EF_PLANE && nuk_on_plane((struct plnstr *)gp) >= 0) {
250 pr("%s can't perform a mission while it carries a nuclear weapon",
260 gp->mission = mission;
262 if (range < mapdist(gp->x, gp->y, x, y)) {
263 pr("%s: out of range! (range %d)\n",
264 obj_nameof(gp), range);
269 gp->radius = MIN(range, radius);
270 put_empobj(type, gp->uid, gp);
273 pr("%s on %s mission, centered on %s, radius %d\n",
274 obj_nameof(gp), mission_name(mission),
275 xyas(x, y, player->cnum), gp->radius);
278 pr("No %s%s\n", ef_nameof(type), splur(num));
281 pr("%d %s%s\n", num, ef_nameof(type), splur(num));
286 clear_mission(struct nstr_item *np)
288 union empobj_storage item;
290 while (nxtitem(np, &item)) {
291 item.gen.mission = 0;
292 put_empobj(item.gen.ef_type, item.gen.uid, &item);
299 show_mission(struct nstr_item *np)
302 union empobj_storage item;
305 while (nxtitem(np, &item)) {
306 gp = (struct empobj *)&item;
307 if (!player->owner || gp->own == 0)
311 pr("Thing x,y op-sect rad mission\n");
314 pr("%-25s", obj_nameof(gp));
315 prxy(" %3d,%-3d", gp->x, gp->y, player->cnum);
316 switch (gp->mission) {
324 prxy(" %3d,%-3d", gp->opx, gp->opy, player->cnum);
325 pr(" %4d", gp->radius);
334 pr(" is on %s mission\n", mission_name(gp->mission));
336 pr(" has no mission.\n");