aboutsummaryrefslogtreecommitdiff
path: root/server/bot/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-12-23 15:37:11 +0100
committermetamuffin <metamuffin@disroot.org>2024-12-25 20:01:20 +0100
commitb0df9b7c27a3d6316969d7feff4d912c3abf99f6 (patch)
tree118daa57feda8b571bd00bd22f6ff0dac4cc46de /server/bot/src
parent2ceeea0e5fc245602618ec47f6ff1f91a094e130 (diff)
downloadhurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar
hurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar.bz2
hurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar.zst
two-handed server
Diffstat (limited to 'server/bot/src')
-rw-r--r--server/bot/src/algos/customer.rs13
-rw-r--r--server/bot/src/algos/simple.rs13
-rw-r--r--server/bot/src/main.rs3
3 files changed, 20 insertions, 9 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs
index b243bd55..826ab534 100644
--- a/server/bot/src/algos/customer.rs
+++ b/server/bot/src/algos/customer.rs
@@ -22,7 +22,7 @@ use crate::{
use hurrycurry_client_lib::Game;
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
- DemandIndex, Message, PacketS, PlayerClass, PlayerID, Score,
+ DemandIndex, Hand, Message, PacketS, PlayerClass, PlayerID, Score,
};
use log::info;
use rand::{random, seq::IndexedRandom, thread_rng};
@@ -313,6 +313,7 @@ impl CustomerState {
PacketS::Interact {
pos: Some(pos),
player: me,
+ hand: Hand::Left,
},
PacketS::ApplyScore(Score {
demands_completed: 1,
@@ -322,6 +323,7 @@ impl CustomerState {
PacketS::Interact {
pos: None,
player: me,
+ hand: Hand::Left,
},
],
..Default::default()
@@ -354,6 +356,7 @@ impl CustomerState {
extra: vec![PacketS::ReplaceHand {
player: me,
item: demand.output,
+ hand: Hand::Left,
}],
..Default::default()
};
@@ -369,7 +372,11 @@ impl CustomerState {
cooldown,
} => {
*cooldown -= dt;
- if game.players.get(&me).is_some_and(|pl| pl.item.is_none()) {
+ if game
+ .players
+ .get(&me)
+ .is_some_and(|pl| pl.items[Hand::Left.index()].is_none())
+ {
if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), *origin) {
*self = CustomerState::Exiting { path };
}
@@ -383,10 +390,12 @@ impl CustomerState {
PacketS::Interact {
player: me,
pos: Some(*table),
+ hand: Hand::Left,
},
PacketS::Interact {
player: me,
pos: None,
+ hand: Hand::Left,
},
],
direction,
diff --git a/server/bot/src/algos/simple.rs b/server/bot/src/algos/simple.rs
index 14eb38c4..5a7e61a0 100644
--- a/server/bot/src/algos/simple.rs
+++ b/server/bot/src/algos/simple.rs
@@ -21,7 +21,7 @@ use crate::{
};
use hurrycurry_client_lib::Game;
use hurrycurry_protocol::{
- glam::IVec2, ItemIndex, Message, PlayerID, Recipe, RecipeIndex, TileIndex,
+ glam::IVec2, Hand, ItemIndex, Message, PlayerID, Recipe, RecipeIndex, TileIndex,
};
use log::{debug, warn};
@@ -106,16 +106,17 @@ impl State for Simple {
impl<S> Context<'_, S> {
pub fn is_hand_item(&self, item: ItemIndex) -> bool {
- self.game
- .players
- .get(&self.me)
- .is_some_and(|p| p.item.as_ref().is_some_and(|i| i.kind == item))
+ self.game.players.get(&self.me).is_some_and(|p| {
+ p.items[Hand::Left.index()]
+ .as_ref()
+ .is_some_and(|i| i.kind == item)
+ })
}
pub fn is_hand_occupied(&self) -> bool {
self.game
.players
.get(&self.me)
- .map(|p| p.item.is_some())
+ .map(|p| p.items[Hand::Left.index()].is_some())
.unwrap_or(false)
}
pub fn find_demand(&self) -> Option<(ItemIndex, IVec2)> {
diff --git a/server/bot/src/main.rs b/server/bot/src/main.rs
index 61ae1c1c..0ffbf4b6 100644
--- a/server/bot/src/main.rs
+++ b/server/bot/src/main.rs
@@ -19,7 +19,7 @@ use anyhow::Result;
use clap::Parser;
use hurrycurry_bot::{algos::ALGO_CONSTRUCTORS, BotAlgo, BotInput};
use hurrycurry_client_lib::{network::sync::Network, Game};
-use hurrycurry_protocol::{PacketC, PacketS, PlayerClass, PlayerID};
+use hurrycurry_protocol::{Hand, PacketC, PacketS, PlayerClass, PlayerID};
use log::warn;
use std::{thread::sleep, time::Duration};
@@ -109,6 +109,7 @@ fn main() -> Result<()> {
network.queue_out.push_back(PacketS::Interact {
player: b.id,
pos: interact,
+ hand: Hand::Left,
})
}
network.queue_out.push_back(PacketS::Movement {