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? ");
99 if ((num = onearg(player->argp[2], "Plane number? ")) < 0)
101 if (!getplane(num, &item.plane))
105 if ((num = onearg(player->argp[2], "Ship number? ")) < 0)
107 if (!getship(num, &item.ship))
111 if ((num = onearg(player->argp[2], "Unit number? ")) < 0)
113 if (!getland(num, &item.land))
117 pr("Not implemented yet.\n");
123 if (!player->argp[3]) {
126 print_sect(&item.sect);
132 print_plane(&item.plane);
135 print_ship(&item.ship);
138 print_land(&item.land);
145 if (player->argp[arg_index]) {
146 if (player->argp[arg_index+1]) {
147 key = player->argp[arg_index++];
148 ptr = player->argp[arg_index++];
151 } else if (arg_index == 3) {
152 key = getin(buf, &ptr);
162 if (!check_obj_ok(&item.gen))
165 * edit_nat() may update the edited country by sending it
166 * bulletins. Writing back item.nat would trigger a seqno
167 * mismatch oops. Workaround: edit in-place.
169 ret = edit_nat(np, key, ptr);
177 if (!check_sect_ok(&item.sect))
179 ret = edit_sect(&item.sect, key, ptr);
182 if (!putsect(&item.sect))
186 if (!check_ship_ok(&item.ship))
188 ret = edit_ship(&item.ship, key, ptr);
191 if (!putship(item.ship.shp_uid, &item.ship))
195 if (!check_land_ok(&item.land))
197 ret = edit_land(&item.land, key, ptr);
200 if (!putland(item.land.lnd_uid, &item.land))
204 if (!check_plane_ok(&item.plane))
206 ret = edit_plane(&item.plane, key, ptr);
209 if (!putplane(item.plane.pln_uid, &item.plane))
219 noise(struct sctstr *sptr, char *name, int old, int new)
221 divine_sct_change(sptr, name, new != old, new - old,
222 "from %d to %d", old, new);
226 print_sect(struct sctstr *sect)
228 pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
229 pr("Distribution sector <D>: %s\n",
230 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
231 pr("Designation <s>: %c\tNew designation <S>: %c\n",
232 dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
233 pr("own oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
234 pr(" o O e m i g f c u w l x X p t F a\n");
235 pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
236 sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
237 sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
238 sect->sct_uran, sect->sct_work, sect->sct_loyal,
239 sect->sct_che, sect->sct_che_target,
240 sect->sct_pstage, sect->sct_ptime,
241 sect->sct_fallout, sect->sct_avail);
243 pr("Mines <M>: %d\n", sect->sct_mines);
244 pr("Road %% <R>: %d\t", sect->sct_road);
245 pr("Rail %% <r>: %d\t", sect->sct_rail);
246 pr("Defense %% <d>: %d\n", sect->sct_defense);
250 print_nat(struct natstr *np)
254 pr("Country #: %2d\n", np->nat_cnum);
255 pr("Name <n>: %-20s\t", np->nat_cnam);
256 pr("Representative <r>: %-20s\n", np->nat_pnam);
257 pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
258 pr("Reserves <m>: %5d\n", np->nat_reserve);
259 pr("Capital <c>: %s\t\t",
260 xyas(np->nat_xcap, np->nat_ycap, player->cnum));
261 pr("Origin <o>: %3s\n",
262 xyas(np->nat_xorg, np->nat_yorg, player->cnum));
263 pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
264 pr("Seconds Used <u>: %3d\n", np->nat_timeused);
265 pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
266 pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
267 pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
268 pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
269 pr("Money <M>: $%6d\n", np->nat_money);
270 pr("Telegrams <t>: %6d\n", np->nat_tgms);
272 pr("Countries contacted: ");
273 for (i = 0; i < MAXNOC; i++) {
274 if (getcontact(np, i))
275 pr("%d(%d) ", i, getcontact(np, i));
282 print_plane(struct plnstr *plane)
284 pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
285 pr("UID <U>: %d\t\t", plane->pln_uid);
286 pr("Owner <O>: %d\t\t", plane->pln_own);
287 pr("Location <l>: %s\n",
288 xyas(plane->pln_x, plane->pln_y, player->cnum));
289 pr("Efficiency <e>: %d\t", plane->pln_effic);
290 pr("Mobility <m>: %d\n", plane->pln_mobil);
291 pr("Tech <t>: %d\t\t", plane->pln_tech);
292 pr("Wing <w>: %.1s\n", &plane->pln_wing);
293 pr("Range <r>: %d\t\t", plane->pln_range);
294 pr("Flags <f>: %d\n", plane->pln_flags);
295 pr("Ship <s>: %d\t\t", plane->pln_ship);
296 pr("Land Unit <y>: %d\t", plane->pln_land);
300 print_land(struct lndstr *land)
302 pr("%s %s\n", prnatid(land->lnd_own), prland(land));
303 pr("UID <U>: %d\n", land->lnd_uid);
304 pr("Owner <O>: %d\n", land->lnd_own);
305 pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
306 pr("Efficiency <e>: %d\t", land->lnd_effic);
307 pr("Mobility <M>: %d\n", land->lnd_mobil);
308 pr("Tech <t>: %d\t\t", land->lnd_tech);
309 pr("Army <a>: %.1s\n", &land->lnd_army);
310 pr("Fortification <F>: %d\t", land->lnd_harden);
311 pr("Land unit <Y>: %d\n", land->lnd_land);
312 pr("Ship <S>: %d\t\t", land->lnd_ship);
313 pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
314 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
315 land->lnd_rpath, land->lnd_rflags);
316 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
317 pr(" c m u f s g p i d o l h r\n");
318 pr("%3d", land->lnd_item[I_CIVIL]);
319 pr("%4d", land->lnd_item[I_MILIT]);
320 pr("%4d", land->lnd_item[I_UW]);
321 pr("%5d", land->lnd_item[I_FOOD]);
322 pr("%4d", land->lnd_item[I_SHELL]);
323 pr("%4d", land->lnd_item[I_GUN]);
324 pr("%5d", land->lnd_item[I_PETROL]);
325 pr("%5d", land->lnd_item[I_IRON]);
326 pr("%5d", land->lnd_item[I_DUST]);
327 pr("%5d", land->lnd_item[I_OIL]);
328 pr("%5d", land->lnd_item[I_LCM]);
329 pr("%5d", land->lnd_item[I_HCM]);
330 pr("%4d", land->lnd_item[I_RAD]);
335 print_ship(struct shpstr *ship)
337 pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
338 pr("UID <U>: %d\n", ship->shp_uid);
339 pr("Owner <O>: %d\t\t\t", ship->shp_own);
340 pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
341 pr("Tech <T>: %d\t\t\t", ship->shp_tech);
342 pr("Efficiency <E>: %d\n", ship->shp_effic);
343 pr("Mobility <M>: %d\t\t", ship->shp_mobil);
344 pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
345 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
346 ship->shp_rpath, ship->shp_rflags);
347 pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
348 pr("Plague Time <b>: %d\n", ship->shp_ptime);
349 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
350 pr(" c m u f s g p i d o l h r\n");
351 pr("%3d", ship->shp_item[I_CIVIL]);
352 pr("%4d", ship->shp_item[I_MILIT]);
353 pr("%4d", ship->shp_item[I_UW]);
354 pr("%5d", ship->shp_item[I_FOOD]);
355 pr("%4d", ship->shp_item[I_SHELL]);
356 pr("%4d", ship->shp_item[I_GUN]);
357 pr("%5d", ship->shp_item[I_PETROL]);
358 pr("%5d", ship->shp_item[I_IRON]);
359 pr("%5d", ship->shp_item[I_DUST]);
360 pr("%5d", ship->shp_item[I_OIL]);
361 pr("%5d", ship->shp_item[I_LCM]);
362 pr("%5d", ship->shp_item[I_HCM]);
363 pr("%4d", ship->shp_item[I_RAD]);
368 getin(char *buf, char **valp)
375 p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
378 switch (parse(p, buf, argp, NULL, NULL, NULL)) {
389 #if 0 /* not needed right now */
391 warn_deprecated(char key)
393 pr("Key <%c> is deprecated and will go away in a future release\n", key);
398 edit_sect_i(struct sctstr *sect, char *key, int arg)
404 if (arg < 0 || arg >= MAXNOC)
406 divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
408 prnatid(sect->sct_own), prnatid(arg));
409 if (arg == sect->sct_own)
411 report_god_takes("Sector ",
412 xyas(sect->sct_x, sect->sct_y, sect->sct_own),
414 report_god_gives("Sector ",
415 xyas(sect->sct_x, sect->sct_y, arg),
420 if (arg < 0 || arg >= MAXNOC)
422 divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
424 prnatid(sect->sct_oldown), prnatid(arg));
425 sect->sct_oldown = arg;
428 new = LIMIT_TO(arg, 0, 100);
429 noise(sect, "Efficiency", sect->sct_effic, new);
430 sect->sct_effic = new;
433 new = LIMIT_TO(arg, -127, 127);
434 noise(sect, "Mobility", sect->sct_mobil, new);
435 sect->sct_mobil = new;
438 new = LIMIT_TO(arg, 0, 100);
439 noise(sect, "Iron ore content", sect->sct_min, new);
440 sect->sct_min = (unsigned char)new;
443 new = LIMIT_TO(arg, 0, 100);
444 noise(sect, "Gold content", sect->sct_gmin, new);
445 sect->sct_gmin = (unsigned char)new;
448 new = LIMIT_TO(arg, 0, 100);
449 noise(sect, "Fertility", sect->sct_fertil, new);
450 sect->sct_fertil = (unsigned char)new;
453 new = LIMIT_TO(arg, 0, 100);
454 noise(sect, "Oil content", sect->sct_oil, new);
455 sect->sct_oil = (unsigned char)new;
458 new = LIMIT_TO(arg, 0, 100);
459 noise(sect, "Uranium content", sect->sct_uran, new);
460 sect->sct_uran = (unsigned char)new;
463 new = LIMIT_TO(arg, 0, 100);
464 noise(sect, "Workforce percentage", sect->sct_work, new);
465 sect->sct_work = (unsigned char)new;
468 new = LIMIT_TO(arg, 0, 127);
469 divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
470 "from %d to %d", sect->sct_loyal, new);
471 sect->sct_loyal = (unsigned char)new;
474 new = LIMIT_TO(arg, 0, CHE_MAX);
475 divine_sct_change_quiet(sect, "Guerillas", new != sect->sct_che,
476 "from %d to %d", sect->sct_che, new);
480 if (arg < 0 || arg >= MAXNOC)
482 divine_sct_change_quiet(sect, "Che target",
483 arg != sect->sct_che_target,
485 prnatid(sect->sct_che_target),
487 sect->sct_che_target = arg;
492 new = LIMIT_TO(arg, 0, PLG_EXPOSED);
493 divine_sct_change_quiet(sect, "Plague stage",
494 new != sect->sct_pstage,
495 "from %d to %d", sect->sct_pstage, new);
496 sect->sct_pstage = new;
499 new = LIMIT_TO(arg, 0, 32767);
500 divine_sct_change_quiet(sect, "Plague time",
501 new != sect->sct_ptime,
502 "from %d to %d", sect->sct_ptime, new);
503 sect->sct_ptime = new;
506 new = LIMIT_TO(arg, 0, FALLOUT_MAX);
507 noise(sect, "Fallout", sect->sct_fallout, new);
508 sect->sct_fallout = new;
511 new = LIMIT_TO(arg, 0, 9999);
512 noise(sect, "Available workforce", sect->sct_avail, new);
513 sect->sct_avail = new;
516 new = LIMIT_TO(arg, 0, MINES_MAX);
517 if (sect->sct_own == sect->sct_oldown)
518 noise(sect, "Mines", sect->sct_mines, new);
520 divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
521 "from %d to %d", sect->sct_mines, new);
522 sect->sct_mines = new;
525 new = LIMIT_TO(arg, 0, 100);
526 noise(sect, "Road percentage", sect->sct_road, new);
527 sect->sct_road = new;
530 new = LIMIT_TO(arg, 0, 100);
531 noise(sect, "Rail percentage", sect->sct_rail, new);
532 sect->sct_rail = new;
535 new = LIMIT_TO(arg, 0, 100);
536 noise(sect, "Defense percentage", sect->sct_defense, new);
537 sect->sct_defense = new;
540 pr("huh? (%s)\n", key);
547 edit_sect(struct sctstr *sect, char *key, char *p)
551 struct sctstr newsect;
555 if (!sarg_xy(p, &newx, &newy))
557 if (newx == sect->sct_x && newy == sect->sct_y) {
558 pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
561 getsect(newx, newy, &newsect);
562 pr("Sector %s duplicated to %s\n",
563 xyas(sect->sct_x, sect->sct_y, player->cnum),
564 xyas(newx, newy, player->cnum));
565 report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
567 report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
571 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
574 if (!sarg_xy(p, &newx, &newy))
576 divine_sct_change_quiet(sect, "Distribution sector",
577 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
579 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
580 xyas(newx, newy, player->cnum));
581 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
583 if (sect->sct_own && sect->sct_own != player->cnum)
585 "Distribution sector of %s changed from %s to %s"
586 " by an act of %s\n",
587 xyas(sect->sct_x, sect->sct_y, player->cnum),
588 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
589 xyas(newx, newy, player->cnum),
590 cname(player->cnum));
591 sect->sct_dist_x = newx;
592 sect->sct_dist_y = newy;
595 new = sct_typematch(p);
598 divine_sct_change(sect, "Designation",
599 new != sect->sct_type, 0, "from %c to %c",
600 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
601 set_coastal(sect, sect->sct_type, new);
602 sect->sct_type = new;
605 new = sct_typematch(p);
608 divine_sct_change(sect, "New designation",
609 new != sect->sct_newtype, 0, "from %c to %c",
610 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
611 sect->sct_newtype = new;
614 return edit_sect_i(sect, key, atoi(p));
620 edit_level(struct natstr *np, int lvl, char *name, char *p)
622 float new = (float)atof(p);
625 divine_nat_change(np, name,
626 new != np->nat_level[lvl],
627 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
628 "from %.2f to %.2f", np->nat_level[lvl], new);
629 np->nat_level[lvl] = new;
633 edit_nat(struct natstr *np, char *key, char *p)
636 natid nat = np->nat_cnum;
641 if (!check_nat_name(p, nat))
643 divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
644 "from %s to %s", np->nat_cnam, p);
646 nreport(player->cnum, N_NAME_CHNG, 0, 1);
647 strcpy(np->nat_cnam, p);
650 divine_nat_change(np, "Country representative",
651 strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
653 np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
654 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
657 arg = LIMIT_TO(arg, 0, USHRT_MAX);
658 divine_nat_change_quiet(np, "Number of unread telegrams",
660 "from %d to %d", np->nat_tgms, arg);
664 arg = LIMIT_TO(arg, 0, max_btus);
665 divine_nat_change(np, "BTUs",
666 arg != np->nat_btu, arg - np->nat_btu,
667 "from %d to %d", np->nat_btu, arg);
671 arg = LIMIT_TO(arg, 0, INT_MAX);
672 divine_nat_change(np, "Military reserves",
673 arg != np->nat_reserve, arg - np->nat_reserve,
674 "from %d to %d", np->nat_reserve, arg);
675 np->nat_reserve = arg;
678 if (!sarg_xy(p, &newx, &newy))
680 if (newx == np->nat_xcap && newy == np->nat_ycap)
681 pr("Capital unchanged\n");
683 pr("Capital moved from %s to %s\n",
684 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
685 xyas(newx, newy, player->cnum));
686 if (nat != player->cnum)
688 "Capital moved from %s to %s by an act of %s!\n",
689 xyas(np->nat_xcap, np->nat_ycap, nat),
690 xyas(newx, newy, nat), cname(player->cnum));
696 if (!sarg_xy(p, &newx, &newy))
698 if (newx == np->nat_xorg && newy == np->nat_yorg)
699 pr("Origin unchanged\n");
701 pr("Origin moved from %s to %s\n",
702 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
703 xyas(newx, newy, player->cnum));
704 if (nat != player->cnum)
706 "Origin moved from %s to %s by an act of %s!\n",
707 xyas(np->nat_xorg, np->nat_yorg, nat),
708 xyas(newx, newy, nat), cname(player->cnum));
714 arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
715 divine_nat_change(np, "Status",
716 (enum nat_status)arg != np->nat_stat,
717 0, "to %s", nation_status[arg].name);
721 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
722 divine_nat_change(np, "Number of seconds used",
723 arg != np->nat_timeused, arg - np->nat_timeused,
724 "from %d to %d", np->nat_timeused, arg);
725 np->nat_timeused = arg;
728 divine_nat_change(np, "Money",
729 arg != np->nat_money, arg - np->nat_money,
730 "from %d to %d", np->nat_money, arg);
734 edit_level(np, NAT_TLEV, "Technology", p);
737 edit_level(np, NAT_RLEV, "Research", p);
740 edit_level(np, NAT_ELEV, "Education", p);
743 edit_level(np, NAT_HLEV, "Happiness", p);
746 pr("huh? (%s)\n", key);
753 edit_unit(struct empobj *unit, char *key, char *p,
754 int mineff, char *group_name, int on_carrier)
758 union empobj_storage newunit;
761 switch (toupper(*key)) {
765 if (arg == unit->uid) {
766 pr("%s unchanged\n", unit_nameof(unit));
769 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
770 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
773 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
774 ef_set_uid(unit->ef_type, unit, arg);
775 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
776 pr("Replacing %s of %s\n",
777 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
778 report_god_takes("", unit_nameof(&newunit.gen),
781 report_god_gives("", unit_nameof(unit), unit->own);
784 if (arg < 0 || arg >= MAXNOC)
786 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
788 prnatid(unit->own), prnatid(arg));
789 if (arg != unit->own) {
790 report_god_takes("", unit_nameof(unit), unit->own);
791 report_god_gives("", unit_nameof(unit), arg);
796 if (!sarg_xy(p, &newx, &newy))
798 if (on_carrier && (newx != unit->x || newy != unit->y)) {
799 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
802 divine_unit_change_quiet(unit, "Location",
803 unit->own && unit->own != player->cnum,
805 xyas(unit->x, unit->y, player->cnum),
806 xyas(newx, newy, player->cnum));
807 if (unit->own && unit->own != player->cnum)
809 "Location of %s changed from %s to %s by an act of %s!\n",
811 xyas(unit->x, unit->y, unit->own),
812 xyas(newx, newy, unit->own),
813 cname(player->cnum));
818 arg = LIMIT_TO(arg, mineff, 100);
819 divine_unit_change(unit, "Efficiency",
820 arg != unit->effic, arg - unit->effic,
821 "from %d to %d", unit->effic, arg);
825 arg = LIMIT_TO(arg, -127, 127);
826 divine_unit_change(unit, "Mobility",
827 arg != unit->mobil, arg - unit->mobil,
828 "from %d to %d", unit->mobil, arg);
836 else if (isalpha(p[0]))
839 pr("%c: invalid %s\n", p[0], group_name);
842 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
843 "from %s %c to %c", group_name,
844 unit->group ? unit->group : '~', p[0]);
845 unit->group = newgroup;
854 edit_ship(struct shpstr *ship, char *key, char *p)
856 struct mchrstr *mcp = &mchr[ship->shp_type];
867 return edit_unit((struct empobj *)ship, key, p,
868 SHIP_MINEFF, "fleet", 0);
870 arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
871 divine_unit_change((struct empobj *)ship, "Tech level",
872 arg != ship->shp_tech, arg - ship->shp_tech,
873 "from %d to %d", ship->shp_tech, arg);
874 shp_set_tech(ship, arg);
877 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
878 divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
879 arg != ship->shp_pstage,
880 "from %d to %d", ship->shp_pstage, arg);
881 ship->shp_pstage = arg;
884 arg = LIMIT_TO(arg, 0, 32767);
885 divine_unit_change_quiet((struct empobj *)ship, "Plague time",
886 arg != ship->shp_ptime,
887 "from %d to %d", ship->shp_ptime, arg);
888 ship->shp_ptime = arg;
891 divine_unit_change((struct empobj *)ship, "Retreat path",
892 strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
893 0, "from %s to %.*s",
894 ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
895 strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
898 divine_flag_change((struct empobj *)ship, "Retreat conditions",
899 ship->shp_rflags, arg, retreat_flags);
900 ship->shp_rflags = arg;
915 ip = item_by_name(key);
916 arg = LIMIT_TO(arg, 0, mchr[ship->shp_type].m_item[ip->i_uid]);
917 divine_unit_change_quiet((struct empobj *)ship, ip->i_name,
918 arg != ship->shp_item[ip->i_uid],
920 ship->shp_item[ip->i_uid], arg);
921 report_divine_gift(ship->shp_own, ip,
922 arg - ship->shp_item[ip->i_uid], prship(ship));
923 ship->shp_item[ip->i_uid] = arg;
926 pr("huh? (%s)\n", key);
933 edit_land(struct lndstr *land, char *key, char *p)
935 struct lchrstr *lcp = &lchr[land->lnd_type];
946 return edit_unit((struct empobj *)land, key, p,
948 land->lnd_ship >= 0 || land->lnd_land >= 0);
950 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
951 divine_unit_change((struct empobj *)land, "Tech level",
952 arg != land->lnd_tech, arg - land->lnd_tech,
953 "from %d to %d", land->lnd_tech, arg);
954 lnd_set_tech(land, arg);
957 arg = LIMIT_TO(arg, 0, 127);
958 divine_unit_change((struct empobj *)land, "Fortification",
959 arg != land->lnd_harden, arg - land->lnd_harden,
960 "from %d to %d", land->lnd_harden, arg);
961 land->lnd_harden = arg;
964 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
966 if (arg == land->lnd_ship) {
967 pr("Ship of %s unchanged\n", prland(land));
970 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
972 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
975 divine_load((struct empobj *)land, EF_SHIP, arg);
976 land->lnd_ship = arg;
979 if (arg < -1 || arg >= ef_nelem(EF_LAND))
981 if (arg == land->lnd_land) {
982 pr("Land unit of %s unchanged\n", prland(land));
985 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
987 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
990 divine_load((struct empobj *)land, EF_LAND, arg);
991 land->lnd_land = arg;
994 arg = LIMIT_TO(arg, 0, 100);
995 divine_unit_change((struct empobj *)land, "Retreat percentage",
996 arg != land->lnd_retreat, 0,
997 "from %d to %d", land->lnd_retreat, arg);
998 land->lnd_retreat = arg;
1001 divine_unit_change((struct empobj *)land, "Retreat path",
1002 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
1003 0, "from %s to %.*s",
1004 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
1005 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
1008 divine_flag_change((struct empobj *)land, "Retreat condition",
1009 land->lnd_rflags, arg, retreat_flags);
1010 land->lnd_rflags = arg;
1025 ip = item_by_name(key);
1026 arg = LIMIT_TO(arg, 0, lchr[land->lnd_type].l_item[ip->i_uid]);
1027 divine_unit_change_quiet((struct empobj *)land, ip->i_name,
1028 arg != land->lnd_item[ip->i_uid],
1030 land->lnd_item[ip->i_uid], arg);
1031 report_divine_gift(land->lnd_own, ip,
1032 arg - land->lnd_item[ip->i_uid], prland(land));
1033 land->lnd_item[ip->i_uid] = arg;
1036 pr("huh? (%s)\n", key);
1043 edit_plane(struct plnstr *plane, char *key, char *p)
1045 struct plchrstr *pcp = &plchr[plane->pln_type];
1055 return edit_unit((struct empobj *)plane, key, p,
1056 PLANE_MINEFF, "wing",
1057 plane->pln_ship >= 0 || plane->pln_land >= 0);
1059 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1060 divine_unit_change((struct empobj *)plane, "Tech level",
1061 arg != plane->pln_tech, arg - plane->pln_tech,
1062 "from %d to %d", plane->pln_tech, arg);
1063 pln_set_tech(plane, arg);
1066 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1067 divine_unit_change((struct empobj *)plane, "Range",
1068 arg != plane->pln_range, 0,
1069 "from %d to %d", plane->pln_range, arg);
1070 plane->pln_range = (unsigned char)arg;
1073 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1075 if (arg == plane->pln_ship) {
1076 pr("Ship of %s unchanged\n", prplane(plane));
1079 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1081 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1082 plane->pln_land = -1;
1084 divine_load((struct empobj *)plane, EF_SHIP, arg);
1085 plane->pln_ship = arg;
1088 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1090 if (arg == plane->pln_land) {
1091 pr("Land unit of %s unchanged\n", prplane(plane));
1094 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1096 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1097 plane->pln_ship = -1;
1099 divine_load((struct empobj *)plane, EF_LAND, arg);
1100 plane->pln_land = arg;
1103 divine_flag_change((struct empobj *)plane, "Flags",
1104 plane->pln_flags, arg, plane_flags);
1105 plane->pln_flags = arg;
1108 pr("huh? (%s)\n", key);