From 64bd11d34ad27db67ec9f01cf34c0bcff2d9b01e Mon Sep 17 00:00:00 2001 From: Isse Date: Wed, 8 Mar 2023 22:40:16 +0100 Subject: [PATCH] use wpos_to_cpos --- server/src/cmd.rs | 4 +--- server/src/rtsim2/rule/deplete_resources.rs | 5 ++--- server/src/rtsim2/tick.rs | 10 +++------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/server/src/cmd.rs b/server/src/cmd.rs index dc14b666d5..8ad10cdfc3 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1273,9 +1273,7 @@ fn handle_rtsim_chunk( use crate::rtsim2::{ChunkStates, RtSim}; let pos = position(server, target, "target")?; - let chunk_key = pos.0.xy().map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| { - e as i32 / sz as i32 - }); + let chunk_key = pos.0.xy().as_::().wpos_to_cpos(); let rtsim = server.state.ecs().read_resource::(); let data = rtsim.state().data(); diff --git a/server/src/rtsim2/rule/deplete_resources.rs b/server/src/rtsim2/rule/deplete_resources.rs index 810af3aaed..1bc0667b40 100644 --- a/server/src/rtsim2/rule/deplete_resources.rs +++ b/server/src/rtsim2/rule/deplete_resources.rs @@ -1,5 +1,5 @@ use crate::rtsim2::{event::OnBlockChange, ChunkStates}; -use common::{terrain::TerrainChunk, vol::RectRasterableVol}; +use common::{terrain::{TerrainChunk, CoordinateConversions}, vol::RectRasterableVol}; use rtsim2::{RtState, Rule, RuleError}; pub struct DepleteResources; @@ -10,8 +10,7 @@ impl Rule for DepleteResources { let key = ctx .event .wpos - .xy() - .map2(TerrainChunk::RECT_SIZE, |e, sz| e.div_euclid(sz as i32)); + .xy().wpos_to_cpos(); if let Some(Some(chunk_state)) = ctx.state.resource_mut::().0.get(key) { let mut chunk_res = ctx.state.data().nature.get_chunk_resources(key); // Remove resources diff --git a/server/src/rtsim2/tick.rs b/server/src/rtsim2/tick.rs index 7136dc5692..fb53d80eb5 100644 --- a/server/src/rtsim2/tick.rs +++ b/server/src/rtsim2/tick.rs @@ -10,7 +10,7 @@ use common::{ rtsim::{RtSimController, RtSimEntity, RtSimVehicle}, slowjob::SlowJobPool, trade::{Good, SiteInformation}, - LoadoutBuilder, SkillSetBuilder, + LoadoutBuilder, SkillSetBuilder, terrain::CoordinateConversions, }; use common_ecs::{Job, Origin, Phase, System}; use rtsim2::data::{ @@ -216,9 +216,7 @@ impl<'a> System<'a> for Sys { let data = &mut *rtsim.state.data_mut(); for (vehicle_id, vehicle) in data.npcs.vehicles.iter_mut() { - let chunk = vehicle.wpos.xy().map2(TerrainChunk::RECT_SIZE, |e, sz| { - (e as i32).div_euclid(sz as i32) - }); + let chunk = vehicle.wpos.xy().as_::().wpos_to_cpos(); if matches!(vehicle.mode, SimulationMode::Simulated) && chunk_states.0.get(chunk).map_or(false, |c| c.is_some()) @@ -277,9 +275,7 @@ impl<'a> System<'a> for Sys { } for (npc_id, npc) in data.npcs.npcs.iter_mut() { - let chunk = npc.wpos.xy().map2(TerrainChunk::RECT_SIZE, |e, sz| { - (e as i32).div_euclid(sz as i32) - }); + let chunk = npc.wpos.xy().as_::().wpos_to_cpos(); // Load the NPC into the world if it's in a loaded chunk and is not already // loaded