forked from 0ad/0ad
let farms have the terrain ownership, fixes #3741
This was SVN commit r17654.
This commit is contained in:
parent
c4d9b64fe5
commit
b4d11cf747
@ -296,10 +296,21 @@ Foundation.prototype.Build = function(builderEnt, work)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
||||
|
||||
var owner;
|
||||
var cmpTerritoryDecay = Engine.QueryInterface(building, IID_TerritoryDecay);
|
||||
if (cmpTerritoryDecay && cmpTerritoryDecay.HasTerritoryOwnership())
|
||||
{
|
||||
let cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager);
|
||||
owner = cmpTerritoryManager.GetOwner(pos.x, pos.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
||||
owner = cmpOwnership.GetOwner();
|
||||
}
|
||||
var cmpBuildingOwnership = Engine.QueryInterface(building, IID_Ownership);
|
||||
cmpBuildingOwnership.SetOwner(cmpOwnership.GetOwner());
|
||||
cmpBuildingOwnership.SetOwner(owner);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
|
@ -2,13 +2,14 @@ function TerritoryDecay() {}
|
||||
|
||||
TerritoryDecay.prototype.Schema =
|
||||
"<element name='DecayRate' a:help='Decay rate in capture points per second'>" +
|
||||
"<ref name='positiveDecimal'/>" +
|
||||
"<choice><ref name='positiveDecimal'/><value>Infinity</value></choice>" +
|
||||
"</element>";
|
||||
|
||||
TerritoryDecay.prototype.Init = function()
|
||||
{
|
||||
this.decaying = false;
|
||||
this.connectedNeighbours = [];
|
||||
this.territoryOwnership = !isFinite(+this.template.DecayRate);
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.IsConnected = function()
|
||||
@ -84,21 +85,45 @@ TerritoryDecay.prototype.UpdateDecayState = function()
|
||||
Engine.PostMessage(this.entity, MT_TerritoryDecayChanged, { "entity": this.entity, "to": decaying, "rate": this.GetDecayRate() });
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.UpdateOwner = function()
|
||||
{
|
||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
|
||||
if (!cmpOwnership || !cmpPosition || !cmpPosition.IsInWorld())
|
||||
return;
|
||||
let cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager);
|
||||
let pos = cmpPosition.GetPosition2D();
|
||||
let tileOwner = cmpTerritoryManager.GetOwner(pos.x, pos.y);
|
||||
if (tileOwner != cmpOwnership.GetOwner())
|
||||
cmpOwnership.SetOwner(tileOwner);
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.OnTerritoriesChanged = function(msg)
|
||||
{
|
||||
this.UpdateDecayState();
|
||||
if (this.territoryOwnership)
|
||||
this.UpdateOwner();
|
||||
else
|
||||
this.UpdateDecayState();
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.OnTerritoryPositionChanged = function(msg)
|
||||
{
|
||||
this.UpdateDecayState();
|
||||
if (this.territoryOwnership)
|
||||
this.UpdateOwner();
|
||||
else
|
||||
this.UpdateDecayState();
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.OnOwnershipChanged = function(msg)
|
||||
{
|
||||
// if it influences the territory, wait until we get a TerritoriesChanged message
|
||||
if (!Engine.QueryInterface(this.entity, IID_TerritoryInfluence))
|
||||
if (!this.territoryOwnership && !Engine.QueryInterface(this.entity, IID_TerritoryInfluence))
|
||||
this.UpdateDecayState();
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.HasTerritoryOwnership = function()
|
||||
{
|
||||
return this.territoryOwnership;
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_TerritoryDecay, "TerritoryDecay", TerritoryDecay);
|
||||
|
@ -9,7 +9,6 @@
|
||||
<SpecificName>Wheat Field</SpecificName>
|
||||
<History>A farmer's field.</History>
|
||||
</Identity>
|
||||
<TerritoryDecay disable=""/>
|
||||
<VisualActor>
|
||||
<Actor>structures/plot_field_new.xml</Actor>
|
||||
<FoundationActor>structures/plot_field_new.xml</FoundationActor>
|
||||
|
@ -9,6 +9,9 @@
|
||||
<Category>Field</Category>
|
||||
</BuildRestrictions>
|
||||
<Capturable disable=""/>
|
||||
<TerritoryDecay>
|
||||
<DecayRate>Infinity</DecayRate>
|
||||
</TerritoryDecay>
|
||||
<Cost>
|
||||
<BuildTime>50</BuildTime>
|
||||
<Resources>
|
||||
@ -25,7 +28,7 @@
|
||||
</Health>
|
||||
<Identity>
|
||||
<GenericName>Field</GenericName>
|
||||
<VisibleClasses datatype="tokens">Field</VisibleClasses>
|
||||
<VisibleClasses datatype="tokens">Field</VisibleClasses>
|
||||
<Tooltip>Harvest vegetables for food. Max gatherers: 5.</Tooltip>
|
||||
<History>Farming originated around 9500 BC in India and the Middle East. The history of agriculture is a central element of human history, as agricultural progress has been a crucial factor in worldwide socio-economic change. Wealth-building and militaristic specializations rarely seen in hunter-gatherer cultures are commonplace in agricultural and agro-industrial societies - when farmers became capable of producing food beyond the needs of their own families, others in the tribe/nation/empire were freed to devote themselves to projects other than food acquisition.</History>
|
||||
<Icon>structures/field.png</Icon>
|
||||
@ -65,7 +68,6 @@
|
||||
<StatusBars>
|
||||
<HeightOffset>8.0</HeightOffset>
|
||||
</StatusBars>
|
||||
<TerritoryDecay disable=""/>
|
||||
<Vision>
|
||||
<Range>0</Range>
|
||||
</Vision>
|
||||
|
Loading…
Reference in New Issue
Block a user