]> git.pond.sub.org Git - empserver/blob - src/lib/commands/hard.c
Import of Empire 4.2.12
[empserver] / src / lib / commands / hard.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 "var.h"
37 #include "sect.h"
38 #include "item.h"
39 #include "plane.h"
40 #include "nuke.h"
41 #include "ship.h"
42 #include "xy.h"
43 #include "nsc.h"
44 #include "nat.h"
45 #include "file.h"
46 #include "commands.h"
47
48 /*
49  * harden <PLANE> <LEVEL>
50  */
51 int
52 hard(void)
53 {
54         struct  plchrstr *pcp;
55         struct  plnstr pln;
56         int     level;
57         s_char  *p;
58         int     hcm;
59         int     n;
60         struct  nstr_item ni;
61         struct  sctstr sect;
62         s_char  buf[1024];
63         long    cash;
64         struct natstr *natp;
65
66         if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
67                 return RET_SYN;
68         if ((p = getstarg(player->argp[2], "Increase by? ", buf)) == 0 || *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),
97                            xyas(pln.pln_x, pln.pln_y, player->cnum));
98                         continue;
99                 }
100                 hcm = getvar(V_HCM, (s_char *)&sect, EF_SECTOR);
101                 if (hcm == 0) {
102                         pr("No hcm in %s\n",
103                                 xyas(pln.pln_x, pln.pln_y, player->cnum));
104                         continue;
105                 }
106                 if (player->dolcost + 5.0 * n > cash) {
107                         pr("You don't have enough money to harden %s!\n",
108                            prplane(&pln));
109                         continue;
110                 }
111                 if (hcm <= n)
112                         n = hcm;
113                 pln.pln_harden += n;
114                 player->dolcost += (5.0 * n);
115                 putplane(pln.pln_uid, &pln);
116                 putvar(V_HCM, hcm - n, (s_char *)&sect, EF_SECTOR);
117                 putsect(&sect);
118                 pr("%s hardened to %d\n", prplane(&pln), pln.pln_harden);
119         }
120         return RET_OK;
121 }