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