Пример #1
0
void GameLoaderC3Map::Impl::initClimate(std::fstream &f, CityPtr ioCity)
{
  // read climate
  unsigned int i = 0;
  f.seekg(kClimate, std::ios::beg);
  f.read((char*)&i, 1);

  ClimateType climate = (ClimateType) i;
  ioCity->setClimate(climate);

  StringHelper::debug( 0xff, "Climate type is %d", climate );

  // reload all pics for the given climate
  //   PicLoader &pic_loader = PicLoader::instance();
  //   if (climate == C_CENTRAL)
  //   {
  //      pic_loader.load_archive("resources/pics/pics.zip");
  //   }
  //   else if (climate == C_NORTHERN)
  //   {
  //      pic_loader.load_archive("resources/pics/pics_north.zip");
  //   }
  //   else if (climate == C_DESERT)
  //   {
  //      pic_loader.load_archive("resources/pics/pics_south.zip");
  //   }
}
Пример #2
0
bool GameLoaderC3Sav::load(const std::string& filename, Game& game )
{
  std::fstream f(filename.c_str(), std::ios::in | std::ios::binary);
 
  uint32_t tmp;

  // need to rewrite better
  short int     *pGraphicGrid = (short int     *)malloc(52488);
  unsigned char *pEdgeGrid    = (unsigned char *)malloc(26244);
  short int     *pTerrainGrid = (short int     *)malloc(52488);
  unsigned char *pRndmTerGrid = (unsigned char *)malloc(26244);
  unsigned char *pRandomGrid  = (unsigned char *)malloc(26244);
  unsigned char *pZeroGrid    = (unsigned char *)malloc(26244);
  
  if( pGraphicGrid == NULL || pEdgeGrid == NULL || pTerrainGrid == NULL ||
      pRndmTerGrid == NULL || pRandomGrid == NULL || pZeroGrid == NULL )
  {
    THROW("NOT ENOUGH MEMORY!!!! FATAL");
  }    
  
  if (!f.is_open())
    THROW("can't open file");
  
  f.read((char*)&tmp, 4); // read dummy
  
  f.read((char*)&tmp, 4); // read scenario flag
  
  try
  {
    f.read((char*)&tmp, 4); // read length of compressed chunk
    std::cout << "length of compressed ids is " << tmp << std::endl;
    PKWareInputStream *pk = new PKWareInputStream(&f, false, tmp);
    for (int i = 0; i < 162 * 162; i++)
    {
      pGraphicGrid[i] = pk->readShort();
    }
    pk->empty();
    delete pk;
    
    f.read((char*)&tmp, 4); // read length of compressed chunk
    std::cout << "length of compressed egdes is " << tmp << std::endl;
    pk = new PKWareInputStream(&f, false, tmp);
    for (int i = 0; i < 162 * 162; i++)
    {
      pEdgeGrid[i] = pk->readByte();
    }
    pk->empty();
    delete pk;
    
    SkipCompressed(f); // skip building ids
    
    f.read((char*)&tmp, 4); // read length of compressed chunk
    std::cout << "length of compressed terraindata is " << tmp << std::endl;
    pk = new PKWareInputStream(&f, false, tmp);
    for (int i = 0; i < 162 * 162; i++)
    {
      pTerrainGrid[i] = pk->readShort();
    }
    pk->empty();
    delete pk;
    
    SkipCompressed(f);
    SkipCompressed(f);
    SkipCompressed(f);
    SkipCompressed(f);
    
    f.read((char*)pRandomGrid, 26244);
    
    SkipCompressed(f);
    SkipCompressed(f);
    SkipCompressed(f);
    SkipCompressed(f);
    SkipCompressed(f);
    
    // here goes walkers array
    f.read((char*)&tmp, 4); // read length of compressed chunk
    std::cout << "length of compressed walkers data is " << tmp << std::endl;
    pk = new PKWareInputStream(&f, false, tmp);    
    for (int j = 0; j < 1000; j++)
    {
      pk->skip(10);
      pk->readShort();
      pk->skip(8);
      pk->readByte();
      pk->readByte();
      pk->skip(106);
    }
    pk->empty();
    delete pk;
    int length;
    f.read((char*)&length, 4); // read next length :-)
    if (length <= 0)
      f.seekg(1200, std::ios::cur);
    else
      f.seekg(length, std::ios::cur);
    
    SkipCompressed(f);
    SkipCompressed(f);

    // 3x int
    f.read((char*)&tmp, 4);
    f.read((char*)&tmp, 4);
    f.read((char*)&tmp, 4);
    SkipCompressed(f);
    f.seekg(70, std::ios::cur);
    SkipCompressed(f); // skip building list
    f.seekg(208, std::ios::cur);
    SkipCompressed(f); // skip unknown
    f.seekg(788, std::ios::cur); // skip unused data
    f.read((char*)&tmp, 4); //mapsize
    int size = tmp;
    f.seekg(1312, std::ios::cur);
    char climate;
    f.read(&climate, 1);
    
    // here goes the WORK!
    
    CityPtr oCity = game.getCity();
    oCity->setClimate((ClimateType)climate);
    Tilemap& oTilemap = oCity->getTilemap();
    
    oTilemap.resize(size);

    oCity->setCameraPos( TilePos( 0, 0 ) );
    
  // loads the graphics map
  int border_size = (162 - size) / 2;

  for (int itA = 0; itA < size; ++itA)
  {
    for (int itB = 0; itB < size; ++itB)
    {
      int i = itB;
      int j = size - itA - 1;

      int index = 162 * (border_size + itA) + border_size + itB;

      Tile& tile = oTilemap.at(i, j);
      tile.setPicture( TileHelper::convId2PicName( pGraphicGrid[index] ) );
      tile.setOriginalImgId( pGraphicGrid[index] );
      TileHelper::decode( tile, pTerrainGrid[index] );
    }
  }    
    
  }
  catch(PKException)
  {
    THROW("fatal error when unpacking");
  }

  f.close();

  return true;
}