Template loading from the AI

Patch by Sandarac

Reviewed By: mimo
Trac Tickets: #4611

Differential Revision: https://code.wildfiregames.com/D639
This was SVN commit r20162.
This commit is contained in:
mimo
2017-09-11 16:23:54 +00:00
parent 57c8473783
commit 8f05358b5e
4 changed files with 10 additions and 69 deletions
@@ -786,9 +786,10 @@ m.Entity = m.Class({
{
if (!this.get("Attack/Capture"))
return false;
if (!target)
return true;
if (!target.get("Capturable"))
return false;
let restrictedClasses = this.get("Attack/Capture/RestrictedClasses/_string");
return !restrictedClasses || !MatchesClassList(target.classes(), restrictedClasses);
},
@@ -797,7 +798,7 @@ m.Entity = m.Class({
"canGuard": function() { return this.get("UnitAI/CanGuard") === "true"; },
"canGarrison": function() { return this.get("Garrisonable") !== "false"; },
"canGarrison": function() { return "Garrisonable" in this._template; },
move: function(x, z, queued = false) {
Engine.PostCommand(PlayerID,{"type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued });
@@ -54,33 +54,6 @@ m.SharedScript.prototype.Deserialize = function(data)
this.isDeserialized = true;
};
/**
* 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
* that our Template class currently uses.)
*/
m.g_FoundationForbiddenComponents = {
"ProductionQueue": 1,
"ResourceSupply": 1,
"ResourceDropsite": 1,
"GarrisonHolder": 1,
"Capturable": 1
};
/**
* Components that will be disabled in resource entity templates.
* Roughly the inverse of CCmpTemplateManager::CopyResourceSubset.
*/
m.g_ResourceForbiddenComponents = {
"Cost": 1,
"Decay": 1,
"Health": 1,
"UnitAI": 1,
"UnitMotion": 1,
"Vision": 1
};
m.SharedScript.prototype.GetTemplate = function(name)
{
if (this._templates[name])
@@ -89,44 +62,11 @@ m.SharedScript.prototype.GetTemplate = function(name)
if (this._derivedTemplates[name])
return this._derivedTemplates[name];
// If this is a foundation template, construct it automatically
if (name.indexOf("foundation|") !== -1)
let template = Engine.GetTemplate(name);
if (template)
{
let base = this.GetTemplate(name.substr(11));
let foundation = {};
for (let key in base)
if (!m.g_FoundationForbiddenComponents[key])
foundation[key] = base[key];
this._derivedTemplates[name] = foundation;
return foundation;
}
else if (name.indexOf("resource|") !== -1)
{
let base = this.GetTemplate(name.substr(9));
let resource = {};
for (let key in base)
if (!m.g_ResourceForbiddenComponents[key])
resource[key] = base[key];
this._derivedTemplates[name] = resource;
return resource;
}
else if (name.indexOf("ungarrisonable|") !== -1)
{
let base = this.GetTemplate(name.substr(15));
let ent = {};
for (let key in base)
if (key !== "Garrisonable")
ent[key] = base[key];
else
ent[key] = "false";
this._derivedTemplates[name] = ent;
return ent;
this._derivedTemplates[name] = template;
return template;
}
error("Tried to retrieve invalid template '"+name+"'");
@@ -74,9 +74,9 @@ m.BaseManager.prototype.assignEntity = function(gameState, ent)
m.BaseManager.prototype.setAnchor = function(gameState, anchorEntity)
{
if (!anchorEntity.hasClass("Structure") || !anchorEntity.hasTerritoryInfluence())
if (!anchorEntity.hasClass("CivCentre"))
{
warn("Error: Petra base " + this.ID + " has been assigned an anchor building that has no territorial influence.");
warn("Error: Petra base " + this.ID + " has been assigned an anchor that is not a civil centre.");
return false;
}
this.anchor = anchorEntity;
@@ -1139,7 +1139,7 @@ m.HQ.prototype.findMarketLocation = function(gameState, template)
continue;
if (this.basesMap.map[j] === 0) // only in our territory
continue;
// with enough room around to build the cc
// with enough room around to build the market
let i = this.territoryMap.getNonObstructedTile(j, radius, obstructions);
if (i < 0)
continue;