]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/look.c
Fix bitmap overruns when WORLD_X * WORLD_Y not a multiple of 16
[empserver] / src / lib / commands / look.c
index 95a217afd17ddd516340b766aecf6bff3b6aab99..fffd99b5d339af8a400be83d7feb23073f242137 100644 (file)
@@ -62,8 +62,6 @@ do_look(int type)
     union empobj_storage unit;
     struct sctstr sect;
     int x, y;
-    int civ;
-    int mil;
     unsigned char *bitmap;
     int changed = 0;
 
@@ -72,7 +70,7 @@ do_look(int type)
 
     if (!snxtitem(&ni, type, player->argp[1], NULL))
        return RET_SYN;
-    bitmap = calloc(WORLD_SZ() / 8, 1);
+    bitmap = calloc((WORLD_SZ() + 7) / 8, 1);
     if (!bitmap) {
        logerror("malloc failed in do_look\n");
        pr("Memory error.  Tell the deity.\n");
@@ -103,26 +101,9 @@ do_look(int type)
            getsect(x, y, &sect);
            if (sect.sct_type == SCT_WATER)
                continue;
-           if (sect.sct_own == player->cnum)
-               pr("Your ");
-           else
-               pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
-           pr("%s", dchr[sect.sct_type].d_name);
+           look_at_sect(&sect, 10);
            changed += map_set(player->cnum, x, y,
                               dchr[sect.sct_type].d_mnem, 0);
-           pr(" %d%% efficient ", player->owner ? sect.sct_effic :
-              roundintby((int)sect.sct_effic, 10));
-           civ = sect.sct_item[I_CIVIL];
-           mil = sect.sct_item[I_MILIT];
-           if (civ)
-               pr("with %s%d civ ",
-                  player->owner ? "" : "approx ",
-                  player->owner ? civ : roundintby(civ, 10));
-           if (mil)
-               pr("with %s%d mil ",
-                  player->owner ? "" : "approx ",
-                  player->owner ? mil : roundintby(mil, 10));
-           pr("@ %s\n", xyas(x, y, player->cnum));
            if (opt_HIDDEN) {
                setcont(player->cnum, sect.sct_own, FOUND_LOOK);
            }
@@ -134,6 +115,31 @@ do_look(int type)
     return RET_OK;
 }
 
+void look_at_sect(struct sctstr *sp, int mult)
+{
+    int civ, mil;
+    int ours = player->god || sp->sct_own == player->cnum;
+
+    if (sp->sct_own == player->cnum)
+       pr("Your ");
+    else
+       pr("%s (#%d) ", cname(sp->sct_own), sp->sct_own);
+    pr("%s", dchr[sp->sct_type].d_name);
+    pr(" %d%% efficient ",
+       ours ? sp->sct_effic : roundintby(sp->sct_effic, mult));
+    civ = sp->sct_item[I_CIVIL];
+    mil = sp->sct_item[I_MILIT];
+    if (civ)
+       pr("with %s%d civ ",
+          ours ? "" : "approx ",
+          ours ? civ : roundintby(civ, mult));
+    if (mil)
+       pr("with %s%d mil ",
+          ours ? "" : "approx ",
+          ours ? mil : roundintby(mil, mult));
+    pr("@ %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
+}
+
 static void
 look_ship(struct shpstr *lookship)
 {