use core::ffi::c_void;
use crate::abi::{Header, Status, Str};
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Zeroable)]
pub struct GameEventData {
pub header: Header,
pub type_hash: u32,
pub size: u32,
pub data: *const u8,
}
impl_headed!(GameEventData);
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Zeroable)]
pub struct EventTypeInfo {
pub header: Header,
pub name: Str,
pub hash: u32,
pub size: u32,
}
impl_headed!(EventTypeInfo);
pub type GameEventFn = unsafe extern "system" fn(event: *const GameEventData, user: *mut c_void);
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct EntityPlace {
pub entity: u32,
pub reserved: u32,
pub position: [i64; 3],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct TeleportRequest {
pub header: Header,
pub entity: u32,
pub flags: u32,
pub position: [i64; 3],
pub orientation: [f32; 4],
}
impl_headed!(TeleportRequest);
impl TeleportRequest {
pub const BEST_SPAWN: u32 = 1;
pub const ORIENTED: u32 = 2;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct SpawnRequest {
pub header: Header,
pub template: [u8; 16],
pub position: [i64; 3],
pub orientation: [f32; 4],
pub level: u32,
pub reserved: u32,
pub lifetime_ns: u64,
}
impl_headed!(SpawnRequest);
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct CraftCheck {
pub header: Header,
pub player: u32,
pub station: u32,
pub recipe: u32,
pub amount: u32,
}
impl_headed!(CraftCheck);
pub type CraftCheckFn = unsafe extern "system" fn(call: *const CraftCheck, user: *mut c_void) -> u8;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct BuildCheck {
pub header: Header,
pub player: u32,
pub item: u32,
pub position: [i64; 3],
}
impl_headed!(BuildCheck);
pub type BuildCheckFn = unsafe extern "system" fn(call: *const BuildCheck, user: *mut c_void) -> u8;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct DaytimeInfo {
pub header: Header,
pub time: i64,
pub day_start: i64,
pub day_end: i64,
pub day_length: i64,
pub night_length: i64,
pub speed: f32,
pub flags: u32,
}
impl_headed!(DaytimeInfo);
impl DaytimeInfo {
pub const DAY: u32 = 1;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct DamageCheck {
pub header: Header,
pub cause: u32,
pub target: u32,
pub source: u32,
pub attacker: u32,
pub amounts: [f32; 13],
pub total: f32,
}
impl_headed!(DamageCheck);
impl DamageCheck {
pub const HIT: u32 = 0;
pub const FALL: u32 = 1;
pub const SHROUD: u32 = 2;
pub const SHROUD_DEATH: u32 = 3;
pub const DROWNING: u32 = 4;
pub const DROWNING_DEATH: u32 = 5;
pub const FREEZING: u32 = 6;
pub const ADMIN_KILL: u32 = 7;
}
pub type DamageFilterFn = unsafe extern "system" fn(check: *mut DamageCheck, user: *mut c_void);
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct KnowledgeInfo {
pub header: Header,
pub id: u32,
pub kind: u8,
pub scope: u8,
pub reserved: u16,
pub value: u32,
pub flags: u32,
}
impl_headed!(KnowledgeInfo);
impl KnowledgeInfo {
pub const BOOL: u8 = 0;
pub const COUNTER: u8 = 1;
pub const FLAGS: u8 = 2;
pub const WORLD: u8 = 0;
pub const PLAYER: u8 = 1;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct WeatherFront {
pub header: Header,
pub layer: u32,
pub effect: u32,
pub position: [i64; 3],
pub radius: f32,
pub reserved: u32,
pub remaining: i64,
}
impl_headed!(WeatherFront);
impl WeatherFront {
pub const NONE: u32 = 0;
pub const RAIN: u32 = 1;
pub const BLIZZARD: u32 = 2;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct TerrainMaterialInfo {
pub header: Header,
pub id: u8,
pub flags: u8,
pub hardness: u8,
pub reserved: u8,
pub item: u32,
pub health: i32,
}
impl_headed!(TerrainMaterialInfo);
impl TerrainMaterialInfo {
pub const FLATTENS: u8 = 1;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct TerrainEdit {
pub header: Header,
pub kind: u32,
pub shape: u32,
pub flags: u32,
pub material: u32,
pub position: [f32; 3],
pub radius: f32,
pub height: f32,
pub protect: [u8; 16],
}
impl_headed!(TerrainEdit);
impl TerrainEdit {
pub const ADD: u32 = 0;
pub const DIG: u32 = 1;
pub const FLATTEN: u32 = 2;
pub const ROUND: u32 = 0;
pub const SQUARE: u32 = 1;
pub const DRY_RUN: u32 = 1;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, bytemuck::Zeroable)]
pub struct Voxel {
pub kind: u8,
pub material: u8,
pub fill: u8,
pub reserved: u8,
}
impl Voxel {
pub const AIR: u8 = 0;
pub const TERRAIN: u8 = 1;
pub const BUILDING: u8 = 2;
pub const READ_MAX: u64 = 64 * 64 * 64;
pub const END: u32 = 1 << 30;
#[must_use]
pub const fn read_count(min: [u32; 3], size: [u32; 3]) -> Option<u64> {
let mut count = 1u64;
let mut axis = 0;
while axis < 3 {
let within = match min[axis].checked_add(size[axis]) {
Some(end) => end <= Self::END,
None => false,
};
if size[axis] == 0 || !within {
return None;
}
count = match count.checked_mul(size[axis] as u64) {
Some(product) if product <= Self::READ_MAX => product,
_ => return None,
};
axis += 1;
}
Some(count)
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct BuildRights {
pub header: Header,
pub player: u32,
pub refusal: u32,
pub min: [f64; 3],
pub max: [f64; 3],
}
impl_headed!(BuildRights);
impl BuildRights {
pub const ALLOWED: u32 = 0;
pub const NO_CAN_EDIT_WORLD: u32 = 1;
pub const NO_CAN_EDIT_BASE: u32 = 2;
pub const OUTSIDE_BUILDING_ZONE: u32 = 3;
pub const INSIDE_STRICT_BUILD_INHIBITOR_ZONE: u32 = 4;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct TransactionOp {
pub kind: u32,
pub reserved: u32,
pub data: *const c_void,
}
impl TransactionOp {
pub const TERRAIN: u32 = 1;
pub const VOXELS: u32 = 2;
pub const ERASE: u32 = 3;
pub const BLOCK: u32 = 4;
pub const PLACE_PROP: u32 = 5;
pub const REMOVE_PROP: u32 = 6;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct PropPlace {
pub header: Header,
pub item: u32,
pub reserved: u32,
pub position: [f64; 3],
pub orientation: [f32; 4],
}
impl_headed!(PropPlace);
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct PropRemove {
pub header: Header,
pub entity: u32,
pub flags: u32,
}
impl_headed!(PropRemove);
impl PropRemove {
pub const DISCARD_STATE: u32 = 1;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct VoxelWrite {
pub header: Header,
pub min: [u32; 3],
pub size: [u32; 3],
pub voxels: *const Voxel,
pub count: u64,
}
impl_headed!(VoxelWrite);
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct VoxelRegion {
pub header: Header,
pub min: [u32; 3],
pub size: [u32; 3],
}
impl_headed!(VoxelRegion);
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Zeroable)]
pub struct BlockPlace {
pub header: Header,
pub shape: u32,
pub material: u32,
pub position: [f64; 3],
pub rotation: [f32; 4],
}
impl_headed!(BlockPlace);
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, bytemuck::Zeroable)]
pub struct TransactionInfo {
pub header: Header,
pub state: u32,
pub reason: Status,
pub ops: u32,
pub applied: u32,
pub bricks: u64,
pub refusal: u32,
pub reserved: u32,
pub holds: u32,
pub created: u32,
}
impl_headed!(TransactionInfo);
impl TransactionInfo {
pub const PENDING: u32 = 0;
pub const APPLIED: u32 = 1;
pub const UNDOING: u32 = 2;
pub const UNDONE: u32 = 3;
pub const FAILED: u32 = 4;
pub const EXPIRED: u32 = 5;
pub const HOLDS_INVENTORY: u32 = 1;
pub const HOLDS_GROWTH: u32 = 1 << 1;
pub const HOLDS_FACTORY_STATION: u32 = 1 << 2;
pub const HOLDS_NPC_BED: u32 = 1 << 3;
pub const HOLDS_STORE_ASSOCIATED_NPC_IDS: u32 = 1 << 4;
pub const HOLDS_CUSTOM_PLAYER_STRING: u32 = 1 << 5;
pub const HOLDS_FUEL: u32 = 1 << 6;
pub const HOLDS_LOGIC_GRAPH_NODE_CONNECTED: u32 = 1 << 7;
pub const HOLDS_LOGIC_GRAPH_TRIGGER: u32 = 1 << 8;
pub const UNDO_REFUSED: u32 = 6;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Zeroable)]
pub struct MapMarkerInfo {
pub header: Header,
pub position: [f64; 3],
pub marker_type: [u8; 16],
pub label: [u8; 16],
}
impl_headed!(MapMarkerInfo);
impl MapMarkerInfo {
pub const EMPTY: Self = Self {
header: Header::of::<Self>(),
position: [0.0; 3],
marker_type: [0; 16],
label: [0; 16],
};
}