add defense ai control object

alut-include-path
Maikel de Vries 2017-01-08 19:13:06 +01:00
parent eec8127e8a
commit 18a313c962
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,5 @@
[DefCore]
id=DefenseAI
Version=8,0
Category=C4D_None | C4D_MouseIgnore
HideInCreator=true

View File

@ -0,0 +1,51 @@
/**
Defense AI
Controls enemy behaviour in defense scenarios.
@author Sven2, Clonkonaut, Maikel
*/
#include AI
public func AddAI(object clonk)
{
// Add normal AI and adapt it.
var fx = AI->AddAI(clonk);
if (fx)
{
clonk.ExecuteAI = DefenseAI.Execute;
fx.ai = DefenseAI;
}
return fx;
}
private func FindTarget(effect fx)
{
var target = _inherited(fx, ...);
// Focus on defense target if normal target is too far away.
if (!target || ObjectDistance(target, fx.Target) > DefenseAI.AI_AltTargetDistance)
target = GetRandomAttackTarget(fx.Target);
return target;
}
private func FindInventoryWeapon(effect fx)
{
// Alternative behavior when riding the boom attack.
if (fx.vehicle && fx.vehicle->GetID() == DefenseBoomAttack)
{
fx.weapon = FindContents(Bow);
fx.strategy = fx.ai.ExecuteRanged;
fx.projectile_speed = 100;
fx.aim_wait = 0;
fx.ammo_check = fx.ai.HasArrows;
fx.ranged = true;
return true;
}
return _inherited(fx, ...);
}
/*-- Properties --*/
local AI_AltTargetDistance = 400;