Line data Source code
1 : package aiinput
2 :
3 : import (
4 : "github.com/kijimaD/ruins/internal/consts"
5 : "github.com/kijimaD/ruins/internal/rawschema"
6 : w "github.com/kijimaD/ruins/internal/world"
7 : "github.com/kijimaD/ruins/internal/world/query"
8 : "github.com/mlange-42/ark/ecs"
9 : )
10 :
11 : // VisionSystem はAIの視界判定システム
12 : type VisionSystem interface {
13 : CanSeeTarget(world w.World, aiEntity, targetEntity ecs.Entity, viewDistance consts.Tile) bool
14 : }
15 :
16 : // DefaultVisionSystem は標準的な視界判定実装
17 : type DefaultVisionSystem struct{}
18 :
19 : // NewVisionSystem は新しいVisionSystemを作成する
20 : func NewVisionSystem() VisionSystem {
21 1 : return &DefaultVisionSystem{}
22 1 : }
23 :
24 : // CanSeeTarget はターゲットが視界内にいるかチェック
25 : func (vs *DefaultVisionSystem) CanSeeTarget(world w.World, aiEntity, targetEntity ecs.Entity, viewDistance consts.Tile) bool {
26 1 : aiGrid := world.Components.GridElement.Get(aiEntity)
27 1 : targetGrid := world.Components.GridElement.Get(targetEntity)
28 1 :
29 1 : dx := int(aiGrid.X) - int(targetGrid.X)
30 1 : dy := int(aiGrid.Y) - int(targetGrid.Y)
31 1 : distSq := dx*dx + dy*dy
32 1 :
33 1 : viewDist := float64(viewDistance)
34 1 :
35 : // 敵ごと毎ターン呼ばれる最頻経路なので、内訳を作らない単キー導出で読む
36 1 : viewDist = query.ProficiencyValue(world, targetEntity, rawschema.ProficiencyIdEnemyVision).ApplyFloat(viewDist)
37 1 :
38 1 : return float64(distSq) <= viewDist*viewDist
39 1 : }
|