void HighBridge::build( const TilePos& pos )
{
  TilePos endPos, startPos;
  _d->direction=D_NONE;

  _d->subtiles.clear();
  _fgPictures.clear();

  CityPtr city = Scenario::instance().getCity();
  Tilemap& tilemap = city->getTilemap();

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

  if( _d->direction != D_NONE )
  {    
    _computePictures( startPos, endPos, _d->direction );
   
    for( HighBridgeSubTiles::iterator it=_d->subtiles.begin(); it != _d->subtiles.end(); it++ )
    {
      HighBridgeSubTilePtr subtile = (*it);
      TilePos buildPos = pos + subtile->_pos;
      Tile& tile = tilemap.at( buildPos );
      subtile->setPicture( tile.getPicture() );
      subtile->_imgId = tile.getTerrain().getOriginalImgId();
      subtile->_info = tile.getTerrain().encode();
      subtile->_parent = this;
      
      city->build( subtile.as<Construction>(), buildPos );
    }    
  }
}
void LowBridge::build( CityPtr city, const TilePos& pos )
{
  TilePos endPos, startPos;
  _d->direction=D_NONE;

  _d->subtiles.clear();
  _fgPictures.clear();

  Tilemap& tilemap = city->getTilemap();

  _checkParams( city, _d->direction, startPos, endPos, pos );
  int signSum = 1;

  if( _d->direction != D_NONE )
  {    
    switch( _d->direction )
    {
    case D_NORTH_EAST:
      _computePictures( city, endPos, startPos, D_SOUTH_WEST );
      std::swap( _d->subtiles.front()->_pos, _d->subtiles.back()->_pos );
      signSum = -1;      
    break;

    case D_NORTH_WEST:
      _computePictures( city, endPos, startPos, D_SOUTH_EAST );
      std::swap( _d->subtiles.front()->_pos, _d->subtiles.back()->_pos );
      std::swap( startPos, endPos );
      signSum = -1;
    break;

    case D_SOUTH_WEST:
      _computePictures( city, startPos, endPos, _d->direction );
      std::swap( startPos, endPos );
    break;

    case D_SOUTH_EAST:     
      _computePictures( city, startPos, endPos, _d->direction );
    break;

    default: break;
    }
    
    TilemapArea tiles = tilemap.getFilledRectangle( startPos, endPos );
    int index=0;
    for( TilemapArea::iterator it=tiles.begin(); it != tiles.end(); it++ )
    {
      LowBridgeSubTilePtr subtile = _d->subtiles[ index ];
      TilePos buildPos = pos + subtile->_pos * signSum;
      Tile& tile = tilemap.at( buildPos );
      subtile->setPicture( tile.getPicture() );
      subtile->_imgId = tile.getOriginalImgId();
      subtile->_info = TileHelper::encode( tile );
      subtile->_parent = this;
      
      GameEventMgr::append( BuildEvent::create( buildPos, subtile.as<Construction>() ) );
      index++;
    }    
  }
}
bool HighBridge::canBuild( const TilePos& pos ) const
{
  //bool is_constructible = Construction::canBuild( pos );

  TilePos endPos, startPos;
  _d->direction=D_NONE;
  
  _d->subtiles.clear();
  const_cast< HighBridge* >( this )->_fgPictures.clear();

  _checkParams( _d->direction, startPos, endPos, pos );
 
  if( _d->direction != D_NONE )
  {
    const_cast< HighBridge* >( this )->_computePictures( startPos, endPos, _d->direction );
  }

  return (_d->direction != D_NONE);
}