summaryrefslogtreecommitdiff
path: root/server/src/entity
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-20 19:43:14 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-20 19:43:14 +0200
commitfebbc005cfac682257af0b74be5b307d4f23f91c (patch)
treea9884a873bd995b75c74583121e4bdd27c3fa5c2 /server/src/entity
parent1a45b0e0f5de785ddf268d7371f0cdaeafe9daa7 (diff)
downloadhurrycurry-febbc005cfac682257af0b74be5b307d4f23f91c.tar
hurrycurry-febbc005cfac682257af0b74be5b307d4f23f91c.tar.bz2
hurrycurry-febbc005cfac682257af0b74be5b307d4f23f91c.tar.zst
send score menu on game end
Diffstat (limited to 'server/src/entity')
-rw-r--r--server/src/entity/conveyor.rs12
-rw-r--r--server/src/entity/customers/mod.rs6
-rw-r--r--server/src/entity/mod.rs10
-rw-r--r--server/src/entity/portal.rs13
4 files changed, 26 insertions, 15 deletions
diff --git a/server/src/entity/conveyor.rs b/server/src/entity/conveyor.rs
index 38478db7..7f3d8688 100644
--- a/server/src/entity/conveyor.rs
+++ b/server/src/entity/conveyor.rs
@@ -1,3 +1,5 @@
+use std::collections::VecDeque;
+
/*
Hurry Curry! - a game about cooking
Copyright 2024 metamuffin
@@ -18,7 +20,7 @@
use super::EntityT;
use crate::game::{interact_effect, Game};
use anyhow::{anyhow, Result};
-use hurrycurry_protocol::{glam::IVec2, ItemIndex, ItemLocation};
+use hurrycurry_protocol::{glam::IVec2, ItemIndex, ItemLocation, PacketC};
#[derive(Debug, Clone)]
pub struct Conveyor {
@@ -31,7 +33,7 @@ pub struct Conveyor {
}
impl EntityT for Conveyor {
- fn tick(&mut self, game: &mut Game, dt: f32) -> Result<()> {
+ fn tick(&mut self, game: &mut Game, packet_out: &mut VecDeque<PacketC>, dt: f32) -> Result<()> {
let from = game
.tiles
.get(&self.from)
@@ -44,7 +46,9 @@ impl EntityT for Conveyor {
.get(t)
.ok_or(anyhow!("conveyor filter missing"))?;
filter_tile.item.as_ref().map(|e| e.kind)
- } else { self.filter_item.as_ref().map(|i| *i) };
+ } else {
+ self.filter_item.as_ref().map(|i| *i)
+ };
if let Some(filter) = filter {
if from_item.kind != filter {
@@ -71,7 +75,7 @@ impl EntityT for Conveyor {
&mut from.item,
ItemLocation::Tile(self.from),
Some(to.kind),
- &mut game.packet_out,
+ packet_out,
&mut game.score,
true,
);
diff --git a/server/src/entity/customers/mod.rs b/server/src/entity/customers/mod.rs
index e8679dc9..974ae686 100644
--- a/server/src/entity/customers/mod.rs
+++ b/server/src/entity/customers/mod.rs
@@ -22,7 +22,7 @@ use super::EntityT;
use crate::{data::Demand, game::Game};
use anyhow::{anyhow, Result};
use fake::{faker, Fake};
-use hurrycurry_protocol::{glam::IVec2, DemandIndex, Message, PacketS, PlayerID};
+use hurrycurry_protocol::{glam::IVec2, DemandIndex, Message, PacketC, PacketS, PlayerID};
use log::{info, warn};
use pathfinding::{find_path, Path};
use rand::{random, thread_rng};
@@ -74,7 +74,7 @@ impl Customers {
}
impl EntityT for Customers {
- fn tick(&mut self, game: &mut Game, dt: f32) -> Result<()> {
+ fn tick(&mut self, game: &mut Game, packet_out: &mut VecDeque<PacketC>, dt: f32) -> Result<()> {
self.spawn_cooldown -= dt;
self.spawn_cooldown = self.spawn_cooldown.max(0.);
if self.customers.len() < 5 && self.spawn_cooldown <= 0. {
@@ -253,7 +253,7 @@ impl EntityT for Customers {
self.customers.remove(&c).unwrap();
}
for (player, packet) in self.cpackets.drain(..) {
- if let Err(err) = game.packet_in(player, packet, &mut vec![]) {
+ if let Err(err) = game.packet_in(player, packet, &mut vec![], packet_out) {
warn!("demand packet {err}");
}
}
diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs
index c471a6d4..ec5ec744 100644
--- a/server/src/entity/mod.rs
+++ b/server/src/entity/mod.rs
@@ -18,18 +18,18 @@
pub mod conveyor;
pub mod customers;
pub mod portal;
-use std::collections::{HashMap, HashSet};
+use std::collections::{HashMap, HashSet, VecDeque};
use crate::{data::ItemTileRegistry, game::Game, interaction::Recipe};
use anyhow::{anyhow, Result};
use conveyor::Conveyor;
use customers::{demands::generate_demands, Customers};
-use hurrycurry_protocol::{glam::IVec2, ItemIndex, TileIndex};
+use hurrycurry_protocol::{glam::IVec2, ItemIndex, PacketC, TileIndex};
use portal::Portal;
use serde::{Deserialize, Serialize};
pub trait EntityT: Clone {
- fn tick(&mut self, game: &mut Game, dt: f32) -> Result<()>;
+ fn tick(&mut self, game: &mut Game, packet_out: &mut VecDeque<PacketC>, dt: f32) -> Result<()>;
}
macro_rules! entities {
@@ -37,8 +37,8 @@ macro_rules! entities {
#[derive(Debug, Clone)]
pub enum Entity { $($e($e)),* }
impl EntityT for Entity {
- fn tick(&mut self, game: &mut Game, dt: f32) -> Result<()> {
- match self { $(Entity::$e(x) => x.tick(game, dt)),*, }
+ fn tick(&mut self, game: &mut Game, packet_out: &mut VecDeque<PacketC>, dt: f32) -> Result<()> {
+ match self { $(Entity::$e(x) => x.tick(game, packet_out, dt)),*, }
}
}
};
diff --git a/server/src/entity/portal.rs b/server/src/entity/portal.rs
index 2d4a762b..e0ec353f 100644
--- a/server/src/entity/portal.rs
+++ b/server/src/entity/portal.rs
@@ -1,3 +1,5 @@
+use std::collections::VecDeque;
+
/*
Hurry Curry! - a game about cooking
Copyright 2024 metamuffin
@@ -18,7 +20,7 @@
use super::EntityT;
use crate::game::{interact_effect, Game};
use anyhow::{anyhow, Result};
-use hurrycurry_protocol::{glam::IVec2, ItemLocation};
+use hurrycurry_protocol::{glam::IVec2, ItemLocation, PacketC};
#[derive(Debug, Default, Clone)]
pub struct Portal {
@@ -27,7 +29,12 @@ pub struct Portal {
}
impl EntityT for Portal {
- fn tick(&mut self, game: &mut Game, _dt: f32) -> Result<()> {
+ fn tick(
+ &mut self,
+ game: &mut Game,
+ packet_out: &mut VecDeque<PacketC>,
+ _dt: f32,
+ ) -> Result<()> {
let [from, to] = game
.tiles
.get_many_mut([&self.from, &self.to])
@@ -42,7 +49,7 @@ impl EntityT for Portal {
&mut from.item,
ItemLocation::Tile(self.from),
Some(to.kind),
- &mut game.packet_out,
+ packet_out,
&mut game.score,
true,
);