mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Fix dominating message, fix fake player loading, mess around with reactor crystals
This commit is contained in:
@@ -42,33 +42,41 @@ impl CubeLocationsParser {
|
||||
}
|
||||
}
|
||||
|
||||
fn locations_sorted_by_distance_from_point(cubes: &[super::parser::Cube], point: (u8, u8, u8), locations_of_id: u32) -> Vec<CubeLocationInfo> {
|
||||
let target_x = point.0 as f32;
|
||||
let target_y = point.1 as f32;
|
||||
let target_z = point.2 as f32;
|
||||
let mut relevant_cubes: Vec<(f32, CubeLocationInfo)> = cubes.into_iter()
|
||||
.filter(|x| x.id == locations_of_id)
|
||||
.map(|cube| {
|
||||
let distance = (
|
||||
(cube.x as f32 - target_x).powi(2)
|
||||
+ (cube.y as f32 - target_y).powi(2)
|
||||
+ (cube.z as f32 - target_z).powi(2)
|
||||
).sqrt();
|
||||
(distance, CubeLocationInfo {
|
||||
x: cube.x,
|
||||
y: cube.y,
|
||||
z: cube.z,
|
||||
extras: cube.orientation,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
relevant_cubes.sort_by_key(|(distance, _)| (distance * 1_000_000.0) as i64);
|
||||
relevant_cubes.into_iter()
|
||||
.map(|(_, cube)| cube)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn locations_of_by_distance_to_first(&self, r: &mut dyn std::io::Read, locations_of_id: u32, distance_to_id: u32) -> Vec<CubeLocationInfo> {
|
||||
match super::parser::Cube::parse_list(r) {
|
||||
Ok(cubes) => {
|
||||
if let Some(target) = cubes.iter().find(|x| x.id == distance_to_id) {
|
||||
let target_x = target.x as f32;
|
||||
let target_y = target.y as f32;
|
||||
let target_z = target.z as f32;
|
||||
let mut relevant_cubes: Vec<(f32, CubeLocationInfo)> = cubes.into_iter()
|
||||
.filter(|x| x.id == locations_of_id)
|
||||
.map(|cube| {
|
||||
let distance = (
|
||||
(cube.x as f32 - target_x).powi(2)
|
||||
+ (cube.y as f32 - target_y).powi(2)
|
||||
+ (cube.z as f32 - target_z).powi(2)
|
||||
).sqrt();
|
||||
(distance, CubeLocationInfo {
|
||||
x: cube.x,
|
||||
y: cube.y,
|
||||
z: cube.z,
|
||||
extras: cube.orientation,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
relevant_cubes.sort_by_key(|(distance, _)| (distance * 1_000_000.0) as i64);
|
||||
relevant_cubes.into_iter()
|
||||
.map(|(_, cube)| cube)
|
||||
.collect()
|
||||
Self::locations_sorted_by_distance_from_point(
|
||||
&cubes,
|
||||
(target.x, target.y, target.z),
|
||||
locations_of_id,
|
||||
)
|
||||
} else {
|
||||
log::warn!("No cube with id {} to calculate distance", distance_to_id);
|
||||
cubes.into_iter()
|
||||
@@ -89,4 +97,20 @@ impl CubeLocationsParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn locations_of_by_distance_from(&self, r: &mut dyn std::io::Read, locations_of_id: u32, from: (u8, u8, u8)) -> Vec<CubeLocationInfo> {
|
||||
match super::parser::Cube::parse_list(r) {
|
||||
Ok(cubes) => {
|
||||
Self::locations_sorted_by_distance_from_point(
|
||||
&cubes,
|
||||
from,
|
||||
locations_of_id,
|
||||
)
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to parse cube data to find cube locations: {}", e);
|
||||
Vec::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user