2011-01-12 13:29:00 +01:00
|
|
|
function AIInterface() {}
|
|
|
|
|
|
|
|
AIInterface.prototype.Schema =
|
|
|
|
"<a:component type='system'/><empty/>";
|
|
|
|
|
|
|
|
AIInterface.prototype.Init = function()
|
|
|
|
{
|
|
|
|
this.events = [];
|
2011-03-03 01:16:14 +01:00
|
|
|
this.changedEntities = {};
|
2011-01-12 13:29:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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 = [];
|
|
|
|
|
2011-01-16 00:35:20 +01:00
|
|
|
// Add entity representations
|
2011-03-03 01:16:14 +01:00
|
|
|
Engine.ProfileStart("proxy representations");
|
2011-01-16 00:35:20 +01:00
|
|
|
state.entities = {};
|
2011-03-03 01:16:14 +01:00
|
|
|
for (var id in this.changedEntities)
|
2011-01-16 00:35:20 +01:00
|
|
|
{
|
2011-03-03 01:16:14 +01:00
|
|
|
var aiProxy = Engine.QueryInterface(+id, IID_AIProxy);
|
|
|
|
if (aiProxy)
|
|
|
|
state.entities[id] = aiProxy.GetRepresentation();
|
2011-01-16 00:35:20 +01:00
|
|
|
}
|
2011-03-03 01:16:14 +01:00
|
|
|
this.changedEntities = {};
|
|
|
|
Engine.ProfileStop();
|
2011-01-16 00:35:20 +01:00
|
|
|
|
2011-01-12 13:29:00 +01:00
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
2011-03-03 01:16:14 +01:00
|
|
|
AIInterface.prototype.ChangedEntity = function(ent)
|
|
|
|
{
|
|
|
|
this.changedEntities[ent] = 1;
|
|
|
|
};
|
|
|
|
|
2011-02-05 21:35:34 +01:00
|
|
|
// AIProxy sets up a load of event handlers to capture interesting things going on
|
|
|
|
// in the world, which we will report to AI. Handle those, and add a few more handlers
|
|
|
|
// for events that AIProxy won't capture.
|
2011-01-12 13:29:00 +01:00
|
|
|
|
2011-02-05 21:35:34 +01:00
|
|
|
AIInterface.prototype.PushEvent = function(type, msg)
|
2011-01-12 13:29:00 +01:00
|
|
|
{
|
2011-02-05 21:35:34 +01:00
|
|
|
this.events.push({"type": type, "msg": msg});
|
2011-01-12 13:29:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
AIInterface.prototype.OnGlobalPlayerDefeated = function(msg)
|
|
|
|
{
|
|
|
|
this.events.push({"type": "PlayerDefeated", "msg": msg});
|
|
|
|
};
|
|
|
|
|
|
|
|
Engine.RegisterComponentType(IID_AIInterface, "AIInterface", AIInterface);
|