Skip to content

Commit

Permalink
add gamemap argument to tod_manager::add_time_area(config &c)
Browse files Browse the repository at this point in the history
This is needed to properly parse a list of locations from strings,
to have the dimensions available.

This allows to refactor tod_manager and not use resources:: ptrs
in its implementation, instead using the objects from the relevant
context.
  • Loading branch information
cbeck88 committed Jun 13, 2014
1 parent fe00d72 commit 8531dde
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/editor/map/map_context.cpp
Expand Up @@ -281,7 +281,7 @@ void map_context::load_scenario(const config& game_config)

tod_manager_.reset(new tod_manager(scenario));
BOOST_FOREACH(const config &time_area, scenario.child_range("time_area")) {
tod_manager_->add_time_area(time_area);
tod_manager_->add_time_area(map_,time_area);
}

BOOST_FOREACH(const config& item, scenario.child_range("item")) {
Expand Down
2 changes: 1 addition & 1 deletion src/play_controller.cpp
Expand Up @@ -195,7 +195,7 @@ void play_controller::init(CVideo& video){
}

BOOST_FOREACH(const config &t, level_.child_range("time_area")) {
tod_manager_.add_time_area(t);
tod_manager_.add_time_area(gameboard_.map(),t);
}

LOG_NG << "initialized teams... " << (SDL_GetTicks() - ticks_) << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions src/tod_manager.cpp
Expand Up @@ -13,18 +13,18 @@
*/

#include "tod_manager.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"

#include "display_context.hpp"
#include "formula_string_utils.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "map.hpp"
#include "play_controller.hpp"
#include "random_new.hpp"
#include "resources.hpp"
#include "unit.hpp"
#include "unit_abilities.hpp"
#include "wml_exception.hpp"

#include <boost/foreach.hpp>
#include <boost/range/adaptors.hpp>
Expand Down Expand Up @@ -316,15 +316,15 @@ const std::set<map_location>& tod_manager::get_area_by_index(int index) const
return areas_[index].hexes;
}

void tod_manager::add_time_area(const config& cfg)
void tod_manager::add_time_area(const gamemap & map, const config& cfg)
{
areas_.push_back(area_time_of_day());
area_time_of_day &area = areas_.back();
area.id = cfg["id"].str();
area.xsrc = cfg["x"].str();
area.ysrc = cfg["y"].str();
area.currentTime = cfg["current_time"].to_int(0);
std::vector<map_location> const& locs (resources::disp_context->map().parse_location_range(area.xsrc, area.ysrc, true));
std::vector<map_location> const& locs (map.parse_location_range(area.xsrc, area.ysrc, true));
area.hexes.insert(locs.begin(), locs.end());
time_of_day::parse_times(cfg, area.times);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tod_manager.hpp
Expand Up @@ -117,7 +117,7 @@ class tod_manager : public savegame::savegame_config
* @param cfg Config object containing x,y range/list of
* locations and desired [time] information.
*/
void add_time_area(const config& cfg);
void add_time_area(const gamemap & map, const config& cfg);

/**
* Adds a new local time area from a set of locations, making those
Expand Down

0 comments on commit 8531dde

Please sign in to comment.