# Partial support for saved games with AI.

Support cancelling loads while inside a loader callback.
Fix use of ArchiveReader/Writer since their API changed.
Improve error-detection in deserializer to avoid crashes.
Report deserializer errors to users.
Expand load-error message box to fit message about invalid saved games.

This was SVN commit r10787.
This commit is contained in:
Ykkrosh
2011-12-22 14:04:32 +00:00
parent 5f0d5e4137
commit 6399ec0cd2
14 changed files with 202 additions and 117 deletions
@@ -16,7 +16,7 @@ function cancelOnError(msg)
if (msg)
{
Engine.PushGuiPage("page_msgbox.xml", {
width: 400,
width: 500,
height: 200,
message: '[font="serif-bold-18"]' + msg + '[/font]',
title: "Loading Aborted",
@@ -3,16 +3,41 @@ function BaseAI(settings)
if (!settings)
return;
// Make some properties non-enumerable, so they won't be serialised
Object.defineProperty(this, "_player", {value: settings.player, enumerable: false});
Object.defineProperty(this, "_templates", {value: settings.templates, enumerable: false});
Object.defineProperty(this, "_derivedTemplates", {value: {}, enumerable: false});
// Copies of static engine data (not serialized)
this._player = settings.player;
this._templates = settings.templates;
this._derivedTemplates = {};
// Representation of the current world state (requires serialization)
this._rawEntities = null;
this._ownEntities = {};
this._entityMetadata = {};
}
// Return a simple object (using no classes etc) that will be serialized
// into saved games
BaseAI.prototype.Serialize = function()
{
return {
_rawEntities: this._rawEntities,
_ownEntities: this._ownEntities,
_entityMetadata: this._entityMetadata,
};
// TODO: ought to get the AI script subclass to serialize its own state
};
// Called after the constructor when loading a saved game, with 'data' being
// whatever Serialize() returned
BaseAI.prototype.Deserialize = function(data)
{
this._rawEntities = data._rawEntities;
this._ownEntities = data._ownEntities;
this._entityMetadata = data._entityMetadata;
// TODO: ought to get the AI script subclass to deserialize its own state
};
// Components that will be disabled in foundation entity templates.
// (This is a bit yucky and fragile since it's the inverse of
// CCmpTemplateManager::CopyFoundationSubset and only includes components
@@ -160,7 +185,8 @@ BaseAI.prototype.ApplyEntitiesDelta = function(state)
};
BaseAI.prototype.OnUpdate = function()
{ // AIs override this function
{
// AIs override this function
};
BaseAI.prototype.chat = function(message)
@@ -2,6 +2,8 @@ function InitGame(settings)
{
// This will be called after the map settings have been loaded,
// before the simulation has started.
// This is only called at the start of a new game, not when loading
// a saved game.
// No settings when loading a map in Atlas, so do nothing
if (!settings)