OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Protected Member Functions | List of all members
OpenXcom::Ruleset Class Reference

Set of rules and stats for a game. More...

#include <Ruleset.h>

Public Member Functions

 Ruleset ()
 Creates a blank ruleset. More...
 
 ~Ruleset ()
 Cleans up the ruleset. More...
 
void load (const std::string &source)
 Loads a ruleset from the given source. More...
 
SavedGamenewSave () const
 Generates the starting saved game. More...
 
const std::vector
< SoldierNamePool * > & 
getPools () const
 Gets the pool list for soldier names. More...
 
RuleCountrygetCountry (const std::string &id) const
 Gets the ruleset for a country type. More...
 
const std::vector< std::string > & getCountriesList () const
 Gets the available countries. More...
 
RuleRegiongetRegion (const std::string &id) const
 Gets the ruleset for a region type. More...
 
const std::vector< std::string > & getRegionsList () const
 Gets the available regions. More...
 
RuleBaseFacilitygetBaseFacility (const std::string &id) const
 Gets the ruleset for a facility type. More...
 
const std::vector< std::string > & getBaseFacilitiesList () const
 Gets the available facilities. More...
 
RuleCraftgetCraft (const std::string &id) const
 Gets the ruleset for a craft type. More...
 
const std::vector< std::string > & getCraftsList () const
 Gets the available crafts. More...
 
RuleCraftWeapongetCraftWeapon (const std::string &id) const
 Gets the ruleset for a craft weapon type. More...
 
const std::vector< std::string > & getCraftWeaponsList () const
 Gets the available craft weapons. More...
 
RuleItemgetItem (const std::string &id) const
 Gets the ruleset for an item type. More...
 
const std::vector< std::string > & getItemsList () const
 Gets the available items. More...
 
RuleUfogetUfo (const std::string &id) const
 Gets the ruleset for a UFO type. More...
 
const std::vector< std::string > & getUfosList () const
 Gets the available UFOs. More...
 
const std::vector< std::string > & getTerrainList () const
 Gets the available terrains. More...
 
RuleTerraingetTerrain (const std::string &name) const
 Gets terrains for battlescape games. More...
 
MapDataSetgetMapDataSet (const std::string &name)
 Gets mapdatafile for battlescape games. More...
 
RuleSoldiergetSoldier (const std::string &name) const
 Gets soldier unit rules. More...
 
UnitgetUnit (const std::string &name) const
 Gets generated unit rules. More...
 
AlienRacegetAlienRace (const std::string &name) const
 Gets alien race rules. More...
 
const std::vector< std::string > & getAlienRacesList () const
 Gets the available alien races. More...
 
AlienDeploymentgetDeployment (const std::string &name) const
 Gets deployment rules. More...
 
const std::vector< std::string > & getDeploymentsList () const
 Gets the available alien deployments. More...
 
ArmorgetArmor (const std::string &name) const
 Gets armor rules. More...
 
const std::vector< std::string > & getArmorsList () const
 Gets the available armors. More...
 
ArticleDefinitiongetUfopaediaArticle (const std::string &name) const
 Gets Ufopaedia article definition. More...
 
const std::vector< std::string > & getUfopaediaList () const
 Gets the available articles. More...
 
std::map< std::string,
RuleInventory * > * 
getInventories ()
 Gets the inventory list. More...
 
RuleInventorygetInventory (const std::string &id) const
 Gets the ruleset for a specific inventory. More...
 
int getSoldierCost () const
 Gets the cost of a soldier. More...
 
int getEngineerCost () const
 Gets the cost of an engineer. More...
 
int getScientistCost () const
 Gets the cost of a scientist. More...
 
int getPersonnelTime () const
 Gets the transfer time of personnel. More...
 
RuleResearchgetResearch (const std::string &id) const
 Gets the ruleset for a specific research project. More...
 
const std::vector< std::string > & getResearchList () const
 Gets the list of all research projects. More...
 
RuleManufacturegetManufacture (const std::string &id) const
 Gets the ruleset for a specific manufacture project. More...
 
const std::vector< std::string > & getManufactureList () const
 Gets the list of all manufacture projects. More...
 
std::vector
< OpenXcom::RuleBaseFacility * > 
getCustomBaseFacilities () const
 Gets facilities for custom bases. More...
 
const UfoTrajectorygetUfoTrajectory (const std::string &id) const
 Gets a specific UfoTrajectory. More...
 
const RuleAlienMissiongetAlienMission (const std::string &id) const
 Gets the ruleset for a specific alien mission. More...
 
const std::vector< std::string > & getAlienMissionList () const
 Gets the list of all alien missions. More...
 
const CitylocateCity (double lon, double lat) const
 Gets the city at the specified coordinates. More...
 
const std::vector< std::vector
< int > > & 
getAlienItemLevels () const
 Gets the alien item level table. More...
 
const YAML::Node & getStartingBase ()
 Gets the Defined starting base. More...
 
MCDPatchgetMCDPatch (const std::string name) const
 Gets an MCDPatch. More...
 
std::vector< std::pair
< std::string, ExtraSprites * > > 
getExtraSprites () const
 Gets the list of external Sprites. More...
 
std::vector< std::pair
< std::string, ExtraSounds * > > 
getExtraSounds () const
 Gets the list of external Sounds. More...
 
std::map< std::string,
ExtraStrings * > 
getExtraStrings () const
 Gets the list of external Strings. More...
 
std::vector< StatString * > getStatStrings () const
 Gets the list of StatStrings. More...
 
void sortLists ()
 Sorts all our lists according to their weight.
 
std::vector< std::string > getPsiRequirements () const
 Gets the research-requirements for Psi-Lab (it's a cache for psiStrengthEval)
 
const std::vector< std::string > & getInvsList () const
 Returns the sorted list of inventories. More...
 
SoldiergenSoldier (SavedGame *save) const
 Generates a new soldier. More...
 

Protected Member Functions

void loadFile (const std::string &filename)
 Loads a ruleset from a YAML file. More...
 
void loadFiles (const std::string &dirname)
 Loads all ruleset files from a directory. More...
 
template<typename T >
T * loadRule (const YAML::Node &node, std::map< std::string, T * > *map, std::vector< std::string > *index=0, const std::string &key="type")
 Loads a ruleset element. More...
 

Detailed Description

Set of rules and stats for a game.

A ruleset holds all the constant info that never changes throughout a game, like stats of all the in-game items, countries, research tree, soldier names, starting base, etc.

Constructor & Destructor Documentation

OpenXcom::Ruleset::Ruleset ( )

Creates a blank ruleset.

Creates a ruleset with blank sets of rules.

OpenXcom::Ruleset::~Ruleset ( )

Cleans up the ruleset.

Deletes all the contained rules from memory.

Member Function Documentation

Soldier * OpenXcom::Ruleset::genSoldier ( SavedGame save) const

Generates a new soldier.

Creates a new randomly-generated soldier.

Parameters
saveSaved game the soldier belongs to.
Returns
Newly generated soldier.
const std::vector< std::vector< int > > & OpenXcom::Ruleset::getAlienItemLevels ( ) const

Gets the alien item level table.

Returns
A deep array containing the alien item levels.
const RuleAlienMission * OpenXcom::Ruleset::getAlienMission ( const std::string &  id) const

Gets the ruleset for a specific alien mission.

Returns the rules for the specified alien mission.

Parameters
idAlien mission type.
Returns
Rules for the alien mission.
const std::vector< std::string > & OpenXcom::Ruleset::getAlienMissionList ( ) const

Gets the list of all alien missions.

Returns the list of alien mission types.

Returns
The list of alien mission types.
AlienRace * OpenXcom::Ruleset::getAlienRace ( const std::string &  name) const

Gets alien race rules.

Returns the info about a specific alien race.

Parameters
nameRace name.
Returns
Rules for the race.
const std::vector< std::string > & OpenXcom::Ruleset::getAlienRacesList ( ) const

Gets the available alien races.

Returns the list of all alien races.

provided by the ruleset.

Returns
List of alien races.
Armor * OpenXcom::Ruleset::getArmor ( const std::string &  name) const

Gets armor rules.

Returns the info about a specific armor.

Parameters
nameArmor name.
Returns
Rules for the armor.
const std::vector< std::string > & OpenXcom::Ruleset::getArmorsList ( ) const

Gets the available armors.

Returns the list of all armors provided by the ruleset.

Returns
List of armors.
const std::vector< std::string > & OpenXcom::Ruleset::getBaseFacilitiesList ( ) const

Gets the available facilities.

Returns the list of all base facilities provided by the ruleset.

Returns
List of base faciliies.
RuleBaseFacility * OpenXcom::Ruleset::getBaseFacility ( const std::string &  id) const

Gets the ruleset for a facility type.

Returns the rules for the specified base facility.

Parameters
idFacility type.
Returns
Rules for the facility.
const std::vector< std::string > & OpenXcom::Ruleset::getCountriesList ( ) const

Gets the available countries.

Returns the list of all countries provided by the ruleset.

Returns
List of countries.
RuleCountry * OpenXcom::Ruleset::getCountry ( const std::string &  id) const

Gets the ruleset for a country type.

Returns the rules for the specified country.

Parameters
idCountry type.
Returns
Rules for the country.
RuleCraft * OpenXcom::Ruleset::getCraft ( const std::string &  id) const

Gets the ruleset for a craft type.

Returns the rules for the specified craft.

Parameters
idCraft type.
Returns
Rules for the craft.
const std::vector< std::string > & OpenXcom::Ruleset::getCraftsList ( ) const

Gets the available crafts.

Returns the list of all crafts provided by the ruleset.

Returns
List of crafts.
RuleCraftWeapon * OpenXcom::Ruleset::getCraftWeapon ( const std::string &  id) const

Gets the ruleset for a craft weapon type.

Returns the rules for the specified craft weapon.

Parameters
idCraft weapon type.
Returns
Rules for the craft weapon.
const std::vector< std::string > & OpenXcom::Ruleset::getCraftWeaponsList ( ) const

Gets the available craft weapons.

Returns the list of all craft weapons provided by the ruleset.

Returns
List of craft weapons.
std::vector< OpenXcom::RuleBaseFacility * > OpenXcom::Ruleset::getCustomBaseFacilities ( ) const

Gets facilities for custom bases.

Generates and returns a list of facilities for custom bases.

The list contains all the facilities that are listed in the 'startingBase' part of the ruleset.

Returns
The list of facilities for custom bases.
AlienDeployment * OpenXcom::Ruleset::getDeployment ( const std::string &  name) const

Gets deployment rules.

Returns the info about a specific deployment.

Parameters
nameDeployment name.
Returns
Rules for the deployment.
const std::vector< std::string > & OpenXcom::Ruleset::getDeploymentsList ( ) const

Gets the available alien deployments.

Returns the list of all alien deployments provided by the ruleset.

Returns
List of alien deployments.
int OpenXcom::Ruleset::getEngineerCost ( ) const

Gets the cost of an engineer.

Returns the cost of an individual engineer for purchase/maintenance.

Returns
Cost.
std::vector< std::pair< std::string, ExtraSounds * > > OpenXcom::Ruleset::getExtraSounds ( ) const

Gets the list of external Sounds.

Gets the list of external sounds.

Returns
The list of external sounds.
std::vector< std::pair< std::string, ExtraSprites * > > OpenXcom::Ruleset::getExtraSprites ( ) const

Gets the list of external Sprites.

Gets the list of external sprites.

Returns
The list of external sprites.
std::map< std::string, ExtraStrings * > OpenXcom::Ruleset::getExtraStrings ( ) const

Gets the list of external Strings.

Gets the list of external strings.

Returns
The list of external strings.
std::map< std::string, RuleInventory * > * OpenXcom::Ruleset::getInventories ( )

Gets the inventory list.

Returns the list of inventories.

Returns
Pointer to inventory list.
RuleInventory * OpenXcom::Ruleset::getInventory ( const std::string &  id) const

Gets the ruleset for a specific inventory.

Returns the rules for a specific inventory.

Parameters
idInventory type.
Returns
Inventory ruleset.
const std::vector< std::string > & OpenXcom::Ruleset::getInvsList ( ) const

Returns the sorted list of inventories.

Returns the list of inventories.

Returns
The list of inventories.
RuleItem * OpenXcom::Ruleset::getItem ( const std::string &  id) const

Gets the ruleset for an item type.

Returns the rules for the specified item.

Parameters
idItem type.
Returns
Rules for the item, or 0 when the item is not found.
const std::vector< std::string > & OpenXcom::Ruleset::getItemsList ( ) const

Gets the available items.

Returns the list of all items provided by the ruleset.

Returns
List of items.
RuleManufacture * OpenXcom::Ruleset::getManufacture ( const std::string &  id) const

Gets the ruleset for a specific manufacture project.

Returns the rules for the specified manufacture project.

Parameters
idManufacture project type.
Returns
Rules for the manufacture project.
const std::vector< std::string > & OpenXcom::Ruleset::getManufactureList ( ) const

Gets the list of all manufacture projects.

Returns the list of manufacture projects.

Returns
The list of manufacture projects.
MapDataSet * OpenXcom::Ruleset::getMapDataSet ( const std::string &  name)

Gets mapdatafile for battlescape games.

Returns the info about a specific map data file.

Parameters
nameDatafile name.
Returns
Rules for the datafile.
MCDPatch * OpenXcom::Ruleset::getMCDPatch ( const std::string  id) const

Gets an MCDPatch.

Parameters
idThe ID of the MCDPatch we want.
Returns
The MCDPatch based on ID, or 0 if none defined.
int OpenXcom::Ruleset::getPersonnelTime ( ) const

Gets the transfer time of personnel.

Returns the time it takes to transfer personnel between bases.

Returns
Time in hours.
const std::vector< SoldierNamePool * > & OpenXcom::Ruleset::getPools ( ) const

Gets the pool list for soldier names.

Returns the list of soldier name pools.

Returns
Pointer to soldier name pool list.
RuleRegion * OpenXcom::Ruleset::getRegion ( const std::string &  id) const

Gets the ruleset for a region type.

Returns the rules for the specified region.

Parameters
idRegion type.
Returns
Rules for the region.
const std::vector< std::string > & OpenXcom::Ruleset::getRegionsList ( ) const

Gets the available regions.

Returns the list of all regions provided by the ruleset.

Returns
List of regions.
RuleResearch * OpenXcom::Ruleset::getResearch ( const std::string &  id) const

Gets the ruleset for a specific research project.

Returns the rules for the specified research project.

Parameters
idResearch project type.
Returns
Rules for the research project.
const std::vector< std::string > & OpenXcom::Ruleset::getResearchList ( ) const

Gets the list of all research projects.

Returns the list of research projects.

Returns
The list of research projects.
int OpenXcom::Ruleset::getScientistCost ( ) const

Gets the cost of a scientist.

Returns the cost of an individual scientist for purchase/maintenance.

Returns
Cost.
RuleSoldier * OpenXcom::Ruleset::getSoldier ( const std::string &  name) const

Gets soldier unit rules.

Returns the info about a specific unit.

Parameters
nameUnit name.
Returns
Rules for the units.
int OpenXcom::Ruleset::getSoldierCost ( ) const

Gets the cost of a soldier.

Returns the cost of an individual soldier for purchase/maintenance.

Returns
Cost.
const YAML::Node & OpenXcom::Ruleset::getStartingBase ( )

Gets the Defined starting base.

Returns
The starting base definition.
std::vector< StatString * > OpenXcom::Ruleset::getStatStrings ( ) const

Gets the list of StatStrings.

Returns
The list of StatStrings.
RuleTerrain * OpenXcom::Ruleset::getTerrain ( const std::string &  name) const

Gets terrains for battlescape games.

Returns the rules for the specified terrain.

Parameters
nameTerrain name.
Returns
Rules for the terrain.
const std::vector< std::string > & OpenXcom::Ruleset::getTerrainList ( ) const

Gets the available terrains.

Returns the list of all terrains provided by the ruleset.

Returns
List of terrains.
RuleUfo * OpenXcom::Ruleset::getUfo ( const std::string &  id) const

Gets the ruleset for a UFO type.

Returns the rules for the specified UFO.

Parameters
idUFO type.
Returns
Rules for the UFO.
ArticleDefinition * OpenXcom::Ruleset::getUfopaediaArticle ( const std::string &  name) const

Gets Ufopaedia article definition.

Returns the article definition for a given name.

Parameters
nameArticle name.
Returns
Article definition.
const std::vector< std::string > & OpenXcom::Ruleset::getUfopaediaList ( ) const

Gets the available articles.

Returns the list of all articles provided by the ruleset.

Returns
List of articles.
const std::vector< std::string > & OpenXcom::Ruleset::getUfosList ( ) const

Gets the available UFOs.

Returns the list of all ufos provided by the ruleset.

Returns
List of ufos.
const UfoTrajectory * OpenXcom::Ruleset::getUfoTrajectory ( const std::string &  id) const

Gets a specific UfoTrajectory.

Returns the data for the specified ufo trajectory.

Parameters
idUfo trajectory id.
Returns
A pointer to the data for the specified ufo trajectory.
Unit * OpenXcom::Ruleset::getUnit ( const std::string &  name) const

Gets generated unit rules.

Returns the info about a specific unit.

Parameters
nameUnit name.
Returns
Rules for the units.
void OpenXcom::Ruleset::load ( const std::string &  source)

Loads a ruleset from the given source.

Loads a ruleset's contents from the given source.

Parameters
sourceThe source to use.
void OpenXcom::Ruleset::loadFile ( const std::string &  filename)
protected

Loads a ruleset from a YAML file.

Loads a ruleset's contents from a YAML file.

Rules that match pre-existing rules overwrite them.

Parameters
filenameYAML filename.
void OpenXcom::Ruleset::loadFiles ( const std::string &  dirname)
protected

Loads all ruleset files from a directory.

Loads the contents of all the rule files in the given directory.

Parameters
dirnameThe name of an existing directory containing rule files.
template<typename T >
T * OpenXcom::Ruleset::loadRule ( const YAML::Node &  node,
std::map< std::string, T * > *  map,
std::vector< std::string > *  index = 0,
const std::string &  key = "type" 
)
protected

Loads a ruleset element.

Loads a rule element, adding/removing from vectors as necessary.

Parameters
nodeYAML node.
mapMap associated to the rule type.
indexIndex vector for the rule type.
keyRule key name.
Returns
Pointer to new rule if one was created, or NULL if one was removed.
const City * OpenXcom::Ruleset::locateCity ( double  lon,
double  lat 
) const

Gets the city at the specified coordinates.

Finds the city at coordinates lon, lat.

The search will only match exact coordinates.

Parameters
lonThe longtitude.
latThe latitude.
Returns
A pointer to the city information, or 0 if no city was found.
SavedGame * OpenXcom::Ruleset::newSave ( ) const

Generates the starting saved game.

Generates a brand new saved game with starting data.

Returns
A new saved game.

The documentation for this class was generated from the following files: