fixes remaining town bell defects, closes #2353, patch by Itms
This was SVN commit r14689.
This commit is contained in:
parent
c61badb04c
commit
cbc1c9f0ab
@ -37,29 +37,17 @@ AlertRaiser.prototype.SoundAlert = function()
|
||||
PlaySound(alertString, this.entity);
|
||||
};
|
||||
|
||||
AlertRaiser.prototype.UpdateUnits = function()
|
||||
{
|
||||
// Find units owned by this unit's player
|
||||
var players = [];
|
||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
||||
if (cmpOwnership)
|
||||
players = [cmpOwnership.GetOwner()];
|
||||
|
||||
// Select units to put under alert, ignoring domestic animals (NB : war dogs are not domestic)
|
||||
var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
||||
var level = this.GetLevel();
|
||||
var units = rangeMan.ExecuteQuery(this.entity, 0, this.template.Range, players, IID_UnitAI).filter( function(e){
|
||||
var cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI);
|
||||
return (!cmpUnitAI.IsUnderAlert() && cmpUnitAI.ReactsToAlert(level) && !cmpUnitAI.IsDomestic());
|
||||
});
|
||||
|
||||
AlertRaiser.prototype.UpdateUnits = function(units)
|
||||
{
|
||||
for each (var unit in units)
|
||||
{
|
||||
var cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI);
|
||||
if (!cmpUnitAI)
|
||||
continue;
|
||||
cmpUnitAI.ReplaceOrder("Alert", {"raiser": this.entity, "force": true});
|
||||
this.walkingUnits.push(unit);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AlertRaiser.prototype.IncreaseAlertLevel = function()
|
||||
{
|
||||
@ -69,12 +57,12 @@ AlertRaiser.prototype.IncreaseAlertLevel = function()
|
||||
this.level++;
|
||||
this.SoundAlert();
|
||||
|
||||
// Find buildings owned by this unit's player
|
||||
// Find buildings/units owned by this unit's player
|
||||
var players = [];
|
||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
||||
if (cmpOwnership)
|
||||
players = [cmpOwnership.GetOwner()];
|
||||
|
||||
|
||||
// Select production buildings to put "under alert", including the raiser itself if possible
|
||||
var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
||||
var level = this.GetLevel();
|
||||
@ -82,59 +70,72 @@ AlertRaiser.prototype.IncreaseAlertLevel = function()
|
||||
var ownCmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue);
|
||||
if (ownCmpProductionQueue)
|
||||
buildings.push(this.entity);
|
||||
|
||||
|
||||
for each (var building in buildings)
|
||||
{
|
||||
var cmpProductionQueue = Engine.QueryInterface(building, IID_ProductionQueue);
|
||||
cmpProductionQueue.PutUnderAlert(this.entity);
|
||||
this.prodBuildings.push(building);
|
||||
}
|
||||
|
||||
// Put units under alert
|
||||
this.UpdateUnits();
|
||||
|
||||
|
||||
// Select units to put under alert, ignoring domestic animals (NB : war dogs are not domestic)
|
||||
var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
||||
var level = this.GetLevel();
|
||||
var units = rangeMan.ExecuteQuery(this.entity, 0, this.template.Range, players, IID_UnitAI).filter( function(e){
|
||||
var cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI);
|
||||
return (!cmpUnitAI.IsUnderAlert() && cmpUnitAI.ReactsToAlert(level) && !cmpUnitAI.IsDomestic());
|
||||
});
|
||||
|
||||
for each (var unit in units)
|
||||
{
|
||||
var cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI);
|
||||
cmpUnitAI.ReplaceOrder("Alert", {"raiser": this.entity, "force": true});
|
||||
this.walkingUnits.push(unit);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
AlertRaiser.prototype.OnUnitGarrisonedAfterAlert = function(msg)
|
||||
{
|
||||
this.garrisonedUnits.push({"holder": msg.holder, "unit": msg.unit});
|
||||
|
||||
|
||||
var index = this.walkingUnits.indexOf(msg.unit);
|
||||
if (index != -1)
|
||||
this.walkingUnits.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
AlertRaiser.prototype.EndOfAlert = function()
|
||||
{
|
||||
this.level = 0;
|
||||
this.SoundAlert();
|
||||
|
||||
|
||||
// First, handle units not yet garrisoned
|
||||
for each (var unit in this.walkingUnits)
|
||||
{
|
||||
var cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI);
|
||||
if (!cmpUnitAI)
|
||||
continue;
|
||||
|
||||
|
||||
cmpUnitAI.ResetAlert();
|
||||
|
||||
|
||||
if (cmpUnitAI.HasWorkOrders())
|
||||
cmpUnitAI.BackToWork();
|
||||
else
|
||||
cmpUnitAI.ReplaceOrder("Stop", undefined);
|
||||
}
|
||||
this.walkingUnits = [];
|
||||
|
||||
|
||||
// Then, eject garrisoned units
|
||||
for each (var slot in this.garrisonedUnits)
|
||||
{
|
||||
var cmpGarrisonHolder = Engine.QueryInterface(slot.holder, IID_GarrisonHolder);
|
||||
var cmpUnitAI = Engine.QueryInterface(slot.unit, IID_UnitAI);
|
||||
if (!cmpUnitAI || !cmpGarrisonHolder)
|
||||
if (!cmpUnitAI)
|
||||
continue;
|
||||
|
||||
if(cmpGarrisonHolder && cmpGarrisonHolder.PerformEject([slot.unit], true))
|
||||
|
||||
// If the garrison building was destroyed, the unit is already ejected
|
||||
if (!cmpGarrisonHolder || cmpGarrisonHolder.PerformEject([slot.unit], true))
|
||||
{
|
||||
cmpUnitAI.ResetAlert();
|
||||
if (cmpUnitAI.HasWorkOrders())
|
||||
@ -151,7 +152,7 @@ AlertRaiser.prototype.EndOfAlert = function()
|
||||
cmpProductionQueue.ResetAlert();
|
||||
}
|
||||
this.prodBuildings = [];
|
||||
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -609,7 +609,7 @@ ProductionQueue.prototype.SpawnUnits = function(templateName, count, metadata)
|
||||
{
|
||||
var cmpAlertRaiser = Engine.QueryInterface(this.alertRaiser, IID_AlertRaiser);
|
||||
if(cmpAlertRaiser)
|
||||
cmpAlertRaiser.UpdateUnits();
|
||||
cmpAlertRaiser.UpdateUnits(createdEnts);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user