]> git.pond.sub.org Git - empserver/blob - src/lib/commands/hard.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / hard.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  *  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 "misc.h"
37 #include "player.h"
38 #include "sect.h"
39 #include "item.h"
40 #include "plane.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
69         || *p == 0)
70         return RET_SYN;
71     level = atoi(p);
72     if (level < 0)
73         return RET_SYN;
74     natp = getnatp(player->cnum);
75     cash = natp->nat_money;
76     while (nxtitem(&ni, &pln)) {
77         if (!player->owner)
78             continue;
79         pcp = &plchr[(int)pln.pln_type];
80         if ((pcp->pl_flags & P_M) == 0) {
81             pr("%s isn't a missile!\n", prplane(&pln));
82             continue;
83         }
84         if (pln.pln_ship >= 0)  /* can't harden ssbns ... */
85             continue;
86         n = level;
87         if (level + pln.pln_harden > 127)
88             n = 127 - pln.pln_harden;
89         if (n <= 0) {
90             pr("%s is already completely hardened!\n", prplane(&pln));
91             continue;
92         }
93         if (!getsect(pln.pln_x, pln.pln_y, &sect))
94             continue;
95         if (sect.sct_own != player->cnum) {
96             pr("%s: you don't own %s!\n",
97                prplane(&pln), xyas(pln.pln_x, pln.pln_y, player->cnum));
98             continue;
99         }
100         hcm = sect.sct_item[I_HCM];
101         if (hcm == 0) {
102             pr("No hcm in %s\n", xyas(pln.pln_x, pln.pln_y, player->cnum));
103             continue;
104         }
105         if (player->dolcost + 5.0 * n > cash) {
106             pr("You don't have enough money to harden %s!\n",
107                prplane(&pln));
108             continue;
109         }
110         if (hcm <= n)
111             n = hcm;
112         pln.pln_harden += n;
113         player->dolcost += (5.0 * n);
114         putplane(pln.pln_uid, &pln);
115         sect.sct_item[I_HCM] = hcm - n;
116         putsect(&sect);
117         pr("%s hardened to %d\n", prplane(&pln), pln.pln_harden);
118     }
119     return RET_OK;
120 }