11 static const string PORT_ERROR_OFFSET =
"ErrorOffset";
12 static const string PORT_BASE_TARGET =
"BaseTargetIn";
13 static const string PORT_AIM_POINT =
"AimPoint";
14 static const string PORT_TOLERANCE =
"AimingTolerance";
15 static const string PORT_AIMPOINT_TYPE_0 =
"AimpointType0";
16 static const string PORT_AIMPOINT_TYPE_1 =
"AimpointType1";
17 static const float CLOSE_RANGE_THRESHOLD = 15.0;
18 static const float LONG_RANGE_THRESHOLD = 200.0;
19 static const float AIMING_ERROR_SCALE = 1.0;
20 static const float AIMING_ERROR_FACTOR_MIN = 0.4;
21 static const float AIMING_ERROR_CLOSE_RANGE_FACTOR_MIN = 0.05;
22 static const float AIMING_ERROR_FACTOR_MAX = 1.4;
23 static const float MAXIMAL_TOLERANCE = 10.0;
24 static const float MINIMAL_TOLERANCE = 0.003;
30 protected ref array<ref Shape> m_aDebugShapes = {};
41 private int m_iTorsoCount = 0;
44 override void OnInit(AIAgent owner)
46 IEntity ent = owner.GetControlledEntity();
81 IEntity entity = owner.GetControlledEntity();
86 m_aDebugShapes.Clear();
101 IEntity targetEntity = target.GetTargetEntity();
115 aimpointTypes[0] = aimpointType0;
116 aimpointTypes[1] = aimpointType1;
138 float angularSize,
distance, tolerance;
147 offsetX =
GetRandomFactor(currentSkill, 0) * offsetX * AIMING_ERROR_SCALE * distanceFactor * offsetWeaponFactor * illuminationFactor;
148 offsetY =
GetRandomFactor(currentSkill, 0) * offsetY * AIMING_ERROR_SCALE * distanceFactor * offsetWeaponFactor * illuminationFactor;
175 vector shooterCenter, joinNorm, join, min, max;
176 float dimension = 2 * targetAimpoint.GetDimension();
180 shooterCenter = (min + max) * 0.5;
181 join = targetAimpoint.GetPosition() - shooterCenter;
185 joinNorm = join.Normalized();
186 sizeVectorX = (
vector.Up * joinNorm).Normalized();
187 sizeVectorY = (joinNorm * sizeVectorX).Normalized();
189 sizeVectorX *= dimension;
190 sizeVectorY *= dimension;
195 m_aDebugShapes.Insert(
Shape.CreateArrow(shooterCenter, shooterCenter + sizeVectorX, 0.1,
COLOR_BLUE,
ShapeFlags.NOZBUFFER));
196 m_aDebugShapes.Insert(
Shape.CreateArrow(shooterCenter, shooterCenter + sizeVectorY, 0.1,
COLOR_RED,
ShapeFlags.NOZBUFFER));
197 m_aDebugShapes.Insert(
Shape.CreateArrow(shooterCenter, shooterCenter + joinNorm * dimension, 0.1,
COLOR_YELLOW,
ShapeFlags.NOZBUFFER));
206 if (
distance < CLOSE_RANGE_THRESHOLD)
207 return Math.Map(
distance, 0, CLOSE_RANGE_THRESHOLD, AIMING_ERROR_CLOSE_RANGE_FACTOR_MIN, AIMING_ERROR_FACTOR_MIN);
209 float distanceCl =
Math.Clamp((
distance - CLOSE_RANGE_THRESHOLD) / LONG_RANGE_THRESHOLD, 0, 1);
210 return Math.Lerp(AIMING_ERROR_FACTOR_MIN, AIMING_ERROR_FACTOR_MAX, distanceCl);
221 if (perceivable.GetIlluminationFactor() < 0.5)
239 case EAISkill.ROOKIE :
244 case EAISkill.REGULAR :
249 case EAISkill.VETERAN :
254 case EAISkill.EXPERT :
259 case EAISkill.CYLON :
265 return Math.RandomGaussFloat(sigma,mu);
273 bool setMaxTolerance;
276 if (
distance < CLOSE_RANGE_THRESHOLD)
277 return MAXIMAL_TOLERANCE;
279 tolerance = angularSize / 2;
284 tolerance = MAXIMAL_TOLERANCE;
290 return Math.Clamp(tolerance, MINIMAL_TOLERANCE, MAXIMAL_TOLERANCE);
300 enemyVelocity = enemyPhysics.GetVelocity();
303 vector observerAngularVelocity;
308 observerVelocity = observerPhysics.GetVelocity();
309 observerAngularVelocity = observerPhysics.GetAngularVelocity();
312 vector relativeVelocity = enemyVelocity - observerVelocity;
315 vector targetLocalAngularVelocity = observerAngularVelocity + (positionVector * relativeVelocity / positionVector.LengthSq());
316 float totalTargetLocalAngularVelocity = targetLocalAngularVelocity.Length();
318 if (totalTargetLocalAngularVelocity < 0.07)
320 else if (totalTargetLocalAngularVelocity < 0.17)
323 setBigTolerance =
true;
378 if (!targetPerceivable)
381 array<ref AimPoint> aimPoints = {};
384 for (
int i = 0; i < 3; i++)
387 if (aimpointType == -1)
390 targetPerceivable.GetAimpointsOfType(aimPoints, aimpointType);
391 if (!aimPoints.IsEmpty())
395 int index = aimPoints.GetRandomIndex();
398 return aimPoints[
index];
407 protected static override string GetOnHoverDescription() {
return "Get aiming error position from the center of the target";}
when task is activated by player or by killing enemy
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external Physics GetPhysics()
proto external void GetWorldBounds(out vector mins, out vector maxs)
proto external IEntity GetRootParent()
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
proto void ClearVariable(string name)
float GetTolerance(IEntity observer, IEntity target, float angularSize, float distance, EWeaponType weaponType)
basic tolerance based on angular size of target in degrees
EAimPointType m_eAimPointType
static override string GetOnHoverDescription()
float GetRandomFactor(EAISkill skill, float mu)
float GetDistanceFactor(float distance)
returns factor of error scale based on distance to target
override array< string > GetVariablesIn()
SCR_AICombatComponent m_CombatComponent
float m_fDefaultPrecisionXY
float GetAngularSpeedFactor(IEntity observer, IEntity enemy, out bool setBigTolerance)
EAimingPreference m_eAimingPreference
static override bool VisibleInPalette()
float GetOffsetWeaponTypeFactor(EWeaponType weaponType)
Scales offset depending on weapon type.
void GetTargetAngularBounds(IEntity shooter, AimPoint targetAimpoint, out vector sizeVectorX, out vector sizeVectorY, out float angularSize, out float distance)
returns vectors of aimpoint volume projected onto shooter's BB center and the angular size of the tar...
float GetWeaponTypeFactor(EWeaponType weaponType)
static ref TStringArray s_aVarsOut
AimPoint GetAimPoint(BaseTarget target, EAimPointType aimpointTypes[3])
static ref TStringArray s_aVarsIn
override array< string > GetVariablesOut()
float GetTargetIlluminationFactor(BaseTarget tgt)
returns 1.0 if target is well illuminated, and a bigger value if target is poorly illuminated.
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Instance of created debug visualizer.
@ NONE
When Shape is created and not initialized yet.
SCR_FieldOfViewSettings Attribute
array< string > TStringArray