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
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.
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.
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/>.
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.
27 * edit.c: Edit things (sectors, ships, planes, units, nukes, countries)
29 * Known contributors to this file:
32 * Steve McClure, 1998-2000
33 * Ron Koenderink, 2003-2009
34 * Markus Armbruster, 2003-2013
52 static void print_sect(struct sctstr *);
53 static void print_nat(struct natstr *);
54 static void print_plane(struct plnstr *);
55 static void print_land(struct lndstr *);
56 static void print_ship(struct shpstr *);
57 static char *getin(char *, char **);
58 static int edit_nat(struct natstr *, char *, char *);
59 static int edit_ship(struct shpstr *, char *, char *);
60 static int edit_land(struct lndstr *, char *, char *);
61 static int edit_plane(struct plnstr *, char *, char *);
66 union empobj_storage item;
77 what = getstarg(player->argp[1],
78 "Edit what (country, land, ship, plane, nuke, unit)? ",
85 if (!(ptr = getstarg(player->argp[2], "Sector : ", buf)))
87 if (!sarg_xy(ptr, &x, &y))
89 if (!getsect(x, y, &item.sect))
93 np = natargp(player->argp[2], "Country? ");
98 if ((num = onearg(player->argp[2], "Plane number? ")) < 0)
100 if (!getplane(num, &item.plane))
104 if ((num = onearg(player->argp[2], "Ship number? ")) < 0)
106 if (!getship(num, &item.ship))
110 if ((num = onearg(player->argp[2], "Unit number? ")) < 0)
112 if (!getland(num, &item.land))
116 pr("Not implemented yet.\n");
122 if (!player->argp[3]) {
125 print_sect(&item.sect);
131 print_plane(&item.plane);
134 print_ship(&item.ship);
137 print_land(&item.land);
144 if (player->argp[arg_index]) {
145 if (player->argp[arg_index+1]) {
146 key = player->argp[arg_index++];
147 ptr = player->argp[arg_index++];
150 } else if (arg_index == 3) {
151 key = getin(buf, &ptr);
161 ret = edit_nat(np, key, ptr);
168 if (!check_sect_ok(&item.sect))
170 ret = edit_sect(&item.sect, key, ptr);
173 if (!putsect(&item.sect))
177 if (!check_ship_ok(&item.ship))
179 ret = edit_ship(&item.ship, key, ptr);
182 if (!putship(item.ship.shp_uid, &item.ship))
186 if (!check_land_ok(&item.land))
188 ret = edit_land(&item.land, key, ptr);
191 if (!putland(item.land.lnd_uid, &item.land))
195 if (!check_plane_ok(&item.plane))
197 ret = edit_plane(&item.plane, key, ptr);
200 if (!putplane(item.plane.pln_uid, &item.plane))
210 noise(struct sctstr *sptr, char *name, int old, int new)
212 divine_sct_change(sptr, name, new != old, new - old,
213 "from %d to %d", old, new);
217 print_sect(struct sctstr *sect)
219 pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
220 pr("Distribution sector <D>: %s\n",
221 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
222 pr("Designation <s>: %c\tNew designation <S>: %c\n",
223 dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
224 pr("own oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
225 pr(" o O e m i g f c u w l x X p t F a\n");
226 pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
227 sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
228 sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
229 sect->sct_uran, sect->sct_work, sect->sct_loyal,
230 sect->sct_che, sect->sct_che_target,
231 sect->sct_pstage, sect->sct_ptime,
232 sect->sct_fallout, sect->sct_avail);
234 pr("Mines <M>: %d\n", sect->sct_mines);
235 pr("Road %% <R>: %d\t", sect->sct_road);
236 pr("Rail %% <r>: %d\t", sect->sct_rail);
237 pr("Defense %% <d>: %d\n", sect->sct_defense);
241 print_nat(struct natstr *np)
245 pr("Country #: %2d\n", np->nat_cnum);
246 pr("Name <n>: %-20s\t", np->nat_cnam);
247 pr("Representative <r>: %-20s\n", np->nat_pnam);
248 pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
249 pr("Reserves <m>: %5d\n", np->nat_reserve);
250 pr("Capital <c>: %s\t\t",
251 xyas(np->nat_xcap, np->nat_ycap, player->cnum));
252 pr("Origin <o>: %3s\n",
253 xyas(np->nat_xorg, np->nat_yorg, player->cnum));
254 pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
255 pr("Seconds Used <u>: %3d\n", np->nat_timeused);
256 pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
257 pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
258 pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
259 pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
260 pr("Money <M>: $%6d\n", np->nat_money);
261 pr("Telegrams <t>: %6d\n", np->nat_tgms);
263 pr("Countries contacted: ");
264 for (i = 0; i < MAXNOC; i++) {
265 if (getcontact(np, i))
266 pr("%d(%d) ", i, getcontact(np, i));
273 print_plane(struct plnstr *plane)
275 pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
276 pr("UID <U>: %d\t\t", plane->pln_uid);
277 pr("Owner <O>: %d\t\t", plane->pln_own);
278 pr("Location <l>: %s\n",
279 xyas(plane->pln_x, plane->pln_y, player->cnum));
280 pr("Efficiency <e>: %d\t", plane->pln_effic);
281 pr("Mobility <m>: %d\n", plane->pln_mobil);
282 pr("Tech <t>: %d\t\t", plane->pln_tech);
283 pr("Wing <w>: %.1s\n", &plane->pln_wing);
284 pr("Range <r>: %d\t\t", plane->pln_range);
285 pr("Flags <f>: %d\n", plane->pln_flags);
286 pr("Ship <s>: %d\t\t", plane->pln_ship);
287 pr("Land Unit <y>: %d\t", plane->pln_land);
291 print_land(struct lndstr *land)
293 pr("%s %s\n", prnatid(land->lnd_own), prland(land));
294 pr("UID <U>: %d\n", land->lnd_uid);
295 pr("Owner <O>: %d\n", land->lnd_own);
296 pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
297 pr("Efficiency <e>: %d\t", land->lnd_effic);
298 pr("Mobility <M>: %d\n", land->lnd_mobil);
299 pr("Tech <t>: %d\t\t", land->lnd_tech);
300 pr("Army <a>: %.1s\n", &land->lnd_army);
301 pr("Fortification <F>: %d\t", land->lnd_harden);
302 pr("Land unit <Y>: %d\n", land->lnd_land);
303 pr("Ship <S>: %d\t\t", land->lnd_ship);
304 pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
305 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
306 land->lnd_rpath, land->lnd_rflags);
307 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
308 pr(" c m u f s g p i d o l h r\n");
309 pr("%3d", land->lnd_item[I_CIVIL]);
310 pr("%4d", land->lnd_item[I_MILIT]);
311 pr("%4d", land->lnd_item[I_UW]);
312 pr("%5d", land->lnd_item[I_FOOD]);
313 pr("%4d", land->lnd_item[I_SHELL]);
314 pr("%4d", land->lnd_item[I_GUN]);
315 pr("%5d", land->lnd_item[I_PETROL]);
316 pr("%5d", land->lnd_item[I_IRON]);
317 pr("%5d", land->lnd_item[I_DUST]);
318 pr("%5d", land->lnd_item[I_OIL]);
319 pr("%5d", land->lnd_item[I_LCM]);
320 pr("%5d", land->lnd_item[I_HCM]);
321 pr("%4d", land->lnd_item[I_RAD]);
326 print_ship(struct shpstr *ship)
328 pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
329 pr("UID <U>: %d\n", ship->shp_uid);
330 pr("Owner <O>: %d\t\t\t", ship->shp_own);
331 pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
332 pr("Tech <T>: %d\t\t\t", ship->shp_tech);
333 pr("Efficiency <E>: %d\n", ship->shp_effic);
334 pr("Mobility <M>: %d\t\t", ship->shp_mobil);
335 pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
336 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
337 ship->shp_rpath, ship->shp_rflags);
338 pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
339 pr("Plague Time <b>: %d\n", ship->shp_ptime);
340 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
341 pr(" c m u f s g p i d o l h r\n");
342 pr("%3d", ship->shp_item[I_CIVIL]);
343 pr("%4d", ship->shp_item[I_MILIT]);
344 pr("%4d", ship->shp_item[I_UW]);
345 pr("%5d", ship->shp_item[I_FOOD]);
346 pr("%4d", ship->shp_item[I_SHELL]);
347 pr("%4d", ship->shp_item[I_GUN]);
348 pr("%5d", ship->shp_item[I_PETROL]);
349 pr("%5d", ship->shp_item[I_IRON]);
350 pr("%5d", ship->shp_item[I_DUST]);
351 pr("%5d", ship->shp_item[I_OIL]);
352 pr("%5d", ship->shp_item[I_LCM]);
353 pr("%5d", ship->shp_item[I_HCM]);
354 pr("%4d", ship->shp_item[I_RAD]);
359 getin(char *buf, char **valp)
366 p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
369 switch (parse(p, buf, argp, NULL, NULL, NULL)) {
380 #if 0 /* not needed right now */
382 warn_deprecated(char key)
384 pr("Key <%c> is deprecated and will go away in a future release\n", key);
389 edit_sect_i(struct sctstr *sect, char *key, int arg)
395 if (arg < 0 || arg >= MAXNOC)
397 divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
399 prnatid(sect->sct_own), prnatid(arg));
400 if (arg == sect->sct_own)
402 report_god_takes("Sector ",
403 xyas(sect->sct_x, sect->sct_y, sect->sct_own),
405 report_god_gives("Sector ",
406 xyas(sect->sct_x, sect->sct_y, arg),
411 if (arg < 0 || arg >= MAXNOC)
413 divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
415 prnatid(sect->sct_oldown), prnatid(arg));
416 sect->sct_oldown = arg;
419 new = LIMIT_TO(arg, 0, 100);
420 noise(sect, "Efficiency", sect->sct_effic, new);
421 sect->sct_effic = new;
424 new = LIMIT_TO(arg, -127, 127);
425 noise(sect, "Mobility", sect->sct_mobil, new);
426 sect->sct_mobil = new;
429 new = LIMIT_TO(arg, 0, 100);
430 noise(sect, "Iron ore content", sect->sct_min, new);
431 sect->sct_min = (unsigned char)new;
434 new = LIMIT_TO(arg, 0, 100);
435 noise(sect, "Gold content", sect->sct_gmin, new);
436 sect->sct_gmin = (unsigned char)new;
439 new = LIMIT_TO(arg, 0, 100);
440 noise(sect, "Fertility", sect->sct_fertil, new);
441 sect->sct_fertil = (unsigned char)new;
444 new = LIMIT_TO(arg, 0, 100);
445 noise(sect, "Oil content", sect->sct_oil, new);
446 sect->sct_oil = (unsigned char)new;
449 new = LIMIT_TO(arg, 0, 100);
450 noise(sect, "Uranium content", sect->sct_uran, new);
451 sect->sct_uran = (unsigned char)new;
454 new = LIMIT_TO(arg, 0, 100);
455 noise(sect, "Workforce percentage", sect->sct_work, new);
456 sect->sct_work = (unsigned char)new;
459 new = LIMIT_TO(arg, 0, 127);
460 divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
461 "from %d to %d", sect->sct_loyal, new);
462 sect->sct_loyal = (unsigned char)new;
465 new = LIMIT_TO(arg, 0, CHE_MAX);
466 divine_sct_change_quiet(sect, "Guerillas", new != sect->sct_che,
467 "from %d to %d", sect->sct_che, new);
471 if (arg < 0 || arg >= MAXNOC)
473 divine_sct_change_quiet(sect, "Che target",
474 arg != sect->sct_che_target,
476 prnatid(sect->sct_che_target),
478 sect->sct_che_target = arg;
483 new = LIMIT_TO(arg, 0, PLG_EXPOSED);
484 divine_sct_change_quiet(sect, "Plague stage",
485 new != sect->sct_pstage,
486 "from %d to %d", sect->sct_pstage, new);
487 sect->sct_pstage = new;
490 new = LIMIT_TO(arg, 0, 32767);
491 divine_sct_change_quiet(sect, "Plague time",
492 new != sect->sct_ptime,
493 "from %d to %d", sect->sct_ptime, new);
494 sect->sct_ptime = new;
497 new = LIMIT_TO(arg, 0, FALLOUT_MAX);
498 noise(sect, "Fallout", sect->sct_fallout, new);
499 sect->sct_fallout = new;
502 new = LIMIT_TO(arg, 0, 9999);
503 noise(sect, "Available workforce", sect->sct_avail, new);
504 sect->sct_avail = new;
507 new = LIMIT_TO(arg, 0, MINES_MAX);
508 if (sect->sct_own == sect->sct_oldown)
509 noise(sect, "Mines", sect->sct_mines, new);
511 divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
512 "from %d to %d", sect->sct_mines, new);
513 sect->sct_mines = new;
516 new = LIMIT_TO(arg, 0, 100);
517 noise(sect, "Road percentage", sect->sct_road, new);
518 sect->sct_road = new;
521 new = LIMIT_TO(arg, 0, 100);
522 noise(sect, "Rail percentage", sect->sct_rail, new);
523 sect->sct_rail = new;
526 new = LIMIT_TO(arg, 0, 100);
527 noise(sect, "Defense percentage", sect->sct_defense, new);
528 sect->sct_defense = new;
531 pr("huh? (%s)\n", key);
538 edit_sect(struct sctstr *sect, char *key, char *p)
542 struct sctstr newsect;
546 if (!sarg_xy(p, &newx, &newy))
548 if (newx == sect->sct_x && newy == sect->sct_y) {
549 pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
552 getsect(newx, newy, &newsect);
553 pr("Sector %s duplicated to %s\n",
554 xyas(sect->sct_x, sect->sct_y, player->cnum),
555 xyas(newx, newy, player->cnum));
556 report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
558 report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
562 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
565 if (!sarg_xy(p, &newx, &newy))
567 divine_sct_change_quiet(sect, "Distribution sector",
568 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
570 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
571 xyas(newx, newy, player->cnum));
572 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
574 if (sect->sct_own && sect->sct_own != player->cnum)
576 "Distribution sector of %s changed from %s to %s"
577 " by an act of %s\n",
578 xyas(sect->sct_x, sect->sct_y, player->cnum),
579 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
580 xyas(newx, newy, player->cnum),
581 cname(player->cnum));
582 sect->sct_dist_x = newx;
583 sect->sct_dist_y = newy;
586 new = sct_typematch(p);
589 divine_sct_change(sect, "Designation",
590 new != sect->sct_type, 0, "from %c to %c",
591 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
592 set_coastal(sect, sect->sct_type, new);
593 sect->sct_type = new;
596 new = sct_typematch(p);
599 divine_sct_change(sect, "New designation",
600 new != sect->sct_newtype, 0, "from %c to %c",
601 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
602 sect->sct_newtype = new;
605 return edit_sect_i(sect, key, atoi(p));
611 edit_level(struct natstr *np, int lvl, char *name, char *p)
613 float new = (float)atof(p);
616 divine_nat_change(np, name,
617 new != np->nat_level[lvl],
618 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
619 "from %.2f to %.2f", np->nat_level[lvl], new);
620 np->nat_level[lvl] = new;
624 edit_nat(struct natstr *np, char *key, char *p)
627 natid nat = np->nat_cnum;
632 if (!check_nat_name(p, nat))
634 divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
635 "from %s to %s", np->nat_cnam, p);
637 nreport(player->cnum, N_NAME_CHNG, 0, 1);
638 strcpy(np->nat_cnam, p);
641 divine_nat_change(np, "Country representative",
642 strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
644 np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
645 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
648 arg = LIMIT_TO(arg, 0, USHRT_MAX);
649 divine_nat_change_quiet(np, "Number of unread telegrams",
651 "from %d to %d", np->nat_tgms, arg);
655 arg = LIMIT_TO(arg, 0, max_btus);
656 divine_nat_change(np, "BTUs",
657 arg != np->nat_btu, arg - np->nat_btu,
658 "from %d to %d", np->nat_btu, arg);
662 arg = LIMIT_TO(arg, 0, INT_MAX);
663 divine_nat_change(np, "Military reserves",
664 arg != np->nat_reserve, arg - np->nat_reserve,
665 "from %d to %d", np->nat_reserve, arg);
666 np->nat_reserve = arg;
669 if (!sarg_xy(p, &newx, &newy))
671 if (newx == np->nat_xcap && newy == np->nat_ycap)
672 pr("Capital unchanged\n");
674 pr("Capital moved from %s to %s\n",
675 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
676 xyas(newx, newy, player->cnum));
677 if (nat != player->cnum)
679 "Capital moved from %s to %s by an act of %s!\n",
680 xyas(np->nat_xcap, np->nat_ycap, nat),
681 xyas(newx, newy, nat), cname(player->cnum));
687 if (!sarg_xy(p, &newx, &newy))
689 if (newx == np->nat_xorg && newy == np->nat_yorg)
690 pr("Origin unchanged\n");
692 pr("Origin moved from %s to %s\n",
693 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
694 xyas(newx, newy, player->cnum));
695 if (nat != player->cnum)
697 "Origin moved from %s to %s by an act of %s!\n",
698 xyas(np->nat_xorg, np->nat_yorg, nat),
699 xyas(newx, newy, nat), cname(player->cnum));
705 arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
706 divine_nat_change(np, "Status",
707 (enum nat_status)arg != np->nat_stat,
708 0, "to %s", nation_status[arg].name);
712 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
713 divine_nat_change(np, "Number of seconds used",
714 arg != np->nat_timeused, arg - np->nat_timeused,
715 "from %d to %d", np->nat_timeused, arg);
716 np->nat_timeused = arg;
719 divine_nat_change(np, "Money",
720 arg != np->nat_money, arg - np->nat_money,
721 "from %d to %d", np->nat_money, arg);
725 edit_level(np, NAT_TLEV, "Technology", p);
728 edit_level(np, NAT_RLEV, "Research", p);
731 edit_level(np, NAT_ELEV, "Education", p);
734 edit_level(np, NAT_HLEV, "Happiness", p);
737 pr("huh? (%s)\n", key);
744 edit_unit(struct empobj *unit, char *key, char *p,
745 int mineff, char *group_name, int on_carrier)
749 union empobj_storage newunit;
752 switch (toupper(*key)) {
756 if (arg == unit->uid) {
757 pr("%s unchanged\n", unit_nameof(unit));
760 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
761 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
764 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
765 ef_set_uid(unit->ef_type, unit, arg);
766 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
767 pr("Replacing %s of %s\n",
768 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
769 report_god_takes("", unit_nameof(&newunit.gen),
772 report_god_gives("", unit_nameof(unit), unit->own);
775 if (arg < 0 || arg >= MAXNOC)
777 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
779 prnatid(unit->own), prnatid(arg));
780 if (arg != unit->own) {
781 report_god_takes("", unit_nameof(unit), unit->own);
782 report_god_gives("", unit_nameof(unit), arg);
787 if (!sarg_xy(p, &newx, &newy))
789 if (on_carrier && (newx != unit->x || newy != unit->y)) {
790 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
793 divine_unit_change_quiet(unit, "Location",
794 unit->own && unit->own != player->cnum,
796 xyas(unit->x, unit->y, player->cnum),
797 xyas(newx, newy, player->cnum));
798 if (unit->own && unit->own != player->cnum)
800 "Location of %s changed from %s to %s by an act of %s!\n",
802 xyas(unit->x, unit->y, unit->own),
803 xyas(newx, newy, unit->own),
804 cname(player->cnum));
809 arg = LIMIT_TO(arg, mineff, 100);
810 divine_unit_change(unit, "Efficiency",
811 arg != unit->effic, arg - unit->effic,
812 "from %d to %d", unit->effic, arg);
816 arg = LIMIT_TO(arg, -127, 127);
817 divine_unit_change(unit, "Mobility",
818 arg != unit->mobil, arg - unit->mobil,
819 "from %d to %d", unit->mobil, arg);
827 else if (isalpha(p[0]))
830 pr("%c: invalid %s\n", p[0], group_name);
833 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
834 "from %s %c to %c", group_name,
835 unit->group ? unit->group : '~', p[0]);
836 unit->group = newgroup;
845 edit_ship(struct shpstr *ship, char *key, char *p)
847 struct mchrstr *mcp = &mchr[ship->shp_type];
858 return edit_unit((struct empobj *)ship, key, p,
859 SHIP_MINEFF, "fleet", 0);
861 arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
862 divine_unit_change((struct empobj *)ship, "Tech level",
863 arg != ship->shp_tech, arg - ship->shp_tech,
864 "from %d to %d", ship->shp_tech, arg);
865 shp_set_tech(ship, arg);
868 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
869 divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
870 arg != ship->shp_pstage,
871 "from %d to %d", ship->shp_pstage, arg);
872 ship->shp_pstage = arg;
875 arg = LIMIT_TO(arg, 0, 32767);
876 divine_unit_change_quiet((struct empobj *)ship, "Plague time",
877 arg != ship->shp_ptime,
878 "from %d to %d", ship->shp_ptime, arg);
879 ship->shp_ptime = arg;
882 divine_unit_change((struct empobj *)ship, "Retreat path",
883 strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
884 0, "from %s to %.*s",
885 ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
886 strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
889 divine_flag_change((struct empobj *)ship, "Retreat conditions",
890 ship->shp_rflags, arg, retreat_flags);
891 ship->shp_rflags = arg;
906 ip = item_by_name(key);
907 arg = LIMIT_TO(arg, 0, mchr[ship->shp_type].m_item[ip->i_uid]);
908 divine_unit_change_quiet((struct empobj *)ship, ip->i_name,
909 arg != ship->shp_item[ip->i_uid],
911 ship->shp_item[ip->i_uid], arg);
912 report_divine_gift(ship->shp_own, ip,
913 arg - ship->shp_item[ip->i_uid], prship(ship));
914 ship->shp_item[ip->i_uid] = arg;
917 pr("huh? (%s)\n", key);
924 edit_land(struct lndstr *land, char *key, char *p)
926 struct lchrstr *lcp = &lchr[land->lnd_type];
937 return edit_unit((struct empobj *)land, key, p,
939 land->lnd_ship >= 0 || land->lnd_land >= 0);
941 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
942 divine_unit_change((struct empobj *)land, "Tech level",
943 arg != land->lnd_tech, arg - land->lnd_tech,
944 "from %d to %d", land->lnd_tech, arg);
945 lnd_set_tech(land, arg);
948 arg = LIMIT_TO(arg, 0, 127);
949 divine_unit_change((struct empobj *)land, "Fortification",
950 arg != land->lnd_harden, arg - land->lnd_harden,
951 "from %d to %d", land->lnd_harden, arg);
952 land->lnd_harden = arg;
955 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
957 if (arg == land->lnd_ship) {
958 pr("Ship of %s unchanged\n", prland(land));
961 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
963 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
966 divine_load((struct empobj *)land, EF_SHIP, arg);
967 land->lnd_ship = arg;
970 if (arg < -1 || arg >= ef_nelem(EF_LAND))
972 if (arg == land->lnd_land) {
973 pr("Land unit of %s unchanged\n", prland(land));
976 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
978 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
981 divine_load((struct empobj *)land, EF_LAND, arg);
982 land->lnd_land = arg;
985 arg = LIMIT_TO(arg, 0, 100);
986 divine_unit_change((struct empobj *)land, "Retreat percentage",
987 arg != land->lnd_retreat, 0,
988 "from %d to %d", land->lnd_retreat, arg);
989 land->lnd_retreat = arg;
992 divine_unit_change((struct empobj *)land, "Retreat path",
993 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
994 0, "from %s to %.*s",
995 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
996 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
999 divine_flag_change((struct empobj *)land, "Retreat condition",
1000 land->lnd_rflags, arg, retreat_flags);
1001 land->lnd_rflags = arg;
1016 ip = item_by_name(key);
1017 arg = LIMIT_TO(arg, 0, lchr[land->lnd_type].l_item[ip->i_uid]);
1018 divine_unit_change_quiet((struct empobj *)land, ip->i_name,
1019 arg != land->lnd_item[ip->i_uid],
1021 land->lnd_item[ip->i_uid], arg);
1022 report_divine_gift(land->lnd_own, ip,
1023 arg - land->lnd_item[ip->i_uid], prland(land));
1024 land->lnd_item[ip->i_uid] = arg;
1027 pr("huh? (%s)\n", key);
1034 edit_plane(struct plnstr *plane, char *key, char *p)
1036 struct plchrstr *pcp = &plchr[plane->pln_type];
1046 return edit_unit((struct empobj *)plane, key, p,
1047 PLANE_MINEFF, "wing",
1048 plane->pln_ship >= 0 || plane->pln_land >= 0);
1050 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1051 divine_unit_change((struct empobj *)plane, "Tech level",
1052 arg != plane->pln_tech, arg - plane->pln_tech,
1053 "from %d to %d", plane->pln_tech, arg);
1054 pln_set_tech(plane, arg);
1057 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1058 divine_unit_change((struct empobj *)plane, "Range",
1059 arg != plane->pln_range, 0,
1060 "from %d to %d", plane->pln_range, arg);
1061 plane->pln_range = (unsigned char)arg;
1064 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1066 if (arg == plane->pln_ship) {
1067 pr("Ship of %s unchanged\n", prplane(plane));
1070 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1072 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1073 plane->pln_land = -1;
1075 divine_load((struct empobj *)plane, EF_SHIP, arg);
1076 plane->pln_ship = arg;
1079 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1081 if (arg == plane->pln_land) {
1082 pr("Land unit of %s unchanged\n", prplane(plane));
1085 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1087 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1088 plane->pln_ship = -1;
1090 divine_load((struct empobj *)plane, EF_LAND, arg);
1091 plane->pln_land = arg;
1094 divine_flag_change((struct empobj *)plane, "Flags",
1095 plane->pln_flags, arg, plane_flags);
1096 plane->pln_flags = arg;
1099 pr("huh? (%s)\n", key);