27 if(!lua_istable(L, idx)) {
30 int n = lua_absindex(L, -1);
34 out.
q = luaL_checkinteger(L, -1);
38 out.
r = luaL_checkinteger(L, -1);
40 out.
s = luaL_checkinteger(L, -1);
42 out.
s = -out.
q - out.
r;
44 if(out.
q + out.
s + out.
r != 0) {
53 luaL_argerror(L, idx,
"expected cubic location");
60 lua_pushinteger(L, loc.
q);
61 lua_rawseti(L, -2, 1);
62 lua_pushinteger(L, loc.
r);
63 lua_rawseti(L, -2, 2);
64 lua_pushinteger(L, loc.
s);
65 lua_rawseti(L, -2, 3);
80 return luaL_argerror(L, 1,
"get_direction: first argument(S) must be a location");
82 int nargs = lua_gettop(L);
84 luaL_error(L,
"get_direction: not missing direction argument");
90 n = luaL_checkinteger(L, -1);
95 if (lua_isstring(L, -1)) {
99 std::string
msg(
"get_direction: second argument should be a direction string, instead found a ");
100 msg += lua_typename(L, lua_type(L, -1));
101 return luaL_argerror(L, -1,
msg.c_str());
116 lua_pushstring(L,
"vector_sum: requires two locations");
131 lua_pushstring(L,
"vector_diff: requires two locations");
148 return luaL_argerror(L, 1,
"expected a location");
160 int k = luaL_checkinteger(L, -1);
164 lua_pushstring(L,
"rotate_right_around_center: requires two locations");
181 lua_pushstring(L,
"tiles_adjacent: requires two locations");
198 return luaL_argerror(L, 1,
"expected a location");
218 return luaL_argerror(L, 1,
"expected a location");
220 int radius = luaL_checkinteger(L, 2);
222 std::vector<map_location> locs;
239 return luaL_argerror(L, 1,
"expected a location");
241 int radius = luaL_checkinteger(L, 2);
243 std::vector<map_location> locs;
259 lua_pushstring(L,
"distance_between: requires two locations");
276 return luaL_argerror(L, 1,
"expected a location");
312 lua_pushstring(L,
"get_relative_dir: requires two locations");
317 lua_pushlstring(L, dir.c_str(), dir.length());
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
std::size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
void luaW_push_namedtuple(lua_State *L, const std::vector< std::string > &names)
Push an empty "named tuple" onto the stack.
void luaW_pushlocation(lua_State *L, const map_location &ml)
Converts a map location object to a Lua table pushed at the top of the stack.
bool luaW_tableget(lua_State *L, int index, const char *key)
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
static void luaW_pushcubeloc(lua_State *L, cubic_location loc)
static cubic_location luaW_checkcubeloc(lua_State *L, int idx)
static bool luaW_tocubeloc(lua_State *L, int idx, cubic_location &out)
int intf_get_relative_dir(lua_State *L)
Expose map_location get_relative_dir.
int intf_vector_negation(lua_State *L)
Expose map_location::vector_negation to lua.
int intf_distance_between(lua_State *L)
Expose map_location distance_between.
int intf_get_in_cubic(lua_State *L)
Expose map_location to_cubic.
int intf_tiles_adjacent(lua_State *L)
Expose map_location tiles_adjacent.
int intf_vector_diff(lua_State *L)
Expose map_location::vector_difference to lua.
int intf_get_from_cubic(lua_State *L)
Expose map_location from_cubic.
int intf_vector_sum(lua_State *L)
Expose map_location::vector_sum to lua.
int intf_get_tile_ring(lua_State *L)
Expose map_location get_tile_ring.
int intf_rotate_right_around_center(lua_State *L)
Expose map_location::rotate_right_around_center to lua.
int intf_get_tiles_in_radius(lua_State *L)
Expose map_location get_tiles_in_radius.
int intf_get_adjacent_tiles(lua_State *L)
Expose map_location get_adjacent_tiles.
int intf_get_direction(lua_State *L)
Expose map_location::get_direction function to lua Arg 1: a location Arg 2: a direction Arg 3: (optio...
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
void get_tiles_in_radius(const map_location ¢er, const int radius, std::vector< map_location > &result)
Function that will add to result all locations within radius tiles of center (excluding center itself...
void get_tile_ring(const map_location ¢er, const int radius, std::vector< map_location > &result)
Function that will add to result all locations exactly radius tiles from center (or nothing if radius...
void lua_push(lua_State *L, const T &val)
Represents a map location in cubic hexagonal coordinates.
Encapsulates the map of the game.
map_location & vector_sum_assign(const map_location &a)
map_location & vector_difference_assign(const map_location &a)
static map_location from_cubic(cubic_location h)
static std::string write_direction(direction dir)
map_location vector_negation() const
map_location get_direction(direction dir, unsigned int n=1u) const
map_location rotate_right_around_center(const map_location ¢er, int k) const
cubic_location to_cubic() const
direction
Valid directions which can be moved in our hexagonal world.
direction get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
static direction parse_direction(const std::string &str)
static map_location::direction n