Soldier: Added preliminary interrupt handling

+ soldier can now set its target destination when ordered to move to a position
+/- Squad: refactored MovementOrder to be less error prone
- cleaned up NotImplementedException for Exeecuting a Movement order
This commit is contained in:
Gabriel Ksawery Skowron-Rodriguez 2022-05-22 21:37:03 +02:00
parent 2c52961575
commit 1469eadfd5
2 changed files with 22 additions and 9 deletions

View File

@ -17,9 +17,8 @@ public class Soldier : MonoBehaviour
{ {
public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs) public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs)
{//TO DO: CALL PROPER FUNCTION TO MOVE {//TO DO: CALL PROPER FUNCTION TO MOVE
Debug.LogWarning($"(tick: {tickEventArgs.tickNumber}) Trying to teleport to {soldier.movementDestination}"); throw new System.NotImplementedException($"(tick: {tickEventArgs.tickNumber}) Trying to teleport to {soldier.movementDestination}");
throw new System.NotImplementedException(); //??tileMap.Teleport(movementDestination)
//tileMap.Teleport(movementDestination)
} }
} }
private class TryAttack : Action private class TryAttack : Action
@ -31,8 +30,16 @@ public class Soldier : MonoBehaviour
soldier.lastAttackTick = tickEventArgs.tickNumber; soldier.lastAttackTick = tickEventArgs.tickNumber;
} }
} }
#endregion #endregion
public enum SoldierType
#region Handling Incoming Orders (Interrupts)
public void HandleMovementOrder(Vector2Int destination)
{
movementDestination = destination;
interrupts.Enqueue(new Movement()); // force soldier to find path to the new destination
}
#endregion
public enum SoldierType
{ {
Ally, Ally,
Enemy Enemy
@ -51,7 +58,7 @@ public class Soldier : MonoBehaviour
[SerializeField] private TMP_Text nameText = null; [SerializeField] private TMP_Text nameText = null;
[SerializeField] private TMP_Text healthPointsText = null; [SerializeField] private TMP_Text healthPointsText = null;
private Vector3Int movementDestination = Vector3Int.zero; [SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
public SoldierType TempGetOwnType() public SoldierType TempGetOwnType()
{ {

View File

@ -15,10 +15,16 @@ public class Squad : MonoBehaviour
public class MovementOrder : Order // example how to add new types of orders public class MovementOrder : Order // example how to add new types of orders
{ {
public int x; public MovementOrder(int x, int y)
public int y; {
this.x = x;
this.y = y;
}
public readonly int x;
public readonly int y;
public override void PassToSoldier(Soldier targetSoldier) public override void PassToSoldier(Soldier targetSoldier)
{// here we would set soldier's target position for example {// here we would set soldier's target position for example
targetSoldier.HandleMovementOrder(new Vector2Int(x, y));
Debug.Log($"Soldier {targetSoldier.name} received movement order towards coordinates {x},{y}"); Debug.Log($"Soldier {targetSoldier.name} received movement order towards coordinates {x},{y}");
} }
} }
@ -54,6 +60,6 @@ public class Squad : MonoBehaviour
{ {
int targetX = 4; int targetX = 4;
int targetY = 2; int targetY = 2;
orders.Enqueue(new MovementOrder() { x = targetX, y = targetY }); orders.Enqueue(new MovementOrder(targetX, targetY));
} }
} }