]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/look.c
Update copyright notice
[empserver] / src / lib / commands / look.c
index 45e316fc8900d71fa22ad5f72aedf582b3cbb7b5..3cfab937c52c4bf93226b8fa23079adc8ce09f5f 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2006-2007
+ *     Markus Armbruster, 2004-2013
  */
 
 #include <config.h>
 
+#include "chance.h"
 #include "commands.h"
 #include "empobj.h"
 #include "map.h"
@@ -55,15 +56,13 @@ llook(void)
 }
 
 int
-do_look(short type)
+do_look(int type)
 {
     int i;
     struct nstr_item ni;
     union empobj_storage unit;
     struct sctstr sect;
     int x, y;
-    int civ;
-    int mil;
     unsigned char *bitmap;
     int changed = 0;
 
@@ -72,7 +71,7 @@ do_look(short 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 +102,9 @@ do_look(short type)
            getsect(x, y, &sect);
            if (sect.sct_type == SCT_WATER)
                continue;
-           if (player->owner)
-               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 +116,29 @@ do_look(short 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;
+
+    pr("%s %s",
+       sp->sct_own == player->cnum ? "Your" : prnatid(sp->sct_own),
+       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)
 {
@@ -188,8 +193,8 @@ look_ship(struct shpstr *lookship)
        /* subs at sea only seen by sonar */
        if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER)
            continue;
-       pr("%s (#%d) %s @ %s\n",
-          cname(sp->shp_own), sp->shp_own, prship(sp),
+       pr("%s %s @ %s\n",
+          prnatid(sp->shp_own), prship(sp),
           xyas(sp->shp_x, sp->shp_y, player->cnum));
        if (opt_HIDDEN)
            setcont(player->cnum, sp->shp_own, FOUND_LOOK);
@@ -217,7 +222,7 @@ look_land(struct lndstr *lookland)
     for (i = 0; NULL != (lp = getlandp(i)); i++) {
        if (lp->lnd_own == player->cnum || lp->lnd_own == 0)
            continue;
-       if (lp->lnd_ship >= 0)
+       if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
            continue;
        /* Don't always see spies */
        if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
@@ -234,9 +239,9 @@ look_land(struct lndstr *lookland)
        if (dist > vrange)
            continue;
 
-       pr("%s (#%d) %s (approx %d mil) @ %s\n",
-          cname(lp->lnd_own), lp->lnd_own,
-          prland(lp), roundintby(lp->lnd_item[I_MILIT], 20),
+       pr("%s %s (approx %d mil) @ %s\n",
+          prnatid(lp->lnd_own), prland(lp),
+          roundintby(lp->lnd_item[I_MILIT], 20),
           xyas(lp->lnd_x, lp->lnd_y, player->cnum));
        if (opt_HIDDEN)
            setcont(player->cnum, lp->lnd_own, FOUND_LOOK);
@@ -244,7 +249,7 @@ look_land(struct lndstr *lookland)
     for (i = 0; NULL != (pp = getplanep(i)); i++) {
        if (pp->pln_own == player->cnum || pp->pln_own == 0)
            continue;
-       if (pp->pln_ship >= 0)
+       if (pp->pln_ship >= 0 || pp->pln_land >= 0)
            continue;
        if (pp->pln_flags & PLN_LAUNCHED)
            continue;
@@ -254,9 +259,9 @@ look_land(struct lndstr *lookland)
        if (dist > vrange)
            continue;
 
-       pr("%s (#%d) %s @ %s\n",
-          cname(pp->pln_own), pp->pln_own,
-          prplane(pp), xyas(pp->pln_x, pp->pln_y, player->cnum));
+       pr("%s %s @ %s\n",
+          prnatid(pp->pln_own), prplane(pp),
+          xyas(pp->pln_x, pp->pln_y, player->cnum));
        if (opt_HIDDEN)
            setcont(player->cnum, pp->pln_own, FOUND_LOOK);
     }