]> git.pond.sub.org Git - empserver/blob - src/lib/commands/arm.c
(arm, tran_nuke): Lookup of the nuke name was broken by nuke.h
[empserver] / src / lib / commands / arm.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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 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.
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 <string.h>
37 #include "misc.h"
38 #include "player.h"
39 #include "nuke.h"
40 #include "plane.h"
41 #include "xy.h"
42 #include "nsc.h"
43 #include "file.h"
44 #include "commands.h"
45 #include "optlist.h"
46
47 int
48 arm(void)
49 {
50     struct nchrstr *ncp;
51     struct plchrstr *plc;
52     struct plnstr pl;
53     struct plnstr start;        /* Used for sanity checking */
54     struct nukstr nuke;
55     s_char *p;
56     int pno;
57     int nuketype;
58     int found;
59     struct nstr_item ni;
60     s_char buf[1024];
61     int disarm = **player->argp == 'd';
62     s_char *prompt = disarm ? "Disarm plane: " : "Arm plane: ";
63
64     if (!(p = getstarg(player->argp[1], prompt, buf)) || !*p)
65         return RET_SYN;
66     pno = atoi(p);
67     if (pno < 0 || !getplane(pno, &pl) || pl.pln_own != player->cnum)
68         return RET_FAIL;
69     memcpy(&start, &pl, sizeof(struct plnstr));
70     plc = &plchr[(int)pl.pln_type];
71     if ((plc->pl_flags & (P_O | P_M)) == (P_O | P_M)) {
72         pr("A %s cannot carry nuclear devices!\n", plc->pl_name);
73         return RET_FAIL;
74     }
75     if (opt_MARKET) {
76         if (ontradingblock(EF_PLANE, (int *)&pl)) {
77             pr("You cannot arm/disarm an item on the trading block!\n");
78             return RET_FAIL;
79         }
80     }
81     if (pl.pln_nuketype == -1) {
82         if (disarm) {
83             pr("%s is not carrying any nuclear devices\n", prplane(&pl));
84             return RET_FAIL;
85         }
86         if ((p = getstarg(player->argp[2], "Device type: ", buf)) == 0)
87             return RET_SYN;
88         if (!check_plane_ok(&start))
89             return RET_FAIL;
90         nuketype = typematch(p, EF_NUKE);
91         if (nuketype < 0) {
92             pr("No such nuke type!\n");
93             return RET_SYN;
94         }
95         ncp = &nchr[nuketype];
96         found = 0;
97         snxtitem_xy(&ni, EF_NUKE, pl.pln_x, pl.pln_y);
98         while (nxtitem(&ni, &nuke)) {
99             if (nuke.nuk_own == player->cnum) {
100                 found = 1;
101                 break;
102             }
103         }
104         if (!found) {
105             pr("You don't own any nukes in that sector.\n");
106             return RET_FAIL;
107         }
108         if (nuke.nuk_types[nuketype] == 0) {
109             pr("No nukes of that type in that sector.\n");
110             return RET_FAIL;
111         }
112         if (pl.pln_load < ncp->n_weight) {
113             pr("A %s cannot carry %s devices!\n", plc->pl_name,
114                ncp->n_name);
115             return RET_FAIL;
116         }
117         p = getstarg(player->argp[3], "Airburst [n]? ", buf);
118
119         if (!check_plane_ok(&start))
120             return RET_FAIL;
121
122         if (p && (*p == 'y' || *p == 'Y'))
123             pl.pln_flags |= PLN_AIRBURST;
124         else
125             pl.pln_flags &= ~PLN_AIRBURST;
126
127         pl.pln_nuketype = nuketype;
128         nuk_delete(&nuke, nuketype, 1);
129     } else if (!disarm) {
130         pr("%s already carrying a warhead.\n", prplane(&pl));
131     }
132     if (disarm) {
133         pr("%s warhead removed from %s and added to %s\n",
134            nchr[(int)pl.pln_nuketype].n_name,
135            prplane(&pl), xyas(pl.pln_x, pl.pln_y, player->cnum));
136         nuk_add(pl.pln_x, pl.pln_y, pl.pln_nuketype, 1);
137         pl.pln_nuketype = -1;
138         pl.pln_flags &= ~PLN_AIRBURST;
139     } else {
140         pr("%s armed with a %s warhead.\n", prplane(&pl),
141            nchr[(int)pl.pln_nuketype].n_name);
142         pr("Warhead on %s is programmed to %s\n",
143            prplane(&pl),
144            pl.pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
145     }
146
147     putplane(pl.pln_uid, &pl);
148     return RET_OK;
149 }