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);
64 what = getstarg(player->argp[1], "transport what (nuke or plane): ", buf);
69 else if (*what == 'p')
75 * Kinda silly; only moves the first nuke.
76 * Maybe nukes should be made into commodities?
92 struct sctstr endsect;
94 struct nstr_item nstr;
97 if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
99 if (!sarg_xy(p, &x, &y))
101 if (!getsect(x, y, §) || !player->owner) {
106 if (!snxtitem_xy(&nstr,EF_NUKE,sect.sct_x,sect.sct_y)) {
107 pr("There are no nukes in %s\n",
108 xyas(sect.sct_x, sect.sct_y, player->cnum));
112 snxtitem_xy(&nstr,EF_NUKE,sect.sct_x,sect.sct_y);
115 while (nxtitem(&nstr, (caddr_t)&nuke)) {
122 pr("There are no nukes in %s\n",
123 xyas(sect.sct_x, sect.sct_y, player->cnum));
126 if (!(p = getstarg(player->argp[3], "warhead type : ", buf)))
128 if (!check_sect_ok(§))
131 for (i=0, ncp = nchr; i<N_MAXNUKE; i++, ncp++) {
132 if (strncmp(ncp->n_name, p, len) == 0)
135 if (i >= N_MAXNUKE) {
136 pr("No such nuke type!\n");
140 if (!nuke.nuk_types[nuketype]) {
141 pr("No %s nukes in %s\n",
143 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)sect.sct_mobil,
180 (double) ncp->n_weight * moving,
181 player->argp[5], tran_map, 0, &dam);
187 pr("Total movement cost = %d\n",mcost);
189 pr("No mobility used\n");
191 dstx = endsect.sct_x;
192 dsty = endsect.sct_y;
194 * decrement mobility from src sector
196 getsect(nuke.nuk_x, nuke.nuk_y, §);
197 sect.sct_mobil -= mcost;
198 if (sect.sct_mobil < 0)
204 if (!getnuke(nuke.nuk_uid, &nuke)) {
205 pr("Could not find that stockpile again.\n");
208 if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) {
209 pr("Stockpile changed!\n");
212 nuk_delete(&nuke, nuketype, moving);
213 nuk_add(dstx, dsty, nuketype, moving);
226 struct nstr_item nstr;
229 struct sctstr endsect;
234 if (!snxtitem(&nstr, EF_PLANE, player->argp[2]))
237 * First do some sanity checks: make sure that they are all in the,
238 * same sector, not on ships, owned, etc.
239 * No one could seriously want to move planes in parallel from
242 while (nxtitem(&nstr, (s_char *)&plane)) {
245 type = plane.pln_type;
246 if (plane.pln_ship >= 0) {
247 pr("%s is at sea and can't be transported\n",
250 } else if (plane.pln_harden != 0) {
251 pr("%s has been hardened and can't be transported\n",
254 } else if ((plane.pln_flags & PLN_LAUNCHED) &&
255 (plchr[type].pl_flags & P_O)) {
256 pr("%s is in space and can't be transported\n",
265 if (plane.pln_x != srcx || plane.pln_y != srcy) {
266 pr("All planes must be in the same sector.\n");
270 weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
277 getsect(srcx, srcy, §);
279 * military control necessary to move
280 * goodies in occupied territory.
282 if (sect.sct_oldown != player->cnum){
286 snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
287 while (nxtitem(&ni, (s_char *)&land))
288 tot_mil += total_mil(&land);
289 if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR)+tot_mil) * 10
290 < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) {
291 pr("Military control required to move goods.\n");
296 mcost = move_ground((s_char *)&plane, §, &endsect,
297 (double)sect.sct_mobil, (double)weight,
298 player->argp[3], tran_map, 0, &dam);
303 dstx = endsect.sct_x;
304 dsty = endsect.sct_y;
305 snxtitem_rewind(&nstr);
306 while (nxtitem(&nstr, (s_char *)&plane)) {
310 planedamage(&plane,dam);
311 pr("\t%s takes %d\n",
317 plane.pln_mission = 0;
318 putplane(plane.pln_uid, &plane);
321 pr("Total movement cost = %d\n",mcost);
323 pr("No mobility used\n");
324 sect.sct_mobil -= mcost;
325 if (sect.sct_mobil < 0)
332 * Pretty tacky, but it works.
333 * If more commands start doing this, then
334 * rewrite map to do the right thing.
336 /* I think this is no longer used, check subs/move.c:move_ground() */
339 tran_map(s_char *what, coord curx, coord cury, s_char *arg)
341 player->argp[1] = arg;