Line data Source code
1 : package overworld
2 :
3 : import (
4 : "github.com/kijimaD/ruins/internal/consts"
5 : "github.com/kijimaD/ruins/internal/i18n"
6 : "github.com/kijimaD/ruins/internal/raw"
7 : "github.com/kijimaD/ruins/internal/rawschema"
8 : w "github.com/kijimaD/ruins/internal/world"
9 : "github.com/kijimaD/ruins/internal/world/query"
10 : )
11 :
12 : // AreaKey は区域の同一性。区域の種類と原点で決まり、同じ種類の別の区域と区別する。ゼロ値は区域でないことを表す
13 : type AreaKey struct {
14 : District string
15 : Anchor consts.Coord[consts.Chunk]
16 : }
17 :
18 : // Area は地上のチャンクの場所。区域・集落・目印・荒れ地のいずれか
19 : type Area struct {
20 : Key AreaKey // スプラッシュを出す大きなエリアの同一性。区域だけが持ち、それ以外はゼロ値
21 : Name i18n.Msgid // エリアの表示名
22 : Building i18n.Msgid // 市街地の建物の表示名。市街地でなければ空
23 : }
24 :
25 : // AreaAt はチャンク c のエリアを返す。区域の Key は種類と原点から作り、同じ種類の別の区域と区別する。
26 : // 墜落現場・集落・目印は1チャンクの小さな場所なので、荒れ地と同じく Key を持たない
27 : func AreaAt(raws rawschema.Raws, runSeed uint64, c consts.Coord[consts.Chunk], cols, spawnRow consts.Chunk) Area {
28 1 : kind, r := classifyChunk(raws, runSeed, c, cols, spawnRow)
29 1 : switch kind {
30 : case chunkCrashSite:
31 1 : return Area{Name: glyphName(raws, crashSiteAt(raws, runSeed, c))}
32 : case chunkUrban:
33 1 : return Area{
34 1 : Key: AreaKey{District: r.kind.Id, Anchor: r.anchor},
35 1 : Name: i18n.Msgid(r.kind.Name),
36 1 : Building: glyphName(raws, urbanFacilityAt(raws, zoneCatalogFrom(raws), r, c, spawnRow)),
37 1 : }
38 : case chunkSettlement:
39 1 : return Area{Name: glyphName(raws, settlementAt(raws, runSeed, c).Id)}
40 : case chunkLandmark:
41 1 : return Area{Name: glyphName(raws, landmarkKindAt(raws, runSeed, c))}
42 : case chunkWasteland:
43 1 : return Area{Name: chunkGlyphName(raws, rawschema.Wasteland)}
44 : }
45 0 : panic("unknown chunk type: " + string(kind))
46 : }
47 :
48 : // PlayerArea はプレイヤーのいるチャンクのエリアを返す。地上にいないかプレイヤーがいなければ ok=false
49 : func PlayerArea(world w.World) (Area, bool) {
50 0 : if !query.IsOnOverworld(world) {
51 0 : return Area{}, false
52 0 : }
53 0 : sb := query.GetSeamlessBand(world)
54 0 : tile, ok := query.PlayerBandTile(world)
55 0 : if sb == nil || !ok || sb.ChunkW <= 0 {
56 0 : return Area{}, false
57 0 : }
58 0 : c := consts.Coord[consts.Chunk]{X: consts.Chunk(int(tile.X) / int(sb.ChunkW)), Y: sb.AbsChunkRow(tile.Y)}
59 0 : return AreaAt(world.Resources.RawMaster, sb.RunSeed, c, sb.Cols, sb.SpawnChunkY()), true
60 : }
61 :
62 : // glyphName は id の地図記号の表示名を返す。記号が無ければ空
63 : func glyphName(raws rawschema.Raws, id string) i18n.Msgid {
64 1 : mg, ok := raw.GetMapGlyph(raws, id)
65 1 : if !ok {
66 0 : return ""
67 0 : }
68 1 : return i18n.Msgid(mg.Name)
69 : }
70 :
71 : // chunkGlyphName は持ち主の行を持たないチャンクの種類の地図記号の表示名を返す。記号が無ければ空
72 : func chunkGlyphName(raws rawschema.Raws, chunk rawschema.GlyphChunk) i18n.Msgid {
73 1 : mg, ok := raw.GetChunkGlyph(raws, chunk)
74 1 : if !ok {
75 0 : return ""
76 0 : }
77 1 : return i18n.Msgid(mg.Name)
78 : }
|