2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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
55 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
64 int size, desired_radius, radius;
68 int num = 0, mobmax, mobused, dist;
70 extern int ship_mob_max;
71 extern int land_mob_max;
72 extern int plane_mob_max;
73 extern double mission_mob_cost;
79 getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
83 if (type == EF_SECTOR)
85 if (type != EF_SHIP && type != EF_LAND && type != EF_PLANE) {
86 pr("Ships, land units or planes only! (s, l, p)\n");
89 sprintf(prompt, "%s(s)? ", ef_nameof(type));
90 p = getstarg(player->argp[2], prompt, buf);
91 if (!snxtitem(&ni, type, p))
95 getstarg(player->argp[3],
96 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
103 * 'o' support attacks
104 * 'd' support defenders
106 * 'r' defensive reserve
107 * 'a' air defense (intercepts)
112 mission = MI_INTERDICT;
116 mission = MI_OSUPPORT;
120 mission = MI_DSUPPORT;
124 mission = MI_SUPPORT;
136 mission = MI_RESERVE;
140 mission = MI_AIR_DEFENSE;
143 show_mission(type, &ni);
146 pr("bad condition\n");
147 pr("i\tinterdiction (any)\n");
148 pr("s\tsupport (tactical planes only)\n");
149 pr("o\toffensive support (tactical planes only)\n");
150 pr("d\tdefensive support (tactical planes only)\n");
151 pr("r\treserve (land units only)\n");
152 pr("e\tescort (tactical or escort planes only)\n");
153 pr("a\tair defense (intercept planes only)\n");
154 pr("c\tclear mission\n");
159 if (mission && !cando(mission, type)) {
160 pr("A %s cannot do that mission!\n", ef_nameof(type));
161 pr("i\tinterdiction (any)\n");
162 pr("s\tsupport (planes only)\n");
163 pr("o\toffensive support (planes only)\n");
164 pr("d\tdefensive support (planes only)\n");
165 pr("r\treserve (land units only)\n");
166 pr("e\tescort (planes only)\n");
167 pr("a\tair defense (planes only)\n");
171 if (mission && ((mission != MI_RESERVE) && (mission != MI_ESCORT))) {
172 if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
177 if (!sarg_xy(p, &x, &y))
180 if (!getsect(x, y, &opsect))
188 if (player->argp[5] != (s_char *)0) {
189 desired_radius = atoi(player->argp[5]);
190 if (desired_radius < 0) {
191 pr("Radius must be greater than zero!\n");
195 desired_radius = 9999;
198 size = max(sizeof(struct lndstr), sizeof(struct plnstr));
199 size = max(size, sizeof(struct shpstr));
200 block = (s_char *)malloc(size);
203 mobmax = ship_mob_max;
206 mobmax = land_mob_max;
209 mobmax = plane_mob_max;
213 mobused = ldround((mission_mob_cost * (double)mobmax), 1);
215 while (nxtitem(&ni, block)) {
216 gp = (struct genitem *)block;
218 if (!player->owner || gp->own == 0)
221 if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
222 pr("%s #%d: not enough mobility! (needs %d)\n",
223 ef_nameof(type), gp->uid, mobused);
226 if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
227 pr("%s is not designed to fight ground troops\n",
228 prland((struct lndstr *)gp));
234 if (!getsect(x, y, &opsect))
238 dist = mapdist(gp->x, gp->y, x, y);
240 if ((mission == MI_INTERDICT || mission == MI_SUPPORT ||
241 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
242 mission == MI_AIR_DEFENSE) &&
243 (oprange(gp, type, &radius) < dist)) {
244 pr("%s #%d: out of range! (range %d)\n",
245 ef_nameof(type), gp->uid, oprange(gp, type, &radius));
249 if (radius > desired_radius)
250 radius = desired_radius;
253 if (mission && (gp->effic < 60)){
254 pr("%s #%d: not efficient enough! (must be>=60%)\n",
255 ef_nameof(type), gp->uid);
260 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
261 if (mchr[(int)gp->type].m_frnge < 1) {
262 pr("%s #%d: cannot fire at range!\n",
263 ef_nameof(type), gp->uid);
267 if ((mission == MI_INTERDICT) && (type == EF_LAND))
268 if (lchr[(int)gp->type].l_frg < 1) {
269 pr("%s #%d: cannot fire at range!\n",
270 ef_nameof(type), gp->uid);
274 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
275 struct plchrstr *pcp;
277 pcp = &plchr[(int)gp->type];
278 if (!(pcp->pl_flags & P_T)) {
279 pr("Only planes with the tactical ability can interdict.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
284 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
285 struct plchrstr *pcp;
287 pcp = &plchr[(int)gp->type];
288 if (!(pcp->pl_flags & P_F)) {
289 pr("Only planes with the intercept abilities can perform air defense.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
294 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
295 struct plchrstr *pcp;
297 pcp = &plchr[(int)gp->type];
298 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
299 pr("Only planes with the escort or intercept abilities can escort.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
304 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
305 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
306 struct plchrstr *pcp;
308 pcp = &plchr[(int)gp->type];
309 if (!(pcp->pl_flags & P_T)) {
310 pr("Only planes with the tactical ability can support.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
315 num++; /* good one.. go with it */
317 if (mission == MI_INTERDICT || mission == MI_SUPPORT ||
318 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
319 mission == MI_AIR_DEFENSE)
324 if (mission == MI_SUPPORT || mission == MI_OSUPPORT ||
325 mission == MI_DSUPPORT || mission == MI_INTERDICT ||
326 mission == MI_AIR_DEFENSE) {
327 pr("%s on %s mission, centered on %s, radius %d\n",
328 nameofitem(buf, gp, type), mission_name(mission),
329 xyas(x, y, player->cnum), gp->radius);
330 } else if (mission == MI_RESERVE) {
333 if (((struct lndstr *)gp)->lnd_rad_max == 0) {
336 getsect(gp->x, gp->y, &opsect);
337 if ((opsect.sct_type == SCT_HEADQ)
338 && (opsect.sct_effic >= 60))
340 plus += ((struct lndstr *)gp)->lnd_rad_max;
343 pr("%s on %s mission with maximum reaction radius %d\n",
344 nameofitem(buf, gp, type), mission_name(mission), plus);
345 } else if (mission) {
346 pr("%s on %s mission\n", nameofitem(buf, gp, type),
347 mission_name(mission));
351 gp->mobil -= mobused;
352 gp->mission = mission;
357 putship(gp->uid, block);
360 putland(gp->uid, block);
363 putplane(gp->uid, block);
368 pr("No %s%s\n", ef_nameof(type), splur(num));
371 pr("%d %s%s\n", num, ef_nameof(type), splur(num));