]> git.pond.sub.org Git - empserver/blob - src/lib/commands/rang.c
Don't store land unit stats in struct lndstr, part 2
[empserver] / src / lib / commands / rang.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, 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  *  rang.c: Edit range of plane/land unit
29  * 
30  *  Known contributors to this file:
31  *     Jeff Bailey
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37 #include "land.h"
38 #include "plane.h"
39
40 int
41 range(void)
42 {
43     struct nstr_item np;
44     struct plnstr plane;
45     int i, rmax;
46     char *p;
47     char buf[1024];
48
49     if (!snxtitem(&np, EF_PLANE, player->argp[1]))
50         return RET_SYN;
51     while (nxtitem(&np, &plane)) {
52         if (!player->owner || plane.pln_own == 0)
53             continue;
54         p = getstarg(player->argp[2], "New range? ", buf);
55         if (!check_plane_ok(&plane))
56             return RET_SYN;
57         if (!p || (i = atoi(p)) < 0)
58             continue;
59         rmax = pln_range_max(&plane);
60         plane.pln_range = MIN(rmax, i);
61         pr("Plane %d range changed to %d\n",
62            plane.pln_uid, plane.pln_range);
63
64         putplane(plane.pln_uid, &plane);
65     }
66
67     return RET_OK;
68 }
69
70 int
71 lrange(void)
72 {
73     struct nstr_item np;
74     struct lndstr land;
75     int i;
76     char *p;
77     char prompt[128];
78     char buf[1024];
79
80     if (!snxtitem(&np, EF_LAND, player->argp[1]))
81         return RET_SYN;
82     while (nxtitem(&np, &land)) {
83         if (!player->owner || land.lnd_own == 0)
84             continue;
85         sprintf(prompt, "New range for %s? ", prland(&land));
86         if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
87             return RET_SYN;
88         if (!check_land_ok(&land))
89             return RET_SYN;
90         if ((i = atoi(p)) < 0)
91             continue;
92         land.lnd_rad_max = MIN(i, lchr[land.lnd_type].l_rad);
93         pr("%s reaction radius changed to %d\n",
94            prland(&land), land.lnd_rad_max);
95         putland(land.lnd_uid, &land);
96     }
97
98     return RET_OK;
99 }