Esempio n. 1
0
void VillageControl::update(bool currentlyActive) {
  considerWelcomeMessage();
  considerCancellingAttack();
  checkEntries();
  if (Collective* enemy = getEnemyCollective())
    maxEnemyPower = max(maxEnemyPower, enemy->getDangerLevel());
  vector<Creature*> allMembers = getCollective()->getCreatures();
  for (auto team : getCollective()->getTeams().getAll()) {
    for (const Creature* c : getCollective()->getTeams().getMembers(team))
      if (!getCollective()->hasTask(c)) {
        getCollective()->getTeams().cancel(team);
        break;
      }
    return;
  }
  double updateFreq = 0.1;
  if (canPerformAttack(currentlyActive) && Random.roll(1 / updateFreq))
    if (villain) {
      double prob = villain->getAttackProbability(this) / updateFreq;
      if (prob > 0 && Random.roll(1 / prob)) {
        vector<Creature*> fighters;
        fighters = getCollective()->getCreatures({MinionTrait::FIGHTER}, {MinionTrait::SUMMONED});
        if (getCollective()->getGame()->isSingleModel())
          fighters = filter(fighters, [this] (const Creature* c) {
              return contains(getCollective()->getTerritory().getAll(), c->getPosition()); });
        Debug() << getCollective()->getName().getShort() << " fighters: " << int(fighters.size())
          << (!getCollective()->getTeams().getAll().empty() ? " attacking " : "");
        if (fighters.size() >= villain->minTeamSize && 
            allMembers.size() >= villain->minPopulation + villain->minTeamSize)
        launchAttack(getPrefix(Random.permutation(fighters),
          Random.get(villain->minTeamSize, min(fighters.size(), allMembers.size() - villain->minPopulation) + 1)));
      }
    }
}
Esempio n. 2
0
void VillageControl::tick(double time) {
  considerWelcomeMessage();
  considerCancellingAttack();
  checkEntries();
  vector<Creature*> allMembers = getCollective()->getCreatures();
  for (auto team : getCollective()->getTeams().getAll()) {
    for (const Creature* c : getCollective()->getTeams().getMembers(team))
      if (!getCollective()->hasTask(c)) {
        getCollective()->getTeams().cancel(team);
        break;
      }
    return;
  }
  double updateFreq = 0.1;
  if (Random.roll(1 / updateFreq))
    for (auto& villain : villains) {
      double prob = villain.getAttackProbability(this) / updateFreq;
      if (prob > 0 && Random.roll(1 / prob)) {
        vector<Creature*> fighters;
        fighters = getCollective()->getCreatures({MinionTrait::FIGHTER}, {MinionTrait::SUMMONED});
        fighters = filter(fighters, [this] (const Creature* c) {
            return contains(getCollective()->getTerritory().getAll(), c->getPosition()); });
        Debug() << getCollective()->getShortName() << " fighters: " << int(fighters.size())
          << (!getCollective()->getTeams().getAll().empty() ? " attacking " : "");
        if (fighters.size() < villain.minTeamSize || allMembers.size() < villain.minPopulation + villain.minTeamSize)
          continue;
        launchAttack(villain, getPrefix(Random.permutation(fighters),
            Random.get(villain.minTeamSize, min(fighters.size(), allMembers.size() - villain.minPopulation) + 1)));
        break;
      }
    }
}