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 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)
231 pr("Country #: %2d\n", np->nat_cnum);
232 pr("Name <n>: %-20s\t", np->nat_cnam);
233 pr("Representative <r>: %-20s\n", np->nat_pnam);
234 pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
235 pr("Reserves <m>: %5d\n", np->nat_reserve);
236 pr("Capital <c>: %s\t\t",
237 xyas(np->nat_xcap, np->nat_ycap, player->cnum));
238 pr("Origin <o>: %3s\n",
239 xyas(np->nat_xorg, np->nat_yorg, player->cnum));
240 pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
241 pr("Seconds Used <u>: %3d\n", np->nat_timeused);
242 pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
243 pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
244 pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
245 pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
246 pr("Money <M>: $%6d\n", np->nat_money);
247 pr("Telegrams <t>: %6d\n", np->nat_tgms);
249 pr("Countries contacted: ");
250 for (i = 0; i < MAXNOC; i++) {
251 if (getcontact(np, i))
252 pr("%d(%d) ", i, getcontact(np, i));
259 print_plane(struct plnstr *plane)
261 pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
262 pr("UID <U>: %d\t\t", plane->pln_uid);
263 pr("Type <T>: %s\n", plchr[plane->pln_type].pl_name);
264 pr("Owner <O>: %d\t\t", plane->pln_own);
265 pr("Location <l>: %s\n",
266 xyas(plane->pln_x, plane->pln_y, player->cnum));
267 pr("Efficiency <e>: %d\t", plane->pln_effic);
268 pr("Mobility <m>: %d\n", plane->pln_mobil);
269 pr("Tech <t>: %d\t\t", plane->pln_tech);
270 pr("Wing <w>: %.1s\n", &plane->pln_wing);
271 pr("Range <r>: %d\t\t", plane->pln_range);
272 pr("Flags <f>: %d\n", plane->pln_flags);
273 pr("Ship <s>: %d\t\t", plane->pln_ship);
274 pr("Land Unit <y>: %d\n", plane->pln_land);
278 print_land(struct lndstr *land)
280 pr("%s %s\n", prnatid(land->lnd_own), prland(land));
281 pr("UID <U>: %d\t\t", land->lnd_uid);
282 pr("Type <T>: %s\n", lchr[land->lnd_type].l_name);
283 pr("Owner <O>: %d\n", land->lnd_own);
284 pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
285 pr("Efficiency <e>: %d\t", land->lnd_effic);
286 pr("Mobility <M>: %d\n", land->lnd_mobil);
287 pr("Tech <t>: %d\t\t", land->lnd_tech);
288 pr("Army <a>: %.1s\n", &land->lnd_army);
289 pr("Fortification <F>: %d\t", land->lnd_harden);
290 pr("Land unit <Y>: %d\n", land->lnd_land);
291 pr("Ship <S>: %d\t\t", land->lnd_ship);
292 pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
293 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
294 land->lnd_rpath, land->lnd_rflags);
295 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
296 pr(" c m u f s g p i d o l h r\n");
297 pr("%3d", land->lnd_item[I_CIVIL]);
298 pr("%4d", land->lnd_item[I_MILIT]);
299 pr("%4d", land->lnd_item[I_UW]);
300 pr("%5d", land->lnd_item[I_FOOD]);
301 pr("%4d", land->lnd_item[I_SHELL]);
302 pr("%4d", land->lnd_item[I_GUN]);
303 pr("%5d", land->lnd_item[I_PETROL]);
304 pr("%5d", land->lnd_item[I_IRON]);
305 pr("%5d", land->lnd_item[I_DUST]);
306 pr("%5d", land->lnd_item[I_OIL]);
307 pr("%5d", land->lnd_item[I_LCM]);
308 pr("%5d", land->lnd_item[I_HCM]);
309 pr("%4d", land->lnd_item[I_RAD]);
314 print_ship(struct shpstr *ship)
316 pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
317 pr("UID <U>: %d\t\t\t", ship->shp_uid);
318 pr("Type <t>: %s\n", mchr[ship->shp_type].m_name);
319 pr("Owner <O>: %d\t\t\t", ship->shp_own);
320 pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
321 pr("Tech <T>: %d\t\t\t", ship->shp_tech);
322 pr("Efficiency <E>: %d\n", ship->shp_effic);
323 pr("Mobility <M>: %d\t\t", ship->shp_mobil);
324 pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
325 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
326 ship->shp_rpath, ship->shp_rflags);
327 pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
328 pr("Plague Time <b>: %d\n", ship->shp_ptime);
329 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
330 pr(" c m u f s g p i d o l h r\n");
331 pr("%3d", ship->shp_item[I_CIVIL]);
332 pr("%4d", ship->shp_item[I_MILIT]);
333 pr("%4d", ship->shp_item[I_UW]);
334 pr("%5d", ship->shp_item[I_FOOD]);
335 pr("%4d", ship->shp_item[I_SHELL]);
336 pr("%4d", ship->shp_item[I_GUN]);
337 pr("%5d", ship->shp_item[I_PETROL]);
338 pr("%5d", ship->shp_item[I_IRON]);
339 pr("%5d", ship->shp_item[I_DUST]);
340 pr("%5d", ship->shp_item[I_OIL]);
341 pr("%5d", ship->shp_item[I_LCM]);
342 pr("%5d", ship->shp_item[I_HCM]);
343 pr("%4d", ship->shp_item[I_RAD]);
348 print_nuke(struct nukstr *nuke)
350 pr("%s %s\n", prnatid(nuke->nuk_own), prnuke(nuke));
351 pr("UID <U>: %d\t\t\t", nuke->nuk_uid);
352 pr("Type <t>: %d\n", nuke->nuk_type);
353 pr("Owner <O>: %d\t\t\t", nuke->nuk_own);
354 pr("Location <L>: %s\n", xyas(nuke->nuk_x, nuke->nuk_y, player->cnum));
355 pr("Tech <T>: %d\t\t\t", nuke->nuk_tech);
356 pr("Stockpile <S>: %.1s\n", &nuke->nuk_stockpile);
357 pr("Plane <p>: %d\n", nuke->nuk_plane);
361 getin(char *buf, char **valp)
368 p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
371 switch (parse(p, buf, argp, NULL, NULL, NULL)) {
382 #if 0 /* not needed right now */
384 warn_deprecated(char key)
386 pr("Key <%c> is deprecated and will go away in a future release\n", key);
391 edit_sect_i(struct sctstr *sect, char *key, int arg)
397 if (arg < 0 || arg >= MAXNOC)
399 divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
401 prnatid(sect->sct_own), prnatid(arg));
402 if (arg == sect->sct_own)
404 report_god_takes("Sector ",
405 xyas(sect->sct_x, sect->sct_y, sect->sct_own),
407 report_god_gives("Sector ",
408 xyas(sect->sct_x, sect->sct_y, arg),
413 if (arg < 0 || arg >= MAXNOC)
415 divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
417 prnatid(sect->sct_oldown), prnatid(arg));
418 sect->sct_oldown = arg;
421 new = LIMIT_TO(arg, 0, 100);
422 noise(sect, "Efficiency", sect->sct_effic, new);
423 sect->sct_effic = new;
426 new = LIMIT_TO(arg, -127, 127);
427 noise(sect, "Mobility", sect->sct_mobil, new);
428 sect->sct_mobil = new;
431 new = LIMIT_TO(arg, 0, 100);
432 noise(sect, "Iron ore content", sect->sct_min, new);
433 sect->sct_min = (unsigned char)new;
436 new = LIMIT_TO(arg, 0, 100);
437 noise(sect, "Gold content", sect->sct_gmin, new);
438 sect->sct_gmin = (unsigned char)new;
441 new = LIMIT_TO(arg, 0, 100);
442 noise(sect, "Fertility", sect->sct_fertil, new);
443 sect->sct_fertil = (unsigned char)new;
446 new = LIMIT_TO(arg, 0, 100);
447 noise(sect, "Oil content", sect->sct_oil, new);
448 sect->sct_oil = (unsigned char)new;
451 new = LIMIT_TO(arg, 0, 100);
452 noise(sect, "Uranium content", sect->sct_uran, new);
453 sect->sct_uran = (unsigned char)new;
456 new = LIMIT_TO(arg, 0, 100);
457 noise(sect, "Workforce percentage", sect->sct_work, new);
458 sect->sct_work = (unsigned char)new;
461 new = LIMIT_TO(arg, 0, 127);
462 divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
463 "from %d to %d", sect->sct_loyal, new);
464 sect->sct_loyal = (unsigned char)new;
467 new = LIMIT_TO(arg, 0, CHE_MAX);
468 divine_sct_change_quiet(sect, "Guerillas", new != sect->sct_che,
469 "from %d to %d", sect->sct_che, new);
473 if (arg < 0 || arg >= MAXNOC)
475 divine_sct_change_quiet(sect, "Che target",
476 arg != sect->sct_che_target,
478 prnatid(sect->sct_che_target),
480 sect->sct_che_target = arg;
485 new = LIMIT_TO(arg, 0, PLG_EXPOSED);
486 divine_sct_change_quiet(sect, "Plague stage",
487 new != sect->sct_pstage,
488 "from %d to %d", sect->sct_pstage, new);
489 sect->sct_pstage = new;
492 new = LIMIT_TO(arg, 0, 32767);
493 divine_sct_change_quiet(sect, "Plague time",
494 new != sect->sct_ptime,
495 "from %d to %d", sect->sct_ptime, new);
496 sect->sct_ptime = new;
499 new = LIMIT_TO(arg, 0, FALLOUT_MAX);
500 noise(sect, "Fallout", sect->sct_fallout, new);
501 sect->sct_fallout = new;
504 new = LIMIT_TO(arg, 0, 9999);
505 noise(sect, "Available workforce", sect->sct_avail, new);
506 sect->sct_avail = new;
509 new = LIMIT_TO(arg, 0, MINES_MAX);
510 if (sect->sct_own == sect->sct_oldown)
511 noise(sect, "Mines", sect->sct_mines, new);
513 divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
514 "from %d to %d", sect->sct_mines, new);
515 sect->sct_mines = new;
518 new = LIMIT_TO(arg, 0, 100);
519 noise(sect, "Road percentage", sect->sct_road, new);
520 sect->sct_road = new;
523 new = LIMIT_TO(arg, 0, 100);
524 noise(sect, "Rail percentage", sect->sct_rail, new);
525 sect->sct_rail = new;
528 new = LIMIT_TO(arg, 0, 100);
529 noise(sect, "Defense percentage", sect->sct_defense, new);
530 sect->sct_defense = new;
533 pr("huh? (%s)\n", key);
540 edit_sect(struct sctstr *sect, char *key, char *p)
544 struct sctstr newsect;
548 if (!sarg_xy(p, &newx, &newy))
550 if (newx == sect->sct_x && newy == sect->sct_y) {
551 pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
554 getsect(newx, newy, &newsect);
555 pr("Sector %s duplicated to %s\n",
556 xyas(sect->sct_x, sect->sct_y, player->cnum),
557 xyas(newx, newy, player->cnum));
558 report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
560 report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
564 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
567 if (!sarg_xy(p, &newx, &newy))
569 divine_sct_change_quiet(sect, "Distribution sector",
570 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
572 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
573 xyas(newx, newy, player->cnum));
574 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
576 if (sect->sct_own && sect->sct_own != player->cnum)
578 "Distribution sector of %s changed from %s to %s"
579 " by an act of %s\n",
580 xyas(sect->sct_x, sect->sct_y, player->cnum),
581 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
582 xyas(newx, newy, player->cnum),
583 cname(player->cnum));
584 sect->sct_dist_x = newx;
585 sect->sct_dist_y = newy;
588 new = sct_typematch(p);
591 divine_sct_change(sect, "Designation",
592 new != sect->sct_type, 0, "from %c to %c",
593 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
594 set_coastal(sect, sect->sct_type, new);
595 sect->sct_type = new;
598 new = sct_typematch(p);
601 divine_sct_change(sect, "New designation",
602 new != sect->sct_newtype, 0, "from %c to %c",
603 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
604 sect->sct_newtype = new;
607 return edit_sect_i(sect, key, atoi(p));
613 edit_level(struct natstr *np, int lvl, char *name, char *p)
615 float new = (float)atof(p);
618 divine_nat_change(np, name,
619 new != np->nat_level[lvl],
620 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
621 "from %.2f to %.2f", np->nat_level[lvl], new);
622 np->nat_level[lvl] = new;
626 edit_nat(struct natstr *np, char *key, char *p)
629 natid nat = np->nat_cnum;
634 if (!check_nat_name(p, nat))
636 divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
637 "from %s to %s", np->nat_cnam, p);
639 nreport(player->cnum, N_NAME_CHNG, 0, 1);
640 strcpy(np->nat_cnam, p);
643 divine_nat_change(np, "Country representative",
644 strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
646 np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
647 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
650 arg = LIMIT_TO(arg, 0, USHRT_MAX);
651 divine_nat_change_quiet(np, "Number of unread telegrams",
653 "from %d to %d", np->nat_tgms, arg);
657 arg = LIMIT_TO(arg, 0, max_btus);
658 divine_nat_change(np, "BTUs",
659 arg != np->nat_btu, arg - np->nat_btu,
660 "from %d to %d", np->nat_btu, arg);
664 arg = LIMIT_TO(arg, 0, INT_MAX);
665 divine_nat_change(np, "Military reserves",
666 arg != np->nat_reserve, arg - np->nat_reserve,
667 "from %d to %d", np->nat_reserve, arg);
668 np->nat_reserve = arg;
671 if (!sarg_xy(p, &newx, &newy))
673 if (newx == np->nat_xcap && newy == np->nat_ycap)
674 pr("Capital unchanged\n");
676 pr("Capital moved from %s to %s\n",
677 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
678 xyas(newx, newy, player->cnum));
679 if (nat != player->cnum)
681 "Capital moved from %s to %s by an act of %s!\n",
682 xyas(np->nat_xcap, np->nat_ycap, nat),
683 xyas(newx, newy, nat), cname(player->cnum));
689 if (!sarg_xy(p, &newx, &newy))
691 if (newx == np->nat_xorg && newy == np->nat_yorg)
692 pr("Origin unchanged\n");
694 pr("Origin moved from %s to %s\n",
695 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
696 xyas(newx, newy, player->cnum));
697 if (nat != player->cnum)
699 "Origin moved from %s to %s by an act of %s!\n",
700 xyas(np->nat_xorg, np->nat_yorg, nat),
701 xyas(newx, newy, nat), cname(player->cnum));
707 arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
708 divine_nat_change(np, "Status",
709 (enum nat_status)arg != np->nat_stat,
710 0, "to %s", nation_status[arg].name);
714 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
715 divine_nat_change(np, "Number of seconds used",
716 arg != np->nat_timeused, arg - np->nat_timeused,
717 "from %d to %d", np->nat_timeused, arg);
718 np->nat_timeused = arg;
721 divine_nat_change(np, "Money",
722 arg != np->nat_money, arg - np->nat_money,
723 "from %d to %d", np->nat_money, arg);
727 edit_level(np, NAT_TLEV, "Technology", p);
730 edit_level(np, NAT_RLEV, "Research", p);
733 edit_level(np, NAT_ELEV, "Education", p);
736 edit_level(np, NAT_HLEV, "Happiness", p);
739 pr("huh? (%s)\n", key);
746 edit_unit(struct empobj *unit, char *key, char *p,
747 int mineff, char *group_name, int on_carrier)
751 union empobj_storage newunit;
754 switch (toupper(*key)) {
758 if (arg == unit->uid) {
759 pr("%s unchanged\n", unit_nameof(unit));
762 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
763 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
766 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
767 ef_set_uid(unit->ef_type, unit, arg);
768 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
769 pr("Replacing %s of %s\n",
770 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
771 report_god_takes("", unit_nameof(&newunit.gen),
774 report_god_gives("", unit_nameof(unit), unit->own);
777 if (arg < 0 || arg >= MAXNOC)
779 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
781 prnatid(unit->own), prnatid(arg));
782 if (arg != unit->own) {
783 report_god_takes("", unit_nameof(unit), unit->own);
784 report_god_gives("", unit_nameof(unit), arg);
786 if (arg && unit->effic < mineff) {
787 divine_unit_change_quiet(unit, "Efficiency", 1,
788 "from %d to %d", unit->effic, mineff);
789 unit->effic = mineff;
794 if (!sarg_xy(p, &newx, &newy))
796 if (on_carrier && (newx != unit->x || newy != unit->y)) {
797 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
800 divine_unit_change_quiet(unit, "Location",
801 unit->own && unit->own != player->cnum,
803 xyas(unit->x, unit->y, player->cnum),
804 xyas(newx, newy, player->cnum));
805 if (newx == unit->x && newy == unit->y)
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);
837 else if (isalpha(p[0]))
840 pr("%c: invalid %s\n", p[0], group_name);
843 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
844 "from %s %c to %c", group_name,
845 unit->group ? unit->group : '~', p[0]);
846 unit->group = newgroup;
855 edit_item(struct empobj *unit, short item[], struct ichrstr *ip, int arg,
858 arg = LIMIT_TO(arg, 0, lim[ip->i_uid]);
859 divine_unit_change_quiet(unit, ip->i_name, arg != item[ip->i_uid],
860 "from %d to %d", item[ip->i_uid], arg);
861 report_divine_gift(unit->own, ip, arg - item[ip->i_uid],
863 item[ip->i_uid] = arg;
867 limit_item(struct empobj *unit, short item[], short lim[])
871 for (it = I_NONE + 1; it <= I_MAX; it++) {
872 if (item[it] > lim[it])
873 edit_item(unit, item, &ichr[it], item[it], lim);
878 edit_ship(struct shpstr *ship, char *key, char *p)
880 struct mchrstr *mcp = &mchr[ship->shp_type];
890 return edit_unit((struct empobj *)ship, key, p,
891 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 ship->shp_type = arg;
902 limit_item((struct empobj *)ship, ship->shp_item, mchr[arg].m_item);
903 if (ship->shp_tech >= mchr[arg].m_tech)
905 arg = mchr[arg].m_tech;
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;
953 edit_item((struct empobj *)ship, ship->shp_item, item_by_name(key),
957 pr("huh? (%s)\n", key);
964 edit_land(struct lndstr *land, char *key, char *p)
966 struct lchrstr *lcp = &lchr[land->lnd_type];
976 return edit_unit((struct empobj *)land, key, p,
978 land->lnd_ship >= 0 || land->lnd_land >= 0);
980 arg = ef_elt_byname(EF_LAND_CHR, p);
982 pr("%s: invalid land unit type\n", p);
985 divine_unit_change((struct empobj *)land, "Type",
986 arg != land->lnd_type, 0,
987 "to %s", lchr[arg].l_name);
988 land->lnd_type = arg;
989 limit_item((struct empobj *)land, land->lnd_item, lchr[arg].l_item);
990 if (land->lnd_tech >= lchr[arg].l_tech)
992 arg = lchr[arg].l_tech;
995 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
996 divine_unit_change((struct empobj *)land, "Tech level",
997 arg != land->lnd_tech, arg - land->lnd_tech,
998 "from %d to %d", land->lnd_tech, arg);
999 lnd_set_tech(land, arg);
1002 arg = LIMIT_TO(arg, 0, 127);
1003 divine_unit_change((struct empobj *)land, "Fortification",
1004 arg != land->lnd_harden, arg - land->lnd_harden,
1005 "from %d to %d", land->lnd_harden, arg);
1006 land->lnd_harden = arg;
1009 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1011 if (arg == land->lnd_ship) {
1012 pr("Ship of %s unchanged\n", prland(land));
1015 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1017 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1018 land->lnd_land = -1;
1020 divine_load((struct empobj *)land, EF_SHIP, arg);
1021 land->lnd_ship = arg;
1024 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1026 if (arg == land->lnd_land) {
1027 pr("Land unit of %s unchanged\n", prland(land));
1030 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1032 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1033 land->lnd_ship = -1;
1035 divine_load((struct empobj *)land, EF_LAND, arg);
1036 land->lnd_land = arg;
1039 arg = LIMIT_TO(arg, 0, 100);
1040 divine_unit_change((struct empobj *)land, "Retreat percentage",
1041 arg != land->lnd_retreat, 0,
1042 "from %d to %d", land->lnd_retreat, arg);
1043 land->lnd_retreat = arg;
1046 divine_unit_change((struct empobj *)land, "Retreat path",
1047 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
1048 0, "from %s to %.*s",
1049 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
1050 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
1053 divine_flag_change((struct empobj *)land, "Retreat condition",
1054 land->lnd_rflags, arg, retreat_flags);
1055 land->lnd_rflags = arg;
1070 edit_item((struct empobj *)land, land->lnd_item, item_by_name(key),
1074 pr("huh? (%s)\n", key);
1081 edit_plane(struct plnstr *plane, char *key, char *p)
1083 struct plchrstr *pcp = &plchr[plane->pln_type];
1093 return edit_unit((struct empobj *)plane, key, p,
1094 PLANE_MINEFF, "wing",
1095 plane->pln_ship >= 0 || plane->pln_land >= 0);
1097 arg = ef_elt_byname(EF_PLANE_CHR, p);
1099 pr("%s: invalid plane type\n", p);
1102 divine_unit_change((struct empobj *)plane, "Type",
1103 arg != plane->pln_type, 0,
1104 "to %s", plchr[arg].pl_name);
1105 plane->pln_type = arg;
1106 if (plane->pln_tech >= plchr[arg].pl_tech)
1108 arg = plchr[arg].pl_tech;
1111 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1112 divine_unit_change((struct empobj *)plane, "Tech level",
1113 arg != plane->pln_tech, arg - plane->pln_tech,
1114 "from %d to %d", plane->pln_tech, arg);
1115 pln_set_tech(plane, arg);
1118 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1119 divine_unit_change((struct empobj *)plane, "Range",
1120 arg != plane->pln_range, 0,
1121 "from %d to %d", plane->pln_range, arg);
1122 plane->pln_range = (unsigned char)arg;
1125 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1127 if (arg == plane->pln_ship) {
1128 pr("Ship of %s unchanged\n", prplane(plane));
1131 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1133 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1134 plane->pln_land = -1;
1136 divine_load((struct empobj *)plane, EF_SHIP, arg);
1137 plane->pln_ship = arg;
1140 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1142 if (arg == plane->pln_land) {
1143 pr("Land unit of %s unchanged\n", prplane(plane));
1146 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1148 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1149 plane->pln_ship = -1;
1151 divine_load((struct empobj *)plane, EF_LAND, arg);
1152 plane->pln_land = arg;
1155 divine_flag_change((struct empobj *)plane, "Flags",
1156 plane->pln_flags, arg, plane_flags);
1157 plane->pln_flags = arg;
1160 pr("huh? (%s)\n", key);
1167 edit_nuke(struct nukstr *nuke, char *key, char *p)
1169 struct nchrstr *ncp = &nchr[nuke->nuk_type];
1177 return edit_unit((struct empobj *)nuke, key, p,
1178 100, "stockpile", nuke->nuk_plane >= 0);
1180 arg = ef_elt_byname(EF_NUKE_CHR, p);
1182 pr("%s: invalid nuke type\n", p);
1185 divine_unit_change((struct empobj *)nuke, "Type",
1186 arg != nuke->nuk_type, 0,
1187 "to %s", nchr[arg].n_name);
1188 nuke->nuk_type = arg;
1189 if (nuke->nuk_tech >= nchr[arg].n_tech)
1191 arg = nchr[arg].n_tech;
1194 arg = LIMIT_TO(arg, ncp->n_tech, SHRT_MAX);
1195 divine_unit_change((struct empobj *)nuke, "Tech level",
1196 arg != nuke->nuk_tech, arg - nuke->nuk_tech,
1197 "from %d to %d", nuke->nuk_tech, arg);
1198 nuke->nuk_tech = arg;
1201 if (arg < -1 || arg >= ef_nelem(EF_PLANE))
1203 if (arg == nuke->nuk_plane) {
1204 pr("Plane of %s unchanged\n", prnuke(nuke));
1207 divine_unload((struct empobj *)nuke, EF_PLANE, nuke->nuk_plane);
1208 divine_load((struct empobj *)nuke, EF_PLANE, arg);
1209 nuke->nuk_plane = arg;
1212 pr("huh? (%s)\n", key);