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
43 static int show_mission(struct nstr_item *);
46 * mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
51 static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
56 int desired_radius, radius;
58 union empobj_storage item;
60 int num = 0, mobmax, mobused, dist;
65 getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
68 type = ef_byname_from(p, ef_with_missions);
70 pr("Ships, land units or planes only! (s, l, p)\n");
73 if (!snxtitem(&ni, type, player->argp[2], NULL))
77 getstarg(player->argp[3],
78 "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ",
86 * 'd' support defenders
88 * 'r' defensive reserve
89 * 'a' air defense (intercepts)
94 mission = MI_INTERDICT;
98 mission = MI_OSUPPORT;
102 mission = MI_DSUPPORT;
106 mission = MI_SUPPORT;
118 mission = MI_RESERVE;
122 mission = MI_AIR_DEFENSE;
125 return show_mission(&ni);
127 pr("bad condition\n");
128 pr("i\tinterdiction (any)\n");
129 pr("s\tsupport (tactical planes only)\n");
130 pr("o\toffensive support (tactical planes only)\n");
131 pr("d\tdefensive support (tactical planes only)\n");
132 pr("r\treserve (land units only)\n");
133 pr("e\tescort (tactical or escort planes only)\n");
134 pr("a\tair defense (intercept planes only)\n");
135 pr("c\tclear mission\n");
140 if (mission && !cando(mission, type)) {
141 pr("A %s cannot do that mission!\n", ef_nameof(type));
142 pr("i\tinterdiction (any)\n");
143 pr("s\tsupport (planes only)\n");
144 pr("o\toffensive support (planes only)\n");
145 pr("d\tdefensive support (planes only)\n");
146 pr("r\treserve (land units only)\n");
147 pr("e\tescort (planes only)\n");
148 pr("a\tair defense (planes only)\n");
153 if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
158 if (!sarg_xy(p, &x, &y))
161 if (!getsect(x, y, &opsect))
169 if (player->argp[5] != NULL) {
170 desired_radius = atoi(player->argp[5]);
171 if (desired_radius < 0) {
172 pr("Radius must be greater than zero!\n");
176 desired_radius = 9999;
179 if ((mobmax = get_empobj_mob_max(type)) == -1)
182 mobused = ldround(mission_mob_cost * (double)mobmax, 1);
184 while (nxtitem(&ni, &item)) {
185 gp = (struct empobj *)&item;
187 if (!player->owner || gp->own == 0)
190 if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
191 pr("%s: not enough mobility! (needs %d)\n",
192 obj_nameof(gp), mobused);
195 if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
196 pr("%s is not designed to fight ground troops\n",
203 if (!getsect(x, y, &opsect))
207 dist = mapdist(gp->x, gp->y, x, y);
210 radius = oprange(gp, mission);
212 pr("%s: out of range! (range %d)\n",
213 obj_nameof(gp), radius);
218 if (radius > desired_radius)
219 radius = desired_radius;
221 if ((mission == MI_INTERDICT) && (type == EF_SHIP))
222 if (mchr[(int)gp->type].m_glim == 0) {
223 pr("%s: cannot fire at range!\n", obj_nameof(gp));
227 if ((mission == MI_INTERDICT) && (type == EF_LAND))
228 if (lchr[(int)gp->type].l_dam == 0) {
229 pr("%s: cannot fire at range!\n", obj_nameof(gp));
233 if ((mission == MI_INTERDICT) && (type == EF_PLANE)) {
234 struct plchrstr *pcp;
236 pcp = &plchr[(int)gp->type];
237 if (!(pcp->pl_flags & P_T)) {
238 pr("Only planes with the tactical ability can interdict.\n"
239 "%s #%d is ineligible\n",
240 pcp->pl_name, gp->uid);
245 if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) {
246 struct plchrstr *pcp;
248 pcp = &plchr[(int)gp->type];
249 if (!(pcp->pl_flags & P_F)) {
250 pr("Only planes with the intercept abilities can perform air defense.\n"
251 "%s #%d is ineligible\n",
252 pcp->pl_name, gp->uid);
257 if ((mission == MI_ESCORT) && (type == EF_PLANE)) {
258 struct plchrstr *pcp;
260 pcp = &plchr[(int)gp->type];
261 if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) {
262 pr("Only planes with the escort or intercept abilities can escort.\n"
263 "%s #%d is ineligible\n",
264 pcp->pl_name, gp->uid);
269 if ((mission == MI_SUPPORT || mission == MI_OSUPPORT ||
270 mission == MI_DSUPPORT) && (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 support.\n"
276 "%s #%d is ineligible\n",
277 pcp->pl_name, gp->uid);
282 num++; /* good one.. go with it */
285 pr("%s on %s mission, centered on %s, radius %d\n",
286 obj_nameof(gp), mission_name(mission),
287 xyas(x, y, player->cnum), radius);
288 gp->mobil -= mobused;
293 gp->mission = mission;
296 put_empobj(type, gp->uid, gp);
299 pr("No %s%s\n", ef_nameof(type), splur(num));
302 pr("%d %s%s\n", num, ef_nameof(type), splur(num));
307 show_mission(struct nstr_item *np)
310 union empobj_storage item;
313 while (nxtitem(np, &item)) {
314 gp = (struct empobj *)&item;
315 if (!player->owner || gp->own == 0)
319 pr("Thing x,y op-sect rad mission\n");
322 pr("%-25s", obj_nameof(gp));
323 prxy(" %3d,%-3d", gp->x, gp->y, player->cnum);
324 switch (gp->mission) {
332 prxy(" %3d,%-3d", gp->opx, gp->opy, player->cnum);
333 pr(" %4d", gp->radius);
342 pr(" is on %s mission\n", mission_name(gp->mission));
344 pr(" has no mission.\n");