diff options
Diffstat (limited to 'server/src/interaction.rs')
| -rw-r--r-- | server/src/interaction.rs | 53 | 
1 files changed, 32 insertions, 21 deletions
| diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 126026d6..938ab715 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -27,6 +27,7 @@ use serde::{Deserialize, Serialize};  pub enum Recipe {      Passive {          duration: f32, +        revert_duration: Option<f32>,          tile: Option<TileIndex>,          input: ItemIndex,          output: Option<ItemIndex>, @@ -60,6 +61,14 @@ impl Recipe {              _ => None,          }      } +    pub fn revert_duration(&self) -> Option<f32> { +        match self { +            Recipe::Passive { +                revert_duration, .. +            } => *revert_duration, +            _ => None, +        } +    }      pub fn warn(&self) -> bool {          match self {              Recipe::Passive { warn, .. } => *warn, @@ -222,30 +231,32 @@ pub fn tick_tile(dt: f32, data: &Gamedata, tile: &mut Tile) -> Option<TickEffect              let r = &data.recipe(a.recipe);              if r.supports_tile(tile.kind) {                  a.progress += a.working as f32 * dt / r.duration().unwrap(); -                if a.progress >= 1. { -                    if let Recipe::Passive { output, .. } = &data.recipe(a.recipe) { -                        tile.item = output.map(|kind| Item { kind, active: None }); -                        return Some(TickEffect::Produce); -                    }; -                    a.progress = 1.; -                } -                return Some(TickEffect::Progress(r.warn())); +            } else if let Some(revert_duration) = r.revert_duration() { +                a.progress -= dt / revert_duration; +            } +            if a.progress >= 1. { +                if let Recipe::Passive { output, .. } = &data.recipe(a.recipe) { +                    tile.item = output.map(|kind| Item { kind, active: None }); +                    return Some(TickEffect::Produce); +                }; +                a.progress = 1.;              } +            if a.progress < 0. { +                item.active = None; +            } +            return Some(TickEffect::Progress(r.warn()));          } else {              for (ri, recipe) in data.recipes() { -                if let Some(tile_constraint) = recipe.tile() { -                    if tile.kind != tile_constraint { -                        continue; -                    } -                } -                if let Recipe::Passive { input, .. } = recipe { -                    if *input == item.kind { -                        item.active = Some(Involvement { -                            recipe: ri, -                            progress: 0., -                            working: 1, -                        }); -                        return Some(TickEffect::Progress(recipe.warn())); +                if recipe.supports_tile(tile.kind) { +                    if let Recipe::Passive { input, .. } = recipe { +                        if *input == item.kind { +                            item.active = Some(Involvement { +                                recipe: ri, +                                progress: 0., +                                working: 1, +                            }); +                            return Some(TickEffect::Progress(recipe.warn())); +                        }                      }                  }              } | 
