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

Base building related stuff. More...

#include "../../DateTime.h"
#include "cp_building.h"
#include "../../cl_shared.h"
#include "../../../shared/parse.h"
#include "cp_campaign.h"
#include "cp_time.h"
Include dependency graph for cp_building.cpp:

Go to the source code of this file.

Data Structures

struct  buildingTypeMapping_s

Functions

bool B_IsBuildingBuiltUp (const building_t *building)
 Returns if a building is fully buildt up.
float B_GetConstructionTimeRemain (const building_t *building)
 Returns the time remaining time of a building construction.
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.
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.
bool B_BuildingScriptSanityCheck (void)
 Checks the parsed buildings for errors.
building_tB_GetBuildingTemplateSilent (const char *buildingName)
 Returns the building in the global building-types list that has the unique name buildingID.
building_tB_GetBuildingTemplate (const char *buildingName)
 Returns the building in the global building-types list that has the unique name buildingID.
const building_tB_GetBuildingTemplateByType (buildingType_t type)
 Returns the building template in the global building-types list for a buildingType.
bool B_CheckBuildingDependencesStatus (const building_t *building)
 Check that the dependences of a building is operationnal.
bool B_FireEvent (const building_t *buildingTemplate, const base_t *base, buildingEvent_t eventType)
 Run eventhandler script for a building.

Variables

static const struct buildingTypeMapping_s buildingTypeMapping []
static const value_t valid_building_vars []
 Holds the names of valid entries in the basemanagement.ufo file.

Detailed Description

Base building related stuff.

Definition in file cp_building.cpp.

Function Documentation

◆ B_BuildingScriptSanityCheck()

bool B_BuildingScriptSanityCheck ( void )

Checks the parsed buildings for errors.

Returns
false if there are errors - true otherwise

Definition at line 242 of file cp_building.cpp.

References ccs, cgi, i, building_t::id, building_t::image, building_t::name, building_t::pedia, and RS_GetTechByID().

◆ B_CheckBuildingDependencesStatus()

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 324 of file cp_building.cpp.

References B_GetBuildingStatus(), building_t::base, and building_t::dependsBuilding.

Referenced by B_CheckUpdateBuilding().

◆ B_FireEvent()

bool B_FireEvent ( const building_t * buildingTemplate,
const base_t * base,
buildingEvent_t eventType )

Run eventhandler script for a building.

Parameters
[in]buildingTemplateBuilding type (template) to run event for
[in]baseThe base to run it at
[in]eventTypeType of the event to run
Returns
true if an event was fired false otherwise (the building may not have one)

Definition at line 344 of file cp_building.cpp.

References B_ONCONSTRUCT, B_ONDESTROY, B_ONDISABLE, B_ONENABLE, building_t::buildingType, cgi, ERR_DROP, base_t::idx, building_t::onConstruct, building_t::onDestroy, building_t::onDisable, building_t::onEnable, and Q_strvalid.

Referenced by B_AddBuildingToBasePos(), B_BuildBuilding(), B_BuildingDestroy(), B_CheckBuildingConstruction(), B_ResetAllStatusAndCapacities(), B_UpdateAllBaseBuildingStatus(), and B_UpdateStatusBuilding().

◆ B_GetBuildingTemplate()

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 292 of file cp_building.cpp.

References B_GetBuildingTemplateSilent(), and cgi.

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

◆ B_GetBuildingTemplateByType()

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 309 of file cp_building.cpp.

References building_t::buildingType, ccs, i, and type.

Referenced by CAP_CheckOverflow(), and UP_AircraftDescription().

◆ B_GetBuildingTemplateSilent()

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 274 of file cp_building.cpp.

References ccs, i, building_t::id, and Q_streq.

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

◆ B_GetBuildingTypeByBuildingID()

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 84 of file cp_building.cpp.

References buildingTypeMapping, MAX_BUILDING_TYPE, Q_streq, and v.

Referenced by B_ParseBuildings().

◆ B_GetConstructionTimeRemain()

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 50 of file cp_building.cpp.

References building_t::buildTime, ccs, DateTime::getDateAsDays(), DateTime::getTimeAsSeconds(), DateTime::SECONDS_PER_DAY, and building_t::timeStart.

Referenced by B_FillMap_f().

◆ B_IsBuildingBuiltUp()

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 37 of file cp_building.cpp.

References building_t::buildTime, ccs, and building_t::timeStart.

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

◆ B_ParseBuildings()

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 133 of file cp_building.cpp.

References B_GetBuildingTemplate(), B_GetBuildingTypeByBuildingID(), building_t::base, BASE_SIZE, building_t::buildingType, ccs, cgi, Com_Parse(), cp_campaignPool, DEBUG_CLIENT, building_t::dependsBuilding, ERR_DROP, i, building_t::id, building_t::idx, MAX_BUILDING_TYPE, MAX_BUILDINGS, building_t::maxCount, name, OBJZERO, Q_streq, RS_GetTechByProvided(), building_t::size, building_t::tech, building_t::tpl, and valid_building_vars.

Referenced by CP_ParseScriptFirst(), and CP_ParseScriptSecond().

Variable Documentation

◆ buildingTypeMapping

const struct buildingTypeMapping_s buildingTypeMapping[]
static
Initial value:
= {
{ "lab", B_LAB },
{ "hospital", B_HOSPITAL },
{ "aliencont", B_ALIEN_CONTAINMENT },
{ "workshop",B_WORKSHOP },
{ "storage", B_STORAGE },
{ "hangar", B_HANGAR },
{ "smallhangar",B_SMALL_HANGAR },
{ "quarters", B_QUARTERS },
{ "power", B_POWER },
{ "command", B_COMMAND },
{ "amstorage", B_ANTIMATTER },
{ "entrance", B_ENTRANCE },
{ "missile", B_DEFENCE_MISSILE },
{ "laser", B_DEFENCE_LASER },
{ "radar", B_RADAR },
}
@ B_ENTRANCE
Definition cp_building.h:64
@ B_QUARTERS
Definition cp_building.h:54
@ B_DEFENCE_LASER
Definition cp_building.h:66
@ B_COMMAND
Definition cp_building.h:62
@ B_RADAR
Definition cp_building.h:67
@ B_HANGAR
Definition cp_building.h:58
@ MAX_BUILDING_TYPE
Definition cp_building.h:69
@ B_POWER
Definition cp_building.h:61
@ B_STORAGE
Definition cp_building.h:55
@ B_LAB
Definition cp_building.h:53
@ B_HOSPITAL
Definition cp_building.h:57
@ B_WORKSHOP
Definition cp_building.h:56
@ B_SMALL_HANGAR
Definition cp_building.h:60
@ B_DEFENCE_MISSILE
Definition cp_building.h:65
@ B_ALIEN_CONTAINMENT
Definition cp_building.h:59
@ B_ANTIMATTER
Definition cp_building.h:63

Referenced by B_GetBuildingTypeByBuildingID().

◆ valid_building_vars

const value_t valid_building_vars[]
static
Initial value:
= {
{"map_name", V_HUNK_STRING, offsetof(building_t, mapPart), 0},
{"max_count", V_INT, offsetof(building_t, maxCount), MEMBER_SIZEOF(building_t, maxCount)},
{"level", V_FLOAT, offsetof(building_t, level), MEMBER_SIZEOF(building_t, level)},
{"name", V_TRANSLATION_STRING, offsetof(building_t, name), 0},
{"tech", V_HUNK_STRING, offsetof(building_t, pedia), 0},
{"status", V_INT, offsetof(building_t, buildingStatus), MEMBER_SIZEOF(building_t, buildingStatus)},
{"image", V_HUNK_STRING, offsetof(building_t, image), 0},
{"size", V_POS, offsetof(building_t, size), MEMBER_SIZEOF(building_t, size)},
{"fixcosts", V_INT, offsetof(building_t, fixCosts), MEMBER_SIZEOF(building_t, fixCosts)},
{"varcosts", V_INT, offsetof(building_t, varCosts), MEMBER_SIZEOF(building_t, varCosts)},
{"build_time", V_INT, offsetof(building_t, buildTime), MEMBER_SIZEOF(building_t, buildTime)},
{"starting_employees", V_INT, offsetof(building_t, maxEmployees), MEMBER_SIZEOF(building_t, maxEmployees)},
{"capacity", V_INT, offsetof(building_t, capacity), MEMBER_SIZEOF(building_t, capacity)},
{"onconstruct", V_HUNK_STRING, offsetof(building_t, onConstruct), 0},
{"ondestroy", V_HUNK_STRING, offsetof(building_t, onDestroy), 0},
{"onenable", V_HUNK_STRING, offsetof(building_t, onEnable), 0},
{"ondisable", V_HUNK_STRING, offsetof(building_t, onDisable), 0},
{"mandatory", V_BOOL, offsetof(building_t, mandatory), MEMBER_SIZEOF(building_t, mandatory)},
{nullptr, V_NULL, 0, 0}
}
level_locals_t level
Definition g_main.cpp:38
voidpf void uLong size
Definition ioapi.h:42
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
@ V_BOOL
Definition scripts.h:50
@ V_FLOAT
Definition scripts.h:54
@ V_TRANSLATION_STRING
Definition scripts.h:59
@ V_HUNK_STRING
Definition scripts.h:69
@ V_NULL
Definition scripts.h:49
@ V_INT
Definition scripts.h:52
@ V_POS
Definition scripts.h:55
#define MEMBER_SIZEOF(TYPE, MEMBER)
Definition scripts.h:34
A building with all it's data.
Definition cp_building.h:73

Holds the names of valid entries in the basemanagement.ufo file.

The valid definition names for BUILDINGS (building_t) in the basemanagement.ufo file. to the appropriate values in the corresponding struct

Definition at line 98 of file cp_building.cpp.

Referenced by B_ParseBuildings().