Class: AIProxy

AIProxy()

new AIProxy()

Source:

Methods

Init()

AIProxy passes its entity's state data to AI scripts. Efficiency is critical: there can be many thousands of entities, and the data returned by this component is serialized and copied to the AI thread every turn, so it can be quite expensive. We omit all data that can be derived statically from the template XML files - the AI scripts can parse the templates themselves. This violates the component interface abstraction and is potentially fragile if the template formats change (since both the component code and the AI will have to be updated in sync), but it's not *that* bad really and it helps performance significantly. We also add an optimisation to avoid copying non-changing values. The first call to GetRepresentation calls GetFullRepresentation, which constructs the complete entity state representation. After that, we simply listen to events from the rest of the gameplay code, and store the changed data in this.changes. Properties in this.changes will override those previously returned from GetRepresentation; if a property isn't overridden then the AI scripts will keep its old value. The event handlers should set this.changes.whatever to exactly the same as GetFullRepresentation would set.
Source: