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