Skip to content

Commit 3e6ec8f

Browse files
committed
Delete nade projectiles & infernos at end of round
Sometimes grenade projectiles and infernos wouldn't be deleted at the end of the round. Now we just clean up when we get the game-event round_officially_ended fixes #42
1 parent 7c9e8ae commit 3e6ec8f

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

datatables.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@ func (p *Parser) bindGrenadeProjectiles(event st.EntityCreatedEvent) {
316316
})
317317
}
318318

319+
// Seperate function because we also use it in round_officially_ended (issue #42)
320+
func (p *Parser) nadeProjectileDestroyed(proj *common.GrenadeProjectile) {
321+
// If the grenade projectile entity is destroyed AFTER round_officially_ended
322+
// we already executed this code when we received that event.
323+
if _, exists := p.gameState.grenadeProjectiles[proj.EntityID]; !exists {
324+
return
325+
}
326+
327+
delete(p.gameState.grenadeProjectiles, proj.EntityID)
328+
}
329+
319330
func (p *Parser) bindWeapon(event st.EntityCreatedEvent) {
320331
p.weapons[event.Entity.ID] = common.NewEquipment("")
321332
eq := &p.weapons[event.Entity.ID]

demoinfocs_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func TestDemoInfoCs(t *testing.T) {
9898
t.Error("Unexprected default value, check output of last round")
9999
}
100100
})
101+
101102
// Check some things at match start
102103
p.RegisterEventHandler(func(events.MatchStartedEvent) {
103104
participants := gs.Participants()
@@ -120,6 +121,13 @@ func TestDemoInfoCs(t *testing.T) {
120121
}
121122
})
122123

124+
// Regression test for grenade projectiles not being deleted at the end of the round (issue #42)
125+
p.RegisterEventHandler(func(events.RoundStartedEvent) {
126+
if nProjectiles := len(p.GameState().GrenadeProjectiles()); nProjectiles > 0 {
127+
t.Error("Expected 0 GrenadeProjectiles at the start of the round, got", nProjectiles)
128+
}
129+
})
130+
123131
// Net-message stuff
124132
var netTickHandlerID dispatch.HandlerIdentifier
125133
netTickHandlerID = p.RegisterNetMessageHandler(func(tick *msg.CNETMsg_Tick) {

game_events.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
7979
Winner: t,
8080
})
8181

82-
case "round_officially_ended": // Round ended. . . probably the event where you get teleported to the spawn (=> You can still walk around between round_end and this?)
82+
case "round_officially_ended": // The event after which you get teleported to the spawn (=> You can still walk around between round_end and this event)
83+
// Issue #42
84+
// Sometimes grenades aren't deleted / destroyed via entity-updates at the end of the round,
85+
// so we need to do it here for those that weren't.
86+
//
87+
// We're not deleting them from entitites though as that's supposed to be as close to the actual demo data as possible.
88+
// We're also not using Entity.Destroy() because it would - in some cases - be called twice on the same entity
89+
// and it's supposed to be called when the demo actually says so (same case as with GameState.entities).
90+
for _, proj := range p.gameState.grenadeProjectiles {
91+
p.nadeProjectileDestroyed(proj)
92+
}
93+
8394
p.eventDispatcher.Dispatch(events.RoundOfficialyEndedEvent{})
8495

8596
case "round_mvp": // Round MVP was announced

0 commit comments

Comments
 (0)