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 *);
66 union empobj_storage item;
71 int type, arg_index, ret;
74 what = getstarg(player->argp[1],
75 "Edit what (country, land, ship, plane, nuke, unit)? ",
93 pr("Not implemented yet.\n");
103 if (!snxtitem(&ni, type, player->argp[2], NULL))
105 while (nxtitem(&ni, &item)) {
106 if (!player->argp[3]) {
109 print_sect(&item.sect);
112 print_ship(&item.ship);
115 print_plane(&item.plane);
118 print_land(&item.land);
121 print_nat(&item.nat);
130 if (player->argp[arg_index]) {
131 if (player->argp[arg_index+1]) {
132 key = player->argp[arg_index++];
133 ptr = player->argp[arg_index++];
136 } else if (arg_index == 3) {
137 key = getin(buf, &ptr);
145 if (!check_obj_ok(&item.gen))
150 * edit_nat() may update the edited country by sending
151 * it bulletins. Writing back item.nat would trigger
152 * a seqno mismatch oops. Workaround: edit in-place.
154 np = getnatp(item.nat.nat_cnum);
155 ret = edit_nat(np, key, ptr);
163 ret = edit_sect(&item.sect, key, ptr);
166 ret = edit_ship(&item.ship, key, ptr);
169 ret = edit_land(&item.land, key, ptr);
172 ret = edit_plane(&item.plane, key, ptr);
179 if (!put_empobj(type, item.gen.uid, &item.gen))
188 noise(struct sctstr *sptr, char *name, int old, int new)
190 divine_sct_change(sptr, name, new != old, new - old,
191 "from %d to %d", old, new);
195 print_sect(struct sctstr *sect)
197 pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
198 pr("Distribution sector <D>: %s\n",
199 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
200 pr("Designation <s>: %c\tNew designation <S>: %c\n",
201 dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
202 pr("own oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
203 pr(" o O e m i g f c u w l x X p t F a\n");
204 pr("%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %5d %4d %5d\n",
205 sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil,
206 sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil,
207 sect->sct_uran, sect->sct_work, sect->sct_loyal,
208 sect->sct_che, sect->sct_che_target,
209 sect->sct_pstage, sect->sct_ptime,
210 sect->sct_fallout, sect->sct_avail);
212 pr("Mines <M>: %d\n", sect->sct_mines);
213 pr("Road %% <R>: %d\t", sect->sct_road);
214 pr("Rail %% <r>: %d\t", sect->sct_rail);
215 pr("Defense %% <d>: %d\n", sect->sct_defense);
219 print_nat(struct natstr *np)
223 pr("Country #: %2d\n", np->nat_cnum);
224 pr("Name <n>: %-20s\t", np->nat_cnam);
225 pr("Representative <r>: %-20s\n", np->nat_pnam);
226 pr("BTUs <b>: %3d\t\t\t", np->nat_btu);
227 pr("Reserves <m>: %5d\n", np->nat_reserve);
228 pr("Capital <c>: %s\t\t",
229 xyas(np->nat_xcap, np->nat_ycap, player->cnum));
230 pr("Origin <o>: %3s\n",
231 xyas(np->nat_xorg, np->nat_yorg, player->cnum));
232 pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
233 pr("Seconds Used <u>: %3d\n", np->nat_timeused);
234 pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
235 pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
236 pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
237 pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
238 pr("Money <M>: $%6d\n", np->nat_money);
239 pr("Telegrams <t>: %6d\n", np->nat_tgms);
241 pr("Countries contacted: ");
242 for (i = 0; i < MAXNOC; i++) {
243 if (getcontact(np, i))
244 pr("%d(%d) ", i, getcontact(np, i));
251 print_plane(struct plnstr *plane)
253 pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
254 pr("UID <U>: %d\t\t", plane->pln_uid);
255 pr("Owner <O>: %d\t\t", plane->pln_own);
256 pr("Location <l>: %s\n",
257 xyas(plane->pln_x, plane->pln_y, player->cnum));
258 pr("Efficiency <e>: %d\t", plane->pln_effic);
259 pr("Mobility <m>: %d\n", plane->pln_mobil);
260 pr("Tech <t>: %d\t\t", plane->pln_tech);
261 pr("Wing <w>: %.1s\n", &plane->pln_wing);
262 pr("Range <r>: %d\t\t", plane->pln_range);
263 pr("Flags <f>: %d\n", plane->pln_flags);
264 pr("Ship <s>: %d\t\t", plane->pln_ship);
265 pr("Land Unit <y>: %d\t", plane->pln_land);
269 print_land(struct lndstr *land)
271 pr("%s %s\n", prnatid(land->lnd_own), prland(land));
272 pr("UID <U>: %d\n", land->lnd_uid);
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\n", ship->shp_uid);
308 pr("Owner <O>: %d\t\t\t", ship->shp_own);
309 pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
310 pr("Tech <T>: %d\t\t\t", ship->shp_tech);
311 pr("Efficiency <E>: %d\n", ship->shp_effic);
312 pr("Mobility <M>: %d\t\t", ship->shp_mobil);
313 pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
314 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
315 ship->shp_rpath, ship->shp_rflags);
316 pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
317 pr("Plague Time <b>: %d\n", ship->shp_ptime);
318 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
319 pr(" c m u f s g p i d o l h r\n");
320 pr("%3d", ship->shp_item[I_CIVIL]);
321 pr("%4d", ship->shp_item[I_MILIT]);
322 pr("%4d", ship->shp_item[I_UW]);
323 pr("%5d", ship->shp_item[I_FOOD]);
324 pr("%4d", ship->shp_item[I_SHELL]);
325 pr("%4d", ship->shp_item[I_GUN]);
326 pr("%5d", ship->shp_item[I_PETROL]);
327 pr("%5d", ship->shp_item[I_IRON]);
328 pr("%5d", ship->shp_item[I_DUST]);
329 pr("%5d", ship->shp_item[I_OIL]);
330 pr("%5d", ship->shp_item[I_LCM]);
331 pr("%5d", ship->shp_item[I_HCM]);
332 pr("%4d", ship->shp_item[I_RAD]);
337 getin(char *buf, char **valp)
344 p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
347 switch (parse(p, buf, argp, NULL, NULL, NULL)) {
358 #if 0 /* not needed right now */
360 warn_deprecated(char key)
362 pr("Key <%c> is deprecated and will go away in a future release\n", key);
367 edit_sect_i(struct sctstr *sect, char *key, int arg)
373 if (arg < 0 || arg >= MAXNOC)
375 divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
377 prnatid(sect->sct_own), prnatid(arg));
378 if (arg == sect->sct_own)
380 report_god_takes("Sector ",
381 xyas(sect->sct_x, sect->sct_y, sect->sct_own),
383 report_god_gives("Sector ",
384 xyas(sect->sct_x, sect->sct_y, arg),
389 if (arg < 0 || arg >= MAXNOC)
391 divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
393 prnatid(sect->sct_oldown), prnatid(arg));
394 sect->sct_oldown = arg;
397 new = LIMIT_TO(arg, 0, 100);
398 noise(sect, "Efficiency", sect->sct_effic, new);
399 sect->sct_effic = new;
402 new = LIMIT_TO(arg, -127, 127);
403 noise(sect, "Mobility", sect->sct_mobil, new);
404 sect->sct_mobil = new;
407 new = LIMIT_TO(arg, 0, 100);
408 noise(sect, "Iron ore content", sect->sct_min, new);
409 sect->sct_min = (unsigned char)new;
412 new = LIMIT_TO(arg, 0, 100);
413 noise(sect, "Gold content", sect->sct_gmin, new);
414 sect->sct_gmin = (unsigned char)new;
417 new = LIMIT_TO(arg, 0, 100);
418 noise(sect, "Fertility", sect->sct_fertil, new);
419 sect->sct_fertil = (unsigned char)new;
422 new = LIMIT_TO(arg, 0, 100);
423 noise(sect, "Oil content", sect->sct_oil, new);
424 sect->sct_oil = (unsigned char)new;
427 new = LIMIT_TO(arg, 0, 100);
428 noise(sect, "Uranium content", sect->sct_uran, new);
429 sect->sct_uran = (unsigned char)new;
432 new = LIMIT_TO(arg, 0, 100);
433 noise(sect, "Workforce percentage", sect->sct_work, new);
434 sect->sct_work = (unsigned char)new;
437 new = LIMIT_TO(arg, 0, 127);
438 divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
439 "from %d to %d", sect->sct_loyal, new);
440 sect->sct_loyal = (unsigned char)new;
443 new = LIMIT_TO(arg, 0, CHE_MAX);
444 divine_sct_change_quiet(sect, "Guerillas", new != sect->sct_che,
445 "from %d to %d", sect->sct_che, new);
449 if (arg < 0 || arg >= MAXNOC)
451 divine_sct_change_quiet(sect, "Che target",
452 arg != sect->sct_che_target,
454 prnatid(sect->sct_che_target),
456 sect->sct_che_target = arg;
461 new = LIMIT_TO(arg, 0, PLG_EXPOSED);
462 divine_sct_change_quiet(sect, "Plague stage",
463 new != sect->sct_pstage,
464 "from %d to %d", sect->sct_pstage, new);
465 sect->sct_pstage = new;
468 new = LIMIT_TO(arg, 0, 32767);
469 divine_sct_change_quiet(sect, "Plague time",
470 new != sect->sct_ptime,
471 "from %d to %d", sect->sct_ptime, new);
472 sect->sct_ptime = new;
475 new = LIMIT_TO(arg, 0, FALLOUT_MAX);
476 noise(sect, "Fallout", sect->sct_fallout, new);
477 sect->sct_fallout = new;
480 new = LIMIT_TO(arg, 0, 9999);
481 noise(sect, "Available workforce", sect->sct_avail, new);
482 sect->sct_avail = new;
485 new = LIMIT_TO(arg, 0, MINES_MAX);
486 if (sect->sct_own == sect->sct_oldown)
487 noise(sect, "Mines", sect->sct_mines, new);
489 divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
490 "from %d to %d", sect->sct_mines, new);
491 sect->sct_mines = new;
494 new = LIMIT_TO(arg, 0, 100);
495 noise(sect, "Road percentage", sect->sct_road, new);
496 sect->sct_road = new;
499 new = LIMIT_TO(arg, 0, 100);
500 noise(sect, "Rail percentage", sect->sct_rail, new);
501 sect->sct_rail = new;
504 new = LIMIT_TO(arg, 0, 100);
505 noise(sect, "Defense percentage", sect->sct_defense, new);
506 sect->sct_defense = new;
509 pr("huh? (%s)\n", key);
516 edit_sect(struct sctstr *sect, char *key, char *p)
520 struct sctstr newsect;
524 if (!sarg_xy(p, &newx, &newy))
526 if (newx == sect->sct_x && newy == sect->sct_y) {
527 pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
530 getsect(newx, newy, &newsect);
531 pr("Sector %s duplicated to %s\n",
532 xyas(sect->sct_x, sect->sct_y, player->cnum),
533 xyas(newx, newy, player->cnum));
534 report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
536 report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
540 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
543 if (!sarg_xy(p, &newx, &newy))
545 divine_sct_change_quiet(sect, "Distribution sector",
546 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
548 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
549 xyas(newx, newy, player->cnum));
550 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
552 if (sect->sct_own && sect->sct_own != player->cnum)
554 "Distribution sector of %s changed from %s to %s"
555 " by an act of %s\n",
556 xyas(sect->sct_x, sect->sct_y, player->cnum),
557 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
558 xyas(newx, newy, player->cnum),
559 cname(player->cnum));
560 sect->sct_dist_x = newx;
561 sect->sct_dist_y = newy;
564 new = sct_typematch(p);
567 divine_sct_change(sect, "Designation",
568 new != sect->sct_type, 0, "from %c to %c",
569 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
570 set_coastal(sect, sect->sct_type, new);
571 sect->sct_type = new;
574 new = sct_typematch(p);
577 divine_sct_change(sect, "New designation",
578 new != sect->sct_newtype, 0, "from %c to %c",
579 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
580 sect->sct_newtype = new;
583 return edit_sect_i(sect, key, atoi(p));
589 edit_level(struct natstr *np, int lvl, char *name, char *p)
591 float new = (float)atof(p);
594 divine_nat_change(np, name,
595 new != np->nat_level[lvl],
596 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
597 "from %.2f to %.2f", np->nat_level[lvl], new);
598 np->nat_level[lvl] = new;
602 edit_nat(struct natstr *np, char *key, char *p)
605 natid nat = np->nat_cnum;
610 if (!check_nat_name(p, nat))
612 divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
613 "from %s to %s", np->nat_cnam, p);
615 nreport(player->cnum, N_NAME_CHNG, 0, 1);
616 strcpy(np->nat_cnam, p);
619 divine_nat_change(np, "Country representative",
620 strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
622 np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
623 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
626 arg = LIMIT_TO(arg, 0, USHRT_MAX);
627 divine_nat_change_quiet(np, "Number of unread telegrams",
629 "from %d to %d", np->nat_tgms, arg);
633 arg = LIMIT_TO(arg, 0, max_btus);
634 divine_nat_change(np, "BTUs",
635 arg != np->nat_btu, arg - np->nat_btu,
636 "from %d to %d", np->nat_btu, arg);
640 arg = LIMIT_TO(arg, 0, INT_MAX);
641 divine_nat_change(np, "Military reserves",
642 arg != np->nat_reserve, arg - np->nat_reserve,
643 "from %d to %d", np->nat_reserve, arg);
644 np->nat_reserve = arg;
647 if (!sarg_xy(p, &newx, &newy))
649 if (newx == np->nat_xcap && newy == np->nat_ycap)
650 pr("Capital unchanged\n");
652 pr("Capital moved from %s to %s\n",
653 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
654 xyas(newx, newy, player->cnum));
655 if (nat != player->cnum)
657 "Capital moved from %s to %s by an act of %s!\n",
658 xyas(np->nat_xcap, np->nat_ycap, nat),
659 xyas(newx, newy, nat), cname(player->cnum));
665 if (!sarg_xy(p, &newx, &newy))
667 if (newx == np->nat_xorg && newy == np->nat_yorg)
668 pr("Origin unchanged\n");
670 pr("Origin moved from %s to %s\n",
671 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
672 xyas(newx, newy, player->cnum));
673 if (nat != player->cnum)
675 "Origin moved from %s to %s by an act of %s!\n",
676 xyas(np->nat_xorg, np->nat_yorg, nat),
677 xyas(newx, newy, nat), cname(player->cnum));
683 arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
684 divine_nat_change(np, "Status",
685 (enum nat_status)arg != np->nat_stat,
686 0, "to %s", nation_status[arg].name);
690 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
691 divine_nat_change(np, "Number of seconds used",
692 arg != np->nat_timeused, arg - np->nat_timeused,
693 "from %d to %d", np->nat_timeused, arg);
694 np->nat_timeused = arg;
697 divine_nat_change(np, "Money",
698 arg != np->nat_money, arg - np->nat_money,
699 "from %d to %d", np->nat_money, arg);
703 edit_level(np, NAT_TLEV, "Technology", p);
706 edit_level(np, NAT_RLEV, "Research", p);
709 edit_level(np, NAT_ELEV, "Education", p);
712 edit_level(np, NAT_HLEV, "Happiness", p);
715 pr("huh? (%s)\n", key);
722 edit_unit(struct empobj *unit, char *key, char *p,
723 int mineff, char *group_name, int on_carrier)
727 union empobj_storage newunit;
730 switch (toupper(*key)) {
734 if (arg == unit->uid) {
735 pr("%s unchanged\n", unit_nameof(unit));
738 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
739 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
742 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
743 ef_set_uid(unit->ef_type, unit, arg);
744 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
745 pr("Replacing %s of %s\n",
746 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
747 report_god_takes("", unit_nameof(&newunit.gen),
750 report_god_gives("", unit_nameof(unit), unit->own);
753 if (arg < 0 || arg >= MAXNOC)
755 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
757 prnatid(unit->own), prnatid(arg));
758 if (arg != unit->own) {
759 report_god_takes("", unit_nameof(unit), unit->own);
760 report_god_gives("", unit_nameof(unit), arg);
765 if (!sarg_xy(p, &newx, &newy))
767 if (on_carrier && (newx != unit->x || newy != unit->y)) {
768 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
771 divine_unit_change_quiet(unit, "Location",
772 unit->own && unit->own != player->cnum,
774 xyas(unit->x, unit->y, player->cnum),
775 xyas(newx, newy, player->cnum));
776 if (unit->own && unit->own != player->cnum)
778 "Location of %s changed from %s to %s by an act of %s!\n",
780 xyas(unit->x, unit->y, unit->own),
781 xyas(newx, newy, unit->own),
782 cname(player->cnum));
787 arg = LIMIT_TO(arg, mineff, 100);
788 divine_unit_change(unit, "Efficiency",
789 arg != unit->effic, arg - unit->effic,
790 "from %d to %d", unit->effic, arg);
794 arg = LIMIT_TO(arg, -127, 127);
795 divine_unit_change(unit, "Mobility",
796 arg != unit->mobil, arg - unit->mobil,
797 "from %d to %d", unit->mobil, arg);
805 else if (isalpha(p[0]))
808 pr("%c: invalid %s\n", p[0], group_name);
811 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
812 "from %s %c to %c", group_name,
813 unit->group ? unit->group : '~', p[0]);
814 unit->group = newgroup;
823 edit_ship(struct shpstr *ship, char *key, char *p)
825 struct mchrstr *mcp = &mchr[ship->shp_type];
836 return edit_unit((struct empobj *)ship, key, p,
837 SHIP_MINEFF, "fleet", 0);
839 arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
840 divine_unit_change((struct empobj *)ship, "Tech level",
841 arg != ship->shp_tech, arg - ship->shp_tech,
842 "from %d to %d", ship->shp_tech, arg);
843 shp_set_tech(ship, arg);
846 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
847 divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
848 arg != ship->shp_pstage,
849 "from %d to %d", ship->shp_pstage, arg);
850 ship->shp_pstage = arg;
853 arg = LIMIT_TO(arg, 0, 32767);
854 divine_unit_change_quiet((struct empobj *)ship, "Plague time",
855 arg != ship->shp_ptime,
856 "from %d to %d", ship->shp_ptime, arg);
857 ship->shp_ptime = arg;
860 divine_unit_change((struct empobj *)ship, "Retreat path",
861 strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
862 0, "from %s to %.*s",
863 ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
864 strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
867 divine_flag_change((struct empobj *)ship, "Retreat conditions",
868 ship->shp_rflags, arg, retreat_flags);
869 ship->shp_rflags = arg;
884 ip = item_by_name(key);
885 arg = LIMIT_TO(arg, 0, mchr[ship->shp_type].m_item[ip->i_uid]);
886 divine_unit_change_quiet((struct empobj *)ship, ip->i_name,
887 arg != ship->shp_item[ip->i_uid],
889 ship->shp_item[ip->i_uid], arg);
890 report_divine_gift(ship->shp_own, ip,
891 arg - ship->shp_item[ip->i_uid], prship(ship));
892 ship->shp_item[ip->i_uid] = arg;
895 pr("huh? (%s)\n", key);
902 edit_land(struct lndstr *land, char *key, char *p)
904 struct lchrstr *lcp = &lchr[land->lnd_type];
915 return edit_unit((struct empobj *)land, key, p,
917 land->lnd_ship >= 0 || land->lnd_land >= 0);
919 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
920 divine_unit_change((struct empobj *)land, "Tech level",
921 arg != land->lnd_tech, arg - land->lnd_tech,
922 "from %d to %d", land->lnd_tech, arg);
923 lnd_set_tech(land, arg);
926 arg = LIMIT_TO(arg, 0, 127);
927 divine_unit_change((struct empobj *)land, "Fortification",
928 arg != land->lnd_harden, arg - land->lnd_harden,
929 "from %d to %d", land->lnd_harden, arg);
930 land->lnd_harden = arg;
933 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
935 if (arg == land->lnd_ship) {
936 pr("Ship of %s unchanged\n", prland(land));
939 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
941 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
944 divine_load((struct empobj *)land, EF_SHIP, arg);
945 land->lnd_ship = arg;
948 if (arg < -1 || arg >= ef_nelem(EF_LAND))
950 if (arg == land->lnd_land) {
951 pr("Land unit of %s unchanged\n", prland(land));
954 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
956 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
959 divine_load((struct empobj *)land, EF_LAND, arg);
960 land->lnd_land = arg;
963 arg = LIMIT_TO(arg, 0, 100);
964 divine_unit_change((struct empobj *)land, "Retreat percentage",
965 arg != land->lnd_retreat, 0,
966 "from %d to %d", land->lnd_retreat, arg);
967 land->lnd_retreat = arg;
970 divine_unit_change((struct empobj *)land, "Retreat path",
971 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
972 0, "from %s to %.*s",
973 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
974 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
977 divine_flag_change((struct empobj *)land, "Retreat condition",
978 land->lnd_rflags, arg, retreat_flags);
979 land->lnd_rflags = arg;
994 ip = item_by_name(key);
995 arg = LIMIT_TO(arg, 0, lchr[land->lnd_type].l_item[ip->i_uid]);
996 divine_unit_change_quiet((struct empobj *)land, ip->i_name,
997 arg != land->lnd_item[ip->i_uid],
999 land->lnd_item[ip->i_uid], arg);
1000 report_divine_gift(land->lnd_own, ip,
1001 arg - land->lnd_item[ip->i_uid], prland(land));
1002 land->lnd_item[ip->i_uid] = arg;
1005 pr("huh? (%s)\n", key);
1012 edit_plane(struct plnstr *plane, char *key, char *p)
1014 struct plchrstr *pcp = &plchr[plane->pln_type];
1024 return edit_unit((struct empobj *)plane, key, p,
1025 PLANE_MINEFF, "wing",
1026 plane->pln_ship >= 0 || plane->pln_land >= 0);
1028 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1029 divine_unit_change((struct empobj *)plane, "Tech level",
1030 arg != plane->pln_tech, arg - plane->pln_tech,
1031 "from %d to %d", plane->pln_tech, arg);
1032 pln_set_tech(plane, arg);
1035 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1036 divine_unit_change((struct empobj *)plane, "Range",
1037 arg != plane->pln_range, 0,
1038 "from %d to %d", plane->pln_range, arg);
1039 plane->pln_range = (unsigned char)arg;
1042 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1044 if (arg == plane->pln_ship) {
1045 pr("Ship of %s unchanged\n", prplane(plane));
1048 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1050 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1051 plane->pln_land = -1;
1053 divine_load((struct empobj *)plane, EF_SHIP, arg);
1054 plane->pln_ship = arg;
1057 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1059 if (arg == plane->pln_land) {
1060 pr("Land unit of %s unchanged\n", prplane(plane));
1063 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1065 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1066 plane->pln_ship = -1;
1068 divine_load((struct empobj *)plane, EF_LAND, arg);
1069 plane->pln_land = arg;
1072 divine_flag_change((struct empobj *)plane, "Flags",
1073 plane->pln_flags, arg, plane_flags);
1074 plane->pln_flags = arg;
1077 pr("huh? (%s)\n", key);