‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
ai_blackboard.gsc
Go to the documentation of this file.
1 #insert scripts\shared\shared.gsh;
2 
3 #define _BLACKBOARD_UPDATE_RATE 1
4 
5 #namespace Blackboard;
6 
7 function autoexec ‪main()
8 {
10 }
11 
12 function private ‪_InitializeBlackboard()
13 {
14  level.__ai_blackboard = [];
15  level thread ‪_UpdateEvents();
16 }
17 
18 function private ‪_UpdateEvents()
19 {
21  updateMillis = waitTime * 1000;
22 
23  while ( true )
24  {
25  foreach ( eventName, events in level.__ai_blackboard )
26  {
27  liveEvents = [];
28 
29  // Reduce time to live, and only keep events that still have addition time to live.
30  foreach ( event in events )
31  {
32  event.ttl = event.ttl - updateMillis;
33 
34  if ( event.ttl > 0 )
35  {
36  liveEvents[ liveEvents.size ] = event;
37  }
38  }
39 
40  level.__ai_blackboard[ eventName ] = liveEvents;
41  }
42 
43  wait waitTime;
44  }
45 }
46 
47 function ‪AddBlackboardEvent( eventName, data, timeToLiveInMillis )
48 {
49  /#
50  assert( IsString( eventName ), "Must pass in an event name when adding an event to the blackboard." );
51  assert( IsDefined( data ), "Must pass in some type of data to store as an event." );
52  assert( IsInt( timeToLiveInMillis ) && timeToLiveInMillis > 0,
53  "Must pass in a positive time to live value for the lifespan of the event." );
54  #/
55 
56  event = SpawnStruct();
57  event.data = data;
58  event.timestamp = GetTime();
59  event.ttl = timeToLiveInMillis;
60 
61  ‪ARRAY_ADD( level.__ai_blackboard[eventName], event );
62 }
63 
64 function ‪GetBlackboardEvents( eventName )
65 {
66  if ( IsDefined( level.__ai_blackboard[eventName] ) )
67  {
68  return level.__ai_blackboard[eventName];
69  }
70 
71  return [];
72 }
73 
74 function ‪RemoveBlackboardEvents( eventName )
75 {
76  if ( IsDefined( level.__ai_blackboard[eventName] ) )
77  {
78  level.__ai_blackboard[eventName] = undefined;
79  }
80 }
‪_BLACKBOARD_UPDATE_RATE
‪#define _BLACKBOARD_UPDATE_RATE
Definition: ai_blackboard.gsc:3
‪ARRAY_ADD
‪#define ARRAY_ADD(__array, __item)
Definition: shared.gsh:304
‪SERVER_FRAME
‪#define SERVER_FRAME
Definition: shared.gsh:264
‪AddBlackboardEvent
‪function AddBlackboardEvent(eventName, data, timeToLiveInMillis)
Definition: ai_blackboard.gsc:47
‪RemoveBlackboardEvents
‪function RemoveBlackboardEvents(eventName)
Definition: ai_blackboard.gsc:74
‪main
‪function autoexec main()
Definition: ai_blackboard.gsc:7
‪_InitializeBlackboard
‪function private _InitializeBlackboard()
Definition: ai_blackboard.gsc:12
‪_UpdateEvents
‪function private _UpdateEvents()
Definition: ai_blackboard.gsc:18
‪GetBlackboardEvents
‪function GetBlackboardEvents(eventName)
Definition: ai_blackboard.gsc:64