Vultraz

Untitled

Aug 15th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. void gamemap::overlay(const gamemap& m, const config& rules_cfg, int xpos, int ypos, bool border)
  2. {
  3.     const config::const_child_itors &rules = rules_cfg.child_range("rule");
  4.     int actual_border = border ? border_size() : 0;
  5.  
  6.     ERR_CF << "m.w is " << m.w() << std::endl;
  7.     ERR_CF << "m.h is " << m.h() << std::endl;
  8.     ERR_CF << "w is   " << w() << std::endl;
  9.     ERR_CF << "h is   " << h() << std::endl;
  10.  
  11.     const int xstart = -std::min<int>(actual_border, xpos + actual_border) + 1;
  12.     const int ystart = -std::min<int>(actual_border, ypos + actual_border + ((xpos & 1) ? 1 : 0)) + 1;
  13.     const int xend = std::min<int>(m.w() + actual_border, w() + border_size() - xpos) + 1;
  14.     const int yend = std::min<int>(m.h() + actual_border, h() + border_size() - ypos) + 1;
  15.  
  16.     ERR_CF << "xstart is " << xstart << std::endl;
  17.     ERR_CF << "ystart is " << ystart << std::endl;
  18.     ERR_CF << "xend is   " << xend << std::endl;
  19.     ERR_CF << "yend is   " << yend << std::endl;
  20.  
  21.     ERR_CF << "xpos is   " << xpos << std::endl;
  22.     ERR_CF << "ypos is   " << ypos << std::endl;
  23.  
  24.     for(int x1 = xstart; x1 < xend; ++x1) {
  25.         for(int y1 = ystart; y1 < yend; ++y1) {
  26.             const int x2 = x1 + xpos;
  27.             const int y2 = y1 + ypos +
  28.                 ((xpos & 1) && (x1 & 1) ? 1 : 0);
  29.  
  30.             ERR_CF << "x1 is " << x1 << std::endl;
  31.             ERR_CF << "y1 is " << y1 << std::endl;
  32.             ERR_CF << "x2 is " << x2 << std::endl;
  33.             ERR_CF << "y2 is " << y2 << std::endl;
  34.  
  35.             const t_translation::t_terrain t = m[x1][y1 + actual_border];
  36.             const t_translation::t_terrain current = (*this)[x2][y2 + border_size()];
  37.  
  38.             if(t == t_translation::FOGGED || t == t_translation::VOID_TERRAIN) {
  39.                 continue;
  40.             }
  41.  
  42.             // See if there is a matching rule
  43.             config::const_child_iterator rule = rules.first;
  44.             for( ; rule != rules.second; ++rule) {
  45.                 static const std::string src_key = "old", src_not_key = "old_not",
  46.                                          dst_key = "new", dst_not_key = "new_not";
  47.                 const config &cfg = *rule;
  48.                 const t_translation::t_list& src = t_translation::read_list(cfg[src_key]);
  49.  
  50.                 if(!src.empty() && t_translation::terrain_matches(current, src) == false) {
  51.                     continue;
  52.                 }
  53.  
  54.                 const t_translation::t_list& src_not = t_translation::read_list(cfg[src_not_key]);
  55.  
  56.                 if(!src_not.empty() && t_translation::terrain_matches(current, src_not)) {
  57.                     continue;
  58.                 }
  59.  
  60.                 const t_translation::t_list& dst = t_translation::read_list(cfg[dst_key]);
  61.  
  62.                 if(!dst.empty() && t_translation::terrain_matches(t, dst) == false) {
  63.                     continue;
  64.                 }
  65.  
  66.                 const t_translation::t_list& dst_not = t_translation::read_list(cfg[dst_not_key]);
  67.  
  68.                 if(!dst_not.empty() && t_translation::terrain_matches(t, dst_not)) {
  69.                     continue;
  70.                 }
  71.  
  72.                 break;
  73.             }
  74.  
  75.  
  76.             if (rule != rules.second) {
  77.                 const config &cfg = *rule;
  78.                 const t_translation::t_list& terrain = t_translation::read_list(cfg["terrain"]);
  79.  
  80.                 terrain_type_data::tmerge_mode mode = terrain_type_data::BOTH;
  81.                 if (cfg["layer"] == "base") {
  82.                     mode = terrain_type_data::BASE;
  83.                 } else if (cfg["layer"] == "overlay") {
  84.                     mode = terrain_type_data::OVERLAY;
  85.                 }
  86.  
  87.                 t_translation::t_terrain new_terrain = t;
  88.                 if(!terrain.empty()) {
  89.                     new_terrain = terrain[0];
  90.                 }
  91.  
  92.                 if (!cfg["use_old"].to_bool()) {
  93.                     set_terrain(map_location(x2, y2), new_terrain, mode, cfg["replace_if_failed"].to_bool());
  94.                 }
  95.             } else {
  96.                 set_terrain(map_location(x2,y2),t);
  97.             }
  98.         }
  99.     }
  100.  
  101.     for(const map_location* pos = m.startingPositions_;
  102.             pos != m.startingPositions_ + sizeof(m.startingPositions_)/sizeof(*m.startingPositions_);
  103.             ++pos) {
  104.  
  105.         if(pos->valid()) {
  106.             startingPositions_[pos - m.startingPositions_] = *pos;
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment