use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OpenStrandedMap {
pub meta: MapMeta,
pub terrain: TerrainData,
#[serde(default)]
pub entities: Vec<MapEntity>,
#[serde(default)]
pub player_spawn: Option<PlayerSpawn>,
#[serde(default)]
pub environment: HashMap<String, String>,
#[serde(default)]
pub colormap: Option<ColormapData>,
#[serde(default)]
pub grass: Option<GrassData>,
#[serde(default)]
pub password: String,
#[serde(default)]
pub scripts: Vec<ScriptData>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MapMeta {
pub name: String,
pub engine_version: String,
pub map_version: String,
#[serde(default)]
pub source_file: String,
#[serde(default)]
pub s2_header: Option<S2Header>,
#[serde(default)]
pub created_at: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct S2Header {
pub version: String,
pub date: String,
pub time: String,
pub author: String,
pub map_type: String,
#[serde(default)]
pub type_format: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TerrainData {
pub size: u32,
pub heights: Vec<f32>,
#[serde(default = "default_seaground")]
pub seaground_level: f32,
}
fn default_seaground() -> f32 {
-2.0
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColormapData {
pub dim: u32,
pub pixels: Vec<u8>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GrassData {
pub dim: u32,
pub values: Vec<u8>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MapEntity {
pub class: String,
pub type_id: u32,
pub id: u32,
pub position: (f32, f32, f32),
#[serde(default)]
pub rotation_yaw: f32,
#[serde(default)]
pub health: f32,
#[serde(default)]
pub health_max: f32,
#[serde(default)]
pub states: Vec<String>,
#[serde(default)]
pub script: Option<String>,
#[serde(default)]
pub amount: u32,
#[serde(default)]
pub parent_id: u32,
#[serde(default)]
pub parent_class: u8,
#[serde(default)]
pub links: Vec<u32>,
#[serde(default)]
pub build_progress: u32,
#[serde(default)]
pub unit_data: Option<UnitData>,
#[serde(default)]
pub extensions: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnitData {
#[serde(default)]
pub hunger: f32,
#[serde(default)]
pub thirst: f32,
#[serde(default)]
pub exhaustion: f32,
#[serde(default)]
pub ai_center_x: f32,
#[serde(default)]
pub ai_center_z: f32,
#[serde(default)]
pub day_timer: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlayerSpawn {
pub position: (f32, f32, f32),
pub rotation_yaw: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScriptData {
pub text: String,
pub entity_id: u32,
}
#[derive(Debug, Clone)]
pub struct S2Map {
pub header: S2Header,
pub minimap: Vec<u8>,
pub password: S2Password,
pub env_vars: S2EnvVars,
pub quickslots: Vec<String>,
pub colormap_dim: u32,
pub colormap: Vec<u8>,
pub terrain_size: u32,
pub heights: Vec<f32>,
pub grass: Vec<u8>,
pub objects: Vec<S2Object>,
pub units: Vec<S2Unit>,
pub items: Vec<S2Item>,
pub infos: Vec<S2Info>,
pub states: Vec<S2State>,
pub extensions: Vec<S2Extension>,
pub trailer: S2Trailer,
}
#[derive(Debug, Clone)]
pub struct S2Password {
pub key: u8,
pub encoded: String,
pub decoded: String,
}
#[derive(Debug, Clone)]
pub struct S2EnvVars {
pub day: u32,
pub hour: u8,
pub minute: u8,
pub freezetime: u8,
pub skybox: String,
pub multiplayer: u8,
pub climate: u8,
pub music: String,
pub briefing: String,
pub fog: [u8; 4],
pub extra: u8,
}
#[derive(Debug, Clone)]
pub struct S2Object {
pub id: u32,
pub typ: u32,
pub x: f32,
pub z: f32,
pub yaw: f32,
pub health: f32,
pub health_max: f32,
pub day_timer: u32,
}
#[derive(Debug, Clone)]
pub struct S2Unit {
pub id: u32,
pub typ: u32,
pub x: f32,
pub y: f32,
pub z: f32,
pub yaw: f32,
pub health: f32,
pub health_max: f32,
pub hunger: f32,
pub thirst: f32,
pub exhaustion: f32,
pub ai_center_x: f32,
pub ai_center_z: f32,
}
#[derive(Debug, Clone)]
pub struct S2Item {
pub id: u32,
pub typ: u32,
pub x: f32,
pub y: f32,
pub z: f32,
pub yaw: f32,
pub health: f32,
pub count: u32,
pub parent_class: u8,
pub parent_mode: u8,
pub parent_id: u32,
}
#[derive(Debug, Clone)]
pub struct S2Info {
pub id: u32,
pub typ: u8,
pub x: f32,
pub y: f32,
pub z: f32,
pub pitch: f32,
pub yaw: f32,
pub vars: String,
}
#[derive(Debug, Clone)]
pub struct S2State {
pub typ: u32,
pub parent_class: u32,
pub parent_id: u32,
pub x: f32,
pub y: f32,
pub z: f32,
pub fx: f32,
pub fy: f32,
pub fz: f32,
pub value: u32,
pub value_f: f32,
pub value_s: String,
}
#[derive(Debug, Clone)]
pub struct S2Extension {
pub typ: u8,
pub parent_class: u8,
pub parent_id: u32,
pub mode: u32,
pub key: String,
pub value: String,
pub stuff: String,
}
#[derive(Debug, Clone)]
pub struct S2Trailer {
pub blank: String,
pub eof_marker: String,
pub url: String,
}