New unit stat development functions

The macros defining unit stat development in tech are somewhat
inconvenient to use.  Define more convenient functions, and hide away
the macros near the function definitions.
This commit is contained in:
Markus Armbruster 2008-02-29 06:49:18 +01:00
parent 3d0e083aec
commit 0219bf086a
10 changed files with 222 additions and 118 deletions

View file

@ -142,32 +142,6 @@ struct lchrstr {
#define L_TRAIN bit(11) /* train unit - neato */
#define L_HEAVY bit(12) /* heavy unit - can't go on trains */
#define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))) \
> 127 ? 127 : \
((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))))
#define LND_SPD(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 2.1))) > 127 \
? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 2.1))))
#define LND_VUL(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0 \
? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
#define LND_VIS(b, t) (b)
#define LND_SPY(b, t) (b)
#define LND_RAD(b, t) (b)
#define LND_FRG(b, t) ((t) ? \
((b) * (logx((t), 35.0) < 1.0 ? 1.0 : \
logx((t), 35.0))) : (b))
#define LND_DAM(b, t) ((t) ? \
((b) * (logx((t), 60.0) < 1.0 ? 1.0 : \
logx((t), 60.0))) : (b))
#define LND_ACC(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0 \
? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
#define LND_AMM(b, t) (b)
#define LND_AAF(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 3.0))) > 127 \
? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 3.0))))
#define LND_FC(b, t) (b)
#define LND_FU(b, t) (b)
#define LND_XPL(b, t) (b)
#define LND_MXL(b, t) (b)
/* Work required for building 100% */
#define LND_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm))
@ -184,6 +158,15 @@ enum {
LND_AIROPS_EFF = 50 /* min. efficiency for air ops */
};
extern float l_att(struct lchrstr *, int);
extern float l_def(struct lchrstr *, int);
extern int l_vul(struct lchrstr *, int);
extern int l_spd(struct lchrstr *, int);
extern int l_frg(struct lchrstr *, int);
extern int l_acc(struct lchrstr *, int);
extern int l_dam(struct lchrstr *, int);
extern int l_aaf(struct lchrstr *, int);
/* src/lib/subs/lndsub.c */
extern void lnd_sweep(struct emp_qelem *, int, int, natid);
extern int lnd_interdict(struct emp_qelem *, coord, coord, natid);

View file

@ -146,15 +146,15 @@ struct shiplist {
struct shiplist *next;
};
#define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))
#define PLN_ACC(b, t) (b * (1.0 - (sqrt(t) / 50.)))
#define PLN_RAN(b, t) (t ? (b + (logx(t, 2.0))) : b)
#define PLN_LOAD(b, t) (t ? (b * (logx(t, 50.0) < 1.0 ? 1.0 : \
logx(t, 50.0))) : b)
/* Work required for building 100% */
#define PLN_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm))
extern int pl_att(struct plchrstr *, int);
extern int pl_def(struct plchrstr *, int);
extern int pl_acc(struct plchrstr *, int);
extern int pl_range(struct plchrstr *, int);
extern int pl_load(struct plchrstr *, int);
/* src/lib/subs/aircombat.c */
extern void ac_combat_headers(natid, natid);
extern void ac_airtoair(struct emp_qelem *, struct emp_qelem *);

View file

@ -163,16 +163,6 @@ struct mchrstr {
extern struct mchrstr mchr[SHP_TYPE_MAX + 2];
#define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \
logx(t, 40.0))) : b)
#define SHP_SPD(b, t) (t ? (b * (logx(t, 35.0) < 1.0 ? 1.0 : \
logx(t, 35.0))) : b)
#define SHP_VIS(b, t) (b * (1 - (sqrt(t) / 50)))
#define SHP_RNG(b, t) (t ? (b * (logx(t, 35.0) < 1.0 ? 1.0 : \
logx(t, 35.0))) : b)
#define SHP_FIR(b, t) (t ? (b * (logx(t, 60.0) < 1.0 ? 1.0 : \
logx(t, 60.0))) : b)
/* Work required for building 100% */
#define SHP_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm))
@ -187,4 +177,10 @@ enum {
SHP_TORP_SHELLS = 3 /* number of shells used by a torpedo */
};
extern int m_armor(struct mchrstr *, int);
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);
#endif

View file

@ -35,6 +35,8 @@
#include <config.h>
#include <math.h>
#include "misc.h"
#include "land.h"
/*
@ -43,3 +45,78 @@
* Terminated by a sentinel with null l_name.
*/
struct lchrstr lchr[LND_TYPE_MAX + 2];
#define logx(a, b) (log((a)) / log((b)))
#define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))) \
> 127 ? 127 : \
((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))))
#define LND_SPD(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 2.1))) > 127 \
? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 2.1))))
#define LND_VUL(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0 \
? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
#define LND_VIS(b, t) (b)
#define LND_SPY(b, t) (b)
#define LND_RAD(b, t) (b)
#define LND_FRG(b, t) ((t) ? \
((b) * (logx((t), 35.0) < 1.0 ? 1.0 : \
logx((t), 35.0))) : (b))
#define LND_DAM(b, t) ((t) ? \
((b) * (logx((t), 60.0) < 1.0 ? 1.0 : \
logx((t), 60.0))) : (b))
#define LND_ACC(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0 \
? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
#define LND_AMM(b, t) (b)
#define LND_AAF(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 3.0))) > 127 \
? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 3.0))))
#define LND_FC(b, t) (b)
#define LND_FU(b, t) (b)
#define LND_XPL(b, t) (b)
#define LND_MXL(b, t) (b)
float
l_att(struct lchrstr *lcp, int tech)
{
return LND_ATTDEF(lcp->l_att, MAX(0, tech - lcp->l_tech));
}
float
l_def(struct lchrstr *lcp, int tech)
{
return LND_ATTDEF(lcp->l_def, MAX(0, tech - lcp->l_tech));
}
int
l_vul(struct lchrstr *lcp, int tech)
{
return LND_VUL(lcp->l_vul, MAX(0, tech - lcp->l_tech));
}
int
l_spd(struct lchrstr *lcp, int tech)
{
return LND_SPD(lcp->l_spd, MAX(0, tech - lcp->l_tech));
}
int
l_frg(struct lchrstr *lcp, int tech)
{
return LND_FRG(lcp->l_frg, MAX(0, tech - lcp->l_tech));
}
int
l_acc(struct lchrstr *lcp, int tech)
{
return LND_ACC(lcp->l_acc, MAX(0, tech - lcp->l_tech));
}
int
l_dam(struct lchrstr *lcp, int tech)
{
return LND_DAM(lcp->l_dam, MAX(0, tech - lcp->l_tech));
}
int
l_aaf(struct lchrstr *lcp, int tech)
{
return LND_AAF(lcp->l_aaf, MAX(0, tech - lcp->l_tech));
}

View file

@ -37,6 +37,8 @@
#include <config.h>
#include <math.h>
#include "misc.h"
#include "plane.h"
/*
@ -45,3 +47,40 @@
* Terminated by a sentinel with null pl_name.
*/
struct plchrstr plchr[PLN_TYPE_MAX + 2];
#define logx(a, b) (log((a)) / log((b)))
#define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))
#define PLN_ACC(b, t) (b * (1.0 - (sqrt(t) / 50.)))
#define PLN_RAN(b, t) (t ? (b + (logx(t, 2.0))) : b)
#define PLN_LOAD(b, t) (t ? (b * (logx(t, 50.0) < 1.0 ? 1.0 : \
logx(t, 50.0))) : b)
int
pl_att(struct plchrstr *pcp, int tech)
{
return PLN_ATTDEF(pcp->pl_att, MAX(0, tech - pcp->pl_tech));
}
int
pl_def(struct plchrstr *pcp, int tech)
{
return PLN_ATTDEF(pcp->pl_def, MAX(0, tech - pcp->pl_tech));
}
int
pl_acc(struct plchrstr *pcp, int tech)
{
return PLN_ACC(pcp->pl_acc, MAX(0, tech - pcp->pl_tech));
}
int
pl_range(struct plchrstr *pcp, int tech)
{
return PLN_RAN(pcp->pl_range, MAX(0, tech - pcp->pl_tech));
}
int
pl_load(struct plchrstr *pcp, int tech)
{
return PLN_LOAD(pcp->pl_load, MAX(0, tech - pcp->pl_tech));
}

View file

@ -37,6 +37,8 @@
#include <config.h>
#include <math.h>
#include "misc.h"
#include "ship.h"
/*
@ -45,3 +47,44 @@
* Terminated by a sentinel with null m_name.
*/
struct mchrstr mchr[SHP_TYPE_MAX + 2];
#define logx(a, b) (log((a)) / log((b)))
#define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \
logx(t, 40.0))) : b)
#define SHP_SPD(b, t) (t ? (b * (logx(t, 35.0) < 1.0 ? 1.0 : \
logx(t, 35.0))) : b)
#define SHP_VIS(b, t) (b * (1 - (sqrt(t) / 50)))
#define SHP_RNG(b, t) (t ? (b * (logx(t, 35.0) < 1.0 ? 1.0 : \
logx(t, 35.0))) : b)
#define SHP_FIR(b, t) (t ? (b * (logx(t, 60.0) < 1.0 ? 1.0 : \
logx(t, 60.0))) : b)
int
m_armor(struct mchrstr *mcp, int tech)
{
return SHP_DEF(mcp->m_armor, MAX(0, tech - mcp->m_tech));
}
int
m_speed(struct mchrstr *mcp, int tech)
{
return SHP_SPD(mcp->m_speed, MAX(0, tech - mcp->m_tech));
}
int
m_visib(struct mchrstr *mcp, int tech)
{
return SHP_VIS(mcp->m_visib, MAX(0, tech - mcp->m_tech));
}
int
m_frnge(struct mchrstr *mcp, int tech)
{
return SHP_RNG(mcp->m_frnge, MAX(0, tech - mcp->m_tech));
}
int
m_glim(struct mchrstr *mcp, int tech)
{
return SHP_FIR(mcp->m_glim, MAX(0, tech - mcp->m_tech));
}

View file

@ -1277,28 +1277,25 @@ void
lnd_set_tech(struct lndstr *lp, int tlev)
{
struct lchrstr *lcp = lchr + lp->lnd_type;
int tech_diff = tlev - lcp->l_tech;
if (CANT_HAPPEN(tech_diff < 0)) {
tlev -= tech_diff;
tech_diff = 0;
}
if (CANT_HAPPEN(tlev < lcp->l_tech))
tlev = 0;
lp->lnd_tech = tlev;
lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, tech_diff);
lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
lp->lnd_maxland = (int)LND_MXL(lcp->l_nland, tech_diff);
lp->lnd_att = l_att(lcp, tlev);
lp->lnd_def = l_def(lcp, tlev);
lp->lnd_vul = l_vul(lcp, tlev);
lp->lnd_spd = l_spd(lcp, tlev);
lp->lnd_vis = lcp->l_vis;
lp->lnd_spy = lcp->l_spy;
lp->lnd_rad = lcp->l_rad;
lp->lnd_frg = l_frg(lcp, tlev);
lp->lnd_acc = l_acc(lcp, tlev);
lp->lnd_dam = l_dam(lcp, tlev);
lp->lnd_ammo = lcp->l_ammo;
lp->lnd_aaf = lcp->l_aaf;
lp->lnd_fuelc = lcp->l_fuelc;
lp->lnd_fuelu = lcp->l_fuelu;
lp->lnd_maxlight = lcp->l_nxlight;
lp->lnd_maxland = lcp->l_nland;
}

View file

@ -36,7 +36,6 @@
#include <config.h>
#include <math.h>
#include "file.h"
#include "item.h"
#include "land.h"
@ -1238,20 +1237,17 @@ void
pln_set_tech(struct plnstr *pp, int tlev)
{
struct plchrstr *pcp = plchr + pp->pln_type;
int tech_diff = tlev - pcp->pl_tech;
int limited_range = pp->pln_range < pp->pln_range_max;
if (CANT_HAPPEN(tech_diff < 0)) {
tlev -= tech_diff;
tech_diff = 0;
}
if (CANT_HAPPEN(tlev < pcp->pl_tech))
tlev = pcp->pl_tech;
pp->pln_tech = tlev;
pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
pp->pln_att = pl_att(pcp, tlev);
pp->pln_def = pl_def(pcp, tlev);
pp->pln_acc = pl_acc(pcp, tlev);
pp->pln_range_max = pl_range(pcp, tlev);
pp->pln_load = pl_load(pcp, tlev);
if (!limited_range || pp->pln_range > pp->pln_range_max)
pp->pln_range = pp->pln_range_max;

View file

@ -242,7 +242,6 @@ show_ship_stats(int tlev)
{
struct mchrstr *mp;
int scount;
int techdiff;
pr("%25s s v s r f l p h x", "");
if (opt_FUEL)
@ -267,15 +266,10 @@ show_ship_stats(int tlev)
if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
continue;
techdiff = (int)(tlev - mp->m_tech);
pr("%-25.25s %3d %2d %2d %2d %2d %2d ",
mp->m_name,
(short)SHP_DEF(mp->m_armor, techdiff),
(short)SHP_SPD(mp->m_speed, techdiff),
(short)SHP_VIS(mp->m_visib, techdiff),
mp->m_vrnge,
(short)SHP_RNG(mp->m_frnge, techdiff),
(short)SHP_FIR(mp->m_glim, techdiff));
mp->m_name, m_armor(mp, tlev), m_speed(mp, tlev),
m_visib(mp, tlev), mp->m_vrnge,
m_frnge(mp, tlev), m_glim(mp, tlev));
pr("%2d ", mp->m_nland);
pr("%2d ", mp->m_nplanes);
@ -336,12 +330,8 @@ show_plane_stats(int tlev)
for (pcount = 0; pcount < lookup_list_cnt; pcount++) {
pp = (struct plchrstr *)lookup_list[pcount].l_u.pp;
pr("%-25.25s %3d %4d %3d %3d %3d %4d ",
pp->pl_name,
(int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)),
(int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)),
(int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)),
(int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)),
(int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)),
pp->pl_name, pl_acc(pp, tlev), pl_load(pp, tlev),
pl_att(pp, tlev), pl_def(pp, tlev), pl_range(pp, tlev),
pp->pl_fuel);
pr("%4d%% ", pp->pl_stealth);
pr("\n");
@ -454,7 +444,6 @@ show_land_stats(int tlev)
{
struct lchrstr *lcp;
int lcount;
int ourtlev;
pr("%25s s v s r r a f a a x l\n", "");
pr("%25s p i p a n c i m a f f p n\n", "");
@ -466,28 +455,16 @@ show_land_stats(int tlev)
if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES)
continue;
ourtlev = (int)(tlev - lcp->l_tech);
pr("%-25s %1.1f %1.1f %3d ",
lcp->l_name,
LND_ATTDEF(lcp->l_att, ourtlev),
LND_ATTDEF(lcp->l_def, ourtlev),
(int)LND_VUL(lcp->l_vul, ourtlev));
l_att(lcp, tlev), l_def(lcp, tlev), l_vul(lcp, tlev));
pr("%2d %2d %2d %2d ",
(int)LND_SPD(lcp->l_spd, ourtlev),
(int)LND_VIS(lcp->l_vis, ourtlev),
(int)LND_SPY(lcp->l_spy, ourtlev),
(int)LND_RAD(lcp->l_rad, ourtlev));
l_spd(lcp, tlev), lcp->l_vis, lcp->l_spy, lcp->l_rad);
pr("%2d %2d %2d %2d %2d ",
(int)LND_FRG(lcp->l_frg, ourtlev),
(int)LND_ACC(lcp->l_acc, ourtlev),
(int)LND_DAM(lcp->l_dam, ourtlev),
(int)LND_AMM(lcp->l_ammo, ourtlev),
(int)LND_AAF(lcp->l_aaf, ourtlev));
l_frg(lcp, tlev), l_acc(lcp, tlev), l_dam(lcp, tlev),
lcp->l_ammo, lcp->l_aaf);
pr("%2d %2d %2d %2d ",
(int)LND_FC(lcp->l_fuelc, ourtlev),
(int)LND_FU(lcp->l_fuelu, ourtlev),
(int)LND_XPL(lcp->l_nxlight, ourtlev),
(int)LND_MXL(lcp->l_nland, ourtlev));
lcp->l_fuelc, lcp->l_fuelu, lcp->l_nxlight, lcp->l_nland);
pr("\n");
}

View file

@ -35,7 +35,6 @@
#include <config.h>
#include <math.h>
#include <stdlib.h>
#include "damage.h"
#include "file.h"
@ -980,17 +979,14 @@ void
shp_set_tech(struct shpstr *sp, int tlev)
{
struct mchrstr *mcp = mchr + sp->shp_type;
int tech_diff = tlev - mcp->m_tech;
if (CANT_HAPPEN(tech_diff < 0)) {
tlev -= tech_diff;
tech_diff = 0;
}
if (CANT_HAPPEN(tlev < mcp->m_tech))
tlev = mcp->m_tech;
sp->shp_tech = tlev;
sp->shp_armor = (short)SHP_DEF(mcp->m_armor, tech_diff);
sp->shp_speed = (short)SHP_SPD(mcp->m_speed, tech_diff);
sp->shp_visib = (short)SHP_VIS(mcp->m_visib, tech_diff);
sp->shp_frnge = (short)SHP_RNG(mcp->m_frnge, tech_diff);
sp->shp_glim = (short)SHP_FIR(mcp->m_glim, tech_diff);
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);
}