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