/** * @brief increases production amount if possible * @param[in,out] prod Pointer to the production * @param[in] amount Additional amount to add * @returns the amount added */ int PR_IncreaseProduction (production_t* prod, int amount) { if (PR_IsDisassembly(prod)) return 0; base_t* base = PR_ProductionBase(prod); assert(base); /* amount limit per one production */ if (prod->amount + amount > MAX_PRODUCTION_AMOUNT) { amount = std::max(0, MAX_PRODUCTION_AMOUNT - prod->amount); } const technology_t* tech = PR_GetTech(&prod->data); assert(tech); amount = PR_RequirementsMet(amount, &tech->requireForProduction, base); if (amount == 0) return 0; prod->amount += amount; PR_UpdateRequiredItemsInBasestorage(base, -amount, &tech->requireForProduction); return amount; }
/** * @brief decreases production amount * @param[in,out] prod Pointer to the production * @param[in] amount Additional amount to remove (positive number) * @returns the amount removed * @note if production amount falls below 1 it removes the whole production from the queue as well */ int PR_DecreaseProduction (production_t* prod, int amount) { assert(prod); base_t* base = PR_ProductionBase(prod); assert(base); if (PR_IsDisassembly(prod)) return 0; if (prod->amount <= amount) { production_queue_t* queue = PR_GetProductionForBase(base); amount = prod->amount; PR_QueueDelete(base, queue, prod->idx); return amount; } const technology_t* tech = PR_GetTech(&prod->data); if (tech == nullptr) cgi->Com_Error(ERR_DROP, "No tech pointer for production"); prod->amount += -amount; PR_UpdateRequiredItemsInBasestorage(base, amount, &tech->requireForProduction); return amount; }
/** * @brief Calculates the remaining time for a technology in minutes * @param[in] prod Pointer to the production structure */ int PR_GetRemainingMinutes (const production_t* prod) { assert(prod); const base_t *base = PR_ProductionBase(prod); return (prod->totalFrames - prod->frame) / std::max(1, PR_WorkersAvailable(base)); }