2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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
44 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
49 static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
54 int desired_radius, radius;
56 union empobj_storage item;
58 int num = 0, mobmax, mobused, dist;
63 getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
66 type = ef_byname_from(p, ef_with_missions);
68 pr("Ships, land units or planes only! (s, l, p)\n");
71 if (!snxtitem(&ni, type, player->argp[2], NULL))
75 getstarg(player->argp[3],
76 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
84 * 'd' support defenders
86 * 'r' defensive reserve
87 * 'a' air defense (intercepts)
92 mission = MI_INTERDICT;
96 mission = MI_OSUPPORT;
100 mission = MI_DSUPPORT;
104 mission = MI_SUPPORT;
116 mission = MI_RESERVE;
120 mission = MI_AIR_DEFENSE;
123 show_mission(type, &ni);
126 pr("bad condition\n");
127 pr("i\tinterdiction (any)\n");
128 pr("s\tsupport (tactical planes only)\n");
129 pr("o\toffensive support (tactical planes only)\n");
130 pr("d\tdefensive support (tactical planes only)\n");
131 pr("r\treserve (land units only)\n");
132 pr("e\tescort (tactical or escort planes only)\n");
133 pr("a\tair defense (intercept planes only)\n");
134 pr("c\tclear mission\n");
139 if (mission && !cando(mission, type)) {
140 pr("A %s cannot do that mission!\n", ef_nameof(type));
141 pr("i\tinterdiction (any)\n");
142 pr("s\tsupport (planes only)\n");
143 pr("o\toffensive support (planes only)\n");
144 pr("d\tdefensive support (planes only)\n");
145 pr("r\treserve (land units only)\n");
146 pr("e\tescort (planes only)\n");
147 pr("a\tair defense (planes only)\n");
151 if (mission && ((mission != MI_RESERVE) && (mission != MI_ESCORT))) {
152 if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
157 if (!sarg_xy(p, &x, &y))
160 if (!getsect(x, y, &opsect))
168 if (player->argp[5] != NULL) {
169 desired_radius = atoi(player->argp[5]);
170 if (desired_radius < 0) {
171 pr("Radius must be greater than zero!\n");
175 desired_radius = 9999;
178 if ((mobmax = get_empobj_mob_max(type)) == -1)
181 mobused = ldround(mission_mob_cost * (double)mobmax, 1);
183 while (nxtitem(&ni, &item)) {
184 gp = (struct empobj *)&item;
186 if (!player->owner || gp->own == 0)
189 if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
190 pr("%s: not enough mobility! (needs %d)\n",
191 obj_nameof(gp), mobused);
194 if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
195 pr("%s is not designed to fight ground troops\n",
202 if (!getsect(x, y, &opsect))
206 dist = mapdist(gp->x, gp->y, x, y);
208 if ((mission == MI_INTERDICT || mission == MI_SUPPORT ||
209 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
210 mission == MI_AIR_DEFENSE) &&
211 (oprange(gp, &radius) < dist)) {
212 pr("%s: out of range! (range %d)\n",
213 obj_nameof(gp), oprange(gp, &radius));
217 if (radius > desired_radius)
218 radius = desired_radius;
220 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
221 if (mchr[(int)gp->type].m_glim == 0) {
222 pr("%s: cannot fire at range!\n", obj_nameof(gp));
226 if ((mission == MI_INTERDICT) && (type == EF_LAND))
227 if (lchr[(int)gp->type].l_dam == 0) {
228 pr("%s: cannot fire at range!\n", obj_nameof(gp));
232 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
233 struct plchrstr *pcp;
235 pcp = &plchr[(int)gp->type];
236 if (!(pcp->pl_flags & P_T)) {
237 pr("Only planes with the tactical ability can interdict.\n"
238 "%s #%d is ineligible\n",
239 pcp->pl_name, gp->uid);
244 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
245 struct plchrstr *pcp;
247 pcp = &plchr[(int)gp->type];
248 if (!(pcp->pl_flags & P_F)) {
249 pr("Only planes with the intercept abilities can perform air defense.\n"
250 "%s #%d is ineligible\n",
251 pcp->pl_name, gp->uid);
256 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
257 struct plchrstr *pcp;
259 pcp = &plchr[(int)gp->type];
260 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
261 pr("Only planes with the escort or intercept abilities can escort.\n"
262 "%s #%d is ineligible\n",
263 pcp->pl_name, gp->uid);
268 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
269 mission == MI_DSUPPORT) && (type == EF_PLANE)) {
270 struct plchrstr *pcp;
272 pcp = &plchr[(int)gp->type];
273 if (!(pcp->pl_flags & P_T)) {
274 pr("Only planes with the tactical ability can support.\n"
275 "%s #%d is ineligible\n",
276 pcp->pl_name, gp->uid);
281 num++; /* good one.. go with it */
283 if (mission == MI_INTERDICT || mission == MI_SUPPORT ||
284 mission == MI_OSUPPORT || mission == MI_DSUPPORT ||
285 mission == MI_AIR_DEFENSE)
290 if (mission == MI_SUPPORT || mission == MI_OSUPPORT ||
291 mission == MI_DSUPPORT || mission == MI_INTERDICT ||
292 mission == MI_AIR_DEFENSE) {
293 pr("%s on %s mission, centered on %s, radius %d\n",
294 obj_nameof(gp), mission_name(mission),
295 xyas(x, y, player->cnum), gp->radius);
296 } else if (mission == MI_RESERVE) {
299 if (((struct lndstr *)gp)->lnd_rad_max == 0) {
302 getsect(gp->x, gp->y, &opsect);
303 if ((opsect.sct_type == SCT_HEADQ)
304 && (opsect.sct_effic >= 60))
306 plus += ((struct lndstr *)gp)->lnd_rad_max;
309 pr("%s on %s mission with maximum reaction radius %d\n",
310 obj_nameof(gp), mission_name(mission), plus);
311 } else if (mission) {
312 pr("%s on %s mission\n", obj_nameof(gp),
313 mission_name(mission));
317 gp->mobil -= mobused;
318 gp->mission = mission;
321 put_empobj(type, gp->uid, gp);
324 pr("No %s%s\n", ef_nameof(type), splur(num));
327 pr("%d %s%s\n", num, ef_nameof(type), splur(num));