void Health::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { //draw background //engine.draw( tile.picture(), screenPos ); drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int healthLevel = -1; if( _isVisibleObject( overlay->type() ) ) { // Base set of visible objects needDrawAnimations = true; } else if( _flags.count( overlay->type() ) ) { needDrawAnimations = true; //city::Helper helper( _city() ); //drawArea( engine, helper.getArea( overlay ), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } else if( overlay->type() == object::house ) { HousePtr house = ptr_cast<House>( overlay ); healthLevel = _getLevelValue( house ); needDrawAnimations = (house->spec().level() == 1) && (house->habitants().empty()); if( !needDrawAnimations ) { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } } else //other buildings { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( healthLevel > 0 ) { drawColumn( engine, screenPos, healthLevel ); } } tile.setWasDrawn(); }
void Unemployed::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { //draw background //engine.draw( tile.picture(), screenPos ); drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); WorkingBuildingPtr workBuilding = overlay.as<WorkingBuilding>(); int worklessPercent = 0; if( _isVisibleObject( overlay->type() ) ) { needDrawAnimations = true; } else if( overlay->type() == object::house ) { HousePtr house = overlay.as<House>(); int worklessNumber = (int)house->getServiceValue( Service::recruter ); int matureNumber = (int)house->habitants().mature_n(); worklessPercent = math::percentage( worklessNumber, matureNumber ); needDrawAnimations = (house->spec().level() == 1) && house->habitants().empty(); if( !needDrawAnimations ) { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } } else if( workBuilding.isValid() ) { worklessPercent = math::percentage( workBuilding->needWorkers(), workBuilding->maximumWorkers() ); needDrawAnimations = workBuilding->needWorkers() > 0; if( !needDrawAnimations ) drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( worklessPercent > 0 ) { drawColumn( engine, screenPos, worklessPercent ); } } tile.setWasDrawn(); }
void Religion::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { //draw background //engine.draw( tile.picture(), screenPos ); drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int religionLevel = -1; if( _isVisibleObject( overlay->type() ) ) { // Base set of visible objects needDrawAnimations = true; } else if( overlay->type() == object::house ) { HousePtr house = ptr_cast<House>( overlay ); religionLevel = (int) house->getServiceValue(Service::religionMercury); religionLevel += house->getServiceValue(Service::religionVenus); religionLevel += house->getServiceValue(Service::religionMars); religionLevel += house->getServiceValue(Service::religionNeptune); religionLevel += house->getServiceValue(Service::religionCeres); religionLevel = math::clamp( religionLevel / (house->spec().minReligionLevel()+1), 0, 100 ); needDrawAnimations = (house->spec().level() == 1) && house->habitants().empty(); if( !needDrawAnimations ) { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } } else { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( religionLevel > 0 ) { drawColumn( engine, screenPos, religionLevel ); } } tile.setWasDrawn(); }
void Tax::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { //draw background //engine.draw( tile.picture(), screenPos ); drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int taxLevel = -1; if( _isVisibleObject( overlay->type() ) ) { // Base set of visible objects needDrawAnimations = true; } else if( overlay->type() == object::house ) { auto house = overlay.as<House>(); int taxAccess = house->getServiceValue( Service::forum ); taxLevel = math::clamp<int>( house->taxesThisYear(), 0, 100 ); needDrawAnimations = ((house->level() <= HouseLevel::hovel && house->habitants().empty()) || taxAccess < 25); if( !needDrawAnimations ) { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } } else { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( taxLevel > 0 ) { drawColumn( engine, screenPos, taxLevel ); } } tile.setRendered(); }
void Fire::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { //draw background //engine.draw( tile.picture(), screenPos ); drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int fireLevel = 0; if( _isVisibleObject( overlay->type() ) ) { // Base set of visible objects needDrawAnimations = true; } else if( overlay->type() == object::house ) { HousePtr house = ptr_cast<House>( overlay ); fireLevel = (int)house->state( pr::fire ); needDrawAnimations = (house->spec().level() == 1) && house->habitants().empty(); drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } else //other buildings { ConstructionPtr constr = ptr_cast<Construction>( overlay ); if( constr != 0 ) { fireLevel = (int)constr->state( pr::fire ); } drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( fireLevel >= 0) { _addColumn( screenPos, fireLevel ); } } tile.setWasDrawn(); }
void Sentiment::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { //draw background //engine.draw( tile.picture(), screenPos ); drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int sentimentLevel = 0; if( _isVisibleObject( overlay->type() ) ) { needDrawAnimations = true; } else if( overlay->type() == object::house ) { HousePtr house = overlay.as<House>(); sentimentLevel = (int)house->state( pr::happiness ); needDrawAnimations = (house->spec().level() == 1) && house->habitants().empty(); if( !needDrawAnimations ) { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } } else { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( sentimentLevel > 0 ) { drawColumn( engine, screenPos, 100 - sentimentLevel ); } } tile.setWasDrawn(); }
void Entertainment::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int entertainmentLevel = -1; if( _isVisibleObject( overlay->type() ) ) { // Base set of visible objects needDrawAnimations = true; } else if( _flags.count( overlay->type() ) > 0 ) { needDrawAnimations = true; } else if( overlay->type() == object::house ) { auto house = overlay.as<House>(); entertainmentLevel = _getLevelValue( house ); needDrawAnimations = (house->level() <= HouseLevel::hovel) && (house->habitants().empty()); drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } else { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( entertainmentLevel > 0 ) { drawColumn( engine, screenPos, entertainmentLevel ); } } tile.setRendered(); }
void MarketAccess::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int accessLevel = 0; if( _isVisibleObject( overlay->type() ) ) { needDrawAnimations = true; } else if( overlay->type() == object::house ) { auto house = overlay.as<House>(); accessLevel = (int)house->getServiceValue( Service::market ); needDrawAnimations = (house->level() <= HouseLevel::hovel) && house->habitants().empty(); if( !needDrawAnimations ) { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } } else { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( accessLevel >= 0 ) { drawColumn( engine, screenPos, accessLevel ); } } tile.setRendered(); }
void Aborigens::drawTile(Engine& engine, Tile& tile, const Point& offset) { Point screenPos = tile.mappos() + offset; if( tile.overlay().isNull() ) { //draw background //engine.draw( tile.picture(), screenPos ); drawPass( engine, tile, offset, Renderer::ground ); drawPass( engine, tile, offset, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int discontentLevel = 0; if( _isVisibleObject( overlay->type() ) ) { needDrawAnimations = true; } else if( overlay->type() == object::native_hut ) { auto nativeHut = overlay.as<NativeHut>(); discontentLevel = (int)nativeHut->discontent(); needDrawAnimations = false; drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::inHouseBase ); } else { drawArea( engine, overlay->area(), offset, ResourceGroup::foodOverlay, OverlayPic::base ); } if( needDrawAnimations ) { Layer::drawTile( engine, tile, offset ); registerTileForRendering( tile ); } else if( discontentLevel >= 0 ) { drawColumn( engine, screenPos, discontentLevel ); } } tile.setRendered(); }
void Crime::drawTile( const RenderInfo& rinfo, Tile& tile) { if( tile.overlay().isNull() ) { drawPass( rinfo, tile, Renderer::ground ); drawPass( rinfo, tile, Renderer::groundAnimation ); } else { bool needDrawAnimations = false; OverlayPtr overlay = tile.overlay(); int crime = -1; if( _isVisibleObject( overlay->type() ) ) { needDrawAnimations = true; } else if( overlay->type() == object::house ) { auto house = overlay.as<House>(); crime = (int)house->getServiceValue( Service::crime ); needDrawAnimations = (house->level() <= HouseLevel::hovel) && house->habitants().empty(); // In case of vacant terrain drawArea( rinfo, overlay->area(), config::layer.ground, config::tile.house ); } else { drawArea( rinfo, overlay->area(), config::layer.ground, config::tile.constr ); } if( needDrawAnimations ) { Layer::drawTile( rinfo, tile ); registerTileForRendering( tile ); } else if( crime >= 0) { Point screenPos = tile.mappos() + rinfo.offset; drawColumn( rinfo, screenPos, crime ); } } tile.setRendered(); }
void Water::drawTile( const RenderInfo& rinfo, Tile& tile) { bool needDrawAnimations = false; Size areaSize = Size::square(1); if( tile.overlay().isNull() ) { drawLandTile( rinfo, tile ); } else { OverlayPtr overlay = tile.overlay(); if( _isVisibleObject( overlay->type() ) ) { // Base set of visible objects needDrawAnimations = true; areaSize = overlay->size(); } else { int tileNumber = 0; bool haveWater = tile.param( Tile::pFountainWater ) > 0 || tile.param( Tile::pWellWater ) > 0; needDrawAnimations = false; if ( overlay->type() == object::house ) { auto house = overlay.as<House>(); needDrawAnimations = (house->level() <= HouseLevel::hovel) && house->habitants().empty(); tileNumber = config::tile.house-1; haveWater = haveWater || house->hasServiceAccess(Service::fountain) || house->hasServiceAccess(Service::well); } if( !needDrawAnimations ) { tileNumber += (haveWater ? config::layer.haveWater : 0); tileNumber += tile.param( Tile::pReservoirWater ) > 0 ? config::layer.reservoirRange : 0; drawArea( rinfo, overlay->area(), config::layer.water, config::tile.constr + tileNumber ); areaSize = Size::zero; } } if ( needDrawAnimations ) { Point screenPos = tile.mappos() + rinfo.offset; Layer::drawTile( rinfo, tile ); if( _d->showWaterValue ) { auto aqueduct = tile.overlay<Aqueduct>(); if( aqueduct.isValid() ) { Font f = Font::create( "FONT_2" ).withColor( ColorList::red ); int df = aqueduct->water(); f.draw( rinfo.engine.screen(), utils::format( 0xff, "%x", df), screenPos + Point( 20, -80 ), false ); } int wellValue = tile.param( Tile::pWellWater ); int fountainValue = tile.param( Tile::pFountainWater ); int reservoirWater = tile.param( Tile::pReservoirWater ); if( wellValue > 0 || fountainValue > 0 || reservoirWater > 0 ) { std::string text = utils::format( 0xff, "%d/%d/%d", wellValue, fountainValue, reservoirWater ); Font f = Font::create( "FONT_2" ).withColor( ColorList::red ); f.draw( rinfo.engine.screen(), text, screenPos + Point( 20, -80 ), false ); } } registerTileForRendering( tile ); } } if( !needDrawAnimations && ( tile.isWalkable(true) || tile.getFlag( Tile::tlOverlay ) ) ) { _drawLandTile( rinfo, tile, areaSize ); } tile.setRendered(); }
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; } }
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 ); }