‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
animation_selector_table_evaluators.gsc
Go to the documentation of this file.
1 #using scripts\shared\ai\systems\animation_selector_table;
2 #using scripts\shared\array_shared;
3 
4 #insert scripts\shared\ai\systems\blackboard.gsh;
5 #insert scripts\shared\ai\systems\animation_selector_table.gsh;
6 #insert scripts\shared\shared.gsh;
7 
8 function autoexec ‪RegisterASTScriptFunctions()
9 {
10  AST_REGISTER_API( "testFunction", &‪testFunction );
11 
12  // ------- EVALUATOR BLOCKED BY GEO ANIMATIONS -----------//
13  AST_REGISTER_API( "evaluateBlockedAnimations", &‪evaluateBlockedAnimations );
14 
15  // ------- EVALUATOR HUMAN LOCOMOTION TURNS -----------//
16  AST_REGISTER_API( "evaluateHumanTurnAnimations", &‪evaluateHumanTurnAnimations );
17 
18  // ------- EVALUATOR HUMAN EXPOSED ARRIVALS -----------//
19  AST_REGISTER_API( "evaluateHumanExposedArrivalAnimations", &‪evaluateHumanExposedArrivalAnimations );
20 }
21 
22 function ‪testFunction( entity, animations )
23 {
24  if ( IsArray( animations ) && animations.size > 0 )
25  {
26  return animations[0];
27  }
28 }
29 
30 function private ‪Evaluator_CheckAnimationAgainstGeo( entity, animation )
31 {
32  PixBeginEvent( "Evaluator_CheckAnimationAgainstGeo" );
33 
34  assert( IsActor( entity ) );
35 
36  // Since this check is mostly used for turn animations, a better approximation
37  // of movement is to use the midpoint position of the animation and the end
38  // point of the animation.
39  localDeltaHalfVector = GetMoveDelta( animation, 0, 0.5, entity );
40  midPoint = entity LocalToWorldCoords( localDeltaHalfVector );
41  // ignore any Z translation.
42  midPoint = ( midPoint[0], midPoint[1], entity.origin[2] );
43 
44  /#
45  RecordLine( entity.origin, midPoint, ‪ORANGE, "Animscript", entity );
46  #/
47 
48  if( entity MayMoveToPoint( midPoint, true, true ) )
49  {
50  localDeltaVector = GetMoveDelta( animation, 0, 1, entity );
51  endPoint = entity LocalToWorldCoords( localDeltaVector );
52  endPoint = ( endPoint[0], endPoint[1], entity.origin[2] );
53 
54  /#
55  RecordLine( midPoint, endPoint, ‪ORANGE, "Animscript", entity );
56  #/
57 
58  if ( entity MayMoveFromPointToPoint( midPoint, endPoint, true, true ) )
59  {
60  PixEndEvent();
61  return true;
62  }
63  }
64 
65  PixEndEvent();
66  return false;
67 }
68 
69 function private ‪Evaluator_CheckAnimationEndPointAgainstGeo( entity, animation )
70 {
71  PixBeginEvent( "Evaluator_CheckAnimationEndPointAgainstGeo" );
72 
73  assert( IsActor( entity ) );
74 
75  localDeltaVector = GetMoveDelta( animation, 0, 1, entity );
76  endPoint = entity LocalToWorldCoords( localDeltaVector );
77  endPoint = ( endPoint[0], endPoint[1], entity.origin[2] );
78 
79  if( entity MayMoveToPoint( endPoint, false, false ) )
80  {
81  PixEndEvent();
82  return true;
83  }
84 
85  PixEndEvent();
86  return false;
87 }
88 
89 function private ‪Evaluator_CheckAnimationForOverShootingGoal( entity, animation )
90 {
91  PixBeginEvent( "Evaluator_CheckAnimationForOverShootingGoal" );
92 
93  assert( IsActor( entity ) );
94 
95  localDeltaVector = GetMoveDelta( animation, 0, 1, entity );
96  endPoint = entity LocalToWorldCoords( localDeltaVector );
97  animDistSq = LengthSquared( localDeltaVector );
98 
99  if( entity HasPath() )
100  {
101  startPos = entity.origin;
102  goalPos = entity.pathGoalPos;
103 
104  assert( IsDefined( goalPos ) );
105  distToGoalSq = DistanceSquared( startPos, goalPos );
106 
107  // goal is straight in front of the AI, just make sure that the endpoint is not beyond the goal position
108  if( animDistSq < distToGoalSq )
109  {
110  PixEndEvent();
111  return true;
112  }
113  }
114 
115  PixEndEvent();
116  return false;
117 }
118 
119 function private ‪Evaluator_CheckAnimationAgainstNavmesh( entity, animation )
120 {
121  assert( IsActor( entity ) );
122 
123  localDeltaVector = GetMoveDelta( animation, 0, 1, entity );
124  endPoint = entity LocalToWorldCoords( localDeltaVector );
125 
126  // make sure that the point is on the navmesh and away from boundary
127  if( IsPointOnNavMesh( endPoint, entity ) )
128  return true;
129 
130  return false;
131 }
132 
133 function private ‪Evaluator_CheckAnimationArrivalPosition( entity, animation )
134 {
135  localDeltaVector = GetMoveDelta( animation, 0, 1, entity );
136  endPoint = entity LocalToWorldCoords( localDeltaVector );
137  animDistSq = LengthSquared( localDeltaVector );
138 
139  startPos = entity.origin;
140  goalPos = entity.pathGoalPos;
141 
142  distToGoalSq = DistanceSquared( startPos, goalPos );
143 
144  return distToGoalSq < animDistSq && entity IsPosAtGoal( endPoint );
145 }
146 
147 function private ‪Evaluator_FindFirstValidAnimation( entity, animations, tests )
148 {
149  assert( IsArray( animations ), "An array of animations must be passed in to validate against." );
150  assert( IsArray( tests ), "An array of test functions must be passed in to validate an animation." );
151 
152  // Only check the first animation within the group of animations, since each animation is synonymous with each other.
153  foreach ( aliasAnimations in animations )
154  {
155  if ( aliasAnimations.size > 0 )
156  {
157  valid = true;
158  animation = aliasAnimations[0];
159 
160  foreach ( test in tests )
161  {
162  if ( ![[test]]( entity, animation ) )
163  {
164  valid = false;
165  break;
166  }
167  }
168 
169  if ( valid )
170  {
171  return animation;
172  }
173  }
174  }
175 }
176 
177 // ------- EVALUATOR BLOCKED BY GEO ANIMATIONS -----------//
178 function private ‪evaluateBlockedAnimations( entity, animations )
179 {
180  if( animations.size > 0 )
181  {
183  entity,
184  animations,
185  ‪array(
188  }
189 
190  return undefined;
191 
192 }
193 
194 
195 function private ‪evaluateHumanTurnAnimations( entity, animations )
196 {
197  /#
198  // SUMEET - Added this check just for testing.
199  if( ‪IS_TRUE( level.ai_dontTurn ) )
200  return undefined;
201  #/
202 
203  /#
204  Record3DText( "" + GetTime() + ": Turn Evaluator", entity.origin, ‪ORANGE, "Animscript", entity );
205  #/
206 
207  if( animations.size > 0 )
208  {
210  entity,
211  animations,
212  ‪array(
216  }
217 
218  return undefined;
219 }
220 
221 
222 function private ‪evaluateHumanExposedArrivalAnimations( entity, animations )
223 {
224  if( !IsDefined( entity.pathGoalPos ) )
225  return undefined;
226 
227  if( animations.size > 0 )
228  {
230  entity,
231  animations,
233  }
234 
235  return undefined;
236 }
‪testFunction
‪function testFunction(entity, animations)
Definition: animation_selector_table_evaluators.gsc:22
‪Evaluator_CheckAnimationEndPointAgainstGeo
‪function private Evaluator_CheckAnimationEndPointAgainstGeo(entity, animation)
Definition: animation_selector_table_evaluators.gsc:69
‪evaluateHumanTurnAnimations
‪function private evaluateHumanTurnAnimations(entity, animations)
Definition: animation_selector_table_evaluators.gsc:195
‪evaluateBlockedAnimations
‪function private evaluateBlockedAnimations(entity, animations)
Definition: animation_selector_table_evaluators.gsc:178
‪Evaluator_FindFirstValidAnimation
‪function private Evaluator_FindFirstValidAnimation(entity, animations, tests)
Definition: animation_selector_table_evaluators.gsc:147
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪RegisterASTScriptFunctions
‪function autoexec RegisterASTScriptFunctions()
Definition: animation_selector_table_evaluators.gsc:8
‪Evaluator_CheckAnimationArrivalPosition
‪function private Evaluator_CheckAnimationArrivalPosition(entity, animation)
Definition: animation_selector_table_evaluators.gsc:133
‪array
‪function filter array
Definition: array_shared.csc:16
‪Evaluator_CheckAnimationAgainstGeo
‪function private Evaluator_CheckAnimationAgainstGeo(entity, animation)
Definition: animation_selector_table_evaluators.gsc:30
‪evaluateHumanExposedArrivalAnimations
‪function private evaluateHumanExposedArrivalAnimations(entity, animations)
Definition: animation_selector_table_evaluators.gsc:222
‪ORANGE
‪#define ORANGE
Definition: shared.gsh:179
‪Evaluator_CheckAnimationForOverShootingGoal
‪function private Evaluator_CheckAnimationForOverShootingGoal(entity, animation)
Definition: animation_selector_table_evaluators.gsc:89
‪Evaluator_CheckAnimationAgainstNavmesh
‪function private Evaluator_CheckAnimationAgainstNavmesh(entity, animation)
Definition: animation_selector_table_evaluators.gsc:119