work on devorination
fixed issue where observed turtles can't move added a layer of inderection to the lua ffi so it works with serde and the computercraft standard library
This commit is contained in:
parent
043baa7e35
commit
16ff51a0cc
4 changed files with 25 additions and 13 deletions
|
@ -73,7 +73,11 @@ local function namefront()
|
||||||
if not front or not front.shutdown then
|
if not front or not front.shutdown then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return front.getLabel()
|
return { ["Name"] = { string = front.getLabel() } }
|
||||||
|
end
|
||||||
|
|
||||||
|
local function name()
|
||||||
|
return { ["Name"] = os.computerLabel() }
|
||||||
end
|
end
|
||||||
|
|
||||||
local function inventoryinfo()
|
local function inventoryinfo()
|
||||||
|
@ -151,7 +155,7 @@ local commands = {
|
||||||
["CycleFront"] = restartfront,
|
["CycleFront"] = restartfront,
|
||||||
["Poweroff"] = os.shutdown,
|
["Poweroff"] = os.shutdown,
|
||||||
["GetFuelLimit"] = turtle.getFuelLimit,
|
["GetFuelLimit"] = turtle.getFuelLimit,
|
||||||
["Name"] = os.computerLabel,
|
["Name"] = name,
|
||||||
["NameFront"] = namefront,
|
["NameFront"] = namefront,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -97,16 +97,20 @@ async fn devore(turtle: &TurtleCommander) {
|
||||||
|
|
||||||
loop { // cancel the task of the turtle ahead so that it doesn't go wild in the depot
|
loop { // cancel the task of the turtle ahead so that it doesn't go wild in the depot
|
||||||
if let TurtleCommandResponse::Name(name) = turtle.execute(NameFront).await.ret {
|
if let TurtleCommandResponse::Name(name) = turtle.execute(NameFront).await.ret {
|
||||||
|
let name = name.string;
|
||||||
|
info!("rebirth: {name}");
|
||||||
match Name::from_str(&name) {
|
match Name::from_str(&name) {
|
||||||
Ok(name) => {
|
Ok(name) => {
|
||||||
let mut scheduler = turtle.scheduler().await;
|
let mut scheduler = turtle.scheduler().await;
|
||||||
scheduler.cancel(name).await;
|
scheduler.cancel(name).await;
|
||||||
|
info!("rebirth: canceled existing");
|
||||||
scheduler.do_on(move |turtle| tokio::spawn(async move {
|
scheduler.do_on(move |turtle| tokio::spawn(async move {
|
||||||
depot::dump(&turtle).await;
|
depot::dump(&turtle).await;
|
||||||
depot::refuel(&turtle).await;
|
depot::refuel(&turtle).await;
|
||||||
// *teleports behind you*
|
// *teleports behind you*
|
||||||
turtle.goto(Position::new(staging - position.dir.unit(), position.dir)).await;
|
turtle.goto(Position::new(staging - position.dir.unit(), position.dir)).await;
|
||||||
}).abort_handle(), name).unwrap();
|
}).abort_handle(), name).unwrap();
|
||||||
|
info!("rebirth: launched move");
|
||||||
break;
|
break;
|
||||||
},
|
},
|
||||||
Err(_) => error!("bad turtle name: {name}"),
|
Err(_) => error!("bad turtle name: {name}"),
|
||||||
|
|
|
@ -125,14 +125,12 @@ impl Scheduler {
|
||||||
where T: FnMut(TurtleCommander) -> AbortHandle
|
where T: FnMut(TurtleCommander) -> AbortHandle
|
||||||
{
|
{
|
||||||
let turtle = self.turtles.iter_mut().filter(|t| t.0.name() == turtle).next()?;
|
let turtle = self.turtles.iter_mut().filter(|t| t.0.name() == turtle).next()?;
|
||||||
match turtle.1 {
|
if let Some(task) = turtle.1.take() { // this may be unsound
|
||||||
Some(_) => None,
|
task.abort();
|
||||||
None => {
|
|
||||||
trace!("new adhoc task on {}", turtle.0.name().to_str());
|
|
||||||
turtle.1 = Some(task(turtle.0.clone()));
|
|
||||||
Some(())
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
trace!("new adhoc task on {}", turtle.0.name().to_str());
|
||||||
|
turtle.1 = Some(task(turtle.0.clone()));
|
||||||
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn task_on(&mut self, mut task: Box<dyn Task>, turtle: Name) -> Option<()> {
|
pub fn task_on(&mut self, mut task: Box<dyn Task>, turtle: Name) -> Option<()> {
|
||||||
|
|
|
@ -388,7 +388,7 @@ impl TurtleCommander {
|
||||||
let steps: Vec<TurtleCommand> = route.iter().map_windows(|[from,to]| from.difference(**to).unwrap()).collect();
|
let steps: Vec<TurtleCommand> = route.iter().map_windows(|[from,to]| from.difference(**to).unwrap()).collect();
|
||||||
|
|
||||||
'route: for (next_position, command) in route.into_iter().skip(1).zip(steps) {
|
'route: for (next_position, command) in route.into_iter().skip(1).zip(steps) {
|
||||||
if world.occupied(next_position.pos).await {
|
if recent.pos != next_position.pos && world.occupied(next_position.pos).await {
|
||||||
if world.garbage(next_position.pos).await {
|
if world.garbage(next_position.pos).await {
|
||||||
let command = recent.dig(next_position.pos);
|
let command = recent.dig(next_position.pos);
|
||||||
match command {
|
match command {
|
||||||
|
@ -399,7 +399,7 @@ impl TurtleCommander {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
warn!("non destructible block on route");
|
warn!("non destructible block on route: {} at {:?}", world.get(next_position.pos).await.unwrap().name, next_position);
|
||||||
break 'route;
|
break 'route;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,7 +480,7 @@ pub(crate) async fn process_turtle_update(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(send) = turtle.callback.take() {
|
if let Some(send) = turtle.callback.take() {
|
||||||
send.send(info).unwrap();
|
send.send(info).unwrap_or_else(|_| warn!("task cancelled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(recv) = turtle.receiver.as_mut() {
|
if let Some(recv) = turtle.receiver.as_mut() {
|
||||||
|
@ -544,6 +544,12 @@ pub(crate) struct InventorySlot {
|
||||||
pub(crate) count: u32,
|
pub(crate) count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bodge
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
|
pub struct TurtleString {
|
||||||
|
pub string: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub(crate) enum TurtleCommandResponse {
|
pub(crate) enum TurtleCommandResponse {
|
||||||
None,
|
None,
|
||||||
|
@ -551,7 +557,7 @@ pub(crate) enum TurtleCommandResponse {
|
||||||
Failure,
|
Failure,
|
||||||
Item(InventorySlot),
|
Item(InventorySlot),
|
||||||
Inventory(Vec<InventorySlot>),
|
Inventory(Vec<InventorySlot>),
|
||||||
Name(String),
|
Name(TurtleString),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TurtleCommand {
|
impl TurtleCommand {
|
||||||
|
|
Loading…
Reference in a new issue