Index: ps/trunk/binaries/data/mods/public/gui/session/unit_actions.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/unit_actions.js +++ ps/trunk/binaries/data/mods/public/gui/session/unit_actions.js @@ -893,7 +893,6 @@ "entities": selection, "target": action.target, "queued": queued, - "autocontinue": true, "formation": g_AutoFormation.getNull() }); Index: ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js +++ ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js @@ -859,12 +859,11 @@ return this; }, - "collectTreasure": function(target, autocontinue = false, queued = false, pushFront = false) { + "collectTreasure": function(target, queued = false, pushFront = false) { Engine.PostCommand(PlayerID, { "type": "collect-treasure", "entities": [this.id()], "target": target.id(), - "autocontinue": autocontinue, "queued": queued, "pushFront": pushFront }); Index: ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js +++ ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js @@ -642,20 +642,22 @@ }, "Order.CollectTreasure": function(msg) { - let cmpTreasureCollecter = Engine.QueryInterface(this.entity, IID_TreasureCollecter); - if (!cmpTreasureCollecter || !cmpTreasureCollecter.CanCollect(msg.data.target)) + if (this.CheckTargetRange(msg.data.target, IID_TreasureCollecter)) + this.SetNextState("INDIVIDUAL.COLLECTTREASURE.COLLECTING"); + else if (this.AbleToMove()) + this.SetNextState("INDIVIDUAL.COLLECTTREASURE.APPROACHING"); + else return this.FinishOrder(); - this.SetNextState("COLLECTTREASURE"); return ACCEPT_ORDER; }, "Order.CollectTreasureNearPosition": function(msg) { - let nearbyTreasure = this.FindNearbyTreasure(msg.data.x, msg.data.z); - if (nearbyTreasure) - this.CollectTreasure(nearbyTreasure, oldData.autocontinue, true); - else - this.SetNextState("COLLECTTREASURE"); + if (!this.AbleToMove()) + return this.FinishOrder(); + this.SetNextState("INDIVIDUAL.COLLECTTREASURE.WALKING"); + msg.data.initPos = { 'x': msg.data.x, 'z': msg.data.z }; + msg.data.relaxed = true; return ACCEPT_ORDER; }, @@ -2772,20 +2774,6 @@ }, "COLLECTTREASURE": { - "enter": function() { - let cmpTreasureCollecter = Engine.QueryInterface(this.entity, IID_TreasureCollecter); - if (!cmpTreasureCollecter || !cmpTreasureCollecter.CanCollect(this.order.data.target)) - { - this.SetNextState("FINDINGNEWTARGET"); - return true; - } - if (this.CheckTargetRange(this.order.data.target, IID_TreasureCollecter)) - this.SetNextState("COLLECTING"); - else - this.SetNextState("APPROACHING"); - return true; - }, - "leave": function() { }, @@ -2847,24 +2835,41 @@ "FINDINGNEWTARGET": { "enter": function() { - let oldData = this.order.data; + let oldTarget = this.order.data.target || INVALID_ENTITY; // Switch to the next order (if any). if (this.FinishOrder()) return true; - // If autocontinue explicitly disabled (e.g. by AI) - // then do nothing automatically. - if (!oldData.autocontinue) - return false; - - let nearbyTreasure = this.FindNearbyTreasure(this.TargetPosOrEntPos(oldData.target)); + let nearbyTreasure = this.FindNearbyTreasure(this.TargetPosOrEntPos(oldTarget)); if (nearbyTreasure) - this.CollectTreasure(nearbyTreasure, oldData.autocontinue, true); + this.CollectTreasure(nearbyTreasure, true); return true; }, }, + + // Walking to a good place to collect treasures near, used by CollectTreasureNearPosition. + "WALKING": { + "enter": function() { + if (!this.MoveTo(this.order.data)) + { + this.FinishOrder(); + return true; + } + return false; + }, + + "leave": function() { + this.StopMoving(); + }, + + "MovementUpdate": function(msg) { + if (msg.likelyFailure || msg.obstructed && this.RelaxedMaxRangeCheck(this.order.data, this.DefaultRelaxedMaxRange) || + this.CheckRange(this.order.data)) + this.SetNextState("FINDINGNEWTARGET"); + }, + }, }, "TRADE": { @@ -5605,27 +5610,24 @@ /** * Adds order to collect a treasure to queue, forced by the player. */ -UnitAI.prototype.CollectTreasure = function(target, autocontinue, queued) +UnitAI.prototype.CollectTreasure = function(target, queued, pushFront) { this.AddOrder("CollectTreasure", { "target": target, - "autocontinue": autocontinue, "force": true - }, queued); + }, queued, pushFront); }; /** * Adds order to collect a treasure to queue, forced by the player. */ -UnitAI.prototype.CollectTreasureNearPosition = function(posX, posZ, autocontinue, queued) +UnitAI.prototype.CollectTreasureNearPosition = function(posX, posZ, queued, pushFront) { this.AddOrder("CollectTreasureNearPosition", { "x": posX, "z": posZ, - "target": target, - "autocontinue": autocontinue, - "force": false - }, queued); + "force": true + }, queued, pushFront); }; UnitAI.prototype.CancelSetupTradeRoute = function(target) Index: ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js +++ ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js @@ -75,14 +75,14 @@ "collect-treasure": function(player, cmd, data) { GetFormationUnitAIs(data.entities, player, cmd, data.formation).forEach(cmpUnitAI => { - cmpUnitAI.CollectTreasure(cmd.target, cmd.autocontinue, cmd.queued); + cmpUnitAI.CollectTreasure(cmd.target, cmd.queued); }); }, "collect-treasure-near-position": function(player, cmd, data) { GetFormationUnitAIs(data.entities, player, cmd, data.formation).forEach(cmpUnitAI => { - cmpUnitAI.CollectTreasureNearPosition(cmd.x, cmd.z, cmd.autocontinue, cmd.queued); + cmpUnitAI.CollectTreasureNearPosition(cmd.x, cmd.z, cmd.queued); }); }, Index: ps/trunk/binaries/data/mods/public/simulation/helpers/RallyPointCommands.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/helpers/RallyPointCommands.js +++ ps/trunk/binaries/data/mods/public/simulation/helpers/RallyPointCommands.js @@ -117,8 +117,7 @@ "type": "collect-treasure", "entities": spawnedEnts, "target": data[i].target, - "queued": true, - "autocontinue": i == rallyPos.length - 1 + "queued": true }); break; case "collect-treasure-near-position": @@ -127,8 +126,7 @@ "entities": spawnedEnts, "x": rallyPos[i].x, "z": rallyPos[i].z, - "queued": true, - "autocontinue": i == rallyPos.length - 1 + "queued": true }); break; default: