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

Header for base building related stuff. More...

Go to the source code of this file.

Data Structures

struct  building_s
 A building with all it's data. More...
 

Typedefs

typedef struct building_s building_t
 A building with all it's data. More...
 

Enumerations

enum  buildingStatus_t {
  B_STATUS_NOT_SET, B_STATUS_UNDER_CONSTRUCTION, B_STATUS_CONSTRUCTION_FINISHED, B_STATUS_WORKING,
  B_STATUS_DOWN
}
 All possible building status. More...
 
enum  buildingEvent_t {
  B_ONCONSTRUCT, B_ONENABLE, B_ONDISABLE, B_ONDESTROY,
  B_MAXEVENT
}
 Building events. More...
 
enum  buildingType_t {
  B_MISC, B_LAB, B_QUARTERS, B_STORAGE,
  B_WORKSHOP, B_HOSPITAL, B_HANGAR, B_ALIEN_CONTAINMENT,
  B_SMALL_HANGAR, B_POWER, B_COMMAND, B_ANTIMATTER,
  B_ENTRANCE, B_DEFENCE_MISSILE, B_DEFENCE_LASER, B_RADAR,
  MAX_BUILDING_TYPE
}
 All different building types. More...
 

Functions

void B_ParseBuildings (const char *name, const char **text, bool link)
 Copies an entry from the building description file into the list of building types. More...
 
bool B_BuildingScriptSanityCheck (void)
 Checks the parsed buildings for errors. More...
 
building_tB_GetBuildingTemplate (const char *buildingName)
 Returns the building in the global building-types list that has the unique name buildingID. More...
 
building_tB_GetBuildingTemplateSilent (const char *buildingName)
 Returns the building in the global building-types list that has the unique name buildingID. More...
 
const building_tB_GetBuildingTemplateByType (buildingType_t type)
 Returns the building template in the global building-types list for a buildingType. More...
 
buildingType_t B_GetBuildingTypeByBuildingID (const char *buildingID)
 Returns the building type for a given building identified by its building id from the ufo script files. More...
 
bool B_CheckBuildingDependencesStatus (const building_t *building)
 Check that the dependences of a building is operationnal. More...
 
bool B_IsBuildingBuiltUp (const building_t *building)
 Returns if a building is fully buildt up. More...
 
float B_GetConstructionTimeRemain (const building_t *building)
 Returns the time remaining time of a building construction. More...
 
bool B_FireEvent (const building_t *buildingTemplate, const struct base_s *base, buildingEvent_t eventType)
 

Detailed Description

Header for base building related stuff.

Definition in file cp_building.h.

Typedef Documentation

typedef struct building_s building_t

A building with all it's data.

Enumeration Type Documentation

Building events.

Enumerator
B_ONCONSTRUCT 

building was placed on the base map

B_ONENABLE 

building get operational (built up and all dependencies met)

B_ONDISABLE 

building got disabled (ex: a dependency was destroyed)

B_ONDESTROY 

building was destroyed

B_MAXEVENT 

Definition at line 41 of file cp_building.h.

All possible building status.

Enumerator
B_STATUS_NOT_SET 

not build yet

B_STATUS_UNDER_CONSTRUCTION 

right now under construction

B_STATUS_CONSTRUCTION_FINISHED 

construction finished - no workers assigned

B_STATUS_WORKING 

working normal (or workers assigned when needed)

B_STATUS_DOWN 

totally damaged

Definition at line 31 of file cp_building.h.

All different building types.

Note
if you change the order, you'll load values of hasBuilding in wrong indice
Enumerator
B_MISC 

this building is nothing with a special function (used when a building appears twice in .ufo file)

B_LAB 

this building is a lab

B_QUARTERS 

this building is a quarter

B_STORAGE 

this building is a storage

B_WORKSHOP 

this building is a workshop

B_HOSPITAL 

this building is a hospital

B_HANGAR 

this building is a hangar

B_ALIEN_CONTAINMENT 

this building is an alien containment

B_SMALL_HANGAR 

this building is a small hangar

B_POWER 

this building is power plant

B_COMMAND 

this building is command centre

B_ANTIMATTER 

this building is antimatter storage

B_ENTRANCE 

this building is an entrance

B_DEFENCE_MISSILE 

this building is a missile rack

B_DEFENCE_LASER 

this building is a laser battery

B_RADAR 

this building is a radar

MAX_BUILDING_TYPE 

Definition at line 51 of file cp_building.h.

Function Documentation

bool B_BuildingScriptSanityCheck ( void  )

Checks the parsed buildings for errors.

Returns
false if there are errors - true otherwise

Definition at line 244 of file cp_building.cpp.

References ccs_s::buildingTemplates, ccs, cgi, i, building_s::id, building_s::image, building_s::name, ccs_s::numBuildingTemplates, building_s::pedia, and RS_GetTechByID().

bool B_CheckBuildingDependencesStatus ( const building_t building)

Check that the dependences of a building is operationnal.

Parameters
[in]buildingPointer to the building to check
Returns
true if base contains needed dependence for entering building

Definition at line 326 of file cp_building.cpp.

References B_GetBuildingStatus(), building_s::base, building_s::buildingType, building_s::dependsBuilding, and building_s::tpl.

Referenced by B_CheckUpdateBuilding().

bool B_FireEvent ( const building_t buildingTemplate,
const struct base_s base,
buildingEvent_t  eventType 
)
building_t* B_GetBuildingTemplate ( const char *  buildingName)

Returns the building in the global building-types list that has the unique name buildingID.

Parameters
[in]buildingNameThe unique id of the building (building_t->id).
Returns
Building template pointer if found, nullptr otherwise
Todo:
make the returned pointer const

Definition at line 294 of file cp_building.cpp.

References B_GetBuildingTemplateSilent(), and cgi.

Referenced by B_LoadXML(), B_ParseBuildings(), TEST_F(), and UP_BuildingDescription().

const building_t* B_GetBuildingTemplateByType ( buildingType_t  type)

Returns the building template in the global building-types list for a buildingType.

Parameters
[in]typeBuilding type.

Definition at line 311 of file cp_building.cpp.

References ccs_s::buildingTemplates, building_s::buildingType, ccs, i, and ccs_s::numBuildingTemplates.

Referenced by CAP_CheckOverflow(), and UP_AircraftDescription().

building_t* B_GetBuildingTemplateSilent ( const char *  buildingName)

Returns the building in the global building-types list that has the unique name buildingID.

Parameters
[in]buildingNameThe unique id of the building (building_t->id).
Returns
Building template pointer if found, nullptr otherwise
Todo:
make the returned pointer const

Definition at line 276 of file cp_building.cpp.

References ccs_s::buildingTemplates, ccs, i, building_s::id, ccs_s::numBuildingTemplates, and Q_streq.

Referenced by AIR_CanIntercept(), AIR_GetHangarCapacityType(), B_BuildBuilding_f(), B_FillBuildingInfo_f(), and B_GetBuildingTemplate().

buildingType_t B_GetBuildingTypeByBuildingID ( const char *  buildingID)

Returns the building type for a given building identified by its building id from the ufo script files.

See also
B_ParseBuildings
Parameters
[in]buildingIDThe script building id that should get converted into the enum value

Definition at line 86 of file cp_building.cpp.

References buildingTypeMapping, MAX_BUILDING_TYPE, Q_streq, and v.

Referenced by B_ParseBuildings().

float B_GetConstructionTimeRemain ( const building_t building)

Returns the time remaining time of a building construction.

Parameters
[in]buildingPointer to the building to check

Definition at line 51 of file cp_building.cpp.

References building_s::buildTime, ccs, ccs_s::date, Date_Substract(), date_s::day, date_s::sec, SECONDS_PER_DAY, and building_s::timeStart.

Referenced by B_FillMap_f().

bool B_IsBuildingBuiltUp ( const building_t building)

Returns if a building is fully buildt up.

Parameters
[in]buildingPointer to the building to check
Note
it always return true for buildings with {0, 0} timeStart

Definition at line 36 of file cp_building.cpp.

References building_s::buildTime, Date_IsDue(), date_s::day, date_s::sec, and building_s::timeStart.

Referenced by B_AssembleMap(), B_BuildBuilding(), B_CheckBuildingConstruction(), B_FillMap_f(), and B_GetNeighbours().

void B_ParseBuildings ( const char *  name,
const char **  text,
bool  link 
)

Copies an entry from the building description file into the list of building types.

Note
Parses one "building" entry in the basemanagement.ufo file and writes it into the next free entry in bmBuildings[0], which is the list of buildings in the first base (building_t).
Parameters
[in]nameUnique script id of a building. This is parsed from "building xxx" -> id=xxx.
[in]textthe whole following text that is part of the "building" item definition in .ufo.
[in]linkBool value that decides whether to link the tech pointer in or not
See also
CL_ParseScriptFirst (link is false here)
CL_ParseScriptSecond (link it true here)

Definition at line 135 of file cp_building.cpp.

References B_GetBuildingTemplate(), B_GetBuildingTypeByBuildingID(), building_s::base, BASE_SIZE, ccs_s::buildingTemplates, building_s::buildingType, ccs, cgi, cgame_import_s::Com_EParse(), Com_Parse(), cp_campaignPool, DEBUG_CLIENT, building_s::dependsBuilding, ERR_DROP, i, building_s::id, building_s::idx, MAX_BUILDING_TYPE, MAX_BUILDINGS, building_s::maxCount, ccs_s::numBuildingTemplates, OBJZERO, cgame_import_s::PoolStrDup(), Q_streq, RS_GetTechByProvided(), building_s::size, building_s::tech, and building_s::tpl.

Referenced by CP_ParseScriptFirst(), and CP_ParseScriptSecond().