public void SwapUnits(Unit a, Unit b) { Debug.Assert(a.position.Distance(b.position) == 1); var targetPosition = b.position; // Remove a CacheRemoveUnitAt(a.position); // Tell b to move into a's spot Debug.Assert(b.orders.Count == 0, "Swap: b still had orders left."); b.orders.Add(Order.CreateMoveOrder(a.position)); b.Update(); // This will force the unit to wait the appropriate amount of time before moving back // Debug.Assert(b.position.Equals(a.position), "Swap: b did not move back to original position."); // Add a to b's old position a.previousPosition = a.position; a.position = targetPosition; a.animationStartTick = currentTick; CacheSetUnitAt(a); // Give an order to b to go back to his original position OrderMove(b, targetPosition); }
public void OrderMove(Unit unit, Position targetPosition) { unit.orders.Add(Order.CreateMoveOrder(targetPosition)); ScheduleUpdate(1, unit); }