Beispiel #1
0
void BotControl::MaintainBotQuota (void)
{
   // this function keeps number of bots up to date, and don't allow to maintain bot creation
   // while creation process in process.

   if (!m_creationTab.IsEmpty () && m_maintainTime < engine->GetTime ())
   {
      CreateItem last = m_creationTab.Pop ();
      int resultOfCall = CreateBot (last.name, last.skill, last.personality, last.team, last.member);

      // check the result of creation
      if (resultOfCall == 0)
      {
         m_creationTab.RemoveAll (); // something wrong with waypoints, reset tab of creation
         yb_quota.SetInt (0); // reset quota
      }
      else if (resultOfCall == 2)
      {
         m_creationTab.RemoveAll (); // maximum players reached, so set quota to maximum players
         yb_quota.SetInt (GetBotsNum ());
      }
      m_maintainTime = engine->GetTime () + 0.2f;
   }

   // now keep bot number up to date
   if (m_maintainTime < engine->GetTime ())
   {
      int botNumber = GetBotsNum ();
      int humanNumber = GetHumansNum ();

      if (botNumber > yb_quota.GetInt ())
         RemoveRandom ();

      if (yb_autovacate.GetBool ())
      {
         if (botNumber < yb_quota.GetInt () && botNumber < engine->GetMaxClients () - 1)
            AddRandom ();

         if (humanNumber >= engine->GetMaxClients ())
            RemoveRandom ();
      }
      else
      {
         if (botNumber < yb_quota.GetInt () && botNumber < engine->GetMaxClients ())
            AddRandom ();
      }

      int botQuota = yb_autovacate.GetBool () ? (engine->GetMaxClients () - 1 - (humanNumber + 1)) : engine->GetMaxClients ();

      // check valid range of quota
      if (yb_quota.GetInt () > botQuota)
         yb_quota.SetInt (botQuota);

      else if (yb_quota.GetInt () < 0)
         yb_quota.SetInt (0);

      m_maintainTime = engine->GetTime () + 0.25f;
   }
}
Beispiel #2
0
//
// This function sets up the group with a given number of randomly generated AI. This function also sets the
// group's dungeon pointer, meaning this function MUST be called first before calling AddRandom or SpawnBoss.
//
// @Param n - The number of AI to spawn
// @Param d - The dungeon where the AI will be spawned
//
void AI_Group::RandomSetup(int n, DungeonGenerator &d)
{
	// If the group is not empty, clear it first
	if (!group.empty())
		GroupClear();

	BossActive = false;
	dungeon = &d;

	for (int i = 0; i < n; i++)
		AddRandom();
}