sc2_techtree/
unittype.rs

1use noisy_float::prelude::*;
2use serde::{Deserialize, Serialize};
3use std::collections::HashSet;
4
5use crate::attribute::Attribute;
6use crate::ids::*;
7use crate::requirement::Requirement;
8use crate::weapon::*;
9use crate::Race;
10
11/// Unit or structure
12#[derive(Debug, Serialize, Deserialize, Clone, Eq)]
13pub struct UnitType {
14    /// Id
15    pub id: UnitTypeId,
16    /// Name
17    pub name: String,
18    /// Race
19    pub race: Race,
20    /// Supply
21    pub supply: R32,
22    /// None for untransportable
23    cargo_size: Option<u32>,
24    /// None if cannot transport units
25    cargo_capacity: Option<u32>,
26    /// Max hp
27    max_health: u32,
28    /// Max shield
29    max_shield: Option<u32>,
30    /// Armor
31    armor: u32,
32    /// Vision range
33    sight: R32,
34    /// None if not detector
35    detection_range: Option<R32>,
36    /// Speed without upgrades of buffs, None if cannot move at all
37    speed: Option<R32>,
38    /// Creep speed multiplier without upgrades of buffs
39    speed_creep_mul: Option<R32>,
40    /// Max energy
41    max_energy: Option<u32>,
42    /// Start energy
43    start_energy: Option<u32>,
44    /// List of weapons, sorted by priority
45    weapons: Vec<Weapon>,
46    /// Attributes
47    attributes: HashSet<Attribute>,
48    /// A list of abilities and their requirements
49    abilities: Vec<UnitAbilityReq>,
50    /// Building size on grid, not available for non-structures
51    placement_size: Option<u32>,
52    /// Radius approximating the size of the unit.
53    #[serde(default)] // TODO: remove this and require
54    radius: R32,
55    /// Produces pylon power with this radius
56    power_radius: Option<R32>,
57    /// Terran add-on can be used with this structure
58    accepts_addon: bool,
59    /// Requires a pylon power to function
60    needs_power: bool,
61    /// Requires creep for placement
62    needs_creep: bool,
63    /// Requires a vespene gayser for placement
64    needs_gayser: bool,
65    /// Structure attribute is set
66    is_structure: bool,
67    /// Can be used as an add-on
68    is_addon: bool,
69    /// Workers: Probe, Drone, SCV
70    is_worker: bool,
71    /// Flying buildings not included
72    is_townhall: bool,
73}
74impl PartialEq for UnitType {
75    fn eq(&self, other: &Self) -> bool {
76        self.id == other.id
77    }
78}
79
80/// Unit ability with a possible requirement
81#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
82pub struct UnitAbilityReq {
83    ability: AbilityId,
84    requirement: Option<Requirement>,
85}