forked from 0ad/0ad
Ykkrosh
dd501b2a5a
Support direct access to serializer streams, so serializers can be nested. Make component script "this.template" read-only. Stop globally-subscribed component scripts receiving messages posted to local components, to reduce out-of-sync risks. Move pathfinder data out of entity template directory. Fix GuiInterface deserialization. This was SVN commit r8865.
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
function AIInterface() {}
|
|
|
|
AIInterface.prototype.Schema =
|
|
"<a:component type='system'/><empty/>";
|
|
|
|
AIInterface.prototype.Init = function()
|
|
{
|
|
this.events = [];
|
|
};
|
|
|
|
AIInterface.prototype.GetRepresentation = function()
|
|
{
|
|
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
|
|
|
// Return the same game state as the GUI uses
|
|
var state = cmpGuiInterface.GetSimulationState(-1);
|
|
|
|
// Add some extra AI-specific data
|
|
state.events = this.events;
|
|
|
|
// Reset the event list for the next turn
|
|
this.events = [];
|
|
|
|
return state;
|
|
};
|
|
|
|
// Set up a load of event handlers to capture interesting things going on
|
|
// in the world, which we will report to AI:
|
|
// (This shouldn't include extremely high-frequency events, like PositionChanged,
|
|
// because that would be very expensive and AI will rarely care about all those
|
|
// events.)
|
|
|
|
AIInterface.prototype.OnGlobalCreate = function(msg)
|
|
{
|
|
this.events.push({"type": "Create", "msg": msg});
|
|
};
|
|
|
|
AIInterface.prototype.OnGlobalDestroy = function(msg)
|
|
{
|
|
this.events.push({"type": "Destroy", "msg": msg});
|
|
};
|
|
|
|
AIInterface.prototype.OnGlobalOwnershipChanged = function(msg)
|
|
{
|
|
this.events.push({"type": "OwnershipChanged", "msg": msg});
|
|
};
|
|
|
|
AIInterface.prototype.OnGlobalAttacked = function(msg)
|
|
{
|
|
this.events.push({"type": "Attacked", "msg": msg});
|
|
};
|
|
|
|
AIInterface.prototype.OnGlobalConstructionFinished = function(msg)
|
|
{
|
|
this.events.push({"type": "ConstructionFinished", "msg": msg});
|
|
};
|
|
|
|
AIInterface.prototype.OnGlobalPlayerDefeated = function(msg)
|
|
{
|
|
this.events.push({"type": "PlayerDefeated", "msg": msg});
|
|
};
|
|
|
|
Engine.RegisterComponentType(IID_AIInterface, "AIInterface", AIInterface);
|