Simplify automatic bmap update from ship radar

Inline radmap2() into radmapupd() and simplify.  Drop unused parameter
seesub.  Rename to rad_map_set().
This commit is contained in:
Markus Armbruster 2010-06-20 13:43:16 +02:00
parent 27f22f36bb
commit 0d477e5df1
4 changed files with 39 additions and 20 deletions

View file

@ -584,7 +584,7 @@ extern int ufindpfx(char *, int);
extern int deltx(struct range *, coord); extern int deltx(struct range *, coord);
extern int delty(struct range *, coord); extern int delty(struct range *, coord);
extern void radmap(int, int, int, int, double); 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 */ /* rej.c */
extern int setrel(natid, natid, int); extern int setrel(natid, natid, int);
extern int setcont(natid, natid, int); extern int setcont(natid, natid, int);

View file

@ -157,11 +157,9 @@ do_unit_move(struct emp_qelem *ulist, int *together,
cp = buf; cp = buf;
} }
if (type == EF_SHIP) { if (type == EF_SHIP) {
radmapupd(player->cnum, leader->x, leader->y, leader->effic, rad_map_set(player->cnum, leader->x, leader->y, leader->effic,
(int)techfact(leader->tech, (int)techfact(leader->tech,
mchr[leader->type].m_vrnge), mchr[leader->type].m_vrnge));
(mchr[leader->type].m_flags & M_SONAR)
? techfact(leader->tech, 1.0) : 0.0);
} }
if (cp == NULL || *cp == '\0') if (cp == NULL || *cp == '\0')
cp = &dirch[DIR_STOP]; cp = &dirch[DIR_STOP];

View 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); 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 /* More dynamic world sized buffers. We create 'em once, and then
* never again. No need to keep creating/tearing apart. We may * never again. No need to keep creating/tearing apart. We may
* want to do this in other places too where it doesn't matter. */ * 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 - r->ly;
return y + WORLD_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);
}

View file

@ -733,7 +733,6 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
int stopping = 0; int stopping = 0;
double mobcost; double mobcost;
double tech; /* for mapping */ double tech; /* for mapping */
double tf; /* for mapping */
char dp[80]; char dp[80];
int navigate; 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 */ /* Now update the map for this ship */
tech = techfact(mlp->unit.ship.shp_tech, tech = techfact(mlp->unit.ship.shp_tech,
((struct mchrstr *)mlp->chrp)->m_vrnge); ((struct mchrstr *)mlp->chrp)->m_vrnge);
if (((struct mchrstr *)mlp->chrp)->m_flags & M_SONAR) rad_map_set(mlp->unit.ship.shp_own,
tf = techfact(mlp->unit.ship.shp_tech, 1.0); mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
else mlp->unit.ship.shp_effic, (int)tech);
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);
} }
if (QEMPTY(list)) if (QEMPTY(list))
return stopping; return stopping;