Don't store ship stats in struct shpstr

New shp_armor(), shp_speed(), shp_visib(), shp_frnge(), shp_glim()
replace the struct shpstr members with the same names.
This commit is contained in:
Markus Armbruster 2008-03-04 21:15:59 +01:00
parent ffc5d0cfd7
commit f86d726406
13 changed files with 73 additions and 45 deletions

View file

@ -79,11 +79,6 @@ struct shpstr {
/* end of part matching struct empobj */
unsigned char shp_nplane; /* number of planes on board */
unsigned char shp_nland; /* number of land units on board */
short shp_armor;
short shp_speed;
short shp_visib;
short shp_frnge;
short shp_glim;
coord shp_destx[2]; /* location for ship destination */
coord shp_desty[2];
i_type shp_tstart[TMAX]; /* what goods to pick up at start point */
@ -182,6 +177,11 @@ extern int m_speed(struct mchrstr *, int);
extern int m_visib(struct mchrstr *, int);
extern int m_frnge(struct mchrstr *, int);
extern int m_glim(struct mchrstr *, int);
extern int shp_armor(struct shpstr *);
extern int shp_speed(struct shpstr *);
extern int shp_visib(struct shpstr *);
extern int shp_frnge(struct shpstr *);
extern int shp_glim(struct shpstr *);
extern int shp_dchrg(struct shpstr *);
extern int shp_fire(struct shpstr *);

View file

@ -161,9 +161,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);

View file

@ -183,7 +183,7 @@ multifire(void)
pr("Not enough mil on ship #%d\n", item.ship.shp_uid);
continue;
}
if (item.ship.shp_glim == 0) {
if (mchr[item.ship.shp_type].m_glim == 0) {
pr("Ships %d cannot fire guns!\n", item.ship.shp_uid);
continue;
}

View file

@ -354,19 +354,19 @@ sdump(void)
pr(" %d", ship.shp_item[I_RAD]);
break;
case 27:
pr(" %d", ship.shp_armor);
pr(" %d", shp_armor(&ship));
break;
case 28:
pr(" %d", ship.shp_speed);
pr(" %d", shp_speed(&ship));
break;
case 29:
pr(" %d", ship.shp_visib);
pr(" %d", shp_visib(&ship));
break;
case 30:
pr(" %d", ship.shp_frnge);
pr(" %d", shp_frnge(&ship));
break;
case 31:
pr(" %d", ship.shp_glim);
pr(" %d", shp_glim(&ship));
break;
case 32:
/*

View file

@ -56,7 +56,7 @@ sona(void)
struct mchrstr *tmcp;
struct nstr_sect ns;
int range;
int pingrange;
int visib, pingrange;
int srange;
int vrange;
int dist;
@ -147,7 +147,8 @@ sona(void)
if (targ.shp_own == player->cnum || targ.shp_own == 0)
continue;
tmcp = &mchr[(int)targ.shp_type];
pingrange = MIN(7, MAX(targ.shp_visib, 10) * range / 10);
visib = shp_visib(&targ);
pingrange = MIN(7, MAX(visib, 10) * range / 10);
vrange = pingrange * ship.shp_effic / 200;
dist = mapdist(targ.shp_x, targ.shp_y, ship.shp_x, ship.shp_y);
pingrange = (MAX(pingrange, 2) * targ.shp_effic) / 100;
@ -173,11 +174,11 @@ sona(void)
continue;
if (tmcp->m_flags & M_SUB &&
getrel(getnatp(targ.shp_own), player->cnum) < FRIENDLY) {
if (mcp->m_vrnge + targ.shp_visib < 8)
if (mcp->m_vrnge + visib < 8)
pr("Sonar detects sub #%d @ %s\n",
targ.shp_uid,
xyas(targ.shp_x, targ.shp_y, player->cnum));
else if (mcp->m_vrnge + targ.shp_visib < 10)
else if (mcp->m_vrnge + visib < 10)
pr("Sonar detects %s @ %s\n",
prship(&targ),
xyas(targ.shp_x, targ.shp_y, player->cnum));
@ -190,8 +191,8 @@ sona(void)
cname(targ.shp_own), prship(&targ),
xyas(targ.shp_x, targ.shp_y, player->cnum));
if (targ.shp_visib > vis[y][x]) {
vis[y][x] = targ.shp_visib;
if (visib > vis[y][x]) {
vis[y][x] = visib;
/* &~0x20 makes it a cap letter */
rad[y][x] = (*mchr[(int)targ.shp_type].m_name) & ~0x20;
}
@ -224,7 +225,7 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
struct plist *ip;
struct sctstr sect;
int found = 0;
int range, i;
int range, i, vis;
int pingrange;
int vrange;
int dist;
@ -252,7 +253,8 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
if (roll(100) > pln_identchance(pp, shp_hardtarget(targ),
EF_SHIP))
continue;
pingrange = MAX(targ->shp_visib, 10) * range / 10;
vis = shp_visib(targ);
pingrange = MAX(vis, 10) * range / 10;
vrange = pingrange * (pp->pln_effic / 200.0);
dist = mapdist(targ->shp_x, targ->shp_y, x, y);
pingrange = (MAX(pingrange, 2) * targ->shp_effic);

View file

@ -63,8 +63,8 @@ sstat(void)
pr(" %3d%% %4d %3d %3d %3d %3d %3d",
ship.shp_effic,
ship.shp_tech,
ship.shp_armor,
ship.shp_speed, ship.shp_visib, ship.shp_frnge, ship.shp_glim);
shp_armor(&ship), shp_speed(&ship), shp_visib(&ship),
shp_frnge(&ship), shp_glim(&ship));
pr("\n");
}
if (nships == 0) {

View file

@ -88,3 +88,33 @@ m_glim(struct mchrstr *mcp, int tech)
{
return SHP_FIR(mcp->m_glim, MAX(0, tech - mcp->m_tech));
}
int
shp_armor(struct shpstr *sp)
{
return m_armor(mchr + sp->shp_type, sp->shp_tech);
}
int
shp_speed(struct shpstr *sp)
{
return m_speed(mchr + sp->shp_type, sp->shp_tech);
}
int
shp_visib(struct shpstr *sp)
{
return m_visib(mchr + sp->shp_type, sp->shp_tech);
}
int
shp_frnge(struct shpstr *sp)
{
return m_frnge(mchr + sp->shp_type, sp->shp_tech);
}
int
shp_glim(struct shpstr *sp)
{
return m_glim(mchr + sp->shp_type, sp->shp_tech);
}

View file

@ -576,8 +576,8 @@ board_abort(struct combat *off, struct combat *def)
}
getship(off->shp_uid, &aship);
getship(def->shp_uid, &dship);
if (techfact(aship.shp_tech, 1.0) * aship.shp_speed * off->eff
<= techfact(dship.shp_tech, 1.0) * dship.shp_speed * def->eff) {
if (techfact(aship.shp_tech, shp_speed(&aship)) * off->eff
<= techfact(dship.shp_tech, shp_speed(&dship)) * def->eff) {
pr("Victim ship moves faster than you do!\n");
if (def->own)
wu(0, def->own,
@ -893,7 +893,7 @@ calc_mobcost(int combat_mode, struct combat *off, struct combat *def,
case EF_SHIP:
/* the 2 in the formula below is a fudge factor */
getship(def->shp_uid, &ship);
off->mobcost += (def->eff / 100) * (ship.shp_speed / 2);
off->mobcost += (def->eff / 100) * (shp_speed(&ship) / 2);
}
}
}
@ -1141,7 +1141,7 @@ att_combat_eff(struct combat *com)
eff = sector_strength(getsectp(com->x, com->y));
} else if (com->type == EF_SHIP && com->own != player->cnum) {
getship(com->shp_uid, &ship);
eff = 1.0 + ship.shp_armor / 100.0;
eff = 1.0 + shp_armor(&ship) / 100.0;
}
return eff;
}

View file

@ -82,7 +82,7 @@ ship_damage(struct shpstr *sp, int dam)
void
shipdamage(struct shpstr *sp, int dam)
{
ship_damage(sp, (int)(dam / (1.0 + sp->shp_armor / 100.0)));
ship_damage(sp, (int)(dam / (1.0 + shp_armor(sp) / 100.0)));
}
void

View file

@ -222,7 +222,7 @@ lnd_fire(struct lndstr *lp)
int
shp_usable_guns(struct shpstr *sp)
{
return MIN(sp->shp_glim, sp->shp_item[I_GUN]);
return MIN(shp_glim(sp), sp->shp_item[I_GUN]);
}
/*
@ -259,7 +259,7 @@ fortrange(struct sctstr *sp)
double
shp_fire_range(struct shpstr *sp)
{
return effrange(sp->shp_frnge, sp->shp_tech);
return effrange(shp_frnge(sp), sp->shp_tech);
}
/*
@ -268,7 +268,7 @@ shp_fire_range(struct shpstr *sp)
double
torprange(struct shpstr *sp)
{
return effrange(sp->shp_frnge * 2, sp->shp_tech)
return effrange(shp_frnge(sp) * 2, sp->shp_tech)
* sp->shp_effic / 100.0;
}
@ -278,7 +278,7 @@ torprange(struct shpstr *sp)
double
shp_torp_hitchance(struct shpstr *sp, int range)
{
return DTORP_HITCHANCE(range, sp->shp_visib);
return DTORP_HITCHANCE(range, shp_visib(sp));
}
/*

View file

@ -79,7 +79,7 @@ static void
radmap2(int owner,
int cx, int cy, int eff, int range, double seesub, int pr_flag)
{
int rng;
int visib, rng;
struct sctstr sect;
struct shpstr ship;
struct plnstr plane;
@ -158,14 +158,15 @@ radmap2(int owner,
x = deltx(&ns.range, (int)ship.shp_x);
y = delty(&ns.range, (int)ship.shp_y);
rng = (int)(range * ship.shp_visib / 20.0);
visib = shp_visib(&ship);
rng = (int)(range * visib / 20.0);
if (ni.curdist > rng)
continue;
if ((mchr[(int)ship.shp_type].m_flags & M_SUB) &&
ni.curdist > rng * seesub)
continue;
if (ship.shp_visib > vis[y][x]) {
vis[y][x] = ship.shp_visib;
if (visib > vis[y][x]) {
vis[y][x] = visib;
/* &~0x20 makes it a cap letter */
rad[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
}

View file

@ -690,13 +690,13 @@ shp_hardtarget(struct shpstr *sp)
int vis, onsea;
struct mchrstr *mcp = mchr + sp->shp_type;
vis = sp->shp_visib;
vis = shp_visib(sp);
getsect(sp->shp_x, sp->shp_y, &sect);
onsea = sect.sct_type == SCT_WATER;
if (mcp->m_flags & M_SUB)
vis *= 4;
return (int)((sp->shp_effic / 100.0) *
(20 + sp->shp_speed * onsea / 2.0 - vis));
(20 + shp_speed(sp) * onsea / 2.0 - vis));
}
static int
@ -952,7 +952,7 @@ shp_missdef(struct shpstr *sp, natid victim)
double
shp_mobcost(struct shpstr *sp)
{
return speed_factor(sp->shp_effic * 0.01 * sp->shp_speed,
return speed_factor(sp->shp_effic * 0.01 * shp_speed(sp),
sp->shp_tech);
}
@ -968,9 +968,4 @@ shp_set_tech(struct shpstr *sp, int tlev)
tlev = mcp->m_tech;
sp->shp_tech = tlev;
sp->shp_armor = m_armor(mcp, tlev);
sp->shp_speed = m_speed(mcp, tlev);
sp->shp_visib = m_visib(mcp, tlev);
sp->shp_frnge = m_frnge(mcp, tlev);
sp->shp_glim = m_glim(mcp, tlev);
}

View file

@ -291,7 +291,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
wf = 0;
/* only military can work on a military boat */
if (ship->shp_glim > 0)
if (mp->m_glim != 0)
wf = etus * ship->shp_item[I_MILIT] / 2;
else
wf = etus * (ship->shp_item[I_CIVIL] / 2 + ship->shp_item[I_MILIT] / 5);