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