Robot Devastation
MentalMap.hpp
1 // Authors: see AUTHORS.md at project root.
2 // CopyPolicy: released under the terms of the LGPLv2.1, see LICENSE at project root.
3 // URL: https://github.com/asrob-uc3m/robotDevastation
4 
5 #ifndef __RD_MENTAL_MAP_HPP__
6 #define __RD_MENTAL_MAP_HPP__
7 
8 #include <vector>
9 
10 #include "Player.hpp"
11 #include "Target.hpp"
12 #include "Weapon.hpp"
13 #include "MentalMapEventListener.hpp"
14 #include "NetworkEventListener.hpp"
15 #include "AudioManager.hpp"
16 
17 namespace rd{
18 
39 {
40  public:
41  //-- Creation and configuration
42  //--------------------------------------------------------------------------------------------
44  static MentalMap * getMentalMap();
45 
47  static bool destroyMentalMap();
48 
50  bool configure(const int& player_id );
51 
52 
53  //-- Interface to get data
54  //--------------------------------------------------------------------------------------------
55  std::vector<Target> getTargets() const;
56  std::vector<Player> getPlayers() const;
57  Target getTarget(const int& id = -1) const;
58  Player getPlayer(const int& id = -1) const;
59 
61  Player getMyself() const;
62 
63 
64  //-- Weapon interface
65  //--------------------------------------------------------------------------------------------
66  void addWeapon(Weapon weapon);
67  Weapon getCurrentWeapon() const;
68 
70  bool shoot();
71 
73  bool reload();
74 
75 
76  //-- Functions to update data
77  //--------------------------------------------------------------------------------------------
79  bool updatePlayers(const std::vector<Player> & new_player_vector);
80 
87  bool updateTargets(const std::vector<Target> & new_target_detections);
88 
90  bool respawn();
91 
92 
93  //-- Listeners
94  //--------------------------------------------------------------------------------------------
97 
100 
101  private:
108  MentalMap();
109 
110  MentalMap(const MentalMap &);
111  MentalMap & operator=(const MentalMap &);
112 
115 
116 
118  std::map<int, Target> targets;
119 
121  std::map<int, Player> players;
122 
124  std::vector<Weapon> weapons;
125 
128 
129 
131  int my_id;
132 
135 
136 
139 
140 
142  std::vector<MentalMapEventListener *> listeners;
143 
144 
145  //-- Implementation of NetworkEventListener functions
146  //--------------------------------------------------------------------------------------------
148  bool onDataArrived(const std::vector<Player> & players);
149 };
150 
151 }
152 
153 #endif //__RD_MENTAL_MAP_HPP__
rd::MentalMap
Mental map is a repository for information about the players, targets and weapons.
Definition: MentalMap.hpp:38
rd::AudioManager
Music and sound effects manager.
Definition: AudioManager.hpp:28
rd::MentalMap::shoot
bool shoot()
Manage all the actions to be carried out when the user shoots (sound, update players,...
Definition: MentalMap.cpp:137
rd::MentalMap::weapons
std::vector< Weapon > weapons
Storage for the weapons data.
Definition: MentalMap.hpp:124
rd::MentalMap::updateTargets
bool updateTargets(const std::vector< Target > &new_target_detections)
Update the targets stored in the mental map.
Definition: MentalMap.cpp:218
rd::MentalMap::my_id
int my_id
Id of the player corresponding to the user.
Definition: MentalMap.hpp:131
rd::Player
Class that represents a player of this game, with a 'unique' id, name, health, team id and score.
Definition: Player.hpp:21
rd
The main, catch-all namespace for Robot Devastation.
Definition: groups.dox:4
rd::MentalMap::targets
std::map< int, Target > targets
Storage for the target data. The key of the dictionary is the player id.
Definition: MentalMap.hpp:118
rd::MentalMap::respawn
bool respawn()
Restores the health of current player (and does more stuff if needed)
Definition: MentalMap.cpp:237
rd::MentalMap::onDataArrived
bool onDataArrived(const std::vector< Player > &players)
Updates the local information about the players with the new data received by the NetworkManager.
Definition: MentalMap.cpp:260
rd::MentalMap::updatePlayers
bool updatePlayers(const std::vector< Player > &new_player_vector)
The current implementation just replaces the players inside the mental map by the new players.
Definition: MentalMap.cpp:198
rd::MentalMap::reload
bool reload()
Manage all the actions to be carried out when the user reloads (sound, update weapons,...
Definition: MentalMap.cpp:192
rd::MentalMap::myself
Player * myself
Pointer to the player corresponding to the user.
Definition: MentalMap.hpp:134
rd::MentalMap::configure
bool configure(const int &player_id)
Store the id of the player corresponding to the user.
Definition: MentalMap.cpp:46
rd::Weapon
Class that represents a weapon.
Definition: Weapon.hpp:22
rd::MentalMap::audioManager
AudioManager * audioManager
Reference to the AudioManager.
Definition: MentalMap.hpp:138
rd::MentalMap::removeMentalMapEventListeners
bool removeMentalMapEventListeners()
Unregisters all the MentalMapEventListener stored.
Definition: MentalMap.cpp:254
rd::Target
Class that represents a target detected. This target is (or should be) associated to a player.
Definition: Target.hpp:18
rd::MentalMap::listeners
std::vector< MentalMapEventListener * > listeners
Observers registered to be notified of data change events.
Definition: MentalMap.hpp:142
rd::NetworkEventListener
Interface for objects that can be notified of input events by the NetworkManager.
Definition: NetworkEventListener.hpp:18
rd::MentalMap::addMentalMapEventListener
bool addMentalMapEventListener(MentalMapEventListener *listener)
Adds a MentalMapEventListener to the list of observers to be notified of events.
Definition: MentalMap.cpp:248
rd::MentalMap::mentalMapInstance
static MentalMap * mentalMapInstance
Stores the unique instance of the MentalMap.
Definition: MentalMap.hpp:114
rd::MentalMap::current_weapon
int current_weapon
Index of the weapon currenly selected.
Definition: MentalMap.hpp:127
rd::MentalMap::getMentalMap
static MentalMap * getMentalMap()
Get a reference to the MentalMap.
Definition: MentalMap.cpp:27
rd::MentalMap::MentalMap
MentalMap()
Constructor.
Definition: MentalMap.cpp:18
rd::MentalMap::players
std::map< int, Player > players
Storage for the players data. The key of the dictionary is the player id.
Definition: MentalMap.hpp:121
rd::MentalMap::getMyself
Player getMyself() const
Get the player corresponding to the user.
Definition: MentalMap.cpp:106
rd::MentalMap::destroyMentalMap
static bool destroyMentalMap()
Get a reference to the MentalMap.
Definition: MentalMap.cpp:35
rd::MentalMapEventListener
Interface for objects that can be notified of events related to changes on the data stored.
Definition: MentalMapEventListener.hpp:21