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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use num_derive::FromPrimitive;
use serde_repr::{Deserialize_repr, Serialize_repr};
use stdweb::Reference;
use crate::{
local::Position,
objects::{
ConstructionSite, Creep, Deposit, Flag, Mineral, Nuke, OwnedStructure, PowerCreep,
Resource, Ruin, Source, Structure, StructureSpawn, Tombstone,
},
traits::FromExpectedType,
};
pub unsafe trait FindConstant {
type Item: FromExpectedType<Reference>;
fn find_code(&self) -> i16;
}
#[derive(
Debug, PartialEq, Eq, Clone, Copy, Hash, FromPrimitive, Deserialize_repr, Serialize_repr,
)]
#[repr(i16)]
pub enum RoomObject {
Creeps = 101,
MyCreeps = 102,
HostileCreeps = 103,
SourcesActive = 104,
Sources = 105,
DroppedResources = 106,
Structures = 107,
MyStructures = 108,
HostileStructures = 109,
Flags = 110,
ConstructionSites = 111,
MySpawns = 112,
HostileSpawns = 113,
MyConstructionSites = 114,
HostileConstructionSites = 115,
Minerals = 116,
Nukes = 117,
Tombstones = 118,
PowerCreeps = 119,
MyPowerCreeps = 120,
HostilePowerCreeps = 121,
Deposits = 122,
Ruins = 123,
}
unsafe impl FindConstant for RoomObject {
type Item = crate::objects::RoomObject;
#[inline]
fn find_code(&self) -> i16 {
*self as i16
}
}
#[derive(
Copy, Clone, Debug, FromPrimitive, Deserialize_repr, Serialize_repr, PartialEq, Eq, Hash,
)]
#[repr(i16)]
pub enum Exit {
Top = 1,
Right = 3,
Bottom = 5,
Left = 7,
All = 10,
}
impl Exit {
#[inline]
pub fn top() -> Self {
Exit::Top
}
#[inline]
pub fn right() -> Self {
Exit::Right
}
#[inline]
pub fn bottom() -> Self {
Exit::Bottom
}
#[inline]
pub fn left() -> Self {
Exit::Left
}
#[inline]
pub fn all() -> Self {
Exit::All
}
}
unsafe impl FindConstant for Exit {
type Item = Position;
#[inline]
fn find_code(&self) -> i16 {
*self as i16
}
}
typesafe_find_constants! {
pub struct CREEPS = (101, Creep);
pub struct MY_CREEPS = (102, Creep);
pub struct HOSTILE_CREEPS = (103, Creep);
pub struct SOURCES_ACTIVE = (104, Source);
pub struct SOURCES = (105, Source);
pub struct DROPPED_RESOURCES = (106, Resource);
pub struct STRUCTURES = (107, Structure);
pub struct MY_STRUCTURES = (108, OwnedStructure);
pub struct HOSTILE_STRUCTURES = (109, OwnedStructure);
pub struct FLAGS = (110, Flag);
pub struct CONSTRUCTION_SITES = (111, ConstructionSite);
pub struct MY_SPAWNS = (112, StructureSpawn);
pub struct HOSTILE_SPAWNS = (113, StructureSpawn);
pub struct MY_CONSTRUCTION_SITES = (114, ConstructionSite);
pub struct HOSTILE_CONSTRUCTION_SITES = (115, ConstructionSite);
pub struct MINERALS = (116, Mineral);
pub struct NUKES = (117, Nuke);
pub struct TOMBSTONES = (118, Tombstone);
pub struct POWER_CREEPS = (119, PowerCreep);
pub struct MY_POWER_CREEPS = (120, PowerCreep);
pub struct HOSTILE_POWER_CREEPS = (121, PowerCreep);
pub struct DEPOSITS = (122, Deposit);
pub struct RUINS = (123, Ruin);
pub struct EXIT_TOP = (Exit::Top as i16, Position);
pub struct EXIT_RIGHT = (Exit::Right as i16, Position);
pub struct EXIT_BOTTOM = (Exit::Bottom as i16, Position);
pub struct EXIT_LEFT = (Exit::Left as i16, Position);
pub struct EXIT = (Exit::All as i16, Position);
}