Robot Devastation
|
Mental map is a repository for information about the players, targets and weapons. More...
#include <MentalMap.hpp>
Public Member Functions | |
bool | configure (const int &player_id) |
Store the id of the player corresponding to the user. | |
std::vector< Target > | getTargets () const |
std::vector< Player > | getPlayers () const |
Target | getTarget (const int &id=-1) const |
Player | getPlayer (const int &id=-1) const |
Player | getMyself () const |
Get the player corresponding to the user. | |
void | addWeapon (Weapon weapon) |
Weapon | getCurrentWeapon () const |
bool | shoot () |
Manage all the actions to be carried out when the user shoots (sound, update players, etc) | |
bool | reload () |
Manage all the actions to be carried out when the user reloads (sound, update weapons, etc) | |
bool | updatePlayers (const std::vector< Player > &new_player_vector) |
The current implementation just replaces the players inside the mental map by the new players. | |
bool | updateTargets (const std::vector< Target > &new_target_detections) |
Update the targets stored in the mental map. More... | |
bool | respawn () |
Restores the health of current player (and does more stuff if needed) | |
bool | addMentalMapEventListener (MentalMapEventListener *listener) |
Adds a MentalMapEventListener to the list of observers to be notified of events. | |
bool | removeMentalMapEventListeners () |
Unregisters all the MentalMapEventListener stored. | |
Static Public Member Functions | |
static MentalMap * | getMentalMap () |
Get a reference to the MentalMap. | |
static bool | destroyMentalMap () |
Get a reference to the MentalMap. | |
Private Member Functions | |
MentalMap () | |
Constructor. More... | |
MentalMap (const MentalMap &) | |
MentalMap & | operator= (const MentalMap &) |
bool | onDataArrived (const std::vector< Player > &players) |
Updates the local information about the players with the new data received by the NetworkManager. | |
Private Attributes | |
std::map< int, Target > | targets |
Storage for the target data. The key of the dictionary is the player id. | |
std::map< int, Player > | players |
Storage for the players data. The key of the dictionary is the player id. | |
std::vector< Weapon > | weapons |
Storage for the weapons data. | |
int | current_weapon |
Index of the weapon currenly selected. | |
int | my_id |
Id of the player corresponding to the user. | |
Player * | myself |
Pointer to the player corresponding to the user. | |
AudioManager * | audioManager |
Reference to the AudioManager. | |
std::vector< MentalMapEventListener * > | listeners |
Observers registered to be notified of data change events. | |
Static Private Attributes | |
static MentalMap * | mentalMapInstance = NULL |
Stores the unique instance of the MentalMap. | |
MentalMap is a singleton text (only one instance of this object can exist, that is is shared by all the users). To use this class, we first get the reference to the MentalMap with getMentalMap() and then we access the MentalMap with that reference.
When the program finishes, the MentalMap can be deallocated using destroyMentalMap().
MentalMap implements the NetworkEventListener observer interface, which allows this class to receive notification of network events to update its local data.
Data change events are broadcasted to the registered listeners, along with the data relevant to the event triggered (i.e. the new targets detected).
|
private |
Constructor for this class is private, since the singleton can only be instantiated once, and the instantiation is done at the getMentalMap() method.
bool rd::MentalMap::updateTargets | ( | const std::vector< Target > & | new_target_detections | ) |
If a target previously detected is no longer present in the new detections, decreases the belief value until reaching 0. Then, it deletes that target.