Exemplo n.º 1
0
void LowBridge::build( CityPtr city, const TilePos& pos )
{
  TilePos endPos, startPos;
  _d->direction=noneDirection;

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

  Tilemap& tilemap = city->getTilemap();

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

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

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

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

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

    default: break;
    }
    
    TilemapArea tiles = tilemap.getArea( 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;
      
      events::GameEventPtr event = events::BuildEvent::create( buildPos, subtile.as<TileOverlay>() );
      event->dispatch();
      index++;
    }    
  }
}
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++;
    }    
  }
}