|
| 1 | +package common |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/golang/geo/r3" |
| 5 | + |
| 6 | + st "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/sendtables" |
| 7 | +) |
| 8 | + |
| 9 | +// HostageState is the type for the various HostageStateXYZ constants. |
| 10 | +type HostageState byte |
| 11 | + |
| 12 | +// HostageState constants give information about hostages state. |
| 13 | +// e.g. being untied, picked up, rescued etc. |
| 14 | +const ( |
| 15 | + HostageStateIdle HostageState = 0 |
| 16 | + HostageStateBeingUntied HostageState = 1 |
| 17 | + HostageStateGettingPickedUp HostageState = 2 |
| 18 | + HostageStateBeingCarried HostageState = 3 |
| 19 | + HostageStateFollowingPlayer HostageState = 4 |
| 20 | + HostageStateGettingDropped HostageState = 5 |
| 21 | + HostageStateRescued HostageState = 6 |
| 22 | + HostageStateDead HostageState = 7 |
| 23 | +) |
| 24 | + |
| 25 | +// Hostage represents a hostage. |
| 26 | +type Hostage struct { |
| 27 | + Entity st.Entity |
| 28 | + demoInfoProvider demoInfoProvider |
| 29 | +} |
| 30 | + |
| 31 | +// Position returns the current position of the hostage. |
| 32 | +func (hostage *Hostage) Position() r3.Vector { |
| 33 | + if hostage.Entity == nil { |
| 34 | + return r3.Vector{} |
| 35 | + } |
| 36 | + |
| 37 | + return hostage.Entity.Position() |
| 38 | +} |
| 39 | + |
| 40 | +// State returns the current hostage's state. |
| 41 | +// e.g. being untied, picked up, rescued etc. |
| 42 | +// See HostageState for all possible values. |
| 43 | +func (hostage *Hostage) State() HostageState { |
| 44 | + return HostageState(getInt(hostage.Entity, "m_nHostageState")) |
| 45 | +} |
| 46 | + |
| 47 | +// Health returns the hostage's health points. |
| 48 | +// ! On Valve MM matches hostages are invulnerable, it will always return 100 unless "mp_hostages_takedamage" is set to 1 |
| 49 | +func (hostage *Hostage) Health() int { |
| 50 | + return getInt(hostage.Entity, "m_iHealth") |
| 51 | +} |
| 52 | + |
| 53 | +// Leader returns the possible player leading the hostage. |
| 54 | +// Returns nil if the hostage is not following a player. |
| 55 | +func (hostage *Hostage) Leader() *Player { |
| 56 | + return hostage.demoInfoProvider.FindPlayerByHandle(getInt(hostage.Entity, "m_leader")) |
| 57 | +} |
| 58 | + |
| 59 | +// NewHostage creates a hostage. |
| 60 | +func NewHostage(demoInfoProvider demoInfoProvider, entity st.Entity) *Hostage { |
| 61 | + return &Hostage{ |
| 62 | + demoInfoProvider: demoInfoProvider, |
| 63 | + Entity: entity, |
| 64 | + } |
| 65 | +} |
0 commit comments