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:
parent
3d0e083aec
commit
0219bf086a
10 changed files with 222 additions and 118 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue