Index: binaries/data/mods/public/simulation/components/Builder.js =================================================================== --- binaries/data/mods/public/simulation/components/Builder.js +++ binaries/data/mods/public/simulation/components/Builder.js @@ -11,6 +11,9 @@ "" + "" + "" + + "" + + "" + + "" + "" + "" + "tokens" + @@ -57,6 +60,11 @@ return { "max": max, "min": 0 }; }; +Builder.prototype.GetSearchRange = function() +{ + return ApplyValueModificationsToEntity("Builder/SearchRange", +this.template.SearchRange, this.entity); +}; + Builder.prototype.GetRate = function() { return ApplyValueModificationsToEntity("Builder/Rate", +this.template.Rate, this.entity); Index: binaries/data/mods/public/simulation/components/ResourceGatherer.js =================================================================== --- binaries/data/mods/public/simulation/components/ResourceGatherer.js +++ binaries/data/mods/public/simulation/components/ResourceGatherer.js @@ -21,6 +21,9 @@ "" + "" + "" + + "" + + "" + + "" + "" + "" + "" + @@ -40,6 +43,8 @@ // The last exact type gathered, so we can render appropriate props this.lastCarriedType = undefined; // { generic, specific } + + this.searchRange = +this.template.SearchRange; }; /** @@ -103,7 +108,9 @@ this.lastCarriedType = lastCarriedType; }; -// Since this code is very performancecritical and applying technologies quite slow, cache it. +/** + * Since this code is very performancecritical and applying technologies quite slow, cache it. + */ ResourceGatherer.prototype.RecalculateGatherRatesAndCapacities = function() { this.baseSpeed = ApplyValueModificationsToEntity("ResourceGatherer/BaseSpeed", +this.template.BaseSpeed, this.entity); @@ -126,6 +133,8 @@ this.capacities = {}; for (let r in this.template.Capacities) this.capacities[r] = ApplyValueModificationsToEntity("ResourceGatherer/Capacities/" + r, +this.template.Capacities[r], this.entity); + + this.searchRange = ApplyValueModificationsToEntity("ResourceGatherer/SearchRange", +this.template.SearchRange, this.entity); }; ResourceGatherer.prototype.GetGatherRates = function() @@ -154,6 +163,11 @@ // maybe this should depend on the unit or target or something? }; +ResourceGatherer.prototype.GetSearchRange = function() +{ + return this.searchRange; +}; + /** * Try to gather treasure * @return 'true' if treasure is successfully gathered, otherwise 'false' Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -4186,10 +4186,12 @@ return undefined; let owner = cmpOwnership.GetOwner(); - // We accept resources owned by Gaia or any player + // We accept resources owned by any player (including Gaia). let players = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetAllPlayers(); - let range = 64; // TODO: what's a sensible number? + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + if (!cmpResourceGatherer) + return undefined; let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); @@ -4200,7 +4202,7 @@ if (cmpPosition && cmpPosition.IsInWorld()) pos = cmpPosition.GetPosition2D(); } - let nearby = cmpRangeManager.ExecuteQueryAroundPos(pos, 0, range, players, IID_ResourceSupply); + let nearby = cmpRangeManager.ExecuteQueryAroundPos(pos, 0, cmpResourceGatherer.GetSearchRange(), players, IID_ResourceSupply); return nearby.find(ent => { if (!this.CanGather(ent) || !this.CheckTargetVisible(ent)) return false; @@ -4280,17 +4282,18 @@ */ UnitAI.prototype.FindNearbyFoundation = function() { - var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); if (!cmpOwnership || cmpOwnership.GetOwner() == INVALID_PLAYER) return undefined; - // Find buildings owned by this unit's player - var players = [cmpOwnership.GetOwner()]; + let cmpBuilder = Engine.QueryInterface(this.entity, IID_Builder); + if (!cmpBuilder) + return undefined; - var range = 64; // TODO: what's a sensible number? + let players = [cmpOwnership.GetOwner()]; - var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); - var nearby = cmpRangeManager.ExecuteQuery(this.entity, 0, range, players, IID_Foundation); + let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + let nearby = cmpRangeManager.ExecuteQuery(this.entity, 0, cmpBuilder.GetSearchRange(), players, IID_Foundation); // Skip foundations that are already complete. (This matters since // we process the ConstructionFinished message before the foundation Index: binaries/data/mods/public/simulation/components/tests/test_Builder.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Builder.js +++ binaries/data/mods/public/simulation/components/tests/test_Builder.js @@ -12,8 +12,9 @@ }); let cmpBuilder = ConstructComponent(builderId, "Builder", { - "Rate": 1.0, - "Entities": { "_string": "structures/{civ}_barracks structures/{civ}_civil_centre structures/{native}_house" } + "Rate": "1", + "Entities": { "_string": "structures/{civ}_barracks structures/{civ}_civil_centre structures/{native}_house" }, + "SearchRange": "64" }); TS_ASSERT_UNEVAL_EQUALS(cmpBuilder.GetEntitiesList(), []); Index: binaries/data/mods/public/simulation/templates/template_unit.xml =================================================================== --- binaries/data/mods/public/simulation/templates/template_unit.xml +++ binaries/data/mods/public/simulation/templates/template_unit.xml @@ -82,6 +82,7 @@ 2.0 + 64 1.0 1 Index: binaries/data/mods/public/simulation/templates/template_unit_infantry.xml =================================================================== --- binaries/data/mods/public/simulation/templates/template_unit_infantry.xml +++ binaries/data/mods/public/simulation/templates/template_unit_infantry.xml @@ -23,6 +23,7 @@ 1.0 + 64 structures/{civ}_house structures/{civ}_storehouse Index: binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml =================================================================== --- binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml +++ binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml @@ -25,6 +25,7 @@ 1.0 + 64 structures/{civ}_house structures/{civ}_storehouse Index: binaries/data/mods/public/simulation/templates/template_unit_support_slave.xml =================================================================== --- binaries/data/mods/public/simulation/templates/template_unit_support_slave.xml +++ binaries/data/mods/public/simulation/templates/template_unit_support_slave.xml @@ -2,6 +2,7 @@ 0.5 + 64 structures/{civ}_house structures/{civ}_storehouse Index: binaries/data/mods/public/simulation/templates/units/maur_support_elephant.xml =================================================================== --- binaries/data/mods/public/simulation/templates/units/maur_support_elephant.xml +++ binaries/data/mods/public/simulation/templates/units/maur_support_elephant.xml @@ -7,6 +7,7 @@ 2.0 + 64