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

Header for production related stuff. More...

Go to the source code of this file.

Data Structures

struct  productionData_t
 
union  productionData_t::productionItem_t
 
struct  production_s
 Holds all information for the production of one item-type. More...
 
struct  production_queue_s
 A production queue. Lists all items to be produced. More...
 

Macros

#define MAX_PRODUCTIONS   40
 Maximum number of productions queued in any one base. More...
 
#define MAX_PRODUCTION_AMOUNT   500
 
#define UGV_SIZE   300
 
#define PR_IsDisassemblyData(data)   ((data)->type == PRODUCTION_TYPE_DISASSEMBLY)
 
#define PR_IsAircraftData(data)   ((data)->type == PRODUCTION_TYPE_AIRCRAFT)
 
#define PR_IsItemData(data)   ((data)->type == PRODUCTION_TYPE_ITEM)
 
#define PR_IsProductionData(data)   (!PR_IsDisassemblyData(data))
 
#define PR_IsDisassembly(prod)   (PR_IsDisassemblyData(&(prod)->data))
 
#define PR_IsAircraft(prod)   (PR_IsAircraftData(&(prod)->data))
 
#define PR_IsItem(prod)   (PR_IsItemData(&(prod)->data))
 
#define PR_IsProduction(prod)   (!PR_IsDisassembly(prod))
 
#define PR_SetData(dataPtr, typeVal, ptr)   do { assert(ptr); (dataPtr)->data.pointer = (ptr); (dataPtr)->type = (typeVal); } while (0);
 
#define PR_IsDataValid(dataPtr)   ((dataPtr)->data.pointer != nullptr)
 
#define PR_GetProgress(prod)   ((double)(prod)->frame / (prod)->totalFrames)
 
#define PR_IsReady(prod)   ((prod)->frame > (prod)->totalFrames)
 
#define PR_GetProductionForBase(base)   (&((base)->productions))
 

Typedefs

typedef struct production_s production_t
 Holds all information for the production of one item-type. More...
 
typedef struct production_queue_s production_queue_t
 A production queue. Lists all items to be produced. More...
 

Enumerations

enum  productionType_t { PRODUCTION_TYPE_ITEM, PRODUCTION_TYPE_AIRCRAFT, PRODUCTION_TYPE_DISASSEMBLY, PRODUCTION_TYPE_MAX }
 

Functions

int PR_GetPrice (const int productionCost)
 Used in production costs (to allow reducing prices below 1x). More...
 
void PR_ProductionInit (void)
 
void PR_ProductionRun (void)
 Checks whether an item is finished. More...
 
bool PR_ItemIsProduceable (const objDef_t *item)
 check if an item is producable. More...
 
struct base_sPR_ProductionBase (const production_t *production)
 Returns the base pointer the production belongs to. 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...
 
const char * PR_GetName (const productionData_t *data)
 
technology_tPR_GetTech (const productionData_t *data)
 
void PR_UpdateProductionCap (struct base_s *base, int workerChange=0)
 Update the current capacity of Workshop. More...
 
void PR_UpdateRequiredItemsInBasestorage (struct base_s *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, struct base_s *base)
 Checks if the production requirements are met for a defined amount. More...
 
int PR_WorkersAvailable (const struct base_s *base)
 
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 struct base_s *base, const productionData_t *prodData)
 
production_tPR_QueueNew (struct base_s *base, const productionData_t *data, signed int amount)
 Add a new item to the bottom of the production queue. More...
 
void PR_QueueMove (production_queue_t *queue, int index, int dir)
 Moves the given queue item in the given direction. More...
 
void PR_QueueDelete (struct base_s *base, production_queue_t *queue, int index)
 Delete the selected entry from the queue. More...
 
void PR_QueueNext (struct base_s *base)
 Queues the next production in the queue. More...
 

Detailed Description

Header for production related stuff.

Definition in file cp_produce.h.

Macro Definition Documentation

#define MAX_PRODUCTION_AMOUNT   500

Maximum number of produced items.

Definition at line 30 of file cp_produce.h.

Referenced by PR_IncreaseProduction(), and PR_ProductionIncrease_f().

#define MAX_PRODUCTIONS   40

Maximum number of productions queued in any one base.

Definition at line 28 of file cp_produce.h.

Referenced by PR_LoadXML(), PR_ProductionBase(), and PR_QueueNew().

#define PR_GetProgress (   prod)    ((double)(prod)->frame / (prod)->totalFrames)

Definition at line 83 of file cp_produce.h.

Referenced by PR_ShowActiveProduction_f().

#define PR_IsAircraft (   prod)    (PR_IsAircraftData(&(prod)->data))
#define PR_IsAircraftData (   data)    ((data)->type == PRODUCTION_TYPE_AIRCRAFT)

Definition at line 71 of file cp_produce.h.

Referenced by PR_ProductionIncrease_f(), and PR_ProductionInfo().

#define PR_IsDataValid (   dataPtr)    ((dataPtr)->data.pointer != nullptr)
#define PR_IsDisassemblyData (   data)    ((data)->type == PRODUCTION_TYPE_DISASSEMBLY)

Definition at line 70 of file cp_produce.h.

Referenced by PR_ProductionInfo(), and PR_QueueNew().

#define PR_IsItem (   prod)    (PR_IsItemData(&(prod)->data))
#define PR_IsItemData (   data)    ((data)->type == PRODUCTION_TYPE_ITEM)

Definition at line 72 of file cp_produce.h.

Referenced by PR_ProductionInfo().

#define PR_IsProduction (   prod)    (!PR_IsDisassembly(prod))

Definition at line 78 of file cp_produce.h.

Referenced by PR_ProductionRun().

#define PR_IsProductionData (   data)    (!PR_IsDisassemblyData(data))

Definition at line 73 of file cp_produce.h.

Referenced by PR_CalculateTotalFrames().

#define PR_IsReady (   prod)    ((prod)->frame > (prod)->totalFrames)

Definition at line 84 of file cp_produce.h.

Referenced by PR_ProductionRun().

#define PR_SetData (   dataPtr,
  typeVal,
  ptr 
)    do { assert(ptr); (dataPtr)->data.pointer = (ptr); (dataPtr)->type = (typeVal); } while (0);
#define UGV_SIZE   300

Size of a UGV in hangar capacity

Definition at line 33 of file cp_produce.h.

Referenced by BS_Buy_f(), BS_BuyUGV(), CAP_UpdateStorageCap(), E_HireEmployee(), E_MoveIntoNewBase(), and Employee::unhire().

Typedef Documentation

A production queue. Lists all items to be produced.

See also
production_t
typedef struct production_s production_t

Holds all information for the production of one item-type.

Enumeration Type Documentation

Enumerator
PRODUCTION_TYPE_ITEM 
PRODUCTION_TYPE_AIRCRAFT 
PRODUCTION_TYPE_DISASSEMBLY 
PRODUCTION_TYPE_MAX 

Definition at line 35 of file cp_produce.h.

Function Documentation

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().

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 struct base_s base,
const productionData_t prodData 
)
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().

struct base_s* 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().

void PR_ProductionInit ( void  )
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().

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 struct base_s base)