2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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
43 static int clear_mission(struct nstr_item *);
44 static int show_mission(struct nstr_item *);
47 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
52 static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
57 int desired_radius, radius;
58 union empobj_storage item;
60 int num = 0, mobmax, mobused;
65 getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
68 type = ef_byname_from(p, ef_with_missions);
70 pr("Ships, land units or planes only! (s, l, p)\n");
73 if (!snxtitem(&ni, type, player->argp[2], NULL))
77 getstarg(player->argp[3],
78 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
86 * 'd' support defenders
88 * 'r' defensive reserve
89 * 'a' air defense (intercepts)
94 mission = MI_INTERDICT;
98 mission = MI_OSUPPORT;
102 mission = MI_DSUPPORT;
106 mission = MI_SUPPORT;
110 return clear_mission(&ni);
117 mission = MI_RESERVE;
121 mission = MI_AIR_DEFENSE;
124 return show_mission(&ni);
126 pr("bad condition\n");
127 pr("i\tinterdiction (any)\n");
128 pr("s\tsupport (tactical planes only)\n");
129 pr("o\toffensive support (tactical planes only)\n");
130 pr("d\tdefensive support (tactical planes only)\n");
131 pr("r\treserve (land units only)\n");
132 pr("e\tescort (tactical or escort planes only)\n");
133 pr("a\tair defense (intercept planes only)\n");
134 pr("c\tclear mission\n");
139 if (!cando(mission, type)) {
140 pr("A %s cannot do that mission!\n", ef_nameof(type));
141 pr("i\tinterdiction (any)\n");
142 pr("s\tsupport (planes only)\n");
143 pr("o\toffensive support (planes only)\n");
144 pr("d\tdefensive support (planes only)\n");
145 pr("r\treserve (land units only)\n");
146 pr("e\tescort (planes only)\n");
147 pr("a\tair defense (planes only)\n");
151 if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
156 if (!sarg_xy(p, &x, &y))
160 if (player->argp[5] != NULL) {
161 desired_radius = atoi(player->argp[5]);
162 if (desired_radius < 0) {
163 pr("Radius must be greater than zero!\n");
167 desired_radius = 9999;
170 if ((mobmax = get_empobj_mob_max(type)) == -1)
173 mobused = ldround(mission_mob_cost * (double)mobmax, 1);
175 while (nxtitem(&ni, &item)) {
176 gp = (struct empobj *)&item;
178 if (!player->owner || gp->own == 0)
181 if (gp->mobil < mobused && mission_mob_cost) {
182 pr("%s: not enough mobility! (needs %d)\n",
183 obj_nameof(gp), mobused);
186 if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
187 pr("%s is not designed to fight ground troops\n",
196 radius = oprange(gp, mission);
197 if (radius < mapdist(gp->x, gp->y, x, y)) {
198 pr("%s: out of range! (range %d)\n",
199 obj_nameof(gp), radius);
203 if (radius > desired_radius)
204 radius = desired_radius;
206 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
207 if (mchr[(int)gp->type].m_glim == 0) {
208 pr("%s: cannot fire at range!\n", obj_nameof(gp));
212 if ((mission == MI_INTERDICT) && (type == EF_LAND))
213 if (lchr[(int)gp->type].l_dam == 0) {
214 pr("%s: cannot fire at range!\n", obj_nameof(gp));
218 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
219 struct plchrstr *pcp;
221 pcp = &plchr[(int)gp->type];
222 if (!(pcp->pl_flags & P_T)) {
223 pr("Only planes with the tactical ability can interdict.\n"
224 "%s #%d is ineligible\n",
225 pcp->pl_name, gp->uid);
230 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
231 struct plchrstr *pcp;
233 pcp = &plchr[(int)gp->type];
234 if (!(pcp->pl_flags & P_F)) {
235 pr("Only planes with the intercept abilities can perform air defense.\n"
236 "%s #%d is ineligible\n",
237 pcp->pl_name, gp->uid);
242 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
243 struct plchrstr *pcp;
245 pcp = &plchr[(int)gp->type];
246 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
247 pr("Only planes with the escort or intercept abilities can escort.\n"
248 "%s #%d is ineligible\n",
249 pcp->pl_name, gp->uid);
254 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
255 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
256 struct plchrstr *pcp;
258 pcp = &plchr[(int)gp->type];
259 if (!(pcp->pl_flags & P_T)) {
260 pr("Only planes with the tactical ability can support.\n"
261 "%s #%d is ineligible\n",
262 pcp->pl_name, gp->uid);
267 num++; /* good one.. go with it */
269 pr("%s on %s mission, centered on %s, radius %d\n",
270 obj_nameof(gp), mission_name(mission),
271 xyas(x, y, player->cnum), radius);
272 gp->mobil -= mobused;
274 gp->mission = mission;
278 put_empobj(type, gp->uid, gp);
281 pr("No %s%s\n", ef_nameof(type), splur(num));
284 pr("%d %s%s\n", num, ef_nameof(type), splur(num));
289 clear_mission(struct nstr_item *np)
291 union empobj_storage item;
293 while (nxtitem(np, &item)) {
294 item.gen.mission = 0;
295 put_empobj(item.gen.ef_type, item.gen.uid, &item);
302 show_mission(struct nstr_item *np)
305 union empobj_storage item;
308 while (nxtitem(np, &item)) {
309 gp = (struct empobj *)&item;
310 if (!player->owner || gp->own == 0)
314 pr("Thing x,y op-sect rad mission\n");
317 pr("%-25s", obj_nameof(gp));
318 prxy(" %3d,%-3d", gp->x, gp->y, player->cnum);
319 switch (gp->mission) {
327 prxy(" %3d,%-3d", gp->opx, gp->opy, player->cnum);
328 pr(" %4d", gp->radius);
337 pr(" is on %s mission\n", mission_name(gp->mission));
339 pr(" has no mission.\n");