2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * tran.c: Transport nuclear devices and planes
29 * Known contributors to this file:
31 * Markus Armbruster, 2006-2009
42 static int tran_pmap(coord curx, coord cury, char *arg);
43 static int tran_nmap(coord curx, coord cury, char *arg);
44 static int tran_nuke(void);
45 static int tran_plane(void);
53 what = getstarg(player->argp[1], "transport what (nuke or plane): ",
59 else if (*what == 'p')
72 struct nstr_item nstr;
75 struct sctstr endsect;
79 if (!snxtitem(&nstr, EF_NUKE, player->argp[2], NULL))
81 while (nxtitem(&nstr, &nuke)) {
85 if (nuke.nuk_plane >= 0) {
86 pr("%s is armed and can't be transported\n", prnuke(&nuke));
93 if (nuke.nuk_x != srcx || nuke.nuk_y != srcy) {
94 pr("All nukes must be in the same sector.\n");
98 weight += nchr[type].n_weight;
105 if (!getsect(srcx, srcy, §) || !player->owner) {
106 pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
109 if (!military_control(§)) {
110 pr("Military control required to move nukes.\n");
114 mcost = move_ground(§, &endsect, weight,
115 player->argp[3], tran_nmap, 0, &dam);
119 dstx = endsect.sct_x;
120 dsty = endsect.sct_y;
121 snxtitem_rewind(&nstr);
122 while (nxtitem(&nstr, &nuke)) {
128 nuke.nuk_mission = 0;
129 putnuke(nuke.nuk_uid, &nuke);
132 pr("Total movement cost = %d\n", mcost);
134 pr("No mobility used\n");
135 getsect(srcx, srcy, §);
136 if (sect.sct_mobil >= mcost)
137 sect.sct_mobil -= mcost;
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 if (sect.sct_mobil >= mcost)
233 sect.sct_mobil -= mcost;
241 * Pretty tacky, but it works.
242 * If more commands start doing this, then
243 * rewrite map to do the right thing.
247 tran_pmap(coord curx, coord cury, char *arg)
249 return display_region_map(0, EF_PLANE, curx, cury, arg);
253 tran_nmap(coord curx, coord cury, char *arg)
255 return display_region_map(0, EF_NUKE, curx, cury, arg);