Emergency 20 Dokumentation  4.2.0
SpawnPoolManager.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
13 #include "em5/Export.h"
14 
16 
17 #include <boost/container/flat_map.hpp>
18 
19 #include <unordered_map>
20 
21 
22 //[-------------------------------------------------------]
23 //[ Namespace ]
24 //[-------------------------------------------------------]
25 namespace em5
26 {
27 
28 
29  //[-------------------------------------------------------]
30  //[ Classes ]
31  //[-------------------------------------------------------]
33  {
34 
35 
36  //[-------------------------------------------------------]
37  //[ Public data ]
38  //[-------------------------------------------------------]
39  public:
41  {
42  float spawnRate;
43  boost::container::flat_map<std::string, float> equipment;
44  std::string activity;
45  };
47 
48 
49  //[-------------------------------------------------------]
50  //[ Public methods ]
51  //[-------------------------------------------------------]
52  public:
58 
63  virtual ~SpawnPoolManager();
64 
69  void loadAssets();
70 
81  bool loadByFilename(const std::string& filename);
82 
93  const std::string& getRandomNameFromSpawnPool(const std::string& spawnPoolName, SpawnInstanceDataPointer* instanceData = nullptr) const;
94 
95  const std::string& getRandomEquipmentName(const SpawnInstanceData& instanceData) const;
96 
97  bool getSpawnpoolInstance(const std::string& spawnPoolName, const std::string& instanceName, SpawnInstanceDataPointer* instanceData = nullptr) const;
98 
99 
100  //[-------------------------------------------------------]
101  //[ Private definitions ]
102  //[-------------------------------------------------------]
103  private:
104  struct SpawnPoolData
105  {
106  boost::container::flat_map<std::string, SpawnInstanceData> data; // Key is the name of the entity for spawning, value is the percent of spawning rate
107  };
108 
109 
110  //[-------------------------------------------------------]
111  //[ Private methods ]
112  //[-------------------------------------------------------]
113  private:
114  float calculateRandomTriggerValueFromSpawnPool(const SpawnPoolData& spawnPoolData) const;
115 
116 
117  //[-------------------------------------------------------]
118  //[ Private data ]
119  //[-------------------------------------------------------]
120  private:
121  // TODO(mk) To improve performance use uint32 (hashed name) as key
122  std::unordered_map<std::string, SpawnPoolData> mSpawnPools;
123 
124 
125  };
126 
127 
128 //[-------------------------------------------------------]
129 //[ Namespace ]
130 //[-------------------------------------------------------]
131 } // em5
Definition: SpawnPoolManager.h:32
Definition: ActionPriority.h:13
std::string activity
The name of the activity the entity gets at start.
Definition: SpawnPoolManager.h:44
#define EM5_API_EXPORT
Definition: Export.h:28
Abstract manager interface.
Definition: Manager.h:40
float spawnRate
Definition: SpawnPoolManager.h:42
const SpawnInstanceData * SpawnInstanceDataPointer
Definition: SpawnPoolManager.h:46
boost::container::flat_map< std::string, float > equipment
Key is the name of the equipment prefab the entity is spawning, value is the percent of spawning rate...
Definition: SpawnPoolManager.h:43
Definition: SpawnPoolManager.h:40