]> git.pond.sub.org Git - empserver/blob - src/lib/commands/edit.c
f78d5bbc01953c2b05e3281c87d7c9d8f564e910
[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 good)
229 {
230     if (!opt_GODNEWS)
231         return;
232
233     if (good) {
234         if (who)
235             nreport(player->cnum, N_AIDS, who, 1);
236     } else {
237         if (who)
238             nreport(player->cnum, N_HURTS, who, 1);
239     }
240 }
241
242 static void
243 noise(struct sctstr *sptr, char *name, int old, int new)
244 {
245     pr("%s of %s changed from %d to %d\n",
246        name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new);
247     if (sptr->sct_own)
248         wu(player->cnum, sptr->sct_own,
249            "%s in %s was changed from %d to %d by an act of %s\n",
250            name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own),
251            old, new, cname(player->cnum));
252     benefit(sptr->sct_own, old < new);
253 }
254
255 static void
256 print_sect(struct sctstr *sect)
257 {
258     pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
259     pr("Distribution sector <D>: %s\n",
260        xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
261     pr("Designation <s>: %c\tNew designation <S>: %c\n",
262        dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
263     pr("own  oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
264     pr("  o   O   e   m   i   g   f   c   u   w   l   x   X   p     t    F     a\n");
265     pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
266        sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
267        sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
268        sect->sct_uran, sect->sct_work, sect->sct_loyal,
269        sect->sct_che, sect->sct_che_target,
270        sect->sct_pstage, sect->sct_ptime,
271        sect->sct_fallout, sect->sct_avail);
272
273     pr("Mines <M>: %d\n", sect->sct_mines);
274     pr("Road %% <R>: %d\t", sect->sct_road);
275     pr("Rail %% <r>: %d\t", sect->sct_rail);
276     pr("Defense %% <d>: %d\n", sect->sct_defense);
277 }
278
279 static void
280 print_nat(struct natstr *np)
281 {
282     int i;
283
284     pr("Country #: %2d\n", np->nat_cnum);
285     pr("Name <n>: %-20s\t", np->nat_cnam);
286     pr("Representative <r>: %-20s\n", np->nat_pnam);
287     pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
288     pr("Reserves <m>: %5d\n", np->nat_reserve);
289     pr("Capital <c>: %s\t\t",
290        xyas(np->nat_xcap, np->nat_ycap, player->cnum));
291     pr("Origin <o>: %3s\n",
292        xyas(np->nat_xorg, np->nat_yorg, player->cnum));
293     pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
294     pr("Seconds Used <u>: %3d\n", np->nat_timeused);
295     pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
296     pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
297     pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
298     pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
299     pr("Money <M>: $%6d\n", np->nat_money);
300     pr("Telegrams <t>: %6d\n", np->nat_tgms);
301     if (opt_HIDDEN) {
302         pr("Countries contacted: ");
303         for (i = 0; i < MAXNOC; i++) {
304             if (getcontact(np, i))
305                 pr("%d(%d) ", i, getcontact(np, i));
306         }
307         pr("\n");
308     }
309 }
310
311 static void
312 print_plane(struct plnstr *plane)
313 {
314     pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
315     pr("UID <U>: %d\t\t", plane->pln_uid);
316     pr("Owner <O>: %d\t\t", plane->pln_own);
317     pr("Location <l>: %s\n",
318        xyas(plane->pln_x, plane->pln_y, player->cnum));
319     pr("Efficiency <e>: %d\t", plane->pln_effic);
320     pr("Mobility <m>: %d\n", plane->pln_mobil);
321     pr("Tech <t>: %d\t\t", plane->pln_tech);
322     pr("Wing <w>: %.1s\n", &plane->pln_wing);
323     pr("Range <r>: %d\t\t", plane->pln_range);
324     pr("Flags <f>: %d\n", plane->pln_flags);
325     pr("Ship <s>: %d\t\t", plane->pln_ship);
326     pr("Land Unit <y>: %d\t", plane->pln_land);
327 }
328
329 static void
330 print_land(struct lndstr *land)
331 {
332     pr("%s %s\n", prnatid(land->lnd_own), prland(land));
333     pr("UID <U>: %d\n", land->lnd_uid);
334     pr("Owner <O>: %d\n", land->lnd_own);
335     pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
336     pr("Efficiency <e>: %d\t", land->lnd_effic);
337     pr("Mobility <M>: %d\n", land->lnd_mobil);
338     pr("Tech <t>: %d\t\t", land->lnd_tech);
339     pr("Army <a>: %.1s\n", &land->lnd_army);
340     pr("Fortification <F>: %d\t", land->lnd_harden);
341     pr("Land unit <Y>: %d\n", land->lnd_land);
342     pr("Ship <S>: %d\t\t", land->lnd_ship);
343     pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
344     pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
345        land->lnd_rpath, land->lnd_rflags);
346     pr("civ mil  uw food shl gun  pet  irn  dst  oil  lcm  hcm rad\n");
347     pr("  c   m   u    f   s   g    p    i    d    o    l    h   r\n");
348     pr("%3d", land->lnd_item[I_CIVIL]);
349     pr("%4d", land->lnd_item[I_MILIT]);
350     pr("%4d", land->lnd_item[I_UW]);
351     pr("%5d", land->lnd_item[I_FOOD]);
352     pr("%4d", land->lnd_item[I_SHELL]);
353     pr("%4d", land->lnd_item[I_GUN]);
354     pr("%5d", land->lnd_item[I_PETROL]);
355     pr("%5d", land->lnd_item[I_IRON]);
356     pr("%5d", land->lnd_item[I_DUST]);
357     pr("%5d", land->lnd_item[I_OIL]);
358     pr("%5d", land->lnd_item[I_LCM]);
359     pr("%5d", land->lnd_item[I_HCM]);
360     pr("%4d", land->lnd_item[I_RAD]);
361     pr("\n");
362 }
363
364 static void
365 print_ship(struct shpstr *ship)
366 {
367     pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
368     pr("UID <U>: %d\n", ship->shp_uid);
369     pr("Owner <O>: %d\t\t\t", ship->shp_own);
370     pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
371     pr("Tech <T>: %d\t\t\t", ship->shp_tech);
372     pr("Efficiency <E>: %d\n", ship->shp_effic);
373     pr("Mobility <M>: %d\t\t", ship->shp_mobil);
374     pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
375     pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
376        ship->shp_rpath, ship->shp_rflags);
377     pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
378     pr("Plague Time <b>: %d\n", ship->shp_ptime);
379     pr("civ mil  uw food shl gun  pet  irn  dst  oil  lcm  hcm rad\n");
380     pr("  c   m   u    f   s   g    p    i    d    o    l    h   r\n");
381     pr("%3d", ship->shp_item[I_CIVIL]);
382     pr("%4d", ship->shp_item[I_MILIT]);
383     pr("%4d", ship->shp_item[I_UW]);
384     pr("%5d", ship->shp_item[I_FOOD]);
385     pr("%4d", ship->shp_item[I_SHELL]);
386     pr("%4d", ship->shp_item[I_GUN]);
387     pr("%5d", ship->shp_item[I_PETROL]);
388     pr("%5d", ship->shp_item[I_IRON]);
389     pr("%5d", ship->shp_item[I_DUST]);
390     pr("%5d", ship->shp_item[I_OIL]);
391     pr("%5d", ship->shp_item[I_LCM]);
392     pr("%5d", ship->shp_item[I_HCM]);
393     pr("%4d", ship->shp_item[I_RAD]);
394     pr("\n");
395 }
396
397 static char *
398 getin(char *buf, char **valp)
399 {
400     char line[1024];
401     char *argp[128];
402     char *p;
403
404     *valp = NULL;
405     p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
406     if (!p)
407         return NULL;
408     switch (parse(p, buf, argp, NULL, NULL, NULL)) {
409     case 0:
410         return "";
411     case 1:
412         return NULL;
413     default:
414         *valp = argp[1];
415         return argp[0];
416     }
417 }
418
419 #if 0   /* not needed right now */
420 static void
421 warn_deprecated(char key)
422 {
423     pr("Key <%c> is deprecated and will go away in a future release\n", key);
424 }
425 #endif
426
427 static int
428 edit_sect(struct sctstr *sect, char *key, int arg, char *p)
429 {
430     coord newx, newy;
431     int new;
432
433     switch (*key) {
434     case 'o':
435         if (arg < 0 || arg >= MAXNOC)
436             return RET_SYN;
437         pr("Owner of %s changed from %s to %s.\n",
438            xyas(sect->sct_x, sect->sct_y, player->cnum),
439            prnatid(sect->sct_own), prnatid(arg));
440         if (sect->sct_own) {
441             wu(player->cnum, sect->sct_own,
442                "Sector %s lost to deity intervention\n",
443                xyas(sect->sct_x, sect->sct_y, sect->sct_own));
444         }
445         benefit(sect->sct_own, 0);
446         sect->sct_own = arg;
447         if (arg) {
448             wu(player->cnum, arg,
449                "Sector %s gained from deity intervention\n",
450                xyas(sect->sct_x, sect->sct_y, arg));
451         }
452         benefit(arg, 1);
453         break;
454     case 'O':
455         if (arg < 0 || arg >= MAXNOC)
456             return RET_SYN;
457         pr("Old owner of %s changed from %s to %s.\n",
458            xyas(sect->sct_x, sect->sct_y, player->cnum),
459            prnatid(sect->sct_oldown), prnatid(arg));
460         sect->sct_oldown = arg;
461         break;
462     case 'e':
463         new = LIMIT_TO(arg, 0, 100);
464         noise(sect, "Efficiency", sect->sct_effic, new);
465         sect->sct_effic = new;
466         break;
467     case 'm':
468         new = LIMIT_TO(arg, -127, 127);
469         noise(sect, "Mobility", sect->sct_mobil, new);
470         sect->sct_mobil = new;
471         break;
472     case 'i':
473         new = LIMIT_TO(arg, 0, 127);
474         noise(sect, "Iron ore content", sect->sct_min, new);
475         sect->sct_min = (unsigned char)new;
476         break;
477     case 'g':
478         new = LIMIT_TO(arg, 0, 127);
479         noise(sect, "Gold content", sect->sct_gmin, new);
480         sect->sct_gmin = (unsigned char)new;
481         break;
482     case 'f':
483         new = LIMIT_TO(arg, 0, 127);
484         noise(sect, "Fertility", sect->sct_fertil, new);
485         sect->sct_fertil = (unsigned char)new;
486         break;
487     case 'c':
488         new = LIMIT_TO(arg, 0, 127);
489         noise(sect, "Oil content", sect->sct_oil, new);
490         sect->sct_oil = (unsigned char)new;
491         break;
492     case 'u':
493         new = LIMIT_TO(arg, 0, 127);
494         noise(sect, "Uranium content", sect->sct_uran, new);
495         sect->sct_uran = (unsigned char)new;
496         break;
497     case 'w':
498         new = LIMIT_TO(arg, 0, 100);
499         noise(sect, "Workforce percentage", sect->sct_work, new);
500         sect->sct_work = (unsigned char)new;
501         break;
502     case 'l':
503         new = LIMIT_TO(arg, 0, 127);
504         pr("Loyalty of %s changed from %d to %d\n",
505            xyas(sect->sct_x, sect->sct_y, player->cnum),
506            sect->sct_loyal, new);
507         sect->sct_loyal = (unsigned char)new;
508         break;
509     case 'x':
510         new = LIMIT_TO(arg, 0, CHE_MAX);
511         pr("Guerillas in %s changed from %d to %d\n",
512            xyas(sect->sct_x, sect->sct_y, player->cnum),
513            sect->sct_che, new);
514         sect->sct_che = new;
515         break;
516     case 'X':
517         if (arg < 0 || arg >= MAXNOC)
518             return RET_SYN;
519         pr("Che target of %s changed from %s to %s.\n",
520            xyas(sect->sct_x, sect->sct_y, player->cnum),
521            prnatid(sect->sct_che_target), prnatid(arg));
522         sect->sct_che_target = arg;
523         if (arg == 0)
524             sect->sct_che = 0;
525         break;
526     case 'p':
527         new = LIMIT_TO(arg, 0, PLG_EXPOSED);
528         pr("Plague stage of %s changed from %d to %d\n",
529            xyas(sect->sct_x, sect->sct_y, player->cnum),
530            sect->sct_pstage, new);
531         sect->sct_pstage = new;
532         break;
533     case 't':
534         new = LIMIT_TO(arg, 0, 32767);
535         pr("Plague time of %s changed from %d to %d\n",
536            xyas(sect->sct_x, sect->sct_y, player->cnum),
537            sect->sct_ptime, new);
538         sect->sct_ptime = new;
539         break;
540     case 'F':
541         new = LIMIT_TO(arg, 0, FALLOUT_MAX);
542         pr("Fallout for sector %s changed from %d to %d\n",
543            xyas(sect->sct_x, sect->sct_y, player->cnum),
544            sect->sct_fallout, new);
545         sect->sct_fallout = new;
546         break;
547     case 'a':
548         new = LIMIT_TO(arg, 0, 9999);
549         noise(sect, "Available workforce", sect->sct_avail, new);
550         sect->sct_avail = new;
551         break;
552     case 'M':
553         new = LIMIT_TO(arg, 0, MINES_MAX);
554         sect->sct_mines = new;
555         pr("Mines changed to %d\n", new);
556         break;
557     case 'L':
558         if (!sarg_xy(p, &newx, &newy))
559             return RET_SYN;
560         sect->sct_x = newx;
561         sect->sct_y = newy;
562         ef_set_uid(EF_SECTOR, &sect, XYOFFSET(newx, newy));
563         break;
564     case 'D':
565         if (!sarg_xy(p, &newx, &newy))
566             return RET_SYN;
567         pr("Distribution location for sector %s changed from %s to %s\n",
568            xyas(sect->sct_x, sect->sct_y, player->cnum),
569            xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
570            xyas(newx, newy, player->cnum));
571         sect->sct_dist_x = newx;
572         sect->sct_dist_y = newy;
573         break;
574     case 's':
575         new = sct_typematch(p);
576         if (new < 0)
577             return RET_SYN;
578         pr("Designation for sector %s changed from %c to %c\n",
579            xyas(sect->sct_x, sect->sct_y, player->cnum),
580            dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
581         set_coastal(sect, sect->sct_type, new);
582         sect->sct_type = new;
583         break;
584     case 'S':
585         new = sct_typematch(p);
586         if (new < 0)
587             return RET_SYN;
588         pr("New designation for sector %s changed from %c to %c\n",
589            xyas(sect->sct_x, sect->sct_y, player->cnum),
590            dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
591         sect->sct_newtype = new;
592         break;
593     case 'R':
594         new = LIMIT_TO(arg, 0, 100);
595         noise(sect, "Road percentage", sect->sct_road, new);
596         sect->sct_road = new;
597         break;
598     case 'r':
599         new = LIMIT_TO(arg, 0, 100);
600         noise(sect, "Rail percentage", sect->sct_rail, new);
601         sect->sct_rail = new;
602         break;
603     case 'd':
604         new = LIMIT_TO(arg, 0, 100);
605         noise(sect, "Defense percentage", sect->sct_defense, new);
606         sect->sct_defense = new;
607         break;
608     default:
609         pr("huh? (%s)\n", key);
610         return RET_SYN;
611     }
612     return RET_OK;
613 }
614
615 static int
616 edit_nat(struct natstr *np, char *key, int arg, char *p)
617 {
618     coord newx, newy;
619     natid nat = np->nat_cnum;
620     float farg = (float)atof(p);
621
622     switch (*key) {
623     case 'n':
624         if (!check_nat_name(p, nat))
625             return RET_SYN;
626         pr("Country name changed from %s to %s\n", np->nat_cnam, p);
627         strcpy(np->nat_cnam, p);
628         break;
629     case 'r':
630         pr("Country representative changed from %s to %s\n",
631            np->nat_pnam, p);
632         strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
633         break;
634     case 't':
635         arg = LIMIT_TO(arg, 0, USHRT_MAX);
636         np->nat_tgms = arg;
637         break;
638     case 'b':
639         arg = LIMIT_TO(arg, 0, max_btus);
640         pr("BTU's changed from %d to %d\n", np->nat_btu, arg);
641         np->nat_btu = arg;
642         break;
643     case 'm':
644         arg = LIMIT_TO(arg, 0, INT_MAX);
645         benefit(nat, np->nat_reserve < arg);
646         pr("Military reserves changed from %d to %d\n",
647            np->nat_reserve, arg);
648         wu(player->cnum, nat,
649            "Military reserves changed from %d to %d by divine intervention.\n",
650            np->nat_reserve, arg);
651         np->nat_reserve = arg;
652         break;
653     case 'c':
654         if (!sarg_xy(p, &newx, &newy))
655             return RET_SYN;
656         pr("Capital coordinates changed from %s to %s\n",
657            xyas(np->nat_xcap, np->nat_ycap, player->cnum),
658            xyas(newx, newy, player->cnum));
659         np->nat_xcap = newx;
660         np->nat_ycap = newy;
661         break;
662     case 'o':
663         if (!sarg_xy(p, &newx, &newy))
664             return RET_SYN;
665         pr("Origin coordinates changed from %s to %s\n",
666            xyas(np->nat_xorg, np->nat_yorg, player->cnum),
667            xyas(newx, newy, player->cnum));
668         np->nat_xorg = newx;
669         np->nat_yorg = newy;
670         break;
671     case 's':
672         np->nat_stat = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
673         break;
674     case 'u':
675         arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
676         pr("Number of seconds used changed from %d to %d.\n",
677            np->nat_timeused, arg);
678         np->nat_timeused = arg;
679         break;
680     case 'M':
681         pr("Money changed from %d to %d\n", np->nat_money, arg);
682         wu(player->cnum, nat,
683            "Money changed from %d to %d by divine intervention.\n",
684            np->nat_money, arg);
685         np->nat_money = arg;
686         break;
687     case 'T':
688         farg = MAX(0.0, farg);
689         pr("Tech changed from %.2f to %.2f.\n",
690            np->nat_level[NAT_TLEV], farg);
691         np->nat_level[NAT_TLEV] = farg;
692         break;
693     case 'R':
694         farg = MAX(0.0, farg);
695         pr("Research changed from %.2f to %.2f.\n",
696            np->nat_level[NAT_RLEV], farg);
697         np->nat_level[NAT_RLEV] = farg;
698         break;
699     case 'E':
700         farg = MAX(0.0, farg);
701         pr("Education changed from %.2f to %.2f.\n",
702            np->nat_level[NAT_ELEV], farg);
703         np->nat_level[NAT_ELEV] = farg;
704         break;
705     case 'H':
706         farg = MAX(0.0, farg);
707         pr("Happiness changed from %.2f to %.2f.\n",
708            np->nat_level[NAT_HLEV], farg);
709         np->nat_level[NAT_HLEV] = farg;
710         break;
711     default:
712         pr("huh? (%s)\n", key);
713         break;
714     }
715     putnat(np);
716     return RET_OK;
717 }
718
719 static int
720 edit_ship(struct shpstr *ship, char *key, int arg, char *p)
721 {
722     struct mchrstr *mcp = &mchr[ship->shp_type];
723     coord newx, newy;
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 (ship->shp_own)
748             wu(player->cnum, ship->shp_own,
749                "%s taken from you by deity intervention!\n", prship(ship));
750         if (arg)
751             wu(player->cnum, (natid)arg,
752                "%s given to you by deity intervention!\n", prship(ship));
753         ship->shp_own = arg;
754         break;
755     case 'L':
756         if (!sarg_xy(p, &newx, &newy))
757             return RET_SYN;
758         ship->shp_x = newx;
759         ship->shp_y = newy;
760         break;
761     case 'T':
762         arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
763         shp_set_tech(ship, arg);
764         break;
765     case 'E':
766         ship->shp_effic = LIMIT_TO(arg, SHIP_MINEFF, 100);
767         break;
768     case 'M':
769         arg = LIMIT_TO(arg, -127, 127);
770         ship->shp_mobil = arg;
771         break;
772     case 'F':
773         if (p[0] == '~')
774             ship->shp_fleet = 0;
775         else if (isalpha(p[0]))
776             ship->shp_fleet = p[0];
777         else {
778             pr("%c: invalid fleet\n", p[0]);
779             return RET_FAIL;
780         }
781         break;
782     case 'c':
783         arg = LIMIT_TO(arg, 0, mcp->m_item[I_CIVIL]);
784         ship->shp_item[I_CIVIL] = arg;
785         break;
786     case 'm':
787         arg = LIMIT_TO(arg, 0, mcp->m_item[I_MILIT]);
788         ship->shp_item[I_MILIT] = arg;
789         break;
790     case 'u':
791         arg = LIMIT_TO(arg, 0, mcp->m_item[I_UW]);
792         ship->shp_item[I_UW] = arg;
793         break;
794     case 'f':
795         arg = LIMIT_TO(arg, 0, mcp->m_item[I_FOOD]);
796         ship->shp_item[I_FOOD] = arg;
797         break;
798     case 's':
799         arg = LIMIT_TO(arg, 0, mcp->m_item[I_SHELL]);
800         ship->shp_item[I_SHELL] = arg;
801         break;
802     case 'g':
803         arg = LIMIT_TO(arg, 0, mcp->m_item[I_GUN]);
804         ship->shp_item[I_GUN] = arg;
805         break;
806     case 'p':
807         arg = LIMIT_TO(arg, 0, mcp->m_item[I_PETROL]);
808         ship->shp_item[I_PETROL] = arg;
809         break;
810     case 'i':
811         arg = LIMIT_TO(arg, 0, mcp->m_item[I_IRON]);
812         ship->shp_item[I_IRON] = arg;
813         break;
814     case 'd':
815         arg = LIMIT_TO(arg, 0, mcp->m_item[I_DUST]);
816         ship->shp_item[I_DUST] = arg;
817         break;
818     case 'o':
819         arg = LIMIT_TO(arg, 0, mcp->m_item[I_OIL]);
820         ship->shp_item[I_OIL] = arg;
821         break;
822     case 'l':
823         arg = LIMIT_TO(arg, 0, mcp->m_item[I_LCM]);
824         ship->shp_item[I_LCM] = arg;
825         break;
826     case 'h':
827         arg = LIMIT_TO(arg, 0, mcp->m_item[I_HCM]);
828         ship->shp_item[I_HCM] = arg;
829         break;
830     case 'r':
831         arg = LIMIT_TO(arg, 0, mcp->m_item[I_RAD]);
832         ship->shp_item[I_RAD] = arg;
833         break;
834     default:
835         pr("huh? (%s)\n", key);
836         return RET_FAIL;
837     }
838     return RET_OK;
839 }
840
841 static int
842 edit_land(struct lndstr *land, char *key, int arg, char *p)
843 {
844     struct lchrstr *lcp = &lchr[land->lnd_type];
845     coord newx, newy;
846
847     newx = newy = 0;
848     switch (*key) {
849     case 'Y':
850         if (arg < -1 || arg >= ef_nelem(EF_LAND))
851             return RET_SYN;
852         if (arg >= 0 && arg != land->lnd_land)
853             land->lnd_ship = -1;
854         land->lnd_land = arg;
855         break;
856     case 'U':
857         ef_set_uid(EF_LAND, land, arg);
858         break;
859     case 'O':
860         if (arg < 0 || arg >= MAXNOC)
861             return RET_SYN;
862         if (land->lnd_own)
863             wu(player->cnum, land->lnd_own,
864                "%s taken from you by deity intervention!\n", prland(land));
865         if (arg)
866             wu(player->cnum, (natid)arg,
867                "%s given to you by deity intervention!\n", prland(land));
868         land->lnd_own = arg;
869         break;
870     case 'L':
871         if (!sarg_xy(p, &newx, &newy))
872             return RET_SYN;
873         land->lnd_x = newx;
874         land->lnd_y = newy;
875         break;
876     case 'e':
877         land->lnd_effic = LIMIT_TO(arg, LAND_MINEFF, 100);
878         break;
879     case 'M':
880         arg = LIMIT_TO(arg, -127, 127);
881         land->lnd_mobil = arg;
882         break;
883     case 't':
884         arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
885         lnd_set_tech(land, arg);
886         break;
887     case 'a':
888         if (p[0] == '~')
889             land->lnd_army = 0;
890         else if (isalpha(p[0]))
891             land->lnd_army = p[0];
892         else {
893             pr("%c: invalid army\n", p[0]);
894             return RET_FAIL;
895         }
896         break;
897     case 'F':
898         land->lnd_harden = LIMIT_TO(arg, 0, 127);
899         break;
900     case 'S':
901         if (arg < -1 || arg >= ef_nelem(EF_SHIP))
902             return RET_SYN;
903         if (arg >= 0 && arg != land->lnd_ship)
904             land->lnd_land = -1;
905         land->lnd_ship = arg;
906         break;
907     case 'Z':
908         arg = LIMIT_TO(arg, 0, 100);
909         land->lnd_retreat = arg;
910         break;
911     case 'R':
912         strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
913         break;
914     case 'W':
915         land->lnd_rflags = arg;
916         break;
917     case 'c':
918         arg = LIMIT_TO(arg, 0, lcp->l_item[I_CIVIL]);
919         land->lnd_item[I_CIVIL] = arg;
920         break;
921     case 'm':
922         arg = LIMIT_TO(arg, 0, lcp->l_item[I_MILIT]);
923         land->lnd_item[I_MILIT] = arg;
924         break;
925     case 'u':
926         arg = LIMIT_TO(arg, 0, lcp->l_item[I_UW]);
927         land->lnd_item[I_UW] = arg;
928         break;
929     case 'f':
930         arg = LIMIT_TO(arg, 0, lcp->l_item[I_FOOD]);
931         land->lnd_item[I_FOOD] = arg;
932         break;
933     case 's':
934         arg = LIMIT_TO(arg, 0, lcp->l_item[I_SHELL]);
935         land->lnd_item[I_SHELL] = arg;
936         break;
937     case 'g':
938         arg = LIMIT_TO(arg, 0, lcp->l_item[I_GUN]);
939         land->lnd_item[I_GUN] = arg;
940         break;
941     case 'p':
942         arg = LIMIT_TO(arg, 0, lcp->l_item[I_PETROL]);
943         land->lnd_item[I_PETROL] = arg;
944         break;
945     case 'i':
946         arg = LIMIT_TO(arg, 0, lcp->l_item[I_IRON]);
947         land->lnd_item[I_IRON] = arg;
948         break;
949     case 'd':
950         arg = LIMIT_TO(arg, 0, lcp->l_item[I_DUST]);
951         land->lnd_item[I_DUST] = arg;
952         break;
953     case 'o':
954         arg = LIMIT_TO(arg, 0, lcp->l_item[I_OIL]);
955         land->lnd_item[I_OIL] = arg;
956         break;
957     case 'l':
958         arg = LIMIT_TO(arg, 0, lcp->l_item[I_LCM]);
959         land->lnd_item[I_LCM] = arg;
960         break;
961     case 'h':
962         arg = LIMIT_TO(arg, 0, lcp->l_item[I_HCM]);
963         land->lnd_item[I_HCM] = arg;
964         break;
965     case 'r':
966         arg = LIMIT_TO(arg, 0, lcp->l_item[I_RAD]);
967         land->lnd_item[I_RAD] = arg;
968         break;
969     default:
970         pr("huh? (%s)\n", key);
971         return RET_FAIL;
972     }
973     return RET_OK;
974 }
975
976 static int
977 edit_plane(struct plnstr *plane, char *key, int arg, char *p)
978 {
979     struct plchrstr *pcp = &plchr[plane->pln_type];
980     coord newx, newy;
981
982     switch (*key) {
983     case 'U':
984         ef_set_uid(EF_PLANE, plane, arg);
985         break;
986     case 'l':
987         if (!sarg_xy(p, &newx, &newy))
988             return RET_SYN;
989         plane->pln_x = newx;
990         plane->pln_y = newy;
991         break;
992     case 'O':
993         if (arg < 0 || arg >= MAXNOC)
994             return RET_SYN;
995         if (plane->pln_own)
996             wu(player->cnum, plane->pln_own,
997                "%s taken from you by deity intervention!\n",
998                prplane(plane));
999         if (arg)
1000             wu(player->cnum, arg,
1001                "%s given to you by deity intervention!\n", prplane(plane));
1002         plane->pln_own = arg;
1003         break;
1004     case 'e':
1005         plane->pln_effic = LIMIT_TO(arg, PLANE_MINEFF, 100);
1006         break;
1007     case 'm':
1008         plane->pln_mobil = LIMIT_TO(arg, -127, 127);
1009         break;
1010     case 't':
1011         arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1012         pln_set_tech(plane, arg);
1013         break;
1014     case 'w':
1015         if (p[0] == '~')
1016             plane->pln_wing = 0;
1017         else if (isalpha(p[0]))
1018             plane->pln_wing = p[0];
1019         else {
1020             pr("%c: invalid wing\n", p[0]);
1021             return RET_FAIL;
1022         }
1023         break;
1024     case 'r':
1025         arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1026         plane->pln_range = (unsigned char)arg;
1027         break;
1028     case 's':
1029         if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1030             return RET_SYN;
1031         if (arg >= 0 && arg != plane->pln_ship)
1032             plane->pln_land = -1;
1033         plane->pln_ship = arg;
1034         break;
1035     case 'y':
1036         if (arg < -1 || arg >= ef_nelem(EF_LAND))
1037             return RET_SYN;
1038         if (arg >= 0 && arg != plane->pln_land)
1039             plane->pln_ship = -1;
1040         plane->pln_land = arg;
1041         break;
1042     case 'f':
1043         plane->pln_flags = arg;
1044         break;
1045     default:
1046         pr("huh? (%s)\n", key);
1047         return RET_FAIL;
1048     }
1049     return RET_OK;
1050 }