aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock16
-rw-r--r--data/recipes.ts7
-rw-r--r--server/src/data.rs25
-rw-r--r--server/src/interaction.rs53
4 files changed, 55 insertions, 46 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 84354732..41ef5e82 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -322,9 +322,9 @@ dependencies = [
[[package]]
name = "httparse"
-version = "1.9.3"
+version = "1.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d0e7a4dd27b9476dc40cb050d3632d3bba3a70ddbff012285f7f8559a1e7e545"
+checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9"
[[package]]
name = "humantime"
@@ -384,9 +384,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miniz_oxide"
-version = "0.7.3"
+version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae"
+checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [
"adler",
]
@@ -464,9 +464,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
-version = "1.0.85"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23"
+checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
@@ -688,9 +688,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.66"
+version = "2.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
+checksum = "ff8655ed1d86f3af4ee3fd3263786bc14245ad17c4c7e85ba7187fb3ae028c90"
dependencies = [
"proc-macro2",
"quote",
diff --git a/data/recipes.ts b/data/recipes.ts
index e7a90047..ea2706ed 100644
--- a/data/recipes.ts
+++ b/data/recipes.ts
@@ -24,6 +24,7 @@ interface Recipe {
outputs: (string | null)[],
action: "instant" | "passive" | "active"
duration?: number
+ revert_duration?: number,
warn?: boolean
}
@@ -60,8 +61,8 @@ function cook(from: string, to?: string) {
const i = from.endsWith("-pot") ? from : from + "-pot"
const o = (to ?? ("cooked-" + from)) + "-pot"
if (!from.endsWith("-pot")) out({ action: "instant", inputs: ["pot", from], outputs: [i] })
- out({ action: "passive", duration: 20, tile: "stove", inputs: [i], outputs: [o] })
- out({ action: "passive", duration: 5, tile: "stove", inputs: [o], outputs: ["burned-pot"], warn: true })
+ out({ action: "passive", duration: 20, revert_duration: 40, tile: "stove", inputs: [i], outputs: [o] })
+ out({ action: "passive", duration: 5, revert_duration: 10, tile: "stove", inputs: [o], outputs: ["burned-pot"], warn: true })
}
function mix(from: string, to?: string) {
const i = from + "-mixer"
@@ -72,7 +73,7 @@ function mix(from: string, to?: string) {
function bake(from: string, to?: string) {
const o = (to ?? ("cooked-" + from))
out({ action: "passive", duration: 25, tile: "oven", inputs: [from], outputs: [o] })
- out({ action: "passive", duration: 15, tile: "oven", inputs: [o], outputs: ["burned"], warn: true })
+ out({ action: "passive", duration: 15, revert_duration: 20, tile: "oven", inputs: [o], outputs: ["burned"], warn: true })
}
function crate(item: string) {
out({ action: "instant", tile: item + "-crate", inputs: [], outputs: [item], })
diff --git a/server/src/data.rs b/server/src/data.rs
index 2d942de4..a8b712b0 100644
--- a/server/src/data.rs
+++ b/server/src/data.rs
@@ -28,8 +28,8 @@ use std::{collections::HashMap, sync::RwLock};
pub enum Action {
#[default]
Never,
- Passive(f32),
- Active(f32),
+ Passive,
+ Active,
Instant,
}
@@ -45,6 +45,10 @@ pub struct RecipeDecl {
action: Action,
#[serde(default)]
warn: bool,
+ #[serde(default)]
+ revert_duration: Option<f32>,
+ #[serde(default)]
+ duration: Option<f32>,
}
#[derive(Debug, Clone, Deserialize)]
@@ -109,15 +113,16 @@ pub fn build_gamedata(
let tile = r.tile.map(|t| TileIndex(register(&tile_names, t)));
match r.action {
Action::Never => {}
- Action::Passive(duration) => recipes.push(Recipe::Passive {
- duration,
+ Action::Passive => recipes.push(Recipe::Passive {
+ duration: r.duration.expect("duration for passive missing"),
warn: r.warn,
tile,
+ revert_duration: r.revert_duration,
input: inputs.next().expect("passive recipe without input"),
output: outputs.next(),
}),
- Action::Active(duration) => recipes.push(Recipe::Active {
- duration,
+ Action::Active => recipes.push(Recipe::Active {
+ duration: r.duration.expect("duration for active missing"),
tile,
input: inputs.next().expect("active recipe without input"),
outputs: [outputs.next(), outputs.next()],
@@ -236,11 +241,3 @@ impl Gamedata {
.map(|(i, e)| (RecipeIndex(i), e))
}
}
-impl Action {
- pub fn duration(&self) -> f32 {
- match self {
- Action::Instant | Action::Never => 0.,
- Action::Passive(x) | Action::Active(x) => *x,
- }
- }
-}
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()));
+ }
}
}
}