Compute radar range in one place, rad_range()
Before, a part was duplicated in radmap() and rad_map_set(), and another part in their callers.
This commit is contained in:
parent
e49cb13480
commit
e41762ca49
5 changed files with 36 additions and 28 deletions
|
@ -583,8 +583,8 @@ extern int ufindpfx(char *, int);
|
||||||
/* radmap.c */
|
/* radmap.c */
|
||||||
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, double, int, double);
|
||||||
extern void rad_map_set(natid, int, int, int, int);
|
extern void rad_map_set(natid, int, int, int, double, 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);
|
||||||
|
|
|
@ -158,8 +158,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
|
||||||
}
|
}
|
||||||
if (type == EF_SHIP) {
|
if (type == EF_SHIP) {
|
||||||
rad_map_set(player->cnum, leader->x, leader->y, leader->effic,
|
rad_map_set(player->cnum, leader->x, leader->y, leader->effic,
|
||||||
(int)techfact(leader->tech,
|
leader->tech, mchr[leader->type].m_vrnge);
|
||||||
mchr[leader->type].m_vrnge));
|
|
||||||
}
|
}
|
||||||
if (cp == NULL || *cp == '\0')
|
if (cp == NULL || *cp == '\0')
|
||||||
cp = &dirch[DIR_STOP];
|
cp = &dirch[DIR_STOP];
|
||||||
|
|
|
@ -54,7 +54,8 @@ radar(int type)
|
||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
double tf;
|
double tf;
|
||||||
double tech;
|
double tlev;
|
||||||
|
int spy;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
union empobj_storage item;
|
union empobj_storage item;
|
||||||
|
@ -73,14 +74,14 @@ radar(int type)
|
||||||
case NS_AREA:
|
case NS_AREA:
|
||||||
if (!snxtsct(&ns, cp))
|
if (!snxtsct(&ns, cp))
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
tech = tfact(player->cnum, 8.0);
|
tlev = getnatp(player->cnum)->nat_level[NAT_TLEV];
|
||||||
while (nxtsct(&ns, &item.sect)) {
|
while (nxtsct(&ns, &item.sect)) {
|
||||||
if (item.sect.sct_type != SCT_RADAR)
|
if (item.sect.sct_type != SCT_RADAR)
|
||||||
continue;
|
continue;
|
||||||
if (!player->owner)
|
if (!player->owner)
|
||||||
continue;
|
continue;
|
||||||
radmap(item.sect.sct_x, item.sect.sct_y, item.sect.sct_effic,
|
radmap(item.sect.sct_x, item.sect.sct_y, item.sect.sct_effic,
|
||||||
(int)(tech * 2.0), 0.0);
|
tlev, 16, 0.0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NS_LIST:
|
case NS_LIST:
|
||||||
|
@ -97,8 +98,7 @@ radar(int type)
|
||||||
if (type == EF_SHIP) {
|
if (type == EF_SHIP) {
|
||||||
if (mchr[(int)item.ship.shp_type].m_flags & M_SONAR)
|
if (mchr[(int)item.ship.shp_type].m_flags & M_SONAR)
|
||||||
tf = techfact(item.ship.shp_tech, 1.0);
|
tf = techfact(item.ship.shp_tech, 1.0);
|
||||||
tech = techfact(item.ship.shp_tech,
|
spy = mchr[item.ship.shp_type].m_vrnge;
|
||||||
mchr[(int)item.ship.shp_type].m_vrnge);
|
|
||||||
} else {
|
} else {
|
||||||
if (!(lchr[(int)item.land.lnd_type].l_flags & L_RADAR)) {
|
if (!(lchr[(int)item.land.lnd_type].l_flags & L_RADAR)) {
|
||||||
pr("%s can't use radar!\n", prland(&item.land));
|
pr("%s can't use radar!\n", prland(&item.land));
|
||||||
|
@ -108,12 +108,12 @@ radar(int type)
|
||||||
pr("Units on ships can't use radar!\n");
|
pr("Units on ships can't use radar!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tech = techfact(item.land.lnd_tech,
|
spy = lchr[item.land.lnd_type].l_spy;
|
||||||
lchr[item.land.lnd_type].l_spy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pr("%s at ", obj_nameof(&item.gen));
|
pr("%s at ", obj_nameof(&item.gen));
|
||||||
radmap(item.gen.x, item.gen.y, item.gen.effic, (int)tech, tf);
|
radmap(item.gen.x, item.gen.y, item.gen.effic,
|
||||||
|
item.gen.tech, spy, tf);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -47,6 +47,8 @@
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
#include "xy.h"
|
#include "xy.h"
|
||||||
|
|
||||||
|
static int rad_range(int, double, int);
|
||||||
|
|
||||||
/* 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. */
|
||||||
|
@ -57,12 +59,11 @@ static signed char *visbuf;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Draw a radar map for radar at CX,CY.
|
* Draw a radar map for radar at CX,CY.
|
||||||
* EFF is the radar's efficiency, and RANGE its range at 100%
|
* EFF is the radar's efficiency, TLEV its tech level, SPY its power.
|
||||||
* efficiency.
|
|
||||||
* Submarines are detected at fraction SEESUB of the range.
|
* Submarines are detected at fraction SEESUB of the range.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
radmap(int cx, int cy, int eff, int range, double seesub)
|
radmap(int cx, int cy, int eff, double tlev, int spy, double seesub)
|
||||||
{
|
{
|
||||||
int visib, rng;
|
int visib, rng;
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
|
@ -73,6 +74,7 @@ radmap(int cx, int cy, int eff, int range, double seesub)
|
||||||
int x, y;
|
int x, y;
|
||||||
int row;
|
int row;
|
||||||
int n;
|
int n;
|
||||||
|
int range = rad_range(eff, tlev, spy);
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
|
|
||||||
if (!radbuf)
|
if (!radbuf)
|
||||||
|
@ -99,9 +101,6 @@ radmap(int cx, int cy, int eff, int range, double seesub)
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(visbuf, 0, (WORLD_Y * (WORLD_X + 1)));
|
memset(visbuf, 0, (WORLD_Y * (WORLD_X + 1)));
|
||||||
range = (int)(range * (eff / 100.0));
|
|
||||||
if (range < 1)
|
|
||||||
range = 1;
|
|
||||||
pr("%s efficiency %d%%, max range %d\n",
|
pr("%s efficiency %d%%, max range %d\n",
|
||||||
xyas(cx, cy, player->cnum), eff, range);
|
xyas(cx, cy, player->cnum), eff, range);
|
||||||
snxtsct_dist(&ns, cx, cy, range);
|
snxtsct_dist(&ns, cx, cy, range);
|
||||||
|
@ -193,20 +192,17 @@ delty(struct range *r, coord y)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update OWNER's bmap for radar at CX,CY.
|
* Update OWNER's bmap for radar at CX,CY.
|
||||||
* EFF is the radar's efficiency, and RANGE its range at 100%
|
* EFF is the radar's efficiency, TLEV its tech level, SPY its power.
|
||||||
* efficiency.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
rad_map_set(natid owner, int cx, int cy, int eff, int range)
|
rad_map_set(natid owner, int cx, int cy, int eff, double tlev, int spy)
|
||||||
{
|
{
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
|
int range = rad_range(eff, tlev, spy);
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
range = (int)(range * (eff / 100.0));
|
|
||||||
if (range < 1)
|
|
||||||
range = 1;
|
|
||||||
snxtsct_dist(&ns, cx, cy, range);
|
snxtsct_dist(&ns, cx, cy, range);
|
||||||
while (nxtsct(&ns, §)) {
|
while (nxtsct(&ns, §)) {
|
||||||
if (sect.sct_own == owner
|
if (sect.sct_own == owner
|
||||||
|
@ -222,3 +218,18 @@ rad_map_set(natid owner, int cx, int cy, int eff, int range)
|
||||||
if (changed)
|
if (changed)
|
||||||
writemap(owner);
|
writemap(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Range of a radar with EFF efficiency, TLEV tech, and SPY power.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
rad_range(int eff, double tlev, int spy)
|
||||||
|
{
|
||||||
|
int range;
|
||||||
|
|
||||||
|
range = (int)techfact(tlev, spy);
|
||||||
|
range = (int)(range * (eff / 100.0));
|
||||||
|
if (range < 1)
|
||||||
|
range = 1;
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
|
|
@ -732,7 +732,6 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
|
||||||
coord newy;
|
coord newy;
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
double mobcost;
|
double mobcost;
|
||||||
double tech; /* for mapping */
|
|
||||||
char dp[80];
|
char dp[80];
|
||||||
int navigate;
|
int navigate;
|
||||||
|
|
||||||
|
@ -785,11 +784,10 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
|
||||||
putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
|
putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
|
||||||
|
|
||||||
/* Now update the map for this ship */
|
/* Now update the map for this ship */
|
||||||
tech = techfact(mlp->unit.ship.shp_tech,
|
|
||||||
((struct mchrstr *)mlp->chrp)->m_vrnge);
|
|
||||||
rad_map_set(mlp->unit.ship.shp_own,
|
rad_map_set(mlp->unit.ship.shp_own,
|
||||||
mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
|
mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
|
||||||
mlp->unit.ship.shp_effic, (int)tech);
|
mlp->unit.ship.shp_effic, mlp->unit.ship.shp_tech,
|
||||||
|
((struct mchrstr *)mlp->chrp)->m_vrnge);
|
||||||
}
|
}
|
||||||
if (QEMPTY(list))
|
if (QEMPTY(list))
|
||||||
return stopping;
|
return stopping;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue