]> git.pond.sub.org Git - empserver/blob - src/lib/commands/arm.c
Change nuke storage and commands to match other units:
[empserver] / src / lib / commands / arm.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  arm.c: Arm planes (missiles) with nuclear devices
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  *     Ken Stevens, 1995
33  *     Steve McClure, 2000
34  */
35
36 #include <config.h>
37
38 #include <string.h>
39 #include "misc.h"
40 #include "player.h"
41 #include "nuke.h"
42 #include "plane.h"
43 #include "xy.h"
44 #include "nsc.h"
45 #include "file.h"
46 #include "commands.h"
47 #include "optlist.h"
48
49 int
50 arm(void)
51 {
52     struct nchrstr *ncp;
53     struct plchrstr *plc;
54     struct plnstr pl;
55     struct nukstr nuke;
56     char *p;
57     int pno, nukno;
58     struct nstr_item ni;
59     char buf[1024];
60     char prompt[128];
61
62     if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
63         return RET_SYN;
64     while (nxtitem(&ni, &pl)) {
65         if (!player->owner)
66             continue;
67         plc = &plchr[(int)pl.pln_type];
68         if ((plc->pl_flags & (P_O | P_M)) == (P_O | P_M)) {
69             pr("A %s cannot carry nuclear devices!\n", plc->pl_name);
70             return RET_FAIL;
71         }
72         if (opt_MARKET) {
73             if (ontradingblock(EF_PLANE, &pl)) {
74                 pr("You cannot disarm %s while it is on the trading block!\n",
75                    prplane(&pl));
76                 return RET_FAIL;
77             }
78         }
79         if (pl.pln_nuketype < 0) {
80             sprintf(prompt, "Nuclear device for %s: ", prplane(&pl));
81             p = getstarg(player->argp[2], prompt, buf);
82             if (!p || !*p)
83                 return RET_SYN;
84             if (!check_plane_ok(&pl))
85                 return RET_FAIL;
86             nukno = atoi(p);
87             if (!getnuke(nukno, &nuke) || !player->owner)
88                 return RET_FAIL;
89         } else {
90             if (nuk_on_plane(&nuke, pl.pln_uid) < 0) {
91                 CANT_REACH();
92                 continue;
93             }
94         }
95         ncp = &nchr[nuke.nuk_type];
96         if (pl.pln_load < ncp->n_weight) {
97             pr("A %s cannot carry %s devices!\n",
98                plc->pl_name, ncp->n_name);
99             return RET_FAIL;
100         }
101         p = getstarg(player->argp[3], "Airburst [n]? ", buf);
102
103         if (!check_plane_ok(&pl) || !check_nuke_ok(&nuke))
104             return RET_FAIL;
105
106         if (p && (*p == 'y' || *p == 'Y'))
107             pl.pln_flags |= PLN_AIRBURST;
108         else
109             pl.pln_flags &= ~PLN_AIRBURST;
110
111         pl.pln_nuketype = nuke.nuk_type;
112         nuke.nuk_plane = pl.pln_uid;
113         putplane(pl.pln_uid, &pl);
114         putnuke(nuke.nuk_uid, &nuke);
115         pr("%s armed with %s.\n", prplane(&pl), prnuke(&nuke));
116         pr("Warhead on %s is programmed to %s\n",
117            prplane(&pl),
118            pl.pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
119     }
120
121     return RET_OK;
122 }
123
124 int
125 disarm(void)
126 {
127     struct plnstr pl;
128     struct nukstr nuke;
129     struct nstr_item ni;
130
131     if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
132         return RET_SYN;
133     while (nxtitem(&ni, &pl)) {
134         if (!player->owner)
135             continue;
136         if (pl.pln_nuketype == -1)
137             continue;
138         if (opt_MARKET) {
139             if (ontradingblock(EF_PLANE, &pl)) {
140                 pr("You cannot disarm %s while it is on the trading block!\n",
141                    prplane(&pl));
142                 return RET_FAIL;
143             }
144         }
145         if (nuk_on_plane(&nuke, pl.pln_uid) < 0) {
146             CANT_REACH();
147             continue;
148         }
149         nuke.nuk_plane = -1;
150         pl.pln_nuketype = -1;
151         pl.pln_flags &= ~PLN_AIRBURST;
152         putplane(pl.pln_uid, &pl);
153         putnuke(nuke.nuk_uid, &nuke);
154         pr("%s removed from %s and added to %s\n",
155            prnuke(&nuke), prplane(&pl),
156            xyas(pl.pln_x, pl.pln_y, player->cnum));
157     }
158     return RET_OK;
159 }