Skip to main content

esi_openapi/groups/
planetary_interaction.rs

1use crate::prelude::*;
2
3/// Endpoints for PlanetaryInteraction
4pub struct PlanetaryInteractionGroup<'a> {
5    pub(crate) esi: &'a Esi,
6}
7
8/// Information about a planetary production schematic.
9#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
10#[allow(missing_docs)]
11pub struct Schematic {
12    /// Time in seconds to process one cycle.
13    pub cycle_time: i64,
14    pub schematic_name: String,
15}
16
17/// The type of a planet that supports planetary interaction.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
19#[serde(rename_all = "snake_case")]
20pub enum PlanetType {
21    /// Temperate.
22    Temperate,
23    /// Barren.
24    Barren,
25    /// Oceanic.
26    Oceanic,
27    /// Ice.
28    Ice,
29    /// Gas.
30    Gas,
31    /// Lava.
32    Lava,
33    /// Storm.
34    Storm,
35    /// Plasma.
36    Plasma,
37    /// A value this version of the crate does not know about.
38    #[serde(other)]
39    Unrecognized,
40}
41
42/// A planet where a character has a colony.
43#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
44pub struct CharacterPlanet {
45    /// Date of the last update of the colony.
46    pub last_update: String,
47    /// Number of pins in the colony.
48    pub num_pins: i64,
49    /// Character ID of the owner.
50    pub owner_id: i64,
51    /// ID of the planet.
52    pub planet_id: i64,
53    /// Type of the planet.
54    pub planet_type: PlanetType,
55    /// Solar system of the planet.
56    pub solar_system_id: i64,
57    /// Command center upgrade level.
58    pub upgrade_level: i64,
59}
60
61/// A link between two pins of a colony.
62#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
63pub struct ColonyLink {
64    /// Pin the link ends at.
65    pub destination_pin_id: i64,
66    /// Level of the link.
67    pub link_level: i64,
68    /// Pin the link starts at.
69    pub source_pin_id: i64,
70}
71
72/// An amount of a commodity stored in a pin.
73#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
74pub struct PinContent {
75    /// Amount stored.
76    pub amount: i64,
77    /// Type ID of the commodity.
78    pub type_id: i64,
79}
80
81/// A head of an extractor control unit.
82#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
83pub struct ExtractorHead {
84    /// ID of the head.
85    pub head_id: i64,
86    /// Latitude of the head.
87    pub latitude: f64,
88    /// Longitude of the head.
89    pub longitude: f64,
90}
91
92/// Details of an extractor control unit.
93#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
94pub struct ExtractorDetails {
95    /// Cycle time in seconds.
96    pub cycle_time: Option<i64>,
97    /// Radius of the heads.
98    pub head_radius: Option<f64>,
99    /// Heads of the control unit.
100    #[serde(default)]
101    pub heads: Vec<ExtractorHead>,
102    /// Type ID of the extracted product.
103    pub product_type_id: Option<i64>,
104    /// Quantity extracted per cycle.
105    pub qty_per_cycle: Option<i64>,
106}
107
108/// Details of a factory.
109#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
110pub struct FactoryDetails {
111    /// ID of the schematic.
112    pub schematic_id: i64,
113}
114
115/// A pin (structure) of a colony.
116#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
117pub struct ColonyPin {
118    /// Contents of the pin.
119    #[serde(default)]
120    pub contents: Vec<PinContent>,
121    /// Expiry time of the pin.
122    pub expiry_time: Option<String>,
123    /// Extractor details, for extractor control units.
124    pub extractor_details: Option<ExtractorDetails>,
125    /// Factory details, for factories.
126    pub factory_details: Option<FactoryDetails>,
127    /// Installation time.
128    pub install_time: Option<String>,
129    /// Start of the last cycle.
130    pub last_cycle_start: Option<String>,
131    /// Latitude of the pin.
132    pub latitude: f64,
133    /// Longitude of the pin.
134    pub longitude: f64,
135    /// ID of the pin.
136    pub pin_id: i64,
137    /// ID of the schematic, for factories.
138    pub schematic_id: Option<i64>,
139    /// Type ID of the pin.
140    pub type_id: i64,
141}
142
143/// A route of commodities between two pins.
144#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
145pub struct ColonyRoute {
146    /// Type ID of the commodity moved by the route.
147    pub content_type_id: i64,
148    /// Pin the route ends at.
149    pub destination_pin_id: i64,
150    /// Quantity moved.
151    pub quantity: f64,
152    /// ID of the route.
153    pub route_id: i64,
154    /// Pin the route starts at.
155    pub source_pin_id: i64,
156    /// Pins the route passes through.
157    #[serde(default)]
158    pub waypoints: Vec<i64>,
159}
160
161/// The layout of a colony.
162#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
163pub struct Colony {
164    /// Links between pins.
165    pub links: Vec<ColonyLink>,
166    /// Pins of the colony.
167    pub pins: Vec<ColonyPin>,
168    /// Routes of the colony.
169    pub routes: Vec<ColonyRoute>,
170}
171
172/// The standing level that decides a customs office tax rate.
173#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
174#[serde(rename_all = "snake_case")]
175pub enum StandingLevel {
176    /// Bad standing.
177    Bad,
178    /// Excellent standing.
179    Excellent,
180    /// Good standing.
181    Good,
182    /// Neutral standing.
183    Neutral,
184    /// Terrible standing.
185    Terrible,
186    /// A value this version of the crate does not know about.
187    #[serde(other)]
188    Unrecognized,
189}
190
191/// A customs office of a corporation.
192#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
193pub struct CustomsOffice {
194    /// Tax rate for alliance members.
195    pub alliance_tax_rate: Option<f64>,
196    /// Whether access is allowed based on standings.
197    pub allow_access_with_standings: bool,
198    /// Whether alliance members have access.
199    pub allow_alliance_access: bool,
200    /// Tax rate for bad standings.
201    pub bad_standing_tax_rate: Option<f64>,
202    /// Tax rate for corporation members.
203    pub corporation_tax_rate: Option<f64>,
204    /// Tax rate for excellent standings.
205    pub excellent_standing_tax_rate: Option<f64>,
206    /// Tax rate for good standings.
207    pub good_standing_tax_rate: Option<f64>,
208    /// Tax rate for neutral standings.
209    pub neutral_standing_tax_rate: Option<f64>,
210    /// ID of the office.
211    pub office_id: i64,
212    /// Hour the reinforcement exit window ends.
213    pub reinforce_exit_end: i64,
214    /// Hour the reinforcement exit window starts.
215    pub reinforce_exit_start: i64,
216    /// Minimum standing level allowed.
217    pub standing_level: Option<StandingLevel>,
218    /// Solar system of the office.
219    pub system_id: i64,
220    /// Tax rate for terrible standings.
221    pub terrible_standing_tax_rate: Option<f64>,
222    /// Type ID of the office.
223    pub type_id: Option<i64>,
224}
225
226impl PlanetaryInteractionGroup<'_> {
227    api_get!(
228        /// Get information about a planetary production schematic.
229        get_schematic,
230        "GetUniverseSchematicsSchematicId",
231        RequestType::Public,
232        Schematic,
233        (schematic_id: i64) => "{schematic_id}"
234    );
235    api_get!(
236        /// List the planets where a character has colonies.
237        get_character_planets,
238        "GetCharactersCharacterIdPlanets",
239        RequestType::Authenticated,
240        Vec<CharacterPlanet>,
241        (character_id: i64) => "{character_id}"
242    );
243
244    api_get!(
245        /// Get the layout of a character's colony on a planet.
246        get_character_planet,
247        "GetCharactersCharacterIdPlanetsPlanetId",
248        RequestType::Authenticated,
249        Colony,
250        (character_id: i64) => "{character_id}",
251        (planet_id: i64) => "{planet_id}"
252    );
253
254    api_get!(
255        /// List the customs offices of a corporation.
256        ///
257        /// Requires the Director role.
258        get_corporation_customs_offices,
259        "GetCorporationsCorporationIdCustomsOffices",
260        RequestType::Authenticated,
261        Vec<CustomsOffice>,
262        (corporation_id: i64) => "{corporation_id}";
263        Optional(page: i32) => "page"
264    );
265}
266
267#[cfg(test)]
268mod colony_tests {
269    use super::*;
270
271    #[test]
272    fn test_parse_colony() {
273        let json = r#"{"links": [{"destination_pin_id": 1000000000001, "link_level": 0, "source_pin_id": 2}],
274            "pins": [{"latitude": 1.0, "longitude": 2.0, "pin_id": 1000000000001, "type_id": 2524,
275                      "extractor_details": {"cycle_time": 3600, "heads": [{"head_id": 0, "latitude": 1.0, "longitude": 1.0}]},
276                      "contents": [{"amount": 3000000000, "type_id": 2268}]}],
277            "routes": [{"content_type_id": 2268, "destination_pin_id": 2, "quantity": 20.0,
278                        "route_id": 1, "source_pin_id": 1}]}"#;
279        let c: Colony = serde_json::from_str(json).unwrap();
280        assert_eq!(c.pins[0].pin_id, 1_000_000_000_001);
281        assert_eq!(c.pins[0].contents[0].amount, 3_000_000_000);
282        assert!(c.routes[0].waypoints.is_empty());
283        assert_eq!(c.pins[0].extractor_details.as_ref().unwrap().heads.len(), 1);
284    }
285
286    #[test]
287    fn test_parse_planets_and_offices() {
288        let p: Vec<CharacterPlanet> = serde_json::from_str(
289            r#"[{"last_update": "u", "num_pins": 5, "owner_id": 2112000000, "planet_id": 40000001,
290                 "planet_type": "lava", "solar_system_id": 30000142, "upgrade_level": 4},
291                {"last_update": "u", "num_pins": 1, "owner_id": 1, "planet_id": 1,
292                 "planet_type": "shattered", "solar_system_id": 1, "upgrade_level": 0}]"#,
293        )
294        .unwrap();
295        assert_eq!(p[0].planet_type, PlanetType::Lava);
296        assert_eq!(p[1].planet_type, PlanetType::Unrecognized);
297        let o: Vec<CustomsOffice> = serde_json::from_str(
298            r#"[{"allow_access_with_standings": true, "allow_alliance_access": false,
299                 "office_id": 1040000000000, "reinforce_exit_end": 21, "reinforce_exit_start": 20,
300                 "system_id": 30000142, "standing_level": "good", "good_standing_tax_rate": 0.05}]"#,
301        )
302        .unwrap();
303        assert_eq!(o[0].standing_level, Some(StandingLevel::Good));
304        assert_eq!(o[0].office_id, 1_040_000_000_000);
305    }
306}