more logs, fixed off by one error & added early exit to fell
This commit is contained in:
parent
722e58d7ad
commit
e52be9c428
6 changed files with 25 additions and 10 deletions
|
@ -53,7 +53,7 @@ impl Depots {
|
|||
|
||||
// dump inventory
|
||||
for (i, _) in turtle.inventory().await.into_iter().enumerate().filter(|(_,n)| n.is_some()) {
|
||||
turtle.execute(Select(i as u32)).await;
|
||||
turtle.execute(Select((i+1) as u32)).await;
|
||||
turtle.execute(DropDown(64)).await;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,17 +10,19 @@ use typetag::serde;
|
|||
use crate::{blocks::{Vec3, Position, Direction}, turtle::{TurtleCommander, TurtleCommand, TurtleCommandResponse, InventorySlot}, tasks::{Task, TaskState}, depot::Depots, mine::fill, paths::TRANSPARENT};
|
||||
|
||||
#[tracing::instrument(skip(turtle))]
|
||||
pub async fn fell_tree(turtle: TurtleCommander, bottom: Vec3) -> Option<()> {
|
||||
pub async fn fell_tree(turtle: TurtleCommander, bottom: Vec3) -> Option<bool> {
|
||||
let mut log = bottom;
|
||||
let mut successful = false;
|
||||
loop {
|
||||
let near = turtle.goto_adjacent(log).await?;
|
||||
if turtle.world().get(log).await.is_some_and(|b| !b.name.contains("log")) {
|
||||
break;
|
||||
}
|
||||
successful = true;
|
||||
turtle.execute(near.dig(log)?).await;
|
||||
log += Vec3::y();
|
||||
}
|
||||
Some(())
|
||||
Some(successful)
|
||||
}
|
||||
|
||||
/// Minutes before checking
|
||||
|
@ -47,12 +49,20 @@ impl TreeFarm {
|
|||
let trees = self.size.product();
|
||||
let spacing = Vec3::new(2, 32, 2);
|
||||
turtle.dock().await;
|
||||
let mut successful = false;
|
||||
for tree in 0..trees {
|
||||
let index = fill(self.size, tree);
|
||||
let offset = index.component_mul(&spacing);
|
||||
trace!("tree {tree}; {offset:?}");
|
||||
let tree = self.position + offset;
|
||||
fell_tree(turtle.clone(), tree).await?;
|
||||
if fell_tree(turtle.clone(), tree).await? {
|
||||
successful = true;
|
||||
}
|
||||
}
|
||||
|
||||
if !successful {
|
||||
warn!("incomplete harvest, no trees found");
|
||||
return Some(());
|
||||
}
|
||||
|
||||
// sweep across floor (not upper levels) to get saplings
|
||||
|
|
|
@ -62,7 +62,7 @@ async fn main() -> Result<(), Error> {
|
|||
let filter = filter::Targets::new()
|
||||
.with_default(Level::INFO)
|
||||
.with_target("server::tasks", Level::TRACE)
|
||||
.with_target("server::turtle", Level::ERROR)
|
||||
.with_target("server::turtle", Level::WARN)
|
||||
.with_target("server::paths", Level::ERROR)
|
||||
.with_target("server::turtle_api", Level::INFO)
|
||||
.with_target("server::fell", Level::WARN)
|
||||
|
|
|
@ -173,7 +173,7 @@ where F: FnMut(InventorySlot) -> bool {
|
|||
for (i, slot) in turtle.inventory().await.into_iter().enumerate() {
|
||||
if let Some(item) = slot {
|
||||
if filter(item) {
|
||||
turtle.execute(Select(i as u32)).await;
|
||||
turtle.execute(Select((i + 1) as u32)).await;
|
||||
turtle.execute(DropFront(64)).await;
|
||||
} else {
|
||||
counter += 1;
|
||||
|
|
|
@ -6,7 +6,7 @@ use tokio::task::spawn_blocking;
|
|||
use tracing::{trace, error};
|
||||
use pathfinding::prelude::astar;
|
||||
|
||||
const LOOKUP_LIMIT: usize = 10_000_000;
|
||||
const LOOKUP_LIMIT: usize = 100_000_000;
|
||||
|
||||
#[tracing::instrument(skip(world))]
|
||||
pub async fn route_facing(from: Position, to: Vec3, world: &SharedWorld) -> Option<Vec<Position>> {
|
||||
|
|
|
@ -369,7 +369,7 @@ impl TurtleCommander {
|
|||
|
||||
attempts -= 1;
|
||||
if attempts == 0 {
|
||||
error!("goto {pos:?} failed");
|
||||
error!("adjacent {pos:?} failed");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -384,9 +384,13 @@ impl TurtleCommander {
|
|||
let command = recent.dig(next_position.pos);
|
||||
match command {
|
||||
Some(command) => self.execute(command).await,
|
||||
None => break 'route,
|
||||
None => {
|
||||
warn!("next location not diggable");
|
||||
break 'route
|
||||
},
|
||||
};
|
||||
} else {
|
||||
warn!("non destructible block on route");
|
||||
break 'route;
|
||||
}
|
||||
}
|
||||
|
@ -399,6 +403,7 @@ impl TurtleCommander {
|
|||
self.execute(TurtleCommand::Left).await;
|
||||
recent = self.execute(TurtleCommand::Left).await.pos;
|
||||
}
|
||||
warn!("command failed");
|
||||
break 'route;
|
||||
}
|
||||
|
||||
|
@ -462,7 +467,7 @@ pub(crate) async fn process_turtle_update(
|
|||
let info = TurtleInfo::from_update(update, turtle.name.clone(), turtle.position.clone());
|
||||
|
||||
if let TurtleCommandResponse::Failure = info.ret {
|
||||
warn!("{}: command failure", turtle.name.to_str());
|
||||
info!("{}: command failure", turtle.name.to_str());
|
||||
}
|
||||
|
||||
if let Some(send) = turtle.callback.take() {
|
||||
|
|
Loading…
Reference in a new issue