1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 18:24:05 +02:00

add player flags (right now I've only done stuff for checking if player is on ground)

This commit is contained in:
ExplodingImplosion 2025-09-29 17:06:31 -04:00
commit d461dbc7c1
2 changed files with 12 additions and 0 deletions

View file

@ -86,6 +86,7 @@ pub struct Player {
pub bounds: Box,
pub weapons: [Handle; 3],
pub handle: Handle,
pub flags: u16,
pub(crate) conditions: [u8; 20],
}
@ -150,6 +151,7 @@ pub const PLAYER_BOX_DEFAULT: Box = Box {
};
impl Player {
pub const FL_ONGROUND: u16 = 1;
pub fn new(entity: EntityId) -> Player {
Player {
entity,
@ -158,6 +160,10 @@ impl Player {
}
}
pub fn is_in_air(&self) -> bool {
self.flags & Player::FL_ONGROUND == 0
}
pub fn collides(&self, projectile: &Projectile, time_per_tick: f32) -> bool {
let current_position = projectile.position;
let next_position = projectile.position + (projectile.initial_speed * time_per_tick);

View file

@ -16,6 +16,9 @@ pub fn handle_player_entity(
const OUTER: SendPropIdentifier = SendPropIdentifier::new("DT_AttributeContainer", "m_hOuter");
const OUTER2: SendPropIdentifier = SendPropIdentifier::new("DT_AttributeManager", "m_hOuter");
const FLAGS_PROP: SendPropIdentifier =
SendPropIdentifier::new("DT_BasePlayer", "m_fFlags");
const HEALTH_PROP: SendPropIdentifier = SendPropIdentifier::new("DT_BasePlayer", "m_iHealth");
const MAX_HEALTH_PROP: SendPropIdentifier =
SendPropIdentifier::new("DT_BasePlayer", "m_iMaxHealth");
@ -114,6 +117,9 @@ pub fn handle_player_entity(
let handle = Handle::try_from(&prop.value).unwrap_or_default();
player.weapons[2] = handle;
}
FLAGS_PROP => {
player.flags = i64::try_from(&prop.value).unwrap_or_default() as u16;
}
PLAYER_COND | PLAYER_COND_BITS => {
player.conditions[0..4].copy_from_slice(
&i64::try_from(&prop.value).unwrap_or_default().to_le_bytes()[0..4],