forked from markus-wa/demoinfocs-golang
/
structs.go
181 lines (158 loc) · 5.16 KB
/
structs.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package common
import (
"math/rand"
r3 "github.com/golang/geo/r3"
st "github.com/markus-wa/demoinfocs-golang/sendtables"
)
// DemoHeader contains information from a demo's header.
type DemoHeader struct {
Filestamp string
Protocol int
NetworkProtocol int
ServerName string
ClientName string
MapName string
GameDirectory string
PlaybackTime float32
PlaybackTicks int
PlaybackFrames int
SignonLength int
}
// FrameRate returns the frame rate of the demo (frames / demo-ticks per second).
// Not necessarily the tick-rate the server ran on during the game.
// VolvoPlx128TixKTnxBye
func (h DemoHeader) FrameRate() float32 {
return float32(h.PlaybackFrames) / h.PlaybackTime
}
// FrameTime returns the time a frame / demo-tick takes in seconds.
func (h DemoHeader) FrameTime() float32 {
return h.PlaybackTime / float32(h.PlaybackFrames)
}
// Player contains mostly game-relevant player information.
type Player struct {
SteamID int64
Position r3.Vector
LastAlivePosition r3.Vector
Velocity r3.Vector
EntityID int
Name string
Hp int
Armor int
Money int
CurrentEquipmentValue int
FreezetimeEndEquipmentValue int
RoundStartEquipmentValue int
ActiveWeaponID int
RawWeapons map[int]*Equipment
AmmoLeft [32]int
Entity *st.Entity
AdditionalPlayerInformation *AdditionalPlayerInformation
ViewDirectionX float32
ViewDirectionY float32
FlashDuration float32
Team Team
IsBot bool
IsDucking bool
IsDisconnected bool
HasDefuseKit bool
HasHelmet bool
Connected bool
}
// IsAlive returns true if the Hp of the player are > 0.
func (p *Player) IsAlive() bool {
return p.Hp > 0
}
// ActiveWeapon returns the currently active / equipped weapon of the player.
func (p *Player) ActiveWeapon() *Equipment {
return p.RawWeapons[p.ActiveWeaponID]
}
// Weapons returns all weapons in the player's possession.
func (p *Player) Weapons() []*Equipment {
res := make([]*Equipment, 0, len(p.RawWeapons))
for _, w := range p.RawWeapons {
res = append(res, w)
}
return res
}
// AdditionalPlayerInformation contains mostly scoreboard information.
type AdditionalPlayerInformation struct {
Kills int
Deaths int
Assists int
Score int
MVPs int
Ping int
ClanTag string
TotalCashSpent int
}
// Equipment is a weapon / piece of equipment belonging to a player.
// This also includes the skin and some additional data.
type Equipment struct {
EntityID int
Weapon EquipmentElement
OriginalString string
SkinID string
AmmoInMagazine int
AmmoType int
Owner *Player
ReserveAmmo int
uniqueID int64
}
// GrenadeProjectile is a grenade thrown intentionally by a player. It is used to track grenade projectile
// positions between the time at which they are thrown and until they detonate.
type GrenadeProjectile struct {
EntityID int
Weapon EquipmentElement
Thrower *Player
Owner *Player
// uniqueID is used to distinguish different grenades (which potentially have the same, reused entityID) from each other.
uniqueID int64
Position r3.Vector
}
// Class returns the class of the equipment.
// E.g. pistol, smg, heavy etc.
func (e Equipment) Class() EquipmentClass {
return e.Weapon.Class()
}
// UniqueID returns the unique id of the equipment element.
// The unique id is a random int generated internally by this library and can be used to differentiate
// equipment from each other. This is needed because demo-files reuse entity ids.
func (e Equipment) UniqueID() int64 {
return e.uniqueID
}
// NewGrenadeProjectile creates a grenade projectile and sets.
//
// Intended for internal use only.
func NewGrenadeProjectile() *GrenadeProjectile {
return &GrenadeProjectile{uniqueID: rand.Int63()}
}
// UniqueID returns the unique id of the grenade.
// The unique id is a random int generated internally by this library and can be used to differentiate
// grenades from each other. This is needed because demo-files reuse entity ids.
func (g GrenadeProjectile) UniqueID() int64 {
return g.uniqueID
}
// NewEquipment is a wrapper for NewSkinEquipment to create weapons without skins.
//
// Intended for internal use only.
func NewEquipment(eqName string) Equipment {
return NewSkinEquipment(eqName, "")
}
// NewSkinEquipment creates an equipment with a skin from a skinID and equipment name.
//
// Intended for internal use only.
func NewSkinEquipment(eqName string, skinID string) Equipment {
var wep EquipmentElement
if len(eqName) > 0 {
wep = MapEquipment(eqName)
} else {
wep = EqUnknown
}
return Equipment{Weapon: wep, SkinID: skinID, uniqueID: rand.Int63()}
}
// NewPlayer creates a *Player with an initialized equipment map.
//
// Intended for internal use only.
func NewPlayer() *Player {
return &Player{RawWeapons: make(map[int]*Equipment)}
}