2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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
54 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
59 static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
64 int size, desired_radius, radius;
68 int num = 0, mobmax, mobused, dist;
74 getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
77 type = ef_byname_from(p, ef_with_missions);
79 pr("Ships, land units or planes only! (s, l, p)\n");
82 sprintf(prompt, "%s(s)? ", ef_nameof(type));
83 p = getstarg(player->argp[2], prompt, buf);
84 if (!snxtitem(&ni, type, p))
88 getstarg(player->argp[3],
89 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
97 * 'd' support defenders
99 * 'r' defensive reserve
100 * 'a' air defense (intercepts)
105 mission = MI_INTERDICT;
109 mission = MI_OSUPPORT;
113 mission = MI_DSUPPORT;
117 mission = MI_SUPPORT;
129 mission = MI_RESERVE;
133 mission = MI_AIR_DEFENSE;
136 show_mission(type, &ni);
139 pr("bad condition\n");
140 pr("i\tinterdiction (any)\n");
141 pr("s\tsupport (tactical planes only)\n");
142 pr("o\toffensive support (tactical planes only)\n");
143 pr("d\tdefensive support (tactical planes only)\n");
144 pr("r\treserve (land units only)\n");
145 pr("e\tescort (tactical or escort planes only)\n");
146 pr("a\tair defense (intercept planes only)\n");
147 pr("c\tclear mission\n");
152 if (mission && !cando(mission, type)) {
153 pr("A %s cannot do that mission!\n", ef_nameof(type));
154 pr("i\tinterdiction (any)\n");
155 pr("s\tsupport (planes only)\n");
156 pr("o\toffensive support (planes only)\n");
157 pr("d\tdefensive support (planes only)\n");
158 pr("r\treserve (land units only)\n");
159 pr("e\tescort (planes only)\n");
160 pr("a\tair defense (planes only)\n");
164 if (mission && ((mission != MI_RESERVE) && (mission != MI_ESCORT))) {
165 if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
170 if (!sarg_xy(p, &x, &y))
173 if (!getsect(x, y, &opsect))
181 if (player->argp[5] != (s_char *)0) {
182 desired_radius = atoi(player->argp[5]);
183 if (desired_radius < 0) {
184 pr("Radius must be greater than zero!\n");
188 desired_radius = 9999;
191 size = max(sizeof(struct lndstr), sizeof(struct plnstr));
192 size = max(size, sizeof(struct shpstr));
193 block = malloc(size);
196 mobmax = ship_mob_max;
199 mobmax = land_mob_max;
202 mobmax = plane_mob_max;
206 mobused = ldround((mission_mob_cost * (double)mobmax), 1);
208 while (nxtitem(&ni, block)) {
209 gp = (struct genitem *)block;
211 if (!player->owner || gp->own == 0)
214 if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
215 pr("%s #%d: not enough mobility! (needs %d)\n",
216 ef_nameof(type), gp->uid, mobused);
219 if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
220 pr("%s is not designed to fight ground troops\n",
221 prland((struct lndstr *)gp));
227 if (!getsect(x, y, &opsect))
231 dist = mapdist(gp->x, gp->y, x, y);
233 if ((mission == MI_INTERDICT || mission == MI_SUPPORT ||
234 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
235 mission == MI_AIR_DEFENSE) &&
236 (oprange(gp, type, &radius) < dist)) {
237 pr("%s #%d: out of range! (range %d)\n",
238 ef_nameof(type), gp->uid, oprange(gp, type, &radius));
242 if (radius > desired_radius)
243 radius = desired_radius;
246 if (mission && (gp->effic < 60)){
247 pr("%s #%d: not efficient enough! (must be>=60%)\n",
248 ef_nameof(type), gp->uid);
253 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
254 if (mchr[(int)gp->type].m_frnge < 1) {
255 pr("%s #%d: cannot fire at range!\n",
256 ef_nameof(type), gp->uid);
260 if ((mission == MI_INTERDICT) && (type == EF_LAND))
261 if (lchr[(int)gp->type].l_frg < 1) {
262 pr("%s #%d: cannot fire at range!\n",
263 ef_nameof(type), gp->uid);
267 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
268 struct plchrstr *pcp;
270 pcp = &plchr[(int)gp->type];
271 if (!(pcp->pl_flags & P_T)) {
272 pr("Only planes with the tactical ability can interdict.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
277 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
278 struct plchrstr *pcp;
280 pcp = &plchr[(int)gp->type];
281 if (!(pcp->pl_flags & P_F)) {
282 pr("Only planes with the intercept abilities can perform air defense.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
287 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
288 struct plchrstr *pcp;
290 pcp = &plchr[(int)gp->type];
291 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
292 pr("Only planes with the escort or intercept abilities can escort.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
297 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
298 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
299 struct plchrstr *pcp;
301 pcp = &plchr[(int)gp->type];
302 if (!(pcp->pl_flags & P_T)) {
303 pr("Only planes with the tactical ability can support.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
308 num++; /* good one.. go with it */
310 if (mission == MI_INTERDICT || mission == MI_SUPPORT ||
311 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
312 mission == MI_AIR_DEFENSE)
317 if (mission == MI_SUPPORT || mission == MI_OSUPPORT ||
318 mission == MI_DSUPPORT || mission == MI_INTERDICT ||
319 mission == MI_AIR_DEFENSE) {
320 pr("%s on %s mission, centered on %s, radius %d\n",
321 nameofitem(gp, type), mission_name(mission),
322 xyas(x, y, player->cnum), gp->radius);
323 } else if (mission == MI_RESERVE) {
326 if (((struct lndstr *)gp)->lnd_rad_max == 0) {
329 getsect(gp->x, gp->y, &opsect);
330 if ((opsect.sct_type == SCT_HEADQ)
331 && (opsect.sct_effic >= 60))
333 plus += ((struct lndstr *)gp)->lnd_rad_max;
336 pr("%s on %s mission with maximum reaction radius %d\n",
337 nameofitem(gp, type), mission_name(mission), plus);
338 } else if (mission) {
339 pr("%s on %s mission\n", nameofitem(gp, type),
340 mission_name(mission));
344 gp->mobil -= mobused;
345 gp->mission = mission;
350 putship(gp->uid, block);
353 putland(gp->uid, block);
356 putplane(gp->uid, block);
361 pr("No %s%s\n", ef_nameof(type), splur(num));
364 pr("%d %s%s\n", num, ef_nameof(type), splur(num));