veloren_rtsim/data/
report.rs1use common::{
2 resources::TimeOfDay,
3 rtsim::{Actor, SiteId},
4 terrain::SpriteKind,
5};
6use serde::{Deserialize, Serialize};
7use slotmap::HopSlotMap;
8use std::ops::Deref;
9use vek::*;
10
11pub use common::rtsim::ReportId;
12
13#[derive(Clone, Serialize, Deserialize)]
26pub struct Report {
27 pub kind: ReportKind,
28 pub at_tod: TimeOfDay,
29}
30
31impl Report {
32 fn remember_for(&self) -> f64 {
34 const DAYS: f64 = 60.0 * 60.0 * 24.0;
35 match &self.kind {
36 ReportKind::Death { killer, .. } => {
37 if killer.is_some() {
38 DAYS * 15.0
40 } else {
41 DAYS * 5.0
42 }
43 },
44 ReportKind::Theft { .. } => DAYS * 1.5,
46 }
47 }
48}
49
50#[derive(Copy, Clone, Serialize, Deserialize)]
51pub enum ReportKind {
52 Death {
53 actor: Actor,
54 killer: Option<Actor>,
55 },
56 Theft {
57 thief: Actor,
58 site: Option<SiteId>,
60 sprite: SpriteKind,
62 },
63}
64
65#[derive(Clone, Default, Serialize, Deserialize)]
66pub struct Reports {
67 pub reports: HopSlotMap<ReportId, Report>,
68}
69
70impl Reports {
71 pub fn create(&mut self, report: Report) -> ReportId { self.reports.insert(report) }
72
73 pub fn cleanup(&mut self, current_time: TimeOfDay) {
74 self.reports.retain(|_, report| {
76 (current_time.0 - report.at_tod.0).max(0.0) < report.remember_for()
77 });
78 }
80}
81
82impl Deref for Reports {
83 type Target = HopSlotMap<ReportId, Report>;
84
85 fn deref(&self) -> &Self::Target { &self.reports }
86}