Skip to content

Commit 4ad2df3

Browse files
authored
Merge pull request #22 from zyphie/nade-entity
Add NadeEntity to NadeEvent Expose Parser.entities
2 parents bcbc984 + cd1bc5b commit 4ad2df3

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

events/events.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
common "github.com/markus-wa/demoinfocs-golang/common"
88
msg "github.com/markus-wa/demoinfocs-golang/msg"
9+
st "github.com/markus-wa/demoinfocs-golang/sendtables"
910
)
1011

1112
// HeaderParsedEvent signals that the header has been parsed.
@@ -112,9 +113,10 @@ type NadeEventIf interface {
112113
// NadeEvent contains the common attributes of nade events. Dont register
113114
// handlers on this tho, you want NadeEventIf for that
114115
type NadeEvent struct {
115-
NadeType common.EquipmentElement
116-
Position r3.Vector
117-
Thrower *common.Player
116+
NadeType common.EquipmentElement
117+
Position r3.Vector
118+
Thrower *common.Player
119+
NadeEntity *st.Entity
118120
}
119121

120122
// Make NadeEvents implement NadeEventIf

game_events.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
common "github.com/markus-wa/demoinfocs-golang/common"
1010
events "github.com/markus-wa/demoinfocs-golang/events"
1111
msg "github.com/markus-wa/demoinfocs-golang/msg"
12+
st "github.com/markus-wa/demoinfocs-golang/sendtables"
1213
)
1314

1415
func (p *Parser) handleGameEventList(gel *msg.CSVCMsg_GameEventList) {
@@ -181,31 +182,32 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
181182
Y: float64(data["y"].ValFloat),
182183
Z: float64(data["z"].ValFloat),
183184
}
185+
nadeEntity := p.entities[int(data["entityid"].GetValShort())]
184186

185187
switch d.Name {
186188
case "flashbang_detonate": // Flash exploded
187-
p.eventDispatcher.Dispatch(events.FlashExplodedEvent{NadeEvent: buildNadeEvent(common.EqFlash, thrower, position)})
189+
p.eventDispatcher.Dispatch(events.FlashExplodedEvent{NadeEvent: buildNadeEvent(common.EqFlash, thrower, position, nadeEntity)})
188190

189191
case "hegrenade_detonate": // HE exploded
190-
p.eventDispatcher.Dispatch(events.HeExplodedEvent{NadeEvent: buildNadeEvent(common.EqHE, thrower, position)})
192+
p.eventDispatcher.Dispatch(events.HeExplodedEvent{NadeEvent: buildNadeEvent(common.EqHE, thrower, position, nadeEntity)})
191193

192194
case "decoy_started": // Decoy started
193-
p.eventDispatcher.Dispatch(events.DecoyStartEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position)})
195+
p.eventDispatcher.Dispatch(events.DecoyStartEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, nadeEntity)})
194196

195197
case "decoy_detonate": // Decoy exploded/expired
196-
p.eventDispatcher.Dispatch(events.DecoyEndEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position)})
198+
p.eventDispatcher.Dispatch(events.DecoyEndEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, nadeEntity)})
197199

198200
case "smokegrenade_detonate": // Smoke popped
199-
p.eventDispatcher.Dispatch(events.SmokeStartEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position)})
201+
p.eventDispatcher.Dispatch(events.SmokeStartEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, nadeEntity)})
200202

201203
case "smokegrenade_expired": // Smoke expired
202-
p.eventDispatcher.Dispatch(events.SmokeEndEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position)})
204+
p.eventDispatcher.Dispatch(events.SmokeEndEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, nadeEntity)})
203205

204206
case "inferno_startburn": // Incendiary exploded/started
205-
p.eventDispatcher.Dispatch(events.FireNadeStartEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position)})
207+
p.eventDispatcher.Dispatch(events.FireNadeStartEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, nadeEntity)})
206208

207209
case "inferno_expire": // Incendiary expired
208-
p.eventDispatcher.Dispatch(events.FireNadeEndEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position)})
210+
p.eventDispatcher.Dispatch(events.FireNadeEndEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, nadeEntity)})
209211
}
210212

211213
case "player_connect": // Bot connected or player reconnected, players normally come in via string tables & data tables
@@ -446,11 +448,12 @@ func mapGameEventData(d *msg.CSVCMsg_GameEventListDescriptorT, e *msg.CSVCMsg_Ga
446448
}
447449

448450
// Just so we can nicely create NadeEvents in one line
449-
func buildNadeEvent(nadeType common.EquipmentElement, thrower *common.Player, position r3.Vector) events.NadeEvent {
451+
func buildNadeEvent(nadeType common.EquipmentElement, thrower *common.Player, position r3.Vector, nadeEntity *st.Entity) events.NadeEvent {
450452
return events.NadeEvent{
451-
NadeType: nadeType,
452-
Thrower: thrower,
453-
Position: position,
453+
NadeType: nadeType,
454+
Thrower: thrower,
455+
Position: position,
456+
NadeEntity: nadeEntity,
454457
}
455458
}
456459

parser.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func (p *Parser) GameState() *GameState {
7979
return &p.gameState
8080
}
8181

82+
// Entities returns the available entities
83+
func (p *Parser) Entities() map[int]*st.Entity {
84+
return p.entities
85+
}
86+
8287
// CurrentFrame return the number of the current frame, aka. 'demo-tick' (Since demos often have a different tick-rate than the game).
8388
// Starts with frame 0, should go up to DemoHeader.PlaybackFrames but might not be the case (usually it's just close to it).
8489
func (p *Parser) CurrentFrame() int {

0 commit comments

Comments
 (0)