Save villages and items.

This commit is contained in:
fendrin 2013-12-21 06:39:01 +01:00
parent 13f8f2d86a
commit 9a44642689
9 changed files with 58 additions and 37 deletions

View file

@ -79,7 +79,7 @@ void display::parse_team_overlays()
{
const team& curr_team = (*teams_)[playing_team()];
const team& prev_team = (*teams_)[playing_team()-1 < teams_->size() ? playing_team()-1 : teams_->size()-1];
BOOST_FOREACH(const game_display::overlay_map::value_type i, overlays_) {
BOOST_FOREACH(const game_display::overlay_map::value_type i, *overlays_) {
const overlay& ov = i.second;
if (!ov.team_name.empty() &&
((ov.team_name.find(curr_team.team_name()) + 1) != 0) !=
@ -97,19 +97,19 @@ void display::add_overlay(const map_location& loc, const std::string& img, const
get_location_y(loc) + hex_size() / 2, halo, loc);
const overlay item(img, halo, halo_handle, team_name, visible_under_fog);
overlays_.insert(overlay_map::value_type(loc,item));
overlays_->insert(overlay_map::value_type(loc,item));
}
void display::remove_overlay(const map_location& loc)
{
typedef overlay_map::const_iterator Itor;
std::pair<Itor,Itor> itors = overlays_.equal_range(loc);
std::pair<Itor,Itor> itors = overlays_->equal_range(loc);
while(itors.first != itors.second) {
halo::remove(itors.first->second.halo_handle);
++itors.first;
}
overlays_.erase(loc);
overlays_->erase(loc);
}
void display::remove_single_overlay(const map_location& loc, const std::string& toDelete)
@ -117,14 +117,14 @@ void display::remove_single_overlay(const map_location& loc, const std::string&
//Iterate through the values with key of loc
typedef overlay_map::iterator Itor;
overlay_map::iterator iteratorCopy;
std::pair<Itor,Itor> itors = overlays_.equal_range(loc);
std::pair<Itor,Itor> itors = overlays_->equal_range(loc);
while(itors.first != itors.second) {
//If image or halo of overlay struct matches toDelete, remove the overlay
if(itors.first->second.image == toDelete || itors.first->second.halo == toDelete) {
iteratorCopy = itors.first;
++itors.first;
halo::remove(iteratorCopy->second.halo_handle);
overlays_.erase(iteratorCopy);
overlays_->erase(iteratorCopy);
}
else {
++itors.first;
@ -2561,7 +2561,7 @@ void display::draw_hex(const map_location& loc) {
if(!shrouded(loc)) {
typedef overlay_map::const_iterator Itor;
std::pair<Itor,Itor> overlays = overlays_.equal_range(loc);
std::pair<Itor,Itor> overlays = overlays_->equal_range(loc);
for( ; overlays.first != overlays.second; ++overlays.first) {
if ((overlays.first->second.team_name == "" ||
overlays.first->second.team_name.find((*teams_)[playing_team()].team_name()) != std::string::npos)

View file

@ -1014,11 +1014,12 @@ protected:
bool reach_map_changed_;
void process_reachmap_changes();
private:
typedef std::multimap<map_location, overlay> overlay_map;
overlay_map overlays_;
private:
overlay_map* overlays_;
/** Handle for the label which displays frames per second. */
int fps_handle_;
@ -1050,6 +1051,9 @@ private:
bool do_reverse_memcpy_workaround_;
#endif
public:
void replace_overlay_map(overlay_map* overlays) { overlays_ = overlays; }
protected:
static display * singleton_;
};

View file

@ -82,6 +82,8 @@ public:
resources::tod_manager = context_manager_.get_map_context().get_time_manager();
context_manager_.gui().change_teams(&context_manager_.get_map_context().get_teams());
context_manager_.gui().replace_overlay_map(&context_manager_.get_map_context().get_overlays());
resources::teams = &context_manager_.get_map_context().get_teams();
resources::state_of_game = &context_manager_.get_map_context().get_game_state();

View file

@ -237,6 +237,11 @@ void map_context::load_scenario(const config& game_config)
tod_manager_->add_time_area(t);
}
BOOST_FOREACH(const config& item, scenario.child_range("item")) {
overlays_.insert(std::pair<map_location,
overlay>(map_location(item["x"], item["y"]), overlay(item) ));
}
BOOST_FOREACH(const config& music, scenario.child_range("music")) {
music_tracks_.insert(std::pair<std::string, sound::music_track>(music["name"], sound::music_track(music)));
}
@ -384,6 +389,19 @@ config map_context::to_config()
labels_.write(scenario);
overlay_map::const_iterator it;
for (it = overlays_.begin(); it != overlays_.end(); it++) {
config& item = scenario.add_child("item");
it->first.write(item);
item["image"] = it->second.image;
item["id"] = it->second.id;
item["halo"] = it->second.halo;
item["visible_in_fog"] = it->second.visible_in_fog;
item["name"] = it->second.name;
item["team_name"] = it->second.team_name;
}
BOOST_FOREACH(const music_map::value_type& track, music_tracks_) {
track.second.write(scenario, true);
}
@ -410,6 +428,10 @@ config map_context::to_config()
side["gold"] = t->gold();
side["income"] = t->base_income();
BOOST_FOREACH(const map_location& village, t->villages()) {
village.write(side.add_child("village"));
}
//current visible units
for(unit_map::const_iterator i = units_.begin(); i != units_.end(); ++i) {
if(i->side() == side_num) {
@ -421,6 +443,9 @@ config map_context::to_config()
}
}
}
return scenario;
}

View file

@ -424,9 +424,13 @@ private:
typedef std::map<std::string, sound::music_track> music_map;
music_map music_tracks_;
typedef std::map<map_location, std::vector<overlay> > overlay_map;
typedef std::multimap<map_location, overlay> overlay_map;
overlay_map overlays_;
public:
overlay_map& get_overlays() { return overlays_; }
};

View file

@ -64,6 +64,7 @@ game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
const tod_manager& tod, const std::vector<team>& t,
const config& theme_cfg, const config& level) :
display(&units, video, &map, &t, theme_cfg, level),
overlay_map_(),
fake_units_(),
attack_indicator_src_(),
attack_indicator_dst_(),
@ -71,7 +72,6 @@ game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
tod_manager_(tod),
level_(level),
displayedUnitHex_(),
// overlays_(),
sidebarScaling_(1.0),
first_turn_(true),
in_game_(false),
@ -79,7 +79,7 @@ game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
chat_messages_(),
game_mode_(RUNNING)
{
replace_overlay_map(&overlay_map_);
clear_screen();
}

View file

@ -290,6 +290,8 @@ private:
void draw_sidebar();
overlay_map overlay_map_;
/// collection of units destined to be drawn but not put into the unit map
std::deque<unit*> fake_units_;
@ -309,23 +311,6 @@ private:
map_location displayedUnitHex_;
// struct overlay {
// overlay(const std::string& img, const std::string& halo_img,
// int handle, const std::string& overlay_team_name, const bool fogged) : image(img), halo(halo_img),
// team_name(overlay_team_name), halo_handle(handle) , visible_in_fog(fogged){}
// std::string image;
// std::string halo;
// std::string team_name;
// int halo_handle;
// bool visible_in_fog;
// };
// typedef std::multimap<map_location,overlay> overlay_map;
// overlay_map overlays_;
double sidebarScaling_;
bool first_turn_, in_game_;

View file

@ -61,16 +61,16 @@ void time_of_day::write(config& cfg) const
cfg["sound"] = sounds;
}
void time_of_day::parse_times(const config& cfg, std::vector<time_of_day>& normal_times)
void time_of_day::parse_times(const config& cfg, std::vector<time_of_day>& times)
{
BOOST_FOREACH(const config &t, cfg.child_range("time")) {
normal_times.push_back(time_of_day(t));
times.push_back(time_of_day(t));
}
if(normal_times.empty())
{
// Make sure we have at least default time
normal_times.push_back(time_of_day());
}
// if(times.empty())
// {
// // Make sure we have at least default time
// times.push_back(time_of_day());
// }
}

View file

@ -378,6 +378,7 @@ int tod_manager::calculate_current_time(
const int current_time,
const bool only_to_allowed_range) const
{
if (number_of_times == 0) return 0;
int new_current_time = 0;
if(only_to_allowed_range) new_current_time = current_time % number_of_times;
else new_current_time = (current_time + for_turn_number - turn_) % number_of_times;