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