2011-01-12 13:29:00 +01:00
|
|
|
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 = [];
|
|
|
|
|
2011-01-16 00:35:20 +01:00
|
|
|
// Add entity representations
|
|
|
|
state.entities = {};
|
|
|
|
for each (var proxy in Engine.GetComponentsWithInterface(IID_AIProxy))
|
|
|
|
{
|
|
|
|
var rep = proxy.GetRepresentation();
|
|
|
|
if (rep !== null)
|
|
|
|
state.entities[proxy.entity] = rep;
|
|
|
|
}
|
|
|
|
|
2011-01-12 13:29:00 +01:00
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
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);
|