process AIVisionManager(faction)
private
allOpponents[MAX_CHARACTERS - 1];
aiCharacters[MAX_CHARACTERS - 1];
knownOpponentIndex;
knownOpponent;
opponent;
aiCharacter;
begin
allOpponents = GetAllOpponents(faction);
aiCharacters = GetFactionList(faction);
loop
// foreach AI
for (x = 0; x < MAX_CHARACTERS; ++x)
if (aiCharacters[x] <= 0)
continue;
end
aiCharacter = aiCharacters[x];
// foreach opponent
for (y = 0; y < MAX_CHARACTERS; ++y)
if (allOpponents[y] <= 0)
continue;
end
opponent = allOpponents[y];
knownOpponentIndex = GetIndexOfValueInTable(
aiCharacter.ai.model.knownOpponents,
MAX_CHARACTERS - 1,
opponent);
// this AI character already knows this opponent, only update position
if (knownOpponentIndex > -1)
knownOpponent = aiCharacter.ai.model.knownOpponents[knownOpponentIndex];
else
// if AI can see opponent, update the AIs model
if (AILineOfSight(aiCharacter.x, aiCharacter.y, opponent.x, opponent.y))
knownOpponentIndex = FindFreeIndexInTable(
aiCharacter.ai.model.knownOpponents,
MAX_CHARACTERS - 1);
aiCharacter.ai.model.knownOpponents[knownOpponentIndex] = opponent;
aiCharacter.ai.model.knownOpponentCount++;
end
end
end
end
frame;
end
end
|