OverlayList Statistic::_Objects::neighbors(OverlayPtr overlay, bool v) const { if( overlay.isNull() ) return OverlayList(); Size size = overlay->size(); TilePos start = overlay->pos() - gfx::tilemap::unitLocation(); TilePos stop = start + TilePos( size.width(), size.height() ); OverlayList ret; gfx::TilesArray tiles = _parent.rcity.tilemap().rect( start, stop ); std::set<OverlayPtr> checked; for( auto tile : tiles ) { OverlayPtr ov = tile->overlay(); if( ov.isValid() && checked.count( ov ) == 0 ) { checked.insert( ov ); ret.push_back( ov ); } } return ret; }
void ClearTile::_exec( Game& game, unsigned int ) { Tilemap& tmap = game.city()->tilemap(); Tile& cursorTile = tmap.at( _pos ); if( cursorTile.getFlag( Tile::isDestructible ) ) { Size size( 1 ); TilePos rPos = _pos; OverlayPtr overlay = cursorTile.overlay(); bool deleteRoad = cursorTile.getFlag( Tile::tlRoad ); if( overlay.isValid() ) { const MetaData& md = MetaDataHolder::find( overlay->type() ); if( !overlay->canDestroy() ) { GameEventPtr e = WarningMessage::create( _( overlay->errorDesc() ), WarningMessage::neitral ); e->dispatch(); if( md.getFlag( MetaDataOptions::requestDestroy, false ) ) { e = RequestDestroy::create( overlay ); e->dispatch(); } return; } if( md.getFlag( MetaDataOptions::precisionDestroy, false ) ) { //overlay->partlyDestroy( _pos ); } } if( overlay.isValid() ) { size = overlay->size(); rPos = overlay->pos(); overlay->deleteLater(); } TilesArray clearedTiles = tmap.area( rPos, size ); for( auto tile : clearedTiles ) { tile->setMaster( NULL ); tile->setFlag( Tile::tlTree, false); tile->setFlag( Tile::tlRoad, false); tile->setFlag( Tile::tlGarden, false); tile->setOverlay( NULL ); deleteRoad |= tile->getFlag( Tile::tlRoad ); if( tile->getFlag( Tile::tlMeadow ) || tile->getFlag( Tile::tlWater ) ) { //tile->setPicture( imgid::toResource( tile->originalImgId() ) ); } else { // choose a random landscape picture: // flat land1a 2-9; // wheat: land1a 18-29; // green_something: land1a 62-119; => 58 // green_flat: land1a 232-289; => 58 // choose a random background image, green_something 62-119 or green_flat 232-240 // 30% => choose green_sth 62-119 // 70% => choose green_flat 232-289 int startOffset = ( (math::random( 10 ) > 6) ? 62 : 232 ); int imgId = math::random( 58-1 ); Picture pic; pic.load( ResourceGroup::land1a, startOffset + imgId ); tile->setPicture( pic ); tile->setImgId( imgid::fromResource( pic.name() ) ); } } // recompute roads; // there is problem that we NEED to recompute all roads map for all buildings // because MaxDistance2Road can be any number // if( deleteRoad ) { game.city()->setOption( PlayerCity::updateRoads, 1 ); } } game.city()->setOption( PlayerCity::updateTiles, 1 ); }