Skip to content

Commit 3b0a6ae

Browse files
committed
Add Entities function on Parser. Changed Entity to NadeEntity.
1 parent cce2692 commit 3b0a6ae

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

events/events.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ type NadeEventIf interface {
113113
// NadeEvent contains the common attributes of nade events. Dont register
114114
// handlers on this tho, you want NadeEventIf for that
115115
type NadeEvent struct {
116-
NadeType common.EquipmentElement
117-
Position r3.Vector
118-
Thrower *common.Player
119-
Entity *st.Entity
116+
NadeType common.EquipmentElement
117+
Position r3.Vector
118+
Thrower *common.Player
119+
NadeEntity *st.Entity
120120
}
121121

122122
// Make NadeEvents implement NadeEventIf

game_events.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,32 +198,32 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
198198
Y: float64(data["y"].ValFloat),
199199
Z: float64(data["z"].ValFloat),
200200
}
201-
entity := p.entities[int(data["entityid"].GetValShort())]
201+
nadeEntity := p.entities[int(data["entityid"].GetValShort())]
202202

203203
switch d.Name {
204204
case "flashbang_detonate": // Flash exploded
205-
p.eventDispatcher.Dispatch(events.FlashExplodedEvent{NadeEvent: buildNadeEvent(common.EqFlash, thrower, position, entity)})
205+
p.eventDispatcher.Dispatch(events.FlashExplodedEvent{NadeEvent: buildNadeEvent(common.EqFlash, thrower, position, nadeEntity)})
206206

207207
case "hegrenade_detonate": // HE exploded
208-
p.eventDispatcher.Dispatch(events.HeExplodedEvent{NadeEvent: buildNadeEvent(common.EqHE, thrower, position, entity)})
208+
p.eventDispatcher.Dispatch(events.HeExplodedEvent{NadeEvent: buildNadeEvent(common.EqHE, thrower, position, nadeEntity)})
209209

210210
case "decoy_started": // Decoy started
211-
p.eventDispatcher.Dispatch(events.DecoyStartEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, entity)})
211+
p.eventDispatcher.Dispatch(events.DecoyStartEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, nadeEntity)})
212212

213213
case "decoy_detonate": // Decoy exploded/expired
214-
p.eventDispatcher.Dispatch(events.DecoyEndEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, entity)})
214+
p.eventDispatcher.Dispatch(events.DecoyEndEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, nadeEntity)})
215215

216216
case "smokegrenade_detonate": // Smoke popped
217-
p.eventDispatcher.Dispatch(events.SmokeStartEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, entity)})
217+
p.eventDispatcher.Dispatch(events.SmokeStartEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, nadeEntity)})
218218

219219
case "smokegrenade_expired": // Smoke expired
220-
p.eventDispatcher.Dispatch(events.SmokeEndEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, entity)})
220+
p.eventDispatcher.Dispatch(events.SmokeEndEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, nadeEntity)})
221221

222222
case "inferno_startburn": // Incendiary exploded/started
223-
p.eventDispatcher.Dispatch(events.FireNadeStartEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, entity)})
223+
p.eventDispatcher.Dispatch(events.FireNadeStartEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, nadeEntity)})
224224

225225
case "inferno_expire": // Incendiary expired
226-
p.eventDispatcher.Dispatch(events.FireNadeEndEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, entity)})
226+
p.eventDispatcher.Dispatch(events.FireNadeEndEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, nadeEntity)})
227227
}
228228

229229
case "player_connect": // Bot connected, players come in via string tables & data tables
@@ -451,12 +451,12 @@ func mapGameEventData(d *msg.CSVCMsg_GameEventListDescriptorT, e *msg.CSVCMsg_Ga
451451
}
452452

453453
// Just so we can nicely create NadeEvents in one line
454-
func buildNadeEvent(nadeType common.EquipmentElement, thrower *common.Player, position r3.Vector, entity *st.Entity) events.NadeEvent {
454+
func buildNadeEvent(nadeType common.EquipmentElement, thrower *common.Player, position r3.Vector, nadeEntity *st.Entity) events.NadeEvent {
455455
return events.NadeEvent{
456-
NadeType: nadeType,
457-
Thrower: thrower,
458-
Position: position,
459-
Entity: entity,
456+
NadeType: nadeType,
457+
Thrower: thrower,
458+
Position: position,
459+
NadeEntity: nadeEntity,
460460
}
461461
}
462462

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)