(grin): Stop grinding before grind puts more than ITEM_MAX bar
constituents in sector. 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 before flushing those.
This commit is contained in:
parent
2a3b29ebe1
commit
ab482ecd39
1 changed files with 11 additions and 13 deletions
|
@ -46,12 +46,12 @@ int
|
||||||
grin(void)
|
grin(void)
|
||||||
{
|
{
|
||||||
struct nstr_sect nstr;
|
struct nstr_sect nstr;
|
||||||
int vec[I_MAX + 1];
|
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
s_char *p;
|
s_char *p;
|
||||||
int i, n, qty;
|
int i, n, qty;
|
||||||
int avail;
|
int avail;
|
||||||
s_char buf[1024];
|
s_char buf[1024];
|
||||||
|
double grind_eff = 0.8;
|
||||||
|
|
||||||
if ((p = getstarg(player->argp[1], "Sectors? ", buf)) == 0)
|
if ((p = getstarg(player->argp[1], "Sectors? ", buf)) == 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
|
@ -65,29 +65,27 @@ grin(void)
|
||||||
while (nxtsct(&nstr, §)) {
|
while (nxtsct(&nstr, §)) {
|
||||||
if (!player->owner)
|
if (!player->owner)
|
||||||
continue;
|
continue;
|
||||||
/* getsect(item.sct_x, item.sct_y, §); */
|
|
||||||
if (sect.sct_effic < 60 || sect.sct_own != player->cnum)
|
if (sect.sct_effic < 60 || sect.sct_own != player->cnum)
|
||||||
continue;
|
continue;
|
||||||
getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
|
n = sect.sct_item[I_BAR] >= qty ? qty : sect.sct_item[I_BAR];
|
||||||
n = (vec[I_BAR] >= qty) ? qty : vec[I_BAR];
|
|
||||||
avail = n * 5.0;
|
avail = n * 5.0;
|
||||||
if (avail > sect.sct_avail) {
|
if (avail > sect.sct_avail) {
|
||||||
n = sect.sct_avail / 5;
|
n = sect.sct_avail / 5;
|
||||||
avail = sect.sct_avail;
|
avail = sect.sct_avail;
|
||||||
if (n == 0)
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (n) {
|
for (i = 0; i < pchr[P_BAR].p_nv; i++) {
|
||||||
vec[I_BAR] -= n;
|
n = min(n,
|
||||||
|
(double)(ITEM_MAX - sect.sct_item[pchr[P_BAR].p_vtype[i]])
|
||||||
|
/ (pchr[P_BAR].p_vamt[i] * grind_eff));
|
||||||
|
}
|
||||||
|
if (n > 0) {
|
||||||
pr("%d bars ground up in %s\n", n,
|
pr("%d bars ground up in %s\n", n,
|
||||||
xyas(sect.sct_x, sect.sct_y, player->cnum));
|
xyas(sect.sct_x, sect.sct_y, player->cnum));
|
||||||
|
sect.sct_item[I_BAR] -= n;
|
||||||
for (i = 0; i < pchr[P_BAR].p_nv; i++) {
|
for (i = 0; i < pchr[P_BAR].p_nv; i++) {
|
||||||
vec[unitem(pchr[P_BAR].p_vtype[i])] += (int)((n *
|
sect.sct_item[pchr[P_BAR].p_vtype[i]]
|
||||||
pchr[P_BAR].
|
+= n * pchr[P_BAR].p_vamt[i] * grind_eff;
|
||||||
p_vamt[i]) *
|
|
||||||
0.8);
|
|
||||||
}
|
}
|
||||||
putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
|
|
||||||
sect.sct_avail -= avail;
|
sect.sct_avail -= avail;
|
||||||
putsect(§);
|
putsect(§);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue