mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-21 07:43:18 +00:00
Game Board: play_controller and game_state are no longer friends
A non-const overload of game_board::map was added in the process
This commit is contained in:
parent
8e13e8811d
commit
3006359321
@ -795,10 +795,11 @@ DEFINE_FAI_FUNCTION(simplest_path, 2, 3)
|
||||
}
|
||||
|
||||
for (std::vector<map_location>::const_iterator loc_iter = route.steps.begin() + 1 ; loc_iter !=route.steps.end(); ++loc_iter) {
|
||||
if (unit_it->movement_cost((resources::gameboard->map())[*loc_iter]) < movetype::UNREACHABLE )
|
||||
if(unit_it->movement_cost(static_cast<const game_board*>(resources::gameboard)->map()[*loc_iter]) < movetype::UNREACHABLE) {
|
||||
locations.emplace_back(std::make_shared<location_callable>(*loc_iter));
|
||||
else
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return variant(locations);
|
||||
|
@ -48,7 +48,6 @@ namespace events {
|
||||
|
||||
class game_board : public display_context
|
||||
{
|
||||
|
||||
std::vector<team> teams_;
|
||||
std::vector<std::string> labels_;
|
||||
|
||||
@ -57,10 +56,8 @@ class game_board : public display_context
|
||||
unit_map units_;
|
||||
|
||||
//TODO: Remove these when we have refactored enough to make it possible.
|
||||
friend class play_controller;
|
||||
friend class events::mouse_handler;
|
||||
friend class events::menu_handler;
|
||||
friend class game_state;
|
||||
friend class game_lua_kernel;
|
||||
|
||||
/**
|
||||
@ -110,6 +107,11 @@ public:
|
||||
return *map_;
|
||||
}
|
||||
|
||||
gamemap& map()
|
||||
{
|
||||
return *map_;
|
||||
}
|
||||
|
||||
virtual const unit_map& units() const override
|
||||
{
|
||||
return units_;
|
||||
|
@ -168,7 +168,7 @@ void game_state::place_sides_in_preferred_locations(const config& level)
|
||||
if(placed.count(i->side) == 0 && positions_taken.count(i->pos) == 0) {
|
||||
placed.insert(i->side);
|
||||
positions_taken.insert(i->pos);
|
||||
board_.map_->set_starting_position(i->side,i->pos);
|
||||
board_.map().set_starting_position(i->side,i->pos);
|
||||
LOG_NG << "placing side " << i->side << " at " << i->pos << std::endl;
|
||||
}
|
||||
}
|
||||
@ -190,9 +190,9 @@ void game_state::init(const config& level, play_controller & pc)
|
||||
|
||||
LOG_NG << "initialized teams... " << (SDL_GetTicks() - pc.ticks()) << std::endl;
|
||||
|
||||
board_.teams_.resize(level.child_count("side"));
|
||||
if (player_number_ > static_cast<int>(board_.teams_.size())) {
|
||||
ERR_NG << "invalid player number " << player_number_ << " #sides=" << board_.teams_.size() << "\n";
|
||||
board_.teams().resize(level.child_count("side"));
|
||||
if (player_number_ > static_cast<int>(board_.teams().size())) {
|
||||
ERR_NG << "invalid player number " << player_number_ << " #sides=" << board_.teams().size() << "\n";
|
||||
player_number_ = 1;
|
||||
// in case there are no teams, using player_number_ migh still cause problems later.
|
||||
}
|
||||
@ -210,7 +210,7 @@ void game_state::init(const config& level, play_controller & pc)
|
||||
}
|
||||
++team_num;
|
||||
team_builder_ptr tb_ptr = create_team_builder(side,
|
||||
board_.teams_, level, board_, team_num);
|
||||
board_.teams(), level, board_, team_num);
|
||||
build_team_stage_one(tb_ptr);
|
||||
team_builders.push_back(tb_ptr);
|
||||
}
|
||||
@ -227,9 +227,9 @@ void game_state::init(const config& level, play_controller & pc)
|
||||
{
|
||||
build_team_stage_two(tb_ptr);
|
||||
}
|
||||
for(std::size_t i = 0; i < board_.teams_.size(); i++) {
|
||||
for(std::size_t i = 0; i < board_.teams().size(); i++) {
|
||||
// Labels from players in your ignore list default to hidden
|
||||
if(preferences::is_ignored(board_.teams_[i].current_player())) {
|
||||
if(preferences::is_ignored(board_.teams()[i].current_player())) {
|
||||
std::string label_cat = "side:" + std::to_string(i + 1);
|
||||
board_.hidden_label_categories().push_back(label_cat);
|
||||
}
|
||||
@ -451,11 +451,11 @@ private:
|
||||
|
||||
void game_state::add_side_wml(config cfg)
|
||||
{
|
||||
cfg["side"] = board_.teams_.size() + 1;
|
||||
cfg["side"] = board_.teams().size() + 1;
|
||||
//if we want to also allow setting the controller we must update the server code.
|
||||
cfg["controller"] = "null";
|
||||
//TODO: is this it? are there caches which must be cleared?
|
||||
board_.teams_.emplace_back();
|
||||
board_.teams_.back().build(cfg, board_.map(), cfg["gold"].to_int());
|
||||
board_.teams().emplace_back();
|
||||
board_.teams().back().build(cfg, board_.map(), cfg["gold"].to_int());
|
||||
config choice = synced_context::ask_server_choice(add_side_wml_choice());
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ bool play_controller::hotkey_handler::do_execute_command(const hotkey::hotkey_co
|
||||
std::string name = cmd.command.substr(prefixlen);
|
||||
const map_location& hex = mouse_handler_.get_last_hex();
|
||||
|
||||
return gamestate().get_wml_menu_items().fire_item(name, hex, gamestate().gamedata_, gamestate(), gamestate().board_.units_, !press);
|
||||
return gamestate().get_wml_menu_items().fire_item(name, hex, gamestate().gamedata_, gamestate(), gamestate().board_.units(), !press);
|
||||
}
|
||||
return command_executor::do_execute_command(cmd, index, press, release);
|
||||
}
|
||||
@ -444,7 +444,7 @@ void play_controller::hotkey_handler::expand_wml_commands(std::vector<config>& i
|
||||
std::vector<config> newitems;
|
||||
|
||||
gamestate().get_wml_menu_items().get_items(mouse_handler_.get_last_hex(), wml_commands_, newitems,
|
||||
gamestate(), gamestate().gamedata_, gamestate().board_.units_);
|
||||
gamestate(), gamestate().gamedata_, gamestate().board_.units());
|
||||
|
||||
// Replace this placeholder entry with available menu items.
|
||||
items.insert(pos, newitems.begin(), newitems.end());
|
||||
|
@ -674,7 +674,7 @@ marked_route mark_route(const plain_route &rt, bool update_move_cost)
|
||||
|
||||
// move_cost of the next step is irrelevant for the last step
|
||||
assert(last_step || resources::gameboard->map().on_board(*(i+1)));
|
||||
const int move_cost = last_step ? 0 : u.movement_cost((resources::gameboard->map())[*(i+1)]);
|
||||
const int move_cost = last_step ? 0 : u.movement_cost(static_cast<const game_board*>(resources::gameboard)->map()[*(i+1)]);
|
||||
|
||||
const team& viewing_team = resources::gameboard->teams()[display::get_singleton()->viewing_team()];
|
||||
|
||||
|
@ -394,7 +394,7 @@ void play_controller::fire_start()
|
||||
check_objectives();
|
||||
// prestart and start events may modify the initial gold amount,
|
||||
// reflect any changes.
|
||||
for (team& tm : gamestate().board_.teams_)
|
||||
for (team& tm : get_teams())
|
||||
{
|
||||
tm.set_start_gold(tm.gold());
|
||||
}
|
||||
@ -834,7 +834,7 @@ void play_controller::process_keyup_event(const SDL_Event& event)
|
||||
unit_movement_resetter move_reset(*u, u->side() != current_side());
|
||||
|
||||
mouse_handler_.set_current_paths(pathfind::paths(*u, false,
|
||||
true, gamestate().board_.teams_[gui_->viewing_team()],
|
||||
true, get_teams()[gui_->viewing_team()],
|
||||
mouse_handler_.get_path_turns()));
|
||||
|
||||
gui_->highlight_reach(mouse_handler_.current_paths());
|
||||
|
@ -2438,7 +2438,7 @@ static int intf_unit_movement_cost(lua_State *L)
|
||||
t_translation::terrain_code t;
|
||||
map_location loc;
|
||||
if(luaW_tolocation(L, 2, loc)) {
|
||||
t = resources::gameboard->map()[loc];
|
||||
t = static_cast<const game_board*>(resources::gameboard)->map()[loc];
|
||||
} else if(lua_isstring(L, 2)) {
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t = t_translation::read_terrain_code(m);
|
||||
@ -2459,7 +2459,7 @@ static int intf_unit_vision_cost(lua_State *L)
|
||||
t_translation::terrain_code t;
|
||||
map_location loc;
|
||||
if(luaW_tolocation(L, 2, loc)) {
|
||||
t = resources::gameboard->map()[loc];
|
||||
t = static_cast<const game_board*>(resources::gameboard)->map()[loc];
|
||||
} else if(lua_isstring(L, 2)) {
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t = t_translation::read_terrain_code(m);
|
||||
@ -2480,7 +2480,7 @@ static int intf_unit_jamming_cost(lua_State *L)
|
||||
t_translation::terrain_code t;
|
||||
map_location loc;
|
||||
if(luaW_tolocation(L, 2, loc)) {
|
||||
t = resources::gameboard->map()[loc];
|
||||
t = static_cast<const game_board*>(resources::gameboard)->map()[loc];
|
||||
} else if(lua_isstring(L, 2)) {
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t = t_translation::read_terrain_code(m);
|
||||
@ -2501,7 +2501,7 @@ static int intf_unit_defense(lua_State *L)
|
||||
t_translation::terrain_code t;
|
||||
map_location loc;
|
||||
if(luaW_tolocation(L, 2, loc)) {
|
||||
t = resources::gameboard->map()[loc];
|
||||
t = static_cast<const game_board*>(resources::gameboard)->map()[loc];
|
||||
} else if(lua_isstring(L, 2)) {
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t = t_translation::read_terrain_code(m);
|
||||
|
Loading…
x
Reference in New Issue
Block a user