fix
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
//! Uses Changed<TaskQueue> + Changed<TaskState> to minimise queries.
|
||||
|
||||
use crate::entities::behaviour::{EntityBehaviourRegistry, EntityType};
|
||||
use crate::entities::cargo::HaulSlot;
|
||||
use crate::entities::cargo::{Cargo, HaulSlot};
|
||||
use crate::entities::shared_components::Ambulatory;
|
||||
use crate::entities::tasks::components::{
|
||||
ChopStep, DropStep, HaulStep, IdleState, Task, TaskQueue, TaskState,
|
||||
@@ -33,6 +33,7 @@ pub fn task_executor_system(
|
||||
mut rng_q: Query<&mut WyRand, With<GlobalRng>>,
|
||||
mut tick: Local<u32>,
|
||||
tree_parts: Query<(Entity, &TreePart)>,
|
||||
mut cargo_query: Query<&mut Cargo>,
|
||||
mut query: Query<(
|
||||
Entity,
|
||||
&mut TaskQueue,
|
||||
@@ -124,7 +125,7 @@ pub fn task_executor_system(
|
||||
ambulatory.target = Some(Vec3::new(
|
||||
target.x as f32,
|
||||
target.y as f32,
|
||||
transform.translation.z,
|
||||
target.z as f32 + 1.0,
|
||||
));
|
||||
ambulatory.current_path = None;
|
||||
}
|
||||
@@ -250,7 +251,7 @@ pub fn task_executor_system(
|
||||
}
|
||||
if let Some(_) = tilemap_mut.remove_cargo(cargo_pos) {
|
||||
haul.pick_up(*cargo_entity);
|
||||
*step = HaulStep::MovingToDest;
|
||||
*step = HaulStep::MovingToDest { chosen_drop: None };
|
||||
} else {
|
||||
failed_writer.write(TaskFailed {
|
||||
entity,
|
||||
@@ -260,11 +261,16 @@ pub fn task_executor_system(
|
||||
*state = TaskState::Failed;
|
||||
}
|
||||
}
|
||||
HaulStep::MovingToDest => {
|
||||
HaulStep::MovingToDest { chosen_drop } => {
|
||||
if chosen_drop.is_none() {
|
||||
*chosen_drop = Some(
|
||||
tilemap_mut
|
||||
.find_nearest_free_cargo_tile(*dest, 8)
|
||||
.unwrap_or(*dest),
|
||||
);
|
||||
}
|
||||
let drop_pos = chosen_drop.unwrap();
|
||||
if ambulatory.target.is_none() {
|
||||
let drop_pos = tilemap_mut
|
||||
.find_nearest_free_cargo_tile(*dest, 8)
|
||||
.unwrap_or(*dest);
|
||||
ambulatory.target = Some(Vec3::new(
|
||||
drop_pos.x as f32,
|
||||
drop_pos.y as f32,
|
||||
@@ -280,19 +286,15 @@ pub fn task_executor_system(
|
||||
* (crate::constants::TILE_SIZE * 1.5);
|
||||
if dist_sq <= arrive_sq {
|
||||
ambulatory.target = None;
|
||||
*step = HaulStep::Dropping;
|
||||
*step = HaulStep::Dropping { drop_pos };
|
||||
}
|
||||
}
|
||||
HaulStep::Dropping => {
|
||||
if let Some(cargo) = haul.release() {
|
||||
let drop_pos = tilemap_mut
|
||||
.find_nearest_free_cargo_tile(
|
||||
transform.translation.as_ivec3(),
|
||||
8,
|
||||
)
|
||||
.unwrap_or(transform.translation.as_ivec3());
|
||||
let _ = tilemap_mut.place_cargo(drop_pos, cargo);
|
||||
// TODO: update Cargo.tile_pos via CargoDroppedEvent
|
||||
HaulStep::Dropping { drop_pos } => {
|
||||
if let Some(cargo_entity) = haul.release() {
|
||||
let _ = tilemap_mut.place_cargo(*drop_pos, cargo_entity);
|
||||
if let Ok(mut cargo) = cargo_query.get_mut(cargo_entity) {
|
||||
cargo.tile_pos = *drop_pos;
|
||||
}
|
||||
}
|
||||
*step = HaulStep::Done;
|
||||
}
|
||||
@@ -308,11 +310,16 @@ pub fn task_executor_system(
|
||||
};
|
||||
|
||||
match step {
|
||||
DropStep::Moving => {
|
||||
DropStep::Moving { chosen_drop } => {
|
||||
if chosen_drop.is_none() {
|
||||
*chosen_drop = Some(
|
||||
tilemap_mut
|
||||
.find_nearest_free_cargo_tile(*pos, 8)
|
||||
.unwrap_or(*pos),
|
||||
);
|
||||
}
|
||||
let drop_pos = chosen_drop.unwrap();
|
||||
if ambulatory.target.is_none() {
|
||||
let drop_pos = tilemap_mut
|
||||
.find_nearest_free_cargo_tile(*pos, 8)
|
||||
.unwrap_or(*pos);
|
||||
ambulatory.target = Some(Vec3::new(
|
||||
drop_pos.x as f32,
|
||||
drop_pos.y as f32,
|
||||
@@ -328,18 +335,15 @@ pub fn task_executor_system(
|
||||
* (crate::constants::TILE_SIZE * 1.5);
|
||||
if dist_sq <= arrive_sq {
|
||||
ambulatory.target = None;
|
||||
*step = DropStep::Dropping;
|
||||
*step = DropStep::Dropping { drop_pos };
|
||||
}
|
||||
}
|
||||
DropStep::Dropping => {
|
||||
if let Some(cargo) = haul.release() {
|
||||
let drop_pos = tilemap_mut
|
||||
.find_nearest_free_cargo_tile(
|
||||
transform.translation.as_ivec3(),
|
||||
8,
|
||||
)
|
||||
.unwrap_or(transform.translation.as_ivec3());
|
||||
let _ = tilemap_mut.place_cargo(drop_pos, cargo);
|
||||
DropStep::Dropping { drop_pos } => {
|
||||
if let Some(cargo_entity) = haul.release() {
|
||||
let _ = tilemap_mut.place_cargo(*drop_pos, cargo_entity);
|
||||
if let Ok(mut cargo) = cargo_query.get_mut(cargo_entity) {
|
||||
cargo.tile_pos = *drop_pos;
|
||||
}
|
||||
}
|
||||
*step = DropStep::Done;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user