Skip to content

Commit bb14185

Browse files
micvbangmarkus-wa
authored andcommitted
Add unique id to Equipment.
1 parent 1c41d30 commit bb14185

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

common/structs.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ type Equipment struct {
108108
AmmoType int
109109
Owner *Player
110110
ReserveAmmo int
111+
112+
uniqueID int64
111113
}
112114

113115
// GrenadeProjectile is a grenade thrown intentionally by a player. It is used to track grenade projectile
@@ -130,12 +132,21 @@ func (e Equipment) Class() EquipmentClass {
130132
return e.Weapon.Class()
131133
}
132134

135+
// UniqueID returns the unique id of the equipment element.
136+
// The unique id is a random int generated internally by this library and can be used to differentiate
137+
// equipment from each other. This is needed because demo-files reuse entity ids.
138+
func (e Equipment) UniqueID() int64 {
139+
return e.uniqueID
140+
}
141+
133142
// NewGrenadeProjectile creates a grenade projectile and sets.
134143
func NewGrenadeProjectile() *GrenadeProjectile {
135144
return &GrenadeProjectile{uniqueID: rand.Int63()}
136145
}
137146

138-
// UniqueID returns the internal id of the grenade, which is used to distinguish grenades that reuse another entity's entity id.
147+
// UniqueID returns the unique id of the grenade.
148+
// The unique id is a random int generated internally by this library and can be used to differentiate
149+
// grenades from each other. This is needed because demo-files reuse entity ids.
139150
func (g GrenadeProjectile) UniqueID() int64 {
140151
return g.uniqueID
141152
}
@@ -153,7 +164,7 @@ func NewSkinEquipment(eqName string, skinID string) Equipment {
153164
} else {
154165
wep = EqUnknown
155166
}
156-
return Equipment{Weapon: wep, SkinID: skinID}
167+
return Equipment{Weapon: wep, SkinID: skinID, uniqueID: rand.Int63()}
157168
}
158169

159170
// NewPlayer creates a *Player with an initialized equipment map.

datatables.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,6 @@ func (p *Parser) bindNewPlayer(playerEntity *st.Entity) {
291291
}
292292

293293
func (p *Parser) bindWeapons() {
294-
for i := 0; i < maxEntities; i++ {
295-
p.weapons[i] = common.NewEquipment("")
296-
}
297-
298294
for _, sc := range p.stParser.ServerClasses() {
299295
for _, bc := range sc.BaseClasses {
300296
switch bc.Name {
@@ -374,7 +370,8 @@ func (p *Parser) bindGrenadeProjectiles(event st.EntityCreatedEvent) {
374370
}
375371

376372
func (p *Parser) bindWeapon(event st.EntityCreatedEvent) {
377-
eq := &p.weapons[event.Entity.ID]
373+
eq := common.NewEquipment("")
374+
p.weapons[event.Entity.ID] = eq
378375
eq.EntityID = event.Entity.ID
379376
eq.Weapon = p.equipmentMapping[event.ServerClass]
380377
eq.AmmoInMagazine = -1

0 commit comments

Comments
 (0)