SuperTuxKart
Loading...
Searching...
No Matches
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
29#include "utils/no_copy.hpp"
30
31#define ALL_KART_GROUPS_ID "all"
32
34class KartProperties;
35class XMLNode;
36
41{
42private:
44 static std::vector<std::string> m_kart_search_path;
45
48 std::vector<std::string> m_all_kart_dirs;
49
51 std::vector<std::string> m_all_groups;
52
54 std::vector<std::string> m_kart_types;
55
57 std::map<std::string, std::vector<int> > m_groups_2_indices;
58
62 std::vector<int> m_selected_karts;
63
66 std::vector<bool> m_kart_available;
67
68 std::unique_ptr<AbstractCharacteristic> m_base_characteristic;
69 std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_difficulty_characteristics;
70 std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_kart_type_characteristics;
71 std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_player_characteristics;
72
73protected:
74
78
79public:
82 static void removeKartSearchDirs();
83 static void addKartSearchDir (const std::string &s);
84 const KartProperties* getKartById (int i) const;
85 const KartProperties* getKart(const std::string &ident) const;
86 const int getKartId(const std::string &ident) const;
87 int getKartByGroup(const std::string& group,
88 int i) const;
89
90 void loadCharacteristics (const XMLNode *root);
91 bool loadKart (const std::string &dir);
92 void loadAllKarts (bool loading_icon = true);
93 void unloadAllKarts ();
94 void removeKart(const std::string &id);
95 const std::vector<int> getKartsInGroup (const std::string& g);
96 bool kartAvailable(int kartid);
97 std::vector<std::string> getAllAvailableKarts() const;
98 void setUnavailableKarts(std::vector<std::string>);
99 void selectKartName(const std::string &kart_name);
100 bool testAndSetKart(int kartid);
101 void getRandomKartList(int count,
102 RemoteKartInfoList* existing_karts,
103 std::vector<std::string> *ai_list);
104 void setHatMeshName(const std::string &hat_name);
105 // ------------------------------------------------------------------------
107 const AbstractCharacteristic* getBaseCharacteristic() const { return m_base_characteristic.get(); }
108 // ------------------------------------------------------------------------
110 const AbstractCharacteristic* getDifficultyCharacteristic(const std::string &type) const;
111 // ------------------------------------------------------------------------
113 const AbstractCharacteristic* getKartTypeCharacteristic(const std::string &type, const std::string &name) const;
114 // ------------------------------------------------------------------------
115 const std::string& getDefaultKartType() const { return m_kart_types[0]; }
116 // ------------------------------------------------------------------------
117 bool hasKartTypeCharacteristic(const std::string& type) const
118 {
119 return m_kart_type_characteristics.find(type) !=
120 m_kart_type_characteristics.end();
121 }
122 // ------------------------------------------------------------------------
124 const AbstractCharacteristic* getPlayerCharacteristic(const std::string &type) const;
125 // ------------------------------------------------------------------------
127 const std::vector<std::string>& getAllGroups() const {return m_all_groups;}
128 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
134 // ------------------------------------------------------------------------
136 int getNumSelectedKarts() const { return (int) m_selected_karts.size(); }
137 // ------------------------------------------------------------------------
139 void selectKart(int kartid) { m_selected_karts.push_back(kartid); }
140 // ------------------------------------------------------------------------
142 const std::vector<std::string>* getAllKartDirs() const
143 { return &m_all_kart_dirs; }
144 // ------------------------------------------------------------------------
146 const unsigned int getNumberOfKarts() const {
147 return (unsigned int)m_karts_properties.size();
148 } // getNumberOfKarts
149 // ------------------------------------------------------------------------
150 void onDemandLoadKartTextures(const std::set<std::string>& kart_list,
151 bool unload_unused = true);
152};
153
154extern KartPropertiesManager *kart_properties_manager;
155
156#endif
157
158/* EOF */
Characteristics are the properties of a kart that influence gameplay mechanics.
Definition: abstract_characteristic.hpp:43
Definition: kart_properties_manager.hpp:41
void selectKart(int kartid)
Sets a kartid to be selected (used in networking only).
Definition: kart_properties_manager.hpp:139
KartPropertiesVector m_karts_properties
All available kart configurations.
Definition: kart_properties_manager.hpp:77
void loadAllKarts(bool loading_icon=true)
Loads all kart properties and models.
Definition: kart_properties_manager.cpp:161
const AbstractCharacteristic * getDifficultyCharacteristic(const std::string &type) const
Get a characteristic that holds the values for a certain difficulty.
Definition: kart_properties_manager.cpp:310
const int getKartId(const std::string &ident) const
Returns index of the kart properties with the given ident.
Definition: kart_properties_manager.cpp:357
bool loadKart(const std::string &dir)
Loads a single kart and (if not disabled) the corresponding 3d model.
Definition: kart_properties_manager.cpp:252
void removeKart(const std::string &id)
Remove a kart from the kart manager.
Definition: kart_properties_manager.cpp:99
const AbstractCharacteristic * getBaseCharacteristic() const
Get the characteristic that holds the base values.
Definition: kart_properties_manager.hpp:107
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:524
const AbstractCharacteristic * getPlayerCharacteristic(const std::string &type) const
Get a characteristic that holds the values for a player difficulty.
Definition: kart_properties_manager.cpp:344
void clearAllSelectedKarts()
Clears all selected karts (used in networking only).
Definition: kart_properties_manager.hpp:130
const std::vector< std::string > & getAllGroups() const
Returns a list of all groups.
Definition: kart_properties_manager.hpp:127
const std::vector< std::string > * getAllKartDirs() const
Returns all directories from which karts were loaded.
Definition: kart_properties_manager.hpp:142
void unloadAllKarts()
Removes all karts from the KartPropertiesManager, so that they can be reloade.
Definition: kart_properties_manager.cpp:86
const unsigned int getNumberOfKarts() const
Returns the number of karts.
Definition: kart_properties_manager.hpp:146
KartPropertiesManager()
Constructor, only clears internal data structures.
Definition: kart_properties_manager.cpp:53
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:44
std::vector< std::string > m_kart_types
List of all kart types.
Definition: kart_properties_manager.hpp:54
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:320
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:411
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:481
void loadCharacteristics(const XMLNode *root)
Loads the characteristics from the characteristics config file.
Definition: kart_properties_manager.cpp:195
static void addKartSearchDir(const std::string &s)
Adds a directory from which karts are loaded.
Definition: kart_properties_manager.cpp:77
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:66
~KartPropertiesManager()
Destructor.
Definition: kart_properties_manager.cpp:61
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:493
std::vector< std::string > getAllAvailableKarts() const
Returns a list of all available kart identifiers.
Definition: kart_properties_manager.cpp:394
std::vector< std::string > m_all_groups
List of all kart groups.
Definition: kart_properties_manager.hpp:51
bool kartAvailable(int kartid)
Returns true if a kart is available to be selected.
Definition: kart_properties_manager.cpp:462
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:57
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:434
std::vector< int > m_selected_karts
Vector containing kart numbers that have been selected in multiplayer games.
Definition: kart_properties_manager.hpp:62
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:301
std::vector< std::string > m_all_kart_dirs
All directories from which karts were loaded.
Definition: kart_properties_manager.hpp:48
void removeLastSelectedKart()
Removed the last selected kart (used in networking only).
Definition: kart_properties_manager.hpp:133
int getNumSelectedKarts() const
Returns the number of selected karts (used in networking only).
Definition: kart_properties_manager.hpp:136
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
Definition: ptr_vector.hpp:44
utility class used to parse XML files
Definition: xml_node.hpp:48