1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#![allow(clippy::modulo_one)] // Caused by derive(Enum) on an enum with only a
                              // single variant.

use std::fmt;

use bincode::{Decode, Encode};
use enum_iterator::Sequence;
use enum_map::Enum;
use serde::{Deserialize, Serialize};

/// Maximum number of buildings belonging to a single player.
pub const PLAYER_MAX_BUILDINGS: u32 = 128;
/// Maximum number of units belonging to a single player.
pub const PLAYER_MAX_UNITS: u32 = 1024;

#[derive(Debug, Encode, Decode, Enum, Sequence, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ObjectType {
    Active(ActiveObjectType),
    Inactive(InactiveObjectType),
}

impl fmt::Display for ObjectType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Self::Active(active) => write!(f, "Active -> {active}"),
            Self::Inactive(inactive) => write!(f, "Inactive -> {inactive}"),
        }
    }
}

#[derive(
    Debug, Encode, Decode, Enum, Sequence, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Hash,
)]
pub enum InactiveObjectType {
    Tree,
}

impl fmt::Display for InactiveObjectType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Self::Tree => write!(f, "Tree"),
        }
    }
}

#[derive(
    Debug, Encode, Decode, Enum, Sequence, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Hash,
)]
pub enum ActiveObjectType {
    Building(BuildingType),
    Unit(UnitType),
}

impl fmt::Display for ActiveObjectType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Self::Building(building) => write!(f, "Building -> {building}"),
            Self::Unit(unit) => write!(f, "Unit -> {unit}"),
        }
    }
}

#[derive(
    Debug, Encode, Decode, Enum, Sequence, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Hash,
)]
pub enum BuildingType {
    Base,
    PowerHub,
}

impl fmt::Display for BuildingType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Self::Base => write!(f, "Base"),
            Self::PowerHub => write!(f, "Power Hub"),
        }
    }
}

#[derive(
    Debug, Encode, Decode, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Enum, Sequence, Hash,
)]
pub enum UnitType {
    Attacker,
}

impl fmt::Display for UnitType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Self::Attacker => write!(f, "Attacker"),
        }
    }
}