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