| 86 | } |
| 87 | |
| 88 | bool CBot::FindEnemy(void) |
| 89 | { |
| 90 | // UNDONE: Enemies are now only scored on their distance |
| 91 | if(BotsAgainstHumans()) |
| 92 | { |
| 93 | m_pMyEnt->enemy = NULL; |
| 94 | if(player1->state == CS_ALIVE) |
| 95 | { |
| 96 | m_pMyEnt->enemy = player1; |
| 97 | } |
| 98 | |
| 99 | return m_pMyEnt->enemy != NULL; |
| 100 | } |
| 101 | |
| 102 | if (m_pMyEnt->enemy) // Bot already has an enemy |
| 103 | { |
| 104 | // Check if the enemy is still in game |
| 105 | bool found = IsInGame(m_pMyEnt->enemy); |
| 106 | |
| 107 | // Check if the enemy is still ingame, still alive, not joined my team and is visible |
| 108 | if (found && !isteam(m_pMyEnt->team, m_pMyEnt->enemy->team)) |
| 109 | { |
| 110 | if ((m_pMyEnt->enemy->state == CS_ALIVE) && (IsVisible(m_pMyEnt->enemy))) |
| 111 | return true; |
| 112 | else |
| 113 | m_pPrevEnemy = m_pMyEnt->enemy; |
| 114 | } |
| 115 | else |
| 116 | m_pMyEnt->enemy = NULL; |
| 117 | } |
| 118 | |
| 119 | if (m_iEnemySearchDelay > lastmillis) return (m_pMyEnt->enemy!=NULL); |
| 120 | |
| 121 | m_pMyEnt->enemy = NULL; |
| 122 | |
| 123 | // Add enemy searchy delay |
| 124 | float MinDelay = m_pBotSkill->flMinEnemySearchDelay; |
| 125 | float MaxDelay = m_pBotSkill->flMaxEnemySearchDelay; |
| 126 | m_iEnemySearchDelay = lastmillis + int(RandomFloat(MinDelay, MaxDelay) * 1000.0f); |
| 127 | |
| 128 | playerent *pNewEnemy = NULL, *d = NULL; |
| 129 | float flDist, flNearestDist = 99999.9f; |
| 130 | short EnemyVal, BestEnemyVal = -100; |
| 131 | |
| 132 | // First loop through all bots |
| 133 | loopv(bots) |
| 134 | { |
| 135 | d = bots[i]; // Handy shortcut |
| 136 | |
| 137 | if (d == m_pMyEnt || !d || isteam(d->team, m_pMyEnt->team) || (d->state != CS_ALIVE)) |
| 138 | continue; |
| 139 | |
| 140 | // Check if the enemy is visible |
| 141 | if(!DetectEnemy(d)) |
| 142 | continue; |
| 143 | |
| 144 | flDist = GetDistance(d->o); |
| 145 | EnemyVal = 1; |
nothing calls this directly
no test coverage detected