demo part 2
This commit is contained in:
@@ -176,13 +176,23 @@ pub fn task_executor_system(
|
||||
&mut tile_changed,
|
||||
&mut occlusion,
|
||||
);
|
||||
// Compute fall direction: from chopper (entity's position) toward trunk
|
||||
let chopper_pos = transform.translation.truncate(); // XY only
|
||||
let trunk_xy = Vec2::new(trunk_pos.x as f32, trunk_pos.y as f32);
|
||||
let mut fall_dir = (trunk_xy - chopper_pos).normalize_or_zero();
|
||||
// If dorf is standing on the trunk (distance ~0), fall direction is arbitrary
|
||||
if fall_dir == Vec2::ZERO {
|
||||
fall_dir = Vec2::new(1.0, 0.0); // default: fall east
|
||||
}
|
||||
let log_sprite = asset_server.load("tree_trunk.png");
|
||||
for &pos in trunk_positions.iter() {
|
||||
crate::entities::cargo::spawn_log_cargo(
|
||||
&mut commands,
|
||||
&mut tilemap_mut,
|
||||
pos,
|
||||
fall_dir,
|
||||
log_sprite.clone(),
|
||||
&mut rng,
|
||||
);
|
||||
}
|
||||
*step = ChopStep::Done;
|
||||
@@ -291,8 +301,14 @@ pub fn task_executor_system(
|
||||
}
|
||||
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) {
|
||||
if tilemap_mut.place_cargo(*drop_pos, cargo_entity).is_err() {
|
||||
warn!(
|
||||
"place_cargo failed at {:?} — tile occupied. \
|
||||
Cargo entity {:?} orphaned.",
|
||||
drop_pos, cargo_entity
|
||||
);
|
||||
} else if let Ok(mut cargo) = cargo_query.get_mut(cargo_entity)
|
||||
{
|
||||
cargo.tile_pos = *drop_pos;
|
||||
}
|
||||
}
|
||||
@@ -340,8 +356,14 @@ pub fn task_executor_system(
|
||||
}
|
||||
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) {
|
||||
if tilemap_mut.place_cargo(*drop_pos, cargo_entity).is_err() {
|
||||
warn!(
|
||||
"place_cargo failed at {:?} — tile occupied. \
|
||||
Cargo entity {:?} orphaned.",
|
||||
drop_pos, cargo_entity
|
||||
);
|
||||
} else if let Ok(mut cargo) = cargo_query.get_mut(cargo_entity)
|
||||
{
|
||||
cargo.tile_pos = *drop_pos;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user