@@ -56,7 +56,7 @@ namespace BBM
56
56
return path;
57
57
}
58
58
59
- std::vector<Vector2f> LuaMap::getNeighbors (Vector2f node) const
59
+ std::vector<Vector2f> LuaMap::getNeighbors (Vector2f node, bool throughBreakable ) const
60
60
{
61
61
std::vector<Vector2f> neighbors;
62
62
for (auto &dir : _dirs) {
@@ -65,7 +65,8 @@ namespace BBM
65
65
continue ;
66
66
if (neighbor.y >= 17 || neighbor.x >= 17 )
67
67
continue ;
68
- if (_map[neighbor.y ][neighbor.x ] == 0 &&
68
+ if ((_map[neighbor.y ][neighbor.x ] == 0 ||
69
+ _map[neighbor.y ][neighbor.x ] == throughBreakable) &&
69
70
_danger[neighbor.y ][neighbor.x ] != 1 )
70
71
neighbors.push_back (neighbor);
71
72
}
@@ -83,7 +84,7 @@ namespace BBM
83
84
return neighbors;
84
85
}
85
86
86
- std::vector<Vector2f> LuaMap::pathfind (Vector2f root, Vector2f target) const
87
+ std::vector<Vector2f> LuaMap::pathfind (Vector2f root, Vector2f target, bool throughBreakable ) const
87
88
{
88
89
std::vector<Vector2f> closed;
89
90
std::vector<Vector2f> open ;
@@ -117,7 +118,7 @@ namespace BBM
117
118
}
118
119
open .erase (std::remove (open .begin (), open .end (), current), open .end ());
119
120
closed.push_back (current);
120
- auto neighbors = getNeighbors (current);
121
+ auto neighbors = getNeighbors (current, throughBreakable );
121
122
for (auto &neighbor : neighbors) {
122
123
if (std::find (closed.begin (), closed.end (), neighbor) != closed.end ())
123
124
continue ;
@@ -224,14 +225,16 @@ namespace BBM
224
225
int LuaMap::getPath (lua_State *L)
225
226
{
226
227
LuaG::State state (L);
227
- auto y2 = state.getNumber (-1 );
228
- auto x2 = state.getNumber (-2 );
229
- auto y1 = state.getNumber (-3 );
230
- auto x1 = state.getNumber (-4 );
231
- const LuaMap *map = reinterpret_cast <const LuaMap *>(state.getPointer (state.getFirstUpValueIdx ()));
228
+ auto throughBreakable = state.getBool (-1 );
229
+ auto y2 = state.getNumber (-2 );
230
+ auto x2 = state.getNumber (-3 );
231
+ auto y1 = state.getNumber (-4 );
232
+ auto x1 = state.getNumber (-5 );
233
+
234
+ const LuaMap *map = reinterpret_cast <const LuaMap *>(state.getPointer (state.getFirstUpValueIdx ()));
232
235
Vector2f fst (x1, y1 );
233
236
Vector2f snd (x2, y2);
234
- auto path = map->pathfind (fst, snd);
237
+ auto path = map->pathfind (fst, snd, throughBreakable );
235
238
int index = 1 ;
236
239
state.newTable ();
237
240
for (auto &r : path) {
@@ -319,6 +322,54 @@ namespace BBM
319
322
return 1 ;
320
323
}
321
324
325
+ int LuaMap::getRadius (lua_State *L)
326
+ {
327
+ LuaG::State state (L);
328
+ const LuaMap *map = reinterpret_cast <const LuaMap *>(state.getPointer (state.getFirstUpValueIdx ()));
329
+ state.push (map->currRadius );
330
+ return 1 ;
331
+ }
332
+
333
+ int LuaMap::getEnemies (lua_State *L)
334
+ {
335
+ LuaG::State state (L);
336
+ const LuaMap *map = reinterpret_cast <const LuaMap *>(state.getPointer (state.getFirstUpValueIdx ()));
337
+ int index = 1 ;
338
+ state.newTable ();
339
+ for (auto &r : map->_enemies ) {
340
+ state.push (index ++);
341
+ state.newTable ();
342
+ state.push (" x" );
343
+ state.push (r.x );
344
+ state.setTable ();
345
+ state.push (" y" );
346
+ state.push (r.y );
347
+ state.setTable ();
348
+ state.setTable ();
349
+ }
350
+ return 1 ;
351
+ }
352
+
353
+ int LuaMap::getEnemiesRound (lua_State *L)
354
+ {
355
+ LuaG::State state (L);
356
+ const LuaMap *map = reinterpret_cast <const LuaMap *>(state.getPointer (state.getFirstUpValueIdx ()));
357
+ int index = 1 ;
358
+ state.newTable ();
359
+ for (auto &r : map->_enemies ) {
360
+ state.push (index ++);
361
+ state.newTable ();
362
+ state.push (" x" );
363
+ state.push (std::round (r.x ));
364
+ state.setTable ();
365
+ state.push (" y" );
366
+ state.push (std::round (r.y ));
367
+ state.setTable ();
368
+ state.setTable ();
369
+ }
370
+ return 1 ;
371
+ }
372
+
322
373
int LuaMap::canPutBomb (lua_State *L)
323
374
{
324
375
LuaG::State state (L);
0 commit comments