Exemple #1
0
TilesArea::TilesArea(const Tilemap& tmap, int distance, OverlayPtr overlay)
{
  if( overlay.isNull() )
    return;

  TilePos offset( distance, distance  );
  TilePos size( overlay->size().width(), overlay->size().height() );
  TilePos start = overlay->tile().epos();
  _size = overlay->size();
  append( tmap.area( start - offset, start + size + offset ) );
}
bool LowBridge::canBuild( const city::AreaInfo& areaInfo ) const
{
  TilePos endPos, startPos;
  _d->direction = direction::none;

  OverlayPtr bridge = areaInfo.city->getOverlay( areaInfo.pos );
  if( bridge.isNull() )
  {
    _d->subtiles.clear();
    LowBridge* thisp = const_cast< LowBridge* >( this );
    thisp->_fgPictures().clear();

    _checkParams( areaInfo.city, _d->direction, startPos, endPos, areaInfo.pos );

    if( _d->direction != direction::none)
    {
      thisp->_computePictures( areaInfo.city, startPos, endPos, _d->direction );
    }
  }

  return (_d->direction != direction::none);
}
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;
}
Exemple #4
0
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()) );
 }