2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, 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-2018
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 void print_nuke(struct nukstr *);
58 static char *getin(char *, char **);
59 static int edit_nat(struct natstr *, char *, char *);
60 static int edit_ship(struct shpstr *, char *, char *);
61 static int edit_land(struct lndstr *, char *, char *);
62 static int edit_plane(struct plnstr *, char *, char *);
63 static int edit_nuke(struct nukstr *, char *, char *);
68 union empobj_storage item;
73 int type, arg_index, ret;
76 what = getstarg(player->argp[1],
77 "Edit what (country, land, ship, plane, nuke, unit)? ",
105 if (!snxtitem(&ni, type, player->argp[2], NULL))
107 while (nxtitem(&ni, &item)) {
108 if (!player->argp[3]) {
111 print_sect(&item.sect);
114 print_ship(&item.ship);
117 print_plane(&item.plane);
120 print_land(&item.land);
123 print_nuke(&item.nuke);
126 print_nat(&item.nat);
135 if (player->argp[arg_index]) {
136 if (player->argp[arg_index+1]) {
137 key = player->argp[arg_index++];
138 ptr = player->argp[arg_index++];
141 } else if (arg_index == 3) {
142 key = getin(buf, &ptr);
150 if (!check_obj_ok(&item.gen))
155 * edit_nat() may update the edited country by sending
156 * it bulletins. Writing back item.nat would trigger
157 * a seqno mismatch oops. Workaround: edit in-place.
159 np = getnatp(item.nat.nat_cnum);
160 ret = edit_nat(np, key, ptr);
168 ret = edit_sect(&item.sect, key, ptr);
171 ret = edit_ship(&item.ship, key, ptr);
174 ret = edit_land(&item.land, key, ptr);
177 ret = edit_plane(&item.plane, key, ptr);
180 ret = edit_nuke(&item.nuke, key, ptr);
187 if (!put_empobj(type, item.gen.uid, &item.gen))
196 noise(struct sctstr *sptr, char *name, int old, int new)
198 divine_sct_change(sptr, name, new != old, new - old,
199 "from %d to %d", old, new);
203 print_sect(struct sctstr *sect)
205 pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
206 pr("Distribution sector <D>: %s\n",
207 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
208 pr("Designation <s>: %c\tNew designation <S>: %c\n",
209 dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
210 pr("own oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
211 pr(" o O e m i g f c u w l x X p t F a\n");
212 pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
213 sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
214 sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
215 sect->sct_uran, sect->sct_work, sect->sct_loyal,
216 sect->sct_che, sect->sct_che_target,
217 sect->sct_pstage, sect->sct_ptime,
218 sect->sct_fallout, sect->sct_avail);
220 pr("Mines <M>: %d\n", sect->sct_mines);
221 pr("Road %% <R>: %d\t", sect->sct_road);
222 pr("Rail %% <r>: %d\t", sect->sct_rail);
223 pr("Defense %% <d>: %d\n", sect->sct_defense);
227 print_nat(struct natstr *np)
229 pr("Country #: %2d\n", np->nat_cnum);
230 pr("Name <n>: %-20s\t", np->nat_cnam);
231 pr("Representative <r>: %s\n", np->nat_pnam);
232 pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
233 pr("Reserves <m>: %5d\n", np->nat_reserve);
234 pr("Capital <c>: %s\t\t",
235 xyas(np->nat_xcap, np->nat_ycap, player->cnum));
236 pr("Origin <o>: %3s\n",
237 xyas(np->nat_xorg, np->nat_yorg, player->cnum));
238 pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
239 pr("Seconds Used <u>: %3d\n", np->nat_timeused);
240 pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
241 pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
242 pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
243 pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
244 pr("Money <M>: $%6d\n", np->nat_money);
245 pr("Telegrams <t>: %6d\n", np->nat_tgms);
249 print_plane(struct plnstr *plane)
251 pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
252 pr("UID <U>: %d\t\t", plane->pln_uid);
253 pr("Type <T>: %s\n", plchr[plane->pln_type].pl_name);
254 pr("Owner <O>: %d\t\t", plane->pln_own);
255 pr("Location <l>: %s\n",
256 xyas(plane->pln_x, plane->pln_y, player->cnum));
257 pr("Efficiency <e>: %d\t", plane->pln_effic);
258 pr("Mobility <m>: %d\n", plane->pln_mobil);
259 pr("Tech <t>: %d\t\t", plane->pln_tech);
260 pr("Wing <w>: %.1s\n", &plane->pln_wing);
261 pr("Range <r>: %d\t\t", plane->pln_range);
262 pr("Flags <f>: %d\n", plane->pln_flags);
263 pr("Ship <s>: %d\t\t", plane->pln_ship);
264 pr("Land Unit <y>: %d\n", plane->pln_land);
268 print_items(short item[])
270 pr(" civ mil uw food sh gun pet iron dust bar oil lcm hcm rad\n"
271 " c m u f s g p i d B o l h r\n"
272 "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d\n",
290 print_land(struct lndstr *land)
292 pr("%s %s\n", prnatid(land->lnd_own), prland(land));
293 pr("UID <U>: %d\t\t", land->lnd_uid);
294 pr("Type <T>: %s\n", lchr[land->lnd_type].l_name);
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 print_items(land->lnd_item);
311 print_ship(struct shpstr *ship)
313 pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
314 pr("UID <U>: %d\t\t\t", ship->shp_uid);
315 pr("Type <t>: %s\n", mchr[ship->shp_type].m_name);
316 pr("Owner <O>: %d\t\t\t", ship->shp_own);
317 pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
318 pr("Tech <T>: %d\t\t\t", ship->shp_tech);
319 pr("Efficiency <E>: %d\n", ship->shp_effic);
320 pr("Mobility <M>: %d\t\t", ship->shp_mobil);
321 pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
322 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
323 ship->shp_rpath, ship->shp_rflags);
324 pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
325 pr("Plague Time <b>: %d\n", ship->shp_ptime);
326 print_items(ship->shp_item);
330 print_nuke(struct nukstr *nuke)
332 pr("%s %s\n", prnatid(nuke->nuk_own), prnuke(nuke));
333 pr("UID <U>: %d\t\t\t", nuke->nuk_uid);
334 pr("Type <t>: %d\n", nuke->nuk_type);
335 pr("Owner <O>: %d\t\t\t", nuke->nuk_own);
336 pr("Location <L>: %s\n", xyas(nuke->nuk_x, nuke->nuk_y, player->cnum));
337 pr("Tech <T>: %d\t\t\t", nuke->nuk_tech);
338 pr("Stockpile <S>: %.1s\n", &nuke->nuk_stockpile);
339 pr("Plane <p>: %d\n", nuke->nuk_plane);
343 getin(char *buf, char **valp)
350 p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
353 switch (parse(p, buf, argp, NULL, NULL, NULL)) {
364 #if 0 /* not needed right now */
366 warn_deprecated(char key)
368 pr("Key <%c> is deprecated and will go away in a future release\n", key);
373 edit_sect_i(struct sctstr *sect, char *key, int arg)
379 if (arg < 0 || arg >= MAXNOC)
381 divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
383 prnatid(sect->sct_own), prnatid(arg));
384 if (arg == sect->sct_own)
386 report_god_takes("Sector ",
387 xyas(sect->sct_x, sect->sct_y, sect->sct_own),
389 report_god_gives("Sector ",
390 xyas(sect->sct_x, sect->sct_y, arg),
395 if (arg < 0 || arg >= MAXNOC)
397 divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
399 prnatid(sect->sct_oldown), prnatid(arg));
400 sect->sct_oldown = arg;
403 new = LIMIT_TO(arg, 0, 100);
404 noise(sect, "Efficiency", sect->sct_effic, new);
405 sect->sct_effic = new;
408 new = LIMIT_TO(arg, -127, 127);
409 noise(sect, "Mobility", sect->sct_mobil, new);
410 sect->sct_mobil = new;
413 new = LIMIT_TO(arg, 0, 100);
414 noise(sect, "Iron ore content", sect->sct_min, new);
415 sect->sct_min = (unsigned char)new;
418 new = LIMIT_TO(arg, 0, 100);
419 noise(sect, "Gold content", sect->sct_gmin, new);
420 sect->sct_gmin = (unsigned char)new;
423 new = LIMIT_TO(arg, 0, 100);
424 noise(sect, "Fertility", sect->sct_fertil, new);
425 sect->sct_fertil = (unsigned char)new;
428 new = LIMIT_TO(arg, 0, 100);
429 noise(sect, "Oil content", sect->sct_oil, new);
430 sect->sct_oil = (unsigned char)new;
433 new = LIMIT_TO(arg, 0, 100);
434 noise(sect, "Uranium content", sect->sct_uran, new);
435 sect->sct_uran = (unsigned char)new;
438 new = LIMIT_TO(arg, 0, 100);
439 noise(sect, "Workforce percentage", sect->sct_work, new);
440 sect->sct_work = (unsigned char)new;
443 new = LIMIT_TO(arg, 0, 127);
444 divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
445 "from %d to %d", sect->sct_loyal, new);
446 sect->sct_loyal = (unsigned char)new;
449 new = LIMIT_TO(arg, 0, CHE_MAX);
450 divine_sct_change_quiet(sect, "Guerrillas", new != sect->sct_che,
451 "from %d to %d", sect->sct_che, new);
455 if (arg < 0 || arg >= MAXNOC)
457 divine_sct_change_quiet(sect, "Che target",
458 arg != sect->sct_che_target,
460 prnatid(sect->sct_che_target),
462 sect->sct_che_target = arg;
467 new = LIMIT_TO(arg, 0, PLG_EXPOSED);
468 divine_sct_change_quiet(sect, "Plague stage",
469 new != sect->sct_pstage,
470 "from %d to %d", sect->sct_pstage, new);
471 sect->sct_pstage = new;
474 new = LIMIT_TO(arg, 0, 32767);
475 divine_sct_change_quiet(sect, "Plague time",
476 new != sect->sct_ptime,
477 "from %d to %d", sect->sct_ptime, new);
478 sect->sct_ptime = new;
481 new = LIMIT_TO(arg, 0, FALLOUT_MAX);
482 noise(sect, "Fallout", sect->sct_fallout, new);
483 sect->sct_fallout = new;
486 new = LIMIT_TO(arg, 0, 9999);
487 noise(sect, "Available workforce", sect->sct_avail, new);
488 sect->sct_avail = new;
491 new = LIMIT_TO(arg, 0, MINES_MAX);
492 if (sect->sct_own == sect->sct_oldown)
493 noise(sect, "Mines", sect->sct_mines, new);
495 divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
496 "from %d to %d", sect->sct_mines, new);
497 sect->sct_mines = new;
500 new = LIMIT_TO(arg, 0, 100);
501 noise(sect, "Road percentage", sect->sct_road, new);
502 sect->sct_road = new;
505 new = LIMIT_TO(arg, 0, 100);
506 noise(sect, "Rail percentage", sect->sct_rail, new);
507 sect->sct_rail = new;
510 new = LIMIT_TO(arg, 0, 100);
511 noise(sect, "Defense percentage", sect->sct_defense, new);
512 sect->sct_defense = new;
515 pr("huh? (%s)\n", key);
522 edit_sect(struct sctstr *sect, char *key, char *p)
526 struct sctstr newsect;
530 if (!sarg_xy(p, &newx, &newy))
532 if (newx == sect->sct_x && newy == sect->sct_y) {
533 pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
536 getsect(newx, newy, &newsect);
537 pr("Sector %s duplicated to %s\n",
538 xyas(sect->sct_x, sect->sct_y, player->cnum),
539 xyas(newx, newy, player->cnum));
540 report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
542 report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
544 if (sect->sct_x == sect->sct_dist_x
545 && sect->sct_y == sect->sct_dist_y) {
546 sect->sct_dist_x = newx;
547 sect->sct_dist_y = newy;
551 sect->sct_coastal = newsect.sct_coastal;
552 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
555 if (!sarg_xy(p, &newx, &newy))
557 divine_sct_change_quiet(sect, "Distribution sector",
558 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
560 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
561 xyas(newx, newy, player->cnum));
562 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
564 if (sect->sct_own && sect->sct_own != player->cnum)
566 "Distribution sector of %s changed from %s to %s"
567 " by an act of %s\n",
568 xyas(sect->sct_x, sect->sct_y, player->cnum),
569 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
570 xyas(newx, newy, player->cnum),
571 cname(player->cnum));
572 sect->sct_dist_x = newx;
573 sect->sct_dist_y = newy;
576 new = sct_typematch(p);
579 divine_sct_change(sect, "Designation",
580 new != sect->sct_type, 0, "from %c to %c",
581 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
582 set_coastal(sect, sect->sct_type, new);
583 sect->sct_type = new;
586 new = sct_typematch(p);
589 divine_sct_change(sect, "New designation",
590 new != sect->sct_newtype, 0, "from %c to %c",
591 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
592 sect->sct_newtype = new;
595 return edit_sect_i(sect, key, atoi(p));
601 edit_level(struct natstr *np, int lvl, char *name, char *p)
603 float new = (float)atof(p);
606 divine_nat_change(np, name,
607 new != np->nat_level[lvl],
608 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
609 "from %.2f to %.2f", np->nat_level[lvl], new);
610 np->nat_level[lvl] = new;
614 edit_nat(struct natstr *np, char *key, char *p)
617 natid nat = np->nat_cnum;
622 if (!check_nat_name(p, nat))
624 divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
625 "from %s to %s", np->nat_cnam, p);
627 nreport(player->cnum, N_NAME_CHNG, 0, 1);
628 strcpy(np->nat_cnam, p);
631 divine_nat_change(np, "Country representative",
632 strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
634 np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
635 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
638 arg = LIMIT_TO(arg, 0, USHRT_MAX);
639 divine_nat_change_quiet(np, "Number of unread telegrams",
641 "from %d to %d", np->nat_tgms, arg);
645 arg = LIMIT_TO(arg, 0, max_btus);
646 divine_nat_change(np, "BTUs",
647 arg != np->nat_btu, arg - np->nat_btu,
648 "from %d to %d", np->nat_btu, arg);
652 arg = LIMIT_TO(arg, 0, INT_MAX);
653 divine_nat_change(np, "Military reserves",
654 arg != np->nat_reserve, arg - np->nat_reserve,
655 "from %d to %d", np->nat_reserve, arg);
656 np->nat_reserve = arg;
659 if (!sarg_xy(p, &newx, &newy))
661 if (newx == np->nat_xcap && newy == np->nat_ycap)
662 pr("Capital unchanged\n");
664 pr("Capital moved from %s to %s\n",
665 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
666 xyas(newx, newy, player->cnum));
667 if (nat != player->cnum)
669 "Capital moved from %s to %s by an act of %s!\n",
670 xyas(np->nat_xcap, np->nat_ycap, nat),
671 xyas(newx, newy, nat), cname(player->cnum));
677 if (!sarg_xy(p, &newx, &newy))
679 if (newx == np->nat_xorg && newy == np->nat_yorg)
680 pr("Origin unchanged\n");
682 pr("Origin moved from %s to %s\n",
683 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
684 xyas(newx, newy, player->cnum));
685 if (nat != player->cnum)
687 "Origin moved from %s to %s by an act of %s!\n",
688 xyas(np->nat_xorg, np->nat_yorg, nat),
689 xyas(newx, newy, nat), cname(player->cnum));
695 arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
696 divine_nat_change(np, "Status",
697 (enum nat_status)arg != np->nat_stat,
698 0, "to %s", nation_status[arg].name);
702 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
703 divine_nat_change(np, "Number of seconds used",
704 arg != np->nat_timeused, arg - np->nat_timeused,
705 "from %d to %d", np->nat_timeused, arg);
706 np->nat_timeused = arg;
709 divine_nat_change(np, "Money",
710 arg != np->nat_money, arg - np->nat_money,
711 "from %d to %d", np->nat_money, arg);
715 edit_level(np, NAT_TLEV, "Technology", p);
718 edit_level(np, NAT_RLEV, "Research", p);
721 edit_level(np, NAT_ELEV, "Education", p);
724 edit_level(np, NAT_HLEV, "Happiness", p);
727 pr("huh? (%s)\n", key);
734 edit_unit(struct empobj *unit, char *key, char *p,
735 int mineff, char *group_name, int on_carrier)
739 union empobj_storage newunit;
742 switch (toupper(*key)) {
746 if (arg == unit->uid) {
747 pr("%s unchanged\n", unit_nameof(unit));
750 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
751 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
754 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
755 ef_set_uid(unit->ef_type, unit, arg);
756 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
757 pr("Replacing %s of %s\n",
758 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
759 report_god_takes("", unit_nameof(&newunit.gen),
762 report_god_gives("", unit_nameof(unit), unit->own);
765 if (arg < 0 || arg >= MAXNOC)
767 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
769 prnatid(unit->own), prnatid(arg));
770 if (arg != unit->own) {
771 report_god_takes("", unit_nameof(unit), unit->own);
772 report_god_gives("", unit_nameof(unit), arg);
774 if (arg && unit->effic < mineff) {
775 divine_unit_change_quiet(unit, "Efficiency", 1,
776 "from %d to %d", unit->effic, mineff);
777 unit->effic = mineff;
782 if (!sarg_xy(p, &newx, &newy))
784 if (on_carrier && (newx != unit->x || newy != unit->y)) {
785 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
788 divine_unit_change_quiet(unit, "Location",
789 newx != unit->x || newy != unit->y,
791 xyas(unit->x, unit->y, player->cnum),
792 xyas(newx, newy, player->cnum));
793 if (newx == unit->x && newy == unit->y)
795 if (unit->own && unit->own != player->cnum)
797 "Location of %s changed from %s to %s by an act of %s!\n",
799 xyas(unit->x, unit->y, unit->own),
800 xyas(newx, newy, unit->own),
801 cname(player->cnum));
802 unit_teleport(unit, newx, newy);
805 arg = LIMIT_TO(arg, mineff, 100);
806 divine_unit_change(unit, "Efficiency",
807 arg != unit->effic, arg - unit->effic,
808 "from %d to %d", unit->effic, arg);
812 arg = LIMIT_TO(arg, -127, 127);
813 divine_unit_change(unit, "Mobility",
814 arg != unit->mobil, arg - unit->mobil,
815 "from %d to %d", unit->mobil, arg);
824 else if (isalpha(p[0]))
827 pr("%c: invalid %s\n", p[0], group_name);
830 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
831 "from %s %c to %c", group_name,
832 unit->group ? unit->group : '~', p[0]);
833 unit->group = newgroup;
842 edit_item(struct empobj *unit, short item[], struct ichrstr *ip, int arg,
845 arg = LIMIT_TO(arg, 0, lim[ip->i_uid]);
846 divine_unit_change_quiet(unit, ip->i_name, arg != item[ip->i_uid],
847 "from %d to %d", item[ip->i_uid], arg);
848 report_divine_gift(unit->own, ip, arg - item[ip->i_uid],
850 item[ip->i_uid] = arg;
854 edit_unit_item(struct empobj *unit, short item[], char *key, int arg,
859 lowkey[0] = tolower(*key);
861 edit_item(unit, item, item_by_name(lowkey), arg, lim);
865 limit_item(struct empobj *unit, short item[], short lim[])
869 for (it = I_NONE + 1; it <= I_MAX; it++) {
870 if (item[it] > lim[it])
871 edit_item(unit, item, &ichr[it], item[it], lim);
876 edit_ship(struct shpstr *ship, char *key, char *p)
878 struct mchrstr *mcp = &mchr[ship->shp_type];
889 ret = edit_unit((struct empobj *)ship, key, p,
890 SHIP_MINEFF, "fleet", 0);
893 arg = ef_elt_byname(EF_SHIP_CHR, p);
895 pr("%s: invalid ship type\n", p);
898 divine_unit_change((struct empobj *)ship, "Type",
899 arg != ship->shp_type, 0,
900 "to %s", mchr[arg].m_name);
901 if (ship->shp_tech < mchr[arg].m_tech)
902 shp_set_tech(ship, mchr[arg].m_tech);
903 ship->shp_type = arg;
904 shp_set_tech(ship, ship->shp_tech);
905 limit_item((struct empobj *)ship, ship->shp_item, mchr[arg].m_item);
908 arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
909 divine_unit_change((struct empobj *)ship, "Tech level",
910 arg != ship->shp_tech, arg - ship->shp_tech,
911 "from %d to %d", ship->shp_tech, arg);
912 shp_set_tech(ship, arg);
915 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
916 divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
917 arg != ship->shp_pstage,
918 "from %d to %d", ship->shp_pstage, arg);
919 ship->shp_pstage = arg;
922 arg = LIMIT_TO(arg, 0, 32767);
923 divine_unit_change_quiet((struct empobj *)ship, "Plague time",
924 arg != ship->shp_ptime,
925 "from %d to %d", ship->shp_ptime, arg);
926 ship->shp_ptime = arg;
929 divine_unit_change((struct empobj *)ship, "Retreat path",
930 strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
931 0, "from %s to %.*s",
932 ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
933 strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
936 divine_flag_change((struct empobj *)ship, "Retreat conditions",
937 ship->shp_rflags, arg, retreat_flags);
938 ship->shp_rflags = arg;
954 edit_unit_item((struct empobj *)ship, ship->shp_item, key, arg,
958 pr("huh? (%s)\n", key);
965 edit_land(struct lndstr *land, char *key, char *p)
967 struct lchrstr *lcp = &lchr[land->lnd_type];
977 return edit_unit((struct empobj *)land, key, p,
979 land->lnd_ship >= 0 || land->lnd_land >= 0);
981 arg = ef_elt_byname(EF_LAND_CHR, p);
983 pr("%s: invalid land unit type\n", p);
986 divine_unit_change((struct empobj *)land, "Type",
987 arg != land->lnd_type, 0,
988 "to %s", lchr[arg].l_name);
989 if (land->lnd_tech < lchr[arg].l_tech)
990 lnd_set_tech(land, lchr[arg].l_tech);
991 land->lnd_type = arg;
992 lnd_set_tech(land, land->lnd_tech);
993 limit_item((struct empobj *)land, land->lnd_item, lchr[arg].l_item);
996 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
997 divine_unit_change((struct empobj *)land, "Tech level",
998 arg != land->lnd_tech, arg - land->lnd_tech,
999 "from %d to %d", land->lnd_tech, arg);
1000 lnd_set_tech(land, arg);
1003 arg = LIMIT_TO(arg, 0, 127);
1004 if (land->lnd_ship >= 0 || land->lnd_land >= 0)
1006 divine_unit_change((struct empobj *)land, "Fortification",
1007 arg != land->lnd_harden, arg - land->lnd_harden,
1008 "from %d to %d", land->lnd_harden, arg);
1009 land->lnd_harden = arg;
1012 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1014 if (arg == land->lnd_ship) {
1015 pr("Ship of %s unchanged\n", prland(land));
1018 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1020 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1021 land->lnd_land = -1;
1023 divine_load((struct empobj *)land, EF_SHIP, arg);
1024 land->lnd_ship = arg;
1027 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1029 if (arg == land->lnd_land) {
1030 pr("Land unit of %s unchanged\n", prland(land));
1033 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1035 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1036 land->lnd_ship = -1;
1038 divine_load((struct empobj *)land, EF_LAND, arg);
1039 land->lnd_land = arg;
1042 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
1043 divine_unit_change_quiet((struct empobj *)land, "Plague stage",
1044 arg != land->lnd_pstage,
1045 "from %d to %d", land->lnd_pstage, arg);
1046 land->lnd_pstage = arg;
1049 arg = LIMIT_TO(arg, 0, 32767);
1050 divine_unit_change_quiet((struct empobj *)land, "Plague time",
1051 arg != land->lnd_ptime,
1052 "from %d to %d", land->lnd_ptime, arg);
1053 land->lnd_ptime = arg;
1056 arg = LIMIT_TO(arg, 0, 100);
1057 divine_unit_change((struct empobj *)land, "Retreat percentage",
1058 arg != land->lnd_retreat, 0,
1059 "from %d to %d", land->lnd_retreat, arg);
1060 land->lnd_retreat = arg;
1063 divine_unit_change((struct empobj *)land, "Retreat path",
1064 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
1065 0, "from %s to %.*s",
1066 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
1067 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
1070 divine_flag_change((struct empobj *)land, "Retreat condition",
1071 land->lnd_rflags, arg, retreat_flags);
1072 land->lnd_rflags = arg;
1088 edit_unit_item((struct empobj *)land, land->lnd_item, key, arg,
1092 pr("huh? (%s)\n", key);
1099 edit_plane(struct plnstr *plane, char *key, char *p)
1101 struct plchrstr *pcp = &plchr[plane->pln_type];
1111 return edit_unit((struct empobj *)plane, key, p,
1112 PLANE_MINEFF, "wing",
1113 plane->pln_ship >= 0 || plane->pln_land >= 0);
1115 arg = ef_elt_byname(EF_PLANE_CHR, p);
1117 pr("%s: invalid plane type\n", p);
1120 divine_unit_change((struct empobj *)plane, "Type",
1121 arg != plane->pln_type, 0,
1122 "to %s", plchr[arg].pl_name);
1123 if (plane->pln_tech < plchr[arg].pl_tech)
1124 pln_set_tech(plane, plchr[arg].pl_tech);
1125 if (plane->pln_range >= pln_range_max(plane))
1126 /* preserve unlimited range, pln_set_tech() will adjust */
1127 plane->pln_range = UCHAR_MAX;
1128 plane->pln_type = arg;
1129 pln_set_tech(plane, plane->pln_tech);
1132 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1133 divine_unit_change((struct empobj *)plane, "Tech level",
1134 arg != plane->pln_tech, arg - plane->pln_tech,
1135 "from %d to %d", plane->pln_tech, arg);
1136 pln_set_tech(plane, arg);
1139 arg = LIMIT_TO(arg, 0, 127);
1140 if (!(pcp->pl_flags & P_M)
1141 || plane->pln_ship >= 0 || plane->pln_land >= 0)
1143 divine_unit_change((struct empobj *)plane, "Fortification",
1144 arg != plane->pln_harden, arg - plane->pln_harden,
1145 "from %d to %d", plane->pln_harden, arg);
1146 plane->pln_harden = arg;
1149 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1150 divine_unit_change((struct empobj *)plane, "Range",
1151 arg != plane->pln_range, 0,
1152 "from %d to %d", plane->pln_range, arg);
1153 plane->pln_range = (unsigned char)arg;
1156 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1158 if (arg == plane->pln_ship) {
1159 pr("Ship of %s unchanged\n", prplane(plane));
1162 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1164 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1165 plane->pln_land = -1;
1167 divine_load((struct empobj *)plane, EF_SHIP, arg);
1168 plane->pln_ship = arg;
1171 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1173 if (arg == plane->pln_land) {
1174 pr("Land unit of %s unchanged\n", prplane(plane));
1177 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1179 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1180 plane->pln_ship = -1;
1182 divine_load((struct empobj *)plane, EF_LAND, arg);
1183 plane->pln_land = arg;
1186 divine_flag_change((struct empobj *)plane, "Flags",
1187 plane->pln_flags, arg, plane_flags);
1188 plane->pln_flags = arg;
1189 if (pln_is_in_orbit(plane))
1190 plane->pln_ship = plane->pln_land = -1;
1193 pr("huh? (%s)\n", key);
1200 edit_nuke(struct nukstr *nuke, char *key, char *p)
1202 struct nchrstr *ncp = &nchr[nuke->nuk_type];
1210 return edit_unit((struct empobj *)nuke, key, p,
1211 100, "stockpile", nuke->nuk_plane >= 0);
1213 arg = ef_elt_byname(EF_NUKE_CHR, p);
1215 pr("%s: invalid nuke type\n", p);
1218 divine_unit_change((struct empobj *)nuke, "Type",
1219 arg != nuke->nuk_type, 0,
1220 "to %s", nchr[arg].n_name);
1221 if (nuke->nuk_tech < nchr[arg].n_tech)
1222 nuke->nuk_tech = nchr[arg].n_tech;
1223 nuke->nuk_type = arg;
1226 arg = LIMIT_TO(arg, ncp->n_tech, SHRT_MAX);
1227 divine_unit_change((struct empobj *)nuke, "Tech level",
1228 arg != nuke->nuk_tech, arg - nuke->nuk_tech,
1229 "from %d to %d", nuke->nuk_tech, arg);
1230 nuke->nuk_tech = arg;
1233 if (arg < -1 || arg >= ef_nelem(EF_PLANE))
1235 if (arg == nuke->nuk_plane) {
1236 pr("Plane of %s unchanged\n", prnuke(nuke));
1239 divine_unload((struct empobj *)nuke, EF_PLANE, nuke->nuk_plane);
1240 divine_load((struct empobj *)nuke, EF_PLANE, arg);
1241 nuke->nuk_plane = arg;
1244 pr("huh? (%s)\n", key);