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