Minor code cleanup regarding special map locations
This commit is contained in:
parent
086c7f5b4c
commit
9dbae39448
5 changed files with 13 additions and 48 deletions
|
@ -1156,7 +1156,7 @@ std::string default_map_generator_job::default_generate_map(
|
|||
const int x = c->x;
|
||||
const int y = c->y;
|
||||
const int player = c - castles.begin() + 1;
|
||||
const struct t_translation::coordinate coord(x, y);
|
||||
const t_translation::coordinate coord(x, y);
|
||||
starting_positions.insert(t_translation::tstarting_positions::value_type(std::to_string(player), coord));
|
||||
terrain[x][y] = t_translation::HUMAN_KEEP;
|
||||
|
||||
|
|
|
@ -247,11 +247,7 @@ static int special_locations_next(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
lua_pushstring(L, it->first.c_str());
|
||||
lua_createtable(L, 2, 0);
|
||||
lua_pushnumber(L, it->second.x + 1);
|
||||
lua_rawseti(L, -2, 1);
|
||||
lua_pushnumber(L, it->second.y + 1);
|
||||
lua_rawseti(L, -2, 2);
|
||||
luaW_pushlocation(L, it->second);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -271,22 +267,18 @@ static int special_locations_index(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
else {
|
||||
lua_createtable(L, 2, 0);
|
||||
lua_pushnumber(L, it->second.x + 1);
|
||||
lua_rawseti(L, -2, 1);
|
||||
lua_pushnumber(L, it->second.y + 1);
|
||||
lua_rawseti(L, -2, 2);
|
||||
luaW_pushlocation(L, it->second);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int special_locations_newindex(lua_State *L)
|
||||
{
|
||||
lua_pushstring(L, "special locations cannot be modified uwing wesnoth.special_locations");
|
||||
lua_pushstring(L, "special locations cannot be modified using wesnoth.special_locations");
|
||||
return lua_error(L);
|
||||
}
|
||||
|
||||
static void push_locations_talbe(lua_State *L)
|
||||
static void push_locations_table(lua_State *L)
|
||||
{
|
||||
lua_newtable(L); // The functor table
|
||||
lua_newtable(L); // The functor metatable
|
||||
|
@ -1090,12 +1082,7 @@ int game_lua_kernel::intf_get_starting_location(lua_State* L)
|
|||
const map_location& starting_pos = board().map().starting_position(side);
|
||||
if(!board().map().on_board(starting_pos)) return 0;
|
||||
|
||||
lua_createtable(L, 2, 0);
|
||||
lua_pushinteger(L, starting_pos.x + 1);
|
||||
lua_rawseti(L, -2, 1);
|
||||
lua_pushinteger(L, starting_pos.y + 1);
|
||||
lua_rawseti(L, -2, 2);
|
||||
|
||||
luaW_pushlocation(L, starting_pos);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -4300,7 +4287,7 @@ game_lua_kernel::game_lua_kernel(CVideo * video, game_state & gs, play_controlle
|
|||
lua_getglobal(L, "wesnoth");
|
||||
lua_newtable(L);
|
||||
lua_setfield(L, -2, "game_events");
|
||||
push_locations_talbe(L);
|
||||
push_locations_table(L);
|
||||
lua_setfield(L, -2, "special_locations");
|
||||
lua_pop(L, 1);
|
||||
|
||||
|
|
|
@ -595,14 +595,12 @@ void luaW_filltable(lua_State *L, config const &cfg)
|
|||
void luaW_pushlocation(lua_State *L, const map_location& ml)
|
||||
{
|
||||
lua_createtable(L, 2, 0);
|
||||
|
||||
lua_pushinteger(L, 1);
|
||||
|
||||
lua_pushinteger(L, ml.x + 1);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushinteger(L, 2);
|
||||
lua_rawseti(L, -3, 1);
|
||||
|
||||
lua_pushinteger(L, ml.y + 1);
|
||||
lua_rawset(L, -3);
|
||||
lua_rawseti(L, -3, 2);
|
||||
}
|
||||
|
||||
bool luaW_tolocation(lua_State *L, int index, map_location& loc) {
|
||||
|
|
|
@ -198,18 +198,6 @@ t_match::t_match(const t_terrain& tcode):
|
|||
}
|
||||
}
|
||||
|
||||
coordinate::coordinate()
|
||||
: x(0)
|
||||
, y(0)
|
||||
{
|
||||
}
|
||||
|
||||
coordinate::coordinate(const int x_, const int y_)
|
||||
: x(x_)
|
||||
, y(y_)
|
||||
{
|
||||
}
|
||||
|
||||
t_terrain read_terrain_code(const std::string& str, const t_layer filler)
|
||||
{
|
||||
return string_to_number_(str, filler);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <boost/bimap/set_of.hpp>
|
||||
#include <boost/bimap/multiset_of.hpp>
|
||||
#include "exceptions.hpp"
|
||||
#include "map/location.hpp"
|
||||
|
||||
namespace t_translation {
|
||||
|
||||
|
@ -93,16 +94,7 @@ namespace t_translation {
|
|||
};
|
||||
|
||||
/** Contains an x and y coordinate used for starting positions in maps. */
|
||||
/** TODO: remove this class and use map_location */
|
||||
struct coordinate {
|
||||
coordinate();
|
||||
coordinate(const int x_, const int y_);
|
||||
int x;
|
||||
int y;
|
||||
friend bool operator <(const coordinate&l, const coordinate&r) {
|
||||
return l.x < r.x || (l.x == r.x && l.y < r.y);
|
||||
}
|
||||
};
|
||||
using coordinate = map_location;
|
||||
|
||||
// Exception thrown if there's an error with the terrain.
|
||||
// Note: atm most thrown result in a crash, but I like
|
||||
|
|
Loading…
Add table
Reference in a new issue