#include <ctype.h>
#include <limits.h>
+#include "actofgod.h"
#include "commands.h"
#include "item.h"
#include "land.h"
#include "plague.h"
#include "plane.h"
#include "ship.h"
+#include "unit.h"
static void print_sect(struct sctstr *);
static void print_nat(struct natstr *);
static void print_plane(struct plnstr *);
static void print_land(struct lndstr *);
static void print_ship(struct shpstr *);
-static int getin(char *, char **);
-static int edit_sect(struct sctstr *, char, int, char *);
-static int edit_nat(struct natstr *, char, int, char *);
-static int edit_ship(struct shpstr *, char, int, char *);
-static int edit_land(struct lndstr *, char, int, char *);
-static int edit_plane(struct plnstr *, char, int, char *);
+static char *getin(char *, char **);
+static int edit_nat(struct natstr *, char *, char *);
+static int edit_ship(struct shpstr *, char *, char *);
+static int edit_land(struct lndstr *, char *, char *);
+static int edit_plane(struct plnstr *, char *, char *);
int
edit(void)
{
- struct sctstr sect;
- struct plnstr plane;
- struct shpstr ship;
- struct lndstr land;
+ union empobj_storage item;
char *what;
- char *ptr;
- char thing;
+ char *key, *ptr;
int num;
- int arg;
int err;
int arg_index = 3;
coord x, y;
return RET_FAIL;
if (!sarg_xy(ptr, &x, &y))
return RET_FAIL;
- if (!getsect(x, y, §))
+ if (!getsect(x, y, &item.sect))
return RET_FAIL;
break;
case 'c':
case 'p':
if ((num = onearg(player->argp[2], "Plane number? ")) < 0)
return RET_SYN;
- if (!getplane(num, &plane))
+ if (!getplane(num, &item.plane))
return RET_SYN;
break;
case 's':
if ((num = onearg(player->argp[2], "Ship number? ")) < 0)
return RET_SYN;
- if (!getship(num, &ship))
+ if (!getship(num, &item.ship))
return RET_SYN;
break;
case 'u':
if ((num = onearg(player->argp[2], "Unit number? ")) < 0)
return RET_SYN;
- if (!getland(num, &land))
+ if (!getland(num, &item.land))
return RET_SYN;
break;
case 'n':
pr("Not implemented yet.\n");
- break;
+ return RET_FAIL;
default:
pr("huh?\n");
return RET_SYN;
if (!player->argp[3]) {
switch (ewhat) {
case 'l':
- print_sect(§);
+ print_sect(&item.sect);
break;
case 'c':
print_nat(np);
break;
case 'p':
- print_plane(&plane);
+ print_plane(&item.plane);
break;
case 's':
- print_ship(&ship);
+ print_ship(&item.ship);
break;
case 'u':
- print_land(&land);
+ print_land(&item.land);
break;
+ default:
+ CANT_REACH();
}
}
for (;;) {
if (player->argp[arg_index]) {
if (player->argp[arg_index+1]) {
- thing = player->argp[arg_index++][0];
+ key = player->argp[arg_index++];
ptr = player->argp[arg_index++];
- arg = atoi(ptr);
} else
return RET_SYN;
} else if (arg_index == 3) {
- err = getin(buf, &ptr);
- if (err < 0)
+ key = getin(buf, &ptr);
+ if (!key)
return RET_SYN;
- if (err == 0) {
- switch (ewhat) {
- case 'c':
- print_nat(np);
- break;
- case 'l':
- print_sect(§);
- break;
- case 's':
- print_ship(&ship);
- break;
- case 'u':
- print_land(&land);
- break;
- case 'p':
- print_plane(&plane);
- break;
- }
+ if (!*key)
return RET_OK;
- }
- thing = err;
- arg = atoi(ptr);
} else
return RET_OK;
switch (ewhat) {
case 'c':
- if ((err = edit_nat(np, thing, arg, ptr)) != RET_OK)
+ if ((err = edit_nat(np, key, ptr)) != RET_OK)
return err;
break;
case 'l':
- if (!check_sect_ok(§))
+ if (!check_sect_ok(&item.sect))
return RET_FAIL;
- if ((err = edit_sect(§, thing, arg, ptr)) != RET_OK)
+ if ((err = edit_sect(&item.sect, key, ptr)) != RET_OK)
return err;
- if (!putsect(§))
+ if (!putsect(&item.sect))
return RET_FAIL;
break;
case 's':
- if (!check_ship_ok(&ship))
+ if (!check_ship_ok(&item.ship))
return RET_FAIL;
- if ((err = edit_ship(&ship, thing, arg, ptr)) != RET_OK)
+ if ((err = edit_ship(&item.ship, key, ptr)) != RET_OK)
return err;
- if (!ef_ensure_space(EF_SHIP, ship.shp_uid, 50))
- return RET_FAIL;
- if (!putship(ship.shp_uid, &ship))
+ if (!putship(item.ship.shp_uid, &item.ship))
return RET_FAIL;
break;
case 'u':
- if (!check_land_ok(&land))
+ if (!check_land_ok(&item.land))
return RET_FAIL;
- if ((err = edit_land(&land, thing, arg, ptr)) != RET_OK)
+ if ((err = edit_land(&item.land, key, ptr)) != RET_OK)
return err;
- if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50))
- return RET_FAIL;
- if (!putland(land.lnd_uid, &land))
+ if (!putland(item.land.lnd_uid, &item.land))
return RET_FAIL;
break;
case 'p':
- if (!check_plane_ok(&plane))
+ if (!check_plane_ok(&item.plane))
return RET_FAIL;
- if ((err = edit_plane(&plane, thing, arg, ptr)) != RET_OK)
+ if ((err = edit_plane(&item.plane, key, ptr)) != RET_OK)
return err;
- if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50))
- return RET_FAIL;
- if (!putplane(plane.pln_uid, &plane))
+ if (!putplane(item.plane.pln_uid, &item.plane))
return RET_FAIL;
break;
+ default:
+ CANT_REACH();
}
}
}
-static void
-benefit(natid who, int good)
-{
- if (!opt_GODNEWS)
- return;
-
- if (good) {
- if (who)
- nreport(player->cnum, N_AIDS, who, 1);
- } else {
- if (who)
- nreport(player->cnum, N_HURTS, who, 1);
- }
-}
-
static void
noise(struct sctstr *sptr, char *name, int old, int new)
{
- pr("%s of %s changed from %d to %d\n",
- name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new);
- if (sptr->sct_own)
- wu(player->cnum, sptr->sct_own,
- "%s in %s was changed from %d to %d by an act of %s\n",
- name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own),
- old, new, cname(player->cnum));
- benefit(sptr->sct_own, old < new);
+ divine_sct_change(sptr, name, new != old, new - old,
+ "from %d to %d", old, new);
}
static void
pr("\n");
}
-static int
+static char *
getin(char *buf, char **valp)
{
+ char line[1024];
+ char *argp[128];
char *p;
- unsigned char thing;
- p = getstarg(NULL, "%c xxxxx -- thing value : ", buf);
+ *valp = NULL;
+ p = getstarg(NULL, "%c xxxxx -- thing value : ", line);
if (!p)
- return -1;
- if (!*p)
- return 0;
- for (; isspace(*p); p++) ;
- if (!*p)
- return -1;
- thing = *p;
- for (; *p && !isspace(*p); p++) ;
- for (; isspace(*p); p++) ;
- if (!*p)
- return -1;
- *valp = p;
- return thing;
+ return NULL;
+ switch (parse(p, buf, argp, NULL, NULL, NULL)) {
+ case 0:
+ return "";
+ case 1:
+ return NULL;
+ default:
+ *valp = argp[1];
+ return argp[0];
+ }
}
#if 0 /* not needed right now */
}
#endif
-static int
-edit_sect(struct sctstr *sect, char op, int arg, char *p)
+int
+edit_sect_i(struct sctstr *sect, char *key, int arg)
{
- coord newx, newy;
int new;
- switch (op) {
+ switch (*key) {
case 'o':
if (arg < 0 || arg >= MAXNOC)
return RET_SYN;
- pr("Owner of %s changed from %s to %s.\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- prnatid(sect->sct_own), prnatid(arg));
- if (sect->sct_own) {
- wu(player->cnum, sect->sct_own,
- "Sector %s lost to deity intervention\n",
- xyas(sect->sct_x, sect->sct_y, sect->sct_own));
- }
- benefit(sect->sct_own, 0);
+ divine_sct_change_quiet(sect, "Owner", arg != sect->sct_own,
+ "from %s to %s",
+ prnatid(sect->sct_own), prnatid(arg));
+ if (arg == sect->sct_own)
+ break;
+ report_god_takes("Sector ",
+ xyas(sect->sct_x, sect->sct_y, sect->sct_own),
+ sect->sct_own);
+ report_god_gives("Sector ",
+ xyas(sect->sct_x, sect->sct_y, arg),
+ arg);
sect->sct_own = arg;
- if (arg) {
- wu(player->cnum, arg,
- "Sector %s gained from deity intervention\n",
- xyas(sect->sct_x, sect->sct_y, arg));
- }
- benefit(arg, 1);
break;
case 'O':
if (arg < 0 || arg >= MAXNOC)
return RET_SYN;
- pr("Old owner of %s changed from %s to %s.\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- prnatid(sect->sct_oldown), prnatid(arg));
+ divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
+ "from %s to %s",
+ prnatid(sect->sct_oldown), prnatid(arg));
sect->sct_oldown = arg;
break;
case 'e':
sect->sct_effic = new;
break;
case 'm':
- new = LIMIT_TO(arg, -127, 255);
+ new = LIMIT_TO(arg, -127, 127);
noise(sect, "Mobility", sect->sct_mobil, new);
sect->sct_mobil = new;
break;
case 'i':
- new = LIMIT_TO(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 100);
noise(sect, "Iron ore content", sect->sct_min, new);
sect->sct_min = (unsigned char)new;
break;
case 'g':
- new = LIMIT_TO(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 100);
noise(sect, "Gold content", sect->sct_gmin, new);
sect->sct_gmin = (unsigned char)new;
break;
case 'f':
- new = LIMIT_TO(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 100);
noise(sect, "Fertility", sect->sct_fertil, new);
sect->sct_fertil = (unsigned char)new;
break;
case 'c':
- new = LIMIT_TO(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 100);
noise(sect, "Oil content", sect->sct_oil, new);
sect->sct_oil = (unsigned char)new;
break;
case 'u':
- new = LIMIT_TO(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 100);
noise(sect, "Uranium content", sect->sct_uran, new);
sect->sct_uran = (unsigned char)new;
break;
break;
case 'l':
new = LIMIT_TO(arg, 0, 127);
- pr("Loyalty of %s changed from %d to %d\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- sect->sct_loyal, new);
+ divine_sct_change_quiet(sect, "Loyalty", new != sect->sct_loyal,
+ "from %d to %d", sect->sct_loyal, new);
sect->sct_loyal = (unsigned char)new;
break;
case 'x':
new = LIMIT_TO(arg, 0, CHE_MAX);
- pr("Guerillas in %s changed from %d to %d\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- sect->sct_che, new);
+ divine_sct_change_quiet(sect, "Guerillas", new != sect->sct_che,
+ "from %d to %d", sect->sct_che, new);
sect->sct_che = new;
break;
case 'X':
if (arg < 0 || arg >= MAXNOC)
return RET_SYN;
- pr("Che target of %s changed from %s to %s.\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- prnatid(sect->sct_che_target), prnatid(arg));
+ divine_sct_change_quiet(sect, "Che target",
+ arg != sect->sct_che_target,
+ "from %s to %s",
+ prnatid(sect->sct_che_target),
+ prnatid(arg));
sect->sct_che_target = arg;
if (arg == 0)
sect->sct_che = 0;
break;
case 'p':
new = LIMIT_TO(arg, 0, PLG_EXPOSED);
- pr("Plague stage of %s changed from %d to %d\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- sect->sct_pstage, new);
+ divine_sct_change_quiet(sect, "Plague stage",
+ new != sect->sct_pstage,
+ "from %d to %d", sect->sct_pstage, new);
sect->sct_pstage = new;
break;
case 't':
- new = LIMIT_TO(arg, 0, 255);
- pr("Plague time of %s changed from %d to %d\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- sect->sct_ptime, new);
+ new = LIMIT_TO(arg, 0, 32767);
+ divine_sct_change_quiet(sect, "Plague time",
+ new != sect->sct_ptime,
+ "from %d to %d", sect->sct_ptime, new);
sect->sct_ptime = new;
break;
case 'F':
new = LIMIT_TO(arg, 0, FALLOUT_MAX);
- pr("Fallout for sector %s changed from %d to %d\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- sect->sct_fallout, new);
+ noise(sect, "Fallout", sect->sct_fallout, new);
sect->sct_fallout = new;
break;
case 'a':
break;
case 'M':
new = LIMIT_TO(arg, 0, MINES_MAX);
+ if (sect->sct_own == sect->sct_oldown)
+ noise(sect, "Mines", sect->sct_mines, new);
+ else
+ divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
+ "from %d to %d", sect->sct_mines, new);
sect->sct_mines = new;
- pr("Mines changed to %d\n", new);
break;
+ case 'R':
+ new = LIMIT_TO(arg, 0, 100);
+ noise(sect, "Road percentage", sect->sct_road, new);
+ sect->sct_road = new;
+ break;
+ case 'r':
+ new = LIMIT_TO(arg, 0, 100);
+ noise(sect, "Rail percentage", sect->sct_rail, new);
+ sect->sct_rail = new;
+ break;
+ case 'd':
+ new = LIMIT_TO(arg, 0, 100);
+ noise(sect, "Defense percentage", sect->sct_defense, new);
+ sect->sct_defense = new;
+ break;
+ default:
+ pr("huh? (%s)\n", key);
+ return RET_SYN;
+ }
+ return RET_OK;
+}
+
+int
+edit_sect(struct sctstr *sect, char *key, char *p)
+{
+ coord newx, newy;
+ int new;
+ struct sctstr newsect;
+
+ switch (*key) {
case 'L':
if (!sarg_xy(p, &newx, &newy))
return RET_SYN;
+ if (newx == sect->sct_x && newy == sect->sct_y) {
+ pr("Sector %s unchanged\n", xyas(newx, newy, player->cnum));
+ break;
+ }
+ getsect(newx, newy, &newsect);
+ pr("Sector %s duplicated to %s\n",
+ xyas(sect->sct_x, sect->sct_y, player->cnum),
+ xyas(newx, newy, player->cnum));
+ report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
+ newsect.sct_own);
+ report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
+ sect->sct_own);
sect->sct_x = newx;
sect->sct_y = newy;
- ef_set_uid(EF_SECTOR, §, XYOFFSET(newx, newy));
+ ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
break;
case 'D':
if (!sarg_xy(p, &newx, &newy))
return RET_SYN;
- pr("Distribution location for sector %s changed from %s to %s\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
- xyas(newx, newy, player->cnum));
+ divine_sct_change_quiet(sect, "Distribution sector",
+ newx != sect->sct_dist_x || newy != sect->sct_dist_y,
+ "from %s to %s",
+ xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
+ xyas(newx, newy, player->cnum));
+ if (newx == sect->sct_dist_x && newy == sect->sct_dist_y)
+ break;
+ if (sect->sct_own && sect->sct_own != player->cnum)
+ wu(0, sect->sct_own,
+ "Distribution sector of %s changed from %s to %s"
+ " by an act of %s\n",
+ xyas(sect->sct_x, sect->sct_y, player->cnum),
+ xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
+ xyas(newx, newy, player->cnum),
+ cname(player->cnum));
sect->sct_dist_x = newx;
sect->sct_dist_y = newy;
break;
new = sct_typematch(p);
if (new < 0)
return RET_SYN;
- pr("Designation for sector %s changed from %c to %c\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
+ divine_sct_change(sect, "Designation",
+ new != sect->sct_type, 0, "from %c to %c",
+ dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
set_coastal(sect, sect->sct_type, new);
sect->sct_type = new;
break;
new = sct_typematch(p);
if (new < 0)
return RET_SYN;
- pr("New designation for sector %s changed from %c to %c\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
+ divine_sct_change(sect, "New designation",
+ new != sect->sct_newtype, 0, "from %c to %c",
+ dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
sect->sct_newtype = new;
break;
- case 'R':
- new = LIMIT_TO(arg, 0, 100);
- noise(sect, "Road percentage", sect->sct_road, new);
- sect->sct_road = new;
- break;
- case 'r':
- new = LIMIT_TO(arg, 0, 100);
- noise(sect, "Rail percentage", sect->sct_rail, new);
- sect->sct_rail = new;
- break;
- case 'd':
- new = LIMIT_TO(arg, 0, 100);
- noise(sect, "Defense percentage", sect->sct_defense, new);
- sect->sct_defense = new;
- break;
default:
- pr("huh? (%c)\n", op);
- return RET_SYN;
+ return edit_sect_i(sect, key, atoi(p));
}
return RET_OK;
}
+static void
+edit_level(struct natstr *np, int lvl, char *name, char *p)
+{
+ float new = (float)atof(p);
+
+ new = MAX(0.0, new);
+ divine_nat_change(np, name,
+ new != np->nat_level[lvl],
+ (new > np->nat_level[lvl]) - (new < np->nat_level[lvl]),
+ "from %.2f to %.2f", np->nat_level[lvl], new);
+ np->nat_level[lvl] = new;
+}
+
static int
-edit_nat(struct natstr *np, char op, int arg, char *p)
+edit_nat(struct natstr *np, char *key, char *p)
{
coord newx, newy;
natid nat = np->nat_cnum;
- float farg = (float)atof(p);
+ int arg = atoi(p);
- switch (op) {
+ switch (*key) {
case 'n':
if (!check_nat_name(p, nat))
return RET_SYN;
- pr("Country name changed from %s to %s\n", np->nat_cnam, p);
+ divine_nat_change(np, "Country name", strcmp(np->nat_cnam, p), 0,
+ "from %s to %s", np->nat_cnam, p);
+ if (opt_GODNEWS)
+ nreport(player->cnum, N_NAME_CHNG, 0, 1);
strcpy(np->nat_cnam, p);
break;
case 'r':
- pr("Country representative changed from %s to %s\n",
- np->nat_pnam, p);
+ divine_nat_change(np, "Country representative",
+ strncmp(p, np->nat_pnam, sizeof(np->nat_pnam) - 1), 0,
+ "from %s to %.*s",
+ np->nat_pnam, (int)sizeof(np->nat_pnam) - 1, p);
strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1);
break;
case 't':
+ arg = LIMIT_TO(arg, 0, USHRT_MAX);
+ divine_nat_change_quiet(np, "Number of unread telegrams",
+ arg != np->nat_tgms,
+ "from %d to %d", np->nat_tgms, arg);
np->nat_tgms = arg;
break;
case 'b':
- arg = LIMIT_TO(arg, 0, 1024);
- pr("BTU's changed from %d to %d\n", np->nat_btu, arg);
+ arg = LIMIT_TO(arg, 0, max_btus);
+ divine_nat_change(np, "BTUs",
+ arg != np->nat_btu, arg - np->nat_btu,
+ "from %d to %d", np->nat_btu, arg);
np->nat_btu = arg;
break;
case 'm':
- benefit(nat, np->nat_reserve < arg);
- pr("Military reserves changed from %d to %d\n",
- np->nat_reserve, arg);
- wu(player->cnum, nat,
- "Military reserves changed from %d to %d by divine intervention.\n",
- np->nat_reserve, arg);
+ arg = LIMIT_TO(arg, 0, INT_MAX);
+ divine_nat_change(np, "Military reserves",
+ arg != np->nat_reserve, arg - np->nat_reserve,
+ "from %d to %d", np->nat_reserve, arg);
np->nat_reserve = arg;
break;
case 'c':
if (!sarg_xy(p, &newx, &newy))
return RET_SYN;
- pr("Capital coordinates changed from %s to %s\n",
- xyas(np->nat_xcap, np->nat_ycap, player->cnum),
- xyas(newx, newy, player->cnum));
+ if (newx == np->nat_xcap && newy == np->nat_ycap)
+ pr("Capital unchanged\n");
+ else {
+ pr("Capital moved from %s to %s\n",
+ xyas(np->nat_xcap, np->nat_ycap, player->cnum),
+ xyas(newx, newy, player->cnum));
+ if (nat != player->cnum)
+ wu(0, nat,
+ "Capital moved from %s to %s by an act of %s!\n",
+ xyas(np->nat_xcap, np->nat_ycap, nat),
+ xyas(newx, newy, nat), cname(player->cnum));
+ }
np->nat_xcap = newx;
np->nat_ycap = newy;
break;
case 'o':
if (!sarg_xy(p, &newx, &newy))
return RET_SYN;
- pr("Origin coordinates changed from %s to %s\n",
- xyas(np->nat_xorg, np->nat_yorg, player->cnum),
- xyas(newx, newy, player->cnum));
+ if (newx == np->nat_xorg && newy == np->nat_yorg)
+ pr("Origin unchanged\n");
+ else {
+ pr("Origin moved from %s to %s\n",
+ xyas(np->nat_xorg, np->nat_yorg, player->cnum),
+ xyas(newx, newy, player->cnum));
+ if (nat != player->cnum)
+ wu(0, nat,
+ "Origin moved from %s to %s by an act of %s!\n",
+ xyas(np->nat_xorg, np->nat_yorg, nat),
+ xyas(newx, newy, nat), cname(player->cnum));
+ }
np->nat_xorg = newx;
np->nat_yorg = newy;
break;
case 's':
- np->nat_stat = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
+ arg = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
+ divine_nat_change(np, "Status",
+ (enum nat_status)arg != np->nat_stat,
+ 0, "to %s", nation_status[arg].name);
+ np->nat_stat = arg;
break;
case 'u':
arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
- pr("Number of seconds used changed from %d to %d.\n",
- np->nat_timeused, arg);
+ divine_nat_change(np, "Number of seconds used",
+ arg != np->nat_timeused, arg - np->nat_timeused,
+ "from %d to %d", np->nat_timeused, arg);
np->nat_timeused = arg;
break;
case 'M':
- pr("Money changed from %d to %d\n", np->nat_money, arg);
- wu(player->cnum, nat,
- "Money changed from %d to %d by divine intervention.\n",
- np->nat_money, arg);
+ divine_nat_change(np, "Money",
+ arg != np->nat_money, arg - np->nat_money,
+ "from %d to %d", np->nat_money, arg);
np->nat_money = arg;
break;
case 'T':
- pr("Tech changed from %.2f to %.2f.\n",
- np->nat_level[NAT_TLEV], farg);
- np->nat_level[NAT_TLEV] = farg;
+ edit_level(np, NAT_TLEV, "Technology", p);
break;
case 'R':
- pr("Research changed from %.2f to %.2f.\n",
- np->nat_level[NAT_RLEV], farg);
- np->nat_level[NAT_RLEV] = farg;
+ edit_level(np, NAT_RLEV, "Research", p);
break;
case 'E':
- pr("Education changed from %.2f to %.2f.\n",
- np->nat_level[NAT_ELEV], farg);
- np->nat_level[NAT_ELEV] = farg;
+ edit_level(np, NAT_ELEV, "Education", p);
break;
case 'H':
- pr("Happiness changed from %.2f to %.2f.\n",
- np->nat_level[NAT_HLEV], farg);
- np->nat_level[NAT_HLEV] = farg;
+ edit_level(np, NAT_HLEV, "Happiness", p);
break;
default:
- pr("huh? (%c)\n", op);
+ pr("huh? (%s)\n", key);
break;
}
putnat(np);
}
static int
-edit_ship(struct shpstr *ship, char op, int arg, char *p)
+edit_unit(struct empobj *unit, char *key, char *p,
+ int mineff, char *group_name, int on_carrier)
{
+ int arg = atoi(p);
coord newx, newy;
-
- newx = newy = 0;
- switch (op) {
- case 'a':
- ship->shp_pstage = arg;
- break;
- case 'b':
- ship->shp_ptime = arg;
- break;
- case 'R':
- strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
- break;
- case 'W':
- ship->shp_rflags = arg;
- break;
+ union empobj_storage newunit;
+ char newgroup;
+
+ switch (toupper(*key)) {
case 'U':
- ef_set_uid(EF_SHIP, ship, arg);
+ if (arg < 0)
+ return RET_SYN;
+ if (arg == unit->uid) {
+ pr("%s unchanged\n", unit_nameof(unit));
+ break;
+ }
+ if (!ef_ensure_space(unit->ef_type, arg, 50)) {
+ pr("Can't copy to %s #%d\n", ef_nameof(unit->ef_type), arg);
+ return RET_FAIL;
+ }
+ pr("%s duplicated to (#%d)\n", unit_nameof(unit), arg);
+ ef_set_uid(unit->ef_type, unit, arg);
+ if (get_empobj(unit->ef_type, arg, &newunit) && newunit.gen.own) {
+ pr("Replacing %s of %s\n",
+ unit_nameof(&newunit.gen), prnatid(newunit.gen.own));
+ report_god_takes("", unit_nameof(&newunit.gen),
+ newunit.gen.own);
+ }
+ report_god_gives("", unit_nameof(unit), unit->own);
break;
case 'O':
if (arg < 0 || arg >= MAXNOC)
return RET_SYN;
- if (ship->shp_own)
- wu(player->cnum, ship->shp_own,
- "%s taken from you by deity intervention!\n", prship(ship));
- if (arg)
- wu(player->cnum, (natid)arg,
- "%s given to you by deity intervention!\n", prship(ship));
- ship->shp_own = arg;
+ divine_unit_change_quiet(unit, "Owner", arg != unit->own,
+ "from %s to %s",
+ prnatid(unit->own), prnatid(arg));
+ if (arg != unit->own) {
+ report_god_takes("", unit_nameof(unit), unit->own);
+ report_god_gives("", unit_nameof(unit), arg);
+ }
+ unit->own = arg;
break;
case 'L':
if (!sarg_xy(p, &newx, &newy))
return RET_SYN;
- ship->shp_x = newx;
- ship->shp_y = newy;
- break;
- case 'T':
- arg = LIMIT_TO(arg, mchr[(int)ship->shp_type].m_tech, SHRT_MAX);
- shp_set_tech(ship, arg);
+ if (on_carrier && (newx != unit->x || newy != unit->y)) {
+ pr("Can't move %s while it's loaded\n", unit_nameof(unit));
+ return RET_FAIL;
+ }
+ divine_unit_change_quiet(unit, "Location",
+ unit->own && unit->own != player->cnum,
+ "from %s to %s",
+ xyas(unit->x, unit->y, player->cnum),
+ xyas(newx, newy, player->cnum));
+ if (unit->own && unit->own != player->cnum)
+ wu(0, unit->own,
+ "Location of %s changed from %s to %s by an act of %s!\n",
+ unit_nameof(unit),
+ xyas(unit->x, unit->y, unit->own),
+ xyas(newx, newy, unit->own),
+ cname(player->cnum));
+ unit->x = newx;
+ unit->y = newy;
break;
case 'E':
- ship->shp_effic = LIMIT_TO(arg, SHIP_MINEFF, 100);
+ arg = LIMIT_TO(arg, mineff, 100);
+ divine_unit_change(unit, "Efficiency",
+ arg != unit->effic, arg - unit->effic,
+ "from %d to %d", unit->effic, arg);
+ unit->effic = arg;
break;
case 'M':
- ship->shp_mobil = arg;
+ arg = LIMIT_TO(arg, -127, 127);
+ divine_unit_change(unit, "Mobility",
+ arg != unit->mobil, arg - unit->mobil,
+ "from %d to %d", unit->mobil, arg);
+ unit->mobil = arg;
break;
case 'F':
+ case 'W':
+ case 'A':
if (p[0] == '~')
- ship->shp_fleet = 0;
+ newgroup = 0;
else if (isalpha(p[0]))
- ship->shp_fleet = p[0];
+ newgroup = p[0];
else {
- pr("%c: invalid fleet\n", p[0]);
+ pr("%c: invalid %s\n", p[0], group_name);
return RET_FAIL;
}
+ divine_unit_change(unit, "Assignment", newgroup != unit->group, 0,
+ "from %s %c to %c", group_name,
+ unit->group ? unit->group : '~', p[0]);
+ unit->group = newgroup;
break;
- case 'c':
- ship->shp_item[I_CIVIL] = arg;
+ default:
+ CANT_REACH();
+ }
+ return RET_OK;
+}
+
+static int
+edit_ship(struct shpstr *ship, char *key, char *p)
+{
+ struct mchrstr *mcp = &mchr[ship->shp_type];
+ int arg = atoi(p);
+ struct ichrstr *ip;
+
+ switch (*key) {
+ case 'U':
+ case 'O':
+ case 'L':
+ case 'E':
+ case 'M':
+ case 'F':
+ return edit_unit((struct empobj *)ship, key, p,
+ SHIP_MINEFF, "fleet", 0);
+ case 'T':
+ arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
+ divine_unit_change((struct empobj *)ship, "Tech level",
+ arg != ship->shp_tech, arg - ship->shp_tech,
+ "from %d to %d", ship->shp_tech, arg);
+ shp_set_tech(ship, arg);
break;
- case 'm':
- ship->shp_item[I_MILIT] = arg;
+ case 'a':
+ arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
+ divine_unit_change_quiet((struct empobj *)ship, "Plague stage",
+ arg != ship->shp_pstage,
+ "from %d to %d", ship->shp_pstage, arg);
+ ship->shp_pstage = arg;
break;
- case 'u':
- ship->shp_item[I_UW] = arg;
+ case 'b':
+ arg = LIMIT_TO(arg, 0, 32767);
+ divine_unit_change_quiet((struct empobj *)ship, "Plague time",
+ arg != ship->shp_ptime,
+ "from %d to %d", ship->shp_ptime, arg);
+ ship->shp_ptime = arg;
break;
- case 'f':
- ship->shp_item[I_FOOD] = arg;
+ case 'R':
+ divine_unit_change((struct empobj *)ship, "Retreat path",
+ strncmp(p, ship->shp_rpath, sizeof(ship->shp_rpath) - 1),
+ 0, "from %s to %.*s",
+ ship->shp_rpath, (int)sizeof(ship->shp_rpath) - 1, p);
+ strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
break;
- case 's':
- ship->shp_item[I_SHELL] = arg;
+ case 'W':
+ divine_flag_change((struct empobj *)ship, "Retreat conditions",
+ ship->shp_rflags, arg, retreat_flags);
+ ship->shp_rflags = arg;
break;
+ case 'c':
+ case 'm':
+ case 'u':
+ case 'f':
+ case 's':
case 'g':
- ship->shp_item[I_GUN] = arg;
- break;
case 'p':
- ship->shp_item[I_PETROL] = arg;
- break;
case 'i':
- ship->shp_item[I_IRON] = arg;
- break;
case 'd':
- ship->shp_item[I_DUST] = arg;
- break;
case 'o':
- ship->shp_item[I_OIL] = arg;
- break;
case 'l':
- ship->shp_item[I_LCM] = arg;
- break;
case 'h':
- ship->shp_item[I_HCM] = arg;
- break;
case 'r':
- ship->shp_item[I_RAD] = arg;
+ ip = item_by_name(key);
+ arg = LIMIT_TO(arg, 0, mchr[ship->shp_type].m_item[ip->i_uid]);
+ divine_unit_change_quiet((struct empobj *)ship, ip->i_name,
+ arg != ship->shp_item[ip->i_uid],
+ "from %d to %d",
+ ship->shp_item[ip->i_uid], arg);
+ report_divine_gift(ship->shp_own, ip,
+ arg - ship->shp_item[ip->i_uid], prship(ship));
+ ship->shp_item[ip->i_uid] = arg;
break;
default:
- pr("huh? (%c)\n", op);
+ pr("huh? (%s)\n", key);
return RET_FAIL;
}
return RET_OK;
}
static int
-edit_land(struct lndstr *land, char op, int arg, char *p)
+edit_land(struct lndstr *land, char *key, char *p)
{
- coord newx, newy;
+ struct lchrstr *lcp = &lchr[land->lnd_type];
+ int arg = atoi(p);
+ struct ichrstr *ip;
- newx = newy = 0;
- switch (op) {
- case 'Y':
- land->lnd_land = arg;
- break;
+ switch (*key) {
case 'U':
- ef_set_uid(EF_LAND, land, arg);
- break;
case 'O':
- if (arg < 0 || arg >= MAXNOC)
- return RET_SYN;
- if (land->lnd_own)
- wu(player->cnum, land->lnd_own,
- "%s taken from you by deity intervention!\n", prland(land));
- if (arg)
- wu(player->cnum, (natid)arg,
- "%s given to you by deity intervention!\n", prland(land));
- land->lnd_own = arg;
- break;
case 'L':
- if (!sarg_xy(p, &newx, &newy))
- return RET_SYN;
- land->lnd_x = newx;
- land->lnd_y = newy;
- break;
case 'e':
- land->lnd_effic = LIMIT_TO(arg, LAND_MINEFF, 100);
- break;
case 'M':
- land->lnd_mobil = arg;
- break;
+ case 'a':
+ return edit_unit((struct empobj *)land, key, p,
+ LAND_MINEFF, "army",
+ land->lnd_ship >= 0 || land->lnd_land >= 0);
case 't':
- arg = LIMIT_TO(arg, lchr[(int)land->lnd_type].l_tech, SHRT_MAX);
+ arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
+ divine_unit_change((struct empobj *)land, "Tech level",
+ arg != land->lnd_tech, arg - land->lnd_tech,
+ "from %d to %d", land->lnd_tech, arg);
lnd_set_tech(land, arg);
break;
- case 'a':
- if (p[0] == '~')
- land->lnd_army = 0;
- else if (isalpha(p[0]))
- land->lnd_army = p[0];
- else {
- pr("%c: invalid army\n", p[0]);
- return RET_FAIL;
- }
- break;
case 'F':
- land->lnd_harden = LIMIT_TO(arg, 0, 255);
+ arg = LIMIT_TO(arg, 0, 127);
+ divine_unit_change((struct empobj *)land, "Fortification",
+ arg != land->lnd_harden, arg - land->lnd_harden,
+ "from %d to %d", land->lnd_harden, arg);
+ land->lnd_harden = arg;
break;
case 'S':
+ if (arg < -1 || arg >= ef_nelem(EF_SHIP))
+ return RET_SYN;
+ if (arg == land->lnd_ship) {
+ pr("Ship of %s unchanged\n", prland(land));
+ break;
+ }
+ divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
+ if (arg >= 0) {
+ divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
+ land->lnd_land = -1;
+ }
+ divine_load((struct empobj *)land, EF_SHIP, arg);
land->lnd_ship = arg;
break;
+ case 'Y':
+ if (arg < -1 || arg >= ef_nelem(EF_LAND))
+ return RET_SYN;
+ if (arg == land->lnd_land) {
+ pr("Land unit of %s unchanged\n", prland(land));
+ break;
+ }
+ divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
+ if (arg >= 0) {
+ divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
+ land->lnd_ship = -1;
+ }
+ divine_load((struct empobj *)land, EF_LAND, arg);
+ land->lnd_land = arg;
+ break;
case 'Z':
+ arg = LIMIT_TO(arg, 0, 100);
+ divine_unit_change((struct empobj *)land, "Retreat percentage",
+ arg != land->lnd_retreat, 0,
+ "from %d to %d", land->lnd_retreat, arg);
land->lnd_retreat = arg;
break;
case 'R':
+ divine_unit_change((struct empobj *)land, "Retreat path",
+ strncmp(p, land->lnd_rpath, sizeof(land->lnd_rpath) - 1),
+ 0, "from %s to %.*s",
+ land->lnd_rpath, (int)sizeof(land->lnd_rpath) - 1, p);
strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
break;
case 'W':
+ divine_flag_change((struct empobj *)land, "Retreat condition",
+ land->lnd_rflags, arg, retreat_flags);
land->lnd_rflags = arg;
break;
case 'c':
- land->lnd_item[I_CIVIL] = arg;
- break;
case 'm':
- land->lnd_item[I_MILIT] = arg;
- break;
case 'u':
- land->lnd_item[I_UW] = arg;
- break;
case 'f':
- land->lnd_item[I_FOOD] = arg;
- break;
case 's':
- land->lnd_item[I_SHELL] = arg;
- break;
case 'g':
- land->lnd_item[I_GUN] = arg;
- break;
case 'p':
- land->lnd_item[I_PETROL] = arg;
- break;
case 'i':
- land->lnd_item[I_IRON] = arg;
- break;
case 'd':
- land->lnd_item[I_DUST] = arg;
- break;
case 'o':
- land->lnd_item[I_OIL] = arg;
- break;
case 'l':
- land->lnd_item[I_LCM] = arg;
- break;
case 'h':
- land->lnd_item[I_HCM] = arg;
- break;
case 'r':
- land->lnd_item[I_RAD] = arg;
+ ip = item_by_name(key);
+ arg = LIMIT_TO(arg, 0, lchr[land->lnd_type].l_item[ip->i_uid]);
+ divine_unit_change_quiet((struct empobj *)land, ip->i_name,
+ arg != land->lnd_item[ip->i_uid],
+ "from %d to %d",
+ land->lnd_item[ip->i_uid], arg);
+ report_divine_gift(land->lnd_own, ip,
+ arg - land->lnd_item[ip->i_uid], prland(land));
+ land->lnd_item[ip->i_uid] = arg;
break;
default:
- pr("huh? (%c)\n", op);
+ pr("huh? (%s)\n", key);
return RET_FAIL;
}
return RET_OK;
}
static int
-edit_plane(struct plnstr *plane, char op, int arg, char *p)
+edit_plane(struct plnstr *plane, char *key, char *p)
{
- coord newx, newy;
+ struct plchrstr *pcp = &plchr[plane->pln_type];
+ int arg = atoi(p);
- switch (op) {
+ switch (*key) {
case 'U':
- ef_set_uid(EF_PLANE, plane, arg);
- break;
- case 'l':
- if (!sarg_xy(p, &newx, &newy))
- return RET_SYN;
- plane->pln_x = newx;
- plane->pln_y = newy;
- break;
case 'O':
- if (arg < 0 || arg >= MAXNOC)
- return RET_SYN;
- if (plane->pln_own)
- wu(player->cnum, plane->pln_own,
- "%s taken from you by deity intervention!\n",
- prplane(plane));
- if (arg)
- wu(player->cnum, arg,
- "%s given to you by deity intervention!\n", prplane(plane));
- plane->pln_own = arg;
- break;
+ case 'l':
case 'e':
- plane->pln_effic = LIMIT_TO(arg, PLANE_MINEFF, 100);
- break;
case 'm':
- plane->pln_mobil = LIMIT_TO(arg, -127, 255);
- break;
+ case 'w':
+ return edit_unit((struct empobj *)plane, key, p,
+ PLANE_MINEFF, "wing",
+ plane->pln_ship >= 0 || plane->pln_land >= 0);
case 't':
- arg = LIMIT_TO(arg, plchr[(int)plane->pln_type].pl_tech, SHRT_MAX);
+ arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
+ divine_unit_change((struct empobj *)plane, "Tech level",
+ arg != plane->pln_tech, arg - plane->pln_tech,
+ "from %d to %d", plane->pln_tech, arg);
pln_set_tech(plane, arg);
break;
- case 'w':
- if (p[0] == '~')
- plane->pln_wing = 0;
- else if (isalpha(p[0]))
- plane->pln_wing = p[0];
- else {
- pr("%c: invalid wing\n", p[0]);
- return RET_FAIL;
- }
- break;
case 'r':
+ arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
+ divine_unit_change((struct empobj *)plane, "Range",
+ arg != plane->pln_range, 0,
+ "from %d to %d", plane->pln_range, arg);
plane->pln_range = (unsigned char)arg;
break;
case 's':
+ if (arg < -1 || arg >= ef_nelem(EF_SHIP))
+ return RET_SYN;
+ if (arg == plane->pln_ship) {
+ pr("Ship of %s unchanged\n", prplane(plane));
+ break;
+ }
+ divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
+ if (arg >= 0) {
+ divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
+ plane->pln_land = -1;
+ }
+ divine_load((struct empobj *)plane, EF_SHIP, arg);
plane->pln_ship = arg;
break;
case 'y':
+ if (arg < -1 || arg >= ef_nelem(EF_LAND))
+ return RET_SYN;
+ if (arg == plane->pln_land) {
+ pr("Land unit of %s unchanged\n", prplane(plane));
+ break;
+ }
+ divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
+ if (arg >= 0) {
+ divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
+ plane->pln_ship = -1;
+ }
+ divine_load((struct empobj *)plane, EF_LAND, arg);
plane->pln_land = arg;
break;
case 'f':
+ divine_flag_change((struct empobj *)plane, "Flags",
+ plane->pln_flags, arg, plane_flags);
plane->pln_flags = arg;
break;
default:
- pr("huh? (%c)\n", op);
+ pr("huh? (%s)\n", key);
return RET_FAIL;
}
return RET_OK;