diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-06-06 20:59:12 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-06-06 20:59:12 +0200 |
| commit | d9a54f1319cc9dcc2861cecc9edfde14cf039c5b (patch) | |
| tree | 74df791d6eda0ffe6c09cb32e5ffd76c4849cbac /engine/order.go | |
| parent | 18592fd9f520a33ab307e496b995c1a7bf284893 (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/order.go')
| -rw-r--r-- | engine/order.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/engine/order.go b/engine/order.go new file mode 100644 index 0000000..8aa991b --- /dev/null +++ b/engine/order.go @@ -0,0 +1,41 @@ +package engine + +import ( + "log/slog" + + "age_of_empires/ecs" + "age_of_empires/monad" + "age_of_empires/physics" +) + +type OrderKind int + +const ( + OrderKindNone OrderKind = iota + OrderKindPatrol + OrderKindGather +) + +func MainAction(g *Game, mainEntity ecs.Entity, target physics.Point, moveMap physics.MoveMap) { + mask := g.Mask[mainEntity] + targetEntity := g.entityAt(target) + gatherTargetRequired := ecs.CM_ResourceSource + mainGatherRequired := ecs.CM_ResourceGatherer | ecs.CM_Move + if targetEntity >= 0 && (g.Mask[targetEntity]&gatherTargetRequired == gatherTargetRequired) && (mask&mainGatherRequired == mainGatherRequired) { + Gather(g.GetMoveMap(), g.Position[mainEntity], &g.Move[mainEntity], &g.Order[mainEntity], &g.ResourceGatherer[mainEntity], targetEntity, g.Position[targetEntity]) + return + } + moveRequired := ecs.CM_Move | ecs.CM_Position + if mask&moveRequired == moveRequired { + position := g.Position[mainEntity] + g.Order[mainEntity] = OrderKindNone + g.Move[mainEntity] = physics.NewMove(position, target, moveMap) + return + } + if mask&ecs.CM_Spawn == ecs.CM_Spawn { + slog.Info("Setting spawn target") + spawn := &g.Spawn[mainEntity] + spawn.SpawnTarget = monad.Some(target) + return + } +} |
