mirror of
https://codeberg.org/demostf/tf-demos-viewer.git
synced 2026-06-03 18:14:11 +02:00
sentry shield
This commit is contained in:
parent
9fcc004d1d
commit
4250ca3938
1 changed files with 16 additions and 3 deletions
19
src/state.rs
19
src/state.rs
|
|
@ -488,6 +488,7 @@ pub struct BuildingState {
|
||||||
ty: BuildingType,
|
ty: BuildingType,
|
||||||
level: u8,
|
level: u8,
|
||||||
build_progress: u8,
|
build_progress: u8,
|
||||||
|
shield: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// for the purpose of viewing the demo in the browser we don't really need high accuracy for
|
// for the purpose of viewing the demo in the browser we don't really need high accuracy for
|
||||||
|
|
@ -517,6 +518,12 @@ impl BuildingState {
|
||||||
Building::Sentry(sentry) => sentry.angle,
|
Building::Sentry(sentry) => sentry.angle,
|
||||||
_ => 0.0,
|
_ => 0.0,
|
||||||
};
|
};
|
||||||
|
let shield = if let Building::Sentry(sentry) = building {
|
||||||
|
sentry.shield
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
BuildingState {
|
BuildingState {
|
||||||
position: VectorXY {
|
position: VectorXY {
|
||||||
x: position.x,
|
x: position.x,
|
||||||
|
|
@ -528,6 +535,7 @@ impl BuildingState {
|
||||||
ty,
|
ty,
|
||||||
level: building.level(),
|
level: building.level(),
|
||||||
build_progress: ((building.construction_progress() * 100.0) as u8).min(100),
|
build_progress: ((building.construction_progress() * 100.0) as u8).min(100),
|
||||||
|
shield,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -537,12 +545,14 @@ impl BuildingState {
|
||||||
// 2 bits level
|
// 2 bits level
|
||||||
// 1 bit team
|
// 1 bit team
|
||||||
// 3 bits for type
|
// 3 bits for type
|
||||||
// 10 bits for health
|
// 9 bits for health
|
||||||
|
// 1 bit for shield
|
||||||
let team = if self.team == Team::Blue { 0 } else { 1 };
|
let team = if self.team == Team::Blue { 0 } else { 1 };
|
||||||
let team_type_health = ((self.level as u16) << 14)
|
let team_type_health = ((self.level as u16) << 14)
|
||||||
+ ((team as u16) << 13)
|
+ ((team as u16) << 13)
|
||||||
+ ((self.ty as u16) << 10)
|
+ ((self.ty as u16) << 10)
|
||||||
+ self.health;
|
+ ((self.health & 511) << 1)
|
||||||
|
+ self.shield as u16;
|
||||||
let combined_bytes = team_type_health.to_le_bytes();
|
let combined_bytes = team_type_health.to_le_bytes();
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
@ -570,7 +580,8 @@ impl BuildingState {
|
||||||
world.boundary_max.y,
|
world.boundary_max.y,
|
||||||
);
|
);
|
||||||
let team_type_health = u16::from_le_bytes([bytes[4], bytes[5]]);
|
let team_type_health = u16::from_le_bytes([bytes[4], bytes[5]]);
|
||||||
let health = team_type_health & 1023;
|
let health = (team_type_health >> 1) & 511;
|
||||||
|
let shield = (team_type_health & 1) == 1;
|
||||||
let angle = Angle(bytes[6]);
|
let angle = Angle(bytes[6]);
|
||||||
let packed_team = (team_type_health >> 13) & 1;
|
let packed_team = (team_type_health >> 13) & 1;
|
||||||
let team = if packed_team == 0 {
|
let team = if packed_team == 0 {
|
||||||
|
|
@ -590,6 +601,7 @@ impl BuildingState {
|
||||||
ty,
|
ty,
|
||||||
level,
|
level,
|
||||||
build_progress,
|
build_progress,
|
||||||
|
shield,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -609,6 +621,7 @@ fn test_building_packing() {
|
||||||
level: 3,
|
level: 3,
|
||||||
ty: BuildingType::Level1Sentry,
|
ty: BuildingType::Level1Sentry,
|
||||||
build_progress: 23,
|
build_progress: 23,
|
||||||
|
shield: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let bytes = input.pack(&world);
|
let bytes = input.pack(&world);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue