2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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
49 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
54 static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
59 int desired_radius, radius;
61 union empobj_storage item;
63 int num = 0, mobmax, mobused, dist;
69 getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
72 type = ef_byname_from(p, ef_with_missions);
74 pr("Ships, land units or planes only! (s, l, p)\n");
77 sprintf(prompt, "%s(s)? ", ef_nameof(type));
78 p = getstarg(player->argp[2], prompt, buf);
79 if (!snxtitem(&ni, type, p))
83 getstarg(player->argp[3],
84 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
92 * 'd' support defenders
94 * 'r' defensive reserve
95 * 'a' air defense (intercepts)
100 mission = MI_INTERDICT;
104 mission = MI_OSUPPORT;
108 mission = MI_DSUPPORT;
112 mission = MI_SUPPORT;
124 mission = MI_RESERVE;
128 mission = MI_AIR_DEFENSE;
131 show_mission(type, &ni);
134 pr("bad condition\n");
135 pr("i\tinterdiction (any)\n");
136 pr("s\tsupport (tactical planes only)\n");
137 pr("o\toffensive support (tactical planes only)\n");
138 pr("d\tdefensive support (tactical planes only)\n");
139 pr("r\treserve (land units only)\n");
140 pr("e\tescort (tactical or escort planes only)\n");
141 pr("a\tair defense (intercept planes only)\n");
142 pr("c\tclear mission\n");
147 if (mission && !cando(mission, type)) {
148 pr("A %s cannot do that mission!\n", ef_nameof(type));
149 pr("i\tinterdiction (any)\n");
150 pr("s\tsupport (planes only)\n");
151 pr("o\toffensive support (planes only)\n");
152 pr("d\tdefensive support (planes only)\n");
153 pr("r\treserve (land units only)\n");
154 pr("e\tescort (planes only)\n");
155 pr("a\tair defense (planes only)\n");
159 if (mission && ((mission != MI_RESERVE) && (mission != MI_ESCORT))) {
160 if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
165 if (!sarg_xy(p, &x, &y))
168 if (!getsect(x, y, &opsect))
176 if (player->argp[5] != NULL) {
177 desired_radius = atoi(player->argp[5]);
178 if (desired_radius < 0) {
179 pr("Radius must be greater than zero!\n");
183 desired_radius = 9999;
188 mobmax = ship_mob_max;
191 mobmax = land_mob_max;
194 mobmax = plane_mob_max;
197 CANT_HAPPEN("bad TYPE");
201 mobused = ldround(mission_mob_cost * (double)mobmax, 1);
203 while (nxtitem(&ni, &item)) {
204 gp = (struct empobj *)&item;
206 if (!player->owner || gp->own == 0)
209 if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
210 pr("%s: not enough mobility! (needs %d)\n",
211 nameofitem(gp, type), mobused);
214 if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
215 pr("%s is not designed to fight ground troops\n",
216 prland((struct lndstr *)gp));
222 if (!getsect(x, y, &opsect))
226 dist = mapdist(gp->x, gp->y, x, y);
228 if ((mission == MI_INTERDICT || mission == MI_SUPPORT ||
229 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
230 mission == MI_AIR_DEFENSE) &&
231 (oprange(gp, type, &radius) < dist)) {
232 pr("%s: out of range! (range %d)\n",
233 nameofitem(gp, type), oprange(gp, type, &radius));
237 if (radius > desired_radius)
238 radius = desired_radius;
240 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
241 if (mchr[(int)gp->type].m_frnge < 1) {
242 pr("%s: cannot fire at range!\n", nameofitem(gp, type));
246 if ((mission == MI_INTERDICT) && (type == EF_LAND))
247 if (lchr[(int)gp->type].l_frg < 1) {
248 pr("%s: cannot fire at range!\n", nameofitem(gp, type));
252 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
253 struct plchrstr *pcp;
255 pcp = &plchr[(int)gp->type];
256 if (!(pcp->pl_flags & P_T)) {
257 pr("Only planes with the tactical ability can interdict.\n"
258 "%s #%d is ineligible\n",
259 pcp->pl_name, gp->uid);
264 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
265 struct plchrstr *pcp;
267 pcp = &plchr[(int)gp->type];
268 if (!(pcp->pl_flags & P_F)) {
269 pr("Only planes with the intercept abilities can perform air defense.\n"
270 "%s #%d is ineligible\n",
271 pcp->pl_name, gp->uid);
276 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
277 struct plchrstr *pcp;
279 pcp = &plchr[(int)gp->type];
280 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
281 pr("Only planes with the escort or intercept abilities can escort.\n"
282 "%s #%d is ineligible\n",
283 pcp->pl_name, gp->uid);
288 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
289 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
290 struct plchrstr *pcp;
292 pcp = &plchr[(int)gp->type];
293 if (!(pcp->pl_flags & P_T)) {
294 pr("Only planes with the tactical ability can support.\n"
295 "%s #%d is ineligible\n",
296 pcp->pl_name, gp->uid);
301 num++; /* good one.. go with it */
303 if (mission == MI_INTERDICT || mission == MI_SUPPORT ||
304 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
305 mission == MI_AIR_DEFENSE)
310 if (mission == MI_SUPPORT || mission == MI_OSUPPORT ||
311 mission == MI_DSUPPORT || mission == MI_INTERDICT ||
312 mission == MI_AIR_DEFENSE) {
313 pr("%s on %s mission, centered on %s, radius %d\n",
314 nameofitem(gp, type), mission_name(mission),
315 xyas(x, y, player->cnum), gp->radius);
316 } else if (mission == MI_RESERVE) {
319 if (((struct lndstr *)gp)->lnd_rad_max == 0) {
322 getsect(gp->x, gp->y, &opsect);
323 if ((opsect.sct_type == SCT_HEADQ)
324 && (opsect.sct_effic >= 60))
326 plus += ((struct lndstr *)gp)->lnd_rad_max;
329 pr("%s on %s mission with maximum reaction radius %d\n",
330 nameofitem(gp, type), mission_name(mission), plus);
331 } else if (mission) {
332 pr("%s on %s mission\n", nameofitem(gp, type),
333 mission_name(mission));
337 gp->mobil -= mobused;
338 gp->mission = mission;
343 putship(gp->uid, &item.ship);
346 putland(gp->uid, &item.land);
349 putplane(gp->uid, &item.plane);
354 pr("No %s%s\n", ef_nameof(type), splur(num));
357 pr("%d %s%s\n", num, ef_nameof(type), splur(num));