2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 * tran.c: Transport nuclear devices and planes
30 * Known contributors to this file:
49 static int tran_map(s_char *what, coord curx, coord cury, s_char *arg);
50 static int tran_nuke(void);
51 static int tran_plane(void);
60 getstarg(player->argp[1], "transport what (nuke or plane): ", buf);
65 else if (*what == 'p')
71 * Kinda silly; only moves the first nuke.
72 * 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(§))
119 for (i = 0, ncp = nchr; i < N_MAXNUKE; i++, ncp++) {
120 if (strncmp(ncp->n_name, p, len) == 0)
123 if (i >= N_MAXNUKE) {
124 pr("No such nuke type!\n");
128 if (!nuke.nuk_types[nuketype]) {
129 pr("No %s nukes in %s\n",
130 ncp->n_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
133 p = getstarg(player->argp[4], "number of warheads : ", buf);
134 if (!check_sect_ok(§))
136 if (p == 0 || *p == 0 || (moving = atoi(p)) < 0)
138 if (moving > nuke.nuk_types[nuketype]) {
139 moving = nuke.nuk_types[nuketype];
141 pr("only moving %d\n", moving);
145 if (!military_control(§)) {
146 pr("Military control required to move nukes.\n");
150 mcost = move_ground((s_char *)&nuke, §, &endsect,
151 (double)ncp->n_weight * moving,
152 player->argp[5], tran_map, 0, &dam);
158 pr("Total movement cost = %d\n", mcost);
160 pr("No mobility used\n");
162 dstx = endsect.sct_x;
163 dsty = endsect.sct_y;
165 * decrement mobility from src sector
167 getsect(nuke.nuk_x, nuke.nuk_y, §);
168 sect.sct_mobil -= mcost;
169 if (sect.sct_mobil < 0)
175 if (!getnuke(nuke.nuk_uid, &nuke)) {
176 pr("Could not find that stockpile again.\n");
179 if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) {
180 pr("Stockpile changed!\n");
183 nuk_delete(&nuke, nuketype, moving);
184 nuk_add(dstx, dsty, nuketype, moving);
196 struct nstr_item nstr;
199 struct sctstr endsect;
203 if (!snxtitem(&nstr, EF_PLANE, player->argp[2]))
206 * First do some sanity checks: make sure that they are all in the,
207 * same sector, not on ships, owned, etc.
208 * No one could seriously want to move planes in parallel from
211 while (nxtitem(&nstr, &plane)) {
214 type = plane.pln_type;
215 if (plane.pln_ship >= 0) {
216 pr("%s is at sea and can't be transported\n", prplane(&plane));
218 } else if (plane.pln_harden != 0) {
219 pr("%s has been hardened and can't be transported\n",
222 } else if ((plane.pln_flags & PLN_LAUNCHED) &&
223 (plchr[type].pl_flags & P_O)) {
224 pr("%s is in space and can't be transported\n",
232 if (plane.pln_x != srcx || plane.pln_y != srcy) {
233 pr("All planes must be in the same sector.\n");
237 weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
244 if (!getsect(srcx, srcy, §) || !player->owner) {
245 pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
248 if (!military_control(§)) {
249 pr("Military control required to move planes.\n");
253 mcost = move_ground((s_char *)&plane, §, &endsect,
255 player->argp[3], tran_map, 0, &dam);
260 dstx = endsect.sct_x;
261 dsty = endsect.sct_y;
262 snxtitem_rewind(&nstr);
263 while (nxtitem(&nstr, &plane)) {
267 planedamage(&plane, dam);
270 plane.pln_mission = 0;
271 putplane(plane.pln_uid, &plane);
274 pr("Total movement cost = %d\n", mcost);
276 pr("No mobility used\n");
277 getsect(srcx, srcy, §);
278 sect.sct_mobil -= mcost;
279 if (sect.sct_mobil < 0)
286 * Pretty tacky, but it works.
287 * If more commands start doing this, then
288 * rewrite map to do the right thing.
290 /* I think this is no longer used, check subs/move.c:move_ground() */
293 tran_map(s_char *what, coord curx, coord cury, s_char *arg)
295 player->argp[1] = arg;