Пример #1
0
/**
 * @brief Calculates the total frame count (minutes) needed for producing an item
 * @param[in] base Pointer to the base the production happen
 * @param[in] prodData Pointer to the productionData structure
 */
static int PR_CalculateTotalFrames (const base_t* base, const productionData_t* prodData)
{
	/* Check how many workers hired in this base. */
	const signed int allWorkers = E_CountHired(base, EMPL_WORKER);
	/* We will not use more workers than workspace capacity in this base. */
	const signed int maxWorkers = std::min(allWorkers, CAP_GetMax(base, CAP_WORKSPACE));

	double timeDefault;
	if (PR_IsProductionData(prodData)) {
		const technology_t* tech = PR_GetTech(prodData);
		/* This is the default production time for PRODUCE_WORKERS workers. */
		timeDefault = tech->produceTime;
	} else {
		const storedUFO_t* storedUFO = prodData->data.ufo;
		/* This is the default disassemble time for PRODUCE_WORKERS workers. */
		timeDefault = storedUFO->comp->time;
		/* Production is 4 times longer when installation is on Antipodes
		 * Penalty starts when distance is greater than 45 degrees */
		timeDefault *= std::max(1.0, GetDistanceOnGlobe(storedUFO->installation->pos, base->pos) / 45.0);
	}
	/* Calculate the time needed for production of the item for our amount of workers. */
	const float rate = PRODUCE_WORKERS / ccs.curCampaign->produceRate;
	double const timeScaled = timeDefault * (MINUTES_PER_HOUR * rate) / std::max(1, maxWorkers);

	/* Don't allow to return a time of less than 1 (you still need at least 1 minute to produce an item). */
	return std::max(1.0, timeScaled) + 1;
}
Пример #2
0
/**
 * @brief Calculates the total frame count (minutes) needed for producing an item for a single worker
 * @param[in] base Pointer to the base the production happen
 * @param[in] prodData Pointer to the productionData structure
 */
static int PR_CalculateTotalFrames (const base_t* base, const productionData_t* prodData)
{
	double time;
	if (PR_IsProductionData(prodData)) {
		const technology_t* tech = PR_GetTech(prodData);
		time = tech->produceTime;
	} else {
		const storedUFO_t* storedUFO = prodData->data.ufo;
		time = storedUFO->comp->time;
		/* Production is 4 times longer when installation is on Antipodes
		 * Penalty starts when distance is greater than 45 degrees */
		time *= std::max(1.0, GetDistanceOnGlobe(storedUFO->installation->pos, base->pos) / 45.0);
	}
	/* Calculate the time needed for production of the item for our amount of workers. */
	time *= MINUTES_PER_HOUR * ccs.curCampaign->produceRate;

	/* Don't allow to return a time of less than 1 (you still need at least 1 minute to produce an item). */
	return std::max(1.0, time) + 1;
}