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
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 };
65 int desired_radius, radius;
69 int num = 0, mobmax, mobused, dist;
75 getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
78 type = ef_byname_from(p, ef_with_missions);
80 pr("Ships, land units or planes only! (s, l, p)\n");
83 sprintf(prompt, "%s(s)? ", ef_nameof(type));
84 p = getstarg(player->argp[2], prompt, buf);
85 if (!snxtitem(&ni, type, p))
89 getstarg(player->argp[3],
90 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
98 * 'd' support defenders
100 * 'r' defensive reserve
101 * 'a' air defense (intercepts)
106 mission = MI_INTERDICT;
110 mission = MI_OSUPPORT;
114 mission = MI_DSUPPORT;
118 mission = MI_SUPPORT;
130 mission = MI_RESERVE;
134 mission = MI_AIR_DEFENSE;
137 show_mission(type, &ni);
140 pr("bad condition\n");
141 pr("i\tinterdiction (any)\n");
142 pr("s\tsupport (tactical planes only)\n");
143 pr("o\toffensive support (tactical planes only)\n");
144 pr("d\tdefensive support (tactical planes only)\n");
145 pr("r\treserve (land units only)\n");
146 pr("e\tescort (tactical or escort planes only)\n");
147 pr("a\tair defense (intercept planes only)\n");
148 pr("c\tclear mission\n");
153 if (mission && !cando(mission, type)) {
154 pr("A %s cannot do that mission!\n", ef_nameof(type));
155 pr("i\tinterdiction (any)\n");
156 pr("s\tsupport (planes only)\n");
157 pr("o\toffensive support (planes only)\n");
158 pr("d\tdefensive support (planes only)\n");
159 pr("r\treserve (land units only)\n");
160 pr("e\tescort (planes only)\n");
161 pr("a\tair defense (planes only)\n");
165 if (mission && ((mission != MI_RESERVE) && (mission != MI_ESCORT))) {
166 if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
171 if (!sarg_xy(p, &x, &y))
174 if (!getsect(x, y, &opsect))
182 if (player->argp[5] != NULL) {
183 desired_radius = atoi(player->argp[5]);
184 if (desired_radius < 0) {
185 pr("Radius must be greater than zero!\n");
189 desired_radius = 9999;
192 size = MAX(sizeof(struct lndstr), sizeof(struct plnstr));
193 size = MAX(size, sizeof(struct shpstr));
194 block = malloc(size);
197 mobmax = ship_mob_max;
200 mobmax = land_mob_max;
203 mobmax = plane_mob_max;
207 mobused = ldround((mission_mob_cost * (double)mobmax), 1);
209 while (nxtitem(&ni, block)) {
210 gp = (struct genitem *)block;
212 if (!player->owner || gp->own == 0)
215 if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
216 pr("%s #%d: not enough mobility! (needs %d)\n",
217 ef_nameof(type), gp->uid, mobused);
220 if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
221 pr("%s is not designed to fight ground troops\n",
222 prland((struct lndstr *)gp));
228 if (!getsect(x, y, &opsect))
232 dist = mapdist(gp->x, gp->y, x, y);
234 if ((mission == MI_INTERDICT || mission == MI_SUPPORT ||
235 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
236 mission == MI_AIR_DEFENSE) &&
237 (oprange(gp, type, &radius) < dist)) {
238 pr("%s #%d: out of range! (range %d)\n",
239 ef_nameof(type), gp->uid, oprange(gp, type, &radius));
243 if (radius > desired_radius)
244 radius = desired_radius;
247 if (mission && (gp->effic < 60)){
248 pr("%s #%d: not efficient enough! (must be>=60%)\n",
249 ef_nameof(type), gp->uid);
254 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
255 if (mchr[(int)gp->type].m_frnge < 1) {
256 pr("%s #%d: cannot fire at range!\n",
257 ef_nameof(type), gp->uid);
261 if ((mission == MI_INTERDICT) && (type == EF_LAND))
262 if (lchr[(int)gp->type].l_frg < 1) {
263 pr("%s #%d: cannot fire at range!\n",
264 ef_nameof(type), gp->uid);
268 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
269 struct plchrstr *pcp;
271 pcp = &plchr[(int)gp->type];
272 if (!(pcp->pl_flags & P_T)) {
273 pr("Only planes with the tactical ability can interdict.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
278 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
279 struct plchrstr *pcp;
281 pcp = &plchr[(int)gp->type];
282 if (!(pcp->pl_flags & P_F)) {
283 pr("Only planes with the intercept abilities can perform air defense.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
288 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
289 struct plchrstr *pcp;
291 pcp = &plchr[(int)gp->type];
292 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
293 pr("Only planes with the escort or intercept abilities can escort.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
298 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
299 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
300 struct plchrstr *pcp;
302 pcp = &plchr[(int)gp->type];
303 if (!(pcp->pl_flags & P_T)) {
304 pr("Only planes with the tactical ability can support.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid);
309 num++; /* good one.. go with it */
311 if (mission == MI_INTERDICT || mission == MI_SUPPORT ||
312 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
313 mission == MI_AIR_DEFENSE)
318 if (mission == MI_SUPPORT || mission == MI_OSUPPORT ||
319 mission == MI_DSUPPORT || mission == MI_INTERDICT ||
320 mission == MI_AIR_DEFENSE) {
321 pr("%s on %s mission, centered on %s, radius %d\n",
322 nameofitem(gp, type), mission_name(mission),
323 xyas(x, y, player->cnum), gp->radius);
324 } else if (mission == MI_RESERVE) {
327 if (((struct lndstr *)gp)->lnd_rad_max == 0) {
330 getsect(gp->x, gp->y, &opsect);
331 if ((opsect.sct_type == SCT_HEADQ)
332 && (opsect.sct_effic >= 60))
334 plus += ((struct lndstr *)gp)->lnd_rad_max;
337 pr("%s on %s mission with maximum reaction radius %d\n",
338 nameofitem(gp, type), mission_name(mission), plus);
339 } else if (mission) {
340 pr("%s on %s mission\n", nameofitem(gp, type),
341 mission_name(mission));
345 gp->mobil -= mobused;
346 gp->mission = mission;
351 putship(gp->uid, block);
354 putland(gp->uid, block);
357 putplane(gp->uid, block);
362 pr("No %s%s\n", ef_nameof(type), splur(num));
365 pr("%d %s%s\n", num, ef_nameof(type), splur(num));