2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * edit.c: Edit things (sectors, ships, planes, units, nukes, countries)
29 * Known contributors to this file:
32 * Steve McClure, 1998-2000
33 * Ron Koenderink, 2003-2009
34 * Markus Armbruster, 2003-2013
52 static void print_sect(struct sctstr *);
53 static void print_nat(struct natstr *);
54 static void print_plane(struct plnstr *);
55 static void print_land(struct lndstr *);
56 static void print_ship(struct shpstr *);
57 static char *getin(char *, char **);
58 static int edit_nat(struct natstr *, char *, char *);
59 static int edit_ship(struct shpstr *, char *, char *);
60 static int edit_land(struct lndstr *, char *, char *);
61 static int edit_plane(struct plnstr *, char *, char *);
80 what = getstarg(player->argp[1],
81 "Edit what (country, land, ship, plane, nuke, unit)? ",
88 if (!(ptr = getstarg(player->argp[2], "Sector : ", buf)))
90 if (!sarg_xy(ptr, &x, &y))
92 if (!getsect(x, y, §))
96 np = natargp(player->argp[2], "Country? ");
101 if ((num = onearg(player->argp[2], "Plane number? ")) < 0)
103 if (!getplane(num, &plane))
107 if ((num = onearg(player->argp[2], "Ship number? ")) < 0)
109 if (!getship(num, &ship))
113 if ((num = onearg(player->argp[2], "Unit number? ")) < 0)
115 if (!getland(num, &land))
119 pr("Not implemented yet.\n");
125 if (!player->argp[3]) {
145 if (player->argp[arg_index]) {
146 if (player->argp[arg_index+1]) {
147 key = player->argp[arg_index++];
148 ptr = player->argp[arg_index++];
151 } else if (arg_index == 3) {
152 key = getin(buf, &ptr);
180 if ((err = edit_nat(np, key, ptr)) != RET_OK)
184 if (!check_sect_ok(§))
186 if ((err = edit_sect(§, key, ptr)) != RET_OK)
192 if (!check_ship_ok(&ship))
194 if ((err = edit_ship(&ship, key, ptr)) != RET_OK)
196 if (!putship(ship.shp_uid, &ship))
200 if (!check_land_ok(&land))
202 if ((err = edit_land(&land, key, ptr)) != RET_OK)
204 if (!putland(land.lnd_uid, &land))
208 if (!check_plane_ok(&plane))
210 if ((err = edit_plane(&plane, key, ptr)) != RET_OK)
212 if (!putplane(plane.pln_uid, &plane))
220 benefit(natid who, int goodness)
222 if (opt_GODNEWS && getnatp(who)->nat_stat != STAT_GOD && goodness)
223 nreport(player->cnum, goodness > 0 ? N_AIDS : N_HURTS, who, 1);
227 noise(struct sctstr *sptr, char *name, int old, int new)
229 divine_sct_change(sptr, name, new != old, new - old,
230 "from %d to %d", old, new);
234 print_sect(struct sctstr *sect)
236 pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
237 pr("Distribution sector <D>: %s\n",
238 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
239 pr("Designation <s>: %c\tNew designation <S>: %c\n",
240 dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
241 pr("own oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
242 pr(" o O e m i g f c u w l x X p t F a\n");
243 pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
244 sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
245 sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
246 sect->sct_uran, sect->sct_work, sect->sct_loyal,
247 sect->sct_che, sect->sct_che_target,
248 sect->sct_pstage, sect->sct_ptime,
249 sect->sct_fallout, sect->sct_avail);
251 pr("Mines <M>: %d\n", sect->sct_mines);
252 pr("Road %% <R>: %d\t", sect->sct_road);
253 pr("Rail %% <r>: %d\t", sect->sct_rail);
254 pr("Defense %% <d>: %d\n", sect->sct_defense);
258 print_nat(struct natstr *np)
262 pr("Country #: %2d\n", np->nat_cnum);
263 pr("Name <n>: %-20s\t", np->nat_cnam);
264 pr("Representative <r>: %-20s\n", np->nat_pnam);
265 pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
266 pr("Reserves <m>: %5d\n", np->nat_reserve);
267 pr("Capital <c>: %s\t\t",
268 xyas(np->nat_xcap, np->nat_ycap, player->cnum));
269 pr("Origin <o>: %3s\n",
270 xyas(np->nat_xorg, np->nat_yorg, player->cnum));
271 pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
272 pr("Seconds Used <u>: %3d\n", np->nat_timeused);
273 pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
274 pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
275 pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
276 pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
277 pr("Money <M>: $%6d\n", np->nat_money);
278 pr("Telegrams <t>: %6d\n", np->nat_tgms);
280 pr("Countries contacted: ");
281 for (i = 0; i < MAXNOC; i++) {
282 if (getcontact(np, i))
283 pr("%d(%d) ", i, getcontact(np, i));
290 print_plane(struct plnstr *plane)
292 pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
293 pr("UID <U>: %d\t\t", plane->pln_uid);
294 pr("Owner <O>: %d\t\t", plane->pln_own);
295 pr("Location <l>: %s\n",
296 xyas(plane->pln_x, plane->pln_y, player->cnum));
297 pr("Efficiency <e>: %d\t", plane->pln_effic);
298 pr("Mobility <m>: %d\n", plane->pln_mobil);
299 pr("Tech <t>: %d\t\t", plane->pln_tech);
300 pr("Wing <w>: %.1s\n", &plane->pln_wing);
301 pr("Range <r>: %d\t\t", plane->pln_range);
302 pr("Flags <f>: %d\n", plane->pln_flags);
303 pr("Ship <s>: %d\t\t", plane->pln_ship);
304 pr("Land Unit <y>: %d\t", plane->pln_land);
308 print_land(struct lndstr *land)
310 pr("%s %s\n", prnatid(land->lnd_own), prland(land));
311 pr("UID <U>: %d\n", land->lnd_uid);
312 pr("Owner <O>: %d\n", land->lnd_own);
313 pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
314 pr("Efficiency <e>: %d\t", land->lnd_effic);
315 pr("Mobility <M>: %d\n", land->lnd_mobil);
316 pr("Tech <t>: %d\t\t", land->lnd_tech);
317 pr("Army <a>: %.1s\n", &land->lnd_army);
318 pr("Fortification <F>: %d\t", land->lnd_harden);
319 pr("Land unit <Y>: %d\n", land->lnd_land);
320 pr("Ship <S>: %d\t\t", land->lnd_ship);
321 pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
322 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
323 land->lnd_rpath, land->lnd_rflags);
324 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
325 pr(" c m u f s g p i d o l h r\n");
326 pr("%3d", land->lnd_item[I_CIVIL]);
327 pr("%4d", land->lnd_item[I_MILIT]);
328 pr("%4d", land->lnd_item[I_UW]);
329 pr("%5d", land->lnd_item[I_FOOD]);
330 pr("%4d", land->lnd_item[I_SHELL]);
331 pr("%4d", land->lnd_item[I_GUN]);
332 pr("%5d", land->lnd_item[I_PETROL]);
333 pr("%5d", land->lnd_item[I_IRON]);
334 pr("%5d", land->lnd_item[I_DUST]);
335 pr("%5d", land->lnd_item[I_OIL]);
336 pr("%5d", land->lnd_item[I_LCM]);
337 pr("%5d", land->lnd_item[I_HCM]);
338 pr("%4d", land->lnd_item[I_RAD]);
343 print_ship(struct shpstr *ship)
345 pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
346 pr("UID <U>: %d\n", ship->shp_uid);
347 pr("Owner <O>: %d\t\t\t", ship->shp_own);
348 pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
349 pr("Tech <T>: %d\t\t\t", ship->shp_tech);
350 pr("Efficiency <E>: %d\n", ship->shp_effic);
351 pr("Mobility <M>: %d\t\t", ship->shp_mobil);
352 pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
353 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
354 ship->shp_rpath, ship->shp_rflags);
355 pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
356 pr("Plague Time <b>: %d\n", ship->shp_ptime);
357 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
358 pr(" c m u f s g p i d o l h r\n");
359 pr("%3d", ship->shp_item[I_CIVIL]);
360 pr("%4d", ship->shp_item[I_MILIT]);
361 pr("%4d", ship->shp_item[I_UW]);
362 pr("%5d", ship->shp_item[I_FOOD]);
363 pr("%4d", ship->shp_item[I_SHELL]);
364 pr("%4d", ship->shp_item[I_GUN]);
365 pr("%5d", ship->shp_item[I_PETROL]);
366 pr("%5d", ship->shp_item[I_IRON]);
367 pr("%5d", ship->shp_item[I_DUST]);
368 pr("%5d", ship->shp_item[I_OIL]);
369 pr("%5d", ship->shp_item[I_LCM]);
370 pr("%5d", ship->shp_item[I_HCM]);
371 pr("%4d", ship->shp_item[I_RAD]);
376 getin(char *buf, char **valp)
383 p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
386 switch (parse(p, buf, argp, NULL, NULL, NULL)) {
397 #if 0 /* not needed right now */
399 warn_deprecated(char key)
401 pr("Key <%c> is deprecated and will go away in a future release\n", key);
406 edit_sect_i(struct sctstr *sect, char *key, int arg)
412 if (arg < 0 || arg >= MAXNOC)
414 divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
416 prnatid(sect->sct_own), prnatid(arg));
417 if (arg == sect->sct_own)
419 report_god_takes("Sector ",
420 xyas(sect->sct_x, sect->sct_y, sect->sct_own),
422 report_god_gives("Sector ",
423 xyas(sect->sct_x, sect->sct_y, arg),
428 if (arg < 0 || arg >= MAXNOC)
430 divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
432 prnatid(sect->sct_oldown), prnatid(arg));
433 sect->sct_oldown = arg;
436 new = LIMIT_TO(arg, 0, 100);
437 noise(sect, "Efficiency", sect->sct_effic, new);
438 sect->sct_effic = new;
441 new = LIMIT_TO(arg, -127, 127);
442 noise(sect, "Mobility", sect->sct_mobil, new);
443 sect->sct_mobil = new;
446 new = LIMIT_TO(arg, 0, 100);
447 noise(sect, "Iron ore content", sect->sct_min, new);
448 sect->sct_min = (unsigned char)new;
451 new = LIMIT_TO(arg, 0, 100);
452 noise(sect, "Gold content", sect->sct_gmin, new);
453 sect->sct_gmin = (unsigned char)new;
456 new = LIMIT_TO(arg, 0, 100);
457 noise(sect, "Fertility", sect->sct_fertil, new);
458 sect->sct_fertil = (unsigned char)new;
461 new = LIMIT_TO(arg, 0, 100);
462 noise(sect, "Oil content", sect->sct_oil, new);
463 sect->sct_oil = (unsigned char)new;
466 new = LIMIT_TO(arg, 0, 100);
467 noise(sect, "Uranium content", sect->sct_uran, new);
468 sect->sct_uran = (unsigned char)new;
471 new = LIMIT_TO(arg, 0, 100);
472 noise(sect, "Workforce percentage", sect->sct_work, new);
473 sect->sct_work = (unsigned char)new;
476 new = LIMIT_TO(arg, 0, 127);
477 divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
478 "from %d to %d", sect->sct_loyal, new);
479 sect->sct_loyal = (unsigned char)new;
482 new = LIMIT_TO(arg, 0, CHE_MAX);
483 divine_sct_change_quiet(sect, "Guerillas", new != sect->sct_che,
484 "from %d to %d", sect->sct_che, new);
488 if (arg < 0 || arg >= MAXNOC)
490 divine_sct_change_quiet(sect, "Che target",
491 arg != sect->sct_che_target,
493 prnatid(sect->sct_che_target),
495 sect->sct_che_target = arg;
500 new = LIMIT_TO(arg, 0, PLG_EXPOSED);
501 divine_sct_change_quiet(sect, "Plague stage",
502 new != sect->sct_pstage,
503 "from %d to %d", sect->sct_pstage, new);
504 sect->sct_pstage = new;
507 new = LIMIT_TO(arg, 0, 32767);
508 divine_sct_change_quiet(sect, "Plague time",
509 new != sect->sct_ptime,
510 "from %d to %d", sect->sct_ptime, new);
511 sect->sct_ptime = new;
514 new = LIMIT_TO(arg, 0, FALLOUT_MAX);
515 noise(sect, "Fallout", sect->sct_fallout, new);
516 sect->sct_fallout = new;
519 new = LIMIT_TO(arg, 0, 9999);
520 noise(sect, "Available workforce", sect->sct_avail, new);
521 sect->sct_avail = new;
524 new = LIMIT_TO(arg, 0, MINES_MAX);
525 if (sect->sct_own == sect->sct_oldown)
526 noise(sect, "Mines", sect->sct_mines, new);
528 divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
529 "from %d to %d", sect->sct_mines, new);
530 sect->sct_mines = new;
533 new = LIMIT_TO(arg, 0, 100);
534 noise(sect, "Road percentage", sect->sct_road, new);
535 sect->sct_road = new;
538 new = LIMIT_TO(arg, 0, 100);
539 noise(sect, "Rail percentage", sect->sct_rail, new);
540 sect->sct_rail = new;
543 new = LIMIT_TO(arg, 0, 100);
544 noise(sect, "Defense percentage", sect->sct_defense, new);
545 sect->sct_defense = new;
548 pr("huh? (%s)\n", key);
555 edit_sect(struct sctstr *sect, char *key, char *p)
559 struct sctstr newsect;
563 if (!sarg_xy(p, &newx, &newy))
565 if (newx == sect->sct_x && newy == sect->sct_y) {
566 pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
569 getsect(newx, newy, &newsect);
570 pr("Sector %s duplicated to %s\n",
571 xyas(sect->sct_x, sect->sct_y, player->cnum),
572 xyas(newx, newy, player->cnum));
573 report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
575 report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
579 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
582 if (!sarg_xy(p, &newx, &newy))
584 divine_sct_change_quiet(sect, "Distribution sector",
585 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
587 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
588 xyas(newx, newy, player->cnum));
589 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
591 if (sect->sct_own && sect->sct_own != player->cnum)
593 "Distribution sector of %s changed from %s to %s"
594 " by an act of %s\n",
595 xyas(sect->sct_x, sect->sct_y, player->cnum),
596 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
597 xyas(newx, newy, player->cnum),
598 cname(player->cnum));
599 sect->sct_dist_x = newx;
600 sect->sct_dist_y = newy;
603 new = sct_typematch(p);
606 divine_sct_change(sect, "Designation",
607 new != sect->sct_type, 0, "from %c to %c",
608 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
609 set_coastal(sect, sect->sct_type, new);
610 sect->sct_type = new;
613 new = sct_typematch(p);
616 divine_sct_change(sect, "New designation",
617 new != sect->sct_newtype, 0, "from %c to %c",
618 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
619 sect->sct_newtype = new;
622 return edit_sect_i(sect, key, atoi(p));
628 edit_level(struct natstr *np, int lvl, char *name, char *p)
630 float new = (float)atof(p);
633 divine_nat_change(np, name,
634 new != np->nat_level[lvl],
635 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
636 "from %.2f to %.2f", np->nat_level[lvl], new);
637 np->nat_level[lvl] = new;
641 edit_nat(struct natstr *np, char *key, char *p)
644 natid nat = np->nat_cnum;
649 if (!check_nat_name(p, nat))
651 pr("Country name changed from %s to %s\n", np->nat_cnam, p);
652 strcpy(np->nat_cnam, p);
655 pr("Country representative changed from %s to %s\n",
657 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
660 arg = LIMIT_TO(arg, 0, USHRT_MAX);
664 arg = LIMIT_TO(arg, 0, max_btus);
665 pr("BTU's changed from %d to %d\n", np->nat_btu, arg);
669 arg = LIMIT_TO(arg, 0, INT_MAX);
670 benefit(nat, arg - np->nat_reserve);
671 pr("Military reserves changed from %d to %d\n",
672 np->nat_reserve, arg);
673 if (arg == np->nat_reserve)
675 if (nat != player->cnum)
677 "Military reserves changed from %d to %d by an act of %s\n",
678 np->nat_reserve, arg, cname(player->cnum));
679 np->nat_reserve = arg;
682 if (!sarg_xy(p, &newx, &newy))
684 pr("Capital coordinates changed from %s to %s\n",
685 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
686 xyas(newx, newy, player->cnum));
691 if (!sarg_xy(p, &newx, &newy))
693 pr("Origin coordinates changed from %s to %s\n",
694 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
695 xyas(newx, newy, player->cnum));
700 np->nat_stat = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
703 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
704 pr("Number of seconds used changed from %d to %d.\n",
705 np->nat_timeused, arg);
706 np->nat_timeused = arg;
709 pr("Money changed from %d to %d\n", np->nat_money, arg);
710 if (arg == np->nat_money)
712 if (nat != player->cnum)
713 wu(0, nat, "Money changed from %d to %d by an act of %s\n",
714 np->nat_money, arg, cname(player->cnum));
718 edit_level(np, NAT_TLEV, "Technology", p);
721 edit_level(np, NAT_RLEV, "Research", p);
724 edit_level(np, NAT_ELEV, "Education", p);
727 edit_level(np, NAT_HLEV, "Happiness", p);
730 pr("huh? (%s)\n", key);
738 edit_unit(struct empobj *unit, char *key, char *p,
739 int mineff, char *group_name, int on_carrier)
743 union empobj_storage newunit;
746 switch (toupper(*key)) {
750 if (arg == unit->uid) {
751 pr("%s unchanged\n", unit_nameof(unit));
754 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
755 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
758 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
759 ef_set_uid(unit->ef_type, unit, arg);
760 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
761 pr("Replacing %s of %s\n",
762 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
763 report_god_takes("", unit_nameof(&newunit.gen),
766 report_god_gives("", unit_nameof(unit), unit->own);
769 if (arg < 0 || arg >= MAXNOC)
771 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
773 prnatid(unit->own), prnatid(arg));
774 if (arg != unit->own) {
775 report_god_takes("", unit_nameof(unit), unit->own);
776 report_god_gives("", unit_nameof(unit), arg);
781 if (!sarg_xy(p, &newx, &newy))
783 if (on_carrier && (newx != unit->x || newy != unit->y)) {
784 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
787 divine_unit_change_quiet(unit, "Location",
788 unit->own && unit->own != player->cnum,
790 xyas(unit->x, unit->y, player->cnum),
791 xyas(newx, newy, player->cnum));
792 if (unit->own && unit->own != player->cnum)
794 "Location of %s changed from %s to %s by an act of %s!\n",
796 xyas(unit->x, unit->y, unit->own),
797 xyas(newx, newy, unit->own),
798 cname(player->cnum));
803 arg = LIMIT_TO(arg, mineff, 100);
804 divine_unit_change(unit, "Efficiency",
805 arg != unit->effic, arg - unit->effic,
806 "from %d to %d", unit->effic, arg);
810 arg = LIMIT_TO(arg, -127, 127);
811 divine_unit_change(unit, "Mobility",
812 arg != unit->mobil, arg - unit->mobil,
813 "from %d to %d", unit->mobil, arg);
821 else if (isalpha(p[0]))
824 pr("%c: invalid %s\n", p[0], group_name);
827 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
828 "from %s %c to %c", group_name,
829 unit->group ? unit->group : '~', p[0]);
830 unit->group = newgroup;
839 edit_ship(struct shpstr *ship, char *key, char *p)
841 struct mchrstr *mcp = &mchr[ship->shp_type];
852 return edit_unit((struct empobj *)ship, key, p,
853 SHIP_MINEFF, "fleet", 0);
855 arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
856 divine_unit_change((struct empobj *)ship, "Tech level",
857 arg != ship->shp_tech, arg - ship->shp_tech,
858 "from %d to %d", ship->shp_tech, arg);
859 shp_set_tech(ship, arg);
862 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
863 divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
864 arg != ship->shp_pstage,
865 "from %d to %d", ship->shp_pstage, arg);
866 ship->shp_pstage = arg;
869 arg = LIMIT_TO(arg, 0, 32767);
870 divine_unit_change_quiet((struct empobj *)ship, "Plague time",
871 arg != ship->shp_ptime,
872 "from %d to %d", ship->shp_ptime, arg);
873 ship->shp_ptime = arg;
876 divine_unit_change((struct empobj *)ship, "Retreat path",
877 strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
878 0, "from %s to %.*s",
879 ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
880 strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
883 divine_flag_change((struct empobj *)ship, "Retreat conditions",
884 ship->shp_rflags, arg, retreat_flags);
885 ship->shp_rflags = arg;
900 ip = item_by_name(key);
901 arg = LIMIT_TO(arg, 0, mchr[ship->shp_type].m_item[ip->i_uid]);
902 divine_unit_change_quiet((struct empobj *)ship, ip->i_name,
903 arg != ship->shp_item[ip->i_uid],
905 ship->shp_item[ip->i_uid], arg);
906 report_divine_gift(ship->shp_own, ip,
907 arg - ship->shp_item[ip->i_uid], prship(ship));
908 ship->shp_item[ip->i_uid] = arg;
911 pr("huh? (%s)\n", key);
918 edit_land(struct lndstr *land, char *key, char *p)
920 struct lchrstr *lcp = &lchr[land->lnd_type];
931 return edit_unit((struct empobj *)land, key, p,
933 land->lnd_ship >= 0 || land->lnd_land >= 0);
935 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
936 divine_unit_change((struct empobj *)land, "Tech level",
937 arg != land->lnd_tech, arg - land->lnd_tech,
938 "from %d to %d", land->lnd_tech, arg);
939 lnd_set_tech(land, arg);
942 arg = LIMIT_TO(arg, 0, 127);
943 divine_unit_change((struct empobj *)land, "Fortification",
944 arg != land->lnd_harden, arg - land->lnd_harden,
945 "from %d to %d", land->lnd_harden, arg);
946 land->lnd_harden = arg;
949 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
951 if (arg == land->lnd_ship) {
952 pr("Ship of %s unchanged\n", prland(land));
955 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
957 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
960 divine_load((struct empobj *)land, EF_SHIP, arg);
961 land->lnd_ship = arg;
964 if (arg < -1 || arg >= ef_nelem(EF_LAND))
966 if (arg == land->lnd_land) {
967 pr("Land unit of %s unchanged\n", prland(land));
970 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
972 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
975 divine_load((struct empobj *)land, EF_LAND, arg);
976 land->lnd_land = arg;
979 arg = LIMIT_TO(arg, 0, 100);
980 divine_unit_change((struct empobj *)land, "Retreat percentage",
981 arg != land->lnd_retreat, 0,
982 "from %d to %d", land->lnd_retreat, arg);
983 land->lnd_retreat = arg;
986 divine_unit_change((struct empobj *)land, "Retreat path",
987 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
988 0, "from %s to %.*s",
989 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
990 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
993 divine_flag_change((struct empobj *)land, "Retreat condition",
994 land->lnd_rflags, arg, retreat_flags);
995 land->lnd_rflags = arg;
1010 ip = item_by_name(key);
1011 arg = LIMIT_TO(arg, 0, lchr[land->lnd_type].l_item[ip->i_uid]);
1012 divine_unit_change_quiet((struct empobj *)land, ip->i_name,
1013 arg != land->lnd_item[ip->i_uid],
1015 land->lnd_item[ip->i_uid], arg);
1016 report_divine_gift(land->lnd_own, ip,
1017 arg - land->lnd_item[ip->i_uid], prland(land));
1018 land->lnd_item[ip->i_uid] = arg;
1021 pr("huh? (%s)\n", key);
1028 edit_plane(struct plnstr *plane, char *key, char *p)
1030 struct plchrstr *pcp = &plchr[plane->pln_type];
1040 return edit_unit((struct empobj *)plane, key, p,
1041 PLANE_MINEFF, "wing",
1042 plane->pln_ship >= 0 || plane->pln_land >= 0);
1044 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1045 divine_unit_change((struct empobj *)plane, "Tech level",
1046 arg != plane->pln_tech, arg - plane->pln_tech,
1047 "from %d to %d", plane->pln_tech, arg);
1048 pln_set_tech(plane, arg);
1051 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1052 divine_unit_change((struct empobj *)plane, "Range",
1053 arg != plane->pln_range, 0,
1054 "from %d to %d", plane->pln_range, arg);
1055 plane->pln_range = (unsigned char)arg;
1058 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1060 if (arg == plane->pln_ship) {
1061 pr("Ship of %s unchanged\n", prplane(plane));
1064 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1066 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1067 plane->pln_land = -1;
1069 divine_load((struct empobj *)plane, EF_SHIP, arg);
1070 plane->pln_ship = arg;
1073 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1075 if (arg == plane->pln_land) {
1076 pr("Land unit of %s unchanged\n", prplane(plane));
1079 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1081 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1082 plane->pln_ship = -1;
1084 divine_load((struct empobj *)plane, EF_LAND, arg);
1085 plane->pln_land = arg;
1088 divine_flag_change((struct empobj *)plane, "Flags",
1089 plane->pln_flags, arg, plane_flags);
1090 plane->pln_flags = arg;
1093 pr("huh? (%s)\n", key);