UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_produce.cpp File Reference

Single player production stuff. More...

#include "../../DateTime.h"
#include "../../cl_shared.h"
#include "cp_campaign.h"
#include "cp_capacity.h"
#include "cp_ufo.h"
#include "cp_produce.h"
#include "cp_produce_callbacks.h"
#include "save/save_produce.h"
Include dependency graph for cp_produce.cpp:

Go to the source code of this file.

Functions

static int PR_CalculateTotalFrames (const base_t *base, const productionData_t *prodData)
 Calculates the total frame count (minutes) needed for producing an item for a single worker.
int PR_WorkersAvailable (const base_t *base)
 Returns the numer of workers available to produce an item.
int PR_GetRemainingMinutes (const production_t *prod)
 Calculates the remaining time for a technology in minutes.
int PR_GetRemainingHours (const production_t *prod)
 Calculates the remaining hours for a technology.
int PR_GetProductionHours (const base_t *base, const productionData_t *prodData)
 Calculates the production time (in hours) for a technology.
void PR_UpdateRequiredItemsInBasestorage (base_t *base, int amount, const requirements_t *reqs)
 Remove or add the required items from/to the a base.
int PR_RequirementsMet (int amount, const requirements_t *reqs, base_t *base)
 Checks if the production requirements are met for a defined amount.
const char * PR_GetName (const productionData_t *data)
technology_tPR_GetTech (const productionData_t *data)
static void PR_ResetUFODisassembly (production_t *prod)
static void PR_SetUFODisassembly (production_t *prod)
production_tPR_QueueNew (base_t *base, const productionData_t *data, signed int amount)
 Add a new item to the bottom of the production queue.
void PR_QueueDelete (base_t *base, production_queue_t *queue, int index)
 Delete the selected entry from the queue.
void PR_QueueMove (production_queue_t *queue, int index, int offset)
 Moves the given queue item in the given direction.
void PR_QueueNext (base_t *base)
 Queues the next production in the queue.
static void PR_EmptyQueue (base_t *base)
 clears the production queue on a base
static void PR_ProductionRollBottom (base_t *base)
 moves the first production to the bottom of the list
static bool PR_CheckFrame (base_t *base, production_t *prod)
 Checks whether production can continue.
static void PR_FinishProduction (base_t *base, production_t *prod)
 Run actions on finishing production of one item/aircraft/UGV..
static void PR_FinishDisassembly (base_t *base, production_t *prod)
 Run actions on finishing disassembling of a ufo.
int PR_IncreaseProduction (production_t *prod, int amount)
 increases production amount if possible
int PR_DecreaseProduction (production_t *prod, int amount)
 decreases production amount
void PR_ProductionRun (void)
 Checks whether an item is finished.
bool PR_ProductionAllowed (const base_t *base)
 Returns true if the current base is able to produce items.
void PR_UpdateProductionCap (base_t *base, int workerChange)
 Update the current capacity of Workshop.
bool PR_ItemIsProduceable (const objDef_t *item)
 check if an item is producable.
base_tPR_ProductionBase (const production_t *production)
 Returns the base pointer the production belongs to.
int PR_GetPrice (const int productionCost)
 Used in production costs (to allow reducing prices below 1x).
bool PR_SaveXML (xmlNode_t *p)
 Save callback for savegames in XML Format.
bool PR_LoadXML (xmlNode_t *p)
 Load callback for xml savegames.
static bool PR_PostLoadInitProgress (void)
 Set percentDone values after loading the campaign.
bool PR_PostLoadInit (void)
 actions to do with productions after loading a savegame

Detailed Description

Single player production stuff.

Note
Production stuff functions prefix: PR_

Definition in file cp_produce.cpp.

Function Documentation

◆ PR_CalculateTotalFrames()

int PR_CalculateTotalFrames ( const base_t * base,
const productionData_t * prodData )
static

Calculates the total frame count (minutes) needed for producing an item for a single worker.

Parameters
[in]basePointer to the base the production happen
[in]prodDataPointer to the productionData structure

Definition at line 40 of file cp_produce.cpp.

References ccs, storedUFO_t::comp, productionData_t::data, GetDistanceOnGlobe(), storedUFO_t::installation, DateTime::MINUTES_PER_HOUR, base_t::pos, installation_t::pos, PR_GetTech(), PR_IsProductionData, technology_t::produceTime, and productionData_t::productionItem_t::ufo.

Referenced by PR_GetProductionHours(), PR_LoadXML(), PR_PostLoadInitProgress(), PR_QueueNew(), and PR_UpdateProductionCap().

◆ PR_CheckFrame()

bool PR_CheckFrame ( base_t * base,
production_t * prod )
static

Checks whether production can continue.

Parameters
baseThe base the production is running in
prodThe production
Returns
false if production is stopped, true if production can be continued.

Definition at line 388 of file cp_produce.cpp.

References _, productionData_t::productionItem_t::aircraft, ccs, Com_sprintf(), cp_messageBuffer, production_t::creditMessage, production_t::data, productionData_t::data, productionData_t::productionItem_t::item, MSO_CheckAddNewMessage(), base_t::name, NT_PRODUCTION_FAILED, PR_GetPrice(), PR_IsAircraft, PR_IsItem, PR_ProductionRollBottom(), aircraft_t::productionCost, and objDef_t::productionCost.

Referenced by PR_ProductionRun().

◆ PR_DecreaseProduction()

int PR_DecreaseProduction ( production_t * prod,
int amount )

decreases production amount

Parameters
[in,out]prodPointer to the production
[in]amountAdditional 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

Definition at line 523 of file cp_produce.cpp.

References production_t::amount, cgi, production_t::data, ERR_DROP, production_t::idx, PR_GetProductionForBase, PR_GetTech(), PR_IsDisassembly, PR_ProductionBase(), PR_QueueDelete(), PR_UpdateRequiredItemsInBasestorage(), and technology_t::requireForProduction.

Referenced by PR_ProductionDecrease_f().

◆ PR_EmptyQueue()

void PR_EmptyQueue ( base_t * base)
static

clears the production queue on a base

Definition at line 360 of file cp_produce.cpp.

References production_queue_t::numItems, PR_GetProductionForBase, and PR_QueueDelete().

Referenced by PR_UpdateProductionCap().

◆ PR_FinishDisassembly()

◆ PR_FinishProduction()

◆ PR_GetName()

const char * PR_GetName ( const productionData_t * data)
Returns
The translated name of the item in production

Definition at line 182 of file cp_produce.cpp.

References _, cgi, data, ERR_DROP, PRODUCTION_TYPE_AIRCRAFT, PRODUCTION_TYPE_DISASSEMBLY, PRODUCTION_TYPE_ITEM, and UFO_TypeToName().

Referenced by PR_FinishProduction(), PR_ProductionIncrease_f(), and PR_ShowActiveProduction_f().

◆ PR_GetPrice()

int PR_GetPrice ( const int productionCost)

Used in production costs (to allow reducing prices below 1x).

Parameters
[in]productionCostproduction cost being modified
Returns
price modified by the component rate in campaign.ufo

Definition at line 667 of file cp_produce.cpp.

References ccs.

Referenced by PR_AircraftInfo(), PR_CheckFrame(), PR_FinishProduction(), and PR_ItemProductionInfo().

◆ PR_GetProductionHours()

int PR_GetProductionHours ( const base_t * base,
const productionData_t * prodData )

Calculates the production time (in hours) for a technology.

Parameters
[in]basePointer to the base to calculate production time at
[in]prodDataPointer to the production data structure

Definition at line 100 of file cp_produce.cpp.

References DateTime::MINUTES_PER_HOUR, PR_CalculateTotalFrames(), and PR_WorkersAvailable().

Referenced by PR_ProductionInfo().

◆ PR_GetRemainingHours()

int PR_GetRemainingHours ( const production_t * prod)

Calculates the remaining hours for a technology.

Parameters
[in]prodPointer to the production structure

Definition at line 90 of file cp_produce.cpp.

References DateTime::MINUTES_PER_HOUR, and PR_GetRemainingMinutes().

Referenced by PR_ProductionInfo(), TEST_F(), TEST_F(), and TEST_F().

◆ PR_GetRemainingMinutes()

int PR_GetRemainingMinutes ( const production_t * prod)

Calculates the remaining time for a technology in minutes.

Parameters
[in]prodPointer to the production structure

Definition at line 79 of file cp_produce.cpp.

References production_t::frame, PR_ProductionBase(), PR_WorkersAvailable(), and production_t::totalFrames.

Referenced by PR_GetRemainingHours(), TEST_F(), TEST_F(), and TEST_F().

◆ PR_GetTech()

◆ PR_IncreaseProduction()

int PR_IncreaseProduction ( production_t * prod,
int amount )

increases production amount if possible

Parameters
[in,out]prodPointer to the production
[in]amountAdditional amount to add
Returns
the amount added

Definition at line 490 of file cp_produce.cpp.

References production_t::amount, production_t::data, MAX_PRODUCTION_AMOUNT, PR_GetTech(), PR_IsDisassembly, PR_ProductionBase(), PR_RequirementsMet(), PR_UpdateRequiredItemsInBasestorage(), and technology_t::requireForProduction.

Referenced by PR_ProductionIncrease_f().

◆ PR_ItemIsProduceable()

bool PR_ItemIsProduceable ( const objDef_t * item)

check if an item is producable.

Parameters
[in]itemPointer to the item that should be checked.

Definition at line 640 of file cp_produce.cpp.

References technology_t::produceTime, and RS_GetTechForItem().

Referenced by CP_ItemsSanityCheck(), PR_ItemProductionInfo(), PR_ProductionListClick_f(), and PR_UpdateProductionList().

◆ PR_LoadXML()

◆ PR_PostLoadInit()

bool PR_PostLoadInit ( void )

actions to do with productions after loading a savegame

See also
SAV_GameActionsAfterLoad

Definition at line 803 of file cp_produce.cpp.

References PR_PostLoadInitProgress().

Referenced by SAV_GameActionsAfterLoad().

◆ PR_PostLoadInitProgress()

bool PR_PostLoadInitProgress ( void )
static

Set percentDone values after loading the campaign.

Note
it need to be done after B_PostLoadInitCapacity
See also
PR_PostLoadInit

Definition at line 785 of file cp_produce.cpp.

References B_GetNext(), production_t::data, production_queue_t::items, production_queue_t::numItems, PR_CalculateTotalFrames(), PR_GetProductionForBase, and production_t::totalFrames.

Referenced by PR_PostLoadInit().

◆ PR_ProductionAllowed()

bool PR_ProductionAllowed ( const base_t * base)

Returns true if the current base is able to produce items.

Parameters
[in]basePointer to the base.
See also
B_BaseInit_f

Definition at line 596 of file cp_produce.cpp.

References B_GetBuildingStatus(), B_IsUnderAttack, B_WORKSHOP, E_CountHired(), and EMPL_WORKER.

Referenced by B_BaseInit_f(), B_BuildingOpenAfterClick_f(), PR_ProductionRun(), PR_ShowActiveProduction_f(), PR_UpdateProductionCap(), TEST_F(), TEST_F(), TEST_F(), and TR_TransferStart().

◆ PR_ProductionBase()

base_t * PR_ProductionBase ( const production_t * production)

Returns the base pointer the production belongs to.

Parameters
[in]productionpointer to the production entry
Returns
base_t pointer to the base

Definition at line 651 of file cp_produce.cpp.

References B_GetNext(), MAX_PRODUCTIONS, and PR_GetProductionForBase.

Referenced by PR_DecreaseProduction(), PR_GetRemainingMinutes(), PR_IncreaseProduction(), and US_RemoveStoredUFO().

◆ PR_ProductionRollBottom()

void PR_ProductionRollBottom ( base_t * base)
static

moves the first production to the bottom of the list

Definition at line 373 of file cp_produce.cpp.

References production_queue_t::numItems, PR_GetProductionForBase, and PR_QueueMove().

Referenced by PR_CheckFrame().

◆ PR_ProductionRun()

void PR_ProductionRun ( void )

Checks whether an item is finished.

Note
One call each game time minute
See also
CP_CampaignRun
PR_DisassemblingFrame
PR_ProductionFrame

Definition at line 556 of file cp_produce.cpp.

References B_GetNext(), production_t::frame, production_queue_t::items, production_queue_t::numItems, PR_CheckFrame(), PR_FinishDisassembly(), PR_FinishProduction(), PR_GetProductionForBase, PR_IsDisassembly, PR_IsProduction, PR_IsReady, PR_ProductionAllowed(), and PR_WorkersAvailable().

Referenced by CP_CampaignRun(), TEST_F(), TEST_F(), and TEST_F().

◆ PR_QueueDelete()

void PR_QueueDelete ( base_t * base,
production_queue_t * queue,
int index )

Delete the selected entry from the queue.

Parameters
[in]basePointer to base, where the queue is.
[in]queuePointer to the queue.
[in]indexSelected index in queue.

Definition at line 281 of file cp_produce.cpp.

References production_t::amount, cgi, production_t::data, ERR_DROP, i, index, production_queue_t::items, production_queue_t::numItems, PR_GetTech(), PR_ResetUFODisassembly(), PR_SetUFODisassembly(), PR_UpdateRequiredItemsInBasestorage(), REMOVE_ELEM_ADJUST_IDX, and technology_t::requireForProduction.

Referenced by PR_DecreaseProduction(), PR_EmptyQueue(), PR_ProductionStop_f(), PR_QueueNext(), and US_RemoveStoredUFO().

◆ PR_QueueMove()

void PR_QueueMove ( production_queue_t * queue,
int index,
int offset )

Moves the given queue item in the given direction.

Parameters
[in]queuePointer to the queue.
[in]indexThe production item index in the queue
[in]offsetThe offset relative to the given index where the item should be moved, too

Definition at line 308 of file cp_produce.cpp.

References i, production_t::idx, index, production_queue_t::items, production_queue_t::numItems, and PR_SetUFODisassembly().

Referenced by PR_ProductionDown_f(), PR_ProductionRollBottom(), and PR_ProductionUp_f().

◆ PR_QueueNew()

production_t * PR_QueueNew ( base_t * base,
const productionData_t * data,
signed int amount )

Add a new item to the bottom of the production queue.

Parameters
[in]basePointer to base, where the queue is.
[in]dataThe production data
[in]amountDesired amount to produce.
Returns
NULL in case the production wasn't enqueued, otherwise the production pointer

Definition at line 234 of file cp_produce.cpp.

References production_t::amount, data, production_t::data, production_t::idx, production_queue_t::items, MAX_PRODUCTIONS, production_queue_t::numItems, OBJZERO, PR_CalculateTotalFrames(), PR_GetProductionForBase, PR_GetTech(), PR_IsDisassemblyData, PR_RequirementsMet(), PR_SetUFODisassembly(), PR_UpdateRequiredItemsInBasestorage(), technology_t::produceTime, technology_t::requireForProduction, and production_t::totalFrames.

Referenced by PR_ProductionIncrease_f(), TEST_F(), TEST_F(), and TEST_F().

◆ PR_QueueNext()

void PR_QueueNext ( base_t * base)

Queues the next production in the queue.

Parameters
[in]basePointer to the base.

Definition at line 345 of file cp_produce.cpp.

References _, Com_sprintf(), cp_messageBuffer, MSG_PRODUCTION, MSO_CheckAddNewMessage(), base_t::name, NT_PRODUCTION_QUEUE_EMPTY, production_queue_t::numItems, PR_GetProductionForBase, and PR_QueueDelete().

Referenced by PR_FinishProduction(), and US_RemoveStoredUFO().

◆ PR_RequirementsMet()

int PR_RequirementsMet ( int amount,
const requirements_t * reqs,
base_t * base )

Checks if the production requirements are met for a defined amount.

Parameters
[in]amountHow many items are planned to be produced.
[in]reqsThe production requirements of the item that is to be produced.
[in]basePointer to base.
Returns
how much item/aircraft/etc can be produced

Definition at line 147 of file cp_produce.cpp.

References requirement_t::amount, B_AntimatterInBase(), B_ItemInBase(), i, requirement_t::link, requirements_t::links, requirements_t::numLinks, requirement_t::typelink_t::od, RS_IsResearched_ptr(), RS_LINK_ANTIMATTER, RS_LINK_ITEM, RS_LINK_TECH, RS_LINK_TECH_NOT, requirement_t::typelink_t::tech, and requirement_t::type.

Referenced by PR_IncreaseProduction(), PR_ProductionIncrease_f(), and PR_QueueNew().

◆ PR_ResetUFODisassembly()

void PR_ResetUFODisassembly ( production_t * prod)
static
Todo
remove this and make the ufo const

Definition at line 213 of file cp_produce.cpp.

References production_t::data, productionData_t::data, PR_IsDisassembly, and productionData_t::productionItem_t::ufo.

Referenced by PR_QueueDelete().

◆ PR_SaveXML()

◆ PR_SetUFODisassembly()

void PR_SetUFODisassembly ( production_t * prod)
static
Todo
remove this and make the ufo const

Definition at line 220 of file cp_produce.cpp.

References production_t::data, productionData_t::data, PR_IsDisassembly, and productionData_t::productionItem_t::ufo.

Referenced by PR_LoadXML(), PR_QueueDelete(), PR_QueueMove(), and PR_QueueNew().

◆ PR_UpdateProductionCap()

void PR_UpdateProductionCap ( base_t * base,
int workerChange )

◆ PR_UpdateRequiredItemsInBasestorage()

void PR_UpdateRequiredItemsInBasestorage ( base_t * base,
int amount,
const requirements_t * reqs )

Remove or add the required items from/to the a base.

Parameters
[in]basePointer to base.
[in]amountHow many items are planned to be added (positive number) or removed (negative number).
[in]reqsThe production requirements of the item that is to be produced. These included numbers are multiplied with 'amount')

Definition at line 111 of file cp_produce.cpp.

References requirement_t::amount, B_AddAntimatter(), B_AddToStorage(), cgi, ERR_DROP, i, requirement_t::link, requirements_t::links, requirements_t::numLinks, requirement_t::typelink_t::od, RS_LINK_ANTIMATTER, RS_LINK_ITEM, RS_LINK_TECH, RS_LINK_TECH_NOT, and requirement_t::type.

Referenced by PR_DecreaseProduction(), PR_IncreaseProduction(), PR_QueueDelete(), and PR_QueueNew().

◆ PR_WorkersAvailable()

int PR_WorkersAvailable ( const base_t * base)

Returns the numer of workers available to produce an item.

Parameters
[in]basePointer to the base the production happen

Definition at line 64 of file cp_produce.cpp.

References CAP_GetMax, CAP_WORKSPACE, E_CountHired(), and EMPL_WORKER.

Referenced by PR_GetProductionHours(), PR_GetRemainingMinutes(), PR_ProductionRun(), TEST_F(), TEST_F(), and TEST_F().