Skip to content

Commit

Permalink
Merge pull request #535 from mateusmaia/master
Browse files Browse the repository at this point in the history
feat: implement player_sound event
  • Loading branch information
markus-wa authored May 17, 2024
2 parents 3cd3eb4 + b12aa13 commit c1e18e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/demoinfocs/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ type PlayerJump struct {
Player *common.Player // May be nil if the demo is partially corrupt (player is 'unconnected', see #156 and #172).
}

// PlayerSound signals that a player emitted a sound.
type PlayerSound struct {
Player *common.Player
Radius int
Duration time.Duration
}

// Kill signals that a player has been killed.
type Kill struct {
Weapon *common.Equipment
Expand Down
11 changes: 10 additions & 1 deletion pkg/demoinfocs/game_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package demoinfocs
import (
"fmt"
"math"
"time"

"github.com/golang/geo/r3"
"github.com/markus-wa/go-unassert"
Expand Down Expand Up @@ -257,7 +258,7 @@ func newGameEventHandler(parser *parser, ignoreBombsiteIndexNotFound bool) gameE
"player_given_c4": nil, // Dunno, only present in locally recorded (POV) demos
"player_ping": nil, // When a player uses the "ping system" added with the operation Broken Fang, only present in locally recorded (POV) demos
"player_ping_stop": nil, // When a player's ping expired, only present in locally recorded (POV) demos
"player_sound": nil, // When a player makes a sound. TODO: implement player_sound
"player_sound": delayIfNoPlayers(geh.playerSound), // When a player makes a sound

// Player changed team. Delayed for two reasons
// - team IDs of other players changing teams in the same tick might not have changed yet
Expand Down Expand Up @@ -420,6 +421,14 @@ func (geh gameEventHandler) playerJump(data map[string]*msg.CSVCMsg_GameEventKey
})
}

func (geh gameEventHandler) playerSound(data map[string]*msg.CSVCMsg_GameEventKeyT) {
geh.dispatch(events.PlayerSound{
Player: geh.playerByUserID32(data["userid"].GetValShort()),
Radius: int(data["radius"].GetValLong()),
Duration: time.Duration(data["duration"].GetValFloat() * float32(time.Second)),
})
}

func (geh gameEventHandler) weaponFire(data map[string]*msg.CSVCMsg_GameEventKeyT) {
if geh.parser.isSource2() && !geh.parser.disableMimicSource1GameEvents {
return
Expand Down

0 comments on commit c1e18e8

Please sign in to comment.