Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void gamemap::overlay(const gamemap& m, const config& rules_cfg, int xpos, int ypos, bool border)
- {
- const config::const_child_itors &rules = rules_cfg.child_range("rule");
- int actual_border = border ? border_size() : 0;
- ERR_CF << "m.w is " << m.w() << std::endl;
- ERR_CF << "m.h is " << m.h() << std::endl;
- ERR_CF << "w is " << w() << std::endl;
- ERR_CF << "h is " << h() << std::endl;
- const int xstart = -std::min<int>(actual_border, xpos + actual_border) + 1;
- const int ystart = -std::min<int>(actual_border, ypos + actual_border + ((xpos & 1) ? 1 : 0)) + 1;
- const int xend = std::min<int>(m.w() + actual_border, w() + border_size() - xpos) + 1;
- const int yend = std::min<int>(m.h() + actual_border, h() + border_size() - ypos) + 1;
- ERR_CF << "xstart is " << xstart << std::endl;
- ERR_CF << "ystart is " << ystart << std::endl;
- ERR_CF << "xend is " << xend << std::endl;
- ERR_CF << "yend is " << yend << std::endl;
- ERR_CF << "xpos is " << xpos << std::endl;
- ERR_CF << "ypos is " << ypos << std::endl;
- for(int x1 = xstart; x1 < xend; ++x1) {
- for(int y1 = ystart; y1 < yend; ++y1) {
- const int x2 = x1 + xpos;
- const int y2 = y1 + ypos +
- ((xpos & 1) && (x1 & 1) ? 1 : 0);
- ERR_CF << "x1 is " << x1 << std::endl;
- ERR_CF << "y1 is " << y1 << std::endl;
- ERR_CF << "x2 is " << x2 << std::endl;
- ERR_CF << "y2 is " << y2 << std::endl;
- const t_translation::t_terrain t = m[x1][y1 + actual_border];
- const t_translation::t_terrain current = (*this)[x2][y2 + border_size()];
- if(t == t_translation::FOGGED || t == t_translation::VOID_TERRAIN) {
- continue;
- }
- // See if there is a matching rule
- config::const_child_iterator rule = rules.first;
- for( ; rule != rules.second; ++rule) {
- static const std::string src_key = "old", src_not_key = "old_not",
- dst_key = "new", dst_not_key = "new_not";
- const config &cfg = *rule;
- const t_translation::t_list& src = t_translation::read_list(cfg[src_key]);
- if(!src.empty() && t_translation::terrain_matches(current, src) == false) {
- continue;
- }
- const t_translation::t_list& src_not = t_translation::read_list(cfg[src_not_key]);
- if(!src_not.empty() && t_translation::terrain_matches(current, src_not)) {
- continue;
- }
- const t_translation::t_list& dst = t_translation::read_list(cfg[dst_key]);
- if(!dst.empty() && t_translation::terrain_matches(t, dst) == false) {
- continue;
- }
- const t_translation::t_list& dst_not = t_translation::read_list(cfg[dst_not_key]);
- if(!dst_not.empty() && t_translation::terrain_matches(t, dst_not)) {
- continue;
- }
- break;
- }
- if (rule != rules.second) {
- const config &cfg = *rule;
- const t_translation::t_list& terrain = t_translation::read_list(cfg["terrain"]);
- terrain_type_data::tmerge_mode mode = terrain_type_data::BOTH;
- if (cfg["layer"] == "base") {
- mode = terrain_type_data::BASE;
- } else if (cfg["layer"] == "overlay") {
- mode = terrain_type_data::OVERLAY;
- }
- t_translation::t_terrain new_terrain = t;
- if(!terrain.empty()) {
- new_terrain = terrain[0];
- }
- if (!cfg["use_old"].to_bool()) {
- set_terrain(map_location(x2, y2), new_terrain, mode, cfg["replace_if_failed"].to_bool());
- }
- } else {
- set_terrain(map_location(x2,y2),t);
- }
- }
- }
- for(const map_location* pos = m.startingPositions_;
- pos != m.startingPositions_ + sizeof(m.startingPositions_)/sizeof(*m.startingPositions_);
- ++pos) {
- if(pos->valid()) {
- startingPositions_[pos - m.startingPositions_] = *pos;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment