aboutsummaryrefslogtreecommitdiff
path: root/engine/patrol_order.go
diff options
context:
space:
mode:
Diffstat (limited to 'engine/patrol_order.go')
-rw-r--r--engine/patrol_order.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/engine/patrol_order.go b/engine/patrol_order.go
new file mode 100644
index 0000000..0889f92
--- /dev/null
+++ b/engine/patrol_order.go
@@ -0,0 +1,46 @@
+package engine
+
+import (
+ "age_of_empires/ecs"
+ "age_of_empires/physics"
+
+ "golang.org/x/exp/slog"
+)
+
+type PatrolOrder struct {
+ origin physics.Point
+ destination physics.Point
+}
+
+func UpdatePatrolSystem(moveMap physics.MoveMap, masks []ecs.Mask, orders []OrderKind, patrols []PatrolOrder, positions []physics.Point, moves []physics.Move) {
+ required := ecs.CM_Position | ecs.CM_Move | ecs.CM_Order | ecs.CM_PatrolOrder
+ for i, mask := range masks {
+ if mask&required == required {
+ order := orders[i]
+ patrol := patrols[i]
+ position := positions[i]
+ move := &moves[i]
+ if order == OrderKindPatrol && !move.IsActive {
+ if position == patrol.destination {
+ *move = physics.NewMove(position, patrol.origin, moveMap)
+ } else {
+ *move = physics.NewMove(position, patrol.destination, moveMap)
+ }
+ }
+ }
+ }
+}
+
+func StartPatrolSystem(destination physics.Point, masks []ecs.Mask, positions []physics.Point, moves []physics.Move, orders []OrderKind, patrols []PatrolOrder) {
+ required := ecs.CM_Position | ecs.CM_Order | ecs.CM_PatrolOrder
+ for i, mask := range masks {
+ if mask&required == required {
+ position := positions[i]
+ order := &orders[i]
+ patrol := &patrols[i]
+ slog.Info("patrolling between", slog.String("origin", position.String()), slog.String("destination", destination.String()))
+ *patrol = PatrolOrder{origin: position, destination: destination}
+ *order = OrderKindPatrol
+ }
+ }
+}