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