Bomberman
LuaMap.hpp
Go to the documentation of this file.
1 //
2 //
3 //
4 
5 #pragma once
6 #include <lua.hpp>
7 #include "LuaGate.hpp"
8 #include "Models/Vector2.hpp"
9 #include <vector>
10 
11 namespace BBM
12 {
13  class LuaMap {
14  public:
16  LuaMap();
17 
19  ~LuaMap();
20 
22  void clearDanger(void);
23 
25  bool setDanger(int xpos, int ypos, int dangerLevel);
26 
28  void setPlayer(Vector3f pos);
29 
31  std::vector<Vector2f> pathfind(Vector2f root, Vector2f target, bool throughBreakable) const;
32 
34  Vector2f findSafeSpace(const std::vector<std::vector<int>> &dangerMap) const;
35 
37  static int getMap(lua_State *L);
38 
40  static int getDanger(lua_State *L);
41 
43  static int getPath(lua_State *L);
44 
46  static int getPlayer(lua_State *L);
47 
49  static int getPlayerRound(lua_State *L);
50 
52  static int getClosestSafeSpace(lua_State *L);
53 
55  static int getDangerLevelPlayer(lua_State *L);
56 
58  static int getDangerLevel(lua_State *L);
59 
61  static int getBlockType(lua_State *L);
62 
64  static int canPutBomb(lua_State *L);
65 
67  static int getRadius(lua_State *L);
68 
70  static int getEnemies(lua_State *L);
71 
73  static int getEnemiesRound(lua_State *L);
74 
76  std::vector<std::vector<int>> _map;
77 
79  std::vector<std::vector<int>> _danger;
80 
83 
85  std::vector<Vector2f> _enemies;
86 
89 
92  private:
94  std::vector<Vector2f> fillPath(std::vector<Vector2f> &path,
95  std::unordered_map<Vector2f, Vector2f> &cameFrom, Vector2f node) const;
96 
98  std::vector<Vector2f> getNeighbors(Vector2f node, bool throughBreakable) const;
99 
100  std::vector<Vector2f> _dirs = {
101  Vector2f(1, 0), Vector2f(-1, 0), Vector2f(0, 1), Vector2f(0, -1)
102  };
103 
104  };
105 }
106 
107 namespace std
108 {
109  template<>
110  struct hash<BBM::Vector2f>
111  {
113  typedef std::size_t result_type;
115  {
116  union {
117  float vector[2];
118  result_type hashed;
119  } hasher;
120  hasher.vector[0] = in.x;
121  hasher.vector[1] = in.y;
122  return hasher.hashed;
123  }
124  };
125 }
BBM::LuaMap::getClosestSafeSpace
static int getClosestSafeSpace(lua_State *L)
get closest safe space of player
Definition: LuaMap.cpp:282
BBM::LuaMap::_player
Vector2f _player
player position
Definition: LuaMap.hpp:82
std::hash< BBM::Vector2f >::result_type
std::size_t result_type
Definition: LuaMap.hpp:113
BBM::LuaMap::getDangerLevelPlayer
static int getDangerLevelPlayer(lua_State *L)
get danger level of player
Definition: LuaMap.cpp:297
BBM::Vector2
A Vector2 data type. (templated to allow any kind of vector2)
Definition: Vector2.hpp:18
BBM::LuaMap::findSafeSpace
Vector2f findSafeSpace(const std::vector< std::vector< int >> &dangerMap) const
find a safe space for current player
Definition: LuaMap.cpp:141
BBM::LuaMap::setPlayer
void setPlayer(Vector3f pos)
set player position
Definition: LuaMap.cpp:43
std::hash< BBM::Vector2f >::operator()
result_type operator()(argument_type const &in) const
Definition: LuaMap.hpp:114
BBM::LuaMap::clearDanger
void clearDanger(void)
Clear danger map.
Definition: LuaMap.cpp:22
BBM::Vector2::x
T x
The x value of the vector.
Definition: Vector2.hpp:22
Vector2.hpp
BBM::LuaMap::_danger
std::vector< std::vector< int > > _danger
dangers in 2D grid
Definition: LuaMap.hpp:79
BBM
Definition: AnimationsComponent.cpp:9
BBM::LuaMap::getNeighbors
std::vector< Vector2f > getNeighbors(Vector2f node, bool throughBreakable) const
get neighbors of node for a_star
Definition: LuaMap.cpp:59
BBM::LuaMap::getPlayer
static int getPlayer(lua_State *L)
get player pos
Definition: LuaMap.cpp:254
BBM::LuaMap::~LuaMap
~LuaMap()
dtor
Definition: LuaMap.cpp:19
BBM::LuaMap::_roundedPlayer
Vector2f _roundedPlayer
rounded player position
Definition: LuaMap.hpp:88
BBM::LuaMap::getPlayerRound
static int getPlayerRound(lua_State *L)
get rounded player pos
Definition: LuaMap.cpp:268
BBM::Vector3< float >
BBM::LuaMap::getEnemiesRound
static int getEnemiesRound(lua_State *L)
Get enemies position rounded.
Definition: LuaMap.cpp:353
BBM::LuaMap::canPutBomb
static int canPutBomb(lua_State *L)
Check if current player can put a bomb with an escape.
Definition: LuaMap.cpp:373
BBM::LuaMap::_dirs
std::vector< Vector2f > _dirs
Definition: LuaMap.hpp:100
BBM::LuaMap::getDanger
static int getDanger(lua_State *L)
push table of table of the danger map
Definition: LuaMap.cpp:205
BBM::LuaMap::fillPath
std::vector< Vector2f > fillPath(std::vector< Vector2f > &path, std::unordered_map< Vector2f, Vector2f > &cameFrom, Vector2f node) const
unwind path for a_star
Definition: LuaMap.cpp:49
BBM::LuaMap::_map
std::vector< std::vector< int > > _map
map blocks in 2D grid
Definition: LuaMap.hpp:76
LuaGate.hpp
BBM::LuaMap::getRadius
static int getRadius(lua_State *L)
Get current explosion radius of the player.
Definition: LuaMap.cpp:325
BBM::LuaMap::getDangerLevel
static int getDangerLevel(lua_State *L)
is xpos ypos in danger
Definition: LuaMap.cpp:305
BBM::LuaMap::LuaMap
LuaMap()
ctor
Definition: LuaMap.cpp:13
BBM::LuaMap::setDanger
bool setDanger(int xpos, int ypos, int dangerLevel)
set dangerlevel at xpos ypos
Definition: LuaMap.cpp:31
BBM::LuaMap::pathfind
std::vector< Vector2f > pathfind(Vector2f root, Vector2f target, bool throughBreakable) const
A star pathfinding between two points.
Definition: LuaMap.cpp:87
std
Definition: View.hpp:210
BBM::Vector2::y
T y
The y value of the vector.
Definition: Vector2.hpp:24
BBM::LuaMap::getBlockType
static int getBlockType(lua_State *L)
get block type at x y
Definition: LuaMap.cpp:315
BBM::LuaMap
Definition: LuaMap.hpp:13
BBM::LuaMap::getMap
static int getMap(lua_State *L)
push table of table of the map
Definition: LuaMap.cpp:185
std::hash< BBM::Vector2f >::argument_type
BBM::Vector2f argument_type
Definition: LuaMap.hpp:112
BBM::Vector2f
Vector2< float > Vector2f
Definition: Vector2.hpp:178
BBM::LuaMap::currRadius
int currRadius
Explosion radius of current player.
Definition: LuaMap.hpp:91
BBM::LuaMap::getEnemies
static int getEnemies(lua_State *L)
Get enemies position.
Definition: LuaMap.cpp:333
BBM::LuaMap::_enemies
std::vector< Vector2f > _enemies
other players position
Definition: LuaMap.hpp:85
BBM::LuaMap::getPath
static int getPath(lua_State *L)
get array of nodes, path from a to b
Definition: LuaMap.cpp:225