示例#1
0
void LoaderHelper::decodeTerrain( Tile &oTile, PlayerCityPtr city, unsigned int forceId )
{
  unsigned int imgId = oTile.originalImgId();
  TileOverlay::Type ovType = construction::unknown;
  if( oTile.getFlag( Tile::tlRoad ) )   // road
  {
    ovType = construction::road;
    Picture pic = Picture::load( ResourceGroup::land1a, 230 + math::random( 59) );
    oTile.setPicture( pic );
    oTile.setOriginalImgId( TileHelper::convPicName2Id( pic.name() ) );
  }
  else if( (imgId >= 372 && imgId <= 427) )
  {
    oTile.setFlag( Tile::tlCoast, true );
    if( imgId >= 388 )
      oTile.setFlag( Tile::tlRubble, true );
  }
  else /*if( oTile.getFlag( Tile::tlBuilding ) )*/
  {
    unsigned id = forceId > 0 ? forceId : oTile.originalImgId();
    ovType = convImgId2ovrType( id );
  }

  if( ovType == construction::unknown )
    return;

  TileOverlayPtr overlay; // This is the overlay object, if any
  overlay = TileOverlayFactory::instance().create( ovType );
  if( ovType == building::elevation )
  {
    std::string elevationPicName = TileHelper::convId2PicName( oTile.originalImgId() );
    overlay->setPicture( Picture::load( elevationPicName ) );
  }

  if( overlay != NULL )
  {
    //Logger::warning( "Building at ( %d, %d ) with ID: %x", oTile.i(), oTile.j(), oTile.originalImgId() );
    if( oTile.overlay().isValid() )
      return;

    overlay->build( city, oTile.pos() );
    city->overlays().push_back( overlay );
  }
}