-
Notifications
You must be signed in to change notification settings - Fork 7
/
Triple.go
104 lines (91 loc) · 2.23 KB
/
Triple.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package object
import "fmt"
// Class describes a general category of objects.
type Class byte
// String returns the textual representation.
func (c Class) String() string {
if int(c) >= len(classNames) {
return fmt.Sprintf("Unknown%02X", int(c))
}
return classNames[c]
}
// Object classes constants.
const (
ClassGun Class = 0
ClassAmmo Class = 1
ClassPhysics Class = 2
ClassGrenade Class = 3
ClassDrug Class = 4
ClassHardware Class = 5
ClassSoftware Class = 6
ClassBigStuff Class = 7
ClassSmallStuff Class = 8
ClassFixture Class = 9
ClassDoor Class = 10
ClassAnimating Class = 11
ClassTrap Class = 12
ClassContainer Class = 13
ClassCritter Class = 14
)
var classNames = []string{
"Gun",
"Ammo",
"Physics",
"Grenade",
"Drug",
"Hardware",
"Software",
"BigStuff",
"SmallStuff",
"Fixture",
"Door",
"Animating",
"Trap",
"Container",
"Critter",
}
// Classes returns a list of all classes.
func Classes() []Class {
var classes [ClassCount]Class
for class := Class(0); class < ClassCount; class++ {
classes[class] = class
}
return classes[:]
}
// Subclass divides an object class.
type Subclass byte
// Type describes one specific object.
type Type byte
// Triple identifies one specific object by its full coordinate.
type Triple struct {
Class Class
Subclass Subclass
Type Type
}
// TripleFrom returns a Triple instance with given values as coordinates.
func TripleFrom(class, subclass, objType int) Triple {
return Triple{
Class: Class(class),
Subclass: Subclass(subclass),
Type: Type(objType),
}
}
// TripleFromInt returns a Triple instance based on a single integer value.
func TripleFromInt(value int) Triple {
return Triple{
Class: Class((value >> 16) & 0xFF),
Subclass: Subclass((value >> 8) & 0xFF),
Type: Type((value >> 0) & 0xFF),
}
}
// String returns the textual representation of the triple as "cl/s/ty" string.
func (triple Triple) String() string {
return fmt.Sprintf("%2d/%d/%2d", triple.Class, triple.Subclass, triple.Type)
}
// Int returns the triple as a single integer value.
func (triple Triple) Int() int {
value := int(triple.Class) << 16
value |= int(triple.Subclass) << 8
value |= int(triple.Type) << 0
return value
}