2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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:
54 static int tran_map(s_char *what, coord curx, coord cury, s_char *arg);
55 static int tran_nuke(void);
56 static int tran_plane(void);
65 getstarg(player->argp[1], "transport what (nuke or plane): ", buf);
70 else if (*what == 'p')
76 * Kinda silly; only moves the first nuke.
77 * Maybe nukes should be made into commodities?
93 struct sctstr endsect;
95 struct nstr_item nstr;
98 if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
100 if (!sarg_xy(p, &x, &y))
102 if (!getsect(x, y, §) || !player->owner) {
107 if (!snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y)) {
108 pr("There are no nukes in %s\n",
109 xyas(sect.sct_x, sect.sct_y, player->cnum));
113 snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y);
116 while (nxtitem(&nstr, (caddr_t)&nuke)) {
123 pr("There are no nukes in %s\n",
124 xyas(sect.sct_x, sect.sct_y, player->cnum));
127 if (!(p = getstarg(player->argp[3], "warhead type : ", buf)))
129 if (!check_sect_ok(§))
132 for (i = 0, ncp = nchr; i < N_MAXNUKE; i++, ncp++) {
133 if (strncmp(ncp->n_name, p, len) == 0)
136 if (i >= N_MAXNUKE) {
137 pr("No such nuke type!\n");
141 if (!nuke.nuk_types[nuketype]) {
142 pr("No %s nukes in %s\n",
143 ncp->n_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
146 p = getstarg(player->argp[4], "number of warheads : ", buf);
147 if (!check_sect_ok(§))
149 if (p == 0 || *p == 0 || (moving = atoi(p)) < 0)
151 if (moving > nuke.nuk_types[nuketype]) {
152 moving = nuke.nuk_types[nuketype];
154 pr("only moving %d\n", moving);
159 * military control necessary to move
160 * goodies in occupied territory.
162 if (sect.sct_oldown != player->cnum) {
166 snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
167 while (nxtitem(&ni, (s_char *)&land)) {
168 if (land.lnd_own == player->cnum)
169 tot_mil += total_mil(&land);
171 if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR) + tot_mil) * 10
172 < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) {
173 pr("Military control required to move goods.\n");
178 mcost = move_ground((s_char *)&nuke, §, &endsect,
179 (double)ncp->n_weight * moving,
180 player->argp[5], tran_map, 0, &dam);
186 pr("Total movement cost = %d\n", mcost);
188 pr("No mobility used\n");
190 dstx = endsect.sct_x;
191 dsty = endsect.sct_y;
193 * decrement mobility from src sector
195 getsect(nuke.nuk_x, nuke.nuk_y, §);
196 sect.sct_mobil -= mcost;
197 if (sect.sct_mobil < 0)
203 if (!getnuke(nuke.nuk_uid, &nuke)) {
204 pr("Could not find that stockpile again.\n");
207 if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) {
208 pr("Stockpile changed!\n");
211 nuk_delete(&nuke, nuketype, moving);
212 nuk_add(dstx, dsty, nuketype, moving);
225 struct nstr_item nstr;
228 struct sctstr endsect;
233 if (!snxtitem(&nstr, EF_PLANE, player->argp[2]))
236 * First do some sanity checks: make sure that they are all in the,
237 * same sector, not on ships, owned, etc.
238 * No one could seriously want to move planes in parallel from
241 while (nxtitem(&nstr, (s_char *)&plane)) {
244 type = plane.pln_type;
245 if (plane.pln_ship >= 0) {
246 pr("%s is at sea and can't be transported\n", prplane(&plane));
248 } else if (plane.pln_harden != 0) {
249 pr("%s has been hardened and can't be transported\n",
252 } else if ((plane.pln_flags & PLN_LAUNCHED) &&
253 (plchr[type].pl_flags & P_O)) {
254 pr("%s is in space and can't be transported\n",
263 if (plane.pln_x != srcx || plane.pln_y != srcy) {
264 pr("All planes must be in the same sector.\n");
268 weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
275 getsect(srcx, srcy, §);
277 * military control necessary to move
278 * goodies in occupied territory.
280 if (sect.sct_oldown != player->cnum) {
284 snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
285 while (nxtitem(&ni, (s_char *)&land))
286 tot_mil += total_mil(&land);
287 if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR) + tot_mil) * 10
288 < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) {
289 pr("Military control required to move goods.\n");
294 mcost = move_ground((s_char *)&plane, §, &endsect,
296 player->argp[3], tran_map, 0, &dam);
301 dstx = endsect.sct_x;
302 dsty = endsect.sct_y;
303 snxtitem_rewind(&nstr);
304 while (nxtitem(&nstr, (s_char *)&plane)) {
308 planedamage(&plane, dam);
309 pr("\t%s takes %d\n", prplane(&plane), dam);
313 plane.pln_mission = 0;
314 putplane(plane.pln_uid, &plane);
317 pr("Total movement cost = %d\n", mcost);
319 pr("No mobility used\n");
320 sect.sct_mobil -= mcost;
321 if (sect.sct_mobil < 0)
328 * Pretty tacky, but it works.
329 * If more commands start doing this, then
330 * rewrite map to do the right thing.
332 /* I think this is no longer used, check subs/move.c:move_ground() */
335 tran_map(s_char *what, coord curx, coord cury, s_char *arg)
337 player->argp[1] = arg;