From 8b6339af9be0ba12c86f3a2b17c4b93e483b1d66 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Sun, 1 Jun 2014 08:41:32 -0400 Subject: [PATCH] move code managing preference encounters out of play controller --- src/game_preferences.cpp | 18 +++++++++++++----- src/game_preferences.hpp | 10 +++++++--- src/play_controller.cpp | 6 +----- src/team.cpp | 2 +- src/team.hpp | 2 +- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/game_preferences.cpp b/src/game_preferences.cpp index 36736cbe970..e4c2f1beb2a 100644 --- a/src/game_preferences.cpp +++ b/src/game_preferences.cpp @@ -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& teams){ - for (std::vector::iterator help_team_it = teams.begin(); +void encounter_recruitable_units(const std::vector& teams){ + for (std::vector::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& teams){ +void encounter_recallable_units(const std::vector& 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& 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(); diff --git a/src/game_preferences.hpp b/src/game_preferences.hpp index ee8b29e0fc4..a56e3a4a13b 100644 --- a/src/game_preferences.hpp +++ b/src/game_preferences.hpp @@ -14,6 +14,7 @@ #ifndef GAME_PREFERENCES_HPP_INCLUDED #define GAME_PREFERENCES_HPP_INCLUDED +struct 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& teams); + void encounter_recruitable_units(const std::vector& 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& 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: diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 3f6e426d2c4..ef073dfce0e 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -240,11 +240,7 @@ void play_controller::init(CVideo& video){ LOG_NG << "loading units..." << (SDL_GetTicks() - ticks_) << std::endl; loadscreen::start_stage("load units"); - preferences::encounter_recruitable_units(gameboard_.teams_); - preferences::encounter_start_units(gameboard_.units_); - preferences::encounter_recallable_units(gameboard_.teams_); - preferences::encounter_map_terrain(gameboard_.map_); - + preferences::encounter_all_content(gameboard_); LOG_NG << "initializing theme... " << (SDL_GetTicks() - ticks_) << std::endl; loadscreen::start_stage("init theme"); diff --git a/src/team.cpp b/src/team.cpp index 2043a98edd1..51623daee7b 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -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::const_iterator it = info_.can_recruit.begin(); it != info_.can_recruit.end(); ++it) { diff --git a/src/team.hpp b/src/team.hpp index 1922ab6e45e..d10d68f68df 100644 --- a/src/team.hpp +++ b/src/team.hpp @@ -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 );