1 // SuperTuxKart - a fun racing game with go-kart
2 //
3 // Copyright (C) 2004-2015 Ingo Ruhnke <>
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
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.
23 #include "utils/ptr_vector.hpp"
24 #include <map>
25 #include <memory>
28 #include "utils/no_copy.hpp"
30 #define ALL_KART_GROUPS_ID "all"
33 class KartProperties;
34 class XMLNode;
40 {
41 private:
43  static std::vector<std::string> m_kart_search_path;
47  std::vector<std::string> m_all_kart_dirs;
50  std::vector<std::string> m_all_groups;
53  std::vector<std::string> m_kart_types;
56  std::map<std::string, std::vector<int> > m_groups_2_indices;
61  std::vector<int> m_selected_karts;
65  std::vector<bool> m_kart_available;
67  std::unique_ptr<AbstractCharacteristic> m_base_characteristic;
68  std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_difficulty_characteristics;
69  std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_kart_type_characteristics;
70  std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_player_characteristics;
72 protected:
78 public:
81  static void removeKartSearchDirs();
82  static void addKartSearchDir (const std::string &s);
83  const KartProperties* getKartById (int i) const;
84  const KartProperties* getKart(const std::string &ident) const;
85  const int getKartId(const std::string &ident) const;
86  int getKartByGroup(const std::string& group,
87  int i) const;
89  void loadCharacteristics (const XMLNode *root);
90  bool loadKart (const std::string &dir);
91  void loadAllKarts (bool loading_icon = true);
92  void unloadAllKarts ();
93  void removeKart(const std::string &id);
94  const std::vector<int> getKartsInGroup (const std::string& g);
95  bool kartAvailable(int kartid);
96  std::vector<std::string> getAllAvailableKarts() const;
97  void setUnavailableKarts(std::vector<std::string>);
98  void selectKartName(const std::string &kart_name);
99  bool testAndSetKart(int kartid);
100  void getRandomKartList(int count,
101  RemoteKartInfoList* existing_karts,
102  std::vector<std::string> *ai_list);
103  void setHatMeshName(const std::string &hat_name);
104  // ------------------------------------------------------------------------
106  const AbstractCharacteristic* getBaseCharacteristic() const { return m_base_characteristic.get(); }
107  // ------------------------------------------------------------------------
109  const AbstractCharacteristic* getDifficultyCharacteristic(const std::string &type) const;
110  // ------------------------------------------------------------------------
112  const AbstractCharacteristic* getKartTypeCharacteristic(const std::string &type, const std::string &name) const;
113  // ------------------------------------------------------------------------
115  const AbstractCharacteristic* getPlayerCharacteristic(const std::string &type) const;
116  // ------------------------------------------------------------------------
118  const std::vector<std::string>& getAllGroups() const {return m_all_groups;}
119  // ------------------------------------------------------------------------
122  // ------------------------------------------------------------------------
125  // ------------------------------------------------------------------------
127  int getNumSelectedKarts() const { return (int) m_selected_karts.size(); }
128  // ------------------------------------------------------------------------
130  void selectKart(int kartid) { m_selected_karts.push_back(kartid); }
131  // ------------------------------------------------------------------------
133  const std::vector<std::string>* getAllKartDirs() const
134  { return &m_all_kart_dirs; }
135  // ------------------------------------------------------------------------
137  const unsigned int getNumberOfKarts() const {
138  return (unsigned int)m_karts_properties.size();
139  } // getNumberOfKarts
140 };
142 extern KartPropertiesManager *kart_properties_manager;
144 #endif
146 /* EOF */
void clearAllSelectedKarts()
Clears all selected karts (used in networking only).
Definition: kart_properties_manager.hpp:121
int getNumSelectedKarts() const
Returns the number of selected karts (used in networking only).
Definition: kart_properties_manager.hpp:127
void removeLastSelectedKart()
Removed the last selected kart (used in networking only).
Definition: kart_properties_manager.hpp:124
std::vector< bool > m_kart_available
Contains a flag for each kart indicating wether it is available on all clients or not.
Definition: kart_properties_manager.hpp:65
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:56
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:474
const int getKartId(const std::string &ident) const
Returns index of the kart properties with the given ident.
Definition: kart_properties_manager.cpp:350
std::vector< std::string > m_all_groups
List of all kart groups.
Definition: kart_properties_manager.hpp:50
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:427
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:517
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:486
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:313
std::vector< std::string > m_kart_types
List of all kart types.
Definition: kart_properties_manager.hpp:53
const std::vector< std::string > & getAllGroups() const
Returns a list of all groups.
Definition: kart_properties_manager.hpp:118
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:43
Definition: kart_properties_manager.cpp:54
const AbstractCharacteristic * getDifficultyCharacteristic(const std::string &type) const
Get a characteristic that holds the values for a certain difficulty.
Definition: kart_properties_manager.cpp:303
std::vector< std::string > getAllAvailableKarts() const
Returns a list of all available kart identifiers.
Definition: kart_properties_manager.cpp:387
Definition: kart_properties_manager.hpp:39
void selectKart(int kartid)
Sets a kartid to be selected (used in networking only).
Definition: kart_properties_manager.hpp:130
const AbstractCharacteristic * getBaseCharacteristic() const
Get the characteristic that holds the base values.
Definition: kart_properties_manager.hpp:106
void loadAllKarts(bool loading_icon=true)
Loads all kart properties and models.
Definition: kart_properties_manager.cpp:154
bool loadKart(const std::string &dir)
Loads a single kart and (if not disabled) the corresponding 3d model.
Definition: kart_properties_manager.cpp:245
void unloadAllKarts()
Removes all karts from the KartPropertiesManager, so that they can be reloade.
Definition: kart_properties_manager.cpp:79
Characteristics are the properties of a kart that influence gameplay mechanics.
Definition: abstract_characteristic.hpp:42
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
const AbstractCharacteristic * getPlayerCharacteristic(const std::string &type) const
Get a characteristic that holds the values for a player difficulty.
Definition: kart_properties_manager.cpp:337
void loadCharacteristics(const XMLNode *root)
Loads the characteristics from the characteristics config file.
Definition: kart_properties_manager.cpp:188
KartPropertiesVector m_karts_properties
All available kart configurations.
Definition: kart_properties_manager.hpp:76
This class stores the properties of a kart.
Definition: kart_properties.hpp:60
const unsigned int getNumberOfKarts() const
Returns the number of karts.
Definition: kart_properties_manager.hpp:137
static void addKartSearchDir(const std::string &s)
Adds a directory from which karts are loaded.
Definition: kart_properties_manager.cpp:70
utility class used to parse XML files
Definition: xml_node.hpp:47
const std::vector< std::string > * getAllKartDirs() const
Returns all directories from which karts were loaded.
Definition: kart_properties_manager.hpp:133
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:294
std::vector< int > m_selected_karts
Vector containing kart numbers that have been selected in multiplayer games.
Definition: kart_properties_manager.hpp:61
std::vector< std::string > m_all_kart_dirs
All directories from which karts were loaded.
Definition: kart_properties_manager.hpp:47
Constructor, only clears internal data structures.
Definition: kart_properties_manager.cpp:46
bool kartAvailable(int kartid)
Returns true if a kart is available to be selected.
Definition: kart_properties_manager.cpp:455
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:404
void removeKart(const std::string &id)
Remove a kart from the kart manager.
Definition: kart_properties_manager.cpp:92