Sectors need space for items, deliveries and distribution thresholds.
To save space, the ancients invented `variables': a collection of key-value pairs, missing means zero value, space for `enough' keys. This complicates the code, as assigning to a `variable' can fail for lack of space. Over time, `enough' increased, and for quite some time now `variables' have been *wasting* space. This changeset replaces them, except in struct mchrstr, struct lchrstr and struct pchrstr, where they are read-only, and will be replaced later. It is only a first step; further cleanup is required. To simplify and minimize this necessarily huge changeset, the new item[] arrays have an unused slot 0, and the old variable types V_CIVIL, ... are still defined, but must have the same values as the item types I_CIVIL, ...
This commit is contained in:
parent
ba86513b01
commit
eccc5cb7d7
86 changed files with 853 additions and 1226 deletions
|
@ -100,22 +100,16 @@ deliver(register struct sctstr *from, struct ichrstr *ip, int dir,
|
|||
if (amt_moved <= 0)
|
||||
return 0;
|
||||
}
|
||||
amt_dst = getvar(vtype, (caddr_t)to, EF_SECTOR);
|
||||
amt_dst = to->sct_item[vtype];
|
||||
if (amt_moved + amt_dst > 9990) {
|
||||
/* delivery backlog */
|
||||
if ((amt_moved = 9990 - amt_dst) <= 0)
|
||||
return 0;
|
||||
}
|
||||
if (putvar(vtype, amt_moved + amt_dst, (s_char *)to, EF_SECTOR) < 0) {
|
||||
/* "No room to deliver commodities */
|
||||
wu(0, from->sct_own, "no room for %s in %s\n",
|
||||
ip->i_name, ownxy(to));
|
||||
return 0;
|
||||
}
|
||||
to->sct_item[vtype] = amt_moved + amt_dst;
|
||||
/* deliver the plague too! */
|
||||
if (plague == PLG_INFECT
|
||||
&& getvar(V_PSTAGE, (s_char *)to, EF_SECTOR) == 0)
|
||||
putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)to, EF_SECTOR);
|
||||
if (plague == PLG_INFECT && to->sct_pstage == PLG_HEALTHY)
|
||||
to->sct_pstage = PLG_EXPOSED;
|
||||
n = from->sct_mobil - (int)(mcost * amt_moved);
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
|
|
|
@ -64,7 +64,6 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
|
|||
int dist_packing;
|
||||
int diff;
|
||||
int item;
|
||||
int dists[I_MAX + 1];
|
||||
int remote[I_MAX + 1];
|
||||
int local[I_MAX + 1];
|
||||
int changed;
|
||||
|
@ -75,9 +74,6 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
|
|||
if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
|
||||
return 0;
|
||||
|
||||
if (getvec(VT_DIST, dists, (s_char *)sp, EF_SECTOR) <= 0)
|
||||
return 0;
|
||||
|
||||
if (path == (s_char *)0) {
|
||||
if (sp->sct_own != 0) {
|
||||
if (imex == EXPORT) /* only want this once */
|
||||
|
@ -104,10 +100,10 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
|
|||
getvec(VT_ITEM, remote, (s_char *)dist, EF_SECTOR);
|
||||
lplague = rplague = changed = 0;
|
||||
for (item = 1; item < I_MAX + 1; item++) {
|
||||
if (dists[item] == 0)
|
||||
if (sp->sct_dist[item] == 0)
|
||||
continue;
|
||||
ip = &ichr[item];
|
||||
thresh = dists[item];
|
||||
thresh = sp->sct_dist[item];
|
||||
/*
|
||||
* calculate costs for importing and exporting.
|
||||
* the div 10.0 is because delivering straight through
|
||||
|
@ -204,19 +200,15 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
|
|||
putvec(VT_ITEM, local, (s_char *)sp, EF_SECTOR);
|
||||
|
||||
if (lplague) {
|
||||
lplague = getvar(V_PSTAGE, (s_char *)dist, EF_SECTOR);
|
||||
if (lplague == PLG_INFECT &&
|
||||
getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_HEALTHY) {
|
||||
putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SECTOR);
|
||||
}
|
||||
lplague = dist->sct_pstage;
|
||||
if (lplague == PLG_INFECT && sp->sct_pstage == PLG_HEALTHY)
|
||||
sp->sct_pstage = PLG_EXPOSED;
|
||||
}
|
||||
|
||||
if (rplague) {
|
||||
rplague = getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR);
|
||||
if (rplague == PLG_INFECT &&
|
||||
getvar(V_PSTAGE, (s_char *)dist, EF_SECTOR) == PLG_HEALTHY) {
|
||||
putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)dist, EF_SECTOR);
|
||||
}
|
||||
rplague = sp->sct_pstage;
|
||||
if (rplague == PLG_INFECT && dist->sct_pstage == PLG_HEALTHY)
|
||||
dist->sct_pstage = PLG_EXPOSED;
|
||||
}
|
||||
|
||||
return changed;
|
||||
|
|
|
@ -116,8 +116,8 @@ upd_land(register struct lndstr *lp, register int etus,
|
|||
/* build = 1, maintain = 0 */
|
||||
{
|
||||
struct lchrstr *lcp;
|
||||
u_short pstage, ptime;
|
||||
int vec[I_MAX + 1];
|
||||
int cvec[I_MAX + 1];
|
||||
int n;
|
||||
int min = morale_base - (int)np->nat_level[NAT_HLEV];
|
||||
int mult;
|
||||
|
@ -186,9 +186,10 @@ upd_land(register struct lndstr *lp, register int etus,
|
|||
* do plague stuff. plague can't break out on land units,
|
||||
* but it can still kill people on them.
|
||||
*/
|
||||
getvec(VT_COND, cvec, (s_char *)lp, EF_LAND);
|
||||
if (cvec[C_PSTAGE] > 0) {
|
||||
n = plague_people(np, vec, cvec, etus);
|
||||
pstage = lp->lnd_pstage;
|
||||
ptime = lp->lnd_ptime;
|
||||
if (pstage != PLG_HEALTHY) {
|
||||
n = plague_people(np, vec, &pstage, &ptime, etus);
|
||||
switch (n) {
|
||||
case PLG_DYING:
|
||||
wu(0, lp->lnd_own,
|
||||
|
@ -200,9 +201,9 @@ upd_land(register struct lndstr *lp, register int etus,
|
|||
break;
|
||||
case PLG_INCUBATE:
|
||||
/* Are we still incubating? */
|
||||
if (n == cvec[C_PSTAGE]) {
|
||||
if (n == pstage) {
|
||||
/* Yes. Will it turn "infectious" next time? */
|
||||
if (cvec[C_PTIME] <= etus) {
|
||||
if (ptime <= etus) {
|
||||
/* Yes. Report an outbreak. */
|
||||
wu(0, lp->lnd_own,
|
||||
"Outbreak of PLAGUE on %s!\n", prland(lp));
|
||||
|
@ -216,9 +217,9 @@ upd_land(register struct lndstr *lp, register int etus,
|
|||
break;
|
||||
case PLG_EXPOSED:
|
||||
/* Has the plague moved to "incubation" yet? */
|
||||
if (n != cvec[C_PSTAGE]) {
|
||||
if (n != pstage) {
|
||||
/* Yes. Will it turn "infectious" next time? */
|
||||
if (cvec[C_PTIME] <= etus) {
|
||||
if (ptime <= etus) {
|
||||
/* Yes. Report an outbreak. */
|
||||
wu(0, lp->lnd_own,
|
||||
"Outbreak of PLAGUE on %s!\n", prland(lp));
|
||||
|
@ -229,7 +230,8 @@ upd_land(register struct lndstr *lp, register int etus,
|
|||
default:
|
||||
break;
|
||||
}
|
||||
putvec(VT_COND, cvec, (s_char *)lp, EF_LAND);
|
||||
lp->lnd_pstage = pstage;
|
||||
lp->lnd_ptime = ptime;
|
||||
}
|
||||
putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
|
||||
} /* end !player->simulation */
|
||||
|
|
|
@ -240,11 +240,11 @@ int
|
|||
nav_ship(register struct shpstr *sp)
|
||||
{
|
||||
struct sctstr *sectp;
|
||||
s_char *cp, item;
|
||||
s_char *cp;
|
||||
int stopping;
|
||||
int quit;
|
||||
int didsomething = 0;
|
||||
int max_amt, food_amt, comm;
|
||||
int max_amt, food_amt;
|
||||
s_char buf[1024];
|
||||
struct emp_qelem ship_list;
|
||||
struct emp_qelem *qp, *newqp;
|
||||
|
@ -332,11 +332,9 @@ nav_ship(register struct shpstr *sp)
|
|||
}
|
||||
/* special case for fishing boats */
|
||||
if ((mchr[(int)sp->shp_type].m_flags & M_FOOD) == 1) {
|
||||
item = (s_char)'f';
|
||||
comm = com_num(&item);
|
||||
food_amt = getvar(comm, (s_char *)sp, EF_SHIP);
|
||||
max_amt = (vl_find(comm, vship->m_vtype,
|
||||
vship->m_vamt, (int)vship->m_nv));
|
||||
food_amt = sp->shp_item[I_FOOD];
|
||||
max_amt = vl_find(V_FOOD, vship->m_vtype,
|
||||
vship->m_vamt, vship->m_nv);
|
||||
sectp = getsectp(sp->shp_x, sp->shp_y);
|
||||
|
||||
if (food_amt < max_amt && (sectp->sct_own == 0))
|
||||
|
|
|
@ -94,8 +94,8 @@ load_it(register struct shpstr *sp, register struct sctstr *psect, int i)
|
|||
item = sp->shp_tend[i]; /* commodity */
|
||||
comm = com_num(&item);
|
||||
|
||||
ship_amt = getvar(comm, (s_char *)sp, EF_SHIP);
|
||||
sect_amt = getvar(comm, (s_char *)psect, EF_SECTOR);
|
||||
ship_amt = sp->shp_item[comm];
|
||||
sect_amt = psect->sct_item[comm];
|
||||
|
||||
/* check for disloyal civilians */
|
||||
if (psect->sct_oldown != shipown && comm == V_CIVIL) {
|
||||
|
@ -133,18 +133,16 @@ load_it(register struct shpstr *sp, register struct sctstr *psect, int i)
|
|||
return 0; /* nothing to move */
|
||||
|
||||
|
||||
putvar(comm, ship_amt + transfer, (s_char *)sp, EF_SHIP);
|
||||
sp->shp_item[comm] = ship_amt + transfer;
|
||||
if (comm == V_CIVIL || comm == V_MILIT)
|
||||
sect_amt++; /*adjustment */
|
||||
putvar(comm, sect_amt - transfer, (s_char *)psect, EF_SECTOR);
|
||||
psect->sct_item[comm] = sect_amt - transfer;
|
||||
|
||||
/* deal with the plague */
|
||||
if (getvar(V_PSTAGE, (s_char *)psect, EF_SECTOR) == PLG_INFECT &&
|
||||
getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_HEALTHY)
|
||||
putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SHIP);
|
||||
if (getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_INFECT &&
|
||||
getvar(V_PSTAGE, (s_char *)psect, EF_SECTOR) == PLG_HEALTHY)
|
||||
putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)psect, EF_SECTOR);
|
||||
if (psect->sct_pstage == PLG_INFECT && sp->shp_pstage == PLG_HEALTHY)
|
||||
sp->shp_pstage = PLG_EXPOSED;
|
||||
if (sp->shp_pstage == PLG_INFECT && psect->sct_pstage == PLG_HEALTHY)
|
||||
psect->sct_pstage = PLG_EXPOSED;
|
||||
|
||||
return 1; /* we did someloading return 1 to keep */
|
||||
/* our loop happy in nav_ship() */
|
||||
|
@ -192,8 +190,8 @@ unload_it(register struct shpstr *sp)
|
|||
continue;
|
||||
|
||||
comm = com_num(&item);
|
||||
ship_amt = getvar(comm, (s_char *)sp, EF_SHIP);
|
||||
sect_amt = getvar(comm, (s_char *)sectp, EF_SECTOR);
|
||||
ship_amt = sp->shp_item[comm];
|
||||
sect_amt = sectp->sct_item[comm];
|
||||
|
||||
/* check for disloyal civilians */
|
||||
if (sectp->sct_oldown != shipown && comm == V_CIVIL) {
|
||||
|
@ -214,25 +212,20 @@ unload_it(register struct shpstr *sp)
|
|||
if (max_amt <= 0)
|
||||
continue;
|
||||
|
||||
putvar(comm, ship_amt - max_amt, (s_char *)sp, EF_SHIP);
|
||||
putvar(comm, sect_amt + max_amt, (s_char *)sectp, EF_SECTOR);
|
||||
|
||||
if (getvar(V_PSTAGE, (s_char *)sectp, EF_SECTOR) == PLG_INFECT &&
|
||||
getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_HEALTHY)
|
||||
putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SHIP);
|
||||
|
||||
if (getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_INFECT &&
|
||||
getvar(V_PSTAGE, (s_char *)sectp, EF_SECTOR) == PLG_HEALTHY)
|
||||
putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sectp, EF_SECTOR);
|
||||
sp->shp_item[comm] = ship_amt - max_amt;
|
||||
sectp->sct_item[comm] = sect_amt + max_amt;
|
||||
|
||||
if (sectp->sct_pstage == PLG_INFECT && sp->shp_pstage == PLG_HEALTHY)
|
||||
sp->shp_pstage = PLG_EXPOSED;
|
||||
if (sp->shp_pstage == PLG_INFECT && sectp->sct_pstage == PLG_HEALTHY)
|
||||
sectp->sct_pstage = PLG_EXPOSED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* com_num
|
||||
* This small but useful bit of code runs through the list
|
||||
* of commodities and return the integer value of the
|
||||
* commodity it finds if possible. Very handy when using getvar().
|
||||
* commodity it finds if possible.
|
||||
* Basicly its a hacked version of whatitem.c found in the
|
||||
* /player directory.
|
||||
* new autonav code.
|
||||
|
|
|
@ -54,7 +54,7 @@ void
|
|||
do_plague(struct sctstr *sp, struct natstr *np, int etu)
|
||||
{
|
||||
int vec[I_MAX + 1];
|
||||
int cvec[I_MAX + 1];
|
||||
u_short pstage, ptime;
|
||||
int n;
|
||||
|
||||
if (opt_NO_PLAGUE) /* no plague nothing to do */
|
||||
|
@ -62,15 +62,14 @@ do_plague(struct sctstr *sp, struct natstr *np, int etu)
|
|||
|
||||
if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
|
||||
return;
|
||||
if (getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR) <= 0)
|
||||
memset(cvec, 0, sizeof(cvec));
|
||||
pstage = sp->sct_pstage;
|
||||
ptime = sp->sct_ptime;
|
||||
|
||||
if (cvec[C_PSTAGE] == 0) {
|
||||
cvec[C_PSTAGE] = infect_people(np, vec, sp->sct_effic,
|
||||
(int)sp->sct_mobil, sp);
|
||||
cvec[C_PTIME] = 0;
|
||||
if (pstage == PLG_HEALTHY) {
|
||||
pstage = infect_people(np, vec, sp->sct_effic, (int)sp->sct_mobil, sp);
|
||||
ptime = 0;
|
||||
} else {
|
||||
n = plague_people(np, vec, cvec, etu);
|
||||
n = plague_people(np, vec, &pstage, &ptime, etu);
|
||||
switch (n) {
|
||||
case PLG_DYING:
|
||||
wu(0, sp->sct_own, "PLAGUE deaths reported in %s.\n",
|
||||
|
@ -82,9 +81,9 @@ do_plague(struct sctstr *sp, struct natstr *np, int etu)
|
|||
break;
|
||||
case PLG_INCUBATE:
|
||||
/* Are we still incubating? */
|
||||
if (n == cvec[C_PSTAGE]) {
|
||||
if (n == pstage) {
|
||||
/* Yes. Will it turn "infectious" next time? */
|
||||
if (cvec[C_PTIME] <= etu) {
|
||||
if (ptime <= etu) {
|
||||
/* Yes. Report an outbreak. */
|
||||
wu(0, sp->sct_own,
|
||||
"Outbreak of PLAGUE in %s!\n", ownxy(sp));
|
||||
|
@ -97,9 +96,9 @@ do_plague(struct sctstr *sp, struct natstr *np, int etu)
|
|||
break;
|
||||
case PLG_EXPOSED:
|
||||
/* Has the plague moved to "incubation" yet? */
|
||||
if (n != cvec[C_PSTAGE]) {
|
||||
if (n != pstage) {
|
||||
/* Yes. Will it turn "infectious" next time? */
|
||||
if (cvec[C_PTIME] <= etu) {
|
||||
if (ptime <= etu) {
|
||||
/* Yes. Report an outbreak. */
|
||||
wu(0, sp->sct_own,
|
||||
"Outbreak of PLAGUE in %s!\n", ownxy(sp));
|
||||
|
@ -118,7 +117,8 @@ do_plague(struct sctstr *sp, struct natstr *np, int etu)
|
|||
sp->sct_oldown = 0;
|
||||
}
|
||||
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
|
||||
putvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_pstage = pstage;
|
||||
sp->sct_ptime = ptime;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
|
@ -160,7 +160,8 @@ infect_people(struct natstr *np, register int *vec, u_int eff, int mobil,
|
|||
* stage. No reports generated here anymore.
|
||||
*/
|
||||
int
|
||||
plague_people(struct natstr *np, register int *vec, register int *cvec,
|
||||
plague_people(struct natstr *np, register int *vec,
|
||||
u_short *pstage, u_short *ptime,
|
||||
int etus)
|
||||
{
|
||||
int stage;
|
||||
|
@ -170,13 +171,13 @@ plague_people(struct natstr *np, register int *vec, register int *cvec,
|
|||
|
||||
if (opt_NO_PLAGUE) /* no plague nothing to do */
|
||||
return PLG_HEALTHY;
|
||||
cvec[C_PTIME] -= etus;
|
||||
stage = cvec[C_PSTAGE];
|
||||
*ptime -= etus;
|
||||
stage = *pstage;
|
||||
switch (stage) {
|
||||
case PLG_DYING:
|
||||
plg_num = 100.0 * etus;
|
||||
plg_denom = (np->nat_level[NAT_RLEV] + 100.0) *
|
||||
(vec[C_PTIME] + etus + 1.0);
|
||||
(*ptime + etus + 1.0);
|
||||
pct_left = 1.0 - (double)(plg_num / plg_denom);
|
||||
if (pct_left < 0.2)
|
||||
pct_left = 0.2;
|
||||
|
@ -188,18 +189,18 @@ plague_people(struct natstr *np, register int *vec, register int *cvec,
|
|||
case PLG_INCUBATE:
|
||||
break;
|
||||
case PLG_EXPOSED:
|
||||
cvec[C_PTIME] = 0;
|
||||
*ptime = 0;
|
||||
break;
|
||||
default:
|
||||
/* bad */
|
||||
logerror("plague_people: bad pstage %d", stage);
|
||||
cvec[C_PSTAGE] = PLG_HEALTHY;
|
||||
cvec[C_PTIME] = 0;
|
||||
*pstage = PLG_HEALTHY;
|
||||
*ptime = 0;
|
||||
return PLG_HEALTHY;
|
||||
}
|
||||
if (cvec[C_PTIME] <= 0) {
|
||||
cvec[C_PSTAGE]--;
|
||||
cvec[C_PTIME] = (etus / 2) + (random() % etus);
|
||||
if (*ptime <= 0) {
|
||||
*pstage -= 1;
|
||||
*ptime = (etus / 2) + (random() % etus);
|
||||
}
|
||||
return stage;
|
||||
}
|
||||
|
|
|
@ -65,12 +65,8 @@ prepare_sects(int etu, int *bp)
|
|||
if (opt_FALLOUT) {
|
||||
if (!player->simulation) {
|
||||
/* First, we determine which sectors to process fallout in */
|
||||
for (n = 0; NULL != (sp = getsectid(n)); n++) {
|
||||
if (getvar(V_FALLOUT, (s_char *)sp, EF_SECTOR))
|
||||
sp->sct_updated = 1;
|
||||
else
|
||||
sp->sct_updated = 0;
|
||||
}
|
||||
for (n = 0; NULL != (sp = getsectid(n)); n++)
|
||||
sp->sct_updated = sp->sct_fallout != 0;
|
||||
/* Next, we process the fallout there */
|
||||
for (n = 0; NULL != (sp = getsectid(n)); n++)
|
||||
if (sp->sct_updated)
|
||||
|
@ -81,7 +77,7 @@ prepare_sects(int etu, int *bp)
|
|||
spread_fallout(sp, etu);
|
||||
/* Next, we decay the fallout */
|
||||
for (n = 0; NULL != (sp = getsectid(n)); n++)
|
||||
if (getvar(V_FALLOUT, (s_char *)sp, EF_SECTOR))
|
||||
if (sp->sct_fallout)
|
||||
decay_fallout(sp, etu);
|
||||
}
|
||||
}
|
||||
|
@ -158,13 +154,13 @@ upd_slmilcosts(natid n, int etu)
|
|||
for (i = 0; NULL != (sp = getshipp(i)); i++) {
|
||||
if (!sp->shp_own || sp->shp_own != n)
|
||||
continue;
|
||||
if ((mil = getvar(V_MILIT, (s_char *)sp, EF_SHIP)) > 0)
|
||||
if ((mil = sp->shp_item[I_MILIT]) > 0)
|
||||
totalmil += mil;
|
||||
}
|
||||
for (i = 0; NULL != (lp = getlandp(i)); i++) {
|
||||
if (!lp->lnd_own || lp->lnd_own != n)
|
||||
continue;
|
||||
if ((mil = getvar(V_MILIT, (s_char *)lp, EF_LAND)) > 0)
|
||||
if ((mil = lp->lnd_item[I_MILIT]) > 0)
|
||||
totalmil += mil;
|
||||
}
|
||||
mil_pay = totalmil * etu * money_mil;
|
||||
|
|
|
@ -64,13 +64,13 @@ revolt(struct sctstr *sp)
|
|||
int n;
|
||||
int target;
|
||||
|
||||
che_combo = getvar(V_CHE, (s_char *)sp, EF_SECTOR);
|
||||
che_combo = sp->sct_che;
|
||||
che = get_che_value(che_combo);
|
||||
target = get_che_cnum(che_combo);
|
||||
if (che_combo != 0 && (target != sp->sct_own || che >= CHE_MAX))
|
||||
return;
|
||||
civ = getvar(V_CIVIL, (s_char *)sp, EF_SECTOR);
|
||||
uw = getvar(V_UW, (s_char *)sp, EF_SECTOR);
|
||||
civ = sp->sct_item[I_CIVIL];
|
||||
uw = sp->sct_item[I_UW];
|
||||
if (che > (civ + uw) * 3)
|
||||
return;
|
||||
che_uw = 0;
|
||||
|
@ -100,11 +100,11 @@ revolt(struct sctstr *sp)
|
|||
uw -= che_uw;
|
||||
set_che_cnum(che_combo, sp->sct_own);
|
||||
set_che_value(che_combo, che);
|
||||
putvar(V_CHE, (int)che_combo, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_che = che_combo;
|
||||
if (che_civ > 0)
|
||||
putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_item[I_CIVIL] = civ;
|
||||
if (che_uw > 0)
|
||||
putvar(V_UW, uw, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_item[I_UW] = uw;
|
||||
#ifdef DEBUG
|
||||
logerror("(#%d) %d che fired up in %s",
|
||||
sp->sct_own, che, ownxy(sp));
|
||||
|
@ -166,7 +166,7 @@ guerrilla(struct sctstr *sp)
|
|||
recruit = 0;
|
||||
convert = 0;
|
||||
move = 0;
|
||||
if ((n = getvar(V_CHE, (s_char *)sp, EF_SECTOR)) <= 0)
|
||||
if ((n = sp->sct_che) <= 0)
|
||||
return;
|
||||
che_combo = n;
|
||||
if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
|
||||
|
@ -213,7 +213,7 @@ guerrilla(struct sctstr *sp)
|
|||
|
||||
/* Security forces killed all the che */
|
||||
if (che <= 0) {
|
||||
putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_che = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -227,8 +227,8 @@ guerrilla(struct sctstr *sp)
|
|||
/* target nation has dissolved: che's retire. */
|
||||
logerror("%d Che targeted at country %d retiring", che, target);
|
||||
civ += che;
|
||||
putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR);
|
||||
putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_che = 0;
|
||||
sp->sct_item[I_CIVIL] = civ;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -352,9 +352,9 @@ guerrilla(struct sctstr *sp)
|
|||
sp->sct_newtype = SCT_AGRI;
|
||||
n = civ / 20;
|
||||
civ -= n;
|
||||
putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR);
|
||||
putvar(V_UW, uw, (s_char *)sp, EF_SECTOR);
|
||||
putvar(V_MILIT, n, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_item[I_CIVIL] = civ;
|
||||
sp->sct_item[I_UW] = uw;
|
||||
sp->sct_item[I_MILIT] = n;
|
||||
move++;
|
||||
recruit = 0;
|
||||
if (sp->sct_own)
|
||||
|
@ -378,14 +378,14 @@ guerrilla(struct sctstr *sp)
|
|||
n = CHE_MAX - che;
|
||||
che += n;
|
||||
civ -= n;
|
||||
putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_item[I_CIVIL] = civ;
|
||||
}
|
||||
n = uw * (random() % 3) / 200;
|
||||
if (n + che > CHE_MAX)
|
||||
n = CHE_MAX - che;
|
||||
che += n;
|
||||
uw -= n;
|
||||
putvar(V_UW, uw, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_item[I_UW] = uw;
|
||||
}
|
||||
domove:
|
||||
if (move && che > 0) {
|
||||
|
@ -402,14 +402,14 @@ guerrilla(struct sctstr *sp)
|
|||
continue;
|
||||
if (nsp->sct_own != target)
|
||||
continue;
|
||||
if ((val = getvar(V_CHE, (s_char *)nsp, EF_SECTOR)) > 0) {
|
||||
if ((val = nsp->sct_che) > 0) {
|
||||
che_combo = val;
|
||||
if (get_che_cnum(che_combo) != target)
|
||||
continue;
|
||||
if (get_che_value(che_combo) + che > CHE_MAX)
|
||||
continue;
|
||||
}
|
||||
val = getvar(V_MILIT, (s_char *)nsp, EF_SECTOR);
|
||||
val = nsp->sct_item[I_MILIT];
|
||||
/* don't give che more precise info than spy */
|
||||
val = roundintby(val, 10);
|
||||
/* inject a modicum of indeterminism; also
|
||||
|
@ -422,20 +422,20 @@ guerrilla(struct sctstr *sp)
|
|||
}
|
||||
/* if we found a nice sector, go there */
|
||||
if (nicest_sp != 0) {
|
||||
che_combo = getvar(V_CHE, (s_char *)nicest_sp, EF_SECTOR);
|
||||
che_combo = nicest_sp->sct_che;
|
||||
che += get_che_value(che_combo);
|
||||
set_che_value(che_combo, che);
|
||||
set_che_cnum(che_combo, target);
|
||||
putvar(V_CHE, (int)che_combo, (s_char *)nicest_sp, EF_SECTOR);
|
||||
nicest_sp->sct_che = che_combo;
|
||||
che = 0;
|
||||
}
|
||||
}
|
||||
if (che > 0) {
|
||||
set_che_value(che_combo, che);
|
||||
set_che_cnum(che_combo, target);
|
||||
putvar(V_CHE, (int)che_combo, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_che = che_combo;
|
||||
} else
|
||||
putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_che = 0;
|
||||
if (mc > 0 || cc > 0) {
|
||||
/* don't tell who won just to be mean */
|
||||
wu(0, target,
|
||||
|
@ -456,13 +456,13 @@ take_casualties(struct sctstr *sp, int mc)
|
|||
struct nstr_item ni;
|
||||
|
||||
/* casualties come out of mil first */
|
||||
orig_mil = getvar(V_MILIT, (s_char *)sp, EF_SECTOR);
|
||||
orig_mil = sp->sct_item[I_MILIT];
|
||||
|
||||
if (mc <= orig_mil) {
|
||||
putvar(V_MILIT, (orig_mil - mc), (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_item[I_MILIT] = orig_mil - mc;
|
||||
return;
|
||||
}
|
||||
putvar(V_MILIT, 0, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_item[I_MILIT] = 0;
|
||||
|
||||
/* remaining casualites */
|
||||
mc -= orig_mil;
|
||||
|
|
|
@ -59,7 +59,6 @@ int
|
|||
dodeliver(struct sctstr *sp, int *vec)
|
||||
{
|
||||
register int i;
|
||||
int del[I_MAX + 1];
|
||||
int thresh;
|
||||
int dir;
|
||||
int plague;
|
||||
|
@ -68,15 +67,13 @@ dodeliver(struct sctstr *sp, int *vec)
|
|||
|
||||
if (sp->sct_mobil <= 0)
|
||||
return 0;
|
||||
if (getvec(VT_DEL, del, (s_char *)sp, EF_SECTOR) <= 0)
|
||||
return 0;
|
||||
changed = 0;
|
||||
plague = getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR);
|
||||
plague = sp->sct_pstage;
|
||||
for (i = 1; i <= I_MAX; i++) {
|
||||
if (del[i] == 0)
|
||||
if (sp->sct_del[i] == 0)
|
||||
continue;
|
||||
thresh = del[i] & ~0x7;
|
||||
dir = del[i] & 0x7;
|
||||
thresh = sp->sct_del[i] & ~0x7;
|
||||
dir = sp->sct_del[i] & 0x7;
|
||||
n = deliver(sp, &ichr[i], dir, thresh, vec[i], plague);
|
||||
if (n > 0) {
|
||||
vec[i] -= n;
|
||||
|
@ -241,23 +238,21 @@ void
|
|||
do_fallout(register struct sctstr *sp, register int etus)
|
||||
{
|
||||
int vec[I_MAX + 1];
|
||||
int cvec[I_MAX + 1];
|
||||
int tvec[I_MAX + 1];
|
||||
struct shpstr *spp;
|
||||
struct lndstr *lp;
|
||||
int i;
|
||||
|
||||
getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
|
||||
getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR);
|
||||
/* This check shouldn't be needed, but just in case. :) */
|
||||
if (!cvec[C_FALLOUT] || !sp->sct_updated)
|
||||
if (!sp->sct_fallout || !sp->sct_updated)
|
||||
return;
|
||||
if (etus > 24)
|
||||
etus = 24;
|
||||
#if 0
|
||||
wu(0, 0, "Running fallout in %d,%d\n", sp->sct_x, sp->sct_y);
|
||||
#endif
|
||||
meltitems(etus, cvec[C_FALLOUT], sp->sct_own, vec, EF_SECTOR,
|
||||
meltitems(etus, sp->sct_fallout, sp->sct_own, vec, EF_SECTOR,
|
||||
sp->sct_x, sp->sct_y, 0);
|
||||
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
|
||||
for (i = 0; NULL != (lp = getlandp(i)); i++) {
|
||||
|
@ -266,7 +261,7 @@ do_fallout(register struct sctstr *sp, register int etus)
|
|||
if (lp->lnd_x != sp->sct_x || lp->lnd_y != sp->sct_y)
|
||||
continue;
|
||||
getvec(VT_ITEM, tvec, (s_char *)lp, EF_LAND);
|
||||
meltitems(etus, cvec[C_FALLOUT], lp->lnd_own, tvec, EF_LAND,
|
||||
meltitems(etus, sp->sct_fallout, lp->lnd_own, tvec, EF_LAND,
|
||||
lp->lnd_x, lp->lnd_y, lp->lnd_uid);
|
||||
putvec(VT_ITEM, tvec, (s_char *)lp, EF_LAND);
|
||||
}
|
||||
|
@ -278,12 +273,12 @@ do_fallout(register struct sctstr *sp, register int etus)
|
|||
if (mchr[(int)spp->shp_type].m_flags & M_SUB)
|
||||
continue;
|
||||
getvec(VT_ITEM, tvec, (s_char *)spp, EF_SHIP);
|
||||
meltitems(etus, cvec[C_FALLOUT], spp->shp_own, tvec, EF_SHIP,
|
||||
meltitems(etus, sp->sct_fallout, spp->shp_own, tvec, EF_SHIP,
|
||||
spp->shp_x, spp->shp_y, spp->shp_uid);
|
||||
putvec(VT_ITEM, tvec, (s_char *)spp, EF_SHIP);
|
||||
}
|
||||
#ifdef GODZILLA
|
||||
if ((cvec[C_FALLOUT] > 20) && chance(100))
|
||||
if ((sp->sct_fallout > 20) && chance(100))
|
||||
do_godzilla(sp);
|
||||
#endif /* GODZILLA */
|
||||
}
|
||||
|
@ -292,58 +287,48 @@ void
|
|||
spread_fallout(struct sctstr *sp, int etus)
|
||||
{
|
||||
struct sctstr *ap;
|
||||
int tvec[I_MAX + 1];
|
||||
int cvec[I_MAX + 1];
|
||||
int n;
|
||||
register int inc;
|
||||
|
||||
if (etus > 24)
|
||||
etus = 24;
|
||||
getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR);
|
||||
for (n = DIR_FIRST; n <= DIR_LAST; n++) {
|
||||
ap = getsectp(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1]);
|
||||
getvec(VT_COND, tvec, (char *)ap, EF_SECTOR);
|
||||
if (ap->sct_type == SCT_SANCT)
|
||||
continue;
|
||||
inc = roundavg(etus * fallout_spread * (cvec[C_FALLOUT])) - 1;
|
||||
inc = roundavg(etus * fallout_spread * (sp->sct_fallout)) - 1;
|
||||
#if 0
|
||||
if (cvec[C_FALLOUT]) {
|
||||
if (sp->sct_fallout) {
|
||||
wu(0, 0, "Fallout from sector %d,%d to %d,%d is %d=%d*%e*%d\n",
|
||||
sp->sct_x, sp->sct_y, sp->sct_x + diroff[n][0],
|
||||
sp->sct_y + diroff[n][1], inc, etus,
|
||||
fallout_spread, cvec[C_FALLOUT]);
|
||||
fallout_spread, sp->sct_fallout);
|
||||
}
|
||||
#endif
|
||||
if (inc < 0)
|
||||
inc = 0;
|
||||
tvec[C_FALLOUT] += inc;
|
||||
putvec(VT_COND, tvec, (char *)ap, EF_SECTOR);
|
||||
ap->sct_fallout += inc;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
decay_fallout(struct sctstr *sp, int etus)
|
||||
{
|
||||
int cvec[I_MAX + 1];
|
||||
int decay;
|
||||
|
||||
if (etus > 24)
|
||||
etus = 24;
|
||||
getvec(VT_COND, cvec, (char *)sp, EF_SECTOR);
|
||||
decay = roundavg(((decay_per_etu + 6.0) * fallout_spread) *
|
||||
(double)etus * (double)cvec[C_FALLOUT]);
|
||||
(double)etus * (double)sp->sct_fallout);
|
||||
|
||||
#if 0
|
||||
if (decay || cvec[C_FALLOUT])
|
||||
if (decay || sp->sct_fallout)
|
||||
wu(0, 0, "Fallout decay in %d,%d is %d from %d\n", sp->sct_x,
|
||||
sp->sct_y, decay, cvec[C_FALLOUT]);
|
||||
sp->sct_y, decay, sp->sct_fallout);
|
||||
#endif
|
||||
|
||||
cvec[C_FALLOUT] =
|
||||
(decay < cvec[C_FALLOUT]) ? (cvec[C_FALLOUT] - decay) : 0;
|
||||
if (cvec[C_FALLOUT] < 0)
|
||||
cvec[C_FALLOUT] = 0;
|
||||
putvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR);
|
||||
sp->sct_fallout =
|
||||
(decay < sp->sct_fallout) ? (sp->sct_fallout - decay) : 0;
|
||||
}
|
||||
|
||||
#define SHOULD_PRODUCE(sp,t) (((sp->sct_type == t) || (t == -1)) ? 1 : 0)
|
||||
|
|
|
@ -117,7 +117,7 @@ upd_ship(register struct shpstr *sp, register int etus,
|
|||
struct sctstr *sectp;
|
||||
struct mchrstr *mp;
|
||||
int vec[I_MAX + 1];
|
||||
int cvec[I_MAX + 1];
|
||||
u_short pstage, ptime;
|
||||
int oil_gained;
|
||||
int max_oil;
|
||||
int max_food;
|
||||
|
@ -204,9 +204,10 @@ upd_ship(register struct shpstr *sp, register int etus,
|
|||
* do plague stuff. plague can't break out on ships,
|
||||
* but it can still kill people.
|
||||
*/
|
||||
getvec(VT_COND, cvec, (s_char *)sp, EF_SHIP);
|
||||
if (cvec[C_PSTAGE] > 0) {
|
||||
n = plague_people(np, vec, cvec, etus);
|
||||
pstage = sp->shp_pstage;
|
||||
ptime = sp->shp_ptime;
|
||||
if (pstage != PLG_HEALTHY) {
|
||||
n = plague_people(np, vec, &pstage, &ptime, etus);
|
||||
switch (n) {
|
||||
case PLG_DYING:
|
||||
wu(0, sp->shp_own,
|
||||
|
@ -218,9 +219,9 @@ upd_ship(register struct shpstr *sp, register int etus,
|
|||
break;
|
||||
case PLG_INCUBATE:
|
||||
/* Are we still incubating? */
|
||||
if (n == cvec[C_PSTAGE]) {
|
||||
if (n == pstage) {
|
||||
/* Yes. Will it turn "infectious" next time? */
|
||||
if (cvec[C_PTIME] <= etus) {
|
||||
if (ptime <= etus) {
|
||||
/* Yes. Report an outbreak. */
|
||||
wu(0, sp->shp_own,
|
||||
"Outbreak of PLAGUE on %s!\n", prship(sp));
|
||||
|
@ -234,9 +235,9 @@ upd_ship(register struct shpstr *sp, register int etus,
|
|||
break;
|
||||
case PLG_EXPOSED:
|
||||
/* Has the plague moved to "incubation" yet? */
|
||||
if (n != cvec[C_PSTAGE]) {
|
||||
if (n != pstage) {
|
||||
/* Yes. Will it turn "infectious" next time? */
|
||||
if (cvec[C_PTIME] <= etus) {
|
||||
if (ptime <= etus) {
|
||||
/* Yes. Report an outbreak. */
|
||||
wu(0, sp->shp_own,
|
||||
"Outbreak of PLAGUE on %s!\n", prship(sp));
|
||||
|
@ -248,7 +249,8 @@ upd_ship(register struct shpstr *sp, register int etus,
|
|||
break;
|
||||
}
|
||||
|
||||
putvec(VT_COND, cvec, (s_char *)sp, EF_SHIP);
|
||||
sp->shp_pstage = pstage;
|
||||
sp->shp_ptime = ptime;
|
||||
}
|
||||
putvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP);
|
||||
pops[sp->shp_own] += vec[I_CIVIL];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue