1 #define _ATTRIBUTE_CALLBACK "callback"
2 #define _ATTRIBUTE_DEFAULT_VALUE "default_value"
3 #define _ATTRIBUTE_MAX_VALUE "max_value"
4 #define _ATTRIBUTE_MIN_VALUE "min_value"
5 #define _ATTRIBUTE_TYPE "type"
6 #define _ATTRIBUTE_VALUES "values"
7 #define _INTERFACE_MATCH_TYPE "_interface_match"
8 #define _INTERFACE_NUMERIC_TYPE "_interface_numeric"
9 #define _INTERFACE_VECTOR_TYPE "_interface_vector"
14 level.__ai_debugInterface = GetDvarInt(
"ai_debugInterface" );
21 attribute = level.__ai_interface[ archetype ][ attributeName ];
28 assert( !IsArray( possibleValues ) || IsInArray( possibleValues, value ),
29 "AI: \"" + value +
"\" is not one of the allowed values for attribute \"" +
30 attributeName +
"\"." );
37 assert( IsInt( value ) || IsFloat( value ),
"AI: Attribute \"" + attributeName +
38 "\" requires a numeric value and \"" + value +
"\" does not qualify." );
39 assert( ( !IsDefined( maxValue ) && !IsDefined( minValue ) ) ||
40 ( value <= maxValue && value >= minValue ),
41 "AI: \"" + value +
"\" is outside the allowed range of (" + minValue +
"," +
46 if ( IsDefined( value ) )
47 assert( IsVec( value ),
"AI: Attribute \"" + attributeName +
48 "\" requires a vector value and \"" + value +
"\" does not qualify." );
53 "\" for attribute \"" + attributeName +
"\"." );
62 assert( IsEntity( entity ),
"AI: Must pass an entity to access an attribute." );
63 assert( IsActor( entity ) || IsVehicle( entity ),
"AI: Must pass an actor or vehicle to access an attribute." );
64 assert( IsString( attribute ),
"AI: Must pass in a valid attribute name." );
67 if ( IsDefined( level.__ai_debugInterface ) && level.__ai_debugInterface > 0 )
69 assert( IsArray( entity.__interface ),
70 "AI: Entity(" + entity.archetype +
") must create an interface before accessing an " +
71 "attribute, see \"ai::CreateInterfaceForEntity\"." );
72 assert( IsArray( level.__ai_interface ),
73 "AI: No attributes have been registered with the AI interface system yet." );
74 assert( IsArray( level.__ai_interface[ entity.archetype ] ),
75 "AI: No attributes for archetype \"" + entity.archetype +
"\" have been registered." );
76 assert( IsArray( level.__ai_interface[ entity.archetype ][ attribute ] ),
77 "AI: Attribute \"" + attribute +
"\" has not been registered for archetype \"" +
78 entity.archetype +
"\" yet." );
79 assert( IsString( level.__ai_interface[ entity.archetype ][ attribute ][
_ATTRIBUTE_TYPE ] ),
80 "AI: Attribute type is undefined for \"" + attribute +
"\"." );
88 assert( IsString( archetype ),
"AI: \"archetype\" value is mandatory for registration." );
89 assert( IsString( attribute ),
"AI: \"attribute\" value is mandatory for registration." );
90 assert( !IsDefined( callbackFunction ) || IsFunctionPtr( callbackFunction ),
91 "AI: \"callbackFunction\" is optional but must be a function pointer if specified." );
97 if ( !IsDefined( level.__ai_interface ) )
99 level.__ai_interface = [];
102 if ( !IsDefined( level.__ai_interface[ archetype ] ) )
104 level.__ai_interface[ archetype ] = [];
112 if ( !IsDefined( entity.__interface ) )
114 entity.__interface = [];
124 if ( !IsDefined( entity.__interface[ attribute ] ) )
129 return entity.__interface[ attribute ];
135 IsDefined( entity ) &&
136 IsDefined( attribute ) &&
137 IsDefined( entity.archetype ) &&
138 IsDefined( level.__ai_interface ) &&
139 IsDefined( level.__ai_interface[ entity.archetype ] ) &&
140 IsDefined( level.__ai_interface[ entity.archetype ][ attribute ] );
147 assert( !IsDefined( possibleValues ) || IsArray( possibleValues ),
148 "AI: \"possibleValues\" is optional but must be an array if specified." );
154 assert( !IsDefined( level.__ai_interface[ archetype ][ attribute ] ),
155 "AI: \"" + attribute +
"\" is already registered for archetype \"" + archetype +
"\"" );
158 level.__ai_interface[ archetype ][ attribute ] = [];
162 level.__ai_interface[ archetype ][ attribute ][
_ATTRIBUTE_VALUES ] = possibleValues;
173 assert( !IsDefined( minimum ) || IsInt( minimum ) || IsFloat( minimum ),
174 "AI: \"minimum\" is optional but must be a numeric if specified." );
175 assert( !IsDefined( maximum ) || IsInt( maximum ) || IsFloat( maximum ),
176 "AI: \"maximum\" is optional but must be a numeric if specified." );
177 assert( ( !IsDefined( minimum ) && !IsDefined( maximum ) ) ||
178 ( IsDefined( minimum ) && IsDefined( maximum ) ),
179 "AI: Either both a minimum and maximum must be defined or both undefined, not mixed.");
180 assert( ( !IsDefined( minimum ) && !IsDefined( maximum ) ) ||
181 ( minimum <= maximum ),
182 "AI: Attribute \"" + attribute +
"\" cannot specify a minimum greater than " +
183 "the attribute's maximum");
189 assert( !IsDefined( level.__ai_interface[ archetype ][ attribute ] ),
190 "AI: \"" + attribute +
"\" is already registered for archetype \"" + archetype +
"\"" );
193 level.__ai_interface[ archetype ][ attribute ] = [];
214 assert( !IsDefined( level.__ai_interface[ archetype ][ attribute ] ),
215 "AI: \"" + attribute +
"\" is already registered for archetype \"" + archetype +
"\"" );
218 level.__ai_interface[ archetype ][ attribute ] = [];
235 oldValue = entity.__interface[ attribute ];
237 if ( !IsDefined( oldValue ) )
242 entity.__interface[ attribute ] = value;
248 [[
callback]]( entity, attribute, oldValue, value );