Game Development Reference
In-Depth Information
Updating decision evaluators
With a centralized data structure in place, we can refactor the decision evaluators in order
to reference the blackboard directly. Removing the enemy evaluation from the Soldier-
Evaluators_CanShootAgent function solves a critical flaw in our previous imple-
mentation, which is the fact that no conditional evaluation should modify the agent. Logic
evaluators should only make true or false calculations in a passive manner and never
mutate the state of an agent:
SoldierEvaluators.lua :
function SoldierEvaluators_CanShootAgent(userData)
local enemy = userData.blackboard:Get("enemy");
if (enemy ~= nil and
Agent.GetHealth(enemy) > 0 and
Vector.Distance(
userData.agent:GetPosition(),
enemy:GetPosition()) < 3) then
return true;
end;
return false;
end
function SoldierEvaluators_HasAmmo(userData)
local ammo = userData.blackboard:Get("ammo");
return ammo ~= nil and ammo > 0;
end
function SoldierEvaluators_HasCriticalHealth(userData)
local maxHealth = userData.blackboard:Get("maxHealth");
return Agent.GetHealth(userData.agent) < (maxHealth *
0.2);
end
Search WWH ::




Custom Search