]> git.pond.sub.org Git - empserver/blob - src/lib/commands/edit.c
edit: Limit resources to 100 instead of 127
[empserver] / src / lib / commands / edit.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  edit.c: Edit things (sectors, ships, planes, units, nukes, countries)
28  *
29  *  Known contributors to this file:
30  *     David Muir Sharnoff
31  *     Chad Zabel, 1994
32  *     Steve McClure, 1998-2000
33  *     Ron Koenderink, 2003-2009
34  *     Markus Armbruster, 2003-2013
35  */
36
37 #include <config.h>
38
39 #include <ctype.h>
40 #include <limits.h>
41 #include "commands.h"
42 #include "item.h"
43 #include "land.h"
44 #include "news.h"
45 #include "optlist.h"
46 #include "plague.h"
47 #include "plane.h"
48 #include "ship.h"
49
50 static void print_sect(struct sctstr *);
51 static void print_nat(struct natstr *);
52 static void print_plane(struct plnstr *);
53 static void print_land(struct lndstr *);
54 static void print_ship(struct shpstr *);
55 static char *getin(char *, char **);
56 static int edit_sect(struct sctstr *, char *, int, char *);
57 static int edit_nat(struct natstr *, char *, int, char *);
58 static int edit_ship(struct shpstr *, char *, int, char *);
59 static int edit_land(struct lndstr *, char *, int, char *);
60 static int edit_plane(struct plnstr *, char *, int, char *);
61
62 int
63 edit(void)
64 {
65     struct sctstr sect;
66     struct plnstr plane;
67     struct shpstr ship;
68     struct lndstr land;
69     char *what;
70     char *key, *ptr;
71     int num;
72     int arg;
73     int err;
74     int arg_index = 3;
75     coord x, y;
76     struct natstr *np;
77     char buf[1024];
78     char ewhat;
79
80     what = getstarg(player->argp[1],
81                     "Edit what (country, land, ship, plane, nuke, unit)? ",
82                     buf);
83     if (!what)
84         return RET_SYN;
85     ewhat = what[0];
86     switch (ewhat) {
87     case 'l':
88         if (!(ptr = getstarg(player->argp[2], "Sector : ", buf)))
89             return RET_FAIL;
90         if (!sarg_xy(ptr, &x, &y))
91             return RET_FAIL;
92         if (!getsect(x, y, &sect))
93             return RET_FAIL;
94         break;
95     case 'c':
96         np = natargp(player->argp[2], "Country? ");
97         if (!np)
98             return RET_SYN;
99         break;
100     case 'p':
101         if ((num = onearg(player->argp[2], "Plane number? ")) < 0)
102             return RET_SYN;
103         if (!getplane(num, &plane))
104             return RET_SYN;
105         break;
106     case 's':
107         if ((num = onearg(player->argp[2], "Ship number? ")) < 0)
108             return RET_SYN;
109         if (!getship(num, &ship))
110             return RET_SYN;
111         break;
112     case 'u':
113         if ((num = onearg(player->argp[2], "Unit number? ")) < 0)
114             return RET_SYN;
115         if (!getland(num, &land))
116             return RET_SYN;
117         break;
118     case 'n':
119         pr("Not implemented yet.\n");
120         break;
121     default:
122         pr("huh?\n");
123         return RET_SYN;
124     }
125     if (!player->argp[3]) {
126         switch (ewhat) {
127         case 'l':
128             print_sect(&sect);
129             break;
130         case 'c':
131             print_nat(np);
132             break;
133         case 'p':
134             print_plane(&plane);
135             break;
136         case 's':
137             print_ship(&ship);
138             break;
139         case 'u':
140             print_land(&land);
141             break;
142         }
143     }
144     for (;;) {
145         if (player->argp[arg_index]) {
146             if (player->argp[arg_index+1]) {
147                 key = player->argp[arg_index++];
148                 ptr = player->argp[arg_index++];
149                 arg = atoi(ptr);
150             } else
151                 return RET_SYN;
152         } else if (arg_index == 3) {
153             key = getin(buf, &ptr);
154             if (!key)
155                 return RET_SYN;
156             if (!*key) {
157                 switch (ewhat) {
158                 case 'c':
159                     print_nat(np);
160                     break;
161                 case 'l':
162                     print_sect(&sect);
163                     break;
164                 case 's':
165                     print_ship(&ship);
166                     break;
167                 case 'u':
168                     print_land(&land);
169                     break;
170                 case 'p':
171                     print_plane(&plane);
172                     break;
173                 }
174                 return RET_OK;
175             }
176             arg = atoi(ptr);
177         } else
178             return RET_OK;
179
180         switch (ewhat) {
181         case 'c':
182             if ((err = edit_nat(np, key, arg, ptr)) != RET_OK)
183                 return err;
184             break;
185         case 'l':
186             if (!check_sect_ok(&sect))
187                 return RET_FAIL;
188             if ((err = edit_sect(&sect, key, arg, ptr)) != RET_OK)
189                 return err;
190             if (!putsect(&sect))
191                 return RET_FAIL;
192             break;
193         case 's':
194             if (!check_ship_ok(&ship))
195                 return RET_FAIL;
196             if ((err = edit_ship(&ship, key, arg, ptr)) != RET_OK)
197                 return err;
198             if (!ef_ensure_space(EF_SHIP, ship.shp_uid, 50))
199                 return RET_FAIL;
200             if (!putship(ship.shp_uid, &ship))
201                 return RET_FAIL;
202             break;
203         case 'u':
204             if (!check_land_ok(&land))
205                 return RET_FAIL;
206             if ((err = edit_land(&land, key, arg, ptr)) != RET_OK)
207                 return err;
208             if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50))
209                 return RET_FAIL;
210             if (!putland(land.lnd_uid, &land))
211                 return RET_FAIL;
212             break;
213         case 'p':
214             if (!check_plane_ok(&plane))
215                 return RET_FAIL;
216             if ((err = edit_plane(&plane, key, arg, ptr)) != RET_OK)
217                 return err;
218             if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50))
219                 return RET_FAIL;
220             if (!putplane(plane.pln_uid, &plane))
221                 return RET_FAIL;
222             break;
223         }
224     }
225 }
226
227 static void
228 benefit(natid who, int goodness)
229 {
230     if (opt_GODNEWS && getnatp(who)->nat_stat != STAT_GOD && goodness)
231         nreport(player->cnum, goodness > 0 ? N_AIDS : N_HURTS, who, 1);
232 }
233
234 static void
235 noise(struct sctstr *sptr, char *name, int old, int new)
236 {
237     pr("%s of %s changed from %d to %d\n",
238        name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new);
239     if (sptr->sct_own && sptr->sct_own != player->cnum && new != old)
240         wu(0, sptr->sct_own,
241            "%s in %s was changed from %d to %d by an act of %s\n",
242            name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own),
243            old, new, cname(player->cnum));
244     benefit(sptr->sct_own, new - old);
245 }
246
247 static void
248 print_sect(struct sctstr *sect)
249 {
250     pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
251     pr("Distribution sector <D>: %s\n",
252        xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
253     pr("Designation <s>: %c\tNew designation <S>: %c\n",
254        dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
255     pr("own  oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
256     pr("  o   O   e   m   i   g   f   c   u   w   l   x   X   p     t    F     a\n");
257     pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
258        sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
259        sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
260        sect->sct_uran, sect->sct_work, sect->sct_loyal,
261        sect->sct_che, sect->sct_che_target,
262        sect->sct_pstage, sect->sct_ptime,
263        sect->sct_fallout, sect->sct_avail);
264
265     pr("Mines <M>: %d\n", sect->sct_mines);
266     pr("Road %% <R>: %d\t", sect->sct_road);
267     pr("Rail %% <r>: %d\t", sect->sct_rail);
268     pr("Defense %% <d>: %d\n", sect->sct_defense);
269 }
270
271 static void
272 print_nat(struct natstr *np)
273 {
274     int i;
275
276     pr("Country #: %2d\n", np->nat_cnum);
277     pr("Name <n>: %-20s\t", np->nat_cnam);
278     pr("Representative <r>: %-20s\n", np->nat_pnam);
279     pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
280     pr("Reserves <m>: %5d\n", np->nat_reserve);
281     pr("Capital <c>: %s\t\t",
282        xyas(np->nat_xcap, np->nat_ycap, player->cnum));
283     pr("Origin <o>: %3s\n",
284        xyas(np->nat_xorg, np->nat_yorg, player->cnum));
285     pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
286     pr("Seconds Used <u>: %3d\n", np->nat_timeused);
287     pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
288     pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
289     pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
290     pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
291     pr("Money <M>: $%6d\n", np->nat_money);
292     pr("Telegrams <t>: %6d\n", np->nat_tgms);
293     if (opt_HIDDEN) {
294         pr("Countries contacted: ");
295         for (i = 0; i < MAXNOC; i++) {
296             if (getcontact(np, i))
297                 pr("%d(%d) ", i, getcontact(np, i));
298         }
299         pr("\n");
300     }
301 }
302
303 static void
304 print_plane(struct plnstr *plane)
305 {
306     pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
307     pr("UID <U>: %d\t\t", plane->pln_uid);
308     pr("Owner <O>: %d\t\t", plane->pln_own);
309     pr("Location <l>: %s\n",
310        xyas(plane->pln_x, plane->pln_y, player->cnum));
311     pr("Efficiency <e>: %d\t", plane->pln_effic);
312     pr("Mobility <m>: %d\n", plane->pln_mobil);
313     pr("Tech <t>: %d\t\t", plane->pln_tech);
314     pr("Wing <w>: %.1s\n", &plane->pln_wing);
315     pr("Range <r>: %d\t\t", plane->pln_range);
316     pr("Flags <f>: %d\n", plane->pln_flags);
317     pr("Ship <s>: %d\t\t", plane->pln_ship);
318     pr("Land Unit <y>: %d\t", plane->pln_land);
319 }
320
321 static void
322 print_land(struct lndstr *land)
323 {
324     pr("%s %s\n", prnatid(land->lnd_own), prland(land));
325     pr("UID <U>: %d\n", land->lnd_uid);
326     pr("Owner <O>: %d\n", land->lnd_own);
327     pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
328     pr("Efficiency <e>: %d\t", land->lnd_effic);
329     pr("Mobility <M>: %d\n", land->lnd_mobil);
330     pr("Tech <t>: %d\t\t", land->lnd_tech);
331     pr("Army <a>: %.1s\n", &land->lnd_army);
332     pr("Fortification <F>: %d\t", land->lnd_harden);
333     pr("Land unit <Y>: %d\n", land->lnd_land);
334     pr("Ship <S>: %d\t\t", land->lnd_ship);
335     pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
336     pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
337        land->lnd_rpath, land->lnd_rflags);
338     pr("civ mil  uw food shl gun  pet  irn  dst  oil  lcm  hcm rad\n");
339     pr("  c   m   u    f   s   g    p    i    d    o    l    h   r\n");
340     pr("%3d", land->lnd_item[I_CIVIL]);
341     pr("%4d", land->lnd_item[I_MILIT]);
342     pr("%4d", land->lnd_item[I_UW]);
343     pr("%5d", land->lnd_item[I_FOOD]);
344     pr("%4d", land->lnd_item[I_SHELL]);
345     pr("%4d", land->lnd_item[I_GUN]);
346     pr("%5d", land->lnd_item[I_PETROL]);
347     pr("%5d", land->lnd_item[I_IRON]);
348     pr("%5d", land->lnd_item[I_DUST]);
349     pr("%5d", land->lnd_item[I_OIL]);
350     pr("%5d", land->lnd_item[I_LCM]);
351     pr("%5d", land->lnd_item[I_HCM]);
352     pr("%4d", land->lnd_item[I_RAD]);
353     pr("\n");
354 }
355
356 static void
357 print_ship(struct shpstr *ship)
358 {
359     pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
360     pr("UID <U>: %d\n", ship->shp_uid);
361     pr("Owner <O>: %d\t\t\t", ship->shp_own);
362     pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
363     pr("Tech <T>: %d\t\t\t", ship->shp_tech);
364     pr("Efficiency <E>: %d\n", ship->shp_effic);
365     pr("Mobility <M>: %d\t\t", ship->shp_mobil);
366     pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
367     pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
368        ship->shp_rpath, ship->shp_rflags);
369     pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
370     pr("Plague Time <b>: %d\n", ship->shp_ptime);
371     pr("civ mil  uw food shl gun  pet  irn  dst  oil  lcm  hcm rad\n");
372     pr("  c   m   u    f   s   g    p    i    d    o    l    h   r\n");
373     pr("%3d", ship->shp_item[I_CIVIL]);
374     pr("%4d", ship->shp_item[I_MILIT]);
375     pr("%4d", ship->shp_item[I_UW]);
376     pr("%5d", ship->shp_item[I_FOOD]);
377     pr("%4d", ship->shp_item[I_SHELL]);
378     pr("%4d", ship->shp_item[I_GUN]);
379     pr("%5d", ship->shp_item[I_PETROL]);
380     pr("%5d", ship->shp_item[I_IRON]);
381     pr("%5d", ship->shp_item[I_DUST]);
382     pr("%5d", ship->shp_item[I_OIL]);
383     pr("%5d", ship->shp_item[I_LCM]);
384     pr("%5d", ship->shp_item[I_HCM]);
385     pr("%4d", ship->shp_item[I_RAD]);
386     pr("\n");
387 }
388
389 static char *
390 getin(char *buf, char **valp)
391 {
392     char line[1024];
393     char *argp[128];
394     char *p;
395
396     *valp = NULL;
397     p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
398     if (!p)
399         return NULL;
400     switch (parse(p, buf, argp, NULL, NULL, NULL)) {
401     case 0:
402         return "";
403     case 1:
404         return NULL;
405     default:
406         *valp = argp[1];
407         return argp[0];
408     }
409 }
410
411 #if 0   /* not needed right now */
412 static void
413 warn_deprecated(char key)
414 {
415     pr("Key <%c> is deprecated and will go away in a future release\n", key);
416 }
417 #endif
418
419 static int
420 edit_sect(struct sctstr *sect, char *key, int arg, char *p)
421 {
422     coord newx, newy;
423     int new;
424
425     switch (*key) {
426     case 'o':
427         if (arg < 0 || arg >= MAXNOC)
428             return RET_SYN;
429         pr("Owner of %s changed from %s to %s.\n",
430            xyas(sect->sct_x, sect->sct_y, player->cnum),
431            prnatid(sect->sct_own), prnatid(arg));
432         if (arg == sect->sct_own)
433             break;
434         if (sect->sct_own && sect->sct_own != player->cnum) {
435             wu(0, sect->sct_own,
436                "Sector %s taken from you by an act of %s!\n",
437                xyas(sect->sct_x, sect->sct_y, sect->sct_own),
438                cname(player->cnum));
439         }
440         benefit(sect->sct_own, -1);
441         sect->sct_own = arg;
442         if (arg && arg != player->cnum) {
443             wu(0, arg,
444                "Sector %s given to you by an act of %s!\n",
445                xyas(sect->sct_x, sect->sct_y, arg),
446                cname(player->cnum));
447         }
448         benefit(arg, 1);
449         break;
450     case 'O':
451         if (arg < 0 || arg >= MAXNOC)
452             return RET_SYN;
453         pr("Old owner of %s changed from %s to %s.\n",
454            xyas(sect->sct_x, sect->sct_y, player->cnum),
455            prnatid(sect->sct_oldown), prnatid(arg));
456         sect->sct_oldown = arg;
457         break;
458     case 'e':
459         new = LIMIT_TO(arg, 0, 100);
460         noise(sect, "Efficiency", sect->sct_effic, new);
461         sect->sct_effic = new;
462         break;
463     case 'm':
464         new = LIMIT_TO(arg, -127, 127);
465         noise(sect, "Mobility", sect->sct_mobil, new);
466         sect->sct_mobil = new;
467         break;
468     case 'i':
469         new = LIMIT_TO(arg, 0, 100);
470         noise(sect, "Iron ore content", sect->sct_min, new);
471         sect->sct_min = (unsigned char)new;
472         break;
473     case 'g':
474         new = LIMIT_TO(arg, 0, 100);
475         noise(sect, "Gold content", sect->sct_gmin, new);
476         sect->sct_gmin = (unsigned char)new;
477         break;
478     case 'f':
479         new = LIMIT_TO(arg, 0, 100);
480         noise(sect, "Fertility", sect->sct_fertil, new);
481         sect->sct_fertil = (unsigned char)new;
482         break;
483     case 'c':
484         new = LIMIT_TO(arg, 0, 100);
485         noise(sect, "Oil content", sect->sct_oil, new);
486         sect->sct_oil = (unsigned char)new;
487         break;
488     case 'u':
489         new = LIMIT_TO(arg, 0, 100);
490         noise(sect, "Uranium content", sect->sct_uran, new);
491         sect->sct_uran = (unsigned char)new;
492         break;
493     case 'w':
494         new = LIMIT_TO(arg, 0, 100);
495         noise(sect, "Workforce percentage", sect->sct_work, new);
496         sect->sct_work = (unsigned char)new;
497         break;
498     case 'l':
499         new = LIMIT_TO(arg, 0, 127);
500         pr("Loyalty of %s changed from %d to %d\n",
501            xyas(sect->sct_x, sect->sct_y, player->cnum),
502            sect->sct_loyal, new);
503         sect->sct_loyal = (unsigned char)new;
504         break;
505     case 'x':
506         new = LIMIT_TO(arg, 0, CHE_MAX);
507         pr("Guerillas in %s changed from %d to %d\n",
508            xyas(sect->sct_x, sect->sct_y, player->cnum),
509            sect->sct_che, new);
510         sect->sct_che = new;
511         break;
512     case 'X':
513         if (arg < 0 || arg >= MAXNOC)
514             return RET_SYN;
515         pr("Che target of %s changed from %s to %s.\n",
516            xyas(sect->sct_x, sect->sct_y, player->cnum),
517            prnatid(sect->sct_che_target), prnatid(arg));
518         sect->sct_che_target = arg;
519         if (arg == 0)
520             sect->sct_che = 0;
521         break;
522     case 'p':
523         new = LIMIT_TO(arg, 0, PLG_EXPOSED);
524         pr("Plague stage of %s changed from %d to %d\n",
525            xyas(sect->sct_x, sect->sct_y, player->cnum),
526            sect->sct_pstage, new);
527         sect->sct_pstage = new;
528         break;
529     case 't':
530         new = LIMIT_TO(arg, 0, 32767);
531         pr("Plague time of %s changed from %d to %d\n",
532            xyas(sect->sct_x, sect->sct_y, player->cnum),
533            sect->sct_ptime, new);
534         sect->sct_ptime = new;
535         break;
536     case 'F':
537         new = LIMIT_TO(arg, 0, FALLOUT_MAX);
538         pr("Fallout for sector %s changed from %d to %d\n",
539            xyas(sect->sct_x, sect->sct_y, player->cnum),
540            sect->sct_fallout, new);
541         sect->sct_fallout = new;
542         break;
543     case 'a':
544         new = LIMIT_TO(arg, 0, 9999);
545         noise(sect, "Available workforce", sect->sct_avail, new);
546         sect->sct_avail = new;
547         break;
548     case 'M':
549         new = LIMIT_TO(arg, 0, MINES_MAX);
550         sect->sct_mines = new;
551         pr("Mines changed to %d\n", new);
552         break;
553     case 'L':
554         if (!sarg_xy(p, &newx, &newy))
555             return RET_SYN;
556         sect->sct_x = newx;
557         sect->sct_y = newy;
558         ef_set_uid(EF_SECTOR, &sect, XYOFFSET(newx, newy));
559         break;
560     case 'D':
561         if (!sarg_xy(p, &newx, &newy))
562             return RET_SYN;
563         pr("Distribution location for sector %s changed from %s to %s\n",
564            xyas(sect->sct_x, sect->sct_y, player->cnum),
565            xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
566            xyas(newx, newy, player->cnum));
567         sect->sct_dist_x = newx;
568         sect->sct_dist_y = newy;
569         break;
570     case 's':
571         new = sct_typematch(p);
572         if (new < 0)
573             return RET_SYN;
574         pr("Designation for sector %s changed from %c to %c\n",
575            xyas(sect->sct_x, sect->sct_y, player->cnum),
576            dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
577         set_coastal(sect, sect->sct_type, new);
578         sect->sct_type = new;
579         break;
580     case 'S':
581         new = sct_typematch(p);
582         if (new < 0)
583             return RET_SYN;
584         pr("New designation for sector %s changed from %c to %c\n",
585            xyas(sect->sct_x, sect->sct_y, player->cnum),
586            dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
587         sect->sct_newtype = new;
588         break;
589     case 'R':
590         new = LIMIT_TO(arg, 0, 100);
591         noise(sect, "Road percentage", sect->sct_road, new);
592         sect->sct_road = new;
593         break;
594     case 'r':
595         new = LIMIT_TO(arg, 0, 100);
596         noise(sect, "Rail percentage", sect->sct_rail, new);
597         sect->sct_rail = new;
598         break;
599     case 'd':
600         new = LIMIT_TO(arg, 0, 100);
601         noise(sect, "Defense percentage", sect->sct_defense, new);
602         sect->sct_defense = new;
603         break;
604     default:
605         pr("huh? (%s)\n", key);
606         return RET_SYN;
607     }
608     return RET_OK;
609 }
610
611 static int
612 edit_nat(struct natstr *np, char *key, int arg, char *p)
613 {
614     coord newx, newy;
615     natid nat = np->nat_cnum;
616     float farg = (float)atof(p);
617
618     switch (*key) {
619     case 'n':
620         if (!check_nat_name(p, nat))
621             return RET_SYN;
622         pr("Country name changed from %s to %s\n", np->nat_cnam, p);
623         strcpy(np->nat_cnam, p);
624         break;
625     case 'r':
626         pr("Country representative changed from %s to %s\n",
627            np->nat_pnam, p);
628         strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
629         break;
630     case 't':
631         arg = LIMIT_TO(arg, 0, USHRT_MAX);
632         np->nat_tgms = arg;
633         break;
634     case 'b':
635         arg = LIMIT_TO(arg, 0, max_btus);
636         pr("BTU's changed from %d to %d\n", np->nat_btu, arg);
637         np->nat_btu = arg;
638         break;
639     case 'm':
640         arg = LIMIT_TO(arg, 0, INT_MAX);
641         benefit(nat, arg - np->nat_reserve);
642         pr("Military reserves changed from %d to %d\n",
643            np->nat_reserve, arg);
644         if (arg == np->nat_reserve)
645             break;
646         if (nat != player->cnum)
647             wu(0, nat,
648                "Military reserves changed from %d to %d by an act of %s\n",
649                np->nat_reserve, arg, cname(player->cnum));
650         np->nat_reserve = arg;
651         break;
652     case 'c':
653         if (!sarg_xy(p, &newx, &newy))
654             return RET_SYN;
655         pr("Capital coordinates changed from %s to %s\n",
656            xyas(np->nat_xcap, np->nat_ycap, player->cnum),
657            xyas(newx, newy, player->cnum));
658         np->nat_xcap = newx;
659         np->nat_ycap = newy;
660         break;
661     case 'o':
662         if (!sarg_xy(p, &newx, &newy))
663             return RET_SYN;
664         pr("Origin coordinates changed from %s to %s\n",
665            xyas(np->nat_xorg, np->nat_yorg, player->cnum),
666            xyas(newx, newy, player->cnum));
667         np->nat_xorg = newx;
668         np->nat_yorg = newy;
669         break;
670     case 's':
671         np->nat_stat = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
672         break;
673     case 'u':
674         arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
675         pr("Number of seconds used changed from %d to %d.\n",
676            np->nat_timeused, arg);
677         np->nat_timeused = arg;
678         break;
679     case 'M':
680         pr("Money changed from %d to %d\n", np->nat_money, arg);
681         if (arg == np->nat_money)
682             break;
683         if (nat != player->cnum)
684             wu(0, nat, "Money changed from %d to %d by an act of %s\n",
685                np->nat_money, arg, cname(player->cnum));
686         np->nat_money = arg;
687         break;
688     case 'T':
689         farg = MAX(0.0, farg);
690         pr("Tech changed from %.2f to %.2f.\n",
691            np->nat_level[NAT_TLEV], farg);
692         np->nat_level[NAT_TLEV] = farg;
693         break;
694     case 'R':
695         farg = MAX(0.0, farg);
696         pr("Research changed from %.2f to %.2f.\n",
697            np->nat_level[NAT_RLEV], farg);
698         np->nat_level[NAT_RLEV] = farg;
699         break;
700     case 'E':
701         farg = MAX(0.0, farg);
702         pr("Education changed from %.2f to %.2f.\n",
703            np->nat_level[NAT_ELEV], farg);
704         np->nat_level[NAT_ELEV] = farg;
705         break;
706     case 'H':
707         farg = MAX(0.0, farg);
708         pr("Happiness changed from %.2f to %.2f.\n",
709            np->nat_level[NAT_HLEV], farg);
710         np->nat_level[NAT_HLEV] = farg;
711         break;
712     default:
713         pr("huh? (%s)\n", key);
714         break;
715     }
716     putnat(np);
717     return RET_OK;
718 }
719
720 static int
721 edit_ship(struct shpstr *ship, char *key, int arg, char *p)
722 {
723     struct mchrstr *mcp = &mchr[ship->shp_type];
724     coord newx, newy;
725     struct ichrstr *ip;
726
727     newx = newy = 0;
728     switch (*key) {
729     case 'a':
730         arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
731         ship->shp_pstage = arg;
732         break;
733     case 'b':
734         arg = LIMIT_TO(arg, 0, 32767);
735         ship->shp_ptime = arg;
736         break;
737     case 'R':
738         strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
739         break;
740     case 'W':
741         ship->shp_rflags = arg;
742         break;
743     case 'U':
744         ef_set_uid(EF_SHIP, ship, arg);
745         break;
746     case 'O':
747         if (arg < 0 || arg >= MAXNOC)
748             return RET_SYN;
749         if (arg == ship->shp_own)
750             break;
751         if (ship->shp_own && ship->shp_own != player->cnum)
752             wu(0, ship->shp_own, "%s taken from you by an act of %s!\n",
753                prship(ship), cname(player->cnum));
754         if (arg && arg != player->cnum)
755             wu(0, arg, "%s given to you by an act of %s!\n",
756                prship(ship), cname(player->cnum));
757         ship->shp_own = arg;
758         break;
759     case 'L':
760         if (!sarg_xy(p, &newx, &newy))
761             return RET_SYN;
762         ship->shp_x = newx;
763         ship->shp_y = newy;
764         break;
765     case 'T':
766         arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
767         shp_set_tech(ship, arg);
768         break;
769     case 'E':
770         ship->shp_effic = LIMIT_TO(arg, SHIP_MINEFF, 100);
771         break;
772     case 'M':
773         arg = LIMIT_TO(arg, -127, 127);
774         ship->shp_mobil = arg;
775         break;
776     case 'F':
777         if (p[0] == '~')
778             ship->shp_fleet = 0;
779         else if (isalpha(p[0]))
780             ship->shp_fleet = p[0];
781         else {
782             pr("%c: invalid fleet\n", p[0]);
783             return RET_FAIL;
784         }
785         break;
786     case 'c':
787     case 'm':
788     case 'u':
789     case 'f':
790     case 's':
791     case 'g':
792     case 'p':
793     case 'i':
794     case 'd':
795     case 'o':
796     case 'l':
797     case 'h':
798     case 'r':
799         ip = item_by_name(key);
800         arg = LIMIT_TO(arg, 0, mchr[ship->shp_type].m_item[ip->i_uid]);
801         ship->shp_item[ip->i_uid] = arg;
802         break;
803     default:
804         pr("huh? (%s)\n", key);
805         return RET_FAIL;
806     }
807     return RET_OK;
808 }
809
810 static int
811 edit_land(struct lndstr *land, char *key, int arg, char *p)
812 {
813     struct lchrstr *lcp = &lchr[land->lnd_type];
814     coord newx, newy;
815     struct ichrstr *ip;
816
817     newx = newy = 0;
818     switch (*key) {
819     case 'Y':
820         if (arg < -1 || arg >= ef_nelem(EF_LAND))
821             return RET_SYN;
822         if (arg >= 0 && arg != land->lnd_land)
823             land->lnd_ship = -1;
824         land->lnd_land = arg;
825         break;
826     case 'U':
827         ef_set_uid(EF_LAND, land, arg);
828         break;
829     case 'O':
830         if (arg < 0 || arg >= MAXNOC)
831             return RET_SYN;
832         if (arg == land->lnd_own)
833             break;
834         if (land->lnd_own && land->lnd_own != player->cnum)
835             wu(0, land->lnd_own, "%s taken from you by an act of %s!\n",
836                prland(land), cname(player->cnum));
837         if (arg && arg != player->cnum)
838             wu(0, arg, "%s given to you by an act of %s!\n",
839                prland(land), cname(player->cnum));
840         land->lnd_own = arg;
841         break;
842     case 'L':
843         if (!sarg_xy(p, &newx, &newy))
844             return RET_SYN;
845         land->lnd_x = newx;
846         land->lnd_y = newy;
847         break;
848     case 'e':
849         land->lnd_effic = LIMIT_TO(arg, LAND_MINEFF, 100);
850         break;
851     case 'M':
852         arg = LIMIT_TO(arg, -127, 127);
853         land->lnd_mobil = arg;
854         break;
855     case 't':
856         arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
857         lnd_set_tech(land, arg);
858         break;
859     case 'a':
860         if (p[0] == '~')
861             land->lnd_army = 0;
862         else if (isalpha(p[0]))
863             land->lnd_army = p[0];
864         else {
865             pr("%c: invalid army\n", p[0]);
866             return RET_FAIL;
867         }
868         break;
869     case 'F':
870         land->lnd_harden = LIMIT_TO(arg, 0, 127);
871         break;
872     case 'S':
873         if (arg < -1 || arg >= ef_nelem(EF_SHIP))
874             return RET_SYN;
875         if (arg >= 0 && arg != land->lnd_ship)
876             land->lnd_land = -1;
877         land->lnd_ship = arg;
878         break;
879     case 'Z':
880         arg = LIMIT_TO(arg, 0, 100);
881         land->lnd_retreat = arg;
882         break;
883     case 'R':
884         strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
885         break;
886     case 'W':
887         land->lnd_rflags = arg;
888         break;
889     case 'c':
890     case 'm':
891     case 'u':
892     case 'f':
893     case 's':
894     case 'g':
895     case 'p':
896     case 'i':
897     case 'd':
898     case 'o':
899     case 'l':
900     case 'h':
901     case 'r':
902         ip = item_by_name(key);
903         arg = LIMIT_TO(arg, 0, lchr[land->lnd_type].l_item[ip->i_uid]);
904         land->lnd_item[ip->i_uid] = arg;
905         break;
906     default:
907         pr("huh? (%s)\n", key);
908         return RET_FAIL;
909     }
910     return RET_OK;
911 }
912
913 static int
914 edit_plane(struct plnstr *plane, char *key, int arg, char *p)
915 {
916     struct plchrstr *pcp = &plchr[plane->pln_type];
917     coord newx, newy;
918
919     switch (*key) {
920     case 'U':
921         ef_set_uid(EF_PLANE, plane, arg);
922         break;
923     case 'l':
924         if (!sarg_xy(p, &newx, &newy))
925             return RET_SYN;
926         plane->pln_x = newx;
927         plane->pln_y = newy;
928         break;
929     case 'O':
930         if (arg < 0 || arg >= MAXNOC)
931             return RET_SYN;
932         if (arg == plane->pln_own)
933             break;
934         if (plane->pln_own && plane->pln_own != player->cnum)
935             wu(0, plane->pln_own, "%s taken from you by an act of %s!\n",
936                prplane(plane), cname(player->cnum));
937         if (arg && arg != player->cnum)
938             wu(0, arg, "%s given to you by an act of %s!\n",
939                prplane(plane), cname(player->cnum));
940         plane->pln_own = arg;
941         break;
942     case 'e':
943         plane->pln_effic = LIMIT_TO(arg, PLANE_MINEFF, 100);
944         break;
945     case 'm':
946         plane->pln_mobil = LIMIT_TO(arg, -127, 127);
947         break;
948     case 't':
949         arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
950         pln_set_tech(plane, arg);
951         break;
952     case 'w':
953         if (p[0] == '~')
954             plane->pln_wing = 0;
955         else if (isalpha(p[0]))
956             plane->pln_wing = p[0];
957         else {
958             pr("%c: invalid wing\n", p[0]);
959             return RET_FAIL;
960         }
961         break;
962     case 'r':
963         arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
964         plane->pln_range = (unsigned char)arg;
965         break;
966     case 's':
967         if (arg < -1 || arg >= ef_nelem(EF_SHIP))
968             return RET_SYN;
969         if (arg >= 0 && arg != plane->pln_ship)
970             plane->pln_land = -1;
971         plane->pln_ship = arg;
972         break;
973     case 'y':
974         if (arg < -1 || arg >= ef_nelem(EF_LAND))
975             return RET_SYN;
976         if (arg >= 0 && arg != plane->pln_land)
977             plane->pln_ship = -1;
978         plane->pln_land = arg;
979         break;
980     case 'f':
981         plane->pln_flags = arg;
982         break;
983     default:
984         pr("huh? (%s)\n", key);
985         return RET_FAIL;
986     }
987     return RET_OK;
988 }