diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-04 20:41:39 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-04 20:41:39 +0200 |
commit | 619c2b27f26e596c8bffc4ffb5b5b94e5bbe72da (patch) | |
tree | b6d9cd0932dd8a3b48ce0edf126a0ea6314b7388 /server/src/interaction.rs | |
parent | eaae75ef73a2d3cafda300ab63b67a9cfcb64955 (diff) | |
download | hurrycurry-619c2b27f26e596c8bffc4ffb5b5b94e5bbe72da.tar hurrycurry-619c2b27f26e596c8bffc4ffb5b5b94e5bbe72da.tar.bz2 hurrycurry-619c2b27f26e596c8bffc4ffb5b5b94e5bbe72da.tar.zst |
precompute recipe speed
Diffstat (limited to 'server/src/interaction.rs')
-rw-r--r-- | server/src/interaction.rs | 42 |
1 files changed, 17 insertions, 25 deletions
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, }); |