mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
use wpos_to_cpos
This commit is contained in:
parent
1a117f1331
commit
64bd11d34a
@ -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_::<i32>().wpos_to_cpos();
|
||||
|
||||
let rtsim = server.state.ecs().read_resource::<RtSim>();
|
||||
let data = rtsim.state().data();
|
||||
|
@ -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::<ChunkStates>().0.get(key) {
|
||||
let mut chunk_res = ctx.state.data().nature.get_chunk_resources(key);
|
||||
// Remove resources
|
||||
|
@ -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_::<i32>().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_::<i32>().wpos_to_cpos();
|
||||
|
||||
// Load the NPC into the world if it's in a loaded chunk and is not already
|
||||
// loaded
|
||||
|
Loading…
Reference in New Issue
Block a user