OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Ruleset.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_RULESET_H
20 #define OPENXCOM_RULESET_H
21 
22 #include <map>
23 #include <vector>
24 #include <string>
25 #include <yaml-cpp/yaml.h>
26 #include "../Savegame/GameTime.h"
27 
28 namespace OpenXcom
29 {
30 
31 class SavedGame;
32 class SoldierNamePool;
33 class Soldier;
34 class RuleCountry;
35 class RuleRegion;
36 class RuleBaseFacility;
37 class RuleCraft;
38 class RuleCraftWeapon;
39 class RuleItem;
40 class RuleUfo;
41 class RuleTerrain;
42 class MapDataSet;
43 class ResourcePack;
44 class RuleSoldier;
45 class Unit;
46 class Armor;
47 class ArticleDefinition;
48 class RuleInventory;
49 class RuleResearch;
50 class RuleManufacture;
51 class AlienRace;
52 class AlienDeployment;
53 class UfoTrajectory;
54 class RuleAlienMission;
55 class City;
56 class Base;
57 class MCDPatch;
58 class ExtraSprites;
59 class ExtraSounds;
60 class ExtraStrings;
61 class StatString;
62 
69 class Ruleset
70 {
71 protected:
72  std::vector<SoldierNamePool*> _names;
73  std::map<std::string, RuleCountry*> _countries;
74  std::map<std::string, RuleRegion*> _regions;
75  std::map<std::string, RuleBaseFacility*> _facilities;
76  std::map<std::string, RuleCraft*> _crafts;
77  std::map<std::string, RuleCraftWeapon*> _craftWeapons;
78  std::map<std::string, RuleItem*> _items;
79  std::map<std::string, RuleUfo*> _ufos;
80  std::map<std::string, RuleTerrain*> _terrains;
81  std::map<std::string, MapDataSet*> _mapDataSets;
82  std::map<std::string, RuleSoldier*> _soldiers;
83  std::map<std::string, Unit*> _units;
84  std::map<std::string, AlienRace*> _alienRaces;
85  std::map<std::string, AlienDeployment*> _alienDeployments;
86  std::map<std::string, Armor*> _armors;
87  std::map<std::string, ArticleDefinition*> _ufopaediaArticles;
88  std::map<std::string, RuleInventory*> _invs;
89  std::map<std::string, RuleResearch *> _research;
90  std::map<std::string, RuleManufacture *> _manufacture;
91  std::map<std::string, UfoTrajectory *> _ufoTrajectories;
92  std::map<std::string, RuleAlienMission *> _alienMissions;
93  std::map<std::string, MCDPatch *> _MCDPatches;
94  std::vector<std::pair<std::string, ExtraSprites *> > _extraSprites;
95  std::vector<std::pair<std::string, ExtraSounds *> > _extraSounds;
96  std::map<std::string, ExtraStrings *> _extraStrings;
97  std::vector<StatString*> _statStrings;
98  int _costSoldier, _costEngineer, _costScientist, _timePersonnel, _initialFunding;
99  YAML::Node _startingBase;
100  GameTime _startingTime;
101  std::vector<std::string> _countriesIndex, _regionsIndex, _facilitiesIndex, _craftsIndex, _craftWeaponsIndex, _itemsIndex, _invsIndex, _ufosIndex;
102  std::vector<std::string> _aliensIndex, _deploymentsIndex, _armorsIndex, _ufopaediaIndex, _researchIndex, _manufactureIndex, _MCDPatchesIndex;
103  std::vector<std::string> _alienMissionsIndex, _terrainIndex, _extraSpritesIndex, _extraSoundsIndex, _extraStringsIndex;
104  std::vector<std::vector<int> > _alienItemLevels;
105  int _modIndex, _facilityListOrder, _craftListOrder, _itemListOrder, _researchListOrder, _manufactureListOrder, _ufopaediaListOrder, _invListOrder;
106  std::vector<std::string> _psiRequirements; // it's a cache for psiStrengthEval
108  void loadFile(const std::string &filename);
110  void loadFiles(const std::string &dirname);
112  template <typename T>
113  T *loadRule(const YAML::Node &node, std::map<std::string, T*> *map, std::vector<std::string> *index = 0, const std::string &key = "type");
114 public:
116  Ruleset();
118  ~Ruleset();
120  void load(const std::string &source);
122  SavedGame *newSave() const;
124  const std::vector<SoldierNamePool*> &getPools() const;
126  RuleCountry *getCountry(const std::string &id) const;
128  const std::vector<std::string> &getCountriesList() const;
130  RuleRegion *getRegion(const std::string &id) const;
132  const std::vector<std::string> &getRegionsList() const;
134  RuleBaseFacility *getBaseFacility(const std::string &id) const;
136  const std::vector<std::string> &getBaseFacilitiesList() const;
138  RuleCraft *getCraft(const std::string &id) const;
140  const std::vector<std::string> &getCraftsList() const;
142  RuleCraftWeapon *getCraftWeapon(const std::string &id) const;
144  const std::vector<std::string> &getCraftWeaponsList() const;
146  RuleItem *getItem(const std::string &id) const;
148  const std::vector<std::string> &getItemsList() const;
150  RuleUfo *getUfo(const std::string &id) const;
152  const std::vector<std::string> &getUfosList() const;
154  const std::vector<std::string> &getTerrainList() const;
156  RuleTerrain *getTerrain(const std::string &name) const;
158  MapDataSet *getMapDataSet(const std::string &name);
160  RuleSoldier *getSoldier(const std::string &name) const;
162  Unit *getUnit(const std::string &name) const;
164  AlienRace *getAlienRace(const std::string &name) const;
166  const std::vector<std::string> &getAlienRacesList() const;
168  AlienDeployment *getDeployment(const std::string &name) const;
170  const std::vector<std::string> &getDeploymentsList() const;
172  Armor *getArmor(const std::string &name) const;
174  const std::vector<std::string> &getArmorsList() const;
176  ArticleDefinition *getUfopaediaArticle(const std::string &name) const;
178  const std::vector<std::string> &getUfopaediaList() const;
180  std::map<std::string, RuleInventory*> *getInventories();
182  RuleInventory *getInventory(const std::string &id) const;
184  int getSoldierCost() const;
186  int getEngineerCost() const;
188  int getScientistCost() const;
190  int getPersonnelTime() const;
192  RuleResearch *getResearch (const std::string &id) const;
194  const std::vector<std::string> &getResearchList () const;
196  RuleManufacture *getManufacture (const std::string &id) const;
198  const std::vector<std::string> &getManufactureList () const;
200  std::vector<OpenXcom::RuleBaseFacility*> getCustomBaseFacilities() const;
202  const UfoTrajectory *getUfoTrajectory(const std::string &id) const;
204  const RuleAlienMission *getAlienMission(const std::string &id) const;
206  const std::vector<std::string> &getAlienMissionList() const;
208  const City *locateCity(double lon, double lat) const;
210  const std::vector<std::vector<int> > &getAlienItemLevels() const;
212  const YAML::Node &getStartingBase();
214  MCDPatch *getMCDPatch(const std::string name) const;
216  std::vector<std::pair<std::string, ExtraSprites *> > getExtraSprites() const;
218  std::vector<std::pair<std::string, ExtraSounds *> > getExtraSounds() const;
220  std::map<std::string, ExtraStrings *> getExtraStrings() const;
222  std::vector<StatString *> getStatStrings() const;
224  void sortLists();
226  std::vector<std::string> getPsiRequirements() const;
228  const std::vector<std::string> &getInvsList () const;
230  Soldier *genSoldier(SavedGame *save) const;
231 
232 };
233 
234 }
235 
236 #endif
ArticleDefinition * getUfopaediaArticle(const std::string &name) const
Gets Ufopaedia article definition.
Definition: Ruleset.cpp:951
RuleSoldier * getSoldier(const std::string &name) const
Gets soldier unit rules.
Definition: Ruleset.cpp:826
const std::vector< std::string > & getCraftsList() const
Gets the available crafts.
Definition: Ruleset.cpp:710
std::vector< std::string > getPsiRequirements() const
Gets the research-requirements for Psi-Lab (it's a cache for psiStrengthEval)
Definition: Ruleset.cpp:1320
Ruleset()
Creates a blank ruleset.
Definition: Ruleset.cpp:73
const std::vector< std::string > & getBaseFacilitiesList() const
Gets the available facilities.
Definition: Ruleset.cpp:689
const std::vector< std::string > & getUfopaediaList() const
Gets the available articles.
Definition: Ruleset.cpp:962
int getEngineerCost() const
Gets the cost of an engineer.
Definition: Ruleset.cpp:921
RuleItem * getItem(const std::string &id) const
Gets the ruleset for an item type.
Definition: Ruleset.cpp:741
const std::vector< std::string > & getItemsList() const
Gets the available items.
Definition: Ruleset.cpp:754
std::map< std::string, ExtraStrings * > getExtraStrings() const
Gets the list of external Strings.
Definition: Ruleset.cpp:1179
void load(const std::string &source)
Loads a ruleset from the given source.
Definition: Ruleset.cpp:200
RuleCraftWeapon * getCraftWeapon(const std::string &id) const
Gets the ruleset for a craft weapon type.
Definition: Ruleset.cpp:720
The game data that gets written to disk when the game is saved.
Definition: SavedGame.h:80
const City * locateCity(double lon, double lat) const
Gets the city at the specified coordinates.
Definition: Ruleset.cpp:1115
const std::vector< std::string > & getAlienRacesList() const
Gets the available alien races.
Definition: Ruleset.cpp:859
SavedGame * newSave() const
Generates the starting saved game.
Definition: Ruleset.cpp:567
RuleUfo * getUfo(const std::string &id) const
Gets the ruleset for a UFO type.
Definition: Ruleset.cpp:764
int getPersonnelTime() const
Gets the transfer time of personnel.
Definition: Ruleset.cpp:941
Unit * getUnit(const std::string &name) const
Gets generated unit rules.
Definition: Ruleset.cpp:837
const YAML::Node & getStartingBase()
Gets the Defined starting base.
Definition: Ruleset.cpp:1142
std::vector< StatString * > getStatStrings() const
Gets the list of StatStrings.
Definition: Ruleset.cpp:1188
const std::vector< std::string > & getTerrainList() const
Gets the available terrains.
Definition: Ruleset.cpp:785
const std::vector< std::string > & getInvsList() const
Returns the sorted list of inventories.
Definition: Ruleset.cpp:991
RuleTerrain * getTerrain(const std::string &name) const
Gets terrains for battlescape games.
Definition: Ruleset.cpp:795
RuleCountry * getCountry(const std::string &id) const
Gets the ruleset for a country type.
Definition: Ruleset.cpp:636
Soldier * genSoldier(SavedGame *save) const
Generates a new soldier.
Definition: Ruleset.cpp:1330
const RuleAlienMission * getAlienMission(const std::string &id) const
Gets the ruleset for a specific alien mission.
Definition: Ruleset.cpp:1074
const std::vector< SoldierNamePool * > & getPools() const
Gets the pool list for soldier names.
Definition: Ruleset.cpp:626
Represents a specific type of item.
Definition: RuleItem.h:41
Armor * getArmor(const std::string &name) const
Gets armor rules.
Definition: Ruleset.cpp:890
Set of rules and stats for a game.
Definition: Ruleset.h:69
Represents a specific race "family", or a "main race" if you wish.
Definition: AlienRace.h:35
RuleBaseFacility * getBaseFacility(const std::string &id) const
Gets the ruleset for a facility type.
Definition: Ruleset.cpp:678
Holds information about a specific trajectory.
Definition: UfoTrajectory.h:49
RuleCraft * getCraft(const std::string &id) const
Gets the ruleset for a craft type.
Definition: Ruleset.cpp:699
const std::vector< std::string > & getArmorsList() const
Gets the available armors.
Definition: Ruleset.cpp:901
Stores the current ingame time/date according to GMT.
Definition: GameTime.h:40
Represents a specific type of armor.
Definition: Armor.h:36
Represents a soldier hired by the player.
Definition: Soldier.h:49
std::vector< OpenXcom::RuleBaseFacility * > getCustomBaseFacilities() const
Gets facilities for custom bases.
Definition: Ruleset.cpp:1043
const std::vector< std::string > & getDeploymentsList() const
Gets the available alien deployments.
Definition: Ruleset.cpp:880
int getSoldierCost() const
Gets the cost of a soldier.
Definition: Ruleset.cpp:911
AlienDeployment * getDeployment(const std::string &name) const
Gets deployment rules.
Definition: Ruleset.cpp:869
const std::vector< std::string > & getUfosList() const
Gets the available UFOs.
Definition: Ruleset.cpp:775
Represents a specific type of craft.
Definition: RuleCraft.h:38
Represents one research project.
Definition: RuleResearch.h:40
std::vector< std::pair< std::string, ExtraSprites * > > getExtraSprites() const
Gets the list of external Sprites.
Definition: Ruleset.cpp:1162
RuleRegion * getRegion(const std::string &id) const
Gets the ruleset for a region type.
Definition: Ruleset.cpp:657
Represents a city of the world.
Definition: City.h:32
std::map< std::string, RuleInventory * > * getInventories()
Gets the inventory list.
Definition: Ruleset.cpp:971
Stores fixed information about a mission type.
Definition: RuleAlienMission.h:61
ArticleDefinition is the base class for all article types.
Definition: ArticleDefinition.h:49
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.
Definition: Ruleset.cpp:522
RuleResearch * getResearch(const std::string &id) const
Gets the ruleset for a specific research project.
Definition: Ruleset.cpp:1001
An MCD data Patch.
Definition: MCDPatch.h:31
void loadFile(const std::string &filename)
Loads a ruleset from a YAML file.
Definition: Ruleset.cpp:214
void sortLists()
Sorts all our lists according to their weight.
Definition: Ruleset.cpp:1303
Represents the information needed to manufacture an object.
Definition: RuleManufacture.h:32
AlienRace * getAlienRace(const std::string &name) const
Gets alien race rules.
Definition: Ruleset.cpp:848
Represents the creation data for a specific type of unit.
Definition: RuleSoldier.h:33
const std::vector< std::string > & getCraftWeaponsList() const
Gets the available craft weapons.
Definition: Ruleset.cpp:731
const std::vector< std::vector< int > > & getAlienItemLevels() const
Gets the alien item level table.
Definition: Ruleset.cpp:1133
MapDataSet * getMapDataSet(const std::string &name)
Gets mapdatafile for battlescape games.
Definition: Ruleset.cpp:806
Represents a specific type of Alien Deployment.
Definition: AlienDeployment.h:55
const std::vector< std::string > & getManufactureList() const
Gets the list of all manufacture projects.
Definition: Ruleset.cpp:1031
void loadFiles(const std::string &dirname)
Loads all ruleset files from a directory.
Definition: Ruleset.cpp:503
Represents a specific type of UFO.
Definition: RuleUfo.h:37
Represents a specific funding country.
Definition: RuleCountry.h:33
int getScientistCost() const
Gets the cost of a scientist.
Definition: Ruleset.cpp:931
Represents a specific type of Battlescape Terrain.
Definition: RuleTerrain.h:41
const std::vector< std::string > & getCountriesList() const
Gets the available countries.
Definition: Ruleset.cpp:647
RuleInventory * getInventory(const std::string &id) const
Gets the ruleset for a specific inventory.
Definition: Ruleset.cpp:981
MCDPatch * getMCDPatch(const std::string name) const
Gets an MCDPatch.
Definition: Ruleset.cpp:1152
Represents a specific region of the world.
Definition: RuleRegion.h:65
const std::vector< std::string > & getResearchList() const
Gets the list of all research projects.
Definition: Ruleset.cpp:1011
RuleManufacture * getManufacture(const std::string &id) const
Gets the ruleset for a specific manufacture project.
Definition: Ruleset.cpp:1021
Represents a Terrain Map Datafile.
Definition: MapDataSet.h:40
const std::vector< std::string > & getRegionsList() const
Gets the available regions.
Definition: Ruleset.cpp:668
const UfoTrajectory * getUfoTrajectory(const std::string &id) const
Gets a specific UfoTrajectory.
Definition: Ruleset.cpp:1063
const std::vector< std::string > & getAlienMissionList() const
Gets the list of all alien missions.
Definition: Ruleset.cpp:1084
~Ruleset()
Cleans up the ruleset.
Definition: Ruleset.cpp:92
Represents a specific type of craft weapon.
Definition: RuleCraftWeapon.h:35
std::vector< std::pair< std::string, ExtraSounds * > > getExtraSounds() const
Gets the list of external Sounds.
Definition: Ruleset.cpp:1171
Represents the static data for a unit that is generated on the battlescape, this includes: HWPs...
Definition: Unit.h:50
Represents a specific section of the inventory, containing information like available slots and scree...
Definition: RuleInventory.h:44
Represents a specific type of base facility.
Definition: RuleBaseFacility.h:35