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

building construction progress

This commit is contained in:
Robin Appelman 2025-06-28 20:09:35 +02:00
commit 4b88c33bf2
2 changed files with 20 additions and 1 deletions

View file

@ -209,6 +209,7 @@ pub struct Sentry {
pub shells: u16,
pub rockets: u16,
pub is_mini: bool,
pub construction_progress: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@ -226,6 +227,7 @@ pub struct Dispenser {
pub angle: f32,
pub healing: Vec<UserId>,
pub metal: u16,
pub construction_progress: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@ -247,6 +249,7 @@ pub struct Teleporter {
pub recharge_duration: f32,
pub times_used: u16,
pub yaw_to_exit: f32,
pub construction_progress: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -354,6 +357,14 @@ impl Building {
Building::Teleporter(_) => BuildingClass::Teleporter,
}
}
pub fn construction_progress(&self) -> f32 {
match self {
Building::Sentry(Sentry { construction_progress, .. })
| Building::Dispenser(Dispenser { construction_progress, .. })
| Building::Teleporter(Teleporter { construction_progress, .. }) => *construction_progress,
}
}
}
#[non_exhaustive]

View file

@ -578,6 +578,8 @@ impl GameStateAnalyser {
const MAX_HEALTH: SendPropIdentifier =
SendPropIdentifier::new("DT_BaseObject", "m_iMaxHealth");
const HEALTH: SendPropIdentifier = SendPropIdentifier::new("DT_BaseObject", "m_iHealth");
const PROGRESS: SendPropIdentifier =
SendPropIdentifier::new("DT_BaseObject", "m_flPercentageConstructed");
match building {
Building::Sentry(Sentry {
@ -590,6 +592,7 @@ impl GameStateAnalyser {
building,
max_health,
health,
construction_progress,
..
})
| Building::Dispenser(Dispenser {
@ -602,6 +605,7 @@ impl GameStateAnalyser {
building,
max_health,
health,
construction_progress,
..
})
| Building::Teleporter(Teleporter {
@ -614,9 +618,10 @@ impl GameStateAnalyser {
building,
max_health,
health,
construction_progress,
..
}) => {
for prop in entity.props(parser_state) {
for prop in &entity.props {
match prop.identifier {
LOCAL_ORIGIN => {
*position = Vector::try_from(&prop.value).unwrap_or_default()
@ -634,6 +639,9 @@ impl GameStateAnalyser {
*max_health = i64::try_from(&prop.value).unwrap_or_default() as u16
}
HEALTH => *health = i64::try_from(&prop.value).unwrap_or_default() as u16,
PROGRESS => {
*construction_progress = f32::try_from(&prop.value).unwrap_or_default()
}
_ => {}
}
}