]> git.pond.sub.org Git - empserver/commitdiff
Simplify automatic bmap update from ship radar
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 20 Jun 2010 11:43:16 +0000 (13:43 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 25 Jul 2010 15:34:44 +0000 (17:34 +0200)
Inline radmap2() into radmapupd() and simplify.  Drop unused parameter
seesub.  Rename to rad_map_set().

include/prototypes.h
src/lib/commands/navi.c
src/lib/subs/radmap.c
src/lib/subs/shpsub.c

index 84614d081a169a4b8b3c699baf2aa7bc6598a680..d93c5c945d395158a75ddde7ac6b3a59cb89bb3b 100644 (file)
@@ -584,7 +584,7 @@ extern int ufindpfx(char *, int);
 extern int deltx(struct range *, coord);
 extern int delty(struct range *, coord);
 extern void radmap(int, int, int, int, double);
-extern void radmapupd(int, int, int, int, int, double);
+extern void rad_map_set(natid, int, int, int, int);
 /* rej.c */
 extern int setrel(natid, natid, int);
 extern int setcont(natid, natid, int);
index c59a16ba5e3ee15820b16bae1032c1840c1acbbd..80588449f91c96ae625a3959cc89761affa8fe6f 100644 (file)
@@ -157,11 +157,9 @@ do_unit_move(struct emp_qelem *ulist, int *together,
                cp = buf;
        }
        if (type == EF_SHIP) {
-           radmapupd(player->cnum, leader->x, leader->y, leader->effic,
-                     (int)techfact(leader->tech,
-                                   mchr[leader->type].m_vrnge),
-                     (mchr[leader->type].m_flags & M_SONAR)
-                     ? techfact(leader->tech, 1.0) : 0.0);
+           rad_map_set(player->cnum, leader->x, leader->y, leader->effic,
+                       (int)techfact(leader->tech,
+                                     mchr[leader->type].m_vrnge));
        }
        if (cp == NULL || *cp == '\0')
            cp = &dirch[DIR_STOP];
index 82aee6eee14f56687aa0a946ad67c464c7eb9f36..6f7e625c336d030880e9edf099e84a62f51066fe 100644 (file)
@@ -55,12 +55,6 @@ radmap(int cx, int cy, int eff, int range, double seesub)
     radmap2(player->cnum, cx, cy, eff, range, seesub, 1);
 }
 
-void
-radmapupd(int own, int cx, int cy, int eff, int range, double seesub)
-{
-    radmap2(own, cx, cy, eff, range, seesub, 0);
-}
-
 /* More dynamic world sized buffers.  We create 'em once, and then
  * never again.  No need to keep creating/tearing apart.  We may
  * want to do this in other places too where it doesn't matter. */
@@ -202,3 +196,35 @@ delty(struct range *r, coord y)
        return y - r->ly;
     return y + WORLD_Y - r->ly;
 }
+
+/*
+ * Update OWNER's bmap for radar at CX,CY.
+ * EFF is the radar's efficiency, and RANGE its range at 100%
+ * efficiency.
+ */
+void
+rad_map_set(natid owner, int cx, int cy, int eff, int range)
+{
+    struct nstr_sect ns;
+    struct sctstr sect;
+    int changed = 0;
+    char ch;
+
+    range = (int)(range * (eff / 100.0));
+    if (range < 1)
+       range = 1;
+    snxtsct_dist(&ns, cx, cy, range);
+    while (nxtsct(&ns, &sect)) {
+       if (sect.sct_own == owner
+           || sect.sct_type == SCT_WATER
+           || sect.sct_type == SCT_MOUNT
+           || sect.sct_type == SCT_WASTE
+           || ns.curdist <= range / 3)
+           ch = dchr[sect.sct_type].d_mnem;
+       else
+           ch = '?';
+       changed += map_set(owner, ns.x, ns.y, ch, 0);
+    }
+    if (changed)
+       writemap(owner);
+}
index f1c6b6e19eb9186d252fa6a52aa2b92df8ee2a09..54dc821b9e1c7fe7c24028a2c1d5e43f5c48f5e7 100644 (file)
@@ -733,7 +733,6 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
     int stopping = 0;
     double mobcost;
     double tech;               /* for mapping */
-    double tf;                 /* for mapping */
     char dp[80];
     int navigate;
 
@@ -788,13 +787,9 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
        /* Now update the map for this ship */
        tech = techfact(mlp->unit.ship.shp_tech,
                        ((struct mchrstr *)mlp->chrp)->m_vrnge);
-       if (((struct mchrstr *)mlp->chrp)->m_flags & M_SONAR)
-           tf = techfact(mlp->unit.ship.shp_tech, 1.0);
-       else
-           tf = 0.0;
-       radmapupd(mlp->unit.ship.shp_own,
-                 mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
-                 (int)mlp->unit.ship.shp_effic, (int)tech, tf);
+       rad_map_set(mlp->unit.ship.shp_own,
+                   mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
+                   mlp->unit.ship.shp_effic, (int)tech);
     }
     if (QEMPTY(list))
        return stopping;