]> git.pond.sub.org Git - empserver/blob - src/lib/commands/rang.c
517829601d68878d05f102cb0c6808dd594d4a62
[empserver] / src / lib / commands / rang.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  *  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;
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         plane.pln_range = (plane.pln_range_max < i) ?
60             plane.pln_range_max : 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     struct lchrstr *lcp;
76     int i;
77     char *p;
78     char prompt[128];
79     char buf[1024];
80
81     if (!snxtitem(&np, EF_LAND, player->argp[1]))
82         return RET_SYN;
83     while (nxtitem(&np, &land)) {
84         if (!player->owner || land.lnd_own == 0)
85             continue;
86         lcp = &lchr[(int)land.lnd_type];
87         sprintf(prompt, "New range for %s? ", prland(&land));
88         if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
89             return RET_SYN;
90         if (!check_land_ok(&land))
91             return RET_SYN;
92         if ((i = atoi(p)) < 0)
93             continue;
94         land.lnd_rad_max = (i < land.lnd_rad) ? i : land.lnd_rad;
95         pr("%s reaction radius changed to %d\n",
96            prland(&land), land.lnd_rad_max);
97         putland(land.lnd_uid, &land);
98     }
99
100     return RET_OK;
101 }