2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2018, 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-2016
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_land(struct lndstr *land)
270 pr("%s %s\n", prnatid(land->lnd_own), prland(land));
271 pr("UID <U>: %d\t\t", land->lnd_uid);
272 pr("Type <T>: %s\n", lchr[land->lnd_type].l_name);
273 pr("Owner <O>: %d\n", land->lnd_own);
274 pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
275 pr("Efficiency <e>: %d\t", land->lnd_effic);
276 pr("Mobility <M>: %d\n", land->lnd_mobil);
277 pr("Tech <t>: %d\t\t", land->lnd_tech);
278 pr("Army <a>: %.1s\n", &land->lnd_army);
279 pr("Fortification <F>: %d\t", land->lnd_harden);
280 pr("Land unit <Y>: %d\n", land->lnd_land);
281 pr("Ship <S>: %d\t\t", land->lnd_ship);
282 pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
283 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
284 land->lnd_rpath, land->lnd_rflags);
285 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
286 pr(" c m u f s g p i d o l h r\n");
287 pr("%3d", land->lnd_item[I_CIVIL]);
288 pr("%4d", land->lnd_item[I_MILIT]);
289 pr("%4d", land->lnd_item[I_UW]);
290 pr("%5d", land->lnd_item[I_FOOD]);
291 pr("%4d", land->lnd_item[I_SHELL]);
292 pr("%4d", land->lnd_item[I_GUN]);
293 pr("%5d", land->lnd_item[I_PETROL]);
294 pr("%5d", land->lnd_item[I_IRON]);
295 pr("%5d", land->lnd_item[I_DUST]);
296 pr("%5d", land->lnd_item[I_OIL]);
297 pr("%5d", land->lnd_item[I_LCM]);
298 pr("%5d", land->lnd_item[I_HCM]);
299 pr("%4d", land->lnd_item[I_RAD]);
304 print_ship(struct shpstr *ship)
306 pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
307 pr("UID <U>: %d\t\t\t", ship->shp_uid);
308 pr("Type <t>: %s\n", mchr[ship->shp_type].m_name);
309 pr("Owner <O>: %d\t\t\t", ship->shp_own);
310 pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
311 pr("Tech <T>: %d\t\t\t", ship->shp_tech);
312 pr("Efficiency <E>: %d\n", ship->shp_effic);
313 pr("Mobility <M>: %d\t\t", ship->shp_mobil);
314 pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
315 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
316 ship->shp_rpath, ship->shp_rflags);
317 pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
318 pr("Plague Time <b>: %d\n", ship->shp_ptime);
319 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
320 pr(" c m u f s g p i d o l h r\n");
321 pr("%3d", ship->shp_item[I_CIVIL]);
322 pr("%4d", ship->shp_item[I_MILIT]);
323 pr("%4d", ship->shp_item[I_UW]);
324 pr("%5d", ship->shp_item[I_FOOD]);
325 pr("%4d", ship->shp_item[I_SHELL]);
326 pr("%4d", ship->shp_item[I_GUN]);
327 pr("%5d", ship->shp_item[I_PETROL]);
328 pr("%5d", ship->shp_item[I_IRON]);
329 pr("%5d", ship->shp_item[I_DUST]);
330 pr("%5d", ship->shp_item[I_OIL]);
331 pr("%5d", ship->shp_item[I_LCM]);
332 pr("%5d", ship->shp_item[I_HCM]);
333 pr("%4d", ship->shp_item[I_RAD]);
338 print_nuke(struct nukstr *nuke)
340 pr("%s %s\n", prnatid(nuke->nuk_own), prnuke(nuke));
341 pr("UID <U>: %d\t\t\t", nuke->nuk_uid);
342 pr("Type <t>: %d\n", nuke->nuk_type);
343 pr("Owner <O>: %d\t\t\t", nuke->nuk_own);
344 pr("Location <L>: %s\n", xyas(nuke->nuk_x, nuke->nuk_y, player->cnum));
345 pr("Tech <T>: %d\t\t\t", nuke->nuk_tech);
346 pr("Stockpile <S>: %.1s\n", &nuke->nuk_stockpile);
347 pr("Plane <p>: %d\n", nuke->nuk_plane);
351 getin(char *buf, char **valp)
358 p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
361 switch (parse(p, buf, argp, NULL, NULL, NULL)) {
372 #if 0 /* not needed right now */
374 warn_deprecated(char key)
376 pr("Key <%c> is deprecated and will go away in a future release\n", key);
381 edit_sect_i(struct sctstr *sect, char *key, int arg)
387 if (arg < 0 || arg >= MAXNOC)
389 divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
391 prnatid(sect->sct_own), prnatid(arg));
392 if (arg == sect->sct_own)
394 report_god_takes("Sector ",
395 xyas(sect->sct_x, sect->sct_y, sect->sct_own),
397 report_god_gives("Sector ",
398 xyas(sect->sct_x, sect->sct_y, arg),
403 if (arg < 0 || arg >= MAXNOC)
405 divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
407 prnatid(sect->sct_oldown), prnatid(arg));
408 sect->sct_oldown = arg;
411 new = LIMIT_TO(arg, 0, 100);
412 noise(sect, "Efficiency", sect->sct_effic, new);
413 sect->sct_effic = new;
416 new = LIMIT_TO(arg, -127, 127);
417 noise(sect, "Mobility", sect->sct_mobil, new);
418 sect->sct_mobil = new;
421 new = LIMIT_TO(arg, 0, 100);
422 noise(sect, "Iron ore content", sect->sct_min, new);
423 sect->sct_min = (unsigned char)new;
426 new = LIMIT_TO(arg, 0, 100);
427 noise(sect, "Gold content", sect->sct_gmin, new);
428 sect->sct_gmin = (unsigned char)new;
431 new = LIMIT_TO(arg, 0, 100);
432 noise(sect, "Fertility", sect->sct_fertil, new);
433 sect->sct_fertil = (unsigned char)new;
436 new = LIMIT_TO(arg, 0, 100);
437 noise(sect, "Oil content", sect->sct_oil, new);
438 sect->sct_oil = (unsigned char)new;
441 new = LIMIT_TO(arg, 0, 100);
442 noise(sect, "Uranium content", sect->sct_uran, new);
443 sect->sct_uran = (unsigned char)new;
446 new = LIMIT_TO(arg, 0, 100);
447 noise(sect, "Workforce percentage", sect->sct_work, new);
448 sect->sct_work = (unsigned char)new;
451 new = LIMIT_TO(arg, 0, 127);
452 divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
453 "from %d to %d", sect->sct_loyal, new);
454 sect->sct_loyal = (unsigned char)new;
457 new = LIMIT_TO(arg, 0, CHE_MAX);
458 divine_sct_change_quiet(sect, "Guerrillas", new != sect->sct_che,
459 "from %d to %d", sect->sct_che, new);
463 if (arg < 0 || arg >= MAXNOC)
465 divine_sct_change_quiet(sect, "Che target",
466 arg != sect->sct_che_target,
468 prnatid(sect->sct_che_target),
470 sect->sct_che_target = arg;
475 new = LIMIT_TO(arg, 0, PLG_EXPOSED);
476 divine_sct_change_quiet(sect, "Plague stage",
477 new != sect->sct_pstage,
478 "from %d to %d", sect->sct_pstage, new);
479 sect->sct_pstage = new;
482 new = LIMIT_TO(arg, 0, 32767);
483 divine_sct_change_quiet(sect, "Plague time",
484 new != sect->sct_ptime,
485 "from %d to %d", sect->sct_ptime, new);
486 sect->sct_ptime = new;
489 new = LIMIT_TO(arg, 0, FALLOUT_MAX);
490 noise(sect, "Fallout", sect->sct_fallout, new);
491 sect->sct_fallout = new;
494 new = LIMIT_TO(arg, 0, 9999);
495 noise(sect, "Available workforce", sect->sct_avail, new);
496 sect->sct_avail = new;
499 new = LIMIT_TO(arg, 0, MINES_MAX);
500 if (sect->sct_own == sect->sct_oldown)
501 noise(sect, "Mines", sect->sct_mines, new);
503 divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
504 "from %d to %d", sect->sct_mines, new);
505 sect->sct_mines = new;
508 new = LIMIT_TO(arg, 0, 100);
509 noise(sect, "Road percentage", sect->sct_road, new);
510 sect->sct_road = new;
513 new = LIMIT_TO(arg, 0, 100);
514 noise(sect, "Rail percentage", sect->sct_rail, new);
515 sect->sct_rail = new;
518 new = LIMIT_TO(arg, 0, 100);
519 noise(sect, "Defense percentage", sect->sct_defense, new);
520 sect->sct_defense = new;
523 pr("huh? (%s)\n", key);
530 edit_sect(struct sctstr *sect, char *key, char *p)
534 struct sctstr newsect;
538 if (!sarg_xy(p, &newx, &newy))
540 if (newx == sect->sct_x && newy == sect->sct_y) {
541 pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
544 getsect(newx, newy, &newsect);
545 pr("Sector %s duplicated to %s\n",
546 xyas(sect->sct_x, sect->sct_y, player->cnum),
547 xyas(newx, newy, player->cnum));
548 report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
550 report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
552 if (sect->sct_x == sect->sct_dist_x
553 && sect->sct_y == sect->sct_dist_y) {
554 sect->sct_dist_x = newx;
555 sect->sct_dist_y = newy;
559 sect->sct_coastal = newsect.sct_coastal;
560 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
563 if (!sarg_xy(p, &newx, &newy))
565 divine_sct_change_quiet(sect, "Distribution sector",
566 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
568 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
569 xyas(newx, newy, player->cnum));
570 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
572 if (sect->sct_own && sect->sct_own != player->cnum)
574 "Distribution sector of %s changed from %s to %s"
575 " by an act of %s\n",
576 xyas(sect->sct_x, sect->sct_y, player->cnum),
577 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
578 xyas(newx, newy, player->cnum),
579 cname(player->cnum));
580 sect->sct_dist_x = newx;
581 sect->sct_dist_y = newy;
584 new = sct_typematch(p);
587 divine_sct_change(sect, "Designation",
588 new != sect->sct_type, 0, "from %c to %c",
589 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
590 set_coastal(sect, sect->sct_type, new);
591 sect->sct_type = new;
594 new = sct_typematch(p);
597 divine_sct_change(sect, "New designation",
598 new != sect->sct_newtype, 0, "from %c to %c",
599 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
600 sect->sct_newtype = new;
603 return edit_sect_i(sect, key, atoi(p));
609 edit_level(struct natstr *np, int lvl, char *name, char *p)
611 float new = (float)atof(p);
614 divine_nat_change(np, name,
615 new != np->nat_level[lvl],
616 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
617 "from %.2f to %.2f", np->nat_level[lvl], new);
618 np->nat_level[lvl] = new;
622 edit_nat(struct natstr *np, char *key, char *p)
625 natid nat = np->nat_cnum;
630 if (!check_nat_name(p, nat))
632 divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
633 "from %s to %s", np->nat_cnam, p);
635 nreport(player->cnum, N_NAME_CHNG, 0, 1);
636 strcpy(np->nat_cnam, p);
639 divine_nat_change(np, "Country representative",
640 strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
642 np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
643 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
646 arg = LIMIT_TO(arg, 0, USHRT_MAX);
647 divine_nat_change_quiet(np, "Number of unread telegrams",
649 "from %d to %d", np->nat_tgms, arg);
653 arg = LIMIT_TO(arg, 0, max_btus);
654 divine_nat_change(np, "BTUs",
655 arg != np->nat_btu, arg - np->nat_btu,
656 "from %d to %d", np->nat_btu, arg);
660 arg = LIMIT_TO(arg, 0, INT_MAX);
661 divine_nat_change(np, "Military reserves",
662 arg != np->nat_reserve, arg - np->nat_reserve,
663 "from %d to %d", np->nat_reserve, arg);
664 np->nat_reserve = arg;
667 if (!sarg_xy(p, &newx, &newy))
669 if (newx == np->nat_xcap && newy == np->nat_ycap)
670 pr("Capital unchanged\n");
672 pr("Capital moved from %s to %s\n",
673 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
674 xyas(newx, newy, player->cnum));
675 if (nat != player->cnum)
677 "Capital moved from %s to %s by an act of %s!\n",
678 xyas(np->nat_xcap, np->nat_ycap, nat),
679 xyas(newx, newy, nat), cname(player->cnum));
685 if (!sarg_xy(p, &newx, &newy))
687 if (newx == np->nat_xorg && newy == np->nat_yorg)
688 pr("Origin unchanged\n");
690 pr("Origin moved from %s to %s\n",
691 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
692 xyas(newx, newy, player->cnum));
693 if (nat != player->cnum)
695 "Origin moved from %s to %s by an act of %s!\n",
696 xyas(np->nat_xorg, np->nat_yorg, nat),
697 xyas(newx, newy, nat), cname(player->cnum));
703 arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
704 divine_nat_change(np, "Status",
705 (enum nat_status)arg != np->nat_stat,
706 0, "to %s", nation_status[arg].name);
710 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
711 divine_nat_change(np, "Number of seconds used",
712 arg != np->nat_timeused, arg - np->nat_timeused,
713 "from %d to %d", np->nat_timeused, arg);
714 np->nat_timeused = arg;
717 divine_nat_change(np, "Money",
718 arg != np->nat_money, arg - np->nat_money,
719 "from %d to %d", np->nat_money, arg);
723 edit_level(np, NAT_TLEV, "Technology", p);
726 edit_level(np, NAT_RLEV, "Research", p);
729 edit_level(np, NAT_ELEV, "Education", p);
732 edit_level(np, NAT_HLEV, "Happiness", p);
735 pr("huh? (%s)\n", key);
742 edit_unit(struct empobj *unit, char *key, char *p,
743 int mineff, char *group_name, int on_carrier)
747 union empobj_storage newunit;
750 switch (toupper(*key)) {
754 if (arg == unit->uid) {
755 pr("%s unchanged\n", unit_nameof(unit));
758 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
759 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
762 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
763 ef_set_uid(unit->ef_type, unit, arg);
764 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
765 pr("Replacing %s of %s\n",
766 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
767 report_god_takes("", unit_nameof(&newunit.gen),
770 report_god_gives("", unit_nameof(unit), unit->own);
773 if (arg < 0 || arg >= MAXNOC)
775 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
777 prnatid(unit->own), prnatid(arg));
778 if (arg != unit->own) {
779 report_god_takes("", unit_nameof(unit), unit->own);
780 report_god_gives("", unit_nameof(unit), arg);
782 if (arg && unit->effic < mineff) {
783 divine_unit_change_quiet(unit, "Efficiency", 1,
784 "from %d to %d", unit->effic, mineff);
785 unit->effic = mineff;
790 if (!sarg_xy(p, &newx, &newy))
792 if (on_carrier && (newx != unit->x || newy != unit->y)) {
793 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
796 divine_unit_change_quiet(unit, "Location",
797 newx != unit->x || newy != unit->y,
799 xyas(unit->x, unit->y, player->cnum),
800 xyas(newx, newy, player->cnum));
801 if (newx == unit->x && newy == unit->y)
803 if (unit->own && unit->own != player->cnum)
805 "Location of %s changed from %s to %s by an act of %s!\n",
807 xyas(unit->x, unit->y, unit->own),
808 xyas(newx, newy, unit->own),
809 cname(player->cnum));
810 unit_teleport(unit, newx, newy);
813 arg = LIMIT_TO(arg, mineff, 100);
814 divine_unit_change(unit, "Efficiency",
815 arg != unit->effic, arg - unit->effic,
816 "from %d to %d", unit->effic, arg);
820 arg = LIMIT_TO(arg, -127, 127);
821 divine_unit_change(unit, "Mobility",
822 arg != unit->mobil, arg - unit->mobil,
823 "from %d to %d", unit->mobil, arg);
832 else if (isalpha(p[0]))
835 pr("%c: invalid %s\n", p[0], group_name);
838 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
839 "from %s %c to %c", group_name,
840 unit->group ? unit->group : '~', p[0]);
841 unit->group = newgroup;
850 edit_item(struct empobj *unit, short item[], struct ichrstr *ip, int arg,
853 arg = LIMIT_TO(arg, 0, lim[ip->i_uid]);
854 divine_unit_change_quiet(unit, ip->i_name, arg != item[ip->i_uid],
855 "from %d to %d", item[ip->i_uid], arg);
856 report_divine_gift(unit->own, ip, arg - item[ip->i_uid],
858 item[ip->i_uid] = arg;
862 limit_item(struct empobj *unit, short item[], short lim[])
866 for (it = I_NONE + 1; it <= I_MAX; it++) {
867 if (item[it] > lim[it])
868 edit_item(unit, item, &ichr[it], item[it], lim);
873 edit_ship(struct shpstr *ship, char *key, char *p)
875 struct mchrstr *mcp = &mchr[ship->shp_type];
886 ret = edit_unit((struct empobj *)ship, key, p,
887 SHIP_MINEFF, "fleet", 0);
890 arg = ef_elt_byname(EF_SHIP_CHR, p);
892 pr("%s: invalid ship type\n", p);
895 divine_unit_change((struct empobj *)ship, "Type",
896 arg != ship->shp_type, 0,
897 "to %s", mchr[arg].m_name);
898 if (ship->shp_tech < mchr[arg].m_tech)
899 shp_set_tech(ship, mchr[arg].m_tech);
900 ship->shp_type = arg;
901 shp_set_tech(ship, ship->shp_tech);
902 limit_item((struct empobj *)ship, ship->shp_item, mchr[arg].m_item);
905 arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
906 divine_unit_change((struct empobj *)ship, "Tech level",
907 arg != ship->shp_tech, arg - ship->shp_tech,
908 "from %d to %d", ship->shp_tech, arg);
909 shp_set_tech(ship, arg);
912 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
913 divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
914 arg != ship->shp_pstage,
915 "from %d to %d", ship->shp_pstage, arg);
916 ship->shp_pstage = arg;
919 arg = LIMIT_TO(arg, 0, 32767);
920 divine_unit_change_quiet((struct empobj *)ship, "Plague time",
921 arg != ship->shp_ptime,
922 "from %d to %d", ship->shp_ptime, arg);
923 ship->shp_ptime = arg;
926 divine_unit_change((struct empobj *)ship, "Retreat path",
927 strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
928 0, "from %s to %.*s",
929 ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
930 strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
933 divine_flag_change((struct empobj *)ship, "Retreat conditions",
934 ship->shp_rflags, arg, retreat_flags);
935 ship->shp_rflags = arg;
950 edit_item((struct empobj *)ship, ship->shp_item, item_by_name(key),
954 pr("huh? (%s)\n", key);
961 edit_land(struct lndstr *land, char *key, char *p)
963 struct lchrstr *lcp = &lchr[land->lnd_type];
973 return edit_unit((struct empobj *)land, key, p,
975 land->lnd_ship >= 0 || land->lnd_land >= 0);
977 arg = ef_elt_byname(EF_LAND_CHR, p);
979 pr("%s: invalid land unit type\n", p);
982 divine_unit_change((struct empobj *)land, "Type",
983 arg != land->lnd_type, 0,
984 "to %s", lchr[arg].l_name);
985 if (land->lnd_tech < lchr[arg].l_tech)
986 lnd_set_tech(land, lchr[arg].l_tech);
987 land->lnd_type = arg;
988 lnd_set_tech(land, land->lnd_tech);
989 limit_item((struct empobj *)land, land->lnd_item, lchr[arg].l_item);
992 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
993 divine_unit_change((struct empobj *)land, "Tech level",
994 arg != land->lnd_tech, arg - land->lnd_tech,
995 "from %d to %d", land->lnd_tech, arg);
996 lnd_set_tech(land, arg);
999 arg = LIMIT_TO(arg, 0, 127);
1000 divine_unit_change((struct empobj *)land, "Fortification",
1001 arg != land->lnd_harden, arg - land->lnd_harden,
1002 "from %d to %d", land->lnd_harden, arg);
1003 land->lnd_harden = arg;
1006 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1008 if (arg == land->lnd_ship) {
1009 pr("Ship of %s unchanged\n", prland(land));
1012 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1014 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1015 land->lnd_land = -1;
1017 divine_load((struct empobj *)land, EF_SHIP, arg);
1018 land->lnd_ship = arg;
1021 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1023 if (arg == land->lnd_land) {
1024 pr("Land unit of %s unchanged\n", prland(land));
1027 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1029 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1030 land->lnd_ship = -1;
1032 divine_load((struct empobj *)land, EF_LAND, arg);
1033 land->lnd_land = arg;
1036 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
1037 divine_unit_change_quiet((struct empobj *)land, "Plague stage",
1038 arg != land->lnd_pstage,
1039 "from %d to %d", land->lnd_pstage, arg);
1040 land->lnd_pstage = arg;
1043 arg = LIMIT_TO(arg, 0, 32767);
1044 divine_unit_change_quiet((struct empobj *)land, "Plague time",
1045 arg != land->lnd_ptime,
1046 "from %d to %d", land->lnd_ptime, arg);
1047 land->lnd_ptime = arg;
1050 arg = LIMIT_TO(arg, 0, 100);
1051 divine_unit_change((struct empobj *)land, "Retreat percentage",
1052 arg != land->lnd_retreat, 0,
1053 "from %d to %d", land->lnd_retreat, arg);
1054 land->lnd_retreat = arg;
1057 divine_unit_change((struct empobj *)land, "Retreat path",
1058 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
1059 0, "from %s to %.*s",
1060 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
1061 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
1064 divine_flag_change((struct empobj *)land, "Retreat condition",
1065 land->lnd_rflags, arg, retreat_flags);
1066 land->lnd_rflags = arg;
1081 edit_item((struct empobj *)land, land->lnd_item, item_by_name(key),
1085 pr("huh? (%s)\n", key);
1092 edit_plane(struct plnstr *plane, char *key, char *p)
1094 struct plchrstr *pcp = &plchr[plane->pln_type];
1104 return edit_unit((struct empobj *)plane, key, p,
1105 PLANE_MINEFF, "wing",
1106 plane->pln_ship >= 0 || plane->pln_land >= 0);
1108 arg = ef_elt_byname(EF_PLANE_CHR, p);
1110 pr("%s: invalid plane type\n", p);
1113 divine_unit_change((struct empobj *)plane, "Type",
1114 arg != plane->pln_type, 0,
1115 "to %s", plchr[arg].pl_name);
1116 if (plane->pln_tech < plchr[arg].pl_tech)
1117 pln_set_tech(plane, plchr[arg].pl_tech);
1118 if (plane->pln_range >= pln_range_max(plane))
1119 /* preserve unlimited range, pln_set_tech() will adjust */
1120 plane->pln_range = UCHAR_MAX;
1121 plane->pln_type = arg;
1122 pln_set_tech(plane, plane->pln_tech);
1125 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1126 divine_unit_change((struct empobj *)plane, "Tech level",
1127 arg != plane->pln_tech, arg - plane->pln_tech,
1128 "from %d to %d", plane->pln_tech, arg);
1129 pln_set_tech(plane, arg);
1132 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1133 divine_unit_change((struct empobj *)plane, "Range",
1134 arg != plane->pln_range, 0,
1135 "from %d to %d", plane->pln_range, arg);
1136 plane->pln_range = (unsigned char)arg;
1139 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1141 if (arg == plane->pln_ship) {
1142 pr("Ship of %s unchanged\n", prplane(plane));
1145 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1147 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1148 plane->pln_land = -1;
1150 divine_load((struct empobj *)plane, EF_SHIP, arg);
1151 plane->pln_ship = arg;
1154 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1156 if (arg == plane->pln_land) {
1157 pr("Land unit of %s unchanged\n", prplane(plane));
1160 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1162 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1163 plane->pln_ship = -1;
1165 divine_load((struct empobj *)plane, EF_LAND, arg);
1166 plane->pln_land = arg;
1169 divine_flag_change((struct empobj *)plane, "Flags",
1170 plane->pln_flags, arg, plane_flags);
1171 plane->pln_flags = arg;
1174 pr("huh? (%s)\n", key);
1181 edit_nuke(struct nukstr *nuke, char *key, char *p)
1183 struct nchrstr *ncp = &nchr[nuke->nuk_type];
1191 return edit_unit((struct empobj *)nuke, key, p,
1192 100, "stockpile", nuke->nuk_plane >= 0);
1194 arg = ef_elt_byname(EF_NUKE_CHR, p);
1196 pr("%s: invalid nuke type\n", p);
1199 divine_unit_change((struct empobj *)nuke, "Type",
1200 arg != nuke->nuk_type, 0,
1201 "to %s", nchr[arg].n_name);
1202 if (nuke->nuk_tech < nchr[arg].n_tech)
1203 nuke->nuk_tech = nchr[arg].n_tech;
1204 nuke->nuk_type = arg;
1207 arg = LIMIT_TO(arg, ncp->n_tech, SHRT_MAX);
1208 divine_unit_change((struct empobj *)nuke, "Tech level",
1209 arg != nuke->nuk_tech, arg - nuke->nuk_tech,
1210 "from %d to %d", nuke->nuk_tech, arg);
1211 nuke->nuk_tech = arg;
1214 if (arg < -1 || arg >= ef_nelem(EF_PLANE))
1216 if (arg == nuke->nuk_plane) {
1217 pr("Plane of %s unchanged\n", prnuke(nuke));
1220 divine_unload((struct empobj *)nuke, EF_PLANE, nuke->nuk_plane);
1221 divine_load((struct empobj *)nuke, EF_PLANE, arg);
1222 nuke->nuk_plane = arg;
1225 pr("huh? (%s)\n", key);