]> git.pond.sub.org Git - empserver/blob - src/lib/commands/fort.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / fort.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  *  fort.c: Increase the fortification value of land units
29  * 
30  *  Known contributors to this file:
31  *    Steve McClure, 1999
32  *     
33  */
34
35 #include <config.h>
36
37 #include "misc.h"
38 #include "player.h"
39 #include "land.h"
40 #include "nsc.h"
41 #include "file.h"
42 #include "commands.h"
43 #include "optlist.h"
44
45 int
46 fort(void)
47 {
48     int nunits;
49     struct nstr_item ni;
50     struct lndstr land;
51     int fort_amt, hard_amt;
52     s_char *p;
53     s_char buf[1024];
54
55     if (!snxtitem(&ni, EF_LAND, player->argp[1]))
56         return RET_SYN;
57     p = getstarg(player->argp[2], "Amount: ", buf);
58     if (p == 0 || *p == 0)
59         return RET_SYN;
60     fort_amt = atoi(p);
61     if (fort_amt > land_mob_max)
62         fort_amt = land_mob_max;
63     nunits = 0;
64     while (nxtitem(&ni, &land)) {
65         if (!player->owner || land.lnd_own == 0)
66             continue;
67         getland(land.lnd_uid, &land);
68         if (land.lnd_mobil < 0)
69             continue;
70         if (land.lnd_ship >= 0) {
71             pr("%s is on a ship and can't be fortified\n", prland(&land));
72             continue;
73         }
74         if (land.lnd_land >= 0) {
75             pr("%s is on a land unit and can't be fortified\n", prland(&land));
76             continue;
77         }
78
79         hard_amt = fort_amt;
80
81         /* This is use for things like "fort * -67" which will
82            use all mobility down to leaving 67 left. */
83         if (hard_amt < 0) {
84             hard_amt = land.lnd_mobil + hard_amt;
85             if (hard_amt < 0)
86                 continue;
87         }
88
89         if (lnd_fortify (&land, hard_amt) <= 0) {
90             pr("%s can't be fortified%s\n", prland(&land),
91                land.lnd_harden >= land_mob_max ? " any further" : "");
92             continue;
93         }
94
95         nunits++;
96         pr("%s hardened to %d\n", prland(&land), land.lnd_harden);
97
98         putland(land.lnd_uid, &land);
99     }
100     if (nunits == 0) {
101         if (player->argp[1])
102             pr("%s: No unit(s)\n", player->argp[1]);
103         else
104             pr("%s: No unit(s)\n", "");
105         return RET_FAIL;
106     } else
107         pr("%d unit%s\n", nunits, splur(nunits));
108     return RET_OK;
109 }