Line data Source code
1 : package query
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/mlange-42/ark/ecs"
8 : )
9 :
10 : // perishRate は entity の現在の劣化速度を返す。1.0 が基準。
11 : // 将来、置き場所の温度でこの値を変える。冷所は遅く、暖所は速い。今は一律 1.0。
12 : func perishRate(_ w.World, _ ecs.Entity) float64 {
13 1 : return 1.0
14 1 : }
15 :
16 : // EffectiveRot は now 時点の累積劣化量を返す。Perishable の RotAccrued に、RotUpdatedTurn からの
17 : // 経過ぶんを現在の速度で加える。読み取り専用で副作用はない。段階算出と合流判定が通る。
18 : func EffectiveRot(world w.World, entity ecs.Entity, now consts.Turn) consts.Turn {
19 1 : p := world.Components.Perishable.Get(entity)
20 1 : elapsed := now - p.RotUpdatedTurn
21 1 : return p.RotAccrued + consts.Turn(float64(elapsed)*perishRate(world, entity))
22 1 : }
23 :
24 : // FreshnessStageOf は entity の鮮度段階を返す。Perishable を持たなければ ok=false。
25 : // 鮮度の算出をここへ集約し、食べる処理と表示が同じ判定を通す
26 : func FreshnessStageOf(world w.World, entity ecs.Entity) (rawschema.FreshnessStageId, bool) {
27 1 : if !world.Components.Perishable.Has(entity) {
28 1 : return "", false
29 1 : }
30 1 : now := GetGameTime(world).TotalTurns
31 1 : stages := world.Components.Perishable.Get(entity).StagesElapsed(EffectiveRot(world, entity, now))
32 1 : return world.Resources.NeedDefs.FreshnessAt(stages).Level, true
33 : }
34 :
35 : // FreshnessMarker はメニュー行に添える鮮度の訳語を返す。新鮮や非腐敗は空文字。
36 : // 呼び出し側は空なら何も足さない
37 : func FreshnessMarker(world w.World, entity ecs.Entity) string {
38 1 : stage, ok := FreshnessStageOf(world, entity)
39 1 : if !ok || !world.Resources.NeedDefs.FreshnessOf(stage).Marker {
40 1 : return ""
41 1 : }
42 1 : return FreshnessName(world, stage)
43 : }
44 :
45 : // FreshnessName は鮮度の段階の訳した表示名を返す
46 : func FreshnessName(world w.World, stage rawschema.FreshnessStageId) string {
47 1 : return T(world, world.Resources.NeedDefs.FreshnessOf(stage).Name)
48 1 : }
|