force garrisoned units as turrets to have stance standground, fixes #2905

This was SVN commit r16318.
This commit is contained in:
mimo 2015-02-11 18:34:06 +00:00
parent 04fa2dd4ec
commit cd9eeef1b7
3 changed files with 32 additions and 1 deletions

View file

@ -242,6 +242,9 @@ GarrisonHolder.prototype.Garrison = function(entity)
vgp.entity = entity;
cmpPosition.SetTurretParent(this.entity, vgp.offset);
visiblyGarrisoned = true;
var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
if (cmpUnitAI)
cmpUnitAI.SetTurretStance();
break;
}
if (!visiblyGarrisoned)
@ -337,6 +340,9 @@ GarrisonHolder.prototype.Eject = function(entity, forced)
if (vgp.entity != entity)
continue;
cmpNewPosition.SetTurretParent(INVALID_ENTITY, new Vector3D());
var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
if (cmpUnitAI)
cmpUnitAI.ResetTurretStance();
vgp.entity = null;
break;
}

View file

@ -5284,6 +5284,29 @@ UnitAI.prototype.SwitchToStance = function(stance)
this.SetupRangeQueries();
};
UnitAI.prototype.SetTurretStance = function()
{
this.previousStance = undefined;
if (this.GetStance().respondStandGround)
return;
for (let stance in g_Stances)
{
if (!g_Stances[stance].respondStandGround)
continue;
this.previousStance = this.GetStanceName();
this.SwitchToStance(stance);
return;
}
};
UnitAI.prototype.ResetTurretStance = function()
{
if (!this.previousStance)
return;
this.SwitchToStance(this.previousStance);
this.previousStance = undefined;
};
/**
* Resets losRangeQuery, and if there are some targets in range that we can
* attack then we start attacking and this returns true; otherwise, returns false.
@ -5468,6 +5491,8 @@ UnitAI.prototype.GetStance = function()
UnitAI.prototype.GetPossibleStances = function()
{
if (this.IsTurret())
return [];
return Object.keys(g_Stances);
};

View file

@ -548,7 +548,7 @@ var commands = {
for each (var ent in data.entities)
{
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
if (cmpUnitAI)
if (cmpUnitAI && !cmpUnitAI.IsTurret())
cmpUnitAI.SwitchToStance(cmd.name);
}
},