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("Type <T>: %s\n", plchr[plane->pln_type].pl_name);
256 pr("Owner <O>: %d\t\t", plane->pln_own);
257 pr("Location <l>: %s\n",
258 xyas(plane->pln_x, plane->pln_y, player->cnum));
259 pr("Efficiency <e>: %d\t", plane->pln_effic);
260 pr("Mobility <m>: %d\n", plane->pln_mobil);
261 pr("Tech <t>: %d\t\t", plane->pln_tech);
262 pr("Wing <w>: %.1s\n", &plane->pln_wing);
263 pr("Range <r>: %d\t\t", plane->pln_range);
264 pr("Flags <f>: %d\n", plane->pln_flags);
265 pr("Ship <s>: %d\t\t", plane->pln_ship);
266 pr("Land Unit <y>: %d\n", plane->pln_land);
270 print_land(struct lndstr *land)
272 pr("%s %s\n", prnatid(land->lnd_own), prland(land));
273 pr("UID <U>: %d\t\t", land->lnd_uid);
274 pr("Type <T>: %s\n", lchr[land->lnd_type].l_name);
275 pr("Owner <O>: %d\n", land->lnd_own);
276 pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
277 pr("Efficiency <e>: %d\t", land->lnd_effic);
278 pr("Mobility <M>: %d\n", land->lnd_mobil);
279 pr("Tech <t>: %d\t\t", land->lnd_tech);
280 pr("Army <a>: %.1s\n", &land->lnd_army);
281 pr("Fortification <F>: %d\t", land->lnd_harden);
282 pr("Land unit <Y>: %d\n", land->lnd_land);
283 pr("Ship <S>: %d\t\t", land->lnd_ship);
284 pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
285 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
286 land->lnd_rpath, land->lnd_rflags);
287 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
288 pr(" c m u f s g p i d o l h r\n");
289 pr("%3d", land->lnd_item[I_CIVIL]);
290 pr("%4d", land->lnd_item[I_MILIT]);
291 pr("%4d", land->lnd_item[I_UW]);
292 pr("%5d", land->lnd_item[I_FOOD]);
293 pr("%4d", land->lnd_item[I_SHELL]);
294 pr("%4d", land->lnd_item[I_GUN]);
295 pr("%5d", land->lnd_item[I_PETROL]);
296 pr("%5d", land->lnd_item[I_IRON]);
297 pr("%5d", land->lnd_item[I_DUST]);
298 pr("%5d", land->lnd_item[I_OIL]);
299 pr("%5d", land->lnd_item[I_LCM]);
300 pr("%5d", land->lnd_item[I_HCM]);
301 pr("%4d", land->lnd_item[I_RAD]);
306 print_ship(struct shpstr *ship)
308 pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
309 pr("UID <U>: %d\t\t\t", ship->shp_uid);
310 pr("Type <t>: %s\n", mchr[ship->shp_type].m_name);
311 pr("Owner <O>: %d\t\t\t", ship->shp_own);
312 pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
313 pr("Tech <T>: %d\t\t\t", ship->shp_tech);
314 pr("Efficiency <E>: %d\n", ship->shp_effic);
315 pr("Mobility <M>: %d\t\t", ship->shp_mobil);
316 pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
317 pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
318 ship->shp_rpath, ship->shp_rflags);
319 pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
320 pr("Plague Time <b>: %d\n", ship->shp_ptime);
321 pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n");
322 pr(" c m u f s g p i d o l h r\n");
323 pr("%3d", ship->shp_item[I_CIVIL]);
324 pr("%4d", ship->shp_item[I_MILIT]);
325 pr("%4d", ship->shp_item[I_UW]);
326 pr("%5d", ship->shp_item[I_FOOD]);
327 pr("%4d", ship->shp_item[I_SHELL]);
328 pr("%4d", ship->shp_item[I_GUN]);
329 pr("%5d", ship->shp_item[I_PETROL]);
330 pr("%5d", ship->shp_item[I_IRON]);
331 pr("%5d", ship->shp_item[I_DUST]);
332 pr("%5d", ship->shp_item[I_OIL]);
333 pr("%5d", ship->shp_item[I_LCM]);
334 pr("%5d", ship->shp_item[I_HCM]);
335 pr("%4d", ship->shp_item[I_RAD]);
340 getin(char *buf, char **valp)
347 p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
350 switch (parse(p, buf, argp, NULL, NULL, NULL)) {
361 #if 0 /* not needed right now */
363 warn_deprecated(char key)
365 pr("Key <%c> is deprecated and will go away in a future release\n", key);
370 edit_sect_i(struct sctstr *sect, char *key, int arg)
376 if (arg < 0 || arg >= MAXNOC)
378 divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
380 prnatid(sect->sct_own), prnatid(arg));
381 if (arg == sect->sct_own)
383 report_god_takes("Sector ",
384 xyas(sect->sct_x, sect->sct_y, sect->sct_own),
386 report_god_gives("Sector ",
387 xyas(sect->sct_x, sect->sct_y, arg),
392 if (arg < 0 || arg >= MAXNOC)
394 divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
396 prnatid(sect->sct_oldown), prnatid(arg));
397 sect->sct_oldown = arg;
400 new = LIMIT_TO(arg, 0, 100);
401 noise(sect, "Efficiency", sect->sct_effic, new);
402 sect->sct_effic = new;
405 new = LIMIT_TO(arg, -127, 127);
406 noise(sect, "Mobility", sect->sct_mobil, new);
407 sect->sct_mobil = new;
410 new = LIMIT_TO(arg, 0, 100);
411 noise(sect, "Iron ore content", sect->sct_min, new);
412 sect->sct_min = (unsigned char)new;
415 new = LIMIT_TO(arg, 0, 100);
416 noise(sect, "Gold content", sect->sct_gmin, new);
417 sect->sct_gmin = (unsigned char)new;
420 new = LIMIT_TO(arg, 0, 100);
421 noise(sect, "Fertility", sect->sct_fertil, new);
422 sect->sct_fertil = (unsigned char)new;
425 new = LIMIT_TO(arg, 0, 100);
426 noise(sect, "Oil content", sect->sct_oil, new);
427 sect->sct_oil = (unsigned char)new;
430 new = LIMIT_TO(arg, 0, 100);
431 noise(sect, "Uranium content", sect->sct_uran, new);
432 sect->sct_uran = (unsigned char)new;
435 new = LIMIT_TO(arg, 0, 100);
436 noise(sect, "Workforce percentage", sect->sct_work, new);
437 sect->sct_work = (unsigned char)new;
440 new = LIMIT_TO(arg, 0, 127);
441 divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
442 "from %d to %d", sect->sct_loyal, new);
443 sect->sct_loyal = (unsigned char)new;
446 new = LIMIT_TO(arg, 0, CHE_MAX);
447 divine_sct_change_quiet(sect, "Guerillas", new != sect->sct_che,
448 "from %d to %d", sect->sct_che, new);
452 if (arg < 0 || arg >= MAXNOC)
454 divine_sct_change_quiet(sect, "Che target",
455 arg != sect->sct_che_target,
457 prnatid(sect->sct_che_target),
459 sect->sct_che_target = arg;
464 new = LIMIT_TO(arg, 0, PLG_EXPOSED);
465 divine_sct_change_quiet(sect, "Plague stage",
466 new != sect->sct_pstage,
467 "from %d to %d", sect->sct_pstage, new);
468 sect->sct_pstage = new;
471 new = LIMIT_TO(arg, 0, 32767);
472 divine_sct_change_quiet(sect, "Plague time",
473 new != sect->sct_ptime,
474 "from %d to %d", sect->sct_ptime, new);
475 sect->sct_ptime = new;
478 new = LIMIT_TO(arg, 0, FALLOUT_MAX);
479 noise(sect, "Fallout", sect->sct_fallout, new);
480 sect->sct_fallout = new;
483 new = LIMIT_TO(arg, 0, 9999);
484 noise(sect, "Available workforce", sect->sct_avail, new);
485 sect->sct_avail = new;
488 new = LIMIT_TO(arg, 0, MINES_MAX);
489 if (sect->sct_own == sect->sct_oldown)
490 noise(sect, "Mines", sect->sct_mines, new);
492 divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
493 "from %d to %d", sect->sct_mines, new);
494 sect->sct_mines = new;
497 new = LIMIT_TO(arg, 0, 100);
498 noise(sect, "Road percentage", sect->sct_road, new);
499 sect->sct_road = new;
502 new = LIMIT_TO(arg, 0, 100);
503 noise(sect, "Rail percentage", sect->sct_rail, new);
504 sect->sct_rail = new;
507 new = LIMIT_TO(arg, 0, 100);
508 noise(sect, "Defense percentage", sect->sct_defense, new);
509 sect->sct_defense = new;
512 pr("huh? (%s)\n", key);
519 edit_sect(struct sctstr *sect, char *key, char *p)
523 struct sctstr newsect;
527 if (!sarg_xy(p, &newx, &newy))
529 if (newx == sect->sct_x && newy == sect->sct_y) {
530 pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
533 getsect(newx, newy, &newsect);
534 pr("Sector %s duplicated to %s\n",
535 xyas(sect->sct_x, sect->sct_y, player->cnum),
536 xyas(newx, newy, player->cnum));
537 report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
539 report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
543 ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
546 if (!sarg_xy(p, &newx, &newy))
548 divine_sct_change_quiet(sect, "Distribution sector",
549 newx != sect->sct_dist_x || newy != sect->sct_dist_y,
551 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
552 xyas(newx, newy, player->cnum));
553 if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
555 if (sect->sct_own && sect->sct_own != player->cnum)
557 "Distribution sector of %s changed from %s to %s"
558 " by an act of %s\n",
559 xyas(sect->sct_x, sect->sct_y, player->cnum),
560 xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
561 xyas(newx, newy, player->cnum),
562 cname(player->cnum));
563 sect->sct_dist_x = newx;
564 sect->sct_dist_y = newy;
567 new = sct_typematch(p);
570 divine_sct_change(sect, "Designation",
571 new != sect->sct_type, 0, "from %c to %c",
572 dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
573 set_coastal(sect, sect->sct_type, new);
574 sect->sct_type = new;
577 new = sct_typematch(p);
580 divine_sct_change(sect, "New designation",
581 new != sect->sct_newtype, 0, "from %c to %c",
582 dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
583 sect->sct_newtype = new;
586 return edit_sect_i(sect, key, atoi(p));
592 edit_level(struct natstr *np, int lvl, char *name, char *p)
594 float new = (float)atof(p);
597 divine_nat_change(np, name,
598 new != np->nat_level[lvl],
599 (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
600 "from %.2f to %.2f", np->nat_level[lvl], new);
601 np->nat_level[lvl] = new;
605 edit_nat(struct natstr *np, char *key, char *p)
608 natid nat = np->nat_cnum;
613 if (!check_nat_name(p, nat))
615 divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
616 "from %s to %s", np->nat_cnam, p);
618 nreport(player->cnum, N_NAME_CHNG, 0, 1);
619 strcpy(np->nat_cnam, p);
622 divine_nat_change(np, "Country representative",
623 strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
625 np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
626 strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
629 arg = LIMIT_TO(arg, 0, USHRT_MAX);
630 divine_nat_change_quiet(np, "Number of unread telegrams",
632 "from %d to %d", np->nat_tgms, arg);
636 arg = LIMIT_TO(arg, 0, max_btus);
637 divine_nat_change(np, "BTUs",
638 arg != np->nat_btu, arg - np->nat_btu,
639 "from %d to %d", np->nat_btu, arg);
643 arg = LIMIT_TO(arg, 0, INT_MAX);
644 divine_nat_change(np, "Military reserves",
645 arg != np->nat_reserve, arg - np->nat_reserve,
646 "from %d to %d", np->nat_reserve, arg);
647 np->nat_reserve = arg;
650 if (!sarg_xy(p, &newx, &newy))
652 if (newx == np->nat_xcap && newy == np->nat_ycap)
653 pr("Capital unchanged\n");
655 pr("Capital moved from %s to %s\n",
656 xyas(np->nat_xcap, np->nat_ycap, player->cnum),
657 xyas(newx, newy, player->cnum));
658 if (nat != player->cnum)
660 "Capital moved from %s to %s by an act of %s!\n",
661 xyas(np->nat_xcap, np->nat_ycap, nat),
662 xyas(newx, newy, nat), cname(player->cnum));
668 if (!sarg_xy(p, &newx, &newy))
670 if (newx == np->nat_xorg && newy == np->nat_yorg)
671 pr("Origin unchanged\n");
673 pr("Origin moved from %s to %s\n",
674 xyas(np->nat_xorg, np->nat_yorg, player->cnum),
675 xyas(newx, newy, player->cnum));
676 if (nat != player->cnum)
678 "Origin moved from %s to %s by an act of %s!\n",
679 xyas(np->nat_xorg, np->nat_yorg, nat),
680 xyas(newx, newy, nat), cname(player->cnum));
686 arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
687 divine_nat_change(np, "Status",
688 (enum nat_status)arg != np->nat_stat,
689 0, "to %s", nation_status[arg].name);
693 arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
694 divine_nat_change(np, "Number of seconds used",
695 arg != np->nat_timeused, arg - np->nat_timeused,
696 "from %d to %d", np->nat_timeused, arg);
697 np->nat_timeused = arg;
700 divine_nat_change(np, "Money",
701 arg != np->nat_money, arg - np->nat_money,
702 "from %d to %d", np->nat_money, arg);
706 edit_level(np, NAT_TLEV, "Technology", p);
709 edit_level(np, NAT_RLEV, "Research", p);
712 edit_level(np, NAT_ELEV, "Education", p);
715 edit_level(np, NAT_HLEV, "Happiness", p);
718 pr("huh? (%s)\n", key);
725 edit_unit(struct empobj *unit, char *key, char *p,
726 int mineff, char *group_name, int on_carrier)
730 union empobj_storage newunit;
733 switch (toupper(*key)) {
737 if (arg == unit->uid) {
738 pr("%s unchanged\n", unit_nameof(unit));
741 if (!ef_ensure_space(unit->ef_type, arg, 50)) {
742 pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
745 pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
746 ef_set_uid(unit->ef_type, unit, arg);
747 if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
748 pr("Replacing %s of %s\n",
749 unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
750 report_god_takes("", unit_nameof(&newunit.gen),
753 report_god_gives("", unit_nameof(unit), unit->own);
756 if (arg < 0 || arg >= MAXNOC)
758 divine_unit_change_quiet(unit, "Owner", arg != unit->own,
760 prnatid(unit->own), prnatid(arg));
761 if (arg != unit->own) {
762 report_god_takes("", unit_nameof(unit), unit->own);
763 report_god_gives("", unit_nameof(unit), arg);
765 if (arg && unit->effic < mineff) {
766 divine_unit_change_quiet(unit, "Efficiency", 1,
767 "from %d to %d", unit->effic, mineff);
768 unit->effic = mineff;
773 if (!sarg_xy(p, &newx, &newy))
775 if (on_carrier && (newx != unit->x || newy != unit->y)) {
776 pr("Can't move %s while it's loaded\n", unit_nameof(unit));
779 divine_unit_change_quiet(unit, "Location",
780 unit->own && unit->own != player->cnum,
782 xyas(unit->x, unit->y, player->cnum),
783 xyas(newx, newy, player->cnum));
784 if (unit->own && unit->own != player->cnum)
786 "Location of %s changed from %s to %s by an act of %s!\n",
788 xyas(unit->x, unit->y, unit->own),
789 xyas(newx, newy, unit->own),
790 cname(player->cnum));
795 arg = LIMIT_TO(arg, mineff, 100);
796 divine_unit_change(unit, "Efficiency",
797 arg != unit->effic, arg - unit->effic,
798 "from %d to %d", unit->effic, arg);
802 arg = LIMIT_TO(arg, -127, 127);
803 divine_unit_change(unit, "Mobility",
804 arg != unit->mobil, arg - unit->mobil,
805 "from %d to %d", unit->mobil, arg);
813 else if (isalpha(p[0]))
816 pr("%c: invalid %s\n", p[0], group_name);
819 divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
820 "from %s %c to %c", group_name,
821 unit->group ? unit->group : '~', p[0]);
822 unit->group = newgroup;
831 edit_item(struct empobj *unit, short item[], struct ichrstr *ip, int arg,
834 arg = LIMIT_TO(arg, 0, lim[ip->i_uid]);
835 divine_unit_change_quiet(unit, ip->i_name, arg != item[ip->i_uid],
836 "from %d to %d", item[ip->i_uid], arg);
837 report_divine_gift(unit->own, ip, arg - item[ip->i_uid],
839 item[ip->i_uid] = arg;
843 limit_item(struct empobj *unit, short item[], short lim[])
847 for (it = I_NONE + 1; it <= I_MAX; it++) {
848 if (item[it] > lim[it])
849 edit_item(unit, item, &ichr[it], item[it], lim);
854 edit_ship(struct shpstr *ship, char *key, char *p)
856 struct mchrstr *mcp = &mchr[ship->shp_type];
866 return edit_unit((struct empobj *)ship, key, p,
867 SHIP_MINEFF, "fleet", 0);
869 arg = ef_elt_byname(EF_SHIP_CHR, p);
871 pr("%s: invalid ship type\n", p);
874 divine_unit_change((struct empobj *)ship, "Type",
875 arg != ship->shp_type, 0,
876 "to %s", mchr[arg].m_name);
877 ship->shp_type = arg;
878 limit_item((struct empobj *)ship, ship->shp_item, mchr[arg].m_item);
879 if (ship->shp_tech >= mchr[arg].m_tech)
881 arg = mchr[arg].m_tech;
884 arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
885 divine_unit_change((struct empobj *)ship, "Tech level",
886 arg != ship->shp_tech, arg - ship->shp_tech,
887 "from %d to %d", ship->shp_tech, arg);
888 shp_set_tech(ship, arg);
891 arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
892 divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
893 arg != ship->shp_pstage,
894 "from %d to %d", ship->shp_pstage, arg);
895 ship->shp_pstage = arg;
898 arg = LIMIT_TO(arg, 0, 32767);
899 divine_unit_change_quiet((struct empobj *)ship, "Plague time",
900 arg != ship->shp_ptime,
901 "from %d to %d", ship->shp_ptime, arg);
902 ship->shp_ptime = arg;
905 divine_unit_change((struct empobj *)ship, "Retreat path",
906 strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
907 0, "from %s to %.*s",
908 ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
909 strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
912 divine_flag_change((struct empobj *)ship, "Retreat conditions",
913 ship->shp_rflags, arg, retreat_flags);
914 ship->shp_rflags = arg;
929 edit_item((struct empobj *)ship, ship->shp_item, item_by_name(key),
933 pr("huh? (%s)\n", key);
940 edit_land(struct lndstr *land, char *key, char *p)
942 struct lchrstr *lcp = &lchr[land->lnd_type];
952 return edit_unit((struct empobj *)land, key, p,
954 land->lnd_ship >= 0 || land->lnd_land >= 0);
956 arg = ef_elt_byname(EF_LAND_CHR, p);
958 pr("%s: invalid land unit type\n", p);
961 divine_unit_change((struct empobj *)land, "Type",
962 arg != land->lnd_type, 0,
963 "to %s", lchr[arg].l_name);
964 land->lnd_type = arg;
965 limit_item((struct empobj *)land, land->lnd_item, lchr[arg].l_item);
966 if (land->lnd_tech >= lchr[arg].l_tech)
968 arg = lchr[arg].l_tech;
971 arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
972 divine_unit_change((struct empobj *)land, "Tech level",
973 arg != land->lnd_tech, arg - land->lnd_tech,
974 "from %d to %d", land->lnd_tech, arg);
975 lnd_set_tech(land, arg);
978 arg = LIMIT_TO(arg, 0, 127);
979 divine_unit_change((struct empobj *)land, "Fortification",
980 arg != land->lnd_harden, arg - land->lnd_harden,
981 "from %d to %d", land->lnd_harden, arg);
982 land->lnd_harden = arg;
985 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
987 if (arg == land->lnd_ship) {
988 pr("Ship of %s unchanged\n", prland(land));
991 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
993 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
996 divine_load((struct empobj *)land, EF_SHIP, arg);
997 land->lnd_ship = arg;
1000 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1002 if (arg == land->lnd_land) {
1003 pr("Land unit of %s unchanged\n", prland(land));
1006 divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
1008 divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
1009 land->lnd_ship = -1;
1011 divine_load((struct empobj *)land, EF_LAND, arg);
1012 land->lnd_land = arg;
1015 arg = LIMIT_TO(arg, 0, 100);
1016 divine_unit_change((struct empobj *)land, "Retreat percentage",
1017 arg != land->lnd_retreat, 0,
1018 "from %d to %d", land->lnd_retreat, arg);
1019 land->lnd_retreat = arg;
1022 divine_unit_change((struct empobj *)land, "Retreat path",
1023 strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
1024 0, "from %s to %.*s",
1025 land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
1026 strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
1029 divine_flag_change((struct empobj *)land, "Retreat condition",
1030 land->lnd_rflags, arg, retreat_flags);
1031 land->lnd_rflags = arg;
1046 edit_item((struct empobj *)land, land->lnd_item, item_by_name(key),
1050 pr("huh? (%s)\n", key);
1057 edit_plane(struct plnstr *plane, char *key, char *p)
1059 struct plchrstr *pcp = &plchr[plane->pln_type];
1069 return edit_unit((struct empobj *)plane, key, p,
1070 PLANE_MINEFF, "wing",
1071 plane->pln_ship >= 0 || plane->pln_land >= 0);
1073 arg = ef_elt_byname(EF_PLANE_CHR, p);
1075 pr("%s: invalid plane type\n", p);
1078 divine_unit_change((struct empobj *)plane, "Type",
1079 arg != plane->pln_type, 0,
1080 "to %s", plchr[arg].pl_name);
1081 plane->pln_type = arg;
1082 if (plane->pln_tech >= plchr[arg].pl_tech)
1084 arg = plchr[arg].pl_tech;
1087 arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
1088 divine_unit_change((struct empobj *)plane, "Tech level",
1089 arg != plane->pln_tech, arg - plane->pln_tech,
1090 "from %d to %d", plane->pln_tech, arg);
1091 pln_set_tech(plane, arg);
1094 arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
1095 divine_unit_change((struct empobj *)plane, "Range",
1096 arg != plane->pln_range, 0,
1097 "from %d to %d", plane->pln_range, arg);
1098 plane->pln_range = (unsigned char)arg;
1101 if (arg < -1 || arg >= ef_nelem(EF_SHIP))
1103 if (arg == plane->pln_ship) {
1104 pr("Ship of %s unchanged\n", prplane(plane));
1107 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1109 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1110 plane->pln_land = -1;
1112 divine_load((struct empobj *)plane, EF_SHIP, arg);
1113 plane->pln_ship = arg;
1116 if (arg < -1 || arg >= ef_nelem(EF_LAND))
1118 if (arg == plane->pln_land) {
1119 pr("Land unit of %s unchanged\n", prplane(plane));
1122 divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
1124 divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
1125 plane->pln_ship = -1;
1127 divine_load((struct empobj *)plane, EF_LAND, arg);
1128 plane->pln_land = arg;
1131 divine_flag_change((struct empobj *)plane, "Flags",
1132 plane->pln_flags, arg, plane_flags);
1133 plane->pln_flags = arg;
1136 pr("huh? (%s)\n", key);