(infect_people): Remove parameters vec, eff, mobil and work with

sp->sct_item, sp->sct_effic, sp->sct_mobil instead.  This is safe,
because the only caller passed a copy of sp->sct_item created with
getvec(), and infect_people() doesn't change it.  Caller changed.
(infect_people): Rewrite plague risk computation for clarity.
This commit is contained in:
Markus Armbruster 2004-03-11 17:18:05 +00:00
parent abaf9e06ec
commit 979f74709b

View file

@ -47,8 +47,7 @@
#include "lost.h" #include "lost.h"
#include "gen.h" #include "gen.h"
static int infect_people(struct natstr *, register int *, u_int, int, static int infect_people(struct natstr *, struct sctstr *);
struct sctstr *);
void void
do_plague(struct sctstr *sp, struct natstr *np, int etu) do_plague(struct sctstr *sp, struct natstr *np, int etu)
@ -60,15 +59,14 @@ do_plague(struct sctstr *sp, struct natstr *np, int etu)
if (opt_NO_PLAGUE) /* no plague nothing to do */ if (opt_NO_PLAGUE) /* no plague nothing to do */
return; return;
if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
return;
pstage = sp->sct_pstage; pstage = sp->sct_pstage;
ptime = sp->sct_ptime; ptime = sp->sct_ptime;
if (pstage == PLG_HEALTHY) { if (pstage == PLG_HEALTHY) {
pstage = infect_people(np, vec, sp->sct_effic, (int)sp->sct_mobil, sp); pstage = infect_people(np, sp);
ptime = 0; ptime = 0;
} else { } else {
getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
n = plague_people(np, vec, &pstage, &ptime, etu); n = plague_people(np, vec, &pstage, &ptime, etu);
switch (n) { switch (n) {
case PLG_DYING: case PLG_DYING:
@ -109,27 +107,24 @@ do_plague(struct sctstr *sp, struct natstr *np, int etu)
default: default:
break; break;
} }
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
} }
if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 && if (sp->sct_item[I_CIVIL] == 0 && sp->sct_item[I_MILIT] == 0
!has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) {
makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
sp->sct_own = 0; sp->sct_own = 0;
sp->sct_oldown = 0; sp->sct_oldown = 0;
} }
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
sp->sct_pstage = pstage; sp->sct_pstage = pstage;
sp->sct_ptime = ptime; sp->sct_ptime = ptime;
} }
/*ARGSUSED*/ /*ARGSUSED*/
static int static int
infect_people(struct natstr *np, register int *vec, u_int eff, int mobil, infect_people(struct natstr *np, struct sctstr *sp)
struct sctstr *sp)
{ {
double plg_num; double pop, pop_space, bad_stuff, pollution, cleanup;
double plg_denom;
double plg_chance; double plg_chance;
double civvies = 999.0;
if (opt_NO_PLAGUE) /* no plague nothing to do */ if (opt_NO_PLAGUE) /* no plague nothing to do */
return PLG_HEALTHY; return PLG_HEALTHY;
@ -137,17 +132,16 @@ infect_people(struct natstr *np, register int *vec, u_int eff, int mobil,
if (np->nat_level[NAT_TLEV] <= 10.0) if (np->nat_level[NAT_TLEV] <= 10.0)
return PLG_HEALTHY; return PLG_HEALTHY;
if (opt_BIG_CITY && (sp->sct_type == SCT_CAPIT))
civvies = 9999.0;
/* /*
* make plague where there was none before... * make plague where there was none before...
*/ */
plg_num = ((vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]) / civvies) * pop = sp->sct_item[I_CIVIL] + sp->sct_item[I_MILIT] + sp->sct_item[I_UW];
((vec[I_IRON] + vec[I_OIL] + (vec[I_RAD] * 2)) / 10.0 + pop_space = opt_BIG_CITY && (sp->sct_type == SCT_CAPIT) ? 9999.0 : 999.0;
np->nat_level[NAT_TLEV] + 100.0); bad_stuff
plg_denom = eff + mobil + 100 + np->nat_level[NAT_RLEV]; = sp->sct_item[I_IRON] + sp->sct_item[I_OIL] + sp->sct_item[I_RAD] * 2;
plg_chance = ((plg_num / plg_denom) - 1.0) * 0.01; pollution = bad_stuff / 10.0 + np->nat_level[NAT_TLEV] + 100.0;
cleanup = sp->sct_effic + sp->sct_mobil + 100 + np->nat_level[NAT_RLEV];
plg_chance = ((pop / pop_space) * (pollution / cleanup) - 1.0) * 0.01;
if (chance(plg_chance)) if (chance(plg_chance))
return PLG_EXPOSED; return PLG_EXPOSED;
return PLG_HEALTHY; return PLG_HEALTHY;