]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/edit.c
edit: Report ship and land unit commodity change properly
[empserver] / src / lib / commands / edit.c
index f003514f7d091ec108dae2f4480640059ffc2a4b..018e256c9a2f07922582b850a393b1c5e0949189 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <ctype.h>
 #include <limits.h>
+#include "actofgod.h"
 #include "commands.h"
 #include "item.h"
 #include "land.h"
@@ -52,12 +53,11 @@ 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)
@@ -67,10 +67,8 @@ edit(void)
     struct shpstr ship;
     struct lndstr land;
     char *what;
-    char *ptr;
-    char thing;
+    char *key, *ptr;
     int num;
-    int arg;
     int err;
     int arg_index = 3;
     coord x, y;
@@ -145,16 +143,15 @@ edit(void)
     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) {
+           if (!*key) {
                switch (ewhat) {
                case 'c':
                    print_nat(np);
@@ -174,20 +171,18 @@ edit(void)
                }
                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(&sect))
                return RET_FAIL;
-           if ((err = edit_sect(&sect, thing, arg, ptr)) != RET_OK)
+           if ((err = edit_sect(&sect, key, ptr)) != RET_OK)
                return err;
            if (!putsect(&sect))
                return RET_FAIL;
@@ -195,7 +190,7 @@ edit(void)
        case 's':
            if (!check_ship_ok(&ship))
                return RET_FAIL;
-           if ((err = edit_ship(&ship, thing, 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;
@@ -205,7 +200,7 @@ edit(void)
        case 'u':
            if (!check_land_ok(&land))
                return RET_FAIL;
-           if ((err = edit_land(&land, thing, 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;
@@ -215,7 +210,7 @@ edit(void)
        case 'p':
            if (!check_plane_ok(&plane))
                return RET_FAIL;
-           if ((err = edit_plane(&plane, thing, 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;
@@ -227,31 +222,17 @@ edit(void)
 }
 
 static void
-benefit(natid who, int good)
+benefit(natid who, int goodness)
 {
-    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);
-    }
+    if (opt_GODNEWS && getnatp(who)->nat_stat != STAT_GOD && goodness)
+       nreport(player->cnum, goodness > 0 ? N_AIDS : 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
@@ -396,27 +377,26 @@ print_ship(struct shpstr *ship)
     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 */
@@ -427,39 +407,34 @@ warn_deprecated(char key)
 }
 #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':
@@ -473,27 +448,27 @@ edit_sect(struct sctstr *sect, char op, int arg, char *p)
        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;
@@ -504,47 +479,45 @@ edit_sect(struct sctstr *sect, char op, int arg, char *p)
        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':
        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':
@@ -554,23 +527,80 @@ edit_sect(struct sctstr *sect, char op, int arg, char *p)
        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, &sect, 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;
@@ -578,9 +608,9 @@ edit_sect(struct sctstr *sect, char op, int arg, char *p)
        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;
@@ -588,41 +618,26 @@ edit_sect(struct sctstr *sect, char op, int arg, char *p)
        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 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;
+    int arg = atoi(p);
     float farg = (float)atof(p);
 
-    switch (op) {
+    switch (*key) {
     case 'n':
        if (!check_nat_name(p, nat))
            return RET_SYN;
@@ -645,12 +660,15 @@ edit_nat(struct natstr *np, char op, int arg, char *p)
        break;
     case 'm':
        arg = LIMIT_TO(arg, 0, INT_MAX);
-       benefit(nat, np->nat_reserve < arg);
+       benefit(nat, arg - np->nat_reserve);
        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);
+       if (arg == np->nat_reserve)
+           break;
+       if (nat != player->cnum)
+           wu(0, nat,
+              "Military reserves changed from %d to %d by an act of %s\n",
+              np->nat_reserve, arg, cname(player->cnum));
        np->nat_reserve = arg;
        break;
     case 'c':
@@ -682,9 +700,11 @@ edit_nat(struct natstr *np, char op, int arg, char *p)
        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);
+       if (arg == np->nat_money)
+           break;
+       if (nat != player->cnum)
+           wu(0, nat, "Money changed from %d to %d by an act of %s\n",
+              np->nat_money, arg, cname(player->cnum));
        np->nat_money = arg;
        break;
     case 'T':
@@ -712,7 +732,7 @@ edit_nat(struct natstr *np, char op, int arg, char *p)
        np->nat_level[NAT_HLEV] = farg;
        break;
     default:
-       pr("huh? (%c)\n", op);
+       pr("huh? (%s)\n", key);
        break;
     }
     putnat(np);
@@ -720,13 +740,15 @@ edit_nat(struct natstr *np, char op, int arg, char *p)
 }
 
 static int
-edit_ship(struct shpstr *ship, char op, int arg, char *p)
+edit_ship(struct shpstr *ship, char *key, char *p)
 {
     struct mchrstr *mcp = &mchr[ship->shp_type];
+    int arg = atoi(p);
     coord newx, newy;
+    struct ichrstr *ip;
 
     newx = newy = 0;
-    switch (op) {
+    switch (*key) {
     case 'a':
        arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
        ship->shp_pstage = arg;
@@ -747,12 +769,14 @@ edit_ship(struct shpstr *ship, char op, int arg, char *p)
     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));
+       if (arg == ship->shp_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 (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;
        break;
     case 'L':
@@ -783,72 +807,45 @@ edit_ship(struct shpstr *ship, char op, int arg, char *p)
        }
        break;
     case 'c':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_CIVIL]);
-       ship->shp_item[I_CIVIL] = arg;
-       break;
     case 'm':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_MILIT]);
-       ship->shp_item[I_MILIT] = arg;
-       break;
     case 'u':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_UW]);
-       ship->shp_item[I_UW] = arg;
-       break;
     case 'f':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_FOOD]);
-       ship->shp_item[I_FOOD] = arg;
-       break;
     case 's':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_SHELL]);
-       ship->shp_item[I_SHELL] = arg;
-       break;
     case 'g':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_GUN]);
-       ship->shp_item[I_GUN] = arg;
-       break;
     case 'p':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_PETROL]);
-       ship->shp_item[I_PETROL] = arg;
-       break;
     case 'i':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_IRON]);
-       ship->shp_item[I_IRON] = arg;
-       break;
     case 'd':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_DUST]);
-       ship->shp_item[I_DUST] = arg;
-       break;
     case 'o':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_OIL]);
-       ship->shp_item[I_OIL] = arg;
-       break;
     case 'l':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_LCM]);
-       ship->shp_item[I_LCM] = arg;
-       break;
     case 'h':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_HCM]);
-       ship->shp_item[I_HCM] = arg;
-       break;
     case 'r':
-       arg = LIMIT_TO(arg, 0, mcp->m_item[I_RAD]);
-       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)
 {
     struct lchrstr *lcp = &lchr[land->lnd_type];
+    int arg = atoi(p);
     coord newx, newy;
+    struct ichrstr *ip;
 
     newx = newy = 0;
-    switch (op) {
+    switch (*key) {
     case 'Y':
        if (arg < -1 || arg >= ef_nelem(EF_LAND))
            return RET_SYN;
@@ -862,12 +859,14 @@ edit_land(struct lndstr *land, char op, int arg, char *p)
     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));
+       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':
@@ -918,71 +917,43 @@ edit_land(struct lndstr *land, char op, int arg, char *p)
        land->lnd_rflags = arg;
        break;
     case 'c':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_CIVIL]);
-       land->lnd_item[I_CIVIL] = arg;
-       break;
     case 'm':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_MILIT]);
-       land->lnd_item[I_MILIT] = arg;
-       break;
     case 'u':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_UW]);
-       land->lnd_item[I_UW] = arg;
-       break;
     case 'f':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_FOOD]);
-       land->lnd_item[I_FOOD] = arg;
-       break;
     case 's':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_SHELL]);
-       land->lnd_item[I_SHELL] = arg;
-       break;
     case 'g':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_GUN]);
-       land->lnd_item[I_GUN] = arg;
-       break;
     case 'p':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_PETROL]);
-       land->lnd_item[I_PETROL] = arg;
-       break;
     case 'i':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_IRON]);
-       land->lnd_item[I_IRON] = arg;
-       break;
     case 'd':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_DUST]);
-       land->lnd_item[I_DUST] = arg;
-       break;
     case 'o':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_OIL]);
-       land->lnd_item[I_OIL] = arg;
-       break;
     case 'l':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_LCM]);
-       land->lnd_item[I_LCM] = arg;
-       break;
     case 'h':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_HCM]);
-       land->lnd_item[I_HCM] = arg;
-       break;
     case 'r':
-       arg = LIMIT_TO(arg, 0, lcp->l_item[I_RAD]);
-       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)
 {
     struct plchrstr *pcp = &plchr[plane->pln_type];
+    int arg = atoi(p);
     coord newx, newy;
 
-    switch (op) {
+    switch (*key) {
     case 'U':
        ef_set_uid(EF_PLANE, plane, arg);
        break;
@@ -995,13 +966,14 @@ edit_plane(struct plnstr *plane, char op, int arg, char *p)
     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));
+       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 'e':
@@ -1046,7 +1018,7 @@ edit_plane(struct plnstr *plane, char op, int arg, char *p)
        plane->pln_flags = arg;
        break;
     default:
-       pr("huh? (%c)\n", op);
+       pr("huh? (%s)\n", key);
        return RET_FAIL;
     }
     return RET_OK;