summaryrefslogtreecommitdiff
path: root/server/src/interaction.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/interaction.rs')
-rw-r--r--server/src/interaction.rs42
1 files changed, 31 insertions, 11 deletions
diff --git a/server/src/interaction.rs b/server/src/interaction.rs
index f2d44dee..11409b10 100644
--- a/server/src/interaction.rs
+++ b/server/src/interaction.rs
@@ -31,14 +31,26 @@ pub fn interact(
}
}
if !edge {
+ debug!("falling edge");
if let Some(ac) = active {
if matches!(data.recipes[ac.recipe].action, Action::Active(_)) {
+ debug!("workers--");
ac.working -= 1;
}
}
return;
}
+ if hand.is_none() {
+ debug!("rising edge");
+ if let Some(active) = active {
+ if matches!(data.recipes[active.recipe].action, Action::Active(_)) {
+ debug!("workers++");
+ active.working += 1;
+ }
+ }
+ }
+
if active.is_none() && !items.is_empty() && hand.is_none() {
out(Take(items.len() - 1));
return;
@@ -54,7 +66,7 @@ pub fn interact(
}
}
- if hand.is_none() {
+ if hand.is_none() && active.is_none() {
'rloop: for (ri, r) in data.recipes.iter().enumerate() {
if tile != r.tile {
continue;
@@ -74,19 +86,27 @@ pub fn interact(
match r.action {
Action::Passive(_) => {
- info!("use recipe {r:?}");
+ info!("use passive recipe {ri}");
*active = Some(ActiveRecipe {
recipe: ri,
progress: 0.,
- working: 0,
+ working: 1,
+ });
+ break 'rloop;
+ }
+ Action::Active(_) => {
+ info!("use active recipe {ri}");
+ *active = Some(ActiveRecipe {
+ recipe: ri,
+ progress: 0.,
+ working: 1,
});
break 'rloop;
}
- Action::Active(_) => {}
Action::Instant => {
- info!("use recipe {r:?}");
- for i in 0..items.len() {
- out(Consume(i))
+ info!("use instant recipe {ri}");
+ for _ in 0..items.len() {
+ out(Consume(0))
}
for i in &r.outputs {
out(Produce(*i));
@@ -108,15 +128,15 @@ pub fn tick_tile(
data: &Gamedata,
_tile: TileIndex,
active: &mut Option<ActiveRecipe>,
- mut items: Vec<ItemIndex>,
+ items: Vec<ItemIndex>,
mut out: impl FnMut(Out),
) {
if let Some(a) = active {
let r = &data.recipes[a.recipe];
- a.progress += dt / r.action.duration();
+ a.progress += a.working as f32 * dt / r.action.duration();
if a.progress >= 1. {
- for i in 0..items.len() {
- out(Consume(i))
+ for _ in 0..items.len() {
+ out(Consume(0))
}
for i in &r.outputs {
out(Produce(*i));