void editor_map::sanity_check() { int errors = 0; if (total_width() != static_cast<int>(tiles_.size())) { ERR_ED << "total_width is " << total_width() << " but tiles_.size() is " << tiles_.size() << "\n"; ++errors; } if (total_height() != static_cast<int>(tiles_[0].size())) { ERR_ED << "total_height is " << total_height() << " but tiles_[0].size() is " << tiles_.size() << "\n"; ++errors; } if (w() + 2 * border_size() != total_width()) { ERR_ED << "h is " << h_ << " and border_size is " << border_size() << " but total_width is " << total_width() << "\n"; ++errors; } if (h() + 2 * border_size() != total_height()) { ERR_ED << "w is " << w_ << " and border_size is " << border_size() << " but total_height is " << total_height() << "\n"; ++errors; } for (size_t i = 1; i < tiles_.size(); ++i) { if (tiles_[i].size() != tiles_[0].size()) { ERR_ED << "tiles_[ " << i << "] has size() " << tiles_[i].size() << " but tiles[0] has size() " << tiles_[0].size() << "\n"; ++errors; } } BOOST_FOREACH(const map_location& loc, selection_) { if (!on_board_with_border(loc)) { ERR_ED << "Off-map tile in selection: " << loc << "\n"; } } if (errors) { throw editor_map_integrity_error(); } }
void gamemap::read(const std::string& data, const bool allow_invalid) { tiles_ = t_translation::ter_map(); villages_.clear(); starting_positions_.clear(); if(data.empty()) { w_ = 0; h_ = 0; if(allow_invalid) return; } int offset = read_header(data); const std::string& data_only = std::string(data, offset); try { tiles_ = t_translation::read_game_map(data_only, starting_positions_, t_translation::coordinate{ border_size(), border_size() }); } catch(const t_translation::error& e) { // We re-throw the error but as map error. // Since all codepaths test for this, it's the least work. throw incorrect_map_format_error(e.message); } // Post processing on the map w_ = total_width() - 2 * border_size(); h_ = total_height() - 2 * border_size(); //Disabled since there are callcases which pass along a valid map header but empty //map data. Still, loading (and actually applying) an empty map causes problems later on. //Other callcases which need to load a dummy map use completely empty data :(. //VALIDATE((w_ >= 1 && h_ >= 1), "A map needs at least 1 tile, the map cannot be loaded."); for(int x = 0; x < total_width(); ++x) { for(int y = 0; y < total_height(); ++y) { // Is the terrain valid? t_translation::terrain_code t = tiles_.get(x, y); if(tdata_->map().count(t) == 0) { if(!tdata_->try_merge_terrains(t)) { std::stringstream ss; ss << "Unknown tile in map: (" << t_translation::write_terrain_code(t) << ") '" << t << "'"; throw incorrect_map_format_error(ss.str().c_str()); } } // Is it a village? if(x >= border_size() && y >= border_size() && x < total_width()- border_size() && y < total_height()- border_size() && tdata_->is_village(tiles_.get(x, y))) { villages_.push_back(map_location(x - border_size(), y - border_size())); } } } }
void for_each_loc(const F& f) const { for (int x = 0; x < total_width(); ++x) { for (int y = 0; y < total_height(); ++y) { f({ x, y , wml_loc()}); } } }
void RICHDB::dump(){ // DUMP constant values cout <<"Dimensions:"<<endl<< " RICradpos: "<<RICHDB::RICradpos()<<endl<< " RICaethk: "<<RICaethk<<endl<< " RIClgthk: "<<RIClgthk<<endl<< " RIClgthk_top: "<<RIClgthk_top<<endl<< " RIClgthk_bot: "<< RIClgthk_bot<<endl<< " RICmithk: "<<RICmithk<<endl<< " RICradmirgap: "<<RICradmirgap<<endl<< " RIClgdmirgap: "<<RIClgdmirgap<<endl<< " RICotherthk: "<<RICotherthk<<endl; // Dump not constant cout<< " rad_clarity: "<<rad_clarity<<endl<< " rad_radius: "<<rad_radius<<endl<< " rad_height: "<<rad_height<<endl<< " rad_length: "<<rad_length<<endl<< " rad_index: "<<rad_index<<endl<< " foil_height: "<<foil_height<<endl<< " foil_index: "<<foil_index<<endl<< // " rad_supthk: "<<rad_supthk<<endl<< " lg_height: "<<lg_height<<endl<< " lg_length: "<<lg_length<<endl<< " lg_bottom_length: "<<lg_bottom_length<<endl<< " inner_pixel: "<<inner_pixel<<endl; // Dump functions cout << " total_height: "<<total_height()<<endl<< " pmtb_height: "<<pmtb_height()<<endl<< " mirror_pos: "<<mirror_pos()<<endl<< " rad_pos: "<<rad_pos()<<endl<< " pmt_pos: "<<pmt_pos()<<endl<< " elec_pos: "<<elec_pos()<<endl<< " cato_pos: "<<cato_pos()<<endl<< " lg_pos: "<<lg_pos()<<endl<< " shield_pos: "<<shield_pos()<<endl; // Other stuff /* cout << " LG top at "<<RICHDB::total_height()/2+AMSRICHIdGeom::pmt_pos(1,2) +RICHDB::lg_height/2.+RICpmtfoil-lg_pos()<<endl<< " Radiator bottom at "<<RICHDB::total_height()/2-RICHDB::rad_pos()- RICHDB::rad_height/2<<endl; */ }
bool editor_map::everything_selected() const { LOG_ED << selection_.size() << " " << total_width() * total_height() << "\n"; return static_cast<int>(selection_.size()) == total_width() * total_height(); }
int Fl_Tree::open(Fl_Node* node) { node->vsub_ = node->sub_; int th = total_height(node->vsub_); node->opened_ = 1; return th; }
int Fl_Tree::close(Fl_Node* node) { int th = total_height(node->vsub_); node->opened_ = 0; node->vsub_ = 0; return th; }
void Fl_Tree::update_height(void) { resize(x(), y(), w(), total_height(first_)); }
bool on_map_noborder(const map_location& loc) const { return loc.wml_x() > 0 && loc.wml_x() < total_width() - 1 && loc.wml_y() > 0 && loc.wml_y() < total_height() - 1; }
bool on_map(const map_location& loc) const { return loc.wml_x() >= 0 && loc.wml_x() < total_width() && loc.wml_y() >= 0 && loc.wml_y() < total_height(); }
/** Effective map height. */ int h() const { return total_height() - 2; }