Ticket #3741: terrainFarm.patch

File terrainFarm.patch, 6.0 KB (added by mimo, 8 years ago)
  • binaries/data/mods/public/simulation/components/Foundation.js

     
    296296        }
    297297
    298298        // ----------------------------------------------------------------------
    299        
    300         var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     299
     300        var owner;
     301        var cmpTerritoryDecay = Engine.QueryInterface(building, IID_TerritoryDecay);
     302        if (cmpTerritoryDecay && cmpTerritoryDecay.HasTerritoryOwnership())
     303        {
     304            let cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager);
     305            owner = cmpTerritoryManager.GetOwner(pos.x, pos.z);
     306        }
     307        else
     308        {
     309            let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     310            owner = cmpOwnership.GetOwner();
     311        }
    301312        var cmpBuildingOwnership = Engine.QueryInterface(building, IID_Ownership);
    302         cmpBuildingOwnership.SetOwner(cmpOwnership.GetOwner());
     313        cmpBuildingOwnership.SetOwner(owner);
    303314       
    304315        // ----------------------------------------------------------------------
    305316       
  • binaries/data/mods/public/simulation/components/TerritoryDecay.js

     
    22
    33TerritoryDecay.prototype.Schema =
    44    "<element name='DecayRate' a:help='Decay rate in capture points per second'>" +
    5         "<ref name='positiveDecimal'/>" +
     5        "<choice><ref name='positiveDecimal'/><value>Infinity</value></choice>" +
    66    "</element>";
    77
    88TerritoryDecay.prototype.Init = function()
     
    99{
    1010    this.decaying = false;
    1111    this.connectedNeighbours = [];
     12    this.territoryOwnership = !isFinite(+this.template.DecayRate);
    1213};
    1314
    1415TerritoryDecay.prototype.IsConnected = function()
     
    8485    Engine.PostMessage(this.entity, MT_TerritoryDecayChanged, { "entity": this.entity, "to": decaying, "rate": this.GetDecayRate() });
    8586};
    8687
     88TerritoryDecay.prototype.UpdateOwner = function()
     89{
     90    let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     91    let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     92    if (!cmpOwnership || !cmpPosition || !cmpPosition.IsInWorld())
     93        return;
     94    let cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager);
     95    let pos = cmpPosition.GetPosition2D();
     96    let tileOwner = cmpTerritoryManager.GetOwner(pos.x, pos.y);
     97    if (tileOwner != cmpOwnership.GetOwner())
     98        cmpOwnership.SetOwner(tileOwner);
     99};
     100
    87101TerritoryDecay.prototype.OnTerritoriesChanged = function(msg)
    88102{
    89     this.UpdateDecayState();
     103    if (this.territoryOwnership)
     104        this.UpdateOwner();
     105    else
     106        this.UpdateDecayState();
    90107};
    91108
    92109TerritoryDecay.prototype.OnTerritoryPositionChanged = function(msg)
    93110{
    94     this.UpdateDecayState();
     111    if (this.territoryOwnership)
     112        this.UpdateOwner();
     113    else
     114        this.UpdateDecayState();
    95115};
    96116
    97117TerritoryDecay.prototype.OnOwnershipChanged = function(msg)
    98118{
    99     // if it influences the territory, wait until we get a TerritoriesChanged message
    100     if (!Engine.QueryInterface(this.entity, IID_TerritoryInfluence))
    101         this.UpdateDecayState();
     119    if (this.territoryOwnership)
     120        if (msg.to != -1)
     121            this.UpdateOwner();
     122    else
     123    {
     124        // if it influences the territory, wait until we get a TerritoriesChanged message
     125        if (!Engine.QueryInterface(this.entity, IID_TerritoryInfluence))
     126            this.UpdateDecayState();
     127    }
    102128};
    103129
     130TerritoryDecay.prototype.HasTerritoryOwnership = function()
     131{
     132    return this.territoryOwnership;
     133};
     134
    104135Engine.RegisterComponentType(IID_TerritoryDecay, "TerritoryDecay", TerritoryDecay);
  • binaries/data/mods/public/simulation/templates/other/generic_field.xml

     
    99    <SpecificName>Wheat Field</SpecificName>
    1010    <History>A farmer's field.</History>
    1111  </Identity>
    12   <TerritoryDecay disable=""/>
    1312  <VisualActor>
    1413    <Actor>structures/plot_field_new.xml</Actor>
    1514    <FoundationActor>structures/plot_field_new.xml</FoundationActor>
  • binaries/data/mods/public/simulation/templates/template_structure_resource_field.xml

     
    99    <Category>Field</Category>
    1010  </BuildRestrictions>
    1111  <Capturable disable=""/>
     12  <TerritoryDecay>
     13    <DecayRate>Infinity</DecayRate>
     14  </TerritoryDecay>
    1215  <Cost>
    1316    <BuildTime>50</BuildTime>
    1417    <Resources>
     
    2528  </Health>
    2629  <Identity>
    2730    <GenericName>Field</GenericName>
    28     <VisibleClasses datatype="tokens">Field</VisibleClasses>
     31    <VisibleClasses datatype="tokens">Field</VisibleClasses>
    2932    <Tooltip>Harvest vegetables for food. Max gatherers: 5.</Tooltip>
    3033    <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>
    3134    <Icon>structures/field.png</Icon>
     
    6568  <StatusBars>
    6669    <HeightOffset>8.0</HeightOffset>
    6770  </StatusBars>
    68   <TerritoryDecay disable=""/>
    6971  <Vision>
    7072    <Range>0</Range>
    7173  </Vision>