SuperTuxKart
kart_properties_manager.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 //
3 // Copyright (C) 2004-2015 Ingo Ruhnke <grumbel@gmx.de>
4 // Copyright (C) 2006-2015 SuperTuxKart-Team
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 3
9 // of the License, or (at your option) any later version.
10 //
11 // This program 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 this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 #ifndef HEADER_KART_PROPERTIES_MANAGER_HPP
21 #define HEADER_KART_PROPERTIES_MANAGER_HPP
22 
23 #include "utils/ptr_vector.hpp"
24 #include <map>
25 #include <memory>
26 #include <set>
27 
28 #include "config/favorite_status.hpp"
30 #include "utils/no_copy.hpp"
31 
32 #define ALL_KART_GROUPS_ID "all"
33 
35 class KartProperties;
36 class XMLNode;
37 
42 {
43 private:
45  static std::vector<std::string> m_kart_search_path;
46 
49  std::vector<std::string> m_all_kart_dirs;
50 
52  std::vector<std::string> m_all_groups;
53 
56 
58  std::vector<std::string> m_kart_types;
59 
61  std::map<std::string, std::vector<int> > m_groups_2_indices;
62 
64  std::map<std::string, std::vector<int> > m_groups_2_indices_no_custom;
65 
69  std::vector<int> m_selected_karts;
70 
73  std::vector<bool> m_kart_available;
74 
75  std::unique_ptr<AbstractCharacteristic> m_base_characteristic;
76  std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_difficulty_characteristics;
77  std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_kart_type_characteristics;
78  std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_player_characteristics;
79 
80 protected:
81 
85 
86 public:
89  static void removeKartSearchDirs();
90  static void addKartSearchDir (const std::string &s);
91  const KartProperties* getKartById (int i) const;
92  const KartProperties* getKart(const std::string &ident) const;
93  const int getKartId(const std::string &ident) const;
94  int getKartByGroup(const std::string& group,
95  int i) const;
96 
97  void loadCharacteristics (const XMLNode *root);
98  bool loadKart (const std::string &dir);
99  void loadAllKarts (bool loading_icon = true);
100  void unloadAllKarts ();
101  void removeKart(const std::string &id);
102  const std::vector<int> getKartsInGroup (const std::string& g);
107  bool kartAvailable(int kartid);
108  std::vector<std::string> getAllAvailableKarts() const;
109  void setUnavailableKarts(std::vector<std::string>);
110  void selectKartName(const std::string &kart_name);
111  bool testAndSetKart(int kartid);
112  void getRandomKartList(int count,
113  RemoteKartInfoList* existing_karts,
114  std::vector<std::string> *ai_list);
115  void setHatMeshName(const std::string &hat_name);
116  // ------------------------------------------------------------------------
118  const AbstractCharacteristic* getBaseCharacteristic() const { return m_base_characteristic.get(); }
119  // ------------------------------------------------------------------------
121  const AbstractCharacteristic* getDifficultyCharacteristic(const std::string &type) const;
122  // ------------------------------------------------------------------------
124  const AbstractCharacteristic* getKartTypeCharacteristic(const std::string &type, const std::string &name) const;
125  // ------------------------------------------------------------------------
126  const std::vector<std::string>& getAllKartTypes() const { return m_kart_types; }
127  // ------------------------------------------------------------------------
128  const std::string& getDefaultKartType() const { return m_kart_types[0]; }
129  // ------------------------------------------------------------------------
130  bool hasKartTypeCharacteristic(const std::string& type) const
131  {
132  return m_kart_type_characteristics.find(type) !=
133  m_kart_type_characteristics.end();
134  }
135  // ------------------------------------------------------------------------
137  const AbstractCharacteristic* getPlayerCharacteristic(const std::string &type) const;
138  // ------------------------------------------------------------------------
140  const std::vector<std::string>& getAllGroups() const { return m_all_groups; }
141  // ------------------------------------------------------------------------
144  // ------------------------------------------------------------------------
147  // ------------------------------------------------------------------------
149  int getNumSelectedKarts() const { return (int) m_selected_karts.size(); }
150  // ------------------------------------------------------------------------
152  void selectKart(int kartid) { m_selected_karts.push_back(kartid); }
153  // ------------------------------------------------------------------------
155  const std::vector<std::string>* getAllKartDirs() const
156  { return &m_all_kart_dirs; }
157  // ------------------------------------------------------------------------
159  const unsigned int getNumberOfKarts() const {
160  return (unsigned int)m_karts_properties.size();
161  } // getNumberOfKarts
162  // ------------------------------------------------------------------------
163  void onDemandLoadKartTextures(const std::set<std::string>& kart_list,
164  bool unload_unused = true);
165 };
166 
167 extern KartPropertiesManager *kart_properties_manager;
168 
169 #endif
170 
171 /* EOF */
Characteristics are the properties of a kart that influence gameplay mechanics.
Definition: abstract_characteristic.hpp:43
Class for storing the current favorites/custom groups of karts and tracks.
Definition: favorite_status.hpp:43
Definition: kart_properties_manager.hpp:42
const AbstractCharacteristic * getBaseCharacteristic() const
Get the characteristic that holds the base values.
Definition: kart_properties_manager.hpp:118
void selectKart(int kartid)
Sets a kartid to be selected (used in networking only).
Definition: kart_properties_manager.hpp:152
std::map< std::string, std::vector< int > > m_groups_2_indices_no_custom
Mapping of group names to list of kart indices in each group without customized ones.
Definition: kart_properties_manager.hpp:64
KartPropertiesVector m_karts_properties
All available kart configurations.
Definition: kart_properties_manager.hpp:84
void loadAllKarts(bool loading_icon=true)
Loads all kart properties and models.
Definition: kart_properties_manager.cpp:198
const AbstractCharacteristic * getDifficultyCharacteristic(const std::string &type) const
Get a characteristic that holds the values for a certain difficulty.
Definition: kart_properties_manager.cpp:351
const int getKartId(const std::string &ident) const
Returns index of the kart properties with the given ident.
Definition: kart_properties_manager.cpp:398
bool loadKart(const std::string &dir)
Loads a single kart and (if not disabled) the corresponding 3d model.
Definition: kart_properties_manager.cpp:290
void removeKart(const std::string &id)
Remove a kart from the kart manager.
Definition: kart_properties_manager.cpp:103
const std::vector< std::string > * getAllKartDirs() const
Returns all directories from which karts were loaded.
Definition: kart_properties_manager.hpp:155
void getRandomKartList(int count, RemoteKartInfoList *existing_karts, std::vector< std::string > *ai_list)
Returns a list of randomly selected karts.
Definition: kart_properties_manager.cpp:608
const AbstractCharacteristic * getPlayerCharacteristic(const std::string &type) const
Get a characteristic that holds the values for a player difficulty.
Definition: kart_properties_manager.cpp:385
void clearAllSelectedKarts()
Clears all selected karts (used in networking only).
Definition: kart_properties_manager.hpp:143
void unloadAllKarts()
Removes all karts from the KartPropertiesManager, so that they can be reloade.
Definition: kart_properties_manager.cpp:89
void setFavoriteKartStatus(FavoriteStatus *status)
Adds a track to the special group of favorite tracks.
Definition: kart_properties_manager.cpp:499
const unsigned int getNumberOfKarts() const
Returns the number of karts.
Definition: kart_properties_manager.hpp:159
KartPropertiesManager()
Constructor, only clears internal data structures.
Definition: kart_properties_manager.cpp:55
static std::vector< std::string > m_kart_search_path
The list of all directories in which to search for karts.
Definition: kart_properties_manager.hpp:45
std::vector< std::string > m_kart_types
List of all kart types.
Definition: kart_properties_manager.hpp:58
const AbstractCharacteristic * getKartTypeCharacteristic(const std::string &type, const std::string &name) const
Get a characteristic that holds the values for a kart type.
Definition: kart_properties_manager.cpp:361
void setUnavailableKarts(std::vector< std::string >)
Marks all karts except the ones listed in the string vector to be unavailable.
Definition: kart_properties_manager.cpp:452
FavoriteStatus * m_current_favorite_status
Current favorite karts.
Definition: kart_properties_manager.hpp:55
void selectKartName(const std::string &kart_name)
Sets a kart to be selected by specifying the identifier (name) of the kart.
Definition: kart_properties_manager.cpp:566
void loadCharacteristics(const XMLNode *root)
Loads the characteristics from the characteristics config file.
Definition: kart_properties_manager.cpp:233
static void addKartSearchDir(const std::string &s)
Adds a directory from which karts are loaded.
Definition: kart_properties_manager.cpp:80
std::vector< bool > m_kart_available
Contains a flag for each kart indicating whether it is available on all clients or not.
Definition: kart_properties_manager.hpp:73
~KartPropertiesManager()
Destructor.
Definition: kart_properties_manager.cpp:64
const std::vector< int > getKartsInGroup(const std::string &g)
Returns a vector with the indices of all karts in the specified group.
Definition: kart_properties_manager.cpp:578
const std::vector< std::string > & getAllGroups() const
Returns a list of all groups.
Definition: kart_properties_manager.hpp:140
std::vector< std::string > getAllAvailableKarts() const
Returns a list of all available kart identifiers.
Definition: kart_properties_manager.cpp:435
std::vector< std::string > m_all_groups
List of all kart groups.
Definition: kart_properties_manager.hpp:52
bool kartAvailable(int kartid)
Returns true if a kart is available to be selected.
Definition: kart_properties_manager.cpp:547
std::map< std::string, std::vector< int > > m_groups_2_indices
Mapping of group names to list of kart indices in each group.
Definition: kart_properties_manager.hpp:61
int getKartByGroup(const std::string &group, int i) const
Returns the (global) index of the n-th kart of a given group.
Definition: kart_properties_manager.cpp:475
std::vector< int > m_selected_karts
Vector containing kart numbers that have been selected in multiplayer games.
Definition: kart_properties_manager.hpp:69
void setHatMeshName(const std::string &hat_name)
Sets the name of a mesh to use as a hat for all karts.
Definition: kart_properties_manager.cpp:342
std::vector< std::string > m_all_kart_dirs
All directories from which karts were loaded.
Definition: kart_properties_manager.hpp:49
void removeLastSelectedKart()
Removed the last selected kart (used in networking only).
Definition: kart_properties_manager.hpp:146
int getNumSelectedKarts() const
Returns the number of selected karts (used in networking only).
Definition: kart_properties_manager.hpp:149
This class stores the properties of a kart.
Definition: kart_properties.hpp:60
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
utility class used to parse XML files
Definition: xml_node.hpp:48