Line data Source code
1 : package states
2 :
3 : import (
4 : es "github.com/kijimaD/ruins/internal/engine/states"
5 : "github.com/kijimaD/ruins/internal/gamelog"
6 : "github.com/kijimaD/ruins/internal/rawschema"
7 : w "github.com/kijimaD/ruins/internal/world"
8 : "github.com/kijimaD/ruins/internal/world/lifecycle"
9 : "github.com/kijimaD/ruins/internal/world/query"
10 : "github.com/mlange-42/ark/ecs"
11 : )
12 :
13 : // NewCubeMenuState は移動拠点キューブの入口メニューを作る。状態で使えない項目は消さずに無効表示で残す。
14 : func NewCubeMenuState(cube ecs.Entity) (es.State[w.World], error) {
15 1 : return NewChoiceMenu(func(world w.World) (string, []Choice) {
16 1 : deployed := world.Components.Deployed.Has(cube)
17 1 : choices := []Choice{
18 1 : deployChoice(world, cube),
19 1 : followChoice(world, cube),
20 1 : Choice{Label: query.T(world, "Fuel"), Run: pushChoice(func() (es.State[w.World], error) {
21 0 : return NewFeedFuelMenuState(CubeFuelSink(cube))
22 0 : })},
23 : Choice{Label: query.T(world, "Module"), Run: pushChoice(func() (es.State[w.World], error) {
24 0 : return NewCubeModuleMenuState(cube)
25 0 : })},
26 : // 設備は展開空間のマスへ装着するので、圧縮中は無効表示にする
27 : Choice{Label: query.T(world, "Facility"), Disabled: !deployed, Run: pushChoice(func() (es.State[w.World], error) {
28 0 : return NewCubeFacilityMenuState(cube)
29 0 : })},
30 : Choice{Label: query.T(world, "Info"), Run: pushChoice(func() (es.State[w.World], error) {
31 0 : return NewCubeInfoState(cube)
32 0 : })},
33 : Choice{Label: query.T(world, "Close"), Run: func(_ w.World) (es.Transition[w.World], error) {
34 0 : return es.Transition[w.World]{Type: es.TransPop}, nil
35 0 : }},
36 : }
37 1 : return query.T(world, "Cube"), choices
38 : }), nil
39 : }
40 :
41 : // followChoice は随伴の方針を追従と待機で切り替える項目を返す。設定の切り替えなのでメニューは閉じない。
42 : func followChoice(world w.World, cube ecs.Entity) Choice {
43 1 : solo := world.Components.SoloAI.Get(cube)
44 1 : if solo.Movement == rawschema.Follow {
45 1 : return Choice{Label: query.T(world, "Stay here"), Run: func(world w.World) (es.Transition[w.World], error) {
46 1 : world.Components.SoloAI.Get(cube).Movement = rawschema.Stationary
47 1 : return es.Transition[w.World]{Type: es.TransNone}, nil
48 1 : }}
49 : }
50 1 : return Choice{Label: query.T(world, "Follow me"), Run: func(world w.World) (es.Transition[w.World], error) {
51 1 : world.Components.SoloAI.Get(cube).Movement = rawschema.Follow
52 1 : return es.Transition[w.World]{Type: es.TransNone}, nil
53 1 : }}
54 : }
55 :
56 : // deployChoice は展開中なら圧縮、圧縮中なら展開の項目を返す。展開は必要な空きが無ければ拒否してログを出す。
57 : func deployChoice(world w.World, cube ecs.Entity) Choice {
58 1 : if world.Components.Deployed.Has(cube) {
59 1 : return Choice{Label: query.T(world, "Compress"), Run: func(world w.World) (es.Transition[w.World], error) {
60 0 : lifecycle.StowCube(world, cube)
61 0 : return es.Transition[w.World]{Type: es.TransPop}, nil
62 0 : }}
63 : }
64 1 : return Choice{Label: query.T(world, "Deploy"), Run: func(world w.World) (es.Transition[w.World], error) {
65 1 : if !lifecycle.DeployCube(world, cube) {
66 1 : gamelog.New(query.GetGameLog(world)).
67 1 : Markup(query.T(world, "Not enough open space to deploy.")).
68 1 : Log()
69 1 : }
70 : // 成否によらずメニューは閉じる。失敗理由はログに出るので、場所を変えて開き直して再挑戦する
71 1 : return es.Transition[w.World]{Type: es.TransPop}, nil
72 : }}
73 : }
|