# Fix units killing their own farms
This was SVN commit r8343.
This commit is contained in:
parent
8abfa5ec89
commit
c1967848d2
@ -6,6 +6,9 @@ ResourceSupply.prototype.Schema =
|
||||
"<Amount>1000</Amount>" +
|
||||
"<Type>food.meat</Type>" +
|
||||
"</a:example>" +
|
||||
"<element name='KillBeforeGather' a:help='Whether this entity must be killed (health reduced to 0) before its resources can be gathered'>" +
|
||||
"<data type='boolean'/>" +
|
||||
"</element>" +
|
||||
"<element name='Amount' a:help='Amount of resources available from this entity'>" +
|
||||
"<data type='nonNegativeInteger'/>" +
|
||||
"</element>" +
|
||||
@ -29,6 +32,11 @@ ResourceSupply.prototype.Init = function()
|
||||
this.amount = this.GetMaxAmount();
|
||||
};
|
||||
|
||||
ResourceSupply.prototype.GetKillBeforeGather = function()
|
||||
{
|
||||
return (this.template.KillBeforeGather == "true");
|
||||
};
|
||||
|
||||
ResourceSupply.prototype.GetMaxAmount = function()
|
||||
{
|
||||
return +this.template.Amount;
|
||||
|
@ -117,7 +117,7 @@ var UnitFsmSpec = {
|
||||
|
||||
"Order.Gather": function(msg) {
|
||||
// If the target is still alive, we need to kill it first
|
||||
if (this.TargetIsAlive(this.order.data.target))
|
||||
if (this.MustKillGatherTarget(this.order.data.target))
|
||||
{
|
||||
// Make sure we can attack the target, else we'll get very stuck
|
||||
if (!this.GetBestAttack())
|
||||
@ -727,6 +727,9 @@ UnitAI.prototype.GetRunSpeed = function()
|
||||
return cmpMotion.GetRunSpeed();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the target exists and has non-zero hitpoints.
|
||||
*/
|
||||
UnitAI.prototype.TargetIsAlive = function(ent)
|
||||
{
|
||||
var cmpHealth = Engine.QueryInterface(ent, IID_Health);
|
||||
@ -736,6 +739,22 @@ UnitAI.prototype.TargetIsAlive = function(ent)
|
||||
return (cmpHealth.GetHitpoints() != 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the target exists and needs to be killed before
|
||||
* beginning to gather resources from it.
|
||||
*/
|
||||
UnitAI.prototype.MustKillGatherTarget = function(ent)
|
||||
{
|
||||
var cmpResourceSupply = Engine.QueryInterface(ent, IID_ResourceSupply);
|
||||
if (!cmpResourceSupply)
|
||||
return false;
|
||||
|
||||
if (!cmpResourceSupply.GetKillBeforeGather())
|
||||
return false;
|
||||
|
||||
return this.TargetIsAlive(ent);
|
||||
};
|
||||
|
||||
/**
|
||||
* Play a sound appropriate to the current entity.
|
||||
*/
|
||||
|
@ -13,6 +13,7 @@
|
||||
</Minimap>
|
||||
<Selectable/>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>false</KillBeforeGather>
|
||||
<Amount>120</Amount>
|
||||
<Type>food.fruit</Type>
|
||||
</ResourceSupply>
|
||||
|
@ -11,6 +11,7 @@
|
||||
</Minimap>
|
||||
<Selectable/>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>false</KillBeforeGather>
|
||||
<Amount>150</Amount>
|
||||
<Type>wood.tree</Type>
|
||||
</ResourceSupply>
|
||||
|
@ -12,6 +12,7 @@
|
||||
</Minimap>
|
||||
<Selectable/>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>false</KillBeforeGather>
|
||||
<Amount>500</Amount>
|
||||
<Type>metal.ore</Type>
|
||||
</ResourceSupply>
|
||||
|
@ -5,7 +5,6 @@
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<Amount>5000</Amount>
|
||||
<Type>metal.ore</Type>
|
||||
</ResourceSupply>
|
||||
<StatusBars>
|
||||
<BarWidth>6.0</BarWidth>
|
||||
|
@ -12,6 +12,7 @@
|
||||
</Minimap>
|
||||
<Selectable/>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>false</KillBeforeGather>
|
||||
<Amount>500</Amount>
|
||||
<Type>stone.rock</Type>
|
||||
</ResourceSupply>
|
||||
|
@ -13,6 +13,7 @@
|
||||
</Resources>
|
||||
</Cost>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>false</KillBeforeGather>
|
||||
<Amount>200</Amount>
|
||||
<Type>food.milk</Type>
|
||||
</ResourceSupply>
|
||||
|
@ -16,6 +16,7 @@
|
||||
</Resources>
|
||||
</Cost>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>false</KillBeforeGather>
|
||||
<Amount>1000</Amount>
|
||||
<Type>food.grain</Type>
|
||||
</ResourceSupply>
|
||||
|
@ -18,6 +18,7 @@
|
||||
<UnitMotion disable=""/>
|
||||
<AnimalAI disable=""/>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>false</KillBeforeGather>
|
||||
<Amount>500</Amount>
|
||||
<Type>food.fish</Type>
|
||||
</ResourceSupply>
|
||||
|
@ -4,6 +4,7 @@
|
||||
<DeathType>remain</DeathType>
|
||||
</Health>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>true</KillBeforeGather>
|
||||
<Amount>100</Amount>
|
||||
<Type>food.meat</Type>
|
||||
</ResourceSupply>
|
||||
|
@ -4,6 +4,7 @@
|
||||
<DeathType>remain</DeathType>
|
||||
</Health>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>true</KillBeforeGather>
|
||||
<Amount>100</Amount>
|
||||
<Type>food.meat</Type>
|
||||
</ResourceSupply>
|
||||
|
Loading…
Reference in New Issue
Block a user