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
60 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
65 static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
70 int desired_radius, radius;
74 int num = 0, mobmax, mobused, dist;
80 getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
83 type = ef_byname_from(p, ef_with_missions);
85 pr("Ships, land units or planes only! (s, l, p)\n");
88 sprintf(prompt, "%s(s)? ", ef_nameof(type));
89 p = getstarg(player->argp[2], prompt, buf);
90 if (!snxtitem(&ni, type, p))
94 getstarg(player->argp[3],
95 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
102 * 'o' support attacks
103 * 'd' support defenders
105 * 'r' defensive reserve
106 * 'a' air defense (intercepts)
111 mission = MI_INTERDICT;
115 mission = MI_OSUPPORT;
119 mission = MI_DSUPPORT;
123 mission = MI_SUPPORT;
135 mission = MI_RESERVE;
139 mission = MI_AIR_DEFENSE;
142 show_mission(type, &ni);
145 pr("bad condition\n");
146 pr("i\tinterdiction (any)\n");
147 pr("s\tsupport (tactical planes only)\n");
148 pr("o\toffensive support (tactical planes only)\n");
149 pr("d\tdefensive support (tactical planes only)\n");
150 pr("r\treserve (land units only)\n");
151 pr("e\tescort (tactical or escort planes only)\n");
152 pr("a\tair defense (intercept planes only)\n");
153 pr("c\tclear mission\n");
158 if (mission && !cando(mission, type)) {
159 pr("A %s cannot do that mission!\n", ef_nameof(type));
160 pr("i\tinterdiction (any)\n");
161 pr("s\tsupport (planes only)\n");
162 pr("o\toffensive support (planes only)\n");
163 pr("d\tdefensive support (planes only)\n");
164 pr("r\treserve (land units only)\n");
165 pr("e\tescort (planes only)\n");
166 pr("a\tair defense (planes only)\n");
170 if (mission && ((mission != MI_RESERVE) && (mission != MI_ESCORT))) {
171 if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
176 if (!sarg_xy(p, &x, &y))
179 if (!getsect(x, y, &opsect))
187 if (player->argp[5] != NULL) {
188 desired_radius = atoi(player->argp[5]);
189 if (desired_radius < 0) {
190 pr("Radius must be greater than zero!\n");
194 desired_radius = 9999;
199 mobmax = ship_mob_max;
202 mobmax = land_mob_max;
205 mobmax = plane_mob_max;
209 mobused = ldround((mission_mob_cost * (double)mobmax), 1);
211 while (nxtitem(&ni, &item)) {
212 gp = (struct genitem *)&item;
214 if (!player->owner || gp->own == 0)
217 if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
218 pr("%s #%d: not enough mobility! (needs %d)\n",
219 ef_nameof(type), gp->uid, mobused);
222 if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
223 pr("%s is not designed to fight ground troops\n",
224 prland((struct lndstr *)gp));
230 if (!getsect(x, y, &opsect))
234 dist = mapdist(gp->x, gp->y, x, y);
236 if ((mission == MI_INTERDICT || mission == MI_SUPPORT ||
237 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
238 mission == MI_AIR_DEFENSE) &&
239 (oprange(gp, type, &radius) < dist)) {
240 pr("%s #%d: out of range! (range %d)\n",
241 ef_nameof(type), gp->uid, oprange(gp, type, &radius));
245 if (radius > desired_radius)
246 radius = desired_radius;
249 if (mission && (gp->effic < 60)){
250 pr("%s #%d: not efficient enough! (must be>=60%)\n",
251 ef_nameof(type), gp->uid);
256 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
257 if (mchr[(int)gp->type].m_frnge < 1) {
258 pr("%s #%d: cannot fire at range!\n",
259 ef_nameof(type), gp->uid);
263 if ((mission == MI_INTERDICT) && (type == EF_LAND))
264 if (lchr[(int)gp->type].l_frg < 1) {
265 pr("%s #%d: cannot fire at range!\n",
266 ef_nameof(type), gp->uid);
270 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
271 struct plchrstr *pcp;
273 pcp = &plchr[(int)gp->type];
274 if (!(pcp->pl_flags & P_T)) {
275 pr("Only planes with the tactical ability can interdict.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
280 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
281 struct plchrstr *pcp;
283 pcp = &plchr[(int)gp->type];
284 if (!(pcp->pl_flags & P_F)) {
285 pr("Only planes with the intercept abilities can perform air defense.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
290 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
291 struct plchrstr *pcp;
293 pcp = &plchr[(int)gp->type];
294 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
295 pr("Only planes with the escort or intercept abilities can escort.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
300 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
301 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
302 struct plchrstr *pcp;
304 pcp = &plchr[(int)gp->type];
305 if (!(pcp->pl_flags & P_T)) {
306 pr("Only planes with the tactical ability can support.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
311 num++; /* good one.. go with it */
313 if (mission == MI_INTERDICT || mission == MI_SUPPORT ||
314 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
315 mission == MI_AIR_DEFENSE)
320 if (mission == MI_SUPPORT || mission == MI_OSUPPORT ||
321 mission == MI_DSUPPORT || mission == MI_INTERDICT ||
322 mission == MI_AIR_DEFENSE) {
323 pr("%s on %s mission, centered on %s, radius %d\n",
324 nameofitem(gp, type), mission_name(mission),
325 xyas(x, y, player->cnum), gp->radius);
326 } else if (mission == MI_RESERVE) {
329 if (((struct lndstr *)gp)->lnd_rad_max == 0) {
332 getsect(gp->x, gp->y, &opsect);
333 if ((opsect.sct_type == SCT_HEADQ)
334 && (opsect.sct_effic >= 60))
336 plus += ((struct lndstr *)gp)->lnd_rad_max;
339 pr("%s on %s mission with maximum reaction radius %d\n",
340 nameofitem(gp, type), mission_name(mission), plus);
341 } else if (mission) {
342 pr("%s on %s mission\n", nameofitem(gp, type),
343 mission_name(mission));
347 gp->mobil -= mobused;
348 gp->mission = mission;
353 putship(gp->uid, &item.ship);
356 putland(gp->uid, &item.land);
359 putplane(gp->uid, &item.plane);
364 pr("No %s%s\n", ef_nameof(type), splur(num));
367 pr("%d %s%s\n", num, ef_nameof(type), splur(num));