]> git.pond.sub.org Git - empserver/blob - src/lib/commands/hard.c
Do not include var.h where no longer needed. Clean up register keywords in these...
[empserver] / src / lib / commands / hard.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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  *  hard.c: Increases the silo protection of a given missile
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "sect.h"
37 #include "item.h"
38 #include "plane.h"
39 #include "nuke.h"
40 #include "ship.h"
41 #include "xy.h"
42 #include "nsc.h"
43 #include "nat.h"
44 #include "file.h"
45 #include "commands.h"
46
47 /*
48  * harden <PLANE> <LEVEL>
49  */
50 int
51 hard(void)
52 {
53     struct plchrstr *pcp;
54     struct plnstr pln;
55     int level;
56     s_char *p;
57     int hcm;
58     int n;
59     struct nstr_item ni;
60     struct sctstr sect;
61     s_char buf[1024];
62     long cash;
63     struct natstr *natp;
64
65     if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
66         return RET_SYN;
67     if ((p = getstarg(player->argp[2], "Increase by? ", buf)) == 0
68         || *p == 0)
69         return RET_SYN;
70     level = atoi(p);
71     if (level < 0)
72         return RET_SYN;
73     natp = getnatp(player->cnum);
74     cash = natp->nat_money;
75     while (nxtitem(&ni, (s_char *)&pln)) {
76         if (!player->owner)
77             continue;
78         pcp = &plchr[(int)pln.pln_type];
79         if ((pcp->pl_flags & P_M) == 0) {
80             pr("%s isn't a missile!\n", prplane(&pln));
81             continue;
82         }
83         if (pln.pln_ship >= 0)  /* can't harden ssbns ... */
84             continue;
85         n = level;
86         if (level + pln.pln_harden > 127)
87             n = 127 - pln.pln_harden;
88         if (n <= 0) {
89             pr("%s is already completely hardened!\n", prplane(&pln));
90             continue;
91         }
92         if (!getsect(pln.pln_x, pln.pln_y, &sect))
93             continue;
94         if (sect.sct_own != player->cnum) {
95             pr("%s: you don't own %s!\n",
96                prplane(&pln), xyas(pln.pln_x, pln.pln_y, player->cnum));
97             continue;
98         }
99         hcm = sect.sct_item[I_HCM];
100         if (hcm == 0) {
101             pr("No hcm in %s\n", xyas(pln.pln_x, pln.pln_y, player->cnum));
102             continue;
103         }
104         if (player->dolcost + 5.0 * n > cash) {
105             pr("You don't have enough money to harden %s!\n",
106                prplane(&pln));
107             continue;
108         }
109         if (hcm <= n)
110             n = hcm;
111         pln.pln_harden += n;
112         player->dolcost += (5.0 * n);
113         putplane(pln.pln_uid, &pln);
114         sect.sct_item[I_HCM] = hcm - n;
115         putsect(&sect);
116         pr("%s hardened to %d\n", prplane(&pln), pln.pln_harden);
117     }
118     return RET_OK;
119 }