4 static const float AGENT_DEFAULT_RADIUS = 0.3;
5 static const float AGENT_DEFAULT_HEIGHT = 1.8;
6 static const float REACTION_DIST_SQ = 100.0;
11 override bool PerformReaction(notnull SCR_AIUtilityComponent utility, notnull
SCR_AIThreatSystem threatSystem, AIDangerEvent dangerEvent)
13 IEntity door = dangerEvent.GetObject();
16 vector agentPos = utility.GetOrigin();
17 vector doorPos = door.GetOrigin();
20 float distSq = vector.DistanceSq(agentPos, doorPos);
21 if (distSq >= REACTION_DIST_SQ)
25 float distToDoorY = doorPos[1] - agentPos[1];
27 if (distToDoorY > AGENT_DEFAULT_HEIGHT)
30 door.GetBounds(min, max);
31 vector doorExtent = max - min;
33 if (-distToDoorY > doorExtent[1])
36 float distToDoorXZ = vector.DistanceXZ(doorPos, agentPos) - AGENT_DEFAULT_RADIUS;
38 float doorLength = doorExtent.Length();
40 if (distToDoorXZ > doorLength)
49 IEntity actionStarter = dangerEvent.GetVictim();
50 if (agent.IsEnemy(actionStarter))
53 utility.m_LookAction.LookAt(actionStarter.GetOrigin(), utility.m_LookAction.PRIO_DANGER_EVENT);
57 ChimeraCharacter character = ChimeraCharacter.Cast(agent.GetControlledEntity());
58 if (character && character.IsInVehicle())
65 vector doorNormal = door.VectorToParent(vector.Forward);
66 bool flipLogic = doorComponent.GetAngleRange() < 0.0;
68 doorNormal = -1.0 * doorNormal;
69 if (doorComponent.IsOpening())
70 doorNormal = -1.0 * doorNormal;
72 vector agentDirection = agentPos - doorComponent.GetDoorPivotPointWS();
73 agentDirection.Normalize();
75 vector rightHand = vector.Up * doorNormal;
77 rightHand = -1.0 * rightHand;
78 if (doorComponent.IsClosing())
79 rightHand = -1.0 * rightHand;
81 IEntity doorFrame = door.GetParent();
85 vector doorFrameUp = doorFrame.VectorToParent(vector.Up);
91 s1 = Shape.CreateArrow(doorPos, doorPos + agentDirection, 0.1, COLOR_RED, ShapeFlags.NOZBUFFER);
92 s2 = Shape.CreateArrow(doorPos, doorPos + doorNormal, 0.1, COLOR_BLUE, ShapeFlags.NOZBUFFER);
93 s3 = Shape.CreateArrow(doorPos, doorPos + rightHand, 0.1, COLOR_GREEN, ShapeFlags.NOZBUFFER);
96 float dotP1 = vector.Dot(doorNormal, agentDirection);
97 float dotP2 = vector.Dot(rightHand, agentDirection);
99 bool isDoorOpeningUpwards = !
float.AlmostEqual(vector.Dot(doorNormal, doorFrameUp),0);
101 if (isDoorOpeningUpwards)
103 if (!doorComponent.IsClosing())
107 distToDoorXZ = vector.DistanceXZ(doorFrame.GetOrigin(), agentPos) - AGENT_DEFAULT_RADIUS;
110 fleeingDir = -1.0 * rightHand;
112 fleeingDir = rightHand;
113 distanceToMove = Math.Clamp((doorLength - distToDoorXZ) * 2.0, doorLength, 2.0 * doorLength);
122 if (doorComponent.IsClosing())
123 fleeingDir = -1.0 * rightHand;
125 fleeingDir = doorNormal;
126 distanceToMove = Math.Clamp((doorLength - distToDoorXZ) * 2.0, 2.0 * AGENT_DEFAULT_RADIUS, doorLength);
131 s4 = Shape.CreateArrow(agentPos, agentPos + fleeingDir * distanceToMove, 0.5, COLOR_YELLOW, ShapeFlags.NOZBUFFER);
133 vector movePos = agentPos + fleeingDir * distanceToMove;