Skip to content

Commit

Permalink
Lua: don't allow setting a unit's x,y coordinated to an off-map location
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Feb 4, 2018
1 parent cfd0f77 commit c1cfcdb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/scripting/lua_unit.cpp
Expand Up @@ -14,9 +14,11 @@

#include "scripting/lua_unit.hpp"

#include "formatter.hpp"
#include "game_board.hpp"
#include "log.hpp"
#include "map/location.hpp" // for map_location
#include "map/map.hpp"
#include "resources.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/lua_unit_attacks.hpp"
Expand Down Expand Up @@ -463,6 +465,12 @@ static int impl_unit_set(lua_State *L)

// TODO: could probably be relegated to a helper function.
if(src != dst) {
// If the dst isn't on the map, the unit will be clobbered. Guard against that.
if(!gb->map().on_board(dst)) {
std::string err_msg = formatter() << "destination hex not on map (excluding border): " << dst;
return luaL_argerror(L, 2, err_msg.c_str());
}

unit_map::iterator u = gb->units().end();
bool success = false;

Expand Down

0 comments on commit c1cfcdb

Please sign in to comment.