Skip to content

Commit

Permalink
move code managing preference encounters out of play controller
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 1, 2014
1 parent 2afe4f4 commit 8b6339a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
18 changes: 13 additions & 5 deletions src/game_preferences.cpp
Expand Up @@ -16,6 +16,7 @@

#define GETTEXT_DOMAIN "wesnoth-lib"

#include "game_board.hpp"
#include "game_display.hpp"
#include "game_preferences.hpp"
#include "gamestatus.hpp"
Expand Down Expand Up @@ -1043,30 +1044,30 @@ 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());
}
}
}

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));
Expand All @@ -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();
Expand Down
10 changes: 7 additions & 3 deletions src/game_preferences.hpp
Expand Up @@ -14,6 +14,7 @@
#ifndef GAME_PREFERENCES_HPP_INCLUDED
#define GAME_PREFERENCES_HPP_INCLUDED

struct game_board;
class gamemap;
class game_state;
class team;
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions src/play_controller.cpp
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/team.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/team.hpp
Expand Up @@ -308,7 +308,7 @@ class team : public savegame::savegame_config
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 );
Expand Down

0 comments on commit 8b6339a

Please sign in to comment.