diff --git a/CHANGELOG.md b/CHANGELOG.md index d318bd45..93ba81c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Unreleased ========== +### Additions: + +- Add `StructureObject::structure_type` function to return the associated `StructureType` +- Implement `OBSTACLE_OBJECT_TYPES` constant for structures by adding `StructureType::is_obstacle` + function + 0.23.0 (2025-04-09) =================== diff --git a/src/constants/numbers.rs b/src/constants/numbers.rs index f0313415..503f3e38 100644 --- a/src/constants/numbers.rs +++ b/src/constants/numbers.rs @@ -9,7 +9,7 @@ use super::types::{ResourceType, StructureType}; // LOOK_* defined in `look.rs` -// OBSTACLE_OBJECT_TYPES not yet implemented +// OBSTACLE_OBJECT_TYPES defined in `types.rs` // BODYPART_COST defined in `small_enums.rs` diff --git a/src/constants/types.rs b/src/constants/types.rs index 394ff2f4..d368abb3 100644 --- a/src/constants/types.rs +++ b/src/constants/types.rs @@ -184,6 +184,38 @@ impl StructureType { }; Some(hits) } + + /// Translates the `OBSTACLE_OBJECT_TYPES` constant, returning true for + /// structure types that are obstacles + #[inline] + pub const fn is_obstacle(self) -> bool { + use self::StructureType::*; + + match self { + Spawn => true, + Extension => true, + Road => false, + Wall => true, + Rampart => false, + KeeperLair => false, + Portal => false, + Controller => true, + Link => true, + Storage => true, + Tower => true, + Observer => true, + PowerBank => true, + PowerSpawn => true, + Extractor => false, + Lab => true, + Terminal => true, + Container => false, + Nuker => true, + Factory => true, + InvaderCore => true, + _ => false, + } + } } /// Translates `SUBSCRIPTION_TOKEN` and `INTERSHARD_RESOURCES` constants. diff --git a/src/enums.rs b/src/enums.rs index c725b41d..c022d6ca 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -7,7 +7,11 @@ pub mod action_error_codes; use enum_dispatch::enum_dispatch; use wasm_bindgen::{JsCast, JsValue}; -use crate::{objects::*, prelude::*, ResourceType, RESOURCES_ALL}; +use crate::{ + constants::{ResourceType, StructureType, RESOURCES_ALL}, + objects::*, + prelude::*, +}; #[enum_dispatch(Attackable)] pub enum AttackableObject { @@ -346,6 +350,36 @@ pub enum StructureObject { StructureWall, } +impl StructureObject { + pub fn structure_type(&self) -> StructureType { + use StructureObject::*; + + match self { + StructureContainer(_) => StructureType::Container, + StructureController(_) => StructureType::Controller, + StructureExtension(_) => StructureType::Extension, + StructureExtractor(_) => StructureType::Extractor, + StructureFactory(_) => StructureType::Factory, + StructureInvaderCore(_) => StructureType::InvaderCore, + StructureKeeperLair(_) => StructureType::KeeperLair, + StructureLab(_) => StructureType::Lab, + StructureLink(_) => StructureType::Link, + StructureNuker(_) => StructureType::Nuker, + StructureObserver(_) => StructureType::Observer, + StructurePortal(_) => StructureType::Portal, + StructurePowerBank(_) => StructureType::PowerBank, + StructurePowerSpawn(_) => StructureType::PowerSpawn, + StructureRampart(_) => StructureType::Rampart, + StructureRoad(_) => StructureType::Road, + StructureSpawn(_) => StructureType::Spawn, + StructureStorage(_) => StructureType::Storage, + StructureTerminal(_) => StructureType::Terminal, + StructureTower(_) => StructureType::Tower, + StructureWall(_) => StructureType::Wall, + } + } +} + #[enum_dispatch(Transferable)] pub enum TransferableObject { StructureExtension, diff --git a/src/lib.rs b/src/lib.rs index 0b87246b..d06f179e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,6 +94,8 @@ // #![warn(clippy::missing_const_for_fn)] +// temporary - TODO remove and fix these if it's made permanent in the current form +#![allow(clippy::uninlined_format_args)] // disable deprecation warnings - TODO need to figure out how to get wasm_bindgen's new thread_local // attribute working #![allow(deprecated)]