(do_fallout, meltitems): Work directly on item arrays instead of
copies made by getvec(). This is safe, because the old code made single copies and always flushed them back into the unit structures. (meltitems): Don't claim more items were lost than existed.
This commit is contained in:
parent
c922b571db
commit
eb94c88806
1 changed files with 12 additions and 24 deletions
|
@ -193,33 +193,32 @@ enlist(register int *vec, int etu, int *cost)
|
||||||
/* Fallout is calculated here. */
|
/* Fallout is calculated here. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meltitems(int etus, int fallout, int own, int *vec, int type, int x, int y,
|
meltitems(int etus, int fallout, int own, short *vec, int type, int x, int y,
|
||||||
int uid)
|
int uid)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
int melt;
|
int melt;
|
||||||
|
|
||||||
for (n = 1; n <= I_MAX; n++) {
|
for (n = 1; n <= I_MAX; n++) {
|
||||||
melt = roundavg(vec[n] * etus * (long)fallout /
|
melt = roundavg(vec[n] * etus * (long)fallout
|
||||||
(1000.0 * melt_item_denom[n]));
|
/ (1000.0 * melt_item_denom[n]));
|
||||||
|
if (melt > vec[n])
|
||||||
|
melt = vec[n];
|
||||||
if (melt > 5 && own) {
|
if (melt > 5 && own) {
|
||||||
if (type == EF_SECTOR)
|
if (type == EF_SECTOR)
|
||||||
wu(0, own, "Lost %d %s to radiation in %s.\n",
|
wu(0, own, "Lost %d %s to radiation in %s.\n",
|
||||||
(melt < vec[n] ? melt : vec[n]), ichr[n].i_name,
|
melt < vec[n] ? melt : vec[n], ichr[n].i_name,
|
||||||
xyas(x, y, own));
|
xyas(x, y, own));
|
||||||
else if (type == EF_LAND)
|
else if (type == EF_LAND)
|
||||||
wu(0, own, "Unit #%d lost %d %s to radiation in %s.\n",
|
wu(0, own, "Unit #%d lost %d %s to radiation in %s.\n",
|
||||||
uid, (melt < vec[n] ? melt : vec[n]), ichr[n].i_name,
|
uid, melt < vec[n] ? melt : vec[n], ichr[n].i_name,
|
||||||
xyas(x, y, own));
|
xyas(x, y, own));
|
||||||
else if (type == EF_SHIP)
|
else if (type == EF_SHIP)
|
||||||
wu(0, own, "Ship #%d lost %d %s to radiation in %s.\n",
|
wu(0, own, "Ship #%d lost %d %s to radiation in %s.\n",
|
||||||
uid, (melt < vec[n] ? melt : vec[n]), ichr[n].i_name,
|
uid, melt < vec[n] ? melt : vec[n], ichr[n].i_name,
|
||||||
xyas(x, y, own));
|
xyas(x, y, own));
|
||||||
}
|
}
|
||||||
if (melt < vec[n])
|
vec[n] -= melt;
|
||||||
vec[n] -= melt;
|
|
||||||
else
|
|
||||||
vec[n] = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,33 +232,24 @@ meltitems(int etus, int fallout, int own, int *vec, int type, int x, int y,
|
||||||
void
|
void
|
||||||
do_fallout(register struct sctstr *sp, register int etus)
|
do_fallout(register struct sctstr *sp, register int etus)
|
||||||
{
|
{
|
||||||
int vec[I_MAX + 1];
|
|
||||||
int tvec[I_MAX + 1];
|
|
||||||
struct shpstr *spp;
|
struct shpstr *spp;
|
||||||
struct lndstr *lp;
|
struct lndstr *lp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
|
|
||||||
/* This check shouldn't be needed, but just in case. :) */
|
/* This check shouldn't be needed, but just in case. :) */
|
||||||
if (!sp->sct_fallout || !sp->sct_updated)
|
if (!sp->sct_fallout || !sp->sct_updated)
|
||||||
return;
|
return;
|
||||||
if (etus > 24)
|
if (etus > 24)
|
||||||
etus = 24;
|
etus = 24;
|
||||||
#if 0
|
meltitems(etus, sp->sct_fallout, sp->sct_own, sp->sct_item, EF_SECTOR,
|
||||||
wu(0, 0, "Running fallout in %d,%d\n", sp->sct_x, sp->sct_y);
|
|
||||||
#endif
|
|
||||||
meltitems(etus, sp->sct_fallout, sp->sct_own, vec, EF_SECTOR,
|
|
||||||
sp->sct_x, sp->sct_y, 0);
|
sp->sct_x, sp->sct_y, 0);
|
||||||
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
|
|
||||||
for (i = 0; NULL != (lp = getlandp(i)); i++) {
|
for (i = 0; NULL != (lp = getlandp(i)); i++) {
|
||||||
if (!lp->lnd_own)
|
if (!lp->lnd_own)
|
||||||
continue;
|
continue;
|
||||||
if (lp->lnd_x != sp->sct_x || lp->lnd_y != sp->sct_y)
|
if (lp->lnd_x != sp->sct_x || lp->lnd_y != sp->sct_y)
|
||||||
continue;
|
continue;
|
||||||
getvec(VT_ITEM, tvec, (s_char *)lp, EF_LAND);
|
meltitems(etus, sp->sct_fallout, lp->lnd_own, lp->lnd_item, EF_LAND,
|
||||||
meltitems(etus, sp->sct_fallout, lp->lnd_own, tvec, EF_LAND,
|
|
||||||
lp->lnd_x, lp->lnd_y, lp->lnd_uid);
|
lp->lnd_x, lp->lnd_y, lp->lnd_uid);
|
||||||
putvec(VT_ITEM, tvec, (s_char *)lp, EF_LAND);
|
|
||||||
}
|
}
|
||||||
for (i = 0; NULL != (spp = getshipp(i)); i++) {
|
for (i = 0; NULL != (spp = getshipp(i)); i++) {
|
||||||
if (!spp->shp_own)
|
if (!spp->shp_own)
|
||||||
|
@ -268,10 +258,8 @@ do_fallout(register struct sctstr *sp, register int etus)
|
||||||
continue;
|
continue;
|
||||||
if (mchr[(int)spp->shp_type].m_flags & M_SUB)
|
if (mchr[(int)spp->shp_type].m_flags & M_SUB)
|
||||||
continue;
|
continue;
|
||||||
getvec(VT_ITEM, tvec, (s_char *)spp, EF_SHIP);
|
meltitems(etus, sp->sct_fallout, spp->shp_own, spp->shp_item, EF_SHIP,
|
||||||
meltitems(etus, sp->sct_fallout, spp->shp_own, tvec, EF_SHIP,
|
|
||||||
spp->shp_x, spp->shp_y, spp->shp_uid);
|
spp->shp_x, spp->shp_y, spp->shp_uid);
|
||||||
putvec(VT_ITEM, tvec, (s_char *)spp, EF_SHIP);
|
|
||||||
}
|
}
|
||||||
#ifdef GODZILLA
|
#ifdef GODZILLA
|
||||||
if ((sp->sct_fallout > 20) && chance(100))
|
if ((sp->sct_fallout > 20) && chance(100))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue