Example #1
0
void Garden::update()
{
  TilesArea nearTiles( _city()->tilemap(), pos(), Size(2) );

  bool canGrow2squareGarden = ( nearTiles.size() == 4 ); // be carefull on map edges
  for( auto tile : nearTiles )
  {
    auto garden = tile->overlay<Garden>();
    canGrow2squareGarden &= (garden.isValid() && garden->size().area() <= 2 );
  }

  if( canGrow2squareGarden )
  {   
    for( auto tile : nearTiles )
    {
      OverlayPtr overlay = tile->overlay();

      //not delete himself
      if( overlay != this && overlay.isValid() )
      {
        overlay->deleteLater();
      }
    }

    Desirability::update( _city(), this, Desirability::off );

    setSize( Size( 2 ) );
    city::AreaInfo info( _city(), pos() );
    Construction::build( info );
    setPicture( MetaDataHolder::randomPicture( type(), size() ) );
    Desirability::update( _city(), this, Desirability::on );
  }
}
Example #2
0
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 Simple::drawTile(Engine& engine, Tile& tile, const Point& offset)
{
    OverlayPtr curOverlay = tile.overlay();

    if( _d->highlight.may )
    {
        bool blowTile = (curOverlay.isValid() && curOverlay == _d->lastOverlay) && _d->highlight.any;
        if( blowTile )
        {
            _d->highlight.alpha.update();
            int value = _d->highlight.alpha.value();
            engine.setColorMask( value << 16, value << 8, value, 0xff000000 );
        }

        Layer::drawTile(engine, tile, offset);

        if( blowTile )
            engine.resetColorMask();
    }
    else
    {
        Layer::drawTile(engine, tile, offset);
    }
}
  std::string sound() const
  {
    if( overlay.isValid() )
    {
      return overlay->sound();
    }
    else
    {
      if( tile->getFlag( Tile::tlWater ) )
      {
        return "river_00001";
      }
      else if( tile->getFlag( Tile::tlTree ) )
      {

      }
      else
      {
        return utils::format( 0xff, "emptyland_%05d", (tile->i() * tile->j()) % 3 + 1  );
      }
    }

    return "";
  }
Example #5
0
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 );
}
 bool isValid() const
 {
   return (overlay.isNull() || (overlay.isValid() && !overlay->isDeleted()) );
 }