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 @@ -24,6 +24,9 @@ "" + "" + "" + + "" + + "" + + "" + "" + "" + "" + @@ -454,7 +457,7 @@ this.order.data.relaxed = true; - this.SetNextState("INDIVIDUAL.PATROL"); + this.SetNextState("INDIVIDUAL.PATROL.PATROLLING"); }, "Order.Heal": function(msg) { @@ -707,7 +710,7 @@ "Order.Patrol": function(msg) { this.CallMemberFunction("SetHeldPosition", [msg.data.x, msg.data.z]); - this.SetNextState("PATROL"); + this.SetNextState("PATROL.PATROLLING"); }, "Order.Guard": function(msg) { @@ -960,7 +963,7 @@ }, "PATROL": { - "enter": function(msg) { + "enter": function() { let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); if (!cmpPosition || !cmpPosition.IsInWorld()) { @@ -975,51 +978,81 @@ this.patrolStartPosOrder.allowCapture = this.order.data.allowCapture; } - if (!this.MoveTo(this.order.data)) - { - this.FinishOrder(); - return true; - } - this.StartTimer(0, 1000); + this.SetAnimationVariant("combat"); - let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); - cmpFormation.SetRearrange(true); - cmpFormation.MoveMembersIntoFormation(true, true, "combat"); return false; }, - "Timer": function(msg) { - this.FindWalkAndFightTargets(); - }, - - "leave": function(msg) { - this.StopTimer(); - this.StopMoving(); + "leave": function() { delete this.patrolStartPosOrder; + this.SetDefaultAnimationVariant(); }, - "MovementUpdate": function(msg) { - if (!msg.likelyFailure && !this.CheckRange(this.order.data)) - return; - /** - * A-B-A-B-..: - * if the user only commands one patrol order, the patrol will be between - * the last position and the defined waypoint - * A-B-C-..-A-B-..: - * otherwise, the patrol is only between the given patrol commands and the - * last position is not included (last position = the position where the unit - * is located at the time of the first patrol order) - */ + "PATROLLING": { + "enter": function() { + let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); + if (!cmpPosition || !cmpPosition.IsInWorld() || + !this.MoveTo(this.order.data)) + { + this.FinishOrder(); + return true; + } - if (this.orderQueue.length == 1) - this.PushOrder("Patrol", this.patrolStartPosOrder); + let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); + cmpFormation.SetRearrange(true); + cmpFormation.MoveMembersIntoFormation(true, true, "combat"); - this.PushOrder(this.order.type, this.order.data); - this.FinishOrder(); + this.StartTimer(0, 1000); + return false; + }, + + "leave": function() { + this.StopMoving(); + this.StopTimer(); + }, + + "Timer": function(msg) { + this.FindWalkAndFightTargets(); + }, + + "MovementUpdate": function(msg) { + if (!msg.likelyFailure && !msg.likelySuccess && !this.RelaxedMaxRangeCheck(this.order.data, this.DefaultRelaxedMaxRange)) + return; + + if (this.orderQueue.length == 1) + this.PushOrder("Patrol", this.patrolStartPosOrder); + + this.PushOrder(this.order.type, this.order.data); + this.SetNextState("CHECKINGWAYPOINT"); + }, }, + + "CHECKINGWAYPOINT": { + "enter": function() { + this.StartTimer(0, 1000); + this.stopSurveying = 0; + // TODO: pick a proper animation + return false; + }, + + "leave": function() { + this.StopTimer(); + delete this.stopSurveying; + }, + + "Timer": function(msg) { + if (this.stopSurveying >= +this.template.PatrolWaitTime) + { + this.FinishOrder(); + return; + } + this.FindWalkAndFightTargets(); + ++this.stopSurveying; + } + } }, - "GARRISON":{ + "GARRISON": { "APPROACHING": { "enter": function() { if (!this.MoveToGarrisonRange(this.order.data.target)) @@ -1593,8 +1626,7 @@ "PATROL": { "enter": function() { let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); - if (!cmpPosition || !cmpPosition.IsInWorld() || - !this.MoveTo(this.order.data)) + if (!cmpPosition || !cmpPosition.IsInWorld()) { this.FinishOrder(); return true; @@ -1608,32 +1640,73 @@ this.patrolStartPosOrder.allowCapture = this.order.data.allowCapture; } - this.StartTimer(0, 1000); this.SetAnimationVariant("combat"); + return false; }, "leave": function() { - this.StopMoving(); - this.StopTimer(); delete this.patrolStartPosOrder; this.SetDefaultAnimationVariant(); }, - "Timer": function(msg) { - this.FindWalkAndFightTargets(); - }, + "PATROLLING": { + "enter": function() { + let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); + if (!cmpPosition || !cmpPosition.IsInWorld() || + !this.MoveTo(this.order.data)) + { + this.FinishOrder(); + return true; + } + this.StartTimer(0, 1000); + return false; + }, - "MovementUpdate": function(msg) { - if (!msg.likelyFailure && !msg.likelySuccess && !this.RelaxedMaxRangeCheck(this.order.data, this.DefaultRelaxedMaxRange)) - return; + "leave": function() { + this.StopMoving(); + this.StopTimer(); + }, - if (this.orderQueue.length == 1) - this.PushOrder("Patrol", this.patrolStartPosOrder); + "Timer": function(msg) { + this.FindWalkAndFightTargets(); + }, - this.PushOrder(this.order.type, this.order.data); - this.FinishOrder(); + "MovementUpdate": function(msg) { + if (!msg.likelyFailure && !msg.likelySuccess && !this.RelaxedMaxRangeCheck(this.order.data, this.DefaultRelaxedMaxRange)) + return; + + if (this.orderQueue.length == 1) + this.PushOrder("Patrol", this.patrolStartPosOrder); + + this.PushOrder(this.order.type, this.order.data); + this.SetNextState("CHECKINGWAYPOINT"); + }, }, + + "CHECKINGWAYPOINT": { + "enter": function() { + this.StartTimer(0, 1000); + this.stopSurveying = 0; + // TODO: pick a proper animation + return false; + }, + + "leave": function() { + this.StopTimer(); + delete this.stopSurveying; + }, + + "Timer": function(msg) { + if (this.stopSurveying >= +this.template.PatrolWaitTime) + { + this.FinishOrder(); + return; + } + this.FindWalkAndFightTargets(); + ++this.stopSurveying; + } + } }, "GUARD": { Index: ps/trunk/binaries/data/mods/public/simulation/templates/template_bird.xml =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/templates/template_bird.xml +++ ps/trunk/binaries/data/mods/public/simulation/templates/template_bird.xml @@ -26,6 +26,7 @@ false false false + 0 1000.0 10.0 10000 Index: ps/trunk/binaries/data/mods/public/simulation/templates/template_formation.xml =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/templates/template_formation.xml +++ ps/trunk/binaries/data/mods/public/simulation/templates/template_formation.xml @@ -65,6 +65,7 @@ 12.0 true true + 2 true Index: ps/trunk/binaries/data/mods/public/simulation/templates/template_unit.xml =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/templates/template_unit.xml +++ ps/trunk/binaries/data/mods/public/simulation/templates/template_unit.xml @@ -126,6 +126,7 @@ false true true + 1 2800