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