]> git.pond.sub.org Git - empserver/blob - src/lib/commands/edit.c
edit &c: Suppress news for acts of god to gods
[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 && 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) {
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) {
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, 127);
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, 127);
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, 127);
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, 127);
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, 127);
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         wu(0, nat,
647            "Military reserves changed from %d to %d by an act of %s\n",
648            np->nat_reserve, arg, cname(player->cnum));
649         np->nat_reserve = arg;
650         break;
651     case 'c':
652         if (!sarg_xy(p, &newx, &newy))
653             return RET_SYN;
654         pr("Capital coordinates changed from %s to %s\n",
655            xyas(np->nat_xcap, np->nat_ycap, player->cnum),
656            xyas(newx, newy, player->cnum));
657         np->nat_xcap = newx;
658         np->nat_ycap = newy;
659         break;
660     case 'o':
661         if (!sarg_xy(p, &newx, &newy))
662             return RET_SYN;
663         pr("Origin coordinates changed from %s to %s\n",
664            xyas(np->nat_xorg, np->nat_yorg, player->cnum),
665            xyas(newx, newy, player->cnum));
666         np->nat_xorg = newx;
667         np->nat_yorg = newy;
668         break;
669     case 's':
670         np->nat_stat = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
671         break;
672     case 'u':
673         arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
674         pr("Number of seconds used changed from %d to %d.\n",
675            np->nat_timeused, arg);
676         np->nat_timeused = arg;
677         break;
678     case 'M':
679         pr("Money changed from %d to %d\n", np->nat_money, arg);
680         if (arg == np->nat_money)
681             break;
682         wu(0, nat, "Money changed from %d to %d by an act of %s\n",
683            np->nat_money, arg, cname(player->cnum));
684         np->nat_money = arg;
685         break;
686     case 'T':
687         farg = MAX(0.0, farg);
688         pr("Tech changed from %.2f to %.2f.\n",
689            np->nat_level[NAT_TLEV], farg);
690         np->nat_level[NAT_TLEV] = farg;
691         break;
692     case 'R':
693         farg = MAX(0.0, farg);
694         pr("Research changed from %.2f to %.2f.\n",
695            np->nat_level[NAT_RLEV], farg);
696         np->nat_level[NAT_RLEV] = farg;
697         break;
698     case 'E':
699         farg = MAX(0.0, farg);
700         pr("Education changed from %.2f to %.2f.\n",
701            np->nat_level[NAT_ELEV], farg);
702         np->nat_level[NAT_ELEV] = farg;
703         break;
704     case 'H':
705         farg = MAX(0.0, farg);
706         pr("Happiness changed from %.2f to %.2f.\n",
707            np->nat_level[NAT_HLEV], farg);
708         np->nat_level[NAT_HLEV] = farg;
709         break;
710     default:
711         pr("huh? (%s)\n", key);
712         break;
713     }
714     putnat(np);
715     return RET_OK;
716 }
717
718 static int
719 edit_ship(struct shpstr *ship, char *key, int arg, char *p)
720 {
721     struct mchrstr *mcp = &mchr[ship->shp_type];
722     coord newx, newy;
723     struct ichrstr *ip;
724
725     newx = newy = 0;
726     switch (*key) {
727     case 'a':
728         arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
729         ship->shp_pstage = arg;
730         break;
731     case 'b':
732         arg = LIMIT_TO(arg, 0, 32767);
733         ship->shp_ptime = arg;
734         break;
735     case 'R':
736         strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
737         break;
738     case 'W':
739         ship->shp_rflags = arg;
740         break;
741     case 'U':
742         ef_set_uid(EF_SHIP, ship, arg);
743         break;
744     case 'O':
745         if (arg < 0 || arg >= MAXNOC)
746             return RET_SYN;
747         if (arg == ship->shp_own)
748             break;
749         if (ship->shp_own)
750             wu(0, ship->shp_own, "%s taken from you by an act of %s!\n",
751                prship(ship), cname(player->cnum));
752         if (arg)
753             wu(0, arg, "%s given to you by an act of %s!\n",
754                prship(ship), cname(player->cnum));
755         ship->shp_own = arg;
756         break;
757     case 'L':
758         if (!sarg_xy(p, &newx, &newy))
759             return RET_SYN;
760         ship->shp_x = newx;
761         ship->shp_y = newy;
762         break;
763     case 'T':
764         arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
765         shp_set_tech(ship, arg);
766         break;
767     case 'E':
768         ship->shp_effic = LIMIT_TO(arg, SHIP_MINEFF, 100);
769         break;
770     case 'M':
771         arg = LIMIT_TO(arg, -127, 127);
772         ship->shp_mobil = arg;
773         break;
774     case 'F':
775         if (p[0] == '~')
776             ship->shp_fleet = 0;
777         else if (isalpha(p[0]))
778             ship->shp_fleet = p[0];
779         else {
780             pr("%c: invalid fleet\n", p[0]);
781             return RET_FAIL;
782         }
783         break;
784     case 'c':
785     case 'm':
786     case 'u':
787     case 'f':
788     case 's':
789     case 'g':
790     case 'p':
791     case 'i':
792     case 'd':
793     case 'o':
794     case 'l':
795     case 'h':
796     case 'r':
797         ip = item_by_name(key);
798         arg = LIMIT_TO(arg, 0, mchr[ship->shp_type].m_item[ip->i_uid]);
799         ship->shp_item[ip->i_uid] = arg;
800         break;
801     default:
802         pr("huh? (%s)\n", key);
803         return RET_FAIL;
804     }
805     return RET_OK;
806 }
807
808 static int
809 edit_land(struct lndstr *land, char *key, int arg, char *p)
810 {
811     struct lchrstr *lcp = &lchr[land->lnd_type];
812     coord newx, newy;
813     struct ichrstr *ip;
814
815     newx = newy = 0;
816     switch (*key) {
817     case 'Y':
818         if (arg < -1 || arg >= ef_nelem(EF_LAND))
819             return RET_SYN;
820         if (arg >= 0 && arg != land->lnd_land)
821             land->lnd_ship = -1;
822         land->lnd_land = arg;
823         break;
824     case 'U':
825         ef_set_uid(EF_LAND, land, arg);
826         break;
827     case 'O':
828         if (arg < 0 || arg >= MAXNOC)
829             return RET_SYN;
830         if (arg == land->lnd_own)
831             break;
832         if (land->lnd_own)
833             wu(0, land->lnd_own, "%s taken from you by an act of %s!\n",
834                prland(land), cname(player->cnum));
835         if (arg)
836             wu(0, arg, "%s given to you by an act of %s!\n",
837                prland(land), cname(player->cnum));
838         land->lnd_own = arg;
839         break;
840     case 'L':
841         if (!sarg_xy(p, &newx, &newy))
842             return RET_SYN;
843         land->lnd_x = newx;
844         land->lnd_y = newy;
845         break;
846     case 'e':
847         land->lnd_effic = LIMIT_TO(arg, LAND_MINEFF, 100);
848         break;
849     case 'M':
850         arg = LIMIT_TO(arg, -127, 127);
851         land->lnd_mobil = arg;
852         break;
853     case 't':
854         arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
855         lnd_set_tech(land, arg);
856         break;
857     case 'a':
858         if (p[0] == '~')
859             land->lnd_army = 0;
860         else if (isalpha(p[0]))
861             land->lnd_army = p[0];
862         else {
863             pr("%c: invalid army\n", p[0]);
864             return RET_FAIL;
865         }
866         break;
867     case 'F':
868         land->lnd_harden = LIMIT_TO(arg, 0, 127);
869         break;
870     case 'S':
871         if (arg < -1 || arg >= ef_nelem(EF_SHIP))
872             return RET_SYN;
873         if (arg >= 0 && arg != land->lnd_ship)
874             land->lnd_land = -1;
875         land->lnd_ship = arg;
876         break;
877     case 'Z':
878         arg = LIMIT_TO(arg, 0, 100);
879         land->lnd_retreat = arg;
880         break;
881     case 'R':
882         strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
883         break;
884     case 'W':
885         land->lnd_rflags = arg;
886         break;
887     case 'c':
888     case 'm':
889     case 'u':
890     case 'f':
891     case 's':
892     case 'g':
893     case 'p':
894     case 'i':
895     case 'd':
896     case 'o':
897     case 'l':
898     case 'h':
899     case 'r':
900         ip = item_by_name(key);
901         arg = LIMIT_TO(arg, 0, lchr[land->lnd_type].l_item[ip->i_uid]);
902         land->lnd_item[ip->i_uid] = arg;
903         break;
904     default:
905         pr("huh? (%s)\n", key);
906         return RET_FAIL;
907     }
908     return RET_OK;
909 }
910
911 static int
912 edit_plane(struct plnstr *plane, char *key, int arg, char *p)
913 {
914     struct plchrstr *pcp = &plchr[plane->pln_type];
915     coord newx, newy;
916
917     switch (*key) {
918     case 'U':
919         ef_set_uid(EF_PLANE, plane, arg);
920         break;
921     case 'l':
922         if (!sarg_xy(p, &newx, &newy))
923             return RET_SYN;
924         plane->pln_x = newx;
925         plane->pln_y = newy;
926         break;
927     case 'O':
928         if (arg < 0 || arg >= MAXNOC)
929             return RET_SYN;
930         if (arg == plane->pln_own)
931             break;
932         if (plane->pln_own)
933             wu(0, plane->pln_own, "%s taken from you by an act of %s!\n",
934                prplane(plane), cname(player->cnum));
935         if (arg)
936             wu(0, arg, "%s given to you by an act of %s!\n",
937                prplane(plane), cname(player->cnum));
938         plane->pln_own = arg;
939         break;
940     case 'e':
941         plane->pln_effic = LIMIT_TO(arg, PLANE_MINEFF, 100);
942         break;
943     case 'm':
944         plane->pln_mobil = LIMIT_TO(arg, -127, 127);
945         break;
946     case 't':
947         arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
948         pln_set_tech(plane, arg);
949         break;
950     case 'w':
951         if (p[0] == '~')
952             plane->pln_wing = 0;
953         else if (isalpha(p[0]))
954             plane->pln_wing = p[0];
955         else {
956             pr("%c: invalid wing\n", p[0]);
957             return RET_FAIL;
958         }
959         break;
960     case 'r':
961         arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
962         plane->pln_range = (unsigned char)arg;
963         break;
964     case 's':
965         if (arg < -1 || arg >= ef_nelem(EF_SHIP))
966             return RET_SYN;
967         if (arg >= 0 && arg != plane->pln_ship)
968             plane->pln_land = -1;
969         plane->pln_ship = arg;
970         break;
971     case 'y':
972         if (arg < -1 || arg >= ef_nelem(EF_LAND))
973             return RET_SYN;
974         if (arg >= 0 && arg != plane->pln_land)
975             plane->pln_ship = -1;
976         plane->pln_land = arg;
977         break;
978     case 'f':
979         plane->pln_flags = arg;
980         break;
981     default:
982         pr("huh? (%s)\n", key);
983         return RET_FAIL;
984     }
985     return RET_OK;
986 }