]> git.pond.sub.org Git - empserver/blob - src/lib/commands/edit.c
(dship, dounit, doplane): No longer accept efficiency values that
[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-2004
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, float farg, 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 = (float)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             farg = (float)atof(ptr);
220             if ((err = dounit(thing[0], arg, ptr, farg, &land))
221                 != RET_OK)
222                 return err;
223             if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50))
224                 return RET_FAIL;
225             if (!putland(land.lnd_uid, &land))
226                 return RET_FAIL;
227             break;
228         case 'p':
229             if ((err = doplane(thing[0], arg, ptr, &plane))
230                 != RET_OK)
231                 return err;
232             if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50))
233                 return RET_FAIL;
234             if (!putplane(plane.pln_uid, &plane))
235                 return RET_FAIL;
236             break;
237         }
238         if (err != RET_OK)
239             break;
240         else
241             ptr = 0;
242     }
243     return RET_OK;
244 }
245
246 static void
247 benefit(natid who, int good)
248 {
249     if (!opt_GODNEWS)
250         return;
251
252     if (good) {
253         if (who)
254             nreport(player->cnum, N_AIDS, who, 1);
255     } else {
256         if (who)
257             nreport(player->cnum, N_HURTS, who, 1);
258     }
259 }
260
261 static void
262 noise(struct sctstr *sptr, int public_amt, s_char *name, int old, int new)
263 {
264     s_char p[100];
265
266     pr("%s of %s changed from %d to %d\n",
267        name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new);
268     if (public_amt)
269         (void)sprintf(p, "changed from %d to %d", old, new);
270     else
271         (void)sprintf(p, "%s", (old < new ? "increased" : "decreased"));
272     if (sptr->sct_own)
273         wu(player->cnum, sptr->sct_own,
274            "%s in %s was %s by an act of %s\n",
275            name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own),
276            p, cname(player->cnum));
277     benefit(sptr->sct_own, (old < new));
278 }
279
280 static void
281 prsect(struct sctstr *sect)
282 {
283     pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
284     pr("Distribution sector <D>: %s\n",
285        xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
286     pr("Designation <s>: %c\t New designation <S>: %c\n",
287        dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
288     pr("own  oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
289     pr("  o   O   e   m   i   g   f   c   u   w   l   x   X   p     t    F     a\n");
290     pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
291        sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
292        sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
293        sect->sct_uran, sect->sct_work, sect->sct_loyal,
294        sect->sct_che, sect->sct_che_target,
295        sect->sct_pstage, sect->sct_ptime,
296        sect->sct_fallout, sect->sct_avail);
297
298     pr("Mines <M>: %d\t", sect->sct_mines);
299     pr("Coastal <C>: %d\n", sect->sct_coastal);
300     pr("Road %% <R>: %d\t", sect->sct_road);
301     pr("Rail %% <r>: %d\t", sect->sct_rail);
302     pr("Defense %% <d>: %d\n", sect->sct_defense);
303 }
304
305
306 static void
307 prnat(natid n)
308 {
309     struct natstr *np;
310     int i;
311
312     if ((np = getnatp(n)) == 0)
313         return;
314     pr("Country #: %2d\n", n);
315     pr("Name <n>: %-20s\t", np->nat_cnam);
316     pr("Connected: %d\n", np->nat_connected);
317     pr("Representative <r>: %-20s\n", np->nat_pnam);
318     pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
319     pr("Reserves <m>: %5ld\n", np->nat_reserve);
320     pr("Capital <c>: %s\t\t",
321        xyas(np->nat_xcap, np->nat_ycap, player->cnum));
322     pr("Origin <o>: %3s\n",
323        xyas(np->nat_xorg, np->nat_yorg, player->cnum));
324     pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
325     pr("Min Used <u>: %3d\n", np->nat_minused);
326     pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
327     pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
328     pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
329     pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
330     pr("Money <M>: $%6ld\n", np->nat_money);
331     pr("Telegrams <t>: %6d\n", np->nat_tgms);
332     if (opt_DEMANDUPDATE)
333         pr("Updates missed <U>: %d\n", np->nat_missed);
334     if (opt_HIDDEN) {
335         pr("Countries contacted: ");
336         for (i = 0; i < MAXNOC; i++) {
337             if (getcontact(np, i))
338                 pr("%d(%d) ", i, getcontact(np, i));
339         }
340         pr("\n");
341     }
342 }
343
344 static void
345 pr_plane(struct plnstr *plane)
346 {
347     pr("UID <U>: %d\t\t", (int)plane->pln_uid);
348     pr("Owner <O>: %d\t\t", (int)plane->pln_own);
349     pr("Location <l>: %s\n",
350        xyas(plane->pln_x, plane->pln_y, player->cnum));
351     pr("Efficiency <e>: %d\t", (int)plane->pln_effic);
352     pr("Mobility <m>: %d\n", (int)plane->pln_mobil);
353     pr("Tech <t>: %d\t\t", plane->pln_tech);
354     pr("Wing <w>: %c\n", plane->pln_wing);
355     pr("Attack <a>: %d\t\t", plane->pln_att);
356     pr("Defense <d>: %d\n", plane->pln_def);
357     pr("Range <r>: %d\t\t", plane->pln_range);
358     pr("Flags <f>: %d\n", plane->pln_flags);
359     pr("Ship <s>: %d\t\t", plane->pln_ship);
360     pr("Land Unit <y>: %d\t", plane->pln_land);
361     pr("Nuke Type <n>: %d\n", plane->pln_nuketype);
362 }
363
364 static void
365 pr_land(struct lndstr *land)
366 {
367     pr("UID <U>: %d\n", (int)land->lnd_uid);
368     pr("Owner <O>: %d\n", (int)land->lnd_own);
369     pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
370     pr("Efficiency <e>: %d\t", (int)land->lnd_effic);
371     pr("Mobility <M>: %d\n", (int)land->lnd_mobil);
372     pr("Tech <t>: %d\t\t", land->lnd_tech);
373     pr("Army <a>: %c\n", land->lnd_army);
374     pr("Attack <A>: %1.2f\t", land->lnd_att);
375     pr("Defense <D>: %1.2f\n", land->lnd_def);
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("Defense <D>: %d\n", (int)ship->shp_armor);
429     pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
430        ship->shp_rpath, (int)ship->shp_rflags);
431     pr("Plague Stage <a>: %d\t\t",ship->shp_pstage);
432     pr("Plague Time <b>: %d\n", ship->shp_ptime);
433     pr("civ mil  uw food shl gun  pet  irn  dst  oil  lcm  hcm rad\n");
434     pr("  c   m   u    f   s   g    p    i    d    o    l    h   r\n");
435     pr("%3d", ship->shp_item[I_CIVIL]);
436     pr("%4d", ship->shp_item[I_MILIT]);
437     pr("%4d", ship->shp_item[I_UW]);
438     pr("%5d", ship->shp_item[I_FOOD]);
439     pr("%4d", ship->shp_item[I_SHELL]);
440     pr("%4d", ship->shp_item[I_GUN]);
441     pr("%5d", ship->shp_item[I_PETROL]);
442     pr("%5d", ship->shp_item[I_IRON]);
443     pr("%5d", ship->shp_item[I_DUST]);
444     pr("%5d", ship->shp_item[I_OIL]);
445     pr("%5d", ship->shp_item[I_LCM]);
446     pr("%5d", ship->shp_item[I_HCM]);
447     pr("%4d", ship->shp_item[I_RAD]);
448     pr("\n");
449 }
450
451 static int
452 errcheck(int num, int min, int max)
453 {
454     if (num < min)
455         return (min);
456     else if (num > max)
457         return (max);
458     return (num);
459 }
460
461 static int
462 getin(s_char **what, s_char **p, int *arg, s_char *buf)
463 {
464     if (!(*what = getstarg(*p, "%c xxxxx -- thing value : ", buf))) {
465         return RET_SYN;
466     }
467     if (**what == '\0')
468         return END;
469     while (**what && isspace(**what))
470         (*what)++;
471     if (**what == '\0')
472         return RET_SYN;
473     for (*p = *what; **p && !isspace(**p); (*p)++)      /* skip non spaces */
474         continue;
475     while (**p && isspace(**p))
476         (*p)++;
477     if (**p == '\0')
478         return RET_SYN;
479     *arg = atoi(*p);
480     return RET_OK;
481 }
482
483
484 static int
485 doland(s_char op, int arg, s_char *p, struct sctstr *sect)
486 {
487     natid newown, oldown;
488     coord newx, newy;
489     int new, old;
490     int des;
491     switch (op) {
492     case 'C':
493         if (arg < 0)
494             return RET_SYN;
495         sect->sct_coastal = (arg ? 1 : 0);
496         pr("Coastal flag of %s changed to %d\n",
497            xyas(sect->sct_x, sect->sct_y, player->cnum),
498            sect->sct_coastal);
499         break;
500     case 'o':
501         if (arg < 0)
502             return RET_SYN;
503         newown = (natid)errcheck(arg, 0, MAXNOC - 1);
504         pr("Owner of %s changed from %s (#%d) to %s (#%d).\n",
505            xyas(sect->sct_x, sect->sct_y, player->cnum),
506            cname(sect->sct_own), sect->sct_own, cname(newown), newown);
507         if (sect->sct_own) {
508             makelost(EF_SECTOR, sect->sct_own, 0, sect->sct_x,
509                      sect->sct_y);
510             wu(player->cnum, sect->sct_own,
511                "Sector %s lost to deity intervention\n", xyas(sect->sct_x,
512                                                               sect->sct_y,
513                                                               sect->
514                                                               sct_own));
515         }
516         benefit(sect->sct_own, 0);
517         sect->sct_own = newown;
518         if (newown) {
519             makenotlost(EF_SECTOR, newown, 0, sect->sct_x, sect->sct_y);
520             wu(player->cnum, newown,
521                "Sector %s gained from deity intervention\n",
522                xyas(sect->sct_x, sect->sct_y, sect->sct_own));
523         }
524         benefit(newown, 1);
525         break;
526     case 'O':
527         if (arg < 0)
528             return RET_SYN;
529         oldown = (natid)errcheck(arg, 0, MAXNOC - 1);
530         pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n",
531            xyas(sect->sct_x, sect->sct_y, player->cnum),
532            cname(sect->sct_oldown),
533            sect->sct_oldown, cname(oldown), oldown);
534         sect->sct_oldown = oldown;
535         break;
536     case 'e':
537         new = errcheck(arg, 0, 100);
538         noise(sect, 1, "Efficiency", (int)sect->sct_effic, new);
539         sect->sct_effic = (u_char)new;
540         break;
541     case 'm':
542         new = errcheck(arg, -127, 255);
543         noise(sect, 1, "Mobility", (int)sect->sct_mobil, new);
544         sect->sct_mobil = new;
545         break;
546     case 'i':
547         new = errcheck(arg, 0, 127);
548         noise(sect, 1, "Iron ore content", (int)sect->sct_min, new);
549         sect->sct_min = (u_char)new;
550         break;
551     case 'g':
552         new = errcheck(arg, 0, 127);
553         noise(sect, 1, "Gold content", (int)sect->sct_gmin, new);
554         sect->sct_gmin = (u_char)new;
555         break;
556     case 'f':
557         new = errcheck(arg, 0, 127);
558         noise(sect, 1, "Fertility", (int)sect->sct_fertil, new);
559         sect->sct_fertil = (u_char)new;
560         break;
561     case 'c':
562         new = errcheck(arg, 0, 127);
563         noise(sect, 1, "Oil content", (int)sect->sct_oil, new);
564         sect->sct_oil = (u_char)new;
565         break;
566     case 'u':
567         new = errcheck(arg, 0, 127);
568         noise(sect, 1, "Uranium content", (int)sect->sct_uran, new);
569         sect->sct_uran = (u_char)new;
570         break;
571     case 'w':
572         new = errcheck(arg, 0, 100);
573         noise(sect, 1, "Workforce percentage", (int)sect->sct_work, new);
574         sect->sct_work = (u_char)new;
575         break;
576     case 'l':
577         new = errcheck(arg, 0, 127);
578         pr("Loyalty of %s changed from %d to %d%%\n",
579            xyas(sect->sct_x, sect->sct_y, player->cnum),
580            sect->sct_loyal, new);
581         sect->sct_loyal = (u_char)new;
582         break;
583     case 'x':
584         old = sect->sct_che;
585         new = errcheck(arg, 0, CHE_MAX);
586         pr("Guerillas in %s changed from %d to %d\n",
587            xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
588         sect->sct_che = new;
589         break;
590     case 'X':
591         old = sect->sct_che_target;
592         new = errcheck(arg, 0, MAXNOC - 1);
593         pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n",
594            xyas(sect->sct_x, sect->sct_y, player->cnum),
595            cname(old), old, cname(new), new);
596         sect->sct_che_target = new;
597         break;
598     case 'p':
599         old = sect->sct_pstage;
600         new = errcheck(arg, 0, PLG_EXPOSED);
601         pr("Plague stage of %s changed from %d to %d%%\n",
602            xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
603         sect->sct_pstage = new;
604         break;
605     case 't':
606         old = sect->sct_ptime;
607         new = errcheck(arg, 0, 255);
608         pr("Plague time of %s changed from %d to %d%%\n",
609            xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
610         sect->sct_ptime = new;
611         break;
612     case 'F':
613         old = sect->sct_fallout;
614         new = errcheck(arg, 0, FALLOUT_MAX);
615         pr("Fallout for sector %s changed from %d to %d\n",
616            xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
617         sect->sct_fallout = new;
618         break;
619     case 'a':
620         new = errcheck(arg, 0, 9999);
621         noise(sect, 1, "Available workforce", (int)sect->sct_avail, new);
622         sect->sct_avail = new;
623         break;
624     case 'M':
625         new = errcheck(arg, 0, MINES_MAX);
626         sect->sct_mines = new;
627         pr("Mines changed to %d\n", new);
628         break;
629     case 'L':
630         if (!sarg_xy(p, &newx, &newy))
631             return RET_SYN;
632         sect->sct_x = newx;
633         sect->sct_y = newy;
634         break;
635     case 'D':
636         if (!sarg_xy(p, &newx, &newy))
637             return RET_SYN;
638         pr("Distribtion Location for sector %s changed from %s to %s\n",
639            xyas(sect->sct_x, sect->sct_y, player->cnum),
640            xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
641            xyas(newx, newy, player->cnum));
642         sect->sct_dist_x = newx;
643         sect->sct_dist_y = newy;
644         break;
645     case 's':
646         des = sct_typematch(p);
647         if (des < 0)
648             return RET_SYN;
649         pr("Designation for sector %s changed from %c to %c\n",
650            xyas(sect->sct_x, sect->sct_y, player->cnum),
651            dchr[sect->sct_type].d_mnem, dchr[des].d_mnem);
652         sect->sct_type = des;
653         break;
654     case 'S':
655         des = sct_typematch(p);
656         if (des < 0)
657             return RET_SYN;
658         pr("New Designation for sector %s changed from %c to %c\n",
659            xyas(sect->sct_x, sect->sct_y, player->cnum),
660            dchr[sect->sct_newtype].d_mnem, dchr[des].d_mnem);
661         sect->sct_newtype = des;
662         break;
663     case 'R':
664         if (arg > 100)
665             arg = 100;
666         if (arg < 0)
667             arg = 0;
668         noise(sect, 1, "Road percentage", (int)sect->sct_road, arg);
669         sect->sct_road = arg;
670         break;
671     case 'r':
672         if (arg > 100)
673             arg = 100;
674         if (arg < 0)
675             arg = 0;
676         noise(sect, 1, "Rail percentage", (int)sect->sct_rail, arg);
677         sect->sct_rail = arg;
678         break;
679     case 'd':
680         if (arg > 100)
681             arg = 100;
682         if (arg < 0)
683             arg = 0;
684         noise(sect, 1, "Defense percentage", (int)sect->sct_defense, arg);
685         sect->sct_defense = arg;
686         break;
687     default:
688         pr("huh? (%c)\n", op);
689         return RET_SYN;
690     }
691     return RET_OK;
692 }
693
694
695 static int
696 docountry(s_char op, int arg, s_char *p, float farg, natid nat,
697           struct natstr *np)
698 {
699     coord newx, newy;
700     switch (op) {
701     case 'n':
702         pr("Country name changed from %s to %s\n", np->nat_cnam, p);
703         strncpy(np->nat_cnam, p, sizeof(np->nat_cnam) - 1);
704         break;
705     case 'r':
706         pr("Country representative changed from %s to %s\n",
707            np->nat_pnam, p);
708         strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
709         break;
710     case 't':
711         np->nat_tgms = arg;
712         break;
713     case 'b':
714         arg = errcheck(arg, 0, 1024);
715         pr("BTU's changed from %d to %d\n", np->nat_btu, arg);
716         np->nat_btu = arg;
717         break;
718     case 'm':
719         benefit(nat, np->nat_reserve < arg);
720         pr("Military Reserves changed from %ld to %d\n",
721            np->nat_reserve, arg);
722         if (np->nat_stat == STAT_NORM)
723             wu(player->cnum, nat,
724                "Military Reserves changed from %ld to %d by divine intervention.\n",
725                np->nat_reserve, arg);
726         np->nat_reserve = arg;
727         break;
728     case 'c':
729         if (!sarg_xy(p, &newx, &newy))
730             return RET_SYN;
731         pr("Capital coordinates changed from %s to %s\n",
732            xyas(np->nat_xcap, np->nat_ycap, player->cnum),
733            xyas(newx, newy, player->cnum));
734         np->nat_xcap = newx;
735         np->nat_ycap = newy;
736         break;
737     case 'o':
738         if (!sarg_xy(p, &newx, &newy))
739             return RET_SYN;
740         pr("Origin coordinates changed from %s to %s\n",
741            xyas(np->nat_xorg, np->nat_yorg, player->cnum),
742            xyas(newx, newy, player->cnum));
743         np->nat_xorg = newx;
744         np->nat_yorg = newy;
745         break;
746     case 's':
747         np->nat_stat = (s_char)errcheck(arg, 0, STAT_NEW);
748         break;
749     case 'u':
750         arg = errcheck(arg, 0, m_m_p_d);
751         pr("Number of minutes used changed from %d to %d.\n",
752            np->nat_minused, arg);
753         np->nat_minused = arg;
754         break;
755     case 'M':
756         pr("Money changed from %ld to %d\n", np->nat_money, arg);
757         wu(player->cnum, nat,
758            "Money changed from %ld to %d by divine intervention.\n",
759            np->nat_money, arg);
760         np->nat_money = arg;
761         break;
762     case 'T':
763         pr("Tech changed from %.2f to %.2f.\n",
764            np->nat_level[NAT_TLEV], farg);
765         np->nat_level[NAT_TLEV] = farg;
766         break;
767     case 'R':
768         pr("Research changed from %.2f to %.2f.\n",
769            np->nat_level[NAT_RLEV], farg);
770         np->nat_level[NAT_RLEV] = farg;
771         break;
772     case 'E':
773         pr("Education changed from %.2f to %.2f.\n",
774            np->nat_level[NAT_ELEV], farg);
775         np->nat_level[NAT_ELEV] = farg;
776         break;
777     case 'H':
778         pr("Happiness changed from %.2f to %.2f.\n",
779            np->nat_level[NAT_HLEV], farg);
780         np->nat_level[NAT_HLEV] = farg;
781         break;
782     case 'U':
783         np->nat_missed = arg;
784         break;
785     default:
786         pr("huh? (%c)\n", op);
787         break;
788     }
789     putnat(np);
790     return RET_OK;
791 }
792
793
794 static int
795 doship(s_char op, int arg, s_char *p, struct shpstr *ship)
796 {
797     coord newx, newy;
798
799     newx = newy = 0;
800     switch (op) {
801     case 'a':
802         ship->shp_pstage = arg;
803         break;
804     case 'b':
805         ship->shp_ptime = arg;
806         break;
807     case 'R':
808         memcpy(ship->shp_rpath, p, sizeof(ship->shp_rpath));
809         break;
810     case 'W':
811         ship->shp_rflags = arg;
812         break;
813     case 'H':
814         ship->shp_nchoppers = arg;
815         break;
816     case 'X':
817         ship->shp_nxlight = arg;
818         break;
819     case 'U':
820         ship->shp_uid = arg;
821         break;
822     case 'O':
823         if (ship->shp_own)
824             wu(player->cnum, ship->shp_own,
825                "%s taken from you by deity intervention!\n", prship(ship));
826         if (arg && arg < MAXNOC) {
827             wu(player->cnum, (natid)arg,
828                "%s given to you by deity intervention!\n", prship(ship));
829             makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x,
830                      ship->shp_y);
831             ship->shp_own = (natid)arg;
832             makenotlost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x,
833                         ship->shp_y);
834         } else if (!arg) {
835             ship->shp_effic = 0;
836             makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x,
837                      ship->shp_y);
838             ship->shp_own = (natid)0;
839         }
840         break;
841     case 'L':
842         if (!sarg_xy(p, &newx, &newy))
843             return RET_SYN;
844         ship->shp_x = newx;
845         ship->shp_y = newy;
846         break;
847     case 'T':
848         ship->shp_tech = arg;
849         break;
850     case 'E':
851         ship->shp_effic = errcheck(arg, SHIP_MINEFF, 100);
852         break;
853     case 'M':
854         ship->shp_mobil = arg;
855         break;
856     case 'B':
857         ship->shp_fuel = errcheck(arg, 0, 255);
858         break;
859     case 'F':
860         if (p[0] == '~')
861             ship->shp_fleet = ' ';
862         else if (isalpha(p[0]))
863             ship->shp_fleet = p[0];
864         else {
865             pr("%c: invalid fleet\n", p[0]);
866             return RET_FAIL;
867         }
868         break;
869     case 'Y':
870         ship->shp_nland = errcheck(arg, 0, 100);
871         break;
872     case 'P':
873         ship->shp_nplane = errcheck(arg, 0, 100);
874         break;
875     case 'c':
876         ship->shp_item[I_CIVIL] = arg;
877         break;
878     case 'm':
879         ship->shp_item[I_MILIT] = arg;
880         break;
881     case 'u':
882         ship->shp_item[I_UW] = arg;
883         break;
884     case 'f':
885         ship->shp_item[I_FOOD] = arg;
886         break;
887     case 's':
888         ship->shp_item[I_SHELL] = arg;
889         break;
890     case 'g':
891         ship->shp_item[I_GUN] = arg;
892         break;
893     case 'p':
894         ship->shp_item[I_PETROL] = arg;
895         break;
896     case 'i':
897         ship->shp_item[I_IRON] = arg;
898         break;
899     case 'd':
900         ship->shp_item[I_DUST] = arg;
901         break;
902     case 'o':
903         ship->shp_item[I_OIL] = arg;
904         break;
905     case 'l':
906         ship->shp_item[I_LCM] = arg;
907         break;
908     case 'h':
909         ship->shp_item[I_HCM] = arg;
910         break;
911     case 'r':
912         ship->shp_item[I_RAD] = arg;
913         break;
914     case 'D':
915         ship->shp_armor = errcheck(arg, 0, 127);
916         break;
917     default:
918         pr("huh? (%c)\n", op);
919         return RET_FAIL;
920     }
921     return RET_OK;
922 }
923
924 static int
925 dounit(s_char op, int arg, s_char *p, float farg, struct lndstr *land)
926 {
927     coord newx, newy;
928
929     newx = newy = 0;
930     switch (op) {
931     case 'Y':
932         land->lnd_land = arg;
933         break;
934     case 'U':
935         land->lnd_uid = arg;
936         break;
937     case 'O':
938         if (land->lnd_own)
939             wu(player->cnum, land->lnd_own,
940                "%s taken from you by deity intervention!\n", prland(land));
941
942         if (arg && arg < MAXNOC) {
943             wu(player->cnum, (natid)arg,
944                "%s given to you by deity intervention!\n", prland(land));
945             makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x,
946                      land->lnd_y);
947             land->lnd_own = (natid)arg;
948             makenotlost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x,
949                         land->lnd_y);
950         } else if (!arg) {
951             makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x,
952                      land->lnd_y);
953             land->lnd_effic = 0;
954             land->lnd_own = (natid)0;
955         }
956         break;
957     case 'L':
958         if (!sarg_xy(p, &newx, &newy))
959             return RET_SYN;
960         land->lnd_x = newx;
961         land->lnd_y = newy;
962         break;
963     case 'e':
964         land->lnd_effic = errcheck(arg, LAND_MINEFF, 100);
965         break;
966     case 'M':
967         land->lnd_mobil = arg;
968         break;
969     case 't':
970         land->lnd_tech = arg;
971         break;
972     case 'a':
973         if (p[0] == '~')
974             land->lnd_army = ' ';
975         else if (isalpha(p[0]))
976             land->lnd_army = p[0];
977         else {
978             pr("%c: invalid army\n", p[0]);
979             return RET_FAIL;
980         }
981         break;
982     case 'F':
983         land->lnd_harden = errcheck(arg, 0, 255);
984         break;
985     case 'B':
986         land->lnd_fuel = errcheck(arg, 0, 255);
987         break;
988     case 'X':
989         land->lnd_nxlight = arg;
990         break;
991     case 'S':
992         land->lnd_ship = arg;
993         break;
994     case 'P':
995         land->lnd_rad_max = arg;
996         break;
997     case 'Z':
998         land->lnd_retreat = arg;
999         break;
1000     case 'R':
1001         memcpy(land->lnd_rpath, p, sizeof(land->lnd_rpath));
1002         break;
1003     case 'W':
1004         land->lnd_rflags = arg;
1005         break;
1006     case 'c':
1007         land->lnd_item[I_CIVIL] = arg;
1008         break;
1009     case 'm':
1010         land->lnd_item[I_MILIT] = arg;
1011         break;
1012     case 'u':
1013         land->lnd_item[I_UW] = arg;
1014         break;
1015     case 'f':
1016         land->lnd_item[I_FOOD] = arg;
1017         break;
1018     case 's':
1019         land->lnd_item[I_SHELL] = arg;
1020         break;
1021     case 'g':
1022         land->lnd_item[I_GUN] = arg;
1023         break;
1024     case 'p':
1025         land->lnd_item[I_PETROL] = arg;
1026         break;
1027     case 'i':
1028         land->lnd_item[I_IRON] = arg;
1029         break;
1030     case 'd':
1031         land->lnd_item[I_DUST] = arg;
1032         break;
1033     case 'o':
1034         land->lnd_item[I_OIL] = arg;
1035         break;
1036     case 'l':
1037         land->lnd_item[I_LCM] = arg;
1038         break;
1039     case 'h':
1040         land->lnd_item[I_HCM] = arg;
1041         break;
1042     case 'r':
1043         land->lnd_item[I_RAD] = arg;
1044         break;
1045     case 'A':
1046         pr("Attack changed from %1.2f to %1.2f.\n",
1047            land->lnd_att, farg);
1048         land->lnd_att = farg;
1049         break;
1050     case 'D':
1051         pr("Defense changed from %1.2f to %1.2f.\n",
1052            land->lnd_def, farg);
1053         land->lnd_def = farg;
1054         break;
1055     default:
1056         pr("huh? (%c)\n", op);
1057         return RET_FAIL;
1058     }
1059     return RET_OK;
1060 }
1061
1062
1063 int
1064 doplane(s_char op, int arg, s_char *p, struct plnstr *plane)
1065 {
1066     coord newx, newy;
1067
1068     switch (op) {
1069     case 'n':
1070         plane->pln_nuketype = arg;
1071         break;
1072     case 'U':
1073         plane->pln_uid = arg;
1074         break;
1075     case 'l':
1076         if (!sarg_xy(p, &newx, &newy))
1077             return RET_SYN;
1078         plane->pln_x = newx;
1079         plane->pln_y = newy;
1080         break;
1081     case 'O':
1082         if (plane->pln_own)
1083             wu(player->cnum, plane->pln_own,
1084                "%s taken from you by deity intervention!\n",
1085                prplane(plane));
1086         if (arg && arg < MAXNOC) {
1087             makelost(EF_PLANE, plane->pln_own, plane->pln_uid,
1088                      plane->pln_x, plane->pln_y);
1089             plane->pln_own = (natid)arg;
1090             makenotlost(EF_PLANE, plane->pln_own, plane->pln_uid,
1091                         plane->pln_x, plane->pln_y);
1092             wu(player->cnum, plane->pln_own,
1093                "%s given to you by deity intervention!\n", prplane(plane));
1094         } else if (!arg) {
1095             plane->pln_effic = 0;
1096             makelost(EF_PLANE, plane->pln_own, plane->pln_uid,
1097                      plane->pln_x, plane->pln_y);
1098             plane->pln_own = (natid)0;
1099         }
1100         break;
1101     case 'e':
1102         plane->pln_effic = errcheck(arg, PLANE_MINEFF, 100);
1103         break;
1104     case 'm':
1105         plane->pln_mobil = errcheck(arg, -127, 255);
1106         break;
1107     case 't':
1108         plane->pln_tech = arg;
1109         break;
1110     case 'w':
1111         if (p[0] == '~')
1112             plane->pln_wing = ' ';
1113         else if (isalpha(p[0]))
1114             plane->pln_wing = p[0];
1115         else {
1116             pr("%c: invalid wing\n", p[0]);
1117             return RET_FAIL;
1118         }
1119         break;
1120     case 'a':
1121         plane->pln_att = (s_char)errcheck(arg, 0, 127);
1122         break;
1123     case 'd':
1124         plane->pln_def = (s_char)arg;
1125         break;
1126     case 'r':
1127         plane->pln_range = (u_char)arg;
1128         break;
1129     case 's':
1130         plane->pln_ship = arg;
1131         break;
1132     case 'y':
1133         plane->pln_land = arg;
1134         break;
1135     case 'f':
1136         plane->pln_flags = arg;
1137         break;
1138     default:
1139         pr("huh? (%c)\n", op);
1140         return RET_FAIL;
1141     }
1142     return RET_OK;
1143 }