From bd7b0fea5dbc424bae73e85b7d13bcc2fa09c77e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 6 Jun 2006 17:53:59 +0000 Subject: [PATCH] (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. --- src/lib/commands/grin.c | 46 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/lib/commands/grin.c b/src/lib/commands/grin.c index e3c09716..d779b3d5 100644 --- a/src/lib/commands/grin.c +++ b/src/lib/commands/grin.c @@ -49,12 +49,19 @@ grin(void) struct nstr_sect nstr; struct sctstr sect; char *p; - int i, n, qty; - int avail; + int prd, i, n, qty; char buf[1024]; double grind_eff = 0.8; - i_type *ctype = pchr[P_BAR].p_ctype; - unsigned short *camt = pchr[P_BAR].p_camt; + struct pchrstr *pp; + 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) return RET_SYN; @@ -65,27 +72,28 @@ grin(void) qty = atoi(p); if (qty < 0) return RET_SYN; + while (nxtsct(&nstr, §)) { if (!player->owner) continue; if (sect.sct_effic < 60 || sect.sct_own != player->cnum) 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 */ - avail = n * 5; - if (avail > sect.sct_avail) { - n = sect.sct_avail / 5; - avail = sect.sct_avail; - } + n = MIN(n, sect.sct_avail / 5); /* space limit */ for (i = 0; i < MAXPRCON; i++) { - if (!camt[i]) + ctype = pp->p_ctype[i]; + camt = pp->p_camt[i]; + if (!camt) continue; - if (CANT_HAPPEN(ctype[i] <= I_NONE || ctype[i] > I_MAX)) + if (CANT_HAPPEN(ctype <= I_NONE || ctype > I_MAX)) continue; n = MIN(n, - (double)(ITEM_MAX - sect.sct_item[ctype[i]]) - / (camt[i] * grind_eff)); + (double)(ITEM_MAX - sect.sct_item[ctype]) + / (camt * grind_eff)); } if (n > 0) { @@ -93,13 +101,15 @@ grin(void) xyas(sect.sct_x, sect.sct_y, player->cnum)); sect.sct_item[I_BAR] -= n; for (i = 0; i < MAXPRCON; i++) { - if (!camt[i]) + ctype = pp->p_ctype[i]; + camt = pp->p_camt[i]; + if (!camt) continue; - if (CANT_HAPPEN(ctype[i] <= I_NONE || ctype[i] > I_MAX)) + if (CANT_HAPPEN(ctype <= I_NONE || ctype > I_MAX)) 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(§); } }