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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
use crate::create_new::CreateNew;
use crate::fillable::{Fillable, Filler};
use crate::positions::Coordinate;
use crate::SchemaExample;
use df_st_derive::{Fillable, Filler, HashAndPartialEqById};
use juniper::GraphQLObject;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// An Entity is a collective of something in the world.
/// This is usually in the form of a civilization or government.
#[derive(
    Serialize,
    Deserialize,
    Clone,
    Debug,
    HashAndPartialEqById,
    Fillable,
    Filler,
    Default,
    JsonSchema,
    GraphQLObject,
)]
pub struct Entity {
    /// Identifier for the entity.
    /// `id` must be unique for the whole world.
    pub id: i32,
    pub name: Option<String>,
    pub honor: Vec<EntityHonor>,
    pub race: Option<String>,
    #[serde(alias = "type")]
    pub type_: Option<String>,
    // for Religion and MilitaryUnit
    pub worship_id: Vec<i32>,
    // for MilitaryUnit: favorite weapons
    pub weapon: Vec<String>,
    // for Guild
    pub profession: Vec<String>,
    pub entity_link: Vec<EntityLink>,
    pub entity_position: Vec<EntityPosition>,
    pub entity_position_assignment: Vec<EntityPositionAssignment>,
    pub hf_ids: Vec<i32>,
    pub child_en_ids: Vec<i32>,
    pub claims: Vec<Coordinate>,
    pub occasion: Vec<EntityOccasion>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct EntityHonor {
    pub local_id: i32,
    pub name: Option<String>,
    pub gives_precedence: Option<i32>,
    pub requires_any_melee_or_ranged_skill: Option<bool>,
    pub required_skill_ip_total: Option<i32>,
    pub required_battles: Option<i32>,
    pub required_years: Option<i32>,
    pub required_skill: Option<String>,
    pub required_kills: Option<i32>,
    pub exempt_ep_id: Option<i32>,
    pub exempt_former_ep_id: Option<i32>,
    pub granted_to_everybody: Option<bool>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct EntityLink {
    pub local_id: i32,
    #[serde(alias = "type")]
    pub type_: Option<String>,
    pub target: Option<i32>,
    pub strength: Option<i32>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct EntityPosition {
    pub local_id: i32,
    pub name: Option<String>,
    pub name_male: Option<String>,
    pub name_female: Option<String>,
    pub spouse: Option<String>,
    pub spouse_male: Option<String>,
    pub spouse_female: Option<String>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct EntityPositionAssignment {
    pub local_id: i32,
    pub hf_id: Option<i32>,
    pub position_id: Option<i32>,
    pub squad_id: Option<i32>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct EntityOccasion {
    pub local_id: i32,
    pub name: Option<String>,
    pub event: Option<i32>,
    pub schedule: Vec<EntityOccasionSchedule>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct EntityOccasionSchedule {
    pub local_id: i32,
    #[serde(alias = "type")]
    pub type_: Option<String>,
    // for THROWING_COMPETITION
    pub item_type: Option<String>,
    pub item_subtype: Option<String>,

    pub reference: Option<i32>,
    pub reference2: Option<i32>,

    pub feature: Vec<EntityOccasionScheduleFeature>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Fillable, Filler, Default, JsonSchema, GraphQLObject,
)]
pub struct EntityOccasionScheduleFeature {
    pub local_id: i32,

    #[serde(alias = "type")]
    pub type_: Option<String>,
    pub reference: Option<i32>,
}

impl Entity {
    pub fn new() -> Self {
        Self::default()
    }
}

impl CreateNew for Entity {
    fn new_by_id(id: i32) -> Self {
        Self {
            id,
            ..Default::default()
        }
    }
}

impl SchemaExample for Entity {
    fn example() -> Self {
        Self::default()
    }
}

impl EntityHonor {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for EntityHonor {
    fn example() -> Self {
        Self::default()
    }
}

impl EntityLink {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for EntityLink {
    fn example() -> Self {
        Self::default()
    }
}

impl EntityPosition {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for EntityPosition {
    fn example() -> Self {
        Self::default()
    }
}

impl EntityPositionAssignment {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for EntityPositionAssignment {
    fn example() -> Self {
        Self::default()
    }
}

impl EntityOccasion {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for EntityOccasion {
    fn example() -> Self {
        Self::default()
    }
}

impl EntityOccasionSchedule {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for EntityOccasionSchedule {
    fn example() -> Self {
        Self::default()
    }
}

impl EntityOccasionScheduleFeature {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for EntityOccasionScheduleFeature {
    fn example() -> Self {
        Self::default()
    }
}

impl PartialEq for EntityLink {
    fn eq(&self, other: &Self) -> bool {
        self.local_id == other.local_id
    }
}

impl std::hash::Hash for EntityLink {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.local_id.hash(state);
    }
}

impl PartialEq for EntityHonor {
    fn eq(&self, other: &Self) -> bool {
        self.local_id == other.local_id
    }
}

impl std::hash::Hash for EntityHonor {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.local_id.hash(state);
    }
}

impl PartialEq for EntityPosition {
    fn eq(&self, other: &Self) -> bool {
        self.local_id == other.local_id
    }
}

impl std::hash::Hash for EntityPosition {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.local_id.hash(state);
    }
}

impl PartialEq for EntityPositionAssignment {
    fn eq(&self, other: &Self) -> bool {
        self.local_id == other.local_id
    }
}

impl std::hash::Hash for EntityPositionAssignment {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.local_id.hash(state);
    }
}

impl PartialEq for EntityOccasion {
    fn eq(&self, other: &Self) -> bool {
        self.local_id == other.local_id
    }
}

impl std::hash::Hash for EntityOccasion {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.local_id.hash(state);
    }
}

impl PartialEq for EntityOccasionSchedule {
    fn eq(&self, other: &Self) -> bool {
        self.local_id == other.local_id
    }
}

impl std::hash::Hash for EntityOccasionSchedule {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.local_id.hash(state);
    }
}

impl PartialEq for EntityOccasionScheduleFeature {
    fn eq(&self, other: &Self) -> bool {
        self.local_id == other.local_id
    }
}

impl std::hash::Hash for EntityOccasionScheduleFeature {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.local_id.hash(state);
    }
}