]> git.lizzy.rs Git - mt.git/blob - mapblk.go
Add high-level protocol (de)serialization
[mt.git] / mapblk.go
1 package mt
2
3 type MapBlkFlags uint8
4
5 const (
6         BlkIsUnderground MapBlkFlags = 1 << iota
7         BlkDayNightDiff
8         BlkLightExpired
9         BlkNotGenerated
10 )
11
12 type LitFromBlks uint16
13
14 const AlwaysLitFrom LitFromBlks = 0xf000
15
16 func LitFrom(d Dir, b LightBank) LitFromBlks {
17         return 1 << (uint8(d) + uint8(6*b))
18 }
19
20 type MapBlk struct {
21         Flags   MapBlkFlags
22         LitFrom LitFromBlks
23
24         //mt:const uint8(2)     // Size of param0 in bytes.
25         //mt:const uint8(1 + 1) // Size of param1 and param2 combined, in bytes.
26
27         //mt:zlib
28         Param0 [4096]Content
29         Param1 [4096]uint8
30         Param2 [4096]uint8
31         //mt:end
32
33         NodeMetas map[uint16]*NodeMeta
34
35         // net info
36         //mt:const uint8(2) // version
37 }
38
39 // Pos2BlkPos converts a node position to a MapBlk position and index.
40 func Pos2Blkpos(pos [3]int16) (blkpos [3]int16, i uint16) {
41         for j := range pos {
42                 blkpos[j] = pos[j] >> 4
43                 i |= uint16(pos[j]&0xf) << (4 * j)
44         }
45
46         return
47 }
48
49 // BlkPos2Pos converts a MapBlk position and index to a node position.
50 func Blkpos2Pos(blkpos [3]int16, i uint16) (pos [3]int16) {
51         for j := range pos {
52                 pos[j] = blkpos[j]<<4 | int16(i>>(4*j)&0xf)
53         }
54
55         return
56 }