(grin): Grind up whatever banks produce instead of P_BAR. This is in

preparation of getting rid of P_BAR & friends.

(grin): Avail use was wrong when amount was reduced due to the space
limit.
This commit is contained in:
Markus Armbruster 2006-06-06 17:53:59 +00:00
parent f284b0beab
commit bd7b0fea5d

View file

@ -49,12 +49,19 @@ grin(void)
struct nstr_sect nstr; struct nstr_sect nstr;
struct sctstr sect; struct sctstr sect;
char *p; char *p;
int i, n, qty; int prd, i, n, qty;
int avail;
char buf[1024]; char buf[1024];
double grind_eff = 0.8; double grind_eff = 0.8;
i_type *ctype = pchr[P_BAR].p_ctype; struct pchrstr *pp;
unsigned short *camt = pchr[P_BAR].p_camt; i_type ctype;
unsigned camt;
prd = dchr[SCT_BANK].d_prd;
if (prd < 0 || pchr[prd].p_type < 0) {
pr("Grinding is disabled.\n");
return RET_FAIL;
}
pp = &pchr[prd];
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,27 +72,28 @@ grin(void)
qty = atoi(p); qty = atoi(p);
if (qty < 0) if (qty < 0)
return RET_SYN; return RET_SYN;
while (nxtsct(&nstr, &sect)) { while (nxtsct(&nstr, &sect)) {
if (!player->owner) if (!player->owner)
continue; continue;
if (sect.sct_effic < 60 || sect.sct_own != player->cnum) if (sect.sct_effic < 60 || sect.sct_own != player->cnum)
continue; continue;
n = sect.sct_item[I_BAR] >= qty ? qty : sect.sct_item[I_BAR];
/* materials limit */
n = MIN(qty, sect.sct_item[pp->p_type]);
/* work limit */ /* work limit */
avail = n * 5; n = MIN(n, sect.sct_avail / 5);
if (avail > sect.sct_avail) {
n = sect.sct_avail / 5;
avail = sect.sct_avail;
}
/* space limit */ /* space limit */
for (i = 0; i < MAXPRCON; i++) { for (i = 0; i < MAXPRCON; i++) {
if (!camt[i]) ctype = pp->p_ctype[i];
camt = pp->p_camt[i];
if (!camt)
continue; continue;
if (CANT_HAPPEN(ctype[i] <= I_NONE || ctype[i] > I_MAX)) if (CANT_HAPPEN(ctype <= I_NONE || ctype > I_MAX))
continue; continue;
n = MIN(n, n = MIN(n,
(double)(ITEM_MAX - sect.sct_item[ctype[i]]) (double)(ITEM_MAX - sect.sct_item[ctype])
/ (camt[i] * grind_eff)); / (camt * grind_eff));
} }
if (n > 0) { if (n > 0) {
@ -93,13 +101,15 @@ grin(void)
xyas(sect.sct_x, sect.sct_y, player->cnum)); xyas(sect.sct_x, sect.sct_y, player->cnum));
sect.sct_item[I_BAR] -= n; sect.sct_item[I_BAR] -= n;
for (i = 0; i < MAXPRCON; i++) { for (i = 0; i < MAXPRCON; i++) {
if (!camt[i]) ctype = pp->p_ctype[i];
camt = pp->p_camt[i];
if (!camt)
continue; continue;
if (CANT_HAPPEN(ctype[i] <= I_NONE || ctype[i] > I_MAX)) if (CANT_HAPPEN(ctype <= I_NONE || ctype > I_MAX))
continue; continue;
sect.sct_item[ctype[i]] += n * camt[i] * grind_eff; sect.sct_item[ctype] += n * camt * grind_eff;
} }
sect.sct_avail -= avail; sect.sct_avail -= n * 5;
putsect(&sect); putsect(&sect);
} }
} }