bool House::_tryEvolve_12_to_20_lvl( int level4grow, int minSize, const char desirability ) { //startPic += math::random( 10 ) > 5 ? 1 : 0; bool mayGrow = true; TilePos buildPos = tile().pos(); if( size() == Size( minSize-1,minSize-1 ) ) { Tilemap& tmap = _map(); std::map<TilePos, TilesArray> possibleAreas; TilePos sPos = tile().pos(); possibleAreas[ sPos ] = tmap.area( sPos, Size(minSize,minSize) ); sPos = tile().pos() - TilePos( 1, 0 ); possibleAreas[ sPos ] = tmap.area( sPos, Size(minSize,minSize) ); sPos = tile().pos() - TilePos( 1, 1 ); possibleAreas[ sPos ] = tmap.area( sPos, Size(minSize,minSize) ); sPos = tile().pos() - TilePos( 0, 1 ); possibleAreas[ sPos ] = tmap.area( sPos, Size(minSize,minSize) ); foreach( itArea, possibleAreas ) { TilesArray& area = itArea->second; for( TilesArray::iterator it=area.begin(); it != area.end(); ) { if( (*it)->overlay() == this ) { it = area.erase( it ); } else { ++it; } } for( auto& tile : area ) { if( tile == NULL ) { mayGrow = false; //some broken, can't grow break; } OverlayPtr overlay = tile->overlay(); if( overlay.isNull() ) { if( !tile->getFlag( Tile::isConstructible ) ) { mayGrow = false; //not constuctible, can't grow break; } } else { if( overlay->type() != object::garden ) { mayGrow = false; //not garden, can't grow break; } } } if( mayGrow ) { buildPos = itArea->first; Desirability::update( _city(), this, Desirability::off ); setSize(Size(minSize, minSize)); _update(true); city::AreaInfo info( _city(), buildPos ); build( info ); _d->desirability.base = desirability; _d->desirability.step = desirability < 0 ? 1 : -1; Desirability::update( _city(), this, Desirability::on ); break; } }
bool isValid() const { return (overlay.isNull() || (overlay.isValid() && !overlay->isDeleted()) ); }
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 ); }
void LoaderHelper::decodeTerrain( Tile &oTile, PlayerCityPtr city, unsigned int forceId ) { int changeId = 0; unsigned int imgId = oTile.originalImgId(); object::Type ovType = object::unknown; if( oTile.getFlag( Tile::tlRoad ) ) // road { ovType = object::road; Picture pic = MetaDataHolder::randomPicture( object::terrain, Size(1) ); oTile.setPicture( pic ); changeId = imgid::fromResource( pic.name() ); } else if( oTile.getFlag( Tile::tlTree ) ) { ovType = object::tree; Picture pic = MetaDataHolder::randomPicture( object::terrain, Size(1) ); oTile.setPicture( pic ); changeId = imgid::fromResource( pic.name() ); } else if( oTile.getFlag( Tile::tlMeadow ) ) { /*bool oldgfx = !SETTINGS_VALUE( c3gfx ).toString().empty(); oldgfx |= SETTINGS_VALUE( oldgfx ).toBool(); if( !oldgfx ) { Picture pic = MetaDataHolder::randomPicture( objects::meadow, Size(1) ); oTile.setPicture( pic ); changeId = imgid::fromResource( pic.name() ); }*/ } else if( imgId >= 0x29c && imgId <= 0x2a1 ) //aqueduct { ovType = object::aqueduct; Picture pic = MetaDataHolder::randomPicture( object::terrain, Size(1) ); oTile.setPicture( pic ); oTile.setFlag( Tile::clearAll, true ); changeId = imgid::fromResource( pic.name() ); } else if( imgId >= 372 && imgId <= 427 ) { oTile.setFlag( Tile::tlCoast, true ); if( imgId >= 388 ) oTile.setFlag( Tile::tlRubble, true ); } else if( imgId >= 863 && imgId <= 870 ) { Picture pic = MetaDataHolder::randomPicture( object::terrain, Size(1) ); oTile.setPicture( pic ); oTile.setFlag( Tile::clearAll, true ); changeId = imgid::fromResource( pic.name() ); oTile.setOriginalImgId( changeId ); } else { unsigned id = forceId > 0 ? forceId : oTile.originalImgId(); ovType = convImgId2ovrType( id ); } if( ovType == object::unknown ) return; OverlayPtr overlay; // This is the overlay object, if any overlay = TileOverlayFactory::instance().create( ovType ); if( ovType == object::elevation ) { std::string elevationPicName = imgid::toResource( oTile.originalImgId() ); overlay->setPicture( Picture( elevationPicName ) ); } if( overlay != NULL ) { //Logger::warning( "Building at ( %d, %d ) with ID: %x", oTile.i(), oTile.j(), oTile.originalImgId() ); if( oTile.overlay().isValid() ) return; city::AreaInfo info( city, oTile.pos() ); overlay->build( info ); city->addOverlay( overlay ); } if( changeId > 0 ) { oTile.setOriginalImgId( changeId ); } }