diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/data/demands.rs | 4 | ||||
-rw-r--r-- | server/src/data/mod.rs | 6 | ||||
-rw-r--r-- | server/src/interaction.rs | 42 |
3 files changed, 22 insertions, 30 deletions
diff --git a/server/src/data/demands.rs b/server/src/data/demands.rs index 3f4b839d..ecfad402 100644 --- a/server/src/data/demands.rs +++ b/server/src/data/demands.rs @@ -57,8 +57,8 @@ pub fn generate_demands( }; let base_cost = match r { - Recipe::Passive { duration, .. } => 2. + duration * 0.1, - Recipe::Active { duration, .. } => 2. + duration, + Recipe::Passive { speed, .. } => 2. + (1. / speed) * 0.1, + Recipe::Active { speed, .. } => 2. + (1. / speed), Recipe::Instant { .. } => 1., }; diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs index 53414178..12d4f23e 100644 --- a/server/src/data/mod.rs +++ b/server/src/data/mod.rs @@ -181,17 +181,17 @@ pub fn build_data( match r.action { RecipeDeclAction::Never => {} RecipeDeclAction::Passive => recipes.push(Recipe::Passive { - duration: r.duration.ok_or(anyhow!("duration for passive missing"))?, + speed: 1. / r.duration.ok_or(anyhow!("duration for passive missing"))?, warn: r.warn, tile, - revert_duration: r.revert_duration, + revert_speed: r.revert_duration.map(|d| 1. / d), input: inputs .next() .ok_or(anyhow!("passive recipe without input"))?, output: outputs.next(), }), RecipeDeclAction::Active => recipes.push(Recipe::Active { - duration: r.duration.ok_or(anyhow!("duration for active missing"))?, + speed: 1. / r.duration.ok_or(anyhow!("duration for active missing"))?, tile, input: inputs .next() diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 99537487..c475e051 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -17,7 +17,7 @@ */ use hurrycurry_client_lib::{Involvement, Item}; use hurrycurry_protocol::{Gamedata, ItemLocation, PacketC, Recipe, Score, TileIndex}; -use log::info; +use log::{info, warn}; use std::collections::VecDeque; pub fn interact( @@ -42,14 +42,11 @@ pub fn interact( if let Some(active) = &mut item.active { let recipe = &data.recipe(active.recipe); if recipe.supports_tile(tile) { - if let Recipe::Active { - outputs, duration, .. - } = recipe - { + if let Recipe::Active { outputs, speed, .. } = recipe { if edge { - active.speed += 1. / duration; + active.speed += speed; } else { - active.speed -= 1. / duration; + active.speed -= speed; } if active.position >= 1. { let this_had_item = this.is_some(); @@ -89,16 +86,14 @@ pub fn interact( continue; } match recipe { - Recipe::Active { - input, duration, .. - } => { + Recipe::Active { input, speed, .. } => { if other.is_none() { if let Some(item) = this { if item.kind == *input && item.active.is_none() { info!("start active recipe {ri:?}"); item.active = Some(Involvement { recipe: ri, - speed: 1. / duration, + speed: *speed, position: 0., warn: false, }); @@ -109,13 +104,13 @@ pub fn interact( if let Some(item) = &other { if item.kind == *input { let mut item = other.take().unwrap(); - if let Some(active) = &mut item.active { - active.speed += 1. / duration; + if item.active.is_some() { + warn!("interact recipe tested when already active") } else { info!("start active recipe {ri:?}"); item.active = Some(Involvement { recipe: ri, - speed: 1. / duration, + speed: *speed, position: 0., warn: false, }); @@ -129,7 +124,7 @@ pub fn interact( packet_out.push_back(PacketC::SetProgress { item: this_loc, position: 0., - speed: 1. / duration, + speed: *speed, warn: false, }); return; @@ -223,12 +218,12 @@ pub fn tick_slot( if r.supports_tile(tile) { if a.speed < 0. { - if let Recipe::Passive { duration, .. } = &data.recipe(a.recipe) { - a.speed = 1. / duration; + if let Recipe::Passive { speed, .. } = &data.recipe(a.recipe) { + a.speed = *speed; } } - } else if let Some(revert_duration) = r.revert_duration() { - a.speed = -1. / revert_duration + } else if let Some(revert_speed) = r.revert_speed() { + a.speed = revert_speed } if a.position < 0. { @@ -271,10 +266,7 @@ pub fn tick_slot( for (ri, recipe) in data.recipes() { if recipe.supports_tile(tile) { if let Recipe::Passive { - input, - warn, - duration, - .. + input, warn, speed, .. } = recipe { if *input == item.kind { @@ -282,11 +274,11 @@ pub fn tick_slot( recipe: ri, position: 0., warn: *warn, - speed: 1. / *duration, + speed: *speed, }); packet_out.push_back(PacketC::SetProgress { position: 0., - speed: 1. / *duration, + speed: *speed, warn: *warn, item: slot_loc, }); |