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.rs35
1 files changed, 21 insertions, 14 deletions
diff --git a/server/src/interaction.rs b/server/src/interaction.rs
index 69fc9e70..adbd3b43 100644
--- a/server/src/interaction.rs
+++ b/server/src/interaction.rs
@@ -17,7 +17,7 @@
*/
use crate::{
data::Gamedata,
- game::{Involvement, Item, Tile},
+ game::{Involvement, Item},
protocol::{ItemIndex, TileIndex},
};
use log::info;
@@ -96,12 +96,12 @@ impl Recipe {
}
}
}
- pub fn supports_tile(&self, tile: TileIndex) -> bool {
+ pub fn supports_tile(&self, tile: Option<TileIndex>) -> bool {
if let Some(tile_constraint) = self.tile() {
- if tile != tile_constraint {
- false
+ if let Some(tile) = tile {
+ tile == tile_constraint
} else {
- true
+ false
}
} else {
true
@@ -118,17 +118,19 @@ pub enum InteractEffect {
pub fn interact(
data: &Gamedata,
edge: bool,
- tile_kind: TileIndex,
+ tile: Option<TileIndex>,
this: &mut Option<Item>,
other: &mut Option<Item>,
points: &mut i64,
) -> Option<InteractEffect> {
- let interactable = data.is_tile_interactable(tile_kind);
+ let interactable = tile
+ .map(|tile| data.is_tile_interactable(tile))
+ .unwrap_or(true);
if interactable && other.is_none() {
if let Some(item) = this {
if let Some(active) = &mut item.active {
let recipe = &data.recipe(active.recipe);
- if recipe.supports_tile(tile_kind) {
+ if recipe.supports_tile(tile) {
if let Recipe::Active { outputs, .. } = recipe {
if edge {
active.working += 1;
@@ -150,7 +152,7 @@ pub fn interact(
}
if interactable {
for (ri, recipe) in data.recipes() {
- if !recipe.supports_tile(tile_kind) {
+ if !recipe.supports_tile(tile) {
continue;
}
match recipe {
@@ -233,18 +235,23 @@ pub enum TickEffect {
Progress(bool),
Produce,
}
-pub fn tick_tile(dt: f32, data: &Gamedata, tile: &mut Tile) -> Option<TickEffect> {
- if let Some(item) = &mut tile.item {
+pub fn tick_tile(
+ dt: f32,
+ data: &Gamedata,
+ tile: Option<TileIndex>,
+ slot: &mut Option<Item>,
+) -> Option<TickEffect> {
+ if let Some(item) = slot {
if let Some(a) = &mut item.active {
let r = &data.recipe(a.recipe);
- if r.supports_tile(tile.kind) {
+ if r.supports_tile(tile) {
a.progress += a.working as f32 * dt / r.duration().unwrap();
} 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 });
+ *slot = output.map(|kind| Item { kind, active: None });
return Some(TickEffect::Produce);
};
a.progress = 1.;
@@ -255,7 +262,7 @@ pub fn tick_tile(dt: f32, data: &Gamedata, tile: &mut Tile) -> Option<TickEffect
return Some(TickEffect::Progress(r.warn()));
} else {
for (ri, recipe) in data.recipes() {
- if recipe.supports_tile(tile.kind) {
+ if recipe.supports_tile(tile) {
if let Recipe::Passive { input, .. } = recipe {
if *input == item.kind {
item.active = Some(Involvement {