aboutsummaryrefslogtreecommitdiff
path: root/server/src/interaction.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/interaction.rs')
-rw-r--r--server/src/interaction.rs282
1 files changed, 140 insertions, 142 deletions
diff --git a/server/src/interaction.rs b/server/src/interaction.rs
index fef1ca40..5dd7099b 100644
--- a/server/src/interaction.rs
+++ b/server/src/interaction.rs
@@ -15,7 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use hurrycurry_client_lib::{gamedata_index::GamedataIndex, Involvement, Item};
+use hurrycurry_client_lib::{Involvement, Item, gamedata_index::GamedataIndex};
use hurrycurry_protocol::{Gamedata, ItemLocation, PacketC, PlayerID, Recipe, Score, TileIndex};
use log::info;
use std::collections::VecDeque;
@@ -36,46 +36,45 @@ pub fn interact(
packet_out: &mut VecDeque<PacketC>,
) {
let _ = automated; //? what was this used for??
- if 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) {
- if let Recipe::Active { outputs, speed, .. } = recipe {
- if edge {
- active.speed += speed;
- } else {
- active.speed -= speed;
- active.speed = active.speed.max(0.); // in case of "release without press" when items cool on active tile
- }
- if active.position >= 1. {
- let this_had_item = this.is_some();
- let other_had_item = other.is_some();
- *other = outputs[0].map(|kind| Item { kind, active: None });
- *this = outputs[1].map(|kind| Item { kind, active: None });
- produce(
- this_had_item,
- other_had_item,
- this,
- this_loc,
- other,
- other_loc,
- score_changed,
- packet_out,
- );
- } else {
- packet_out.push_back(PacketC::SetProgress {
- player,
- item: this_loc,
- position: active.position,
- speed: active.speed,
- warn: active.warn,
- });
- }
- return;
- }
- }
+ if other.is_none()
+ && let Some(item) = this
+ && let Some(active) = &mut item.active
+ {
+ let recipe = &data.recipe(active.recipe);
+ if recipe.supports_tile(tile)
+ && let Recipe::Active { outputs, speed, .. } = recipe
+ {
+ if edge {
+ active.speed += speed;
+ } else {
+ active.speed -= speed;
+ active.speed = active.speed.max(0.); // in case of "release without press" when items cool on active tile
}
+ if active.position >= 1. {
+ let this_had_item = this.is_some();
+ let other_had_item = other.is_some();
+ *other = outputs[0].map(|kind| Item { kind, active: None });
+ *this = outputs[1].map(|kind| Item { kind, active: None });
+ produce(
+ this_had_item,
+ other_had_item,
+ this,
+ this_loc,
+ other,
+ other_loc,
+ score_changed,
+ packet_out,
+ );
+ } else {
+ packet_out.push_back(PacketC::SetProgress {
+ player,
+ item: this_loc,
+ position: active.position,
+ speed: active.speed,
+ warn: active.warn,
+ });
+ }
+ return;
}
}
if !edge {
@@ -87,48 +86,48 @@ pub fn interact(
}
match recipe {
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 {
- player,
- recipe: ri,
- speed: *speed,
- position: 0.,
- warn: false,
- });
- }
- }
+ if other.is_none()
+ && let Some(item) = this
+ && item.kind == *input
+ && item.active.is_none()
+ {
+ info!("start active recipe {ri:?}");
+ item.active = Some(Involvement {
+ player,
+ recipe: ri,
+ speed: *speed,
+ position: 0.,
+ warn: false,
+ });
}
- if this.is_none() {
- if let Some(item) = &other {
- if item.kind == *input && item.active.is_none() {
- let mut item = other.take().unwrap();
- info!("start active recipe {ri:?}");
- item.active = Some(Involvement {
- player,
- recipe: ri,
- speed: *speed,
- position: 0.,
- warn: false,
- });
- *this = Some(item);
- score.active_recipes += 1;
- packet_out.push_back(PacketC::MoveItem {
- from: other_loc,
- to: this_loc,
- });
- packet_out.push_back(PacketC::SetProgress {
- player,
- item: this_loc,
- position: 0.,
- speed: *speed,
- warn: false,
- });
- return;
- }
- }
+ if this.is_none()
+ && let Some(item) = &other
+ && item.kind == *input
+ && item.active.is_none()
+ {
+ let mut item = other.take().unwrap();
+ info!("start active recipe {ri:?}");
+ item.active = Some(Involvement {
+ player,
+ recipe: ri,
+ speed: *speed,
+ position: 0.,
+ warn: false,
+ });
+ *this = Some(item);
+ score.active_recipes += 1;
+ packet_out.push_back(PacketC::MoveItem {
+ from: other_loc,
+ to: this_loc,
+ });
+ packet_out.push_back(PacketC::SetProgress {
+ player,
+ item: this_loc,
+ position: 0.,
+ speed: *speed,
+ warn: false,
+ });
+ return;
}
}
Recipe::Instant {
@@ -176,24 +175,25 @@ pub fn interact(
})
});
- if can_place && this.is_none() {
- if let Some(item) = other.take() {
- *this = Some(item);
- packet_out.push_back(PacketC::MoveItem {
- from: other_loc,
- to: this_loc,
- });
- return;
- }
+ if can_place
+ && this.is_none()
+ && let Some(item) = other.take()
+ {
+ *this = Some(item);
+ packet_out.push_back(PacketC::MoveItem {
+ from: other_loc,
+ to: this_loc,
+ });
+ return;
}
- if other.is_none() {
- if let Some(item) = this.take() {
- *other = Some(item);
- packet_out.push_back(PacketC::MoveItem {
- from: this_loc,
- to: other_loc,
- });
- }
+ if other.is_none()
+ && let Some(item) = this.take()
+ {
+ *other = Some(item);
+ packet_out.push_back(PacketC::MoveItem {
+ from: this_loc,
+ to: other_loc,
+ });
}
}
@@ -225,10 +225,10 @@ pub fn tick_slot(
let prev_speed = a.speed;
if r.supports_tile(tile) {
- if a.speed <= 0. {
- if let Recipe::Passive { speed, .. } = &data.recipe(a.recipe) {
- a.speed = *speed;
- }
+ if a.speed <= 0.
+ && let Recipe::Passive { speed, .. } = &data.recipe(a.recipe)
+ {
+ a.speed = *speed;
}
} else if let Some(revert_speed) = r.revert_speed() {
a.speed = -revert_speed
@@ -241,25 +241,25 @@ pub fn tick_slot(
packet_out.push_back(PacketC::ClearProgress { item: slot_loc });
return;
}
- if a.position >= 1. {
- if let Recipe::Passive { output, warn, .. } = &data.recipe(a.recipe) {
- *slot = output.map(|kind| Item { kind, active: None });
- score.passive_recipes += 1;
- *score_changed = true;
- packet_out.push_back(PacketC::SetProgress {
- player: None,
- warn: *warn,
- item: slot_loc,
- position: 1.,
- speed: 0.,
- });
- packet_out.push_back(PacketC::SetItem {
- location: slot_loc,
- item: slot.as_ref().map(|i| i.kind),
- });
- return;
- };
- }
+ if a.position >= 1.
+ && let Recipe::Passive { output, warn, .. } = &data.recipe(a.recipe)
+ {
+ *slot = output.map(|kind| Item { kind, active: None });
+ score.passive_recipes += 1;
+ *score_changed = true;
+ packet_out.push_back(PacketC::SetProgress {
+ player: None,
+ warn: *warn,
+ item: slot_loc,
+ position: 1.,
+ speed: 0.,
+ });
+ packet_out.push_back(PacketC::SetItem {
+ location: slot_loc,
+ item: slot.as_ref().map(|i| i.kind),
+ });
+ return;
+ };
a.position += dt * a.speed;
a.position = a.position.min(1.);
@@ -276,29 +276,27 @@ pub fn tick_slot(
} else if let Some(recipes) = data_index.recipe_passive_by_input.get(&item.kind) {
for &ri in recipes {
let recipe = data.recipe(ri);
- if recipe.supports_tile(tile) {
- if let Recipe::Passive {
+ if recipe.supports_tile(tile)
+ && let Recipe::Passive {
input, warn, speed, ..
} = recipe
- {
- if *input == item.kind {
- item.active = Some(Involvement {
- player: None,
- recipe: ri,
- position: 0.,
- warn: *warn,
- speed: *speed,
- });
- packet_out.push_back(PacketC::SetProgress {
- player: None,
- position: 0.,
- speed: *speed,
- warn: *warn,
- item: slot_loc,
- });
- return;
- }
- }
+ && *input == item.kind
+ {
+ item.active = Some(Involvement {
+ player: None,
+ recipe: ri,
+ position: 0.,
+ warn: *warn,
+ speed: *speed,
+ });
+ packet_out.push_back(PacketC::SetProgress {
+ player: None,
+ position: 0.,
+ speed: *speed,
+ warn: *warn,
+ item: slot_loc,
+ });
+ return;
}
}
}