diff --git a/src/intdisplay.c b/src/intdisplay.c index ceac4ac6f..96f3ad821 100644 --- a/src/intdisplay.c +++ b/src/intdisplay.c @@ -419,7 +419,7 @@ void intAddProdQuantity(WIDGET *psWidget, W_CONTEXT *psContext) DROID_TEMPLATE *psTemplate = (DROID_TEMPLATE *)psStat; STRUCTURE *psStructure = NULL; BASE_OBJECT *psObj = getCurrentSelected(); - UDWORD quantity = 0; + UDWORD quantity = 0, remaining = 0; if (psObj != NULL && psObj->type == OBJ_STRUCTURE && !isDead(psObj)) { @@ -431,6 +431,16 @@ void intAddProdQuantity(WIDGET *psWidget, W_CONTEXT *psContext) quantity = getProductionQuantity(psStructure, psTemplate); } + // now find out how many we have built + remaining = getProductionBuilt(psStructure, psTemplate); + if (quantity > remaining) + { + quantity -= remaining; + } + else + { + quantity = 0; + } if (quantity != 0) { snprintf(Label->aText, sizeof(Label->aText), "%u", quantity); diff --git a/src/structure.c b/src/structure.c index b14cb5864..ded148bc7 100644 --- a/src/structure.c +++ b/src/structure.c @@ -6814,6 +6814,7 @@ void factoryProdAdjust(STRUCTURE *psStructure, DROID_TEMPLATE *psTemplate, BOOL UDWORD inc, factoryType, factoryInc; FACTORY *psFactory; BOOL bAssigned = FALSE, bCheckForCancel = FALSE; + UBYTE built, quantity, remaining; CHECK_STRUCTURE(psStructure); ASSERT( psStructure->player == productionPlayer, @@ -6828,11 +6829,15 @@ void factoryProdAdjust(STRUCTURE *psStructure, DROID_TEMPLATE *psTemplate, BOOL { if (asProductionRun[factoryType][factoryInc][inc].psTemplate == psTemplate) { - //adjust the prod run - if (add) + //adjust the prod run + if (add) //user left clicked, so increase # in queue { - asProductionRun[factoryType][factoryInc][inc].quantity++; - if (asProductionRun[factoryType][factoryInc][inc].quantity > MAX_IN_RUN) + // Allows us to queue up more units up to MAX_IN_RUN instead of ignoring how many we have built from that queue + quantity = ++asProductionRun[factoryType][factoryInc][inc].quantity; + built = asProductionRun[factoryType][factoryInc][inc].built; + remaining = quantity - built; + // check to see if user canceled all orders in queue + if (remaining > MAX_IN_RUN) { asProductionRun[factoryType][factoryInc][inc].quantity = 0; //initialise the template @@ -6847,7 +6852,7 @@ void factoryProdAdjust(STRUCTURE *psStructure, DROID_TEMPLATE *psTemplate, BOOL } } } - else + else //user right clicked, so we subtract form queue { if (asProductionRun[factoryType][factoryInc][inc].quantity == 0) {