aboutsummaryrefslogtreecommitdiff
path: root/engine/patrol_order.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-06-06 20:59:12 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-06-06 20:59:12 +0200
commitd9a54f1319cc9dcc2861cecc9edfde14cf039c5b (patch)
tree74df791d6eda0ffe6c09cb32e5ffd76c4849cbac /engine/patrol_order.go
parent18592fd9f520a33ab307e496b995c1a7bf284893 (diff)
Add examples catalog with subcommand dispatch
- Extract game engine from package main to engine/ library package - Create examples/ package with registry, Entry type, and BuilderDeps - Register default world as an example (moved from main()) - Add combat example: two teams of units facing each other - Rewrite main.go as thin dispatch: go run . example [name] - Update README with examples catalog one-liner
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
+ }
+ }
+}