2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2015, 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-2015
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>: %s\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),
562 if (sect->sct_x == sect->sct_dist_x
563 && sect->sct_y == sect->sct_dist_y) {
564 sect->sct_dist_x = newx;
565 sect->sct_dist_y = newy;
569 sect->sct_coastal = newsect.sct_coastal;
570 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
573 if (!sarg_xy(p, &newx, &newy))
575 divine_sct_change_quiet(sect, "Distribution sector",
576 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
578 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
579 xyas(newx, newy, player->cnum));
580 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
582 if (sect->sct_own && sect->sct_own != player->cnum)
584 "Distribution sector of %s changed from %s to %s"
585 " by an act of %s\n",
586 xyas(sect->sct_x, sect->sct_y, player->cnum),
587 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
588 xyas(newx, newy, player->cnum),
589 cname(player->cnum));
590 sect->sct_dist_x = newx;
591 sect->sct_dist_y = newy;
594 new = sct_typematch(p);
597 divine_sct_change(sect, "Designation",
598 new != sect->sct_type, 0, "from %c to %c",
599 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
600 set_coastal(sect, sect->sct_type, new);
601 sect->sct_type = new;
604 new = sct_typematch(p);
607 divine_sct_change(sect, "New designation",
608 new != sect->sct_newtype, 0, "from %c to %c",
609 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
610 sect->sct_newtype = new;
613 return edit_sect_i(sect, key, atoi(p));
619 edit_level(struct natstr *np, int lvl, char *name, char *p)
621 float new = (float)atof(p);
624 divine_nat_change(np, name,
625 new != np->nat_level[lvl],
626 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
627 "from %.2f to %.2f", np->nat_level[lvl], new);
628 np->nat_level[lvl] = new;
632 edit_nat(struct natstr *np, char *key, char *p)
635 natid nat = np->nat_cnum;
640 if (!check_nat_name(p, nat))
642 divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
643 "from %s to %s", np->nat_cnam, p);
645 nreport(player->cnum, N_NAME_CHNG, 0, 1);
646 strcpy(np->nat_cnam, p);
649 divine_nat_change(np, "Country representative",
650 strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
652 np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
653 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
656 arg = LIMIT_TO(arg, 0, USHRT_MAX);
657 divine_nat_change_quiet(np, "Number of unread telegrams",
659 "from %d to %d", np->nat_tgms, arg);
663 arg = LIMIT_TO(arg, 0, max_btus);
664 divine_nat_change(np, "BTUs",
665 arg != np->nat_btu, arg - np->nat_btu,
666 "from %d to %d", np->nat_btu, arg);
670 arg = LIMIT_TO(arg, 0, INT_MAX);
671 divine_nat_change(np, "Military reserves",
672 arg != np->nat_reserve, arg - np->nat_reserve,
673 "from %d to %d", np->nat_reserve, arg);
674 np->nat_reserve = arg;
677 if (!sarg_xy(p, &newx, &newy))
679 if (newx == np->nat_xcap && newy == np->nat_ycap)
680 pr("Capital unchanged\n");
682 pr("Capital moved from %s to %s\n",
683 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
684 xyas(newx, newy, player->cnum));
685 if (nat != player->cnum)
687 "Capital moved from %s to %s by an act of %s!\n",
688 xyas(np->nat_xcap, np->nat_ycap, nat),
689 xyas(newx, newy, nat), cname(player->cnum));
695 if (!sarg_xy(p, &newx, &newy))
697 if (newx == np->nat_xorg && newy == np->nat_yorg)
698 pr("Origin unchanged\n");
700 pr("Origin moved from %s to %s\n",
701 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
702 xyas(newx, newy, player->cnum));
703 if (nat != player->cnum)
705 "Origin moved from %s to %s by an act of %s!\n",
706 xyas(np->nat_xorg, np->nat_yorg, nat),
707 xyas(newx, newy, nat), cname(player->cnum));
713 arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
714 divine_nat_change(np, "Status",
715 (enum nat_status)arg != np->nat_stat,
716 0, "to %s", nation_status[arg].name);
720 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
721 divine_nat_change(np, "Number of seconds used",
722 arg != np->nat_timeused, arg - np->nat_timeused,
723 "from %d to %d", np->nat_timeused, arg);
724 np->nat_timeused = arg;
727 divine_nat_change(np, "Money",
728 arg != np->nat_money, arg - np->nat_money,
729 "from %d to %d", np->nat_money, arg);
733 edit_level(np, NAT_TLEV, "Technology", p);
736 edit_level(np, NAT_RLEV, "Research", p);
739 edit_level(np, NAT_ELEV, "Education", p);
742 edit_level(np, NAT_HLEV, "Happiness", p);
745 pr("huh? (%s)\n", key);
752 edit_unit(struct empobj *unit, char *key, char *p,
753 int mineff, char *group_name, int on_carrier)
757 union empobj_storage newunit;
760 switch (toupper(*key)) {
764 if (arg == unit->uid) {
765 pr("%s unchanged\n", unit_nameof(unit));
768 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
769 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
772 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
773 ef_set_uid(unit->ef_type, unit, arg);
774 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
775 pr("Replacing %s of %s\n",
776 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
777 report_god_takes("", unit_nameof(&newunit.gen),
780 report_god_gives("", unit_nameof(unit), unit->own);
783 if (arg < 0 || arg >= MAXNOC)
785 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
787 prnatid(unit->own), prnatid(arg));
788 if (arg != unit->own) {
789 report_god_takes("", unit_nameof(unit), unit->own);
790 report_god_gives("", unit_nameof(unit), arg);
792 if (arg && unit->effic < mineff) {
793 divine_unit_change_quiet(unit, "Efficiency", 1,
794 "from %d to %d", unit->effic, mineff);
795 unit->effic = mineff;
800 if (!sarg_xy(p, &newx, &newy))
802 if (on_carrier && (newx != unit->x || newy != unit->y)) {
803 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
806 divine_unit_change_quiet(unit, "Location",
807 newx != unit->x || newy != unit->y,
809 xyas(unit->x, unit->y, player->cnum),
810 xyas(newx, newy, player->cnum));
811 if (newx == unit->x && newy == unit->y)
813 if (unit->own && unit->own != player->cnum)
815 "Location of %s changed from %s to %s by an act of %s!\n",
817 xyas(unit->x, unit->y, unit->own),
818 xyas(newx, newy, unit->own),
819 cname(player->cnum));
820 unit_teleport(unit, newx, newy);
823 arg = LIMIT_TO(arg, mineff, 100);
824 divine_unit_change(unit, "Efficiency",
825 arg != unit->effic, arg - unit->effic,
826 "from %d to %d", unit->effic, arg);
830 arg = LIMIT_TO(arg, -127, 127);
831 divine_unit_change(unit, "Mobility",
832 arg != unit->mobil, arg - unit->mobil,
833 "from %d to %d", unit->mobil, arg);
842 else if (isalpha(p[0]))
845 pr("%c: invalid %s\n", p[0], group_name);
848 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
849 "from %s %c to %c", group_name,
850 unit->group ? unit->group : '~', p[0]);
851 unit->group = newgroup;
860 edit_item(struct empobj *unit, short item[], struct ichrstr *ip, int arg,
863 arg = LIMIT_TO(arg, 0, lim[ip->i_uid]);
864 divine_unit_change_quiet(unit, ip->i_name, arg != item[ip->i_uid],
865 "from %d to %d", item[ip->i_uid], arg);
866 report_divine_gift(unit->own, ip, arg - item[ip->i_uid],
868 item[ip->i_uid] = arg;
872 limit_item(struct empobj *unit, short item[], short lim[])
876 for (it = I_NONE + 1; it <= I_MAX; it++) {
877 if (item[it] > lim[it])
878 edit_item(unit, item, &ichr[it], item[it], lim);
883 edit_ship(struct shpstr *ship, char *key, char *p)
885 struct mchrstr *mcp = &mchr[ship->shp_type];
896 ret = edit_unit((struct empobj *)ship, key, p,
897 SHIP_MINEFF, "fleet", 0);
900 arg = ef_elt_byname(EF_SHIP_CHR, p);
902 pr("%s: invalid ship type\n", p);
905 divine_unit_change((struct empobj *)ship, "Type",
906 arg != ship->shp_type, 0,
907 "to %s", mchr[arg].m_name);
908 if (ship->shp_tech < mchr[arg].m_tech)
909 shp_set_tech(ship, mchr[arg].m_tech);
910 ship->shp_type = arg;
911 shp_set_tech(ship, ship->shp_tech);
912 limit_item((struct empobj *)ship, ship->shp_item, mchr[arg].m_item);
915 arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
916 divine_unit_change((struct empobj *)ship, "Tech level",
917 arg != ship->shp_tech, arg - ship->shp_tech,
918 "from %d to %d", ship->shp_tech, arg);
919 shp_set_tech(ship, arg);
922 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
923 divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
924 arg != ship->shp_pstage,
925 "from %d to %d", ship->shp_pstage, arg);
926 ship->shp_pstage = arg;
929 arg = LIMIT_TO(arg, 0, 32767);
930 divine_unit_change_quiet((struct empobj *)ship, "Plague time",
931 arg != ship->shp_ptime,
932 "from %d to %d", ship->shp_ptime, arg);
933 ship->shp_ptime = arg;
936 divine_unit_change((struct empobj *)ship, "Retreat path",
937 strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
938 0, "from %s to %.*s",
939 ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
940 strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
943 divine_flag_change((struct empobj *)ship, "Retreat conditions",
944 ship->shp_rflags, arg, retreat_flags);
945 ship->shp_rflags = arg;
960 edit_item((struct empobj *)ship, ship->shp_item, item_by_name(key),
964 pr("huh? (%s)\n", key);
971 edit_land(struct lndstr *land, char *key, char *p)
973 struct lchrstr *lcp = &lchr[land->lnd_type];
983 return edit_unit((struct empobj *)land, key, p,
985 land->lnd_ship >= 0 || land->lnd_land >= 0);
987 arg = ef_elt_byname(EF_LAND_CHR, p);
989 pr("%s: invalid land unit type\n", p);
992 divine_unit_change((struct empobj *)land, "Type",
993 arg != land->lnd_type, 0,
994 "to %s", lchr[arg].l_name);
995 if (land->lnd_tech < lchr[arg].l_tech)
996 lnd_set_tech(land, lchr[arg].l_tech);
997 land->lnd_type = arg;
998 lnd_set_tech(land, land->lnd_tech);
999 limit_item((struct empobj *)land, land->lnd_item, lchr[arg].l_item);
1002 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
1003 divine_unit_change((struct empobj *)land, "Tech level",
1004 arg != land->lnd_tech, arg - land->lnd_tech,
1005 "from %d to %d", land->lnd_tech, arg);
1006 lnd_set_tech(land, arg);
1009 arg = LIMIT_TO(arg, 0, 127);
1010 divine_unit_change((struct empobj *)land, "Fortification",
1011 arg != land->lnd_harden, arg - land->lnd_harden,
1012 "from %d to %d", land->lnd_harden, arg);
1013 land->lnd_harden = arg;
1016 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1018 if (arg == land->lnd_ship) {
1019 pr("Ship of %s unchanged\n", prland(land));
1022 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1024 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1025 land->lnd_land = -1;
1027 divine_load((struct empobj *)land, EF_SHIP, arg);
1028 land->lnd_ship = arg;
1031 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1033 if (arg == land->lnd_land) {
1034 pr("Land unit of %s unchanged\n", prland(land));
1037 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1039 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1040 land->lnd_ship = -1;
1042 divine_load((struct empobj *)land, EF_LAND, arg);
1043 land->lnd_land = arg;
1046 arg = LIMIT_TO(arg, 0, 100);
1047 divine_unit_change((struct empobj *)land, "Retreat percentage",
1048 arg != land->lnd_retreat, 0,
1049 "from %d to %d", land->lnd_retreat, arg);
1050 land->lnd_retreat = arg;
1053 divine_unit_change((struct empobj *)land, "Retreat path",
1054 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
1055 0, "from %s to %.*s",
1056 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
1057 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
1060 divine_flag_change((struct empobj *)land, "Retreat condition",
1061 land->lnd_rflags, arg, retreat_flags);
1062 land->lnd_rflags = arg;
1077 edit_item((struct empobj *)land, land->lnd_item, item_by_name(key),
1081 pr("huh? (%s)\n", key);
1088 edit_plane(struct plnstr *plane, char *key, char *p)
1090 struct plchrstr *pcp = &plchr[plane->pln_type];
1100 return edit_unit((struct empobj *)plane, key, p,
1101 PLANE_MINEFF, "wing",
1102 plane->pln_ship >= 0 || plane->pln_land >= 0);
1104 arg = ef_elt_byname(EF_PLANE_CHR, p);
1106 pr("%s: invalid plane type\n", p);
1109 divine_unit_change((struct empobj *)plane, "Type",
1110 arg != plane->pln_type, 0,
1111 "to %s", plchr[arg].pl_name);
1112 if (plane->pln_tech < plchr[arg].pl_tech)
1113 pln_set_tech(plane, plchr[arg].pl_tech);
1114 if (plane->pln_range >= pln_range_max(plane))
1115 /* preserve unlimited range, pln_set_tech() will adjust */
1116 plane->pln_range = UCHAR_MAX;
1117 plane->pln_type = arg;
1118 pln_set_tech(plane, plane->pln_tech);
1121 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1122 divine_unit_change((struct empobj *)plane, "Tech level",
1123 arg != plane->pln_tech, arg - plane->pln_tech,
1124 "from %d to %d", plane->pln_tech, arg);
1125 pln_set_tech(plane, arg);
1128 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1129 divine_unit_change((struct empobj *)plane, "Range",
1130 arg != plane->pln_range, 0,
1131 "from %d to %d", plane->pln_range, arg);
1132 plane->pln_range = (unsigned char)arg;
1135 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1137 if (arg == plane->pln_ship) {
1138 pr("Ship of %s unchanged\n", prplane(plane));
1141 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1143 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1144 plane->pln_land = -1;
1146 divine_load((struct empobj *)plane, EF_SHIP, arg);
1147 plane->pln_ship = arg;
1150 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1152 if (arg == plane->pln_land) {
1153 pr("Land unit of %s unchanged\n", prplane(plane));
1156 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1158 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1159 plane->pln_ship = -1;
1161 divine_load((struct empobj *)plane, EF_LAND, arg);
1162 plane->pln_land = arg;
1165 divine_flag_change((struct empobj *)plane, "Flags",
1166 plane->pln_flags, arg, plane_flags);
1167 plane->pln_flags = arg;
1170 pr("huh? (%s)\n", key);
1177 edit_nuke(struct nukstr *nuke, char *key, char *p)
1179 struct nchrstr *ncp = &nchr[nuke->nuk_type];
1187 return edit_unit((struct empobj *)nuke, key, p,
1188 100, "stockpile", nuke->nuk_plane >= 0);
1190 arg = ef_elt_byname(EF_NUKE_CHR, p);
1192 pr("%s: invalid nuke type\n", p);
1195 divine_unit_change((struct empobj *)nuke, "Type",
1196 arg != nuke->nuk_type, 0,
1197 "to %s", nchr[arg].n_name);
1198 if (nuke->nuk_tech < nchr[arg].n_tech)
1199 nuke->nuk_tech = nchr[arg].n_tech;
1200 nuke->nuk_type = arg;
1203 arg = LIMIT_TO(arg, ncp->n_tech, SHRT_MAX);
1204 divine_unit_change((struct empobj *)nuke, "Tech level",
1205 arg != nuke->nuk_tech, arg - nuke->nuk_tech,
1206 "from %d to %d", nuke->nuk_tech, arg);
1207 nuke->nuk_tech = arg;
1210 if (arg < -1 || arg >= ef_nelem(EF_PLANE))
1212 if (arg == nuke->nuk_plane) {
1213 pr("Plane of %s unchanged\n", prnuke(nuke));
1216 divine_unload((struct empobj *)nuke, EF_PLANE, nuke->nuk_plane);
1217 divine_load((struct empobj *)nuke, EF_PLANE, arg);
1218 nuke->nuk_plane = arg;
1221 pr("huh? (%s)\n", key);