diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-04 20:35:20 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-04 20:35:20 +0200 |
commit | eaae75ef73a2d3cafda300ab63b67a9cfcb64955 (patch) | |
tree | 33040feb74d7b03e3655dc32135c93bbda75c229 /server/src/interaction.rs | |
parent | 740dc4b45cb59ff184e5cebc5b19f402bb9d54d2 (diff) | |
download | hurrycurry-eaae75ef73a2d3cafda300ab63b67a9cfcb64955.tar hurrycurry-eaae75ef73a2d3cafda300ab63b67a9cfcb64955.tar.bz2 hurrycurry-eaae75ef73a2d3cafda300ab63b67a9cfcb64955.tar.zst |
refactor tile tick and improve active recipe behaviour
Diffstat (limited to 'server/src/interaction.rs')
-rw-r--r-- | server/src/interaction.rs | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/server/src/interaction.rs b/server/src/interaction.rs index e2e4d08b..99537487 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -66,8 +66,15 @@ pub fn interact( score_changed, packet_out, ); - return; + } else { + packet_out.push_back(PacketC::SetProgress { + item: this_loc, + position: active.position, + speed: active.speed, + warn: active.warn, + }); } + return; } } } @@ -119,6 +126,12 @@ pub fn interact( from: other_loc, to: this_loc, }); + packet_out.push_back(PacketC::SetProgress { + item: this_loc, + position: 0., + speed: 1. / duration, + warn: false, + }); return; } } @@ -198,40 +211,61 @@ pub fn tick_slot( data: &Gamedata, tile: Option<TileIndex>, slot: &mut Option<Item>, + slot_loc: ItemLocation, score: &mut Score, -) -> Option<TickEffect> { + score_changed: &mut bool, + packet_out: &mut VecDeque<PacketC>, +) { if let Some(item) = slot { if let Some(a) = &mut item.active { let r = &data.recipe(a.recipe); let prev_speed = a.speed; - if !r.supports_tile(tile) { - if let Some(revert_duration) = r.revert_duration() { - a.speed = -1. / revert_duration + if r.supports_tile(tile) { + if a.speed < 0. { + if let Recipe::Passive { duration, .. } = &data.recipe(a.recipe) { + a.speed = 1. / duration; + } } + } else if let Some(revert_duration) = r.revert_duration() { + a.speed = -1. / revert_duration } + if a.position < 0. { + item.active = None; + packet_out.push_back(PacketC::ClearProgress { item: slot_loc }); + return; + } if a.position >= 1. { if let Recipe::Passive { output, .. } = &data.recipe(a.recipe) { *slot = output.map(|kind| Item { kind, active: None }); score.passive_recipes += 1; - return Some(TickEffect::Produce); + *score_changed = true; + packet_out.push_back(PacketC::SetProgress { + warn: false, + 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 < 0. { - item.active = None; - return Some(TickEffect::ClearProgress); - } a.position += dt * a.speed; - a.position = a.position.clamp(0., 1.); + a.position = a.position.min(1.); if a.speed != prev_speed { - return Some(TickEffect::Progress { - warn: r.warn(), + packet_out.push_back(PacketC::SetProgress { position: a.position, speed: a.speed, + warn: a.warn, + item: slot_loc, }); + return; } } else { for (ri, recipe) in data.recipes() { @@ -250,18 +284,19 @@ pub fn tick_slot( warn: *warn, speed: 1. / *duration, }); - return Some(TickEffect::Progress { + packet_out.push_back(PacketC::SetProgress { position: 0., speed: 1. / *duration, warn: *warn, + item: slot_loc, }); + return; } } } } } } - None } fn produce( |