UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_produce.cpp File Reference

Single player production stuff. More...

#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"

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

Detailed Description

Single player production stuff.

Note
Production stuff functions prefix: PR_

Definition in file cp_produce.cpp.

Function Documentation

static 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 39 of file cp_produce.cpp.

References ccs, storedUFO_s::comp, ccs_s::curCampaign, productionData_t::data, GetDistanceOnGlobe(), storedUFO_s::installation, MINUTES_PER_HOUR, installation_s::pos, base_s::pos, PR_GetTech(), PR_IsProductionData, campaign_s::produceRate, technology_s::produceTime, components_s::time, and productionData_t::productionItem_t::ufo.

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

static 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 387 of file cp_produce.cpp.

References _, productionData_t::productionItem_t::aircraft, ccs, Com_sprintf(), cp_messageBuffer, production_s::creditMessage, ccs_s::credits, productionData_t::data, production_s::data, productionData_t::productionItem_t::item, MSO_CheckAddNewMessage(), base_s::name, NT_PRODUCTION_FAILED, PR_GetPrice(), PR_IsAircraft, PR_IsItem, PR_ProductionRollBottom(), aircraft_s::productionCost, and objDef_s::productionCost.

Referenced by PR_ProductionRun().

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 522 of file cp_produce.cpp.

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

Referenced by PR_ProductionDecrease_f().

static void PR_EmptyQueue ( base_t base)
static

clears the production queue on a base

Definition at line 359 of file cp_produce.cpp.

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

Referenced by PR_UpdateProductionCap().

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 666 of file cp_produce.cpp.

References ccs, campaign_s::componentRate, and ccs_s::curCampaign.

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

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 99 of file cp_produce.cpp.

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

Referenced by PR_ProductionInfo().

int PR_GetRemainingHours ( const production_t prod)

Calculates the remaining hours for a technology.

Parameters
[in]prodPointer to the production structure

Definition at line 89 of file cp_produce.cpp.

References MINUTES_PER_HOUR, and PR_GetRemainingMinutes().

Referenced by PR_ProductionInfo(), and TEST_F().

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 78 of file cp_produce.cpp.

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

Referenced by PR_GetRemainingHours(), and TEST_F().

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 489 of file cp_produce.cpp.

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

Referenced by PR_ProductionIncrease_f().

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 639 of file cp_produce.cpp.

References technology_s::produceTime, and RS_GetTechForItem().

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

bool PR_PostLoadInit ( void  )

actions to do with productions after loading a savegame

See also
SAV_GameActionsAfterLoad

Definition at line 802 of file cp_produce.cpp.

References PR_PostLoadInitProgress().

Referenced by SAV_GameActionsAfterLoad().

static 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 784 of file cp_produce.cpp.

References B_GetNext(), production_s::data, production_queue_s::items, production_queue_s::numItems, PR_CalculateTotalFrames(), PR_GetProductionForBase, and production_s::totalFrames.

Referenced by PR_PostLoadInit().

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 595 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(), and TR_TransferStart().

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 650 of file cp_produce.cpp.

References B_GetNext(), MAX_PRODUCTIONS, and PR_GetProductionForBase.

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

static void PR_ProductionRollBottom ( base_t base)
static

moves the first production to the bottom of the list

Definition at line 372 of file cp_produce.cpp.

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

Referenced by PR_CheckFrame().

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 555 of file cp_produce.cpp.

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

Referenced by CP_CampaignRun(), and TEST_F().

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 280 of file cp_produce.cpp.

References production_s::amount, cgi, production_s::data, ERR_DROP, i, index, production_queue_s::items, production_queue_s::numItems, PR_GetTech(), PR_ResetUFODisassembly(), PR_SetUFODisassembly(), PR_UpdateRequiredItemsInBasestorage(), REMOVE_ELEM_ADJUST_IDX, and technology_s::requireForProduction.

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

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 307 of file cp_produce.cpp.

References i, production_s::idx, index, production_queue_s::items, production_queue_s::numItems, and PR_SetUFODisassembly().

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

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 233 of file cp_produce.cpp.

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

Referenced by PR_ProductionIncrease_f(), and TEST_F().

void PR_QueueNext ( base_t base)

Queues the next production in the queue.

Parameters
[in]basePointer to the base.

Definition at line 344 of file cp_produce.cpp.

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

Referenced by PR_FinishProduction(), and US_RemoveStoredUFO().

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 146 of file cp_produce.cpp.

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

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

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

Definition at line 212 of file cp_produce.cpp.

References productionData_t::data, production_s::data, storedUFO_s::disassembly, PR_IsDisassembly, and productionData_t::productionItem_t::ufo.

Referenced by PR_QueueDelete().

static void PR_SetUFODisassembly ( production_t prod)
static
void PR_UpdateProductionCap ( base_t base,
int  workerChange 
)
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 110 of file cp_produce.cpp.

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

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

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 63 of file cp_produce.cpp.

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

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