Skip to main content

cs2_gsi/model/
map.rs

1//! Map / round-series statistics.
2
3use super::helpers::{de_num_or_str, de_opt_num_or_str};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// Map / series-level state.
8#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
9pub struct Map {
10    /// Game mode, e.g. `"competitive"`, `"casual"`, `"deathmatch"`.
11    #[serde(default)]
12    pub mode: String,
13    /// Map filename, e.g. `"de_dust2"`.
14    #[serde(default)]
15    pub name: String,
16    /// Current map phase.
17    #[serde(default)]
18    pub phase: MapPhase,
19    /// 1-based round number within the current map.
20    #[serde(default, deserialize_with = "de_num_or_str")]
21    pub round: u32,
22    /// Counter-Terrorist team statistics.
23    #[serde(default, alias = "team_ct")]
24    pub team_ct: TeamStatistics,
25    /// Terrorist team statistics.
26    #[serde(default, alias = "team_t")]
27    pub team_t: TeamStatistics,
28    /// Number of round wins required to win a series in this map.
29    #[serde(default, deserialize_with = "de_opt_num_or_str")]
30    pub num_matches_to_win_series: Option<u32>,
31    /// Spectator count for the live broadcast (only present in some modes).
32    #[serde(default, deserialize_with = "de_opt_num_or_str")]
33    pub current_spectators: Option<u32>,
34    /// Souvenir packs awarded so far.
35    #[serde(default, deserialize_with = "de_opt_num_or_str")]
36    pub souvenirs_total: Option<u32>,
37    /// Per-round winner side, keyed by `"<round_index>"`.
38    /// Values are typically `"ct_win_..."` / `"t_win_..."`.
39    #[serde(default)]
40    pub round_wins: HashMap<String, String>,
41}
42
43/// Phase of the current map.
44#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq, Hash)]
45#[serde(rename_all = "lowercase")]
46pub enum MapPhase {
47    /// Pre-match warmup.
48    Warmup,
49    /// Live round play.
50    Live,
51    /// Mid-match intermission (between halves).
52    Intermission,
53    /// Match has ended.
54    Gameover,
55    /// Unrecognized / not-yet-mapped phase.
56    #[serde(other)]
57    #[default]
58    Unknown,
59}
60
61/// Statistics for a side (CT / T).
62#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
63pub struct TeamStatistics {
64    /// Round score for this side.
65    #[serde(default, deserialize_with = "de_num_or_str")]
66    pub score: u32,
67    /// Number of round losses incurred consecutively (for loss-bonus calc).
68    #[serde(default, deserialize_with = "de_num_or_str")]
69    pub consecutive_round_losses: u32,
70    /// Tactical timeouts remaining for this side.
71    #[serde(default, deserialize_with = "de_num_or_str")]
72    pub timeouts_remaining: u32,
73    /// Maps won so far in the current series (BoX).
74    #[serde(default, deserialize_with = "de_num_or_str")]
75    pub matches_won_this_series: u32,
76    /// Optional team name.
77    #[serde(default)]
78    pub name: String,
79    /// Optional team flag identifier.
80    #[serde(default)]
81    pub flag: String,
82}