Advertisement
lucasgautheron

spawnbots

Jul 21st, 2013
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.33 KB | None | 0 0
  1. Index: bot/ac_bot.cpp
  2. ===================================================================
  3. --- bot/ac_bot.cpp  (revision 7508)
  4. +++ bot/ac_bot.cpp  (working copy)
  5. @@ -24,7 +24,7 @@
  6.  void CACBot::Spawn()
  7.  {
  8.      // Init all bot variabeles
  9. -    m_pMyEnt->nextprimary = 2 + rnd(5); // 2011jan18:ft: 2 == GUN_CARBINE, GUN_SHOTGUN, GUN_SUBGUN, GUN_SNIPER, GUN_ASSAULT - if CPISTOL is activated this needs a FIXME to rnd(6)
  10. +    m_pMyEnt->nextprimary = (m_iSpawnPrimary >= 2 && m_iSpawnPrimary <= 6) ? m_iSpawnPrimary : (2 + rnd(5)); // 2011jan18:ft: 2 == GUN_CARBINE, GUN_SHOTGUN, GUN_SUBGUN, GUN_SNIPER, GUN_ASSAULT - if CPISTOL is activated this needs a FIXME to rnd(6)
  11.      m_pMyEnt->targetyaw = m_pMyEnt->targetpitch = 0.0f;
  12.      m_pMyEnt->pBot = this;
  13.  
  14. Index: bot/bot.cpp
  15. ===================================================================
  16. --- bot/bot.cpp (revision 7508)
  17. +++ bot/bot.cpp (working copy)
  18. @@ -100,7 +100,7 @@
  19.              m_pMyEnt->move = 0;
  20.              moveplayer(m_pMyEnt, 1, true);
  21.          }
  22. -        else if (!m_arena && lastmillis-m_pMyEnt->respawnoffset>5000) Spawn();
  23. +        else if (!m_arena && lastmillis-m_pMyEnt->respawnoffset>5000 && m_bAutoRespawn) Spawn();
  24.          SendBotInfo();
  25.          return;
  26.      }
  27. Index: bot/bot.h
  28. ===================================================================
  29. --- bot/bot.h   (revision 7508)
  30. +++ bot/bot.h   (working copy)
  31. @@ -226,6 +226,12 @@
  32.       bot_skill_s *m_pBotSkill; // Pointer to current bot skill
  33.       short m_sSkillNr; // Skill number, 0 == best 4 == worst
  34.  
  35. +     // user-defined variables
  36. +     int m_iSpawnPrimary; // Preferred primary weapon
  37. +     vec m_vSpawnPos; // spawn position
  38. +     bool m_bAutoRespawn; // respawn after death ?
  39. +     bool m_bAttackBots; // does this bot attack other bots, or just humans ?
  40. +
  41.       void AimToVec(const vec &o);
  42.       void AimToIdeal(void);
  43.       float ChangeAngle(float speed, float ideal, float current);
  44. Index: bot/bot_ai.cpp
  45. ===================================================================
  46. --- bot/bot_ai.cpp  (revision 7508)
  47. +++ bot/bot_ai.cpp  (working copy)
  48. @@ -108,7 +108,7 @@
  49.  // WIP
  50.  bool CBot::BotsAgainstHumans()
  51.  {
  52. -    return false;
  53. +    return !m_bAttackBots;
  54.  }
  55.  
  56.  bool CBot::DetectEnemy(playerent *p)
  57. Index: bot/botmanager.cpp
  58. ===================================================================
  59. --- bot/botmanager.cpp  (revision 7508)
  60. +++ bot/botmanager.cpp  (working copy)
  61. @@ -971,7 +971,12 @@
  62.      m->pBot->m_pBotSkill = &BotManager.m_BotSkills[m->pBot->m_sSkillNr];
  63.      // Sync waypoints
  64.      m->pBot->SyncWaypoints();
  65. -    m->pBot->Spawn();
  66. +
  67. +    m->pBot->m_iSpawnPrimary = -1;
  68. +    m->pBot->m_vSpawnPos = vec(0, 0, 0);
  69. +    m->pBot->m_bAutoRespawn = true;
  70. +    m->pBot->m_bAttackBots = true;
  71. +
  72.      bots.add(m);
  73.      return m;
  74.  }
  75. @@ -985,30 +990,47 @@
  76.  
  77.  // Bot manager class end
  78.  
  79. -void addbot(char *arg1, char *arg2, char *arg3)
  80. +void addbot(char *team, char *skill, char *name)
  81.  {
  82. -    if(!botmode()) return;
  83. -    botent *b = BotManager.CreateBot(arg1, arg2, arg3);
  84. -    if (b) conoutf("Bot connected: %s", b->name);
  85. -    else { conoutf("Error: Couldn't create bot!"); return; }
  86. +    botent *b = BotManager.CreateBot(team, skill, name);
  87. +    if (b)
  88. +    {
  89. +        conoutf("connected: %s", b->name);
  90. +        b->pBot->Spawn();
  91. +    }
  92. +    else conoutf("Error: Couldn't create bot!");
  93.  }
  94.  COMMAND(addbot, "sss");
  95.  
  96. -void addnbot(char *arg1, char *arg2, char *arg3)
  97. +void addnbot(int *count, char *team, char *skill)
  98.  {
  99.      if(!botmode()) return;
  100. -    if (!arg1 || !arg1[0]) return;
  101. +    loopi(*count) addbot(team, skill, NULL);
  102. +}
  103. +COMMAND(addnbot, "iss");
  104.  
  105. -    int i = atoi(arg1);
  106. -
  107. -    while(i > 0)
  108. +void spawnbot(char *team, char *skill, char *name, int *primary, int *attackbots, int *autorespawn, int *x, int *y)
  109. +{
  110. +    if(!botmode()) return;
  111. +    botent *b = BotManager.CreateBot(team, skill, name);
  112. +    conoutf("creating bot");
  113. +    if (b)
  114.      {
  115. -        addbot(arg2, arg3, NULL);
  116. -        i--;
  117. -    }
  118. +        b->pBot->m_iSpawnPrimary = *primary;
  119. +        b->pBot->m_vSpawnPos = vec(*x, *y, S(*x, *y)->floor);
  120. +        b->pBot->m_bAutoRespawn = *autorespawn ? true : false;
  121. +        b->pBot->m_bAttackBots = *attackbots ? true : false;
  122. +        b->pBot->Spawn();
  123. +     }
  124. +    else conoutf("Error: Couldn't create bot!");
  125.  }
  126. -COMMAND(addnbot, "sss");
  127. +COMMAND(spawnbot, "sssiiiii");
  128. +
  129. +COMMANDF(respawnbot, "i", (int *cn) {
  130. +    loopv(bots) if(bots[i] && bots[i]->clientnum == *cn && bots[i]->state == CS_DEAD) { bots[i]->pBot->Spawn(); return; }
  131. +});
  132.  
  133. +
  134.  void botsshoot(int *Shoot)
  135.  {
  136.      switch(*Shoot)
  137. Index: clientgame.cpp
  138. ===================================================================
  139. --- clientgame.cpp  (revision 7508)
  140. +++ clientgame.cpp  (working copy)
  141. @@ -661,7 +661,9 @@
  142.  {
  143.      int r = fixspawn-->0 ? 4 : rnd(10)+1;
  144.      entity *e = NULL;
  145. -    if(!mapcenter)
  146. +    bool predefinedspawn = d->type == ENT_BOT && !((botent *)d)->pBot->m_vSpawnPos.iszero();
  147. +
  148. +    if(!mapcenter && !predefinedspawn)
  149.      {
  150.          int type = m_teammode ? team_base(d->team) : 100;
  151.          if(m_arena && arenaspawn >= 0)
  152. @@ -699,6 +701,10 @@
  153.          d->pitch = 0;
  154.          d->roll = 0;
  155.      }
  156. +    else if(predefinedspawn)
  157. +    {
  158. +        d->o = ((botent *)d)->pBot->m_vSpawnPos;
  159. +    }
  160.      else
  161.      {
  162.          d->o.x = d->o.y = (float)ssize/2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement