]> git.pond.sub.org Git - empserver/blob - src/lib/commands/edit.c
(MINES_MAX): New.
[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         new = errcheck(arg, 0, MINES_MAX);
631         sect->sct_mines = new;
632         pr("Mines changed to %d\n", new);
633         break;
634     case 'L':
635         if (!sarg_xy(p, &newx, &newy))
636             return RET_SYN;
637         sect->sct_x = newx;
638         sect->sct_y = newy;
639         break;
640     case 'D':
641         if (!sarg_xy(p, &newx, &newy))
642             return RET_SYN;
643         pr("Distribtion Location for sector %s changed from %s to %s\n",
644            xyas(sect->sct_x, sect->sct_y, player->cnum),
645            xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
646            xyas(newx, newy, player->cnum));
647         sect->sct_dist_x = newx;
648         sect->sct_dist_y = newy;
649         break;
650     case 's':
651         des = sct_typematch(p);
652         if (des < 0)
653             return RET_SYN;
654         pr("Designation for sector %s changed from %c to %c\n",
655            xyas(sect->sct_x, sect->sct_y, player->cnum),
656            dchr[sect->sct_type].d_mnem, dchr[des].d_mnem);
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 %d 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 %d 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 %d to %d\n", np->nat_money, arg);
762         wu(player->cnum, nat,
763            "Money changed from %d 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         ship->shp_tech = arg;
854         break;
855     case 'E':
856         ship->shp_effic = errcheck(arg, 0, 100);
857         if (arg < 10) {
858             ship->shp_effic = 0;
859             makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x,
860                      ship->shp_y);
861             ship->shp_own = (natid)0;
862         }
863         break;
864     case 'M':
865         ship->shp_mobil = arg;
866         break;
867     case 'B':
868         ship->shp_fuel = errcheck(arg, 0, 255);
869         break;
870     case 'F':
871         if (p[0] == '~')
872             ship->shp_fleet = ' ';
873         else if (isalpha(p[0]))
874             ship->shp_fleet = p[0];
875         else {
876             pr("%c: invalid fleet\n", p[0]);
877             return RET_FAIL;
878         }
879         break;
880     case 'Y':
881         ship->shp_nland = errcheck(arg, 0, 100);
882         break;
883     case 'P':
884         ship->shp_nplane = errcheck(arg, 0, 100);
885         break;
886     case 'c':
887         ship->shp_item[I_CIVIL] = arg;
888         break;
889     case 'm':
890         ship->shp_item[I_MILIT] = arg;
891         break;
892     case 'u':
893         ship->shp_item[I_UW] = arg;
894         break;
895     case 'f':
896         ship->shp_item[I_FOOD] = arg;
897         break;
898     case 's':
899         ship->shp_item[I_SHELL] = arg;
900         break;
901     case 'g':
902         ship->shp_item[I_GUN] = arg;
903         break;
904     case 'p':
905         ship->shp_item[I_PETROL] = arg;
906         break;
907     case 'i':
908         ship->shp_item[I_IRON] = arg;
909         break;
910     case 'd':
911         ship->shp_item[I_DUST] = arg;
912         break;
913     case 'o':
914         ship->shp_item[I_OIL] = arg;
915         break;
916     case 'l':
917         ship->shp_item[I_LCM] = arg;
918         break;
919     case 'h':
920         ship->shp_item[I_HCM] = arg;
921         break;
922     case 'r':
923         ship->shp_item[I_RAD] = arg;
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, 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, 0, 100);
973         if (arg < 10) {
974             makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x,
975                      land->lnd_y);
976             land->lnd_effic = 0;
977             land->lnd_own = (natid)0;
978         }
979         break;
980     case 'M':
981         land->lnd_mobil = arg;
982         break;
983     case 't':
984         land->lnd_tech = arg;
985         break;
986     case 'a':
987         if (p[0] == '~')
988             land->lnd_army = ' ';
989         else if (isalpha(p[0]))
990             land->lnd_army = p[0];
991         else {
992             pr("%c: invalid army\n", p[0]);
993             return RET_FAIL;
994         }
995         break;
996     case 'F':
997         land->lnd_harden = errcheck(arg, 0, 255);
998         break;
999     case 'B':
1000         land->lnd_fuel = errcheck(arg, 0, 255);
1001         break;
1002     case 'X':
1003         land->lnd_nxlight = arg;
1004         break;
1005     case 'S':
1006         land->lnd_ship = arg;
1007         break;
1008     case 'P':
1009         land->lnd_rad_max = arg;
1010         break;
1011     case 'Z':
1012         land->lnd_retreat = arg;
1013         break;
1014     case 'R':
1015         memcpy(land->lnd_rpath, p, sizeof(land->lnd_rpath));
1016         break;
1017     case 'W':
1018         land->lnd_rflags = arg;
1019         break;
1020     case 'c':
1021         land->lnd_item[I_CIVIL] = arg;
1022         break;
1023     case 'm':
1024         land->lnd_item[I_MILIT] = arg;
1025         break;
1026     case 'u':
1027         land->lnd_item[I_UW] = arg;
1028         break;
1029     case 'f':
1030         land->lnd_item[I_FOOD] = arg;
1031         break;
1032     case 's':
1033         land->lnd_item[I_SHELL] = arg;
1034         break;
1035     case 'g':
1036         land->lnd_item[I_GUN] = arg;
1037         break;
1038     case 'p':
1039         land->lnd_item[I_PETROL] = arg;
1040         break;
1041     case 'i':
1042         land->lnd_item[I_IRON] = arg;
1043         break;
1044     case 'd':
1045         land->lnd_item[I_DUST] = arg;
1046         break;
1047     case 'o':
1048         land->lnd_item[I_OIL] = arg;
1049         break;
1050     case 'l':
1051         land->lnd_item[I_LCM] = arg;
1052         break;
1053     case 'h':
1054         land->lnd_item[I_HCM] = arg;
1055         break;
1056     case 'r':
1057         land->lnd_item[I_RAD] = arg;
1058         break;
1059     default:
1060         pr("huh? (%c)\n", op);
1061         return RET_FAIL;
1062     }
1063     return RET_OK;
1064 }
1065
1066
1067 int
1068 doplane(s_char op, int arg, s_char *p, struct plnstr *plane)
1069 {
1070     coord newx, newy;
1071
1072     switch (op) {
1073     case 'n':
1074         plane->pln_nuketype = arg;
1075         break;
1076     case 'U':
1077         plane->pln_uid = arg;
1078         break;
1079     case 'l':
1080         if (!sarg_xy(p, &newx, &newy))
1081             return RET_SYN;
1082         plane->pln_x = newx;
1083         plane->pln_y = newy;
1084         break;
1085     case 'O':
1086         if (plane->pln_own)
1087             wu(player->cnum, plane->pln_own,
1088                "%s taken from you by deity intervention!\n",
1089                prplane(plane));
1090         if (arg && arg < MAXNOC) {
1091             makelost(EF_PLANE, plane->pln_own, plane->pln_uid,
1092                      plane->pln_x, plane->pln_y);
1093             plane->pln_own = (natid)arg;
1094             makenotlost(EF_PLANE, plane->pln_own, plane->pln_uid,
1095                         plane->pln_x, plane->pln_y);
1096             wu(player->cnum, plane->pln_own,
1097                "%s given to you by deity intervention!\n", prplane(plane));
1098         } else if (!arg) {
1099             plane->pln_effic = 0;
1100             makelost(EF_PLANE, plane->pln_own, plane->pln_uid,
1101                      plane->pln_x, plane->pln_y);
1102             plane->pln_own = (natid)0;
1103         }
1104         break;
1105     case 'e':
1106         plane->pln_effic = errcheck(arg, 0, 100);
1107         if (arg < 10) {
1108             plane->pln_effic = 0;
1109             makelost(EF_PLANE, plane->pln_own, plane->pln_uid,
1110                      plane->pln_x, plane->pln_y);
1111             plane->pln_own = (natid)0;
1112         }
1113         break;
1114     case 'm':
1115         plane->pln_mobil = errcheck(arg, -127, 255);
1116         break;
1117     case 't':
1118         plane->pln_tech = arg;
1119         break;
1120     case 'w':
1121         if (p[0] == '~')
1122             plane->pln_wing = ' ';
1123         else if (isalpha(p[0]))
1124             plane->pln_wing = p[0];
1125         else {
1126             pr("%c: invalid wing\n", p[0]);
1127             return RET_FAIL;
1128         }
1129         break;
1130     case 'a':
1131         plane->pln_att = (s_char)errcheck(arg, 0, 127);
1132         break;
1133     case 'd':
1134         plane->pln_def = (s_char)arg;
1135         break;
1136     case 'r':
1137         plane->pln_range = (u_char)arg;
1138         break;
1139     case 's':
1140         plane->pln_ship = arg;
1141         break;
1142     case 'y':
1143         plane->pln_land = arg;
1144         break;
1145     case 'f':
1146         plane->pln_flags = arg;
1147         break;
1148     default:
1149         pr("huh? (%c)\n", op);
1150         return RET_FAIL;
1151     }
1152     return RET_OK;
1153 }