cp_produce.c File Reference

Single player production stuff. More...

#include "../cl_shared.h"
#include "../ui/ui_popup.h"
#include "cp_campaign.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.c:

Go to the source code of this file.

Functions

float PR_CalculateProductionPercentDone (const base_t *base, const technology_t *tech, const storedUFO_t *const storedUFO)
 Calculates the fraction (percentage) of production of an item in 1 hour.
void PR_UpdateRequiredItemsInBasestorage (base_t *base, int amount, const requirements_t const *reqs)
 Remove or add the required items from/to the a base.
int PR_RequirementsMet (int amount, const requirements_t const *reqs, base_t *base)
 Checks if the production requirements are met for a defined amount.
int PR_QueueFreeSpace (const production_queue_t const *queue)
 returns the number of free production slots of a queue
production_tPR_QueueNew (base_t *base, production_queue_t *queue, objDef_t *item, aircraft_t *aircraftTemplate, storedUFO_t *ufo, 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 dir)
 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_f (void)
 moves the first production to the bottom of the list
static int PR_DisassembleItem (base_t *base, components_t *comp, float condition, qboolean calculate)
 Disassembles item, adds components to base storage and calculates all components size.
static void PR_ProductionFrame (base_t *base, production_t *prod)
 Runs the production of an item or an aircraft.
static void PR_DisassemblingFrame (base_t *base, production_t *prod)
 Runs the 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.
qboolean PR_ProductionAllowed (const base_t *base)
 Returns true if the current base is able to produce items.
void PR_ProductionInit (void)
void PR_UpdateProductionCap (base_t *base)
 Update the current capacity of Workshop.
qboolean PR_ItemIsProduceable (const objDef_t const *item)
 check if an item is producable.
base_tPR_ProductionBase (production_t *production)
 Returns the base pointer the production belongs to.
base_tPR_ProductionQueueBase (const production_queue_t const *queue)
 Returns the base pointer the production queue belongs to.
qboolean PR_SaveXML (mxml_node_t *p)
 Save callback for savegames in XML Format.
qboolean PR_LoadXML (mxml_node_t *p)
 Load callback for xml savegames.

Variables

const int PRODUCE_FACTOR = 1
 Used in production costs (to allow reducing prices below 1x).
const int PRODUCE_DIVISOR = 1
static const int PRODUCE_WORKERS = 10
 Default amount of workers, the produceTime for technologies is defined.
static cvar_tmn_production_limit
static cvar_tmn_production_workers
static cvar_tmn_production_amount

Detailed Description

Single player production stuff.

Note:
Production stuff functions prefix: PR_

Definition in file cp_produce.c.


Function Documentation

float PR_CalculateProductionPercentDone ( const base_t base,
const technology_t tech,
const storedUFO_t *const   storedUFO 
)

Calculates the fraction (percentage) of production of an item in 1 hour.

Parameters:
[in] base Pointer to the base with given production.
[in] tech Pointer to the technology for given production.
[in] storedUFO Pointer to disassembled UFO.
See also:
PR_ProductionRun
PR_ItemProductionInfo
PR_DisassemblyInfo
Returns:
0 if the production does not make any progress, 1 if the whole item is built in 1 hour

Definition at line 57 of file cp_produce.c.

References CAP_WORKSPACE, base_s::capacities, Com_DPrintf(), storedUFO_s::comp, DEBUG_CLIENT, E_CountHired(), EMPL_WORKER, f, GetDistanceOnGlobe(), technology_s::id, storedUFO_s::installation, cap_maxcur_s::max, base_s::pos, installation_s::pos, PRODUCE_WORKERS, technology_s::produceTime, and components_s::time.

Referenced by PR_AircraftInfo(), PR_DisassemblingFrame(), PR_DisassemblyInfo(), PR_ItemProductionInfo(), and PR_ProductionFrame().

int PR_DecreaseProduction ( production_t prod,
int  amount 
)

decreases production amount

Parameters:
[in,out] prod Pointer to the production
[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

Definition at line 650 of file cp_produce.c.

References production_s::aircraft, production_s::amount, ccs, production_s::idx, base_s::idx, production_s::item, PR_ProductionBase(), PR_QueueDelete(), PR_UpdateRequiredItemsInBasestorage(), ccs_s::productions, technology_s::requireForProduction, RS_GetTechForItem(), aircraft_s::tech, production_s::ufo, and storedUFO_s::ufoTemplate.

Referenced by PR_ProductionDecrease_f().

static int PR_DisassembleItem ( base_t base,
components_t comp,
float  condition,
qboolean  calculate 
) [static]

Disassembles item, adds components to base storage and calculates all components size.

Parameters:
[in] base Pointer to base where the disassembling is being made.
[in] comp Pointer to components definition.
[in] condition condition of the item/UFO being disassembled, objects gathered from disassembly decreased to that factor
[in] calculate True if this is only calculation of item size, false if this is real disassembling.
Returns:
Size of all components in this disassembling.

Definition at line 430 of file cp_produce.c.

References ANTIMATTER_TECH_ID, B_ManageAntimatter(), B_UpdateStorageAndCapacity(), Com_DPrintf(), Com_Error(), COMP_ITEMCOUNT_SCALED, DEBUG_CLIENT, ERR_DROP, i, objDef_s::id, components_s::itemAmount, components_s::itemAmount2, components_s::items, components_s::numItemtypes, qfalse, qtrue, RS_GetTechForItem(), RS_MarkCollected(), and objDef_s::size.

Referenced by PR_DisassemblingFrame().

static void PR_DisassemblingFrame ( base_t base,
production_t prod 
) [static]
static void PR_EmptyQueue ( base_t base  )  [static]

clears the production queue on a base

Definition at line 388 of file cp_produce.c.

References ccs, base_s::idx, production_queue_s::numItems, PR_QueueDelete(), and ccs_s::productions.

Referenced by PR_UpdateProductionCap().

int PR_IncreaseProduction ( production_t prod,
int  amount 
)

increases production amount if possible

Parameters:
[in,out] prod Pointer to the production
[in] amount Additional amount to add
Returns:
the amount added

Definition at line 609 of file cp_produce.c.

References production_s::aircraft, production_s::amount, production_s::item, MAX_PRODUCTION_AMOUNT, PR_ProductionBase(), PR_RequirementsMet(), PR_UpdateRequiredItemsInBasestorage(), technology_s::requireForProduction, RS_GetTechForItem(), aircraft_s::tech, and production_s::ufo.

Referenced by PR_ProductionIncrease_f().

qboolean PR_ItemIsProduceable ( const objDef_t const *  item  ) 

check if an item is producable.

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

Definition at line 768 of file cp_produce.c.

References technology_s::produceTime, and RS_GetTechForItem().

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

qboolean PR_LoadXML ( mxml_node_t p  ) 
qboolean PR_ProductionAllowed ( const base_t base  ) 

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

Parameters:
[in] base Pointer to the base.
See also:
B_BaseInit_f

Definition at line 726 of file cp_produce.c.

References B_GetBuildingStatus(), B_WORKSHOP, BASE_UNDER_ATTACK, base_s::baseStatus, E_CountHired(), EMPL_WORKER, qfalse, and qtrue.

Referenced by B_BaseInit_f(), B_BuildingOpenAfterClick(), PR_ProductionRun(), and TR_TransferStart().

base_t* PR_ProductionBase ( production_t production  ) 

Returns the base pointer the production belongs to.

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

Definition at line 779 of file cp_produce.c.

References B_GetBaseByIDX(), ccs, i, production_queue_s::items, MAX_PRODUCTIONS, ccs_s::numBases, and ccs_s::productions.

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

static void PR_ProductionFrame ( base_t base,
production_t prod 
) [static]
void PR_ProductionInit ( void   ) 

Definition at line 738 of file cp_produce.c.

References Cvar_Get().

Referenced by CP_CampaignInit().

base_t* PR_ProductionQueueBase ( const production_queue_t const *  queue  ) 

Returns the base pointer the production queue belongs to.

Parameters:
[in] queue pointer to the production queue
Returns:
base_t pointer to the base

Definition at line 797 of file cp_produce.c.

References B_GetFoundedBaseByIDX(), ccs, and ccs_s::productions.

Referenced by PR_QueueDelete(), and PR_QueueFreeSpace().

static void PR_ProductionRollBottom_f ( void   )  [static]

moves the first production to the bottom of the list

Definition at line 406 of file cp_produce.c.

References B_GetCurrentSelectedBase(), ccs, base_s::idx, production_queue_s::numItems, PR_QueueMove(), and ccs_s::productions.

Referenced by PR_DisassemblingFrame(), and PR_ProductionFrame().

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

returns the number of free production slots of a queue

Parameters:
[in] queue Pointer to the queue to check

Definition at line 186 of file cp_produce.c.

References B_GetNumberOfBuildingsInBaseByBuildingType(), B_WORKSHOP, MAX_PRODUCTIONS, MAX_PRODUCTIONS_PER_WORKSHOP, production_queue_s::numItems, and PR_ProductionQueueBase().

Referenced by PR_ProductionIncrease_f(), and PR_QueueNew().

void PR_QueueMove ( production_queue_t queue,
int  index,
int  dir 
)

Moves the given queue item in the given direction.

Parameters:
[in] queue Pointer to the queue.
[in] index 
[in] dir 

Definition at line 335 of file cp_produce.c.

References storedUFO_s::disassembly, i, production_s::idx, production_queue_s::items, production_queue_s::numItems, and production_s::ufo.

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

production_t* PR_QueueNew ( base_t base,
production_queue_t queue,
objDef_t item,
aircraft_t aircraftTemplate,
storedUFO_t ufo,
signed int  amount 
)

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

Parameters:
[in] base Pointer to base, where the queue is.
[in] queue Pointer to the queue.
[in] item Item to add.
[in] aircraftTemplate aircraft to add.
[in] ufo The UFO in case of a disassemly.
[in] amount Desired amount to produce.

Todo:
move this check out into a new function
Todo:
move popup into menucode
Todo:
move popup into menucode
Todo:
we should also count aircraft that are already in the queue list

Definition at line 208 of file cp_produce.c.

References _, AIR_CalculateHangarStorage(), production_s::aircraft, production_s::amount, B_COMMAND, B_GetBuildingStatus(), B_HANGAR, B_SMALL_HANGAR, storedUFO_s::disassembly, E_CountHired(), EMPL_WORKER, production_s::idx, production_s::item, production_queue_s::items, production_queue_s::numItems, requirements_s::numLinks, production_s::percentDone, PR_QueueFreeSpace(), PR_RequirementsMet(), PR_UpdateRequiredItemsInBasestorage(), technology_s::produceTime, production_s::production, qfalse, qtrue, technology_s::requireForProduction, RS_GetTechForItem(), aircraft_s::tech, production_s::ufo, storedUFO_s::ufoTemplate, and UI_Popup().

Referenced by PR_ProductionIncrease_f().

void PR_QueueNext ( base_t base  ) 

Queues the next production in the queue.

Parameters:
[in] base Pointer to the base.

Definition at line 373 of file cp_produce.c.

References _, ccs, Com_sprintf(), cp_messageBuffer, base_s::idx, MSG_PRODUCTION, MSO_CheckAddNewMessage(), base_s::name, NT_PRODUCTION_QUEUE_EMPTY, production_queue_s::numItems, PR_QueueDelete(), ccs_s::productions, and qfalse.

Referenced by PR_ProductionFrame(), and US_RemoveStoredUFO().

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

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

Parameters:
[in] amount How many items are planned to be produced.
[in] reqs The production requirements of the item that is to be produced.
[in] base Pointer to base.
Returns:
how much item/aircraft/etc can be produced

Definition at line 149 of file cp_produce.c.

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

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

qboolean PR_SaveXML ( mxml_node_t p  ) 
void PR_UpdateProductionCap ( base_t base  ) 

Update the current capacity of Workshop.

Parameters:
[in] base Pointer to the base containing workshop.

Definition at line 749 of file cp_produce.c.

References CAP_WORKSPACE, base_s::capacities, cap_maxcur_s::cur, E_CountHired(), EMPL_WORKER, cap_maxcur_s::max, and PR_EmptyQueue().

Referenced by B_BuildBase_f(), B_BuildingOnDestroy_f(), B_ResetAllStatusAndCapacities(), E_HireEmployee(), E_RemoveEmployeeFromBuildingOrAircraft(), and PR_ProductionList_f().

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

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

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

Definition at line 108 of file cp_produce.c.

References requirement_s::amount, B_AddToStorage(), B_ManageAntimatter(), Com_Error(), ERR_DROP, i, requirement_s::link, requirements_s::links, requirements_s::numLinks, qfalse, qtrue, 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().


Variable Documentation

Amount of the current production; if no production, an invalid value

Definition at line 45 of file cp_produce.c.

Maximum items in queue.

Definition at line 43 of file cp_produce.c.

Amount of hired workers in base.

Definition at line 44 of file cp_produce.c.

const int PRODUCE_DIVISOR = 1

Definition at line 37 of file cp_produce.c.

Referenced by PR_AircraftInfo(), PR_ItemProductionInfo(), and PR_ProductionFrame().

const int PRODUCE_FACTOR = 1

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

Definition at line 36 of file cp_produce.c.

Referenced by PR_AircraftInfo(), PR_ItemProductionInfo(), and PR_ProductionFrame().

const int PRODUCE_WORKERS = 10 [static]

Default amount of workers, the produceTime for technologies is defined.

Note:
producetime for technology entries is the time for PRODUCE_WORKERS amount of workers.

Definition at line 41 of file cp_produce.c.

Referenced by PR_CalculateProductionPercentDone().


Generated by  doxygen 1.6.2