1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*
Hurry Curry! - a game about cooking
Copyright (C) 2025 Hurry Curry! Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
pub mod book;
pub mod bot;
pub mod campaign;
pub mod conveyor;
pub mod customers;
pub mod environment_effect;
pub mod item_portal;
pub mod pedestrians;
pub mod player_portal;
pub mod tram;
pub mod tutorial;
use crate::{entity::pedestrians::Pedestrians, scoreboard::ScoreboardStore};
use anyhow::Result;
use book::Book;
use campaign::{Gate, Map};
use conveyor::Conveyor;
use customers::Customers;
use environment_effect::{EnvironmentController, EnvironmentEffectController};
use hurrycurry_client_lib::Game;
use hurrycurry_data::{entities::EntityDecl, Serverdata};
use hurrycurry_locale::TrError;
use hurrycurry_protocol::{glam::IVec2, Character, Gamedata, PacketC, PacketS, PlayerID};
use item_portal::ItemPortal;
use player_portal::PlayerPortal;
use std::{
any::Any,
collections::{HashMap, VecDeque},
};
use tram::Tram;
pub type DynEntity = Box<dyn Entity + Send + Sync + 'static>;
pub type Entities = Vec<DynEntity>;
pub struct EntityContext<'a> {
pub game: &'a mut Game,
pub serverdata: &'a Serverdata,
pub packet_out: &'a mut VecDeque<PacketC>,
pub packet_in: &'a mut VecDeque<PacketS>,
pub score_changed: &'a mut bool,
pub load_map: &'a mut Option<String>,
pub scoreboard: &'a ScoreboardStore,
pub replies: Option<&'a mut Vec<PacketC>>,
pub dt: f32,
}
pub trait Entity: Any {
fn tick(&mut self, _c: EntityContext<'_>) -> Result<()> {
Ok(())
}
fn finished(&self) -> bool {
false
}
fn constructor(&mut self, _c: EntityContext<'_>) {}
fn destructor(&mut self, _c: EntityContext<'_>) {}
fn interact(
&mut self,
_c: EntityContext<'_>,
_pos: Option<IVec2>,
_player: PlayerID,
) -> Result<bool, TrError> {
Ok(false)
}
}
pub fn construct_entity(decl: &EntityDecl, data: &Gamedata) -> DynEntity {
match decl.to_owned() {
EntityDecl::Book { pos } => Box::new(Book(pos)),
EntityDecl::ItemPortal { from, to } => Box::new(ItemPortal { from, to }),
EntityDecl::PlayerPortal { from, to } => Box::new(PlayerPortal { from, to }),
EntityDecl::Conveyor { from, to, speed } => Box::new(Conveyor {
from,
to,
max_cooldown: 1. / speed.unwrap_or(2.),
cooldown: 0.,
}),
EntityDecl::Map { name, pos } => Box::new(Map { pos, name }),
EntityDecl::Gate { condition, pos } => Box::new(Gate {
condition,
unlocked: false,
pos,
blocker_tile: data
.get_tile_by_name("fence")
.expect("asserted earlier (tm)"),
active: true,
}),
EntityDecl::Customers { scaling_factor } => {
Box::new(Customers::new(scaling_factor.unwrap_or(0.5)))
}
EntityDecl::EnvironmentEffect(config) => Box::new(EnvironmentEffectController::new(config)),
EntityDecl::Environment(names) => Box::new(EnvironmentController(names)),
EntityDecl::Tram {
length,
color,
points,
smoothing,
spacing,
} => Box::new(Tram {
length,
character: Character {
color: color.unwrap_or_default(),
hairstyle: 0,
headwear: 0,
},
ids: Vec::new(),
points,
progress: 0.,
spacing,
smoothing,
}),
EntityDecl::Pedestrians {
spawn_delay,
spawn_delay_stdev,
points,
speed,
} => Box::new(Pedestrians {
players: HashMap::new(),
points,
spawn_delay_distr: rand_distr::Normal::new(
spawn_delay,
spawn_delay_stdev.unwrap_or(0.),
)
.unwrap(),
cooldown: 0.,
speed: speed.unwrap_or(0.6),
}),
}
}
|