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:
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) {
105 if (!snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y)) {
106 pr("There are no nukes in %s\n",
107 xyas(sect.sct_x, sect.sct_y, player->cnum));
111 snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y);
114 while (nxtitem(&nstr, (caddr_t)&nuke)) {
121 pr("There are no nukes in %s\n",
122 xyas(sect.sct_x, sect.sct_y, player->cnum));
125 if (!(p = getstarg(player->argp[3], "warhead type : ", buf)))
127 if (!check_sect_ok(§))
130 for (i = 0, ncp = nchr; i < N_MAXNUKE; i++, ncp++) {
131 if (strncmp(ncp->n_name, p, len) == 0)
134 if (i >= N_MAXNUKE) {
135 pr("No such nuke type!\n");
139 if (!nuke.nuk_types[nuketype]) {
140 pr("No %s nukes in %s\n",
141 ncp->n_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
144 p = getstarg(player->argp[4], "number of warheads : ", buf);
145 if (!check_sect_ok(§))
147 if (p == 0 || *p == 0 || (moving = atoi(p)) < 0)
149 if (moving > nuke.nuk_types[nuketype]) {
150 moving = nuke.nuk_types[nuketype];
152 pr("only moving %d\n", moving);
157 * military control necessary to move
158 * goodies in occupied territory.
160 if (sect.sct_oldown != player->cnum) {
164 snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
165 while (nxtitem(&ni, (s_char *)&land)) {
166 if (land.lnd_own == player->cnum)
167 tot_mil += total_mil(&land);
169 if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR) + tot_mil) * 10
170 < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) {
171 pr("Military control required to move goods.\n");
176 mcost = move_ground((s_char *)&nuke, §, &endsect,
177 (double)ncp->n_weight * moving,
178 player->argp[5], tran_map, 0, &dam);
184 pr("Total movement cost = %d\n", mcost);
186 pr("No mobility used\n");
188 dstx = endsect.sct_x;
189 dsty = endsect.sct_y;
191 * decrement mobility from src sector
193 getsect(nuke.nuk_x, nuke.nuk_y, §);
194 sect.sct_mobil -= mcost;
195 if (sect.sct_mobil < 0)
201 if (!getnuke(nuke.nuk_uid, &nuke)) {
202 pr("Could not find that stockpile again.\n");
205 if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) {
206 pr("Stockpile changed!\n");
209 nuk_delete(&nuke, nuketype, moving);
210 nuk_add(dstx, dsty, nuketype, moving);
223 struct nstr_item nstr;
226 struct sctstr endsect;
231 if (!snxtitem(&nstr, EF_PLANE, player->argp[2]))
234 * First do some sanity checks: make sure that they are all in the,
235 * same sector, not on ships, owned, etc.
236 * No one could seriously want to move planes in parallel from
239 while (nxtitem(&nstr, (s_char *)&plane)) {
242 type = plane.pln_type;
243 if (plane.pln_ship >= 0) {
244 pr("%s is at sea and can't be transported\n", prplane(&plane));
246 } else if (plane.pln_harden != 0) {
247 pr("%s has been hardened and can't be transported\n",
250 } else if ((plane.pln_flags & PLN_LAUNCHED) &&
251 (plchr[type].pl_flags & P_O)) {
252 pr("%s is in space and can't be transported\n",
261 if (plane.pln_x != srcx || plane.pln_y != srcy) {
262 pr("All planes must be in the same sector.\n");
266 weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
273 getsect(srcx, srcy, §);
275 * military control necessary to move
276 * goodies in occupied territory.
278 if (sect.sct_oldown != player->cnum) {
282 snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
283 while (nxtitem(&ni, (s_char *)&land))
284 tot_mil += total_mil(&land);
285 if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR) + tot_mil) * 10
286 < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) {
287 pr("Military control required to move goods.\n");
292 mcost = move_ground((s_char *)&plane, §, &endsect,
294 player->argp[3], tran_map, 0, &dam);
299 dstx = endsect.sct_x;
300 dsty = endsect.sct_y;
301 snxtitem_rewind(&nstr);
302 while (nxtitem(&nstr, (s_char *)&plane)) {
306 planedamage(&plane, dam);
307 pr("\t%s takes %d\n", prplane(&plane), dam);
311 plane.pln_mission = 0;
312 putplane(plane.pln_uid, &plane);
315 pr("Total movement cost = %d\n", mcost);
317 pr("No mobility used\n");
318 sect.sct_mobil -= mcost;
319 if (sect.sct_mobil < 0)
326 * Pretty tacky, but it works.
327 * If more commands start doing this, then
328 * rewrite map to do the right thing.
330 /* I think this is no longer used, check subs/move.c:move_ground() */
333 tran_map(s_char *what, coord curx, coord cury, s_char *arg)
335 player->argp[1] = arg;