2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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:
52 static int tran_map(s_char *what, coord curx, coord cury, s_char *arg);
53 static int tran_nuke(void);
54 static int tran_plane(void);
63 getstarg(player->argp[1], "transport what (nuke or plane): ", buf);
68 else if (*what == 'p')
74 * Kinda silly; only moves the first nuke.
75 * Maybe nukes should be made into commodities?
91 struct sctstr endsect;
93 struct nstr_item nstr;
96 if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
98 if (!sarg_xy(p, &x, &y))
100 if (!getsect(x, y, §) || !player->owner) {
104 snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y);
106 while (nxtitem(&nstr, &nuke)) {
113 pr("There are no nukes in %s\n",
114 xyas(sect.sct_x, sect.sct_y, player->cnum));
117 if (!(p = getstarg(player->argp[3], "warhead type : ", buf)))
119 if (!check_sect_ok(§))
122 for (i = 0, ncp = nchr; i < N_MAXNUKE; i++, ncp++) {
123 if (strncmp(ncp->n_name, p, len) == 0)
126 if (i >= N_MAXNUKE) {
127 pr("No such nuke type!\n");
131 if (!nuke.nuk_types[nuketype]) {
132 pr("No %s nukes in %s\n",
133 ncp->n_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
136 p = getstarg(player->argp[4], "number of warheads : ", buf);
137 if (!check_sect_ok(§))
139 if (p == 0 || *p == 0 || (moving = atoi(p)) < 0)
141 if (moving > nuke.nuk_types[nuketype]) {
142 moving = nuke.nuk_types[nuketype];
144 pr("only moving %d\n", moving);
148 if (!military_control(§)) {
149 pr("Military control required to move nukes.\n");
153 mcost = move_ground((s_char *)&nuke, §, &endsect,
154 (double)ncp->n_weight * moving,
155 player->argp[5], tran_map, 0, &dam);
161 pr("Total movement cost = %d\n", mcost);
163 pr("No mobility used\n");
165 dstx = endsect.sct_x;
166 dsty = endsect.sct_y;
168 * decrement mobility from src sector
170 getsect(nuke.nuk_x, nuke.nuk_y, §);
171 sect.sct_mobil -= mcost;
172 if (sect.sct_mobil < 0)
178 if (!getnuke(nuke.nuk_uid, &nuke)) {
179 pr("Could not find that stockpile again.\n");
182 if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) {
183 pr("Stockpile changed!\n");
186 nuk_delete(&nuke, nuketype, moving);
187 nuk_add(dstx, dsty, nuketype, moving);
199 struct nstr_item nstr;
202 struct sctstr endsect;
206 if (!snxtitem(&nstr, EF_PLANE, player->argp[2]))
209 * First do some sanity checks: make sure that they are all in the,
210 * same sector, not on ships, owned, etc.
211 * No one could seriously want to move planes in parallel from
214 while (nxtitem(&nstr, (s_char *)&plane)) {
217 type = plane.pln_type;
218 if (plane.pln_ship >= 0) {
219 pr("%s is at sea and can't be transported\n", prplane(&plane));
221 } else if (plane.pln_harden != 0) {
222 pr("%s has been hardened and can't be transported\n",
225 } else if ((plane.pln_flags & PLN_LAUNCHED) &&
226 (plchr[type].pl_flags & P_O)) {
227 pr("%s is in space and can't be transported\n",
235 if (plane.pln_x != srcx || plane.pln_y != srcy) {
236 pr("All planes must be in the same sector.\n");
240 weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
247 if (!getsect(srcx, srcy, §) || !player->owner) {
248 pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
251 if (!military_control(§)) {
252 pr("Military control required to move planes.\n");
256 mcost = move_ground((s_char *)&plane, §, &endsect,
258 player->argp[3], tran_map, 0, &dam);
263 dstx = endsect.sct_x;
264 dsty = endsect.sct_y;
265 snxtitem_rewind(&nstr);
266 while (nxtitem(&nstr, (s_char *)&plane)) {
270 planedamage(&plane, dam);
273 plane.pln_mission = 0;
274 putplane(plane.pln_uid, &plane);
277 pr("Total movement cost = %d\n", mcost);
279 pr("No mobility used\n");
280 getsect(srcx, srcy, §);
281 sect.sct_mobil -= mcost;
282 if (sect.sct_mobil < 0)
289 * Pretty tacky, but it works.
290 * If more commands start doing this, then
291 * rewrite map to do the right thing.
293 /* I think this is no longer used, check subs/move.c:move_ground() */
296 tran_map(s_char *what, coord curx, coord cury, s_char *arg)
298 player->argp[1] = arg;