]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/look.c
Make llook ignore land units and planes loaded on land units
[empserver] / src / lib / commands / look.c
index 6850a9a5f873975eebad786973c896ed3dfbed79..55dd15e2051c483c3191a94cec668f172d0cd7a1 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2011, 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/>.
  *
  *  ---
  *
@@ -26,9 +25,9 @@
  *  ---
  *
  *  look.c: Lookout from a ship or land unit
- * 
+ *
  *  Known contributors to this file:
- *     
+ *     Ron Koenderink, 2006-2007
  */
 
 #include <config.h>
@@ -39,7 +38,6 @@
 #include "optlist.h"
 #include "path.h"
 
-static int do_look(short type);
 static void look_ship(struct shpstr *lookship);
 static void look_land(struct lndstr *lookland);
 
@@ -55,27 +53,28 @@ llook(void)
     return do_look(EF_LAND);
 }
 
-static int
-do_look(short type)
+int
+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;
 
-    if (!snxtitem(&ni, type, player->argp[1]))
+    if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
+       type = EF_SHIP;
+
+    if (!snxtitem(&ni, type, player->argp[1], NULL))
        return RET_SYN;
-    if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
+    bitmap = calloc((WORLD_SZ() + 7) / 8, 1);
+    if (!bitmap) {
        logerror("malloc failed in do_look\n");
        pr("Memory error.  Tell the deity.\n");
        return RET_FAIL;
     }
-    memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
     while (nxtitem(&ni, &unit)) {
        if (!player->owner)
            continue;
@@ -101,26 +100,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);
            }
@@ -132,6 +114,31 @@ 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;
+
+    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)
 {
@@ -159,9 +166,9 @@ look_ship(struct shpstr *lookship)
            continue;
        tmcp = &mchr[(int)sp->shp_type];
        if (smcp->m_flags & M_SUB)
-           vrange = (int)(sp->shp_visib * range / 30.0);
+           vrange = (int)(shp_visib(sp) * range / 30.0);
        else
-           vrange = (int)(sp->shp_visib * range / 20.0);
+           vrange = (int)(shp_visib(sp) * range / 20.0);
        getsect(sp->shp_x, sp->shp_y, &sect);
        if (sect.sct_type != SCT_WATER)
            vrange = MAX(1, vrange);
@@ -205,7 +212,7 @@ look_land(struct lndstr *lookland)
     int i;
     int dist;
 
-    drange = techfact(lookland->lnd_tech, lookland->lnd_spy);
+    drange = techfact(lookland->lnd_tech, lchr[lookland->lnd_type].l_spy);
     drange *= lookland->lnd_effic / 100.0;
     range = ldround(drange, 1);
 
@@ -215,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) {
@@ -226,7 +233,7 @@ look_land(struct lndstr *lookland)
            if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
                continue;
        }
-       vrange = ldround((lp->lnd_vis * range) / 20.0, 1);
+       vrange = ldround((lnd_vis(lp) * range) / 20.0, 1);
        dist = mapdist(lp->lnd_x, lp->lnd_y,
                       lookland->lnd_x, lookland->lnd_y);
        if (dist > vrange)
@@ -242,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;