Merge pull request #180 from cbeck88/add_game_board_struct_alternate
This is a refactor to introduce an object encapsulating the unit map, the game map, and the list of teams. Introducing this object permits us to move a substantial amount of code out of the play_controller object, and also to give a home to some helper functions in unit.?pp that previously sat in the global namespace. It also allows us to simplify the construction of some of the clients of play_controller. This refactor is ongoing WIP. The goals are (1) better organize the architecture of the engine, to make saving and reloading easier. (2) Facilitate the introduction of an improved pathfinding mechanism, which will need to sit between most of the other engine modules and the unit map / game map. (3) Refactoring clarifies what the existing code is doing, therefore it may help us to find bugs in the current system, which may be fixed independently of the refactor in 1.12.
This commit is contained in:
commit
096cb97cc1
37 changed files with 461 additions and 327 deletions
|
@ -285,6 +285,7 @@
|
|||
<Unit filename="../../src/formula_tokenizer.cpp" />
|
||||
<Unit filename="../../src/formula_tokenizer.hpp" />
|
||||
<Unit filename="../../src/game.cpp" />
|
||||
<Unit filename="../../src/game_board.cpp" />
|
||||
<Unit filename="../../src/game_config.cpp" />
|
||||
<Unit filename="../../src/game_config.hpp" />
|
||||
<Unit filename="../../src/game_config_manager.cpp" />
|
||||
|
|
|
@ -322,6 +322,7 @@
|
|||
<Unit filename="..\..\src\formula_tokenizer.cpp" />
|
||||
<Unit filename="..\..\src\formula_tokenizer.hpp" />
|
||||
<Unit filename="..\..\src\game.cpp" />
|
||||
<Unit filename="..\..\src\game_board.cpp" />
|
||||
<Unit filename="..\..\src\game_config.cpp" />
|
||||
<Unit filename="..\..\src\game_config.hpp" />
|
||||
<Unit filename="..\..\src\game_config_manager.cpp" />
|
||||
|
|
|
@ -4285,6 +4285,8 @@
|
|||
<File Name="../../src/tooltips.cpp"/>
|
||||
<File Name="../../src/race.hpp"/>
|
||||
<File Name="../../src/halo.cpp"/>
|
||||
<File Name="../../src/game_board.cpp"/>
|
||||
<File Name="../../src/game_board.hpp"/>
|
||||
<File Name="../../src/play_controller.cpp"/>
|
||||
<File Name="../../src/multiplayer_connect.cpp"/>
|
||||
<File Name="../../src/game_preferences_display.cpp"/>
|
||||
|
|
|
@ -20060,6 +20060,14 @@
|
|||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game_board.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game_board.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game_config.hpp"
|
||||
>
|
||||
|
|
|
@ -737,6 +737,7 @@ set(wesnoth-main_SRC
|
|||
formula_function.cpp
|
||||
formula_string_utils.cpp
|
||||
formula_tokenizer.cpp
|
||||
game_board.cpp
|
||||
game_config_manager.cpp
|
||||
game_controller.cpp
|
||||
game_display.cpp
|
||||
|
|
|
@ -269,6 +269,7 @@ wesnoth_sources = Split("""
|
|||
formula_function.cpp
|
||||
formula_string_utils.cpp
|
||||
formula_tokenizer.cpp
|
||||
game_board.cpp
|
||||
game_config_manager.cpp
|
||||
game_controller.cpp
|
||||
game_display.cpp
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "../config.hpp"
|
||||
#include "../config_assign.hpp"
|
||||
#include "../game_board.hpp"
|
||||
#include "../game_display.hpp"
|
||||
#include "../game_events/pump.hpp"
|
||||
#include "../game_preferences.hpp"
|
||||
|
@ -315,7 +316,7 @@ bool can_recruit_on(const map_location& leader_loc, const map_location& recruit_
|
|||
if ( view_team.shrouded(recruit_loc) )
|
||||
return false;
|
||||
|
||||
if ( get_visible_unit(recruit_loc, view_team) != NULL )
|
||||
if ( resources::gameboard->get_visible_unit(recruit_loc, view_team) != NULL )
|
||||
return false;
|
||||
|
||||
castle_cost_calculator calc(map, view_team);
|
||||
|
|
|
@ -768,7 +768,7 @@ namespace { // Private helpers for move_unit()
|
|||
if ( !is_replay_ ) {
|
||||
// Avoiding stopping on a (known) unit.
|
||||
route_iterator min_end = start == begin_ ? start : start + 1;
|
||||
while ( end != min_end && get_visible_unit(*(end-1), *current_team_) )
|
||||
while ( end != min_end && resources::gameboard->get_visible_unit(*(end-1), *current_team_) )
|
||||
// Backtrack.
|
||||
--end;
|
||||
}
|
||||
|
|
|
@ -284,7 +284,7 @@ bool shroud_clearer::clear_loc(team &tm, const map_location &loc,
|
|||
// Check for units?
|
||||
if ( result && check_units && loc != event_non_loc ) {
|
||||
// Uncovered a unit?
|
||||
unit_map::const_iterator sight_it = find_visible_unit(loc, tm);
|
||||
unit_map::const_iterator sight_it = resources::gameboard->find_visible_unit(loc, tm);
|
||||
if ( sight_it.valid() ) {
|
||||
record_sighting(*sight_it, loc, viewer_id, view_loc);
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "../formula.hpp"
|
||||
#include "../formula_function.hpp"
|
||||
#include "../formula_fwd.hpp"
|
||||
#include "../game_board.hpp"
|
||||
#include "../game_display.hpp"
|
||||
#include "../log.hpp"
|
||||
#include "../map.hpp"
|
||||
|
@ -430,7 +431,7 @@ void readonly_context_impl::calculate_moves(const unit_map& units, std::map<map_
|
|||
continue;
|
||||
}
|
||||
|
||||
if(src != dst && (find_visible_unit(dst, current_team()) == resources::units->end()) ) {
|
||||
if(src != dst && (resources::gameboard->find_visible_unit(dst, current_team()) == resources::units->end()) ) {
|
||||
srcdst.insert(std::pair<map_location,map_location>(src,dst));
|
||||
dstsrc.insert(std::pair<map_location,map_location>(dst,src));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "../composite/engine.hpp"
|
||||
#include "../composite/rca.hpp"
|
||||
#include "../composite/stage.hpp"
|
||||
#include "../../game_board.hpp"
|
||||
#include "../../gamestatus.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../map.hpp"
|
||||
|
@ -935,7 +936,7 @@ void get_villages_phase::execute()
|
|||
if(leader != units_.end() && leader->get_location() == i->second) {
|
||||
leader_move = *i;
|
||||
} else {
|
||||
if (find_visible_unit(i->first, current_team()) == units_.end()) {
|
||||
if (resources::gameboard->find_visible_unit(i->first, current_team()) == units_.end()) {
|
||||
move_result_ptr move_res = execute_move_action(i->second,i->first,true);
|
||||
if (!move_res->is_ok()) {
|
||||
return;
|
||||
|
@ -961,7 +962,7 @@ void get_villages_phase::execute()
|
|||
}
|
||||
|
||||
if(leader_move.second.valid()) {
|
||||
if((find_visible_unit(leader_move.first , current_team()) == units_.end())
|
||||
if((resources::gameboard->find_visible_unit(leader_move.first , current_team()) == units_.end())
|
||||
&& resources::game_map->is_village(leader_move.first)) {
|
||||
move_result_ptr move_res = execute_move_action(leader_move.second,leader_move.first,true);
|
||||
if (!move_res->is_ok()) {
|
||||
|
|
92
src/game_board.cpp
Normal file
92
src/game_board.cpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "config.hpp"
|
||||
#include "game_board.hpp"
|
||||
#include "unit.hpp"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
|
||||
void game_board::new_turn(int player_num) {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
if (i.side() == player_num) {
|
||||
i.new_turn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::end_turn(int player_num) {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
if (i.side() == player_num) {
|
||||
i.end_turn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::set_all_units_user_end_turn() {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
i.set_user_end_turn(true);
|
||||
}
|
||||
}
|
||||
|
||||
unit_map::iterator game_board::find_visible_unit(const map_location &loc,
|
||||
const team& current_team, bool see_all)
|
||||
{
|
||||
if (!map_.on_board(loc)) return units_.end();
|
||||
unit_map::iterator u = units_.find(loc);
|
||||
if (!u.valid() || !u->is_visible_to_team(current_team, see_all))
|
||||
return units_.end();
|
||||
return u;
|
||||
}
|
||||
|
||||
unit* game_board::get_visible_unit(const map_location &loc,
|
||||
const team ¤t_team, bool see_all)
|
||||
{
|
||||
unit_map::iterator ui = find_visible_unit(loc, current_team, see_all);
|
||||
if (ui == units_.end()) return NULL;
|
||||
return &*ui;
|
||||
}
|
||||
|
||||
void game_board::write_config(config & cfg) const {
|
||||
for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
|
||||
int side_num = t - teams_.begin() + 1;
|
||||
|
||||
config& side = cfg.add_child("side");
|
||||
t->write(side);
|
||||
side["no_leader"] = true;
|
||||
side["side"] = str_cast(side_num);
|
||||
|
||||
//current units
|
||||
{
|
||||
BOOST_FOREACH(const unit & i, units_) {
|
||||
if (i.side() == side_num) {
|
||||
config& u = side.add_child("unit");
|
||||
i.get_location().write(u);
|
||||
i.write(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
//recall list
|
||||
{
|
||||
BOOST_FOREACH(const unit & j, t->recall_list()) {
|
||||
config& u = side.add_child("unit");
|
||||
j.write(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//write the map
|
||||
cfg["map_data"] = map_.write();
|
||||
}
|
72
src/game_board.hpp
Normal file
72
src/game_board.hpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GAME_BOARD_HPP_INCLUDED
|
||||
#define GAME_BOARD_HPP_INCLUDED
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "map.hpp"
|
||||
#include "team.hpp"
|
||||
#include "unit_map.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class config;
|
||||
|
||||
namespace events {
|
||||
class mouse_handler;
|
||||
}
|
||||
|
||||
class game_board {
|
||||
|
||||
std::vector<team> teams_;
|
||||
|
||||
gamemap map_;
|
||||
unit_map units_;
|
||||
|
||||
//TODO: Remove these when we have refactored enough to make it possible.
|
||||
friend class play_controller;
|
||||
friend class replay_controller;
|
||||
friend class playsingle_controller;
|
||||
friend class playmp_controller;
|
||||
friend class events::mouse_handler;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors and const accessors
|
||||
|
||||
game_board(const config & game_config, const config & level) : teams_(), map_(game_config, level), units_() {}
|
||||
|
||||
const std::vector<team> & teams() const { return teams_; }
|
||||
const gamemap & map() const { return map_; }
|
||||
const unit_map & units() const { return units_; }
|
||||
|
||||
// Saving
|
||||
|
||||
void write_config(config & cfg) const;
|
||||
|
||||
// Manipulators from play_controller
|
||||
|
||||
void new_turn(int pnum);
|
||||
void end_turn(int pnum);
|
||||
void set_all_units_user_end_turn();
|
||||
|
||||
// Global accessor from unit.hpp
|
||||
|
||||
unit_map::iterator find_visible_unit(const map_location &loc, const team& current_team, bool see_all = false);
|
||||
unit* get_visible_unit(const map_location &loc, const team ¤t_team, bool see_all = false); //TODO: can this not return a pointer?
|
||||
};
|
||||
|
||||
#endif
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "game_board.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "wesconfig.h"
|
||||
|
@ -163,12 +164,12 @@ void game_display::highlight_hex(map_location hex)
|
|||
{
|
||||
wb::future_map future; /**< Lasts for whole method. */
|
||||
|
||||
const unit *u = get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_);
|
||||
const unit *u = resources::gameboard->get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_);
|
||||
if (u) {
|
||||
displayedUnitHex_ = hex;
|
||||
invalidate_unit();
|
||||
} else {
|
||||
u = get_visible_unit(mouseoverHex_, (*teams_)[viewing_team()], !viewpoint_);
|
||||
u = resources::gameboard->get_visible_unit(mouseoverHex_, (*teams_)[viewing_team()], !viewpoint_);
|
||||
if (u) {
|
||||
// mouse moved from unit hex to non-unit hex
|
||||
if (units_->count(selectedHex_)) {
|
||||
|
@ -190,7 +191,7 @@ void game_display::display_unit_hex(map_location hex)
|
|||
|
||||
wb::future_map future; /**< Lasts for whole method. */
|
||||
|
||||
const unit *u = get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_);
|
||||
const unit *u = resources::gameboard->get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_);
|
||||
if (u) {
|
||||
displayedUnitHex_ = hex;
|
||||
invalidate_unit();
|
||||
|
@ -277,7 +278,7 @@ void game_display::draw_hex(const map_location& loc)
|
|||
|
||||
if(on_map && loc == mouseoverHex_) {
|
||||
tdrawing_layer hex_top_layer = LAYER_MOUSEOVER_BOTTOM;
|
||||
const unit *u = get_visible_unit(loc, (*teams_)[viewing_team()] );
|
||||
const unit *u = resources::gameboard->get_visible_unit(loc, (*teams_)[viewing_team()] );
|
||||
if( u != NULL ) {
|
||||
hex_top_layer = LAYER_MOUSEOVER_TOP;
|
||||
}
|
||||
|
@ -459,8 +460,8 @@ void game_display::draw_movement_info(const map_location& loc)
|
|||
// When out-of-turn, it's still interesting to check out the terrain defs of the selected unit
|
||||
else if (selectedHex_.valid() && loc == mouseoverHex_)
|
||||
{
|
||||
const unit_map::const_iterator selectedUnit = find_visible_unit(selectedHex_,resources::teams->at(currentTeam_));
|
||||
const unit_map::const_iterator mouseoveredUnit = find_visible_unit(mouseoverHex_,resources::teams->at(currentTeam_));
|
||||
const unit_map::const_iterator selectedUnit = resources::gameboard->find_visible_unit(selectedHex_,resources::teams->at(currentTeam_));
|
||||
const unit_map::const_iterator mouseoveredUnit = resources::gameboard->find_visible_unit(mouseoverHex_,resources::teams->at(currentTeam_));
|
||||
if(selectedUnit != units_->end() && mouseoveredUnit == units_->end()) {
|
||||
// Display the def% of this terrain
|
||||
int def = 100 - selectedUnit->defense_modifier(get_map().get_terrain(loc));
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "game_board.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
|
@ -1043,22 +1044,22 @@ bool confirm_no_moves()
|
|||
}
|
||||
|
||||
|
||||
void encounter_recruitable_units(std::vector<team>& teams){
|
||||
for (std::vector<team>::iterator help_team_it = teams.begin();
|
||||
void encounter_recruitable_units(const std::vector<team>& teams){
|
||||
for (std::vector<team>::const_iterator help_team_it = teams.begin();
|
||||
help_team_it != teams.end(); ++help_team_it) {
|
||||
help_team_it->log_recruitable();
|
||||
encountered_units_set.insert(help_team_it->recruits().begin(), help_team_it->recruits().end());
|
||||
}
|
||||
}
|
||||
|
||||
void encounter_start_units(unit_map& units){
|
||||
void encounter_start_units(const unit_map& units){
|
||||
for (unit_map::const_iterator help_unit_it = units.begin();
|
||||
help_unit_it != units.end(); ++help_unit_it) {
|
||||
encountered_units_set.insert(help_unit_it->type_id());
|
||||
}
|
||||
}
|
||||
|
||||
void encounter_recallable_units(std::vector<team>& teams){
|
||||
void encounter_recallable_units(const std::vector<team>& teams){
|
||||
BOOST_FOREACH(const team& t, teams) {
|
||||
BOOST_FOREACH(const unit& u, t.recall_list()) {
|
||||
encountered_units_set.insert(u.type_id());
|
||||
|
@ -1066,7 +1067,7 @@ void encounter_recallable_units(std::vector<team>& teams){
|
|||
}
|
||||
}
|
||||
|
||||
void encounter_map_terrain(gamemap& map){
|
||||
void encounter_map_terrain(const gamemap& map){
|
||||
for (int map_x = 0; map_x < map.w(); ++map_x) {
|
||||
for (int map_y = 0; map_y < map.h(); ++map_y) {
|
||||
const t_translation::t_terrain t = map.get_terrain(map_location(map_x, map_y));
|
||||
|
@ -1079,6 +1080,13 @@ void encounter_map_terrain(gamemap& map){
|
|||
}
|
||||
}
|
||||
|
||||
void encounter_all_content(const game_board & gameboard_) {
|
||||
preferences::encounter_recruitable_units(gameboard_.teams());
|
||||
preferences::encounter_start_units(gameboard_.units());
|
||||
preferences::encounter_recallable_units(gameboard_.teams());
|
||||
preferences::encounter_map_terrain(gameboard_.map());
|
||||
}
|
||||
|
||||
void acquaintance::load_from_config(const config& cfg)
|
||||
{
|
||||
nick_ = cfg["nick"].str();
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#ifndef GAME_PREFERENCES_HPP_INCLUDED
|
||||
#define GAME_PREFERENCES_HPP_INCLUDED
|
||||
|
||||
class game_board;
|
||||
class gamemap;
|
||||
class game_state;
|
||||
class team;
|
||||
|
@ -260,15 +261,18 @@ class acquaintance;
|
|||
|
||||
// Add all recruitable units as encountered so that information
|
||||
// about them are displayed to the user in the help system.
|
||||
void encounter_recruitable_units(std::vector<team>& teams);
|
||||
void encounter_recruitable_units(const std::vector<team>& teams);
|
||||
// Add all units that exist at the start to the encountered units so
|
||||
// that information about them are displayed to the user in the help
|
||||
// system.
|
||||
void encounter_start_units(unit_map& units);
|
||||
void encounter_start_units(const unit_map& units);
|
||||
// Add all units that are recallable as encountered units.
|
||||
void encounter_recallable_units(std::vector<team>& teams);
|
||||
// Add all terrains on the map as encountered terrains.
|
||||
void encounter_map_terrain(gamemap& map);
|
||||
void encounter_map_terrain(const gamemap& map);
|
||||
|
||||
// Calls all of the above functions on the current game board
|
||||
void encounter_all_content(const game_board & gb);
|
||||
|
||||
class acquaintance {
|
||||
public:
|
||||
|
|
|
@ -930,12 +930,12 @@ unit_map::iterator menu_handler::current_unit()
|
|||
{
|
||||
const mouse_handler& mousehandler = resources::controller->get_mouse_handler_base();
|
||||
|
||||
unit_map::iterator res = find_visible_unit(mousehandler.get_last_hex(),
|
||||
unit_map::iterator res = resources::gameboard->find_visible_unit(mousehandler.get_last_hex(),
|
||||
teams_[gui_->viewing_team()]);
|
||||
if(res != units_.end()) {
|
||||
return res;
|
||||
} else {
|
||||
return find_visible_unit(mousehandler.get_selected_hex(),
|
||||
return resources::gameboard->find_visible_unit(mousehandler.get_selected_hex(),
|
||||
teams_[gui_->viewing_team()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,13 +53,10 @@ static lg::log_domain log_engine("engine");
|
|||
namespace events{
|
||||
|
||||
|
||||
mouse_handler::mouse_handler(game_display* gui, std::vector<team>& teams,
|
||||
unit_map& units, gamemap& map) :
|
||||
mouse_handler::mouse_handler(game_display* gui, game_board & board) :
|
||||
mouse_handler_base(),
|
||||
map_(map),
|
||||
gui_(gui),
|
||||
teams_(teams),
|
||||
units_(units),
|
||||
board_(board),
|
||||
previous_hex_(),
|
||||
previous_free_hex_(),
|
||||
selected_hex_(),
|
||||
|
@ -113,7 +110,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
// the hex of the selected unit is also "free"
|
||||
{ // start planned unit map scope
|
||||
wb::future_map_if_active raii;
|
||||
if (last_hex_ == selected_hex_ || find_unit(last_hex_) == units_.end()) {
|
||||
if (last_hex_ == selected_hex_ || find_unit(last_hex_) == board_.units_.end()) {
|
||||
previous_free_hex_ = last_hex_;
|
||||
}
|
||||
} // end planned unit map scope
|
||||
|
@ -131,7 +128,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
bool selected_hex_has_unit;
|
||||
{ // start planned unit map scope
|
||||
wb::future_map_if_active planned_unit_map;
|
||||
selected_hex_has_unit = find_unit(selected_hex_) != units_.end();
|
||||
selected_hex_has_unit = find_unit(selected_hex_) != board_.units_.end();
|
||||
} // end planned unit map scope
|
||||
if(selected_hex_.valid() && selected_hex_has_unit ) {
|
||||
// reselect the unit without firing events (updates current_paths_)
|
||||
|
@ -180,14 +177,14 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
//If the cursor is on WAIT, we don't change it and let the setter
|
||||
//of this state end it
|
||||
if (cursor::get() != cursor::WAIT) {
|
||||
if (selected_unit != units_.end() &&
|
||||
if (selected_unit != board_.units_.end() &&
|
||||
selected_unit->side() == side_num_ &&
|
||||
!selected_unit->incapacitated() && !browse)
|
||||
{
|
||||
if (attack_from.valid()) {
|
||||
cursor::set(dragging_started_ ? cursor::ATTACK_DRAG : cursor::ATTACK);
|
||||
}
|
||||
else if (mouseover_unit==units_.end() &&
|
||||
else if (mouseover_unit==board_.units_.end() &&
|
||||
current_paths_.destinations.contains(new_hex))
|
||||
{
|
||||
cursor::set(dragging_started_ ? cursor::MOVE_DRAG : cursor::MOVE);
|
||||
|
@ -198,7 +195,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
} else {
|
||||
// no selected unit or we can't move it
|
||||
|
||||
if ( selected_hex_.valid() && mouseover_unit != units_.end()
|
||||
if ( selected_hex_.valid() && mouseover_unit != board_.units_.end()
|
||||
&& mouseover_unit->side() == side_num_ ) {
|
||||
// empty hex field selected and unit on our site under the cursor
|
||||
cursor::set(dragging_started_ ? cursor::MOVE_DRAG : cursor::MOVE);
|
||||
|
@ -232,15 +229,15 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
dest_un = find_unit(new_hex);
|
||||
}
|
||||
|
||||
if(dest == selected_hex_ || dest_un != units_.end()) {
|
||||
if(dest == selected_hex_ || dest_un != board_.units_.end()) {
|
||||
current_route_.steps.clear();
|
||||
gui().set_route(NULL);
|
||||
resources::whiteboard->erase_temp_move();
|
||||
}
|
||||
else if (!current_paths_.destinations.empty() &&
|
||||
map_.on_board(selected_hex_) && map_.on_board(new_hex))
|
||||
board_.map().on_board(selected_hex_) && board_.map().on_board(new_hex))
|
||||
{
|
||||
if (selected_unit != units_.end() && !selected_unit->incapacitated()) {
|
||||
if (selected_unit != board_.units_.end() && !selected_unit->incapacitated()) {
|
||||
// Show the route from selected unit to mouseover hex
|
||||
current_route_ = get_route(&*selected_unit, dest, viewing_team());
|
||||
|
||||
|
@ -252,10 +249,10 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
}
|
||||
}
|
||||
|
||||
if(map_.on_board(selected_hex_)
|
||||
&& selected_unit == units_.end()
|
||||
if(board_.map().on_board(selected_hex_)
|
||||
&& selected_unit == board_.units_.end()
|
||||
&& mouseover_unit.valid()
|
||||
&& mouseover_unit != units_.end()) {
|
||||
&& mouseover_unit != board_.units_.end()) {
|
||||
// Show the route from selected hex to mouseover unit
|
||||
current_route_ = get_route(&*mouseover_unit, selected_hex_, viewing_team());
|
||||
|
||||
|
@ -264,14 +261,14 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
if(!browse) {
|
||||
gui().set_route(¤t_route_);
|
||||
}
|
||||
} else if (selected_unit == units_.end()) {
|
||||
} else if (selected_unit == board_.units_.end()) {
|
||||
current_route_.steps.clear();
|
||||
gui().set_route(NULL);
|
||||
resources::whiteboard->erase_temp_move();
|
||||
}
|
||||
|
||||
unit_map::iterator iter = mouseover_unit;
|
||||
if (iter != units_.end())
|
||||
if (iter != board_.units_.end())
|
||||
un = &*iter;
|
||||
else
|
||||
un = NULL;
|
||||
|
@ -283,7 +280,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
if (un->side() == side_num_) {
|
||||
//unit is on our team, show path if the unit has one
|
||||
const map_location go_to = un->get_goto();
|
||||
if(map_.on_board(go_to)) {
|
||||
if(board_.map().on_board(go_to)) {
|
||||
pathfind::marked_route route;
|
||||
{ // start planned unit map scope
|
||||
wb::future_map_if_active raii;
|
||||
|
@ -316,7 +313,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
|
|||
unit_map::iterator mouse_handler::selected_unit()
|
||||
{
|
||||
unit_map::iterator res = find_unit(selected_hex_);
|
||||
if(res != units_.end()) {
|
||||
if(res != board_.units_.end()) {
|
||||
return res;
|
||||
} else {
|
||||
return find_unit(last_hex_);
|
||||
|
@ -325,7 +322,7 @@ unit_map::iterator mouse_handler::selected_unit()
|
|||
|
||||
unit_map::iterator mouse_handler::find_unit(const map_location& hex)
|
||||
{
|
||||
unit_map::iterator it = find_visible_unit(hex, viewing_team());
|
||||
unit_map::iterator it = resources::gameboard->find_visible_unit(hex, viewing_team());
|
||||
if (it.valid())
|
||||
return it;
|
||||
else
|
||||
|
@ -334,7 +331,7 @@ unit_map::iterator mouse_handler::find_unit(const map_location& hex)
|
|||
|
||||
unit_map::const_iterator mouse_handler::find_unit(const map_location& hex) const
|
||||
{
|
||||
return find_visible_unit(hex, viewing_team());
|
||||
return resources::gameboard->find_visible_unit(hex, viewing_team());
|
||||
}
|
||||
|
||||
map_location mouse_handler::current_unit_attacks_from(const map_location& loc) const
|
||||
|
@ -349,7 +346,7 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
|
|||
|
||||
// Check that there's a selected unit
|
||||
const unit_map::const_iterator source_unit = find_unit(selected_hex_);
|
||||
bool source_eligible = (source_unit != units_.end());
|
||||
bool source_eligible = (source_unit != board_.units_.end());
|
||||
if (!source_eligible) return map_location();
|
||||
|
||||
// The selected unit must at least belong to the player currently controlling this client.
|
||||
|
@ -375,7 +372,7 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
|
|||
|
||||
// Check that there's a unit at the target location
|
||||
const unit_map::const_iterator target_unit = find_unit(loc);
|
||||
bool target_eligible = (target_unit != units_.end());
|
||||
bool target_eligible = (target_unit != board_.units_.end());
|
||||
if (!target_eligible) return map_location();
|
||||
|
||||
// The player controlling this client must be an enemy of the target unit's side
|
||||
|
@ -398,11 +395,11 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
|
|||
get_adjacent_tiles(loc,adj);
|
||||
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
if(map_.on_board(adj[n]) == false) {
|
||||
if(board_.map().on_board(adj[n]) == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(adj[n] != selected_hex_ && find_unit(adj[n]) != units_.end()) {
|
||||
if(adj[n] != selected_hex_ && find_unit(adj[n]) != board_.units_.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -431,13 +428,13 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
|
|||
pathfind::marked_route mouse_handler::get_route(const unit* un, map_location go_to, team &team) const
|
||||
{
|
||||
// The pathfinder will check unit visibility (fogged/stealthy).
|
||||
const pathfind::shortest_path_calculator calc(*un, team, teams_, map_);
|
||||
const pathfind::shortest_path_calculator calc(*un, team, board_.teams(), board_.map());
|
||||
|
||||
pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(*un, viewing_team());
|
||||
|
||||
pathfind::plain_route route;
|
||||
|
||||
route = pathfind::a_star_search(un->get_location(), go_to, 10000.0, &calc, map_.w(), map_.h(), &allowed_teleports);
|
||||
route = pathfind::a_star_search(un->get_location(), go_to, 10000.0, &calc, board_.map().w(), board_.map().h(), &allowed_teleports);
|
||||
|
||||
return mark_route(route);
|
||||
}
|
||||
|
@ -542,7 +539,7 @@ void mouse_handler::move_action(bool browse)
|
|||
|
||||
//if the unit is selected and then itself clicked on,
|
||||
//any goto command is canceled
|
||||
if (u != units_.end() && !browse && selected_hex_ == hex && u->side() == side_num_) {
|
||||
if (u != board_.units_.end() && !browse && selected_hex_ == hex && u->side() == side_num_) {
|
||||
u->set_goto(map_location());
|
||||
}
|
||||
|
||||
|
@ -595,7 +592,7 @@ void mouse_handler::move_action(bool browse)
|
|||
|
||||
// block where we temporary move the unit
|
||||
{
|
||||
temporary_unit_mover temp_mover(units_, src, attack_from,
|
||||
temporary_unit_mover temp_mover(board_.units_, src, attack_from,
|
||||
itor->move_left);
|
||||
choice = show_attack_dialog(attack_from, clicked_u->get_location());
|
||||
}
|
||||
|
@ -638,19 +635,19 @@ void mouse_handler::move_action(bool browse)
|
|||
// the old use case: move selected unit to mouse hex field
|
||||
( (!browse || resources::whiteboard->is_active()) &&
|
||||
selected_hex_.valid() && selected_hex_ != hex &&
|
||||
u != units_.end() && u.valid() &&
|
||||
u != board_.units_.end() && u.valid() &&
|
||||
(u->side() == side_num_ || resources::whiteboard->is_active()) &&
|
||||
clicked_u == units_.end() &&
|
||||
clicked_u == board_.units_.end() &&
|
||||
!current_route_.steps.empty() &&
|
||||
current_route_.steps.front() == selected_hex_
|
||||
)
|
||||
|| // the new use case: move mouse unit to selected hex field
|
||||
( (!browse || resources::whiteboard->is_active()) &&
|
||||
selected_hex_.valid() && selected_hex_ != hex &&
|
||||
clicked_u != units_.end() &&
|
||||
clicked_u != board_.units_.end() &&
|
||||
!current_route_.steps.empty() &&
|
||||
current_route_.steps.back() == selected_hex_
|
||||
&& u == units_.end()
|
||||
&& u == board_.units_.end()
|
||||
&& clicked_u->side() == side_num_
|
||||
)
|
||||
) {
|
||||
|
@ -678,7 +675,7 @@ void mouse_handler::move_action(bool browse)
|
|||
//Don't move if the unit already has actions
|
||||
//from the whiteboard.
|
||||
if (resources::whiteboard->unit_has_actions(
|
||||
u != units_.end() ? &*u : &*clicked_u )) {
|
||||
u != board_.units_.end() ? &*u : &*clicked_u )) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -707,7 +704,7 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
|
|||
|
||||
unit_map::iterator u = find_unit(selected_hex_);
|
||||
|
||||
if (selected_hex_.valid() && u != units_.end() && u.valid() && !u->get_hidden()) {
|
||||
if (selected_hex_.valid() && u != board_.units_.end() && u.valid() && !u->get_hidden()) {
|
||||
|
||||
next_unit_ = u->get_location();
|
||||
|
||||
|
@ -740,7 +737,7 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
|
|||
return;
|
||||
}
|
||||
|
||||
if (selected_hex_.valid() && u == units_.end()) {
|
||||
if (selected_hex_.valid() && u == board_.units_.end()) {
|
||||
// compute unit in range of the empty selected_hex field
|
||||
|
||||
gui_->unhighlight_reach();
|
||||
|
@ -750,14 +747,14 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
|
|||
pathfind::paths clicked_location;
|
||||
clicked_location.destinations.insert(hex);
|
||||
|
||||
for(unit_map::iterator u = units_.begin(); u != units_.end(); ++u) {
|
||||
for(unit_map::iterator u = board_.units_.begin(); u != board_.units_.end(); ++u) {
|
||||
bool invisible = u->invisible(u->get_location());
|
||||
|
||||
if (!gui_->fogged(u->get_location()) && !u->incapacitated() && !invisible)
|
||||
{
|
||||
|
||||
const pathfind::paths& path = pathfind::paths(*u, false, true,
|
||||
teams_[gui_->viewing_team()], path_turns_, false, false);
|
||||
board_.teams_[gui_->viewing_team()], path_turns_, false, false);
|
||||
|
||||
if (path.destinations.find(hex) != path.destinations.end()) {
|
||||
reaching_unit_locations.destinations.insert(u->get_location());
|
||||
|
@ -767,7 +764,7 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
|
|||
}
|
||||
gui_->highlight_another_reach(reaching_unit_locations);
|
||||
} else {
|
||||
if (units_.find(last_hex_) == units_.end())
|
||||
if (board_.units_.find(last_hex_) == board_.units_.end())
|
||||
gui_->unhighlight_reach();
|
||||
current_paths_ = pathfind::paths();
|
||||
current_route_.steps.clear();
|
||||
|
@ -848,9 +845,9 @@ size_t mouse_handler::move_unit_along_route(const std::vector<map_location> & st
|
|||
//since otherwise it may cause planned recruits to be erased.
|
||||
if ( resources::game_map->is_keep(steps.front()) )
|
||||
{
|
||||
unit_map::const_iterator const u = units_.find(steps.front());
|
||||
unit_map::const_iterator const u = board_.units().find(steps.front());
|
||||
|
||||
if ( u != units_.end() && u->can_recruit() &&
|
||||
if ( u != board_.units().end() && u->can_recruit() &&
|
||||
u->side() == gui().viewing_side() &&
|
||||
!resources::whiteboard->allow_leader_to_move(*u) )
|
||||
{
|
||||
|
@ -939,9 +936,9 @@ int mouse_handler::fill_weapon_choices(std::vector<battle_context>& bc_vector, u
|
|||
int mouse_handler::show_attack_dialog(const map_location& attacker_loc, const map_location& defender_loc)
|
||||
{
|
||||
|
||||
unit_map::iterator attacker = units_.find(attacker_loc);
|
||||
unit_map::iterator defender = units_.find(defender_loc);
|
||||
if(attacker == units_.end() || defender == units_.end()) {
|
||||
unit_map::iterator attacker = board_.units_.find(attacker_loc);
|
||||
unit_map::iterator defender = board_.units_.find(defender_loc);
|
||||
if(attacker == board_.units_.end() || defender == board_.units_.end()) {
|
||||
ERR_NG << "One fighter is missing, can't attack";
|
||||
return -1; // abort, click will do nothing
|
||||
}
|
||||
|
@ -1097,13 +1094,13 @@ void mouse_handler::attack_enemy_(const map_location& att_loc
|
|||
resources::undo_stack->clear();
|
||||
|
||||
unit_map::iterator attacker = find_unit(attacker_loc);
|
||||
if(attacker == units_.end()
|
||||
if(attacker == board_.units_.end()
|
||||
|| attacker->side() != side_num_
|
||||
|| attacker->incapacitated())
|
||||
return;
|
||||
|
||||
unit_map::iterator defender = find_unit(defender_loc);
|
||||
if(defender == units_.end()
|
||||
if(defender == board_.units_.end()
|
||||
|| current_team().is_enemy(defender->side()) == false
|
||||
|| defender->incapacitated())
|
||||
return;
|
||||
|
@ -1143,13 +1140,13 @@ std::set<map_location> mouse_handler::get_adj_enemies(const map_location& loc, i
|
|||
{
|
||||
std::set<map_location> res;
|
||||
|
||||
const team& uteam = teams_[side-1];
|
||||
const team& uteam = board_.teams_[side-1];
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
BOOST_FOREACH(const map_location &aloc, adj) {
|
||||
unit_map::const_iterator i = find_unit(aloc);
|
||||
if (i != units_.end() && uteam.is_enemy(i->side()))
|
||||
if (i != board_.units().end() && uteam.is_enemy(i->side()))
|
||||
res.insert(aloc);
|
||||
}
|
||||
return res;
|
||||
|
@ -1169,7 +1166,7 @@ void mouse_handler::show_attack_options(const unit_map::const_iterator &u)
|
|||
|
||||
// Get the teams involved.
|
||||
const team & cur_team = current_team();
|
||||
const team & u_team = teams_[u->side()-1];
|
||||
const team & u_team = board_.teams_[u->side()-1];
|
||||
|
||||
// Check each adjacent hex.
|
||||
map_location adj[6];
|
||||
|
@ -1178,9 +1175,9 @@ void mouse_handler::show_attack_options(const unit_map::const_iterator &u)
|
|||
{
|
||||
// No attack option shown if no visible unit present.
|
||||
// (Visible to current team, not necessarily the unit's team.)
|
||||
if (!map_.on_board(loc)) continue;
|
||||
unit_map::const_iterator i = units_.find(loc);
|
||||
if ( i == units_.end() || !i->is_visible_to_team(cur_team) )
|
||||
if (!board_.map().on_board(loc)) continue;
|
||||
unit_map::const_iterator i = board_.units().find(loc);
|
||||
if ( i == board_.units().end() || !i->is_visible_to_team(cur_team) )
|
||||
continue;
|
||||
const unit &target = *i;
|
||||
// Can only attack non-petrified enemies.
|
||||
|
@ -1191,7 +1188,7 @@ void mouse_handler::show_attack_options(const unit_map::const_iterator &u)
|
|||
|
||||
bool mouse_handler::unit_in_cycle(unit_map::const_iterator it)
|
||||
{
|
||||
if (it == units_.end())
|
||||
if (it == board_.units().end())
|
||||
return false;
|
||||
|
||||
if (it->side() != side_num_ || it->user_end_turn()
|
||||
|
@ -1211,23 +1208,23 @@ bool mouse_handler::unit_in_cycle(unit_map::const_iterator it)
|
|||
|
||||
void mouse_handler::cycle_units(const bool browse, const bool reverse)
|
||||
{
|
||||
if (units_.begin() == units_.end()) {
|
||||
if (board_.units().begin() == board_.units().end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
unit_map::const_iterator it = find_unit(next_unit_);
|
||||
if (it == units_.end())
|
||||
it = units_.begin();
|
||||
if (it == board_.units().end())
|
||||
it = board_.units().begin();
|
||||
const unit_map::const_iterator itx = it;
|
||||
|
||||
do {
|
||||
if (reverse) {
|
||||
if (it == units_.begin())
|
||||
it = units_.end();
|
||||
if (it == board_.units().begin())
|
||||
it = board_.units().end();
|
||||
--it;
|
||||
} else {
|
||||
if (it == units_.end())
|
||||
it = units_.begin();
|
||||
if (it == board_.units().end())
|
||||
it = board_.units().begin();
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
@ -1248,5 +1245,17 @@ void mouse_handler::set_current_paths(const pathfind::paths & new_paths) {
|
|||
resources::whiteboard->erase_temp_move();
|
||||
}
|
||||
|
||||
team & mouse_handler::viewing_team() {
|
||||
return board_.teams_[gui().viewing_team()];
|
||||
}
|
||||
|
||||
const team& mouse_handler::viewing_team() const {
|
||||
return board_.teams()[gui().viewing_team()];
|
||||
}
|
||||
|
||||
team & mouse_handler::current_team() {
|
||||
return board_.teams_[side_num_ - 1];
|
||||
}
|
||||
|
||||
mouse_handler *mouse_handler::singleton_ = NULL;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace events{
|
|||
|
||||
class mouse_handler : public mouse_handler_base {
|
||||
public:
|
||||
mouse_handler(game_display* gui, std::vector<team>& teams, unit_map& units, gamemap& map);
|
||||
mouse_handler(game_display* gui, game_board & board);
|
||||
~mouse_handler();
|
||||
static mouse_handler* get_singleton() { return singleton_ ;}
|
||||
void set_side(int side_number);
|
||||
|
@ -92,10 +92,6 @@ protected:
|
|||
/** Const version */
|
||||
const game_display& gui() const { return *gui_; }
|
||||
|
||||
team& viewing_team() { return teams_[gui().viewing_team()]; }
|
||||
const team& viewing_team() const { return teams_[gui().viewing_team()]; }
|
||||
team ¤t_team() { return teams_[side_num_ - 1]; }
|
||||
|
||||
int drag_threshold() const;
|
||||
/**
|
||||
* Use update to force an update of the mouse state.
|
||||
|
@ -121,10 +117,12 @@ protected:
|
|||
unit_map::iterator find_unit(const map_location& hex);
|
||||
bool unit_in_cycle(unit_map::const_iterator it);
|
||||
private:
|
||||
gamemap& map_;
|
||||
team& viewing_team();
|
||||
const team& viewing_team() const;
|
||||
team ¤t_team();
|
||||
|
||||
game_display* gui_;
|
||||
std::vector<team>& teams_;
|
||||
unit_map& units_;
|
||||
game_board & board_;
|
||||
|
||||
// previous highlighted hexes
|
||||
// the hex of the selected unit and empty hex are "free"
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "pathfind/pathfind.hpp"
|
||||
#include "pathfind/teleport.hpp"
|
||||
|
||||
#include "game_board.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "log.hpp"
|
||||
|
@ -140,7 +141,7 @@ bool enemy_zoc(team const ¤t_team, map_location const &loc,
|
|||
get_adjacent_tiles(loc,locs);
|
||||
for (int i = 0; i != 6; ++i)
|
||||
{
|
||||
const unit *u = get_visible_unit(locs[i], viewing_team, see_all);
|
||||
const unit *u = resources::gameboard->get_visible_unit(locs[i], viewing_team, see_all);
|
||||
if ( u && current_team.is_enemy(u->side()) && u->emits_zoc() )
|
||||
return true;
|
||||
}
|
||||
|
@ -388,7 +389,7 @@ static void find_routes(
|
|||
|
||||
if ( current_team ) {
|
||||
// Account for enemy units.
|
||||
const unit *v = get_visible_unit(next_hex, *viewing_team, see_all);
|
||||
const unit *v = resources::gameboard->get_visible_unit(next_hex, *viewing_team, see_all);
|
||||
if ( v && current_team->is_enemy(v->side()) ) {
|
||||
// Cannot enter enemy hexes.
|
||||
if ( edges != NULL )
|
||||
|
@ -719,7 +720,7 @@ double shortest_path_calculator::cost(const map_location& loc, const double so_f
|
|||
int other_unit_subcost = 0;
|
||||
if (!ignore_unit_) {
|
||||
const unit *other_unit =
|
||||
get_visible_unit(loc, viewing_team_, see_all_);
|
||||
resources::gameboard->get_visible_unit(loc, viewing_team_, see_all_);
|
||||
|
||||
// We can't traverse visible enemy and we also prefer empty hexes
|
||||
// (less blocking in multi-turn moves and better when exploring fog,
|
||||
|
|
|
@ -72,6 +72,7 @@ static lg::log_domain log_enginerefac("enginerefac");
|
|||
static void clear_resources()
|
||||
{
|
||||
resources::controller = NULL;
|
||||
resources::gameboard = NULL;
|
||||
resources::gamedata = NULL;
|
||||
resources::game_map = NULL;
|
||||
resources::persist = NULL;
|
||||
|
@ -101,8 +102,8 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
|
|||
halo_manager_(),
|
||||
labels_manager_(),
|
||||
help_manager_(&game_config),
|
||||
mouse_handler_(NULL, teams_, units_, map_),
|
||||
menu_handler_(NULL, units_, teams_, level, map_, game_config, state_of_game),
|
||||
mouse_handler_(NULL, gameboard_),
|
||||
menu_handler_(NULL, gameboard_.units_, gameboard_.teams_, level, gameboard_.map_, game_config, state_of_game),
|
||||
soundsources_manager_(),
|
||||
tod_manager_(level),
|
||||
pathfind_manager_(),
|
||||
|
@ -110,11 +111,9 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
|
|||
gui_(),
|
||||
statistics_context_(level["name"]),
|
||||
level_(level),
|
||||
teams_(),
|
||||
gamestate_(state_of_game),
|
||||
gamedata_(level),
|
||||
map_(game_config, level),
|
||||
units_(),
|
||||
gameboard_(game_config, level),
|
||||
undo_stack_(new actions::undo_list(level.child("undo_stack"))),
|
||||
whiteboard_manager_(),
|
||||
xp_mod_(level["experience_modifier"].to_int(100)),
|
||||
|
@ -137,14 +136,15 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
|
|||
scope_()
|
||||
{
|
||||
resources::controller = this;
|
||||
resources::gameboard = &gameboard_;
|
||||
resources::gamedata = &gamedata_;
|
||||
resources::game_map = &map_;
|
||||
resources::game_map = &gameboard_.map_;
|
||||
resources::persist = &persist_;
|
||||
resources::state_of_game = &gamestate_;
|
||||
resources::teams = &teams_;
|
||||
resources::teams = &gameboard_.teams_;
|
||||
resources::tod_manager = &tod_manager_;
|
||||
resources::undo_stack = undo_stack_.get();
|
||||
resources::units = &units_;
|
||||
resources::units = &gameboard_.units_;
|
||||
|
||||
persist_.start_transaction();
|
||||
|
||||
|
@ -223,7 +223,7 @@ void play_controller::init(CVideo& video){
|
|||
}
|
||||
}
|
||||
team_builder_ptr tb_ptr = gamedata_.create_team_builder(side,
|
||||
save_id, teams_, level_, map_, units_, snapshot, gamestate_.replay_start());
|
||||
save_id, gameboard_.teams_, level_, gameboard_.map_, gameboard_.units_, snapshot, gamestate_.replay_start());
|
||||
++team_num;
|
||||
gamedata_.build_team_stage_one(tb_ptr);
|
||||
team_builders.push_back(tb_ptr);
|
||||
|
@ -241,15 +241,11 @@ void play_controller::init(CVideo& video){
|
|||
}
|
||||
|
||||
// mouse_handler expects at least one team for linger mode to work.
|
||||
if (teams_.empty()) end_level_data_.transient.linger_mode = false;
|
||||
if (gameboard_.teams_.empty()) end_level_data_.transient.linger_mode = false;
|
||||
|
||||
LOG_NG << "loading units..." << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
loadscreen::start_stage("load units");
|
||||
preferences::encounter_recruitable_units(teams_);
|
||||
preferences::encounter_start_units(units_);
|
||||
preferences::encounter_recallable_units(teams_);
|
||||
preferences::encounter_map_terrain(map_);
|
||||
|
||||
preferences::encounter_all_content(gameboard_);
|
||||
|
||||
LOG_NG << "initializing theme... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
loadscreen::start_stage("init theme");
|
||||
|
@ -257,7 +253,7 @@ void play_controller::init(CVideo& video){
|
|||
|
||||
LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
loadscreen::start_stage("build terrain");
|
||||
gui_.reset(new game_display(units_, video, map_, tod_manager_, teams_, theme_cfg, level_));
|
||||
gui_.reset(new game_display(gameboard_.units_, video, gameboard_.map_, tod_manager_, gameboard_.teams_, theme_cfg, level_));
|
||||
if (!gui_->video().faked()) {
|
||||
if (gamestate_.mp_settings().mp_countdown)
|
||||
gui_->get_theme().modify_label("time-icon", _ ("time left for current turn"));
|
||||
|
@ -281,9 +277,9 @@ void play_controller::init(CVideo& video){
|
|||
// If not set here observer would be without fog until
|
||||
// the first turn of observable side
|
||||
size_t i;
|
||||
for (i=0;i < teams_.size();++i)
|
||||
for (i=0;i < gameboard_.teams_.size();++i)
|
||||
{
|
||||
if (!teams_[i].get_disallow_observers())
|
||||
if (!gameboard_.teams_[i].get_disallow_observers())
|
||||
{
|
||||
gui_->set_team(i);
|
||||
}
|
||||
|
@ -366,14 +362,14 @@ void play_controller::place_sides_in_preferred_locations()
|
|||
{
|
||||
std::vector<placing_info> placings;
|
||||
|
||||
int num_pos = map_.num_valid_starting_positions();
|
||||
int num_pos = gameboard_.map_.num_valid_starting_positions();
|
||||
|
||||
int side_num = 1;
|
||||
BOOST_FOREACH(const config &side, level_.child_range("side"))
|
||||
{
|
||||
for(int p = 1; p <= num_pos; ++p) {
|
||||
const map_location& pos = map_.starting_position(p);
|
||||
int score = placing_score(side, map_, pos);
|
||||
const map_location& pos = gameboard_.map_.starting_position(p);
|
||||
int score = placing_score(side, gameboard_.map_, pos);
|
||||
placing_info obj;
|
||||
obj.side = side_num;
|
||||
obj.score = score;
|
||||
|
@ -391,7 +387,7 @@ void play_controller::place_sides_in_preferred_locations()
|
|||
if(placed.count(i->side) == 0 && positions_taken.count(i->pos) == 0) {
|
||||
placed.insert(i->side);
|
||||
positions_taken.insert(i->pos);
|
||||
map_.set_starting_position(i->side,i->pos);
|
||||
gameboard_.map_.set_starting_position(i->side,i->pos);
|
||||
LOG_NG << "placing side " << i->side << " at " << i->pos << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -605,7 +601,7 @@ void play_controller::init_gui(){
|
|||
gui_->update_tod();
|
||||
|
||||
if ( !loading_game_ ) {
|
||||
for ( int side = teams_.size(); side != 0; --side )
|
||||
for ( int side = gameboard_.teams_.size(); side != 0; --side )
|
||||
actions::clear_shroud(side, false, false);
|
||||
}
|
||||
}
|
||||
|
@ -689,12 +685,7 @@ void play_controller::do_init_side(bool is_replay, bool only_visual) {
|
|||
// Healing/income happen if it's not the first turn of processing,
|
||||
// or if we are loading a game.
|
||||
if (!only_visual && turn() > 1) {
|
||||
for(unit_map::iterator i = units_.begin(); i != units_.end(); ++i) {
|
||||
if (i->side() == player_number_) {
|
||||
i->new_turn();
|
||||
}
|
||||
}
|
||||
|
||||
gameboard_.new_turn(player_number_);
|
||||
current_team().new_turn();
|
||||
|
||||
// If the expense is less than the number of villages owned
|
||||
|
@ -732,7 +723,7 @@ void play_controller::do_init_side(bool is_replay, bool only_visual) {
|
|||
}
|
||||
|
||||
if (!recorder.is_skipping() && !skip_replay_ && current_team().get_scroll_to_leader()){
|
||||
gui_->scroll_to_leader(units_, player_number_,game_display::ONSCREEN,false);
|
||||
gui_->scroll_to_leader(gameboard_.units_, player_number_,game_display::ONSCREEN,false);
|
||||
}
|
||||
loading_game_ = false;
|
||||
|
||||
|
@ -748,33 +739,7 @@ config play_controller::to_config() const
|
|||
cfg["init_side_done"] = init_side_done_;
|
||||
cfg.merge_attributes(level_);
|
||||
|
||||
for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
|
||||
int side_num = t - teams_.begin() + 1;
|
||||
|
||||
config& side = cfg.add_child("side");
|
||||
t->write(side);
|
||||
side["no_leader"] = true;
|
||||
side["side"] = str_cast(side_num);
|
||||
|
||||
{
|
||||
//current visible units
|
||||
for(unit_map::const_iterator i = units_.begin(); i != units_.end(); ++i) {
|
||||
if (i->side() == side_num) {
|
||||
config& u = side.add_child("unit");
|
||||
i->get_location().write(u);
|
||||
i->write(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
//recall list
|
||||
{
|
||||
for(std::vector<unit>::const_iterator j = t->recall_list().begin();
|
||||
j != t->recall_list().end(); ++j) {
|
||||
config& u = side.add_child("unit");
|
||||
j->write(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
gameboard_.write_config(cfg);
|
||||
|
||||
cfg.merge_with(tod_manager_.to_config());
|
||||
|
||||
|
@ -790,7 +755,6 @@ config play_controller::to_config() const
|
|||
}
|
||||
|
||||
//write out the current state of the map
|
||||
cfg["map_data"] = map_.write();
|
||||
cfg.merge_with(pathfind_manager_->to_config());
|
||||
|
||||
config display;
|
||||
|
@ -807,9 +771,10 @@ void play_controller::finish_side_turn(){
|
|||
|
||||
resources::whiteboard->on_finish_side_turn(player_number_);
|
||||
|
||||
for(unit_map::iterator uit = units_.begin(); uit != units_.end(); ++uit) {
|
||||
if (uit->side() == player_number_)
|
||||
uit->end_turn();
|
||||
BOOST_FOREACH(unit & uit, gameboard_.units_) {
|
||||
if (uit.side() == player_number_) {
|
||||
uit.end_turn();
|
||||
}
|
||||
}
|
||||
// Clear shroud, in case units had been slowed for the turn.
|
||||
actions::clear_shroud(player_number_);
|
||||
|
@ -854,9 +819,11 @@ bool play_controller::enemies_visible() const
|
|||
return true;
|
||||
|
||||
// See if any enemies are visible
|
||||
for(unit_map::const_iterator u = units_.begin(); u != units_.end(); ++u)
|
||||
if (current_team().is_enemy(u->side()) && !gui_->fogged(u->get_location()))
|
||||
BOOST_FOREACH(const unit & u, gameboard_.units_) {
|
||||
if (current_team().is_enemy(u.side()) && !gui_->fogged(u.get_location())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -960,17 +927,17 @@ bool play_controller::can_execute_command(const hotkey::hotkey_command& cmd, int
|
|||
return !linger_ && undo_stack_->can_undo() && !events::commands_disabled && !browse_;
|
||||
|
||||
case hotkey::HOTKEY_UNIT_DESCRIPTION:
|
||||
return menu_handler_.current_unit() != units_.end();
|
||||
return menu_handler_.current_unit() != gameboard_.units_.end();
|
||||
|
||||
case hotkey::HOTKEY_TERRAIN_DESCRIPTION:
|
||||
return mouse_handler_.get_last_hex().valid();
|
||||
|
||||
case hotkey::HOTKEY_RENAME_UNIT:
|
||||
return !events::commands_disabled &&
|
||||
menu_handler_.current_unit() != units_.end() &&
|
||||
menu_handler_.current_unit() != gameboard_.units_.end() &&
|
||||
!(menu_handler_.current_unit()->unrenamable()) &&
|
||||
menu_handler_.current_unit()->side() == gui_->viewing_side() &&
|
||||
teams_[menu_handler_.current_unit()->side() - 1].is_human();
|
||||
gameboard_.teams_[menu_handler_.current_unit()->side() - 1].is_human();
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
@ -1019,10 +986,10 @@ void play_controller::tab()
|
|||
switch(mode) {
|
||||
case gui::TEXTBOX_SEARCH:
|
||||
{
|
||||
BOOST_FOREACH(const unit &u, units_){
|
||||
BOOST_FOREACH(const unit &u, gameboard_.units_){
|
||||
const map_location& loc = u.get_location();
|
||||
if(!gui_->fogged(loc) &&
|
||||
!(teams_[gui_->viewing_team()].is_enemy(u.side()) && u.invisible(loc)))
|
||||
!(gameboard_.teams_[gui_->viewing_team()].is_enemy(u.side()) && u.invisible(loc)))
|
||||
dictionary.insert(u.name());
|
||||
}
|
||||
//TODO List map labels
|
||||
|
@ -1036,7 +1003,7 @@ void play_controller::tab()
|
|||
}
|
||||
case gui::TEXTBOX_MESSAGE:
|
||||
{
|
||||
BOOST_FOREACH(const team& t, teams_) {
|
||||
BOOST_FOREACH(const team& t, gameboard_.teams_) {
|
||||
if(!t.is_empty())
|
||||
dictionary.insert(t.current_player());
|
||||
}
|
||||
|
@ -1081,29 +1048,29 @@ std::string play_controller::get_unique_saveid(const config& cfg, std::set<std::
|
|||
|
||||
team& play_controller::current_team()
|
||||
{
|
||||
assert(player_number_ > 0 && player_number_ <= int(teams_.size()));
|
||||
return teams_[player_number_-1];
|
||||
assert(player_number_ > 0 && player_number_ <= int(gameboard_.teams_.size()));
|
||||
return gameboard_.teams_[player_number_-1];
|
||||
}
|
||||
|
||||
const team& play_controller::current_team() const
|
||||
{
|
||||
assert(player_number_ > 0 && player_number_ <= int(teams_.size()));
|
||||
return teams_[player_number_-1];
|
||||
assert(player_number_ > 0 && player_number_ <= int(gameboard_.teams_.size()));
|
||||
return gameboard_.teams_[player_number_-1];
|
||||
}
|
||||
|
||||
int play_controller::find_human_team_before_current_player() const
|
||||
{
|
||||
if (player_number_ > int(teams_.size()))
|
||||
if (player_number_ > int(gameboard_.teams_.size()))
|
||||
return -2;
|
||||
|
||||
for (int i = player_number_-2; i >= 0; --i) {
|
||||
if (teams_[i].is_human()) {
|
||||
if (gameboard_.teams_[i].is_human()) {
|
||||
return i+1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = teams_.size()-1; i > player_number_-1; --i) {
|
||||
if (teams_[i].is_human()) {
|
||||
for (int i = gameboard_.teams_.size()-1; i > player_number_-1; --i) {
|
||||
if (gameboard_.teams_[i].is_human()) {
|
||||
return i+1;
|
||||
}
|
||||
}
|
||||
|
@ -1157,12 +1124,12 @@ void play_controller::process_keyup_event(const SDL_Event& event) {
|
|||
|
||||
const unit_map::iterator u = mouse_handler_.selected_unit();
|
||||
|
||||
if(u != units_.end()) {
|
||||
if(u != gameboard_.units_.end()) {
|
||||
// if it's not the unit's turn, we reset its moves
|
||||
unit_movement_resetter move_reset(*u, u->side() != player_number_);
|
||||
|
||||
mouse_handler_.set_current_paths(pathfind::paths(*u, false,
|
||||
true, teams_[gui_->viewing_team()],
|
||||
true, gameboard_.teams_[gui_->viewing_team()],
|
||||
mouse_handler_.get_path_turns()));
|
||||
|
||||
gui_->highlight_reach(mouse_handler_.current_paths());
|
||||
|
@ -1267,7 +1234,7 @@ void play_controller::show_menu(const std::vector<std::string>& items_arg, int x
|
|||
// Remove WML commands if they would not be allowed here
|
||||
if(*i == "wml") {
|
||||
if(!context_menu || gui_->viewing_team() != gui_->playing_team()
|
||||
|| events::commands_disabled || !teams_[gui_->viewing_team()].is_human()
|
||||
|| events::commands_disabled || !gameboard_.teams_[gui_->viewing_team()].is_human()
|
||||
|| (linger_ && !game_config::debug)){
|
||||
i = items.erase(i);
|
||||
continue;
|
||||
|
@ -1310,13 +1277,13 @@ bool play_controller::in_context_menu(hotkey::HOTKEY_COMMAND command) const
|
|||
|
||||
wb::future_map future; /* lasts until method returns. */
|
||||
|
||||
unit_map::const_iterator leader = units_.find(last_hex);
|
||||
if ( leader != units_.end() )
|
||||
unit_map::const_iterator leader = gameboard_.units_.find(last_hex);
|
||||
if ( leader != gameboard_.units_.end() )
|
||||
return leader->can_recruit() && leader->side() == viewing_side &&
|
||||
can_recruit_from(*leader);
|
||||
else
|
||||
// Look for a leader who can recruit on last_hex.
|
||||
for ( leader = units_.begin(); leader != units_.end(); ++leader) {
|
||||
for ( leader = gameboard_.units_.begin(); leader != gameboard_.units_.end(); ++leader) {
|
||||
if ( leader->can_recruit() && leader->side() == viewing_side &&
|
||||
can_recruit_on(*leader, last_hex) )
|
||||
return true;
|
||||
|
@ -1357,7 +1324,7 @@ hotkey::ACTION_STATE play_controller::get_action_state(hotkey::HOTKEY_COMMAND co
|
|||
case hotkey::HOTKEY_ZOOM_DEFAULT:
|
||||
return (gui_->get_zoom_factor() == 1.0) ? hotkey::ACTION_ON : hotkey::ACTION_OFF;
|
||||
case hotkey::HOTKEY_DELAY_SHROUD:
|
||||
return teams_[gui_->viewing_team()].auto_shroud_updates() ? hotkey::ACTION_OFF : hotkey::ACTION_ON;
|
||||
return gameboard_.teams_[gui_->viewing_team()].auto_shroud_updates() ? hotkey::ACTION_OFF : hotkey::ACTION_ON;
|
||||
default:
|
||||
return hotkey::ACTION_STATELESS;
|
||||
}
|
||||
|
@ -1404,20 +1371,17 @@ void play_controller::check_victory()
|
|||
}
|
||||
std::set<unsigned> not_defeated;
|
||||
|
||||
for (unit_map::const_iterator i = units_.begin(),
|
||||
i_end = units_.end(); i != i_end; ++i)
|
||||
BOOST_FOREACH( const unit & i , gameboard_.units_)
|
||||
{
|
||||
const team& tm = teams_[i->side()-1];
|
||||
if (i->can_recruit() && tm.defeat_condition() == team::NO_LEADER) {
|
||||
//DBG_NG << "seen leader for side " << i->side() << "\n";
|
||||
not_defeated.insert(i->side());
|
||||
const team& tm = gameboard_.teams_[i.side()-1];
|
||||
if (i.can_recruit() && tm.defeat_condition() == team::NO_LEADER) {
|
||||
not_defeated.insert(i.side());
|
||||
} else if (tm.defeat_condition() == team::NO_UNITS) {
|
||||
//DBG_NG << "side doesn't require leader " << i->side() << "\n";
|
||||
not_defeated.insert(i->side());
|
||||
not_defeated.insert(i.side());
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FOREACH(team& tm, this->teams_)
|
||||
BOOST_FOREACH(team& tm, gameboard_.teams_)
|
||||
{
|
||||
if(tm.defeat_condition() == team::NEVER)
|
||||
{
|
||||
|
@ -1449,16 +1413,16 @@ void play_controller::check_victory()
|
|||
|
||||
std::set<unsigned>::iterator m(n);
|
||||
for (++m; m != not_defeated.end(); ++m) {
|
||||
if (teams_[side].is_enemy(*m)) {
|
||||
if (gameboard_.teams_[side].is_enemy(*m)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (teams_[side].is_human()) {
|
||||
if (gameboard_.teams_[side].is_human()) {
|
||||
found_player = true;
|
||||
}
|
||||
|
||||
if (teams_[side].is_network()) {
|
||||
if (gameboard_.teams_[side].is_network()) {
|
||||
found_network_player = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "controller_base.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "game_board.hpp"
|
||||
#include "help.hpp"
|
||||
#include "menu_events.hpp"
|
||||
#include "mouse_events.hpp"
|
||||
|
@ -67,6 +68,7 @@ namespace wb {
|
|||
class manager; // whiteboard manager
|
||||
} // namespace wb
|
||||
|
||||
|
||||
class play_controller : public controller_base, public events::observer, public savegame::savegame_config
|
||||
{
|
||||
public:
|
||||
|
@ -136,10 +138,10 @@ public:
|
|||
return end_level_data_;
|
||||
}
|
||||
const std::vector<team>& get_teams_const() const {
|
||||
return teams_;
|
||||
return gameboard_.teams_;
|
||||
}
|
||||
const gamemap& get_map_const() const{
|
||||
return map_;
|
||||
return gameboard_.map_;
|
||||
}
|
||||
const tod_manager& get_tod_manager_const() const{
|
||||
return tod_manager_;
|
||||
|
@ -229,11 +231,9 @@ protected:
|
|||
boost::scoped_ptr<game_display> gui_;
|
||||
const statistics::scenario_context statistics_context_;
|
||||
const config& level_;
|
||||
std::vector<team> teams_;
|
||||
game_state& gamestate_;
|
||||
game_data gamedata_;
|
||||
gamemap map_;
|
||||
unit_map units_;
|
||||
game_board gameboard_;
|
||||
/// undo_stack_ is never NULL. It is implemented as a pointer so that
|
||||
/// undo_list can be an incomplete type at this point (which reduces the
|
||||
/// number of files that depend on actions/undo.hpp).
|
||||
|
|
|
@ -313,9 +313,7 @@ void playmp_controller::linger()
|
|||
// stay stuck in linger state when the *next* scenario is over.
|
||||
set_completion setter(gamestate_,"running");
|
||||
// End all unit moves
|
||||
BOOST_FOREACH(unit &u, units_) {
|
||||
u.set_user_end_turn(true);
|
||||
}
|
||||
gameboard_.set_all_units_user_end_turn();
|
||||
//current_team().set_countdown_time(0);
|
||||
//halt and cancel the countdown timer
|
||||
reset_countdown();
|
||||
|
|
|
@ -100,9 +100,9 @@ void playsingle_controller::init_gui(){
|
|||
play_controller::init_gui();
|
||||
|
||||
if(first_human_team_ != -1) {
|
||||
gui_->scroll_to_tile(map_.starting_position(first_human_team_ + 1), game_display::WARP);
|
||||
gui_->scroll_to_tile(gameboard_.map_.starting_position(first_human_team_ + 1), game_display::WARP);
|
||||
}
|
||||
gui_->scroll_to_tile(map_.starting_position(1), game_display::WARP);
|
||||
gui_->scroll_to_tile(gameboard_.map_.starting_position(1), game_display::WARP);
|
||||
|
||||
update_locker lock_display(gui_->video(),recorder.is_skipping());
|
||||
events::raise_draw_event();
|
||||
|
@ -157,7 +157,7 @@ void playsingle_controller::check_end_level()
|
|||
{
|
||||
if (level_result_ == NONE || linger_)
|
||||
{
|
||||
team &t = teams_[gui_->viewing_team()];
|
||||
team &t = gameboard_.teams_[gui_->viewing_team()];
|
||||
if (!browse_ && t.objectives_changed()) {
|
||||
dialogs::show_objectives(level_, t.objectives());
|
||||
t.reset_objectives_changed();
|
||||
|
@ -431,7 +431,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
|
|||
|
||||
// Initialize countdown clock.
|
||||
std::vector<team>::iterator t;
|
||||
for(t = teams_.begin(); t != teams_.end(); ++t) {
|
||||
for(t = gameboard_.teams_.begin(); t != gameboard_.teams_.end(); ++t) {
|
||||
if (gamestate_.mp_settings().mp_countdown && !loading_game_ ){
|
||||
t->set_countdown_time(1000 * gamestate_.mp_settings().mp_countdown_init_time);
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
|
|||
}
|
||||
}
|
||||
|
||||
if (teams_.empty())
|
||||
if (gameboard_.teams_.empty())
|
||||
{
|
||||
//store persistent teams
|
||||
gamestate_.snapshot = config();
|
||||
|
@ -552,13 +552,12 @@ LEVEL_RESULT playsingle_controller::play_scenario(
|
|||
|
||||
// Add all the units that survived the scenario.
|
||||
LOG_NG << "Add units that survived the scenario to the recall list.\n";
|
||||
for(unit_map::iterator un = units_.begin(); un != units_.end(); ++un) {
|
||||
|
||||
if (teams_[un->side() - 1].persistent()) {
|
||||
LOG_NG << "Added unit " << un->id() << ", " << un->name() << "\n";
|
||||
un->new_turn();
|
||||
un->new_scenario();
|
||||
teams_[un->side() - 1].recall_list().push_back(*un);
|
||||
BOOST_FOREACH (unit & un, gameboard_.units_) {
|
||||
if (gameboard_.teams_[un.side() - 1].persistent()) {
|
||||
LOG_NG << "Added unit " << un.id() << ", " << un.name() << "\n";
|
||||
un.new_turn();
|
||||
un.new_scenario();
|
||||
gameboard_.teams_[un.side() - 1].recall_list().push_back(un);
|
||||
}
|
||||
}
|
||||
gamestate_.snapshot = config();
|
||||
|
@ -611,7 +610,7 @@ void playsingle_controller::play_turn()
|
|||
LOG_AIT << "Turn " << turn() << ":" << std::endl;
|
||||
}
|
||||
|
||||
for (player_number_ = first_player_; player_number_ <= int(teams_.size()); ++player_number_)
|
||||
for (player_number_ = first_player_; player_number_ <= int(gameboard_.teams_.size()); ++player_number_)
|
||||
{
|
||||
// If a side is empty skip over it.
|
||||
if (current_team().is_empty()) continue;
|
||||
|
@ -652,8 +651,8 @@ void playsingle_controller::play_turn()
|
|||
}
|
||||
//If the loop exits due to the last team having been processed,
|
||||
//player_number_ will be 1 too high
|
||||
if(player_number_ > static_cast<int>(teams_.size()))
|
||||
player_number_ = teams_.size();
|
||||
if(player_number_ > static_cast<int>(gameboard_.teams_.size()))
|
||||
player_number_ = gameboard_.teams_.size();
|
||||
|
||||
finish_turn();
|
||||
|
||||
|
@ -685,7 +684,7 @@ void playsingle_controller::play_side()
|
|||
if (!skip_next_turn_)
|
||||
end_turn_ = false;
|
||||
|
||||
statistics::reset_turn_stats(teams_[player_number_ - 1].save_id());
|
||||
statistics::reset_turn_stats(gameboard_.teams_[player_number_ - 1].save_id());
|
||||
|
||||
if(current_team().is_human() || temporary_human) {
|
||||
LOG_NG << "is human...\n";
|
||||
|
@ -704,7 +703,7 @@ void playsingle_controller::play_side()
|
|||
player_type_changed_ = true;
|
||||
// If new controller is not human,
|
||||
// reset gui to prev human one
|
||||
if (!teams_[player_number_-1].is_human()) {
|
||||
if (!gameboard_.teams_[player_number_-1].is_human()) {
|
||||
browse_ = true;
|
||||
int s = find_human_team_before_current_player();
|
||||
if (s <= 0)
|
||||
|
@ -747,7 +746,7 @@ void playsingle_controller::play_side()
|
|||
player_type_changed_ = true;
|
||||
// If new controller is not human,
|
||||
// reset gui to prev human one
|
||||
if (!teams_[player_number_-1].is_human()) {
|
||||
if (!gameboard_.teams_[player_number_-1].is_human()) {
|
||||
browse_ = true;
|
||||
int s = find_human_team_before_current_player();
|
||||
if (s <= 0)
|
||||
|
@ -790,7 +789,7 @@ void playsingle_controller::show_turn_dialog(){
|
|||
resources::screen->redraw_everything();
|
||||
std::string message = _("It is now $name|’s turn");
|
||||
utils::string_map symbols;
|
||||
symbols["name"] = teams_[player_number_ - 1].current_player();
|
||||
symbols["name"] = gameboard_.teams_[player_number_ - 1].current_player();
|
||||
message = utils::interpolate_variables_into_string(message, &symbols);
|
||||
gui2::show_transient_message(gui_->video(), "", message);
|
||||
}
|
||||
|
@ -833,9 +832,7 @@ void playsingle_controller::linger()
|
|||
gui_->redraw_everything();
|
||||
|
||||
// End all unit moves
|
||||
for (unit_map::iterator u = units_.begin(); u != units_.end(); ++u) {
|
||||
u->set_user_end_turn(true);
|
||||
}
|
||||
gameboard_.set_all_units_user_end_turn();
|
||||
try {
|
||||
// Same logic as single-player human turn, but
|
||||
// *not* the same as multiplayer human turn.
|
||||
|
@ -991,7 +988,7 @@ bool playsingle_controller::can_execute_command(const hotkey::hotkey_command& cm
|
|||
|
||||
case hotkey::HOTKEY_WML:
|
||||
//code mixed from play_controller::show_menu and code here
|
||||
return (gui_->viewing_team() == gui_->playing_team()) && !events::commands_disabled && teams_[gui_->viewing_team()].is_human() && !linger_ && !browse_;
|
||||
return (gui_->viewing_team() == gui_->playing_team()) && !events::commands_disabled && gameboard_.teams_[gui_->viewing_team()].is_human() && !linger_ && !browse_;
|
||||
case hotkey::HOTKEY_UNIT_HOLD_POSITION:
|
||||
case hotkey::HOTKEY_END_UNIT_TURN:
|
||||
return !browse_ && !linger_ && !events::commands_disabled;
|
||||
|
@ -1003,19 +1000,19 @@ bool playsingle_controller::can_execute_command(const hotkey::hotkey_command& cm
|
|||
return (!browse_ || linger_) && !events::commands_disabled;
|
||||
|
||||
case hotkey::HOTKEY_DELAY_SHROUD:
|
||||
return !linger_ && (teams_[gui_->viewing_team()].uses_fog() || teams_[gui_->viewing_team()].uses_shroud())
|
||||
return !linger_ && (gameboard_.teams_[gui_->viewing_team()].uses_fog() || gameboard_.teams_[gui_->viewing_team()].uses_shroud())
|
||||
&& !events::commands_disabled;
|
||||
case hotkey::HOTKEY_UPDATE_SHROUD:
|
||||
return !linger_
|
||||
&& player_number_ == gui_->viewing_side()
|
||||
&& !events::commands_disabled
|
||||
&& teams_[gui_->viewing_team()].auto_shroud_updates() == false;
|
||||
&& gameboard_.teams_[gui_->viewing_team()].auto_shroud_updates() == false;
|
||||
|
||||
// Commands we can only do if in debug mode
|
||||
case hotkey::HOTKEY_CREATE_UNIT:
|
||||
case hotkey::HOTKEY_CHANGE_SIDE:
|
||||
case hotkey::HOTKEY_KILL_UNIT:
|
||||
return !events::commands_disabled && game_config::debug && map_.on_board(mouse_handler_.get_last_hex());
|
||||
return !events::commands_disabled && game_config::debug && gameboard_.map_.on_board(mouse_handler_.get_last_hex());
|
||||
|
||||
case hotkey::HOTKEY_CLEAR_LABELS:
|
||||
res = !is_observer();
|
||||
|
@ -1023,7 +1020,7 @@ bool playsingle_controller::can_execute_command(const hotkey::hotkey_command& cm
|
|||
case hotkey::HOTKEY_LABEL_TEAM_TERRAIN:
|
||||
case hotkey::HOTKEY_LABEL_TERRAIN: {
|
||||
const terrain_label *label = resources::screen->labels().get_label(mouse_handler_.get_last_hex());
|
||||
res = !events::commands_disabled && map_.on_board(mouse_handler_.get_last_hex())
|
||||
res = !events::commands_disabled && gameboard_.map_.on_board(mouse_handler_.get_last_hex())
|
||||
&& !gui_->shrouded(mouse_handler_.get_last_hex())
|
||||
&& !is_observer()
|
||||
&& (!label || !label->immutable());
|
||||
|
@ -1033,11 +1030,11 @@ bool playsingle_controller::can_execute_command(const hotkey::hotkey_command& cm
|
|||
if(browse_ || events::commands_disabled)
|
||||
return false;
|
||||
|
||||
if( (menu_handler_.current_unit() != units_.end())
|
||||
if( (menu_handler_.current_unit() != gameboard_.units_.end())
|
||||
&& (menu_handler_.current_unit()->move_interrupted()))
|
||||
return true;
|
||||
const unit_map::const_iterator i = units_.find(mouse_handler_.get_selected_hex());
|
||||
if (i == units_.end()) return false;
|
||||
const unit_map::const_iterator i = gameboard_.units_.find(mouse_handler_.get_selected_hex());
|
||||
if (i == gameboard_.units_.end()) return false;
|
||||
return i->move_interrupted();
|
||||
}
|
||||
case hotkey::HOTKEY_WB_TOGGLE:
|
||||
|
|
|
@ -76,9 +76,8 @@ replay_controller::replay_controller(const config& level,
|
|||
game_state& state_of_game, const int ticks,
|
||||
const config& game_config, CVideo& video) :
|
||||
play_controller(level, state_of_game, ticks, game_config, video, false),
|
||||
teams_start_(teams_),
|
||||
gamestate_start_(gamestate_),
|
||||
units_start_(units_),
|
||||
gameboard_start_(gameboard_),
|
||||
tod_manager_start_(level),
|
||||
current_turn_(1),
|
||||
is_playing_(false),
|
||||
|
@ -122,10 +121,10 @@ void replay_controller::init_gui(){
|
|||
else
|
||||
gui_->set_team(0, show_everything_);
|
||||
|
||||
gui_->scroll_to_leader(units_, player_number_, display::WARP);
|
||||
gui_->scroll_to_leader(gameboard_.units_, player_number_, display::WARP);
|
||||
update_locker lock_display((*gui_).video(),false);
|
||||
for(std::vector<team>::iterator t = teams_.begin(); t != teams_.end(); ++t) {
|
||||
t->reset_objectives_changed();
|
||||
BOOST_FOREACH(team & t, gameboard_.teams_) {
|
||||
t.reset_objectives_changed();
|
||||
}
|
||||
|
||||
update_replay_ui();
|
||||
|
@ -272,9 +271,8 @@ void replay_controller::reset_replay()
|
|||
tod_manager_= tod_manager_start_;
|
||||
recorder.start_replay();
|
||||
recorder.set_skip(false);
|
||||
units_ = units_start_;
|
||||
gamestate_ = gamestate_start_;
|
||||
teams_ = teams_start_;
|
||||
gameboard_ = gameboard_start_;
|
||||
if (events_manager_ ){
|
||||
// NOTE: this double reset is required so that the new
|
||||
// instance of game_events::manager isn't created before the
|
||||
|
@ -332,7 +330,7 @@ void replay_controller::replay_next_turn(){
|
|||
play_turn();
|
||||
|
||||
if (!skip_replay_ || !is_playing_){
|
||||
gui_->scroll_to_leader(units_, player_number_,game_display::ONSCREEN,false);
|
||||
gui_->scroll_to_leader(gameboard_.units_, player_number_,game_display::ONSCREEN,false);
|
||||
}
|
||||
|
||||
replay_ui_playback_should_stop();
|
||||
|
@ -348,7 +346,7 @@ void replay_controller::replay_next_side(){
|
|||
}
|
||||
|
||||
if (!skip_replay_ || !is_playing_) {
|
||||
gui_->scroll_to_leader(units_, player_number_,game_display::ONSCREEN,false);
|
||||
gui_->scroll_to_leader(gameboard_.units_, player_number_,game_display::ONSCREEN,false);
|
||||
}
|
||||
|
||||
replay_ui_playback_should_stop();
|
||||
|
@ -416,7 +414,7 @@ void replay_controller::play_replay(){
|
|||
}
|
||||
|
||||
if (!is_playing_) {
|
||||
gui_->scroll_to_leader(units_, player_number_,game_display::ONSCREEN,false);
|
||||
gui_->scroll_to_leader(gameboard_.units_, player_number_,game_display::ONSCREEN,false);
|
||||
}
|
||||
}
|
||||
catch(end_level_exception& e){
|
||||
|
@ -438,7 +436,7 @@ void replay_controller::play_turn(){
|
|||
bool last_team = false;
|
||||
|
||||
while ( (!last_team) && (!recorder.at_end()) && is_playing_ ){
|
||||
last_team = static_cast<size_t>(player_number_) == teams_.size();
|
||||
last_team = static_cast<size_t>(player_number_) == gameboard_.teams_.size();
|
||||
play_side();
|
||||
play_slice();
|
||||
}
|
||||
|
@ -470,9 +468,9 @@ void replay_controller::play_side(){
|
|||
|
||||
player_number_++;
|
||||
|
||||
if (static_cast<size_t>(player_number_) > teams_.size()) {
|
||||
//during the orginal game player_number_ would also be teams_.size(),
|
||||
player_number_ = teams_.size();
|
||||
if (static_cast<size_t>(player_number_) > gameboard_.teams_.size()) {
|
||||
//during the orginal game player_number_ would also be gameboard_.teams_.size(),
|
||||
player_number_ = gameboard_.teams_.size();
|
||||
finish_turn();
|
||||
tod_manager_.next_turn();
|
||||
it_is_a_new_turn_ = true;
|
||||
|
@ -482,11 +480,7 @@ void replay_controller::play_side(){
|
|||
}
|
||||
|
||||
// This is necessary for replays in order to show possible movements.
|
||||
BOOST_FOREACH(unit &u, units_) {
|
||||
if (u.side() == player_number_) {
|
||||
u.new_turn();
|
||||
}
|
||||
}
|
||||
gameboard_.new_turn(player_number_);
|
||||
|
||||
update_teams();
|
||||
update_gui();
|
||||
|
@ -500,7 +494,7 @@ void replay_controller::play_side(){
|
|||
void replay_controller::update_teams(){
|
||||
|
||||
int next_team = player_number_;
|
||||
if(static_cast<size_t>(next_team) > teams_.size()) {
|
||||
if(static_cast<size_t>(next_team) > gameboard_.teams_.size()) {
|
||||
next_team = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,6 @@ public:
|
|||
virtual void check_end_level() {}
|
||||
virtual void on_not_observer() {}
|
||||
|
||||
std::vector<team> teams_start_;
|
||||
|
||||
bool manage_noninteractively();
|
||||
|
||||
protected:
|
||||
|
@ -87,7 +85,7 @@ private:
|
|||
}
|
||||
|
||||
game_state gamestate_start_;
|
||||
unit_map units_start_;
|
||||
game_board gameboard_start_;
|
||||
tod_manager tod_manager_start_;
|
||||
|
||||
unsigned int current_turn_;
|
||||
|
|
|
@ -119,20 +119,24 @@ struct report_generator_helper
|
|||
|
||||
static char const *naps = "</span>";
|
||||
|
||||
namespace reports {
|
||||
|
||||
static const unit *get_visible_unit()
|
||||
{
|
||||
return get_visible_unit(resources::screen->displayed_unit_hex(),
|
||||
return resources::gameboard->get_visible_unit(resources::screen->displayed_unit_hex(),
|
||||
(*resources::teams)[resources::screen->viewing_team()],
|
||||
resources::screen->show_everything());
|
||||
}
|
||||
|
||||
static const unit *get_selected_unit()
|
||||
{
|
||||
return get_visible_unit(resources::screen->selected_hex(),
|
||||
return resources::gameboard->get_visible_unit(resources::screen->selected_hex(),
|
||||
(*resources::teams)[resources::screen->viewing_team()],
|
||||
resources::screen->show_everything());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static config gray_inactive(const std::string &str)
|
||||
{
|
||||
if ( (resources::screen &&
|
||||
|
@ -162,12 +166,12 @@ static config unit_name(const unit *u)
|
|||
|
||||
REPORT_GENERATOR(unit_name)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_name(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_name)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_name(u);
|
||||
}
|
||||
|
||||
|
@ -183,12 +187,12 @@ static config unit_type(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_type)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_type(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_type)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_type(u);
|
||||
}
|
||||
|
||||
|
@ -202,12 +206,12 @@ static config unit_race(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_race)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_race(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_race)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_race(u);
|
||||
}
|
||||
|
||||
|
@ -233,12 +237,12 @@ static config unit_side(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_side)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_side(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_side)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_side(u);
|
||||
}
|
||||
|
||||
|
@ -258,18 +262,18 @@ static config unit_level(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_level)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_level(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_level)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_level(u);
|
||||
}
|
||||
|
||||
REPORT_GENERATOR(unit_amla)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
if (!u) return report();
|
||||
config res;
|
||||
typedef std::pair<std::string, std::string> pair_string;
|
||||
|
@ -300,12 +304,12 @@ static config unit_traits(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_traits)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_traits(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_traits)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_traits(u);
|
||||
}
|
||||
|
||||
|
@ -334,12 +338,12 @@ static config unit_status(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_status)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_status(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_status)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_status(u);
|
||||
}
|
||||
|
||||
|
@ -366,12 +370,12 @@ static config unit_alignment(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_alignment)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_alignment(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_alignment)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_alignment(u);
|
||||
}
|
||||
|
||||
|
@ -411,12 +415,12 @@ static config unit_abilities(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_abilities)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_abilities(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_abilities)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_abilities(u);
|
||||
}
|
||||
|
||||
|
@ -465,12 +469,12 @@ static config unit_hp(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_hp)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_hp(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_hp)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_hp(u);
|
||||
}
|
||||
|
||||
|
@ -487,12 +491,12 @@ static config unit_xp(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_xp)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_xp(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_xp)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_xp(u);
|
||||
}
|
||||
|
||||
|
@ -508,12 +512,12 @@ static config unit_advancement_options(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_advancement_options)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_advancement_options(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_advancement_options)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_advancement_options(u);
|
||||
}
|
||||
|
||||
|
@ -560,13 +564,13 @@ static config unit_defense(const unit* u, const map_location& displayed_unit_hex
|
|||
}
|
||||
REPORT_GENERATOR(unit_defense)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
const map_location& displayed_unit_hex = resources::screen->displayed_unit_hex();
|
||||
return unit_defense(u, displayed_unit_hex);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_defense)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
const map_location& selected_hex = resources::screen->selected_hex();
|
||||
return unit_defense(u, selected_hex);
|
||||
}
|
||||
|
@ -583,12 +587,12 @@ static config unit_vision(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_vision)
|
||||
{
|
||||
const unit* u = get_visible_unit();
|
||||
const unit* u = reports::get_visible_unit();
|
||||
return unit_vision(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_vision)
|
||||
{
|
||||
const unit* u = get_selected_unit();
|
||||
const unit* u = reports::get_selected_unit();
|
||||
return unit_vision(u);
|
||||
}
|
||||
|
||||
|
@ -650,12 +654,12 @@ static config unit_moves(const unit* u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_moves)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
return unit_moves(u);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_moves)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
return unit_moves(u);
|
||||
}
|
||||
|
||||
|
@ -1011,15 +1015,15 @@ static config unit_weapons(const unit *u)
|
|||
}
|
||||
REPORT_GENERATOR(unit_weapons)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
if (!u) return config();
|
||||
|
||||
return unit_weapons(u);
|
||||
}
|
||||
REPORT_GENERATOR(highlighted_unit_weapons)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *sec_u = get_visible_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
const unit *sec_u = reports::get_visible_unit();
|
||||
|
||||
if (!u) return config();
|
||||
if (!sec_u || u == sec_u) return unit_weapons(sec_u);
|
||||
|
@ -1035,8 +1039,8 @@ REPORT_GENERATOR(highlighted_unit_weapons)
|
|||
}
|
||||
REPORT_GENERATOR(selected_unit_weapons)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *sec_u = get_visible_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
const unit *sec_u = reports::get_visible_unit();
|
||||
|
||||
if (!u) return config();
|
||||
if (!sec_u || u == sec_u) return unit_weapons(u);
|
||||
|
@ -1053,26 +1057,26 @@ REPORT_GENERATOR(selected_unit_weapons)
|
|||
|
||||
REPORT_GENERATOR(unit_image)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
if (!u) return report();
|
||||
return image_report(u->absolute_image() + u->image_mods());
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_image)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
if (!u) return report();
|
||||
return image_report(u->absolute_image() + u->image_mods());
|
||||
}
|
||||
|
||||
REPORT_GENERATOR(selected_unit_profile)
|
||||
{
|
||||
const unit *u = get_selected_unit();
|
||||
const unit *u = reports::get_selected_unit();
|
||||
if (!u) return report();
|
||||
return image_report(u->small_profile());
|
||||
}
|
||||
REPORT_GENERATOR(unit_profile)
|
||||
{
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
if (!u) return report();
|
||||
return image_report(u->small_profile());
|
||||
}
|
||||
|
@ -1219,7 +1223,7 @@ static config unit_box_at(const map_location& mouseover_hex)
|
|||
|
||||
bg_terrain_image = bg_terrain_image + "~CS(" + color.str() + ")";
|
||||
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
std::string unit_image;
|
||||
if (u)
|
||||
unit_image = "~BLIT(" + u->absolute_image() + u->image_mods() + ",35,22)";
|
||||
|
@ -1462,7 +1466,7 @@ REPORT_GENERATOR(position)
|
|||
std::ostringstream str;
|
||||
str << mouseover_hex;
|
||||
|
||||
const unit *u = get_visible_unit();
|
||||
const unit *u = reports::get_visible_unit();
|
||||
const team &viewing_team = (*resources::teams)[resources::screen->viewing_team()];
|
||||
if (!u ||
|
||||
(displayed_unit_hex != mouseover_hex &&
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
namespace resources
|
||||
{
|
||||
game_board *gameboard = NULL;
|
||||
game_config_manager *config_manager = NULL;
|
||||
play_controller *controller = NULL;
|
||||
game_data *gamedata = NULL;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
class game_board;
|
||||
class game_config_manager;
|
||||
class game_display;
|
||||
class gamemap;
|
||||
|
@ -41,6 +42,7 @@ namespace resources
|
|||
{
|
||||
extern game_config_manager *config_manager;
|
||||
extern play_controller *controller;
|
||||
extern game_board *gameboard;
|
||||
extern game_data *gamedata;
|
||||
extern gamemap *game_map;
|
||||
extern LuaKernel *lua_kernel; // Set by game_events::manager.
|
||||
|
|
|
@ -779,7 +779,7 @@ static int intf_get_unit(lua_State *L)
|
|||
*/
|
||||
static int intf_get_displayed_unit(lua_State *L)
|
||||
{
|
||||
unit_map::const_iterator ui = find_visible_unit(
|
||||
unit_map::const_iterator ui = resources::gameboard->find_visible_unit(
|
||||
resources::screen->displayed_unit_hex(),
|
||||
(*resources::teams)[resources::screen->viewing_team()],
|
||||
resources::screen->show_everything());
|
||||
|
|
|
@ -263,7 +263,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(move, child, use_undo, show, error_handler)
|
|||
}
|
||||
|
||||
// The nominal destination should appear to be unoccupied.
|
||||
unit_map::iterator u = find_visible_unit(dst, current_team);
|
||||
unit_map::iterator u = resources::gameboard->find_visible_unit(dst, current_team);
|
||||
if ( u.valid() ) {
|
||||
WRN_REPLAY << "Warning: Move destination " << dst << " appears occupied." << std::endl;
|
||||
// We'll still proceed with this movement, though, since
|
||||
|
|
|
@ -823,7 +823,7 @@ std::string team::get_side_highlight_pango(int side)
|
|||
return rgb2highlight_pango(get_side_color_range(side+1).mid());
|
||||
}
|
||||
|
||||
void team::log_recruitable(){
|
||||
void team::log_recruitable() const {
|
||||
LOG_NG << "Adding recruitable units: \n";
|
||||
for (std::set<std::string>::const_iterator it = info_.can_recruit.begin();
|
||||
it != info_.can_recruit.end(); ++it) {
|
||||
|
|
|
@ -308,7 +308,7 @@ public:
|
|||
static std::string get_side_highlight(int side);
|
||||
static std::string get_side_highlight_pango(int side);
|
||||
|
||||
void log_recruitable();
|
||||
void log_recruitable() const;
|
||||
|
||||
/**set the share maps attribute */
|
||||
void set_share_maps( bool share_maps );
|
||||
|
|
20
src/unit.cpp
20
src/unit.cpp
|
@ -3022,26 +3022,6 @@ int side_upkeep(int side)
|
|||
return res;
|
||||
}
|
||||
|
||||
unit_map::iterator find_visible_unit(const map_location &loc,
|
||||
const team& current_team, bool see_all)
|
||||
{
|
||||
unit_map& units = *resources::units;
|
||||
if (!resources::game_map->on_board(loc)) return units.end();
|
||||
unit_map::iterator u = units.find(loc);
|
||||
if (!u.valid() || !u->is_visible_to_team(current_team, see_all))
|
||||
return units.end();
|
||||
return u;
|
||||
}
|
||||
|
||||
unit *get_visible_unit(const map_location &loc,
|
||||
const team ¤t_team, bool see_all)
|
||||
{
|
||||
unit_map::iterator ui = find_visible_unit(loc,
|
||||
current_team, see_all);
|
||||
if (ui == resources::units->end()) return NULL;
|
||||
return &*ui;
|
||||
}
|
||||
|
||||
void unit::refresh()
|
||||
{
|
||||
if (state_ == STATE_FORGET && anim_ && anim_->animation_finished_potential())
|
||||
|
|
|
@ -577,12 +577,6 @@ int side_units_cost(int side_num);
|
|||
|
||||
int side_upkeep(int side_num);
|
||||
|
||||
unit_map::iterator find_visible_unit(const map_location &loc,
|
||||
const team ¤t_team, bool see_all = false);
|
||||
|
||||
unit *get_visible_unit(const map_location &loc,
|
||||
const team ¤t_team, bool see_all = false);
|
||||
|
||||
struct team_data
|
||||
{
|
||||
team_data() :
|
||||
|
|
|
@ -459,7 +459,7 @@ action::error move::check_validity() const
|
|||
}
|
||||
|
||||
//If the path has at least two hexes (it can have less with the attack subclass), ensure destination hex is free
|
||||
if(get_route().steps.size() >= 2 && get_visible_unit(get_dest_hex(),resources::teams->at(viewer_team())) != NULL) {
|
||||
if(get_route().steps.size() >= 2 && resources::gameboard->get_visible_unit(get_dest_hex(),resources::teams->at(viewer_team())) != NULL) {
|
||||
return LOCATION_OCCUPIED;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ unit* future_visible_unit(map_location hex, int viewer_side)
|
|||
return NULL;
|
||||
}
|
||||
//use global method get_visible_unit
|
||||
return get_visible_unit(hex, resources::teams->at(viewer_side - 1), false);
|
||||
return resources::gameboard->get_visible_unit(hex, resources::teams->at(viewer_side - 1), false);
|
||||
}
|
||||
|
||||
unit* future_visible_unit(int on_side, map_location hex, int viewer_side)
|
||||
|
|
Loading…
Add table
Reference in a new issue