2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * tran.c: Transport nuclear devices and planes
30 * Known contributors to this file:
32 * Markus Armbruster, 2006
43 static int tran_pmap(coord curx, coord cury, char *arg);
44 static int tran_nmap(coord curx, coord cury, char *arg);
45 static int tran_nuke(void);
46 static int tran_plane(void);
54 what = getstarg(player->argp[1], "transport what (nuke or plane): ",
60 else if (*what == 'p')
73 struct nstr_item nstr;
76 struct sctstr endsect;
80 if (!snxtitem(&nstr, EF_NUKE, player->argp[2], NULL))
82 while (nxtitem(&nstr, &nuke)) {
86 if (nuke.nuk_plane >= 0) {
87 pr("%s is armed and can't be transported\n", prnuke(&nuke));
94 if (nuke.nuk_x != srcx || nuke.nuk_y != srcy) {
95 pr("All nukes must be in the same sector.\n");
99 weight += nchr[type].n_weight;
106 if (!getsect(srcx, srcy, §) || !player->owner) {
107 pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
110 if (!military_control(§)) {
111 pr("Military control required to move nukes.\n");
115 mcost = move_ground(§, &endsect, weight,
116 player->argp[3], tran_nmap, 0, &dam);
120 dstx = endsect.sct_x;
121 dsty = endsect.sct_y;
122 snxtitem_rewind(&nstr);
123 while (nxtitem(&nstr, &nuke)) {
129 nuke.nuk_mission = 0;
130 putnuke(nuke.nuk_uid, &nuke);
133 pr("Total movement cost = %d\n", mcost);
135 pr("No mobility used\n");
136 getsect(srcx, srcy, §);
137 sect.sct_mobil -= mcost;
138 if (sect.sct_mobil < 0)
152 struct nstr_item nstr;
155 struct sctstr endsect;
159 if (!snxtitem(&nstr, EF_PLANE, player->argp[2], NULL))
162 * First do some sanity checks: make sure that they are all in the,
163 * same sector, not on ships, owned, etc.
164 * No one could seriously want to move planes in parallel from
167 while (nxtitem(&nstr, &plane)) {
170 type = plane.pln_type;
171 if (plane.pln_ship >= 0) {
172 pr("%s is at sea and can't be transported\n", prplane(&plane));
174 } else if (plane.pln_harden != 0) {
175 pr("%s has been hardened and can't be transported\n",
178 } else if (pln_is_in_orbit(&plane)) {
179 pr("%s is in space and can't be transported\n",
187 if (plane.pln_x != srcx || plane.pln_y != srcy) {
188 pr("All planes must be in the same sector.\n");
192 weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
199 if (!getsect(srcx, srcy, §) || !player->owner) {
200 pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
203 if (!military_control(§)) {
204 pr("Military control required to move planes.\n");
208 mcost = move_ground(§, &endsect, weight,
209 player->argp[3], tran_pmap, 0, &dam);
214 dstx = endsect.sct_x;
215 dsty = endsect.sct_y;
216 snxtitem_rewind(&nstr);
217 while (nxtitem(&nstr, &plane)) {
221 planedamage(&plane, dam);
224 plane.pln_mission = 0;
225 putplane(plane.pln_uid, &plane);
228 pr("Total movement cost = %d\n", mcost);
230 pr("No mobility used\n");
231 getsect(srcx, srcy, §);
232 sect.sct_mobil -= mcost;
233 if (sect.sct_mobil < 0)
240 * Pretty tacky, but it works.
241 * If more commands start doing this, then
242 * rewrite map to do the right thing.
246 tran_pmap(coord curx, coord cury, char *arg)
248 return display_region_map(0, EF_PLANE, curx, cury, arg);
252 tran_nmap(coord curx, coord cury, char *arg)
254 return display_region_map(0, EF_NUKE, curx, cury, arg);