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