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