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 * tran.c: Transport nuclear devices and planes
30 * Known contributors to this file:
51 static int tran_map(coord curx, coord cury, char *arg);
52 static int tran_nuke(void);
53 static int tran_plane(void);
61 what = getstarg(player->argp[1], "transport what (nuke or plane): ",
67 else if (*what == 'p')
73 * Kinda silly; only moves the first nuke.
74 * Maybe nukes should be made into commodities?
88 struct sctstr endsect;
90 struct nstr_item nstr;
93 if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
95 if (!sarg_xy(p, &x, &y))
97 if (!getsect(x, y, §) || !player->owner) {
101 snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y);
103 while (nxtitem(&nstr, &nuke)) {
110 pr("There are no nukes in %s\n",
111 xyas(sect.sct_x, sect.sct_y, player->cnum));
114 if (!(p = getstarg(player->argp[3], "warhead type : ", buf)))
116 if (!check_sect_ok(§))
118 nuketype = typematch(p, EF_NUKE);
120 pr("No such nuke type!\n");
123 ncp = &nchr[nuketype];
124 if (!nuke.nuk_types[nuketype]) {
125 pr("No %s nukes in %s\n",
126 ncp->n_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
129 p = getstarg(player->argp[4], "number of warheads : ", buf);
130 if (!check_sect_ok(§))
132 if (p == 0 || *p == 0 || (moving = atoi(p)) < 0)
134 if (moving > nuke.nuk_types[nuketype]) {
135 moving = nuke.nuk_types[nuketype];
137 pr("only moving %d\n", moving);
141 if (!military_control(§)) {
142 pr("Military control required to move nukes.\n");
146 mcost = move_ground(§, &endsect, (double)ncp->n_weight * moving,
147 player->argp[5], tran_map, 0, &dam);
153 pr("Total movement cost = %d\n", mcost);
155 pr("No mobility used\n");
157 dstx = endsect.sct_x;
158 dsty = endsect.sct_y;
160 * decrement mobility from src sector
162 getsect(nuke.nuk_x, nuke.nuk_y, §);
163 sect.sct_mobil -= mcost;
164 if (sect.sct_mobil < 0)
170 if (!getnuke(nuke.nuk_uid, &nuke)) {
171 pr("Could not find that stockpile again.\n");
174 if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) {
175 pr("Stockpile changed!\n");
178 nuk_delete(&nuke, nuketype, moving);
179 nuk_add(dstx, dsty, nuketype, moving);
191 struct nstr_item nstr;
194 struct sctstr endsect;
198 if (!snxtitem(&nstr, EF_PLANE, player->argp[2]))
201 * First do some sanity checks: make sure that they are all in the,
202 * same sector, not on ships, owned, etc.
203 * No one could seriously want to move planes in parallel from
206 while (nxtitem(&nstr, &plane)) {
209 type = plane.pln_type;
210 if (plane.pln_ship >= 0) {
211 pr("%s is at sea and can't be transported\n", prplane(&plane));
213 } else if (plane.pln_harden != 0) {
214 pr("%s has been hardened and can't be transported\n",
217 } else if ((plane.pln_flags & PLN_LAUNCHED) &&
218 (plchr[type].pl_flags & P_O)) {
219 pr("%s is in space and can't be transported\n",
227 if (plane.pln_x != srcx || plane.pln_y != srcy) {
228 pr("All planes must be in the same sector.\n");
232 weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
239 if (!getsect(srcx, srcy, §) || !player->owner) {
240 pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
243 if (!military_control(§)) {
244 pr("Military control required to move planes.\n");
248 mcost = move_ground(§, &endsect, weight,
249 player->argp[3], tran_map, 0, &dam);
254 dstx = endsect.sct_x;
255 dsty = endsect.sct_y;
256 snxtitem_rewind(&nstr);
257 while (nxtitem(&nstr, &plane)) {
261 planedamage(&plane, dam);
264 plane.pln_mission = 0;
265 putplane(plane.pln_uid, &plane);
268 pr("Total movement cost = %d\n", mcost);
270 pr("No mobility used\n");
271 getsect(srcx, srcy, §);
272 sect.sct_mobil -= mcost;
273 if (sect.sct_mobil < 0)
280 * Pretty tacky, but it works.
281 * If more commands start doing this, then
282 * rewrite map to do the right thing.
286 tran_map(coord curx, coord cury, char *arg)
288 player->argp[0] = "map";
289 player->argp[1] = arg;
290 player->argp[2] = NULL;
291 player->condarg = NULL;