Units should only be able to build structures from their owner's civ, and not from their identity civ

Reviewed By: elexis
Trac Tickets: #4870

Differential Revision: https://code.wildfiregames.com/D1065
This was SVN commit r20521.
This commit is contained in:
mimo
2017-11-25 16:22:03 +00:00
parent 60ae523f92
commit 3a5be78aa9
3 changed files with 14 additions and 12 deletions
@@ -810,9 +810,10 @@ m.GameState.prototype.findTrainers = function(template)
*/
m.GameState.prototype.findBuilder = function(template)
{
let civ = this.getPlayerCiv();
for (let ent of this.getOwnUnits().values())
{
let buildable = ent.buildableEntities();
let buildable = ent.buildableEntities(civ);
if (buildable && buildable.indexOf(template) !== -1)
return ent;
}
@@ -38,10 +38,16 @@ m.ConstructionPlan.prototype.start = function(gameState)
{
Engine.ProfileStart("Building construction start");
// We don't care which builder we assign, since they won't actually
// do the building themselves - all we care about is that there is
// at least one unit that can start the foundation
// We don't care which builder we assign, since they won't actually do
// the building themselves - all we care about is that there is at least
// one unit that can start the foundation (should always be the case here).
let builder = gameState.findBuilder(this.type);
if (!builder)
{
API3.warn("petra error: builder not found when starting construction.");
Engine.ProfileStop();
return;
}
let pos = this.findGoodPosition(gameState);
if (!pos)
@@ -27,19 +27,14 @@ Builder.prototype.Serialize = null; // we have no dynamic state to save
Builder.prototype.GetEntitiesList = function()
{
let string = this.template.Entities._string;
if (!string)
return [];
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
if (cmpIdentity)
string = string.replace(/\{civ\}/g, cmpIdentity.GetCiv());
let entities = string.split(/\s+/);
let cmpPlayer = QueryOwnerInterface(this.entity);
if (!cmpPlayer)
return entities;
return [];
let entities = string.replace(/\{civ\}/g, cmpPlayer.GetCiv()).split(/\s+/);
let disabledTemplates = cmpPlayer.GetDisabledTemplates();