Wip: implementing travel groups
parent
0f0e186c2b
commit
f256c54fa7
|
|
@ -21,7 +21,7 @@ impl CreatureId {
|
|||
|
||||
impl Display for CreatureId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "c-{}", self.0)
|
||||
write!(f, "crea-{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@ impl SiteId {
|
|||
|
||||
impl Display for SiteId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "s-{}", self.0)
|
||||
write!(f, "site-{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Site {
|
||||
id: SiteId,
|
||||
pub name: String,
|
||||
pub definition: SiteDef,
|
||||
areas: Vec<SiteArea>,
|
||||
accumulated_time: Duration,
|
||||
pub name: String,
|
||||
pub definition: SiteDef,
|
||||
}
|
||||
|
||||
impl Site {
|
||||
|
|
|
|||
|
|
@ -1,21 +1,72 @@
|
|||
use std::{fmt::Display, time::Duration};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::prelude::*;
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
pub struct TravelGroupId(Uuid);
|
||||
|
||||
impl TravelGroupId {
|
||||
pub fn generate() -> Self {
|
||||
Self(Uuid::new_v4())
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for TravelGroupId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "trav-{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub enum WorldPoint {
|
||||
Coords(WorldCoords),
|
||||
Site(SiteId),
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub struct TravelGroup {
|
||||
id: TravelGroupId,
|
||||
accumulated_movement: Kilometer,
|
||||
pub creatures: Vec<Creature>,
|
||||
pub position: WorldCoords,
|
||||
pub origin: Option<WorldPoint>,
|
||||
pub destination: Option<WorldPoint>,
|
||||
}
|
||||
|
||||
impl TravelGroup {
|
||||
pub fn new(creatures: Vec<Creature>, position: WorldCoords) -> Self {
|
||||
pub fn new(
|
||||
creatures: Vec<Creature>,
|
||||
position: WorldCoords,
|
||||
origin: Option<WorldPoint>,
|
||||
destination: Option<WorldPoint>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: TravelGroupId::generate(),
|
||||
accumulated_movement: 0.,
|
||||
creatures,
|
||||
position,
|
||||
origin,
|
||||
destination,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id(&self) -> TravelGroupId {
|
||||
self.id
|
||||
}
|
||||
|
||||
/// The travel speed of the group in km/h
|
||||
pub fn speed(&self) -> Kilometer {
|
||||
// TODO: hard-coded, should depend on the creatures in the group
|
||||
5.0
|
||||
}
|
||||
|
||||
pub fn advance_time(&mut self, time: Duration) {
|
||||
self.accumulated_movement += time.as_secs_f32() / 3600. * self.speed();
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, creature: Creature) {
|
||||
self.creatures.push(creature)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub type Kilometer = f32;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
pub struct WorldCoords {
|
||||
pub x: i32,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use super::prelude::*;
|
|||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct World {
|
||||
pub sites: Vec<Site>,
|
||||
pub travel_groups: Vec<TravelGroup>,
|
||||
}
|
||||
|
||||
impl World {
|
||||
|
|
|
|||
Loading…
Reference in New Issue