(LND_SPY_DETECT_CHANCE): New.

(look_land, sabo, prunits, unitsatxy, lnd_mar_one_sector,
count_sect_units, takeover): Use it.  Closes bug#786369.
This commit is contained in:
Markus Armbruster 2003-11-09 12:52:16 +00:00
parent fc9ec1323a
commit c2c16e1a04
7 changed files with 10 additions and 19 deletions

View file

@ -172,6 +172,9 @@ struct lchrstr {
#define LND_MXL(b, t) (b) #define LND_MXL(b, t) (b)
#define LND_COST(b, t) ((b) * (1.0 + (sqrt((double)(t)) / 100.0))) #define LND_COST(b, t) ((b) * (1.0 + (sqrt((double)(t)) / 100.0)))
/* Chance to detect L_SPY unit (percent) */
#define LND_SPY_DETECT_CHANCE(eff) ((110-(eff))/100.0)
#define getland(n, p) \ #define getland(n, p) \
ef_read(EF_LAND, n, (caddr_t)p) ef_read(EF_LAND, n, (caddr_t)p)
#define putland(n, p) \ #define putland(n, p) \

View file

@ -258,7 +258,6 @@ look_land(register struct lndstr *lookland)
int i; int i;
int dist; int dist;
double techfact(int, double); double techfact(int, double);
double odds;
drange = techfact(lookland->lnd_tech, (double)lookland->lnd_spy); drange = techfact(lookland->lnd_tech, (double)lookland->lnd_spy);
drange = (drange * ((double)lookland->lnd_effic / 100.0)); drange = (drange * ((double)lookland->lnd_effic / 100.0));
@ -278,8 +277,7 @@ look_land(register struct lndstr *lookland)
enough not to be seen */ enough not to be seen */
if (lp->lnd_ship >= 0 || lp->lnd_land >= 0) if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
continue; continue;
odds = (double)(100 - lp->lnd_effic) + 0.10; if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
if (!(chance(odds)))
continue; continue;
} }
vrange = ldround((double)((lp->lnd_vis * range) / 20.0), 1); vrange = ldround((double)((lp->lnd_vis * range) / 20.0), 1);

View file

@ -87,7 +87,7 @@ sabo(void)
} }
putvar(V_SHELL, vec[I_SHELL] - 1, (s_char *)&land, EF_LAND); putvar(V_SHELL, vec[I_SHELL] - 1, (s_char *)&land, EF_LAND);
odds = (100 - land.lnd_effic) / 100.0 + .10; odds = LND_SPY_DETECT_CHANCE(land.lnd_effic);
if (chance(odds)) { if (chance(odds)) {
wu(0, sect.sct_own, wu(0, sect.sct_own,
"%s spy shot in %s during sabotage attempt.\n", "%s spy shot in %s during sabotage attempt.\n",

View file

@ -281,7 +281,6 @@ prunits(int x, int y)
struct lndstr land; struct lndstr land;
struct nstr_item ni; struct nstr_item ni;
s_char report[128]; s_char report[128];
double odds;
snxtitem_xy(&ni, EF_LAND, x, y); snxtitem_xy(&ni, EF_LAND, x, y);
while (nxtitem(&ni, (s_char *)&land)) { while (nxtitem(&ni, (s_char *)&land)) {
@ -291,8 +290,7 @@ prunits(int x, int y)
continue; continue;
/* Don't always see spies */ /* Don't always see spies */
if (lchr[(int)land.lnd_type].l_flags & L_SPY) { if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
odds = (double)(100 - land.lnd_effic) + 0.10; if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
if (!(chance(odds)))
continue; continue;
} }
if ((land.lnd_own != player->cnum) && land.lnd_own) { if ((land.lnd_own != player->cnum) && land.lnd_own) {

View file

@ -135,7 +135,6 @@ unitsatxy(coord x, coord y, int wantflags, int nowantflags)
struct nstr_item ni; struct nstr_item ni;
struct lchrstr *lp; struct lchrstr *lp;
struct lndstr land; struct lndstr land;
double odds;
first = 1; first = 1;
units = 0; units = 0;
@ -158,8 +157,7 @@ unitsatxy(coord x, coord y, int wantflags, int nowantflags)
} }
if (lp->l_flags & L_SPY) { if (lp->l_flags & L_SPY) {
odds = (double)(100 - land.lnd_effic) + 0.10; if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
if (!(chance(odds)))
continue; continue;
} }

View file

@ -444,7 +444,6 @@ int
count_sect_units(struct sctstr *sp) count_sect_units(struct sctstr *sp)
{ {
int count = 0; int count = 0;
double odds;
struct nstr_item ni; struct nstr_item ni;
struct lndstr land; struct lndstr land;
@ -456,8 +455,7 @@ count_sect_units(struct sctstr *sp)
continue; continue;
/* Don't always see spies */ /* Don't always see spies */
if (lchr[(int)land.lnd_type].l_flags & L_SPY) { if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
odds = (double)(100 - land.lnd_effic) + 0.10; if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
if (!(chance(odds)))
continue; continue;
} }
/* Got here, report it */ /* Got here, report it */
@ -1108,7 +1106,6 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
int stop; int stop;
s_char dp[80]; s_char dp[80];
int rel; int rel;
double odds;
int oldown; int oldown;
if (dir <= DIR_STOP || dir >= DIR_VIEW) { if (dir <= DIR_STOP || dir >= DIR_VIEW) {
@ -1198,8 +1195,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
} }
if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */ if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
/* Always a 10% chance of getting caught. */ /* Always a 10% chance of getting caught. */
odds = (100 - llp->land.lnd_effic) + .10; if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
if (chance(odds)) {
if (rel == NEUTRAL || rel == FRIENDLY) { if (rel == NEUTRAL || rel == FRIENDLY) {
wu(0, sect.sct_own, wu(0, sect.sct_own,
"%s unit spotted in %s\n", cname(player->cnum), "%s unit spotted in %s\n", cname(player->cnum),

View file

@ -61,7 +61,6 @@ takeover(register struct sctstr *sp, natid newown)
int che_count; int che_count;
int oldche; int oldche;
int n, vec[I_MAX + 1]; int n, vec[I_MAX + 1];
double odds;
struct nstr_item ni; struct nstr_item ni;
struct plnstr p; struct plnstr p;
struct lndstr land; struct lndstr land;
@ -101,8 +100,7 @@ takeover(register struct sctstr *sp, natid newown)
continue; continue;
/* Spies get a chance to hide */ /* Spies get a chance to hide */
if (lchr[(int)lp->lnd_type].l_flags & L_SPY) { if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
odds = (double)(100 - lp->lnd_effic) + 0.10; if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
if (!(chance(odds)))
continue; continue;
} }
n = lp->lnd_effic - (30 + (random() % 100)); n = lp->lnd_effic - (30 + (random() % 100));