示例#1
0
void PopulateItems::spawnItems() {
  bool blockers[MAP_X_CELLS][MAP_Y_CELLS];
  eng->mapTests->makeItemBlockerArray(blockers);
  eng->basicUtils->reverseBoolArray(blockers);
  vector<coord> freeCells;
  eng->mapTests->makeMapVectorFromArray(blockers, freeCells);

  const int CELLS_PER_SPAWN = 125;

  int nrOfSpawns = freeCells.size() / CELLS_PER_SPAWN;
  nrOfSpawns = max(1, nrOfSpawns);
  nrOfSpawns += eng->dice(1, (nrOfSpawns / 2) + 2) - 1;

  if(eng->playerBonusHandler->isBonusPicked(playerBonus_treasureHunter)) {
    nrOfSpawns = static_cast<int>(static_cast<double>(nrOfSpawns) * 1.2);
  }

  buildCandidateList();

  //Spawn randomly from the coord-vector
  int n = 0;
  ItemId_t id;

  for(int i = 0; i < nrOfSpawns; i++) {
    if(freeCells.size() > 0) {

      //Roll the dice for random element
      n = eng->dice(1, freeCells.size()) - 1;
      const coord pos(freeCells.at(n));

      //Get type to spawn
      id = getFromCandidateList();

      //Spawn
      eng->itemFactory->spawnItemOnMap(id, pos);

      //Erase coordinate from the vector
      freeCells.erase(freeCells.begin() + n);
    }
  }
}
示例#2
0
void PopulateItems::spawnItems() {
  bool blockers[MAP_X_CELLS][MAP_Y_CELLS];
  eng->mapTests->makeItemBlockerArray(blockers);
  eng->basicUtils->reverseBoolArray(blockers);
  vector<Pos> freeCells;
  eng->mapTests->makeBoolVectorFromMapArray(blockers, freeCells);

  const int CELLS_PER_SPAWN = 135;

  int nrOfSpawns = freeCells.size() / CELLS_PER_SPAWN;
  nrOfSpawns = max(1, nrOfSpawns);
  nrOfSpawns += eng->dice(1, (nrOfSpawns / 2) + 2) - 1;

  if(eng->playerBonHandler->isBonPicked(playerBon_treasureHunter)) {
    nrOfSpawns = (nrOfSpawns * 3) / 2;
  }

  buildCandidateList();

  //Spawn randomly from the Pos-vector
  int n = 0;
  ItemId_t id;

  for(int i = 0; i < nrOfSpawns; i++) {
    if(freeCells.size() > 0) {

      //Roll the dice for random element
      n = eng->dice(1, freeCells.size()) - 1;
      const Pos pos(freeCells.at(n));

      //Get type to spawn
      id = getFromCandidateList();

      //Spawn
      eng->itemFactory->spawnItemOnMap(id, pos);

      //Erase position from the vector
      freeCells.erase(freeCells.begin() + n);
    }
  }
}