#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_land(struct lndstr *);
static void print_ship(struct shpstr *);
static char *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 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)
char *what;
char *key, *ptr;
int num;
- int arg;
int err;
int arg_index = 3;
coord x, y;
if (player->argp[arg_index+1]) {
key = player->argp[arg_index++];
ptr = player->argp[arg_index++];
- arg = atoi(ptr);
} else
return RET_SYN;
} else if (arg_index == 3) {
}
return RET_OK;
}
- arg = atoi(ptr);
} else
return RET_OK;
switch (ewhat) {
case 'c':
- if ((err = edit_nat(np, key, arg, ptr)) != RET_OK)
+ if ((err = edit_nat(np, key, ptr)) != RET_OK)
return err;
break;
case 'l':
if (!check_sect_ok(§))
return RET_FAIL;
- if ((err = edit_sect(§, key, arg, ptr)) != RET_OK)
+ if ((err = edit_sect(§, key, ptr)) != RET_OK)
return err;
if (!putsect(§))
return RET_FAIL;
case 's':
if (!check_ship_ok(&ship))
return RET_FAIL;
- if ((err = edit_ship(&ship, key, arg, ptr)) != RET_OK)
+ if ((err = edit_ship(&ship, key, ptr)) != RET_OK)
return err;
if (!ef_ensure_space(EF_SHIP, ship.shp_uid, 50))
return RET_FAIL;
case 'u':
if (!check_land_ok(&land))
return RET_FAIL;
- if ((err = edit_land(&land, key, arg, ptr)) != RET_OK)
+ if ((err = edit_land(&land, key, ptr)) != RET_OK)
return err;
if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50))
return RET_FAIL;
case 'p':
if (!check_plane_ok(&plane))
return RET_FAIL;
- if ((err = edit_plane(&plane, key, arg, ptr)) != RET_OK)
+ if ((err = edit_plane(&plane, key, ptr)) != RET_OK)
return err;
if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50))
return RET_FAIL;
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 && sptr->sct_own != player->cnum && new != old)
- wu(0, 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, new - old);
+ divine_sct_change(sptr, name, new != old, new - old,
+ "from %d to %d", old, new);
}
static void
}
#endif
-static int
-edit_sect(struct sctstr *sect, char *key, int arg, char *p)
+int
+edit_sect_i(struct sctstr *sect, char *key, int arg)
{
- coord newx, newy;
int new;
- struct sctstr newsect;
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));
+ 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 ",
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));
- if (arg == sect->sct_oldown)
- break;
- if (sect->sct_own && sect->sct_own != player->cnum)
- wu(0, sect->sct_own,
- "Old owner of %s changed from %s to %s by an act of %s\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- prnatid(sect->sct_oldown), prnatid(arg),
- cname(player->cnum));
+ 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':
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, 32767);
- pr("Plague time of %s changed from %d to %d\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- sect->sct_ptime, new);
+ 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':
if (sect->sct_own == sect->sct_oldown)
noise(sect, "Mines", sect->sct_mines, new);
else
- pr("Mines of %s changed from %d to %d\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- sect->sct_mines, new);
+ divine_sct_change_quiet(sect, "Mines", new != sect->sct_mines,
+ "from %d to %d", sect->sct_mines, new);
sect->sct_mines = 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),
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 sector of 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 sector %s changed from %s to %s"
+ "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),
new = sct_typematch(p);
if (new < 0)
return RET_SYN;
- pr("Designation of 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);
- if (new == sect->sct_type)
- break;
- if (sect->sct_own && sect->sct_own != player->cnum)
- wu(0, sect->sct_own,
- "Designation of sector %s changed from %c to %c"
- " by an act of %s\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- dchr[sect->sct_type].d_mnem, dchr[new].d_mnem,
- cname(player->cnum));
+ 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 of 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);
- if (new == sect->sct_newtype)
- break;
- if (sect->sct_own && sect->sct_own != player->cnum)
- wu(0, sect->sct_own,
- "New designation of sector %s changed from %c to %c"
- " by an act of %s\n",
- xyas(sect->sct_x, sect->sct_y, player->cnum),
- dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem,
- cname(player->cnum));
+ 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? (%s)\n", key);
- return RET_SYN;
+ return edit_sect_i(sect, key, atoi(p));
}
return RET_OK;
}
static int
-edit_nat(struct natstr *np, char *key, int arg, char *p)
+edit_nat(struct natstr *np, char *key, char *p)
{
coord newx, newy;
natid nat = np->nat_cnum;
+ int arg = atoi(p);
float farg = (float)atof(p);
switch (*key) {
}
static int
-edit_ship(struct shpstr *ship, char *key, int arg, char *p)
+edit_unit(struct empobj *unit, char *key, char *p,
+ int mineff, char *group_name)
{
- struct mchrstr *mcp = &mchr[ship->shp_type];
+ int arg = atoi(p);
coord newx, newy;
- struct ichrstr *ip;
-
- newx = newy = 0;
- switch (*key) {
- case 'a':
- arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
- ship->shp_pstage = arg;
- break;
- case 'b':
- arg = LIMIT_TO(arg, 0, 32767);
- 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;
+
+ switch (toupper(*key)) {
case 'U':
- ef_set_uid(EF_SHIP, ship, arg);
+ ef_set_uid(unit->ef_type, unit, arg);
break;
case 'O':
if (arg < 0 || arg >= MAXNOC)
return RET_SYN;
- if (arg == ship->shp_own)
+ if (arg == unit->own)
break;
- if (ship->shp_own && ship->shp_own != player->cnum)
- wu(0, ship->shp_own, "%s taken from you by an act of %s!\n",
- prship(ship), cname(player->cnum));
+ if (unit->own && unit->own != player->cnum)
+ wu(0, unit->own, "%s taken from you by an act of %s!\n",
+ unit_nameof(unit), cname(player->cnum));
if (arg && arg != player->cnum)
wu(0, arg, "%s given to you by an act of %s!\n",
- prship(ship), cname(player->cnum));
- ship->shp_own = arg;
+ unit_nameof(unit), cname(player->cnum));
+ 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, mcp->m_tech, SHRT_MAX);
- shp_set_tech(ship, arg);
+ unit->x = newx;
+ unit->y = newy;
break;
case 'E':
- ship->shp_effic = LIMIT_TO(arg, SHIP_MINEFF, 100);
+ arg = LIMIT_TO(arg, mineff, 100);
+ unit->effic = arg;
break;
case 'M':
arg = LIMIT_TO(arg, -127, 127);
- ship->shp_mobil = arg;
+ unit->mobil = arg;
break;
case 'F':
+ case 'W':
+ case 'A':
if (p[0] == '~')
- ship->shp_fleet = 0;
+ unit->group = 0;
else if (isalpha(p[0]))
- ship->shp_fleet = p[0];
+ unit->group = p[0];
else {
- pr("%c: invalid fleet\n", p[0]);
+ pr("%c: invalid %s\n", p[0], group_name);
return RET_FAIL;
}
break;
+ 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");
+ case 'T':
+ arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
+ shp_set_tech(ship, arg);
+ break;
+ case 'a':
+ arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
+ ship->shp_pstage = arg;
+ break;
+ case 'b':
+ arg = LIMIT_TO(arg, 0, 32767);
+ 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;
case 'c':
case 'm':
case 'u':
case 'r':
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:
}
static int
-edit_land(struct lndstr *land, char *key, int arg, char *p)
+edit_land(struct lndstr *land, char *key, char *p)
{
struct lchrstr *lcp = &lchr[land->lnd_type];
- coord newx, newy;
+ int arg = atoi(p);
struct ichrstr *ip;
- newx = newy = 0;
switch (*key) {
- case 'Y':
- if (arg < -1 || arg >= ef_nelem(EF_LAND))
- return RET_SYN;
- if (arg >= 0 && arg != land->lnd_land)
- land->lnd_ship = -1;
- land->lnd_land = arg;
- break;
case 'U':
- ef_set_uid(EF_LAND, land, arg);
- break;
case 'O':
- if (arg < 0 || arg >= MAXNOC)
- return RET_SYN;
- if (arg == land->lnd_own)
- break;
- if (land->lnd_own && land->lnd_own != player->cnum)
- wu(0, land->lnd_own, "%s taken from you by an act of %s!\n",
- prland(land), cname(player->cnum));
- if (arg && arg != player->cnum)
- wu(0, arg, "%s given to you by an act of %s!\n",
- prland(land), cname(player->cnum));
- 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':
- arg = LIMIT_TO(arg, -127, 127);
- land->lnd_mobil = arg;
- break;
+ case 'a':
+ return edit_unit((struct empobj *)land, key, p,
+ LAND_MINEFF, "army");
case 't':
arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
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, 127);
break;
land->lnd_land = -1;
land->lnd_ship = arg;
break;
+ case 'Y':
+ if (arg < -1 || arg >= ef_nelem(EF_LAND))
+ return RET_SYN;
+ if (arg >= 0 && arg != land->lnd_land)
+ land->lnd_ship = -1;
+ land->lnd_land = arg;
+ break;
case 'Z':
arg = LIMIT_TO(arg, 0, 100);
land->lnd_retreat = arg;
case 'r':
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:
}
static int
-edit_plane(struct plnstr *plane, char *key, int arg, char *p)
+edit_plane(struct plnstr *plane, char *key, char *p)
{
struct plchrstr *pcp = &plchr[plane->pln_type];
- coord newx, newy;
+ int arg = atoi(p);
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 (arg == plane->pln_own)
- break;
- if (plane->pln_own && plane->pln_own != player->cnum)
- wu(0, plane->pln_own, "%s taken from you by an act of %s!\n",
- prplane(plane), cname(player->cnum));
- if (arg && arg != player->cnum)
- wu(0, arg, "%s given to you by an act of %s!\n",
- prplane(plane), cname(player->cnum));
- 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, 127);
- break;
+ case 'w':
+ return edit_unit((struct empobj *)plane, key, p,
+ PLANE_MINEFF, "wing");
case 't':
arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
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));
plane->pln_range = (unsigned char)arg;