dcso3/
attribute.rs

1/*
2Copyright 2024 Eric Stokes.
3
4This file is part of dcso3.
5
6dcso3 is free software: you can redistribute it and/or modify it under
7the terms of the MIT License.
8
9dcso3 is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE.
12*/
13
14use super::{as_tbl, String};
15use crate::{wrapped_table, string_enum};
16use anyhow::Result;
17use mlua::{prelude::*, Value};
18use serde_derive::{Serialize, Deserialize};
19use std::ops::Deref;
20
21string_enum!(Attribute, u8, [
22    PlaneCarrier => "plane_carrier",
23    NoTailTrail => "no_tail_trail",
24    Cord => "cord",
25    SkiJump => "ski_jump",
26    Catapult => "catapult",
27    LowReflectionVessel => "low_reflection_vessel",
28    AAFlak => "AA_flak",
29    AAMissile => "AA_missile",
30    CruiseMissiles => "Cruise missiles",
31    AntiShipMissiles => "Anti-Ship missiles",
32    Missiles => "Missiles",
33    Fighters => "Fighters",
34    Interceptors => "Interceptors",
35    MultiroleFighters => "Multirole fighters",
36    Bombers => "Bombers",
37    Battleplanes => "Battleplanes",
38    AWACS => "AWACS",
39    Tankers => "Tankers",
40    Aux => "Aux",
41    Transports => "Transports",
42    StrategicBombers => "Strategic bombers",
43    UAVs => "UAVs",
44    AttackHelicopters => "Attack helicopters",
45    TransportHelicopters => "Transport helicopters",
46    Planes => "Planes",
47    Helicopters => "Helicopters",
48    Cars => "Cars",
49    Trucks => "Trucks",
50    Infantry => "Infantry",
51    Tanks => "Tanks",
52    Artillery => "Artillery",
53    MLRS => "MLRS",
54    IFV => "IFV",
55    APC => "APC",
56    Fortifications => "Fortifications",
57    ArmedVehicles => "Armed vehicles",
58    StaticAAA => "Static AAA",
59    MobileAAA => "Mobile AAA",
60    SAM_SR => "SAM SR",
61    SAM_TR => "SAM TR",
62    SAM_LL => "SAM LL",
63    SAM_CC => "SAM CC",
64    SAM_AUX => "SAM AUX",
65    SR_SAM => "SR SAM",
66    MR_SAM => "MR SAM",
67    LR_SAM => "LR SAM",
68    SAMElements => "SAM elements",
69    IRGuidedSAM => "IR Guided SAM",
70    SAM => "SAM",
71    SAMRelated => "SAM related",
72    AAA => "AAA",
73    EWR => "EWR",
74    AirDefenceVehicles => "Air Defence vehicles",
75    MANPADS => "MANPADS",
76    MANPADS_AUX => "MANPADS AUX",
77    UnarmedVehicles => "Unarmed vehicles",
78    ArmedGroundUnits => "Armed ground units",
79    ArmedAirDefence => "Armed Air Defence",
80    AirDefence => "Air Defence",
81    AircraftCarriers => "Aircraft Carriers",
82    Cruisers => "Cruisers",
83    Destroyers => "Destroyers",
84    Frigates => "Frigates",
85    Corvettes => "Corvettes",
86    HeavyArmedShips => "Heavy armed ships",
87    LightArmedShips => "Light armed ships",
88    ArmedShips => "Armed ships",
89    UnarmedShips => "Unarmed ships",
90    Air => "Air",
91    GroundVehicles => "Ground vehicles",
92    Ships => "Ships",
93    Buildings => "Buildings",
94    HeavyArmoredUnits => "HeavyArmoredUnits",
95    ATGM => "ATGM",
96    OldTanks => "Old Tanks",
97    ModernTanks => "Modern Tanks",
98    LightArmoredUnits => "LightArmoredUnits",
99    RocketAttackValidAirDefence => "Rocket Attack Valid AirDefence",
100    BattleAirplanes => "Battle airplanes",
101    All => "All",
102    InfantryCarriers => "Infantry carriers",
103    Vehicles => "Vehicles",
104    GroundUnits => "Ground Units",
105    GroundUnitsNonAirdefence => "Ground Units Non Airdefence",
106    ArmoredVehicles => "Armored vehicles",
107    AntiAirArmedVehicles => "AntiAir Armed Vehicles",
108    Airfields => "Airfields",
109    Heliports => "Heliports",
110    GrassAirfields => "Grass Airfields",
111    Point => "Point",
112    NonArmoredUnits => "NonArmoredUnits",
113    NonAndLightArmoredUnits => "NonAndLightArmoredUnits",
114    HumanVehicle => "human_vehicle",
115    RADAR_BAND1_FOR_ARM => "RADAR_BAND1_FOR_ARM",
116    RADAR_BAND2_FOR_ARM => "RADAR_BAND2_FOR_ARM",
117    Prone => "Prone",
118    DetectionByAWACS => "DetectionByAWACS",
119    Datalink => "Datalink",
120    CustomAimPoint => "CustomAimPoint",
121    IndirectFire => "Indirect fire",
122    Refuelable => "Refuelable",
123    Weapon => "Weapon",
124    Shell => "Shell",
125    Rocket => "Rocket",
126    Bomb => "Bomb",
127    Missile => "Missile"
128]);
129
130wrapped_table!(Attributes, None);
131
132impl<'lua> Attributes<'lua> {
133    pub fn new(lua: &'lua Lua) -> Result<Self> {
134        Ok(Self {
135            t: lua.create_table()?,
136            lua
137        })
138    }
139
140    pub fn get(&self, attr: Attribute) -> Result<bool> {
141        Ok(self.t.get(attr)?)
142    }
143
144    pub fn set(&self, attr: Attribute, val: bool) -> Result<()> {
145        Ok(self.t.set(attr, val)?)
146    }
147}