| 3635 | // activate a automatically patrol if the first and last order have the same coordinates. |
| 3636 | UnitAI.prototype.CheckPatrolWalk = function() |
| 3637 | { |
| 3638 | if (this.orderQueue.length < 2) |
| 3639 | { |
| 3640 | // a patrol is not possible if less then 2 walk commands are given |
| 3641 | return false; |
| 3642 | } |
| 3643 | |
| 3644 | let finishedOrder = this.order; |
| 3645 | let lastOrder = this.orderQueue.slice(-1)[0]; |
| 3646 | let epsilon = 2; // TODO remove to a better place? |
| 3647 | |
| 3648 | if ((finishedOrder.type != "WalkAndFight" && lastOrder.type != "WalkAndFight") && |
| 3649 | (finishedOrder.type != "Walk" && lastOrder.type != "Walk")) |
| 3650 | { |
| 3651 | // a none-walking order cannot be a patrol by nature |
| 3652 | warn(finishedOrder.type + " / " + lastOrder.type) |
| 3653 | return false; |
| 3654 | } |
| 3655 | |
| 3656 | // do not this check because it is not possible when pressing the shift-key |
| 3657 | /*for each(let o in this.orderQueue) |
| 3658 | { |
| 3659 | if (o.type != "Walk") { |
| 3660 | warn("not all are walks") |
| 3661 | return false; |
| 3662 | } |
| 3663 | }*/ |
| 3664 | |
| 3665 | if (finishedOrder.data.x === undefined /*|| finishedOrder.data.y === undefined*/ || finishedOrder.data.z === undefined) |
| 3666 | { |
| 3667 | warn("missing data finishedOrder") |
| 3668 | return false; |
| 3669 | } |
| 3670 | |
| 3671 | if (lastOrder.data.x === undefined /*|| finishedOrder.data.y === undefined*/ || lastOrder.data.z === undefined) |
| 3672 | { |
| 3673 | warn("missing data lastOrder") |
| 3674 | return false; |
| 3675 | } |
| 3676 | |
| 3677 | warn(finishedOrder.data.x + " / " + finishedOrder.data.z) |
| 3678 | warn(lastOrder.data.x + " / " + lastOrder.data.z) |
| 3679 | |
| 3680 | // compare coordinates of current and last order |
| 3681 | // TODO x and y are always positive? |
| 3682 | if (Math.abs(finishedOrder.data.x - lastOrder.data.x) < epsilon && Math.abs(finishedOrder.data.z - lastOrder.data.z) < epsilon) |
| 3683 | { |
| 3684 | warn("PATROL"); |
| 3685 | return true; |
| 3686 | } |
| 3687 | |
| 3688 | // check neighbours |
| 3689 | /*for (let i = 0; i < this.orderQueue - 1; i++) |
| 3690 | { |
| 3691 | let a = this.orderQueue[i]; |
| 3692 | let b = this.orderQueue[i+1]; |
| 3693 | |
| 3694 | if (Math.abs(a.data.x - b.data.x) < epsilon && Math.abs(a.data.z - b.data.z) < epsilon) |
| 3695 | { |
| 3696 | warn("HERE 2") |
| 3697 | return true; |
| 3698 | } |
| 3699 | }*/ |
| 3700 | |
| 3701 | return false; |
| 3702 | } |
| 3703 | |