@@ -15,24 +15,25 @@ import (
1515type Player struct {
1616 demoInfoProvider demoInfoProvider // provider for demo info such as tick-rate or current tick
1717
18- SteamID64 uint64 // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID
19- LastAlivePosition r3.Vector // The location where the player was last alive. Should be equal to Position if the player is still alive.
20- UserID int // Mostly used in game-events to address this player
21- Name string // Steam / in-game user name
22- Inventory map [int ]* Equipment // All weapons / equipment the player is currently carrying. See also Weapons().
23- AmmoLeft [32 ]int // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType
24- EntityID int // Usually the same as Entity.ID() but may be different between player death and re-spawn.
25- Entity st.Entity // May be nil between player-death and re-spawn
26- FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds)
27- FlashTick int // In-game tick at which the player was last flashed
28- TeamState * TeamState // When keeping the reference make sure you notice when the player changes teams
29- Team Team // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists).
30- IsBot bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot().
31- IsConnected bool
32- IsDefusing bool
33- IsPlanting bool
34- IsReloading bool
35- IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162
18+ SteamID64 uint64 // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID
19+ LastAlivePosition r3.Vector // The location where the player was last alive. Should be equal to Position if the player is still alive.
20+ UserID int // Mostly used in game-events to address this player
21+ Name string // Steam / in-game user name
22+ Inventory map [int ]* Equipment // All weapons / equipment the player is currently carrying. See also Weapons().
23+ AmmoLeft [32 ]int // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType
24+ EntityID int // Usually the same as Entity.ID() but may be different between player death and re-spawn.
25+ Entity st.Entity // May be nil between player-death and re-spawn
26+ FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds)
27+ FlashTick int // In-game tick at which the player was last flashed
28+ TeamState * TeamState // When keeping the reference make sure you notice when the player changes teams
29+ Team Team // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists).
30+ IsBot bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot().
31+ IsConnected bool
32+ IsDefusing bool
33+ IsPlanting bool
34+ IsReloading bool
35+ IsUnknown bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162
36+ PreviousFramePosition r3.Vector // CS2 only, used to compute velocity as it's not networked in CS2 demos
3637}
3738
3839func (p * Player ) PlayerPawnEntity () st.Entity {
@@ -380,7 +381,9 @@ func (p *Player) Armor() int {
380381// CS2 values:
381382// -1 -> Not available, demo probably not coming from a Valve server
382383// 0 -> None?
383- // 11 -> Classic Competitive
384+ // 7 -> Wingman 2v2
385+ // 11 -> Premier mode
386+ // 12 -> Classic Competitive
384387func (p * Player ) RankType () int {
385388 if p .demoInfoProvider .IsSource2 () {
386389 return getInt (p .Entity , "m_iCompetitiveRankType" )
@@ -519,7 +522,14 @@ func (p *Player) PositionEyes() r3.Vector {
519522// Velocity returns the player's velocity.
520523func (p * Player ) Velocity () r3.Vector {
521524 if p .demoInfoProvider .IsSource2 () {
522- panic ("Velocity() is not supported for Source 2 demos" )
525+ t := 64.0
526+ diff := p .Position ().Sub (p .PreviousFramePosition )
527+
528+ return r3.Vector {
529+ X : diff .X * t ,
530+ Y : diff .Y * t ,
531+ Z : diff .Z * t ,
532+ }
523533 }
524534
525535 if p .Entity == nil {
@@ -799,8 +809,9 @@ type demoInfoProvider interface {
799809// Intended for internal use only.
800810func NewPlayer (demoInfoProvider demoInfoProvider ) * Player {
801811 return & Player {
802- Inventory : make (map [int ]* Equipment ),
803- demoInfoProvider : demoInfoProvider ,
812+ Inventory : make (map [int ]* Equipment ),
813+ demoInfoProvider : demoInfoProvider ,
814+ PreviousFramePosition : r3.Vector {},
804815 }
805816}
806817
0 commit comments