mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/payload.rs')
| -rw-r--r-- | src/block/payload.rs | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/src/block/payload.rs b/src/block/payload.rs index f543ca6..e302770 100644 --- a/src/block/payload.rs +++ b/src/block/payload.rs @@ -3,10 +3,11 @@ use std::error::Error; use std::fmt; use crate::block::{self, BlockLogic, DataConvertError, DeserializeError, make_register, SerializeError}; -use crate::block::simple::{SimpleBlock, state_impl}; +use crate::block::simple::{BuildCost, cost, SimpleBlock, state_impl}; use crate::content; use crate::data::GridPos; use crate::data::dynamic::{DynData, DynType}; +use crate::item::storage::Storage; use crate::unit; const GROUND_UNITS: &[unit::Type] = &[unit::Type::Dagger, unit::Type::Crawler, unit::Type::Nova]; @@ -15,32 +16,35 @@ const NAVAL_UNITS: &[unit::Type] = &[unit::Type::Risso, unit::Type::Retusa]; make_register! ( - GROUND_FACTORY: "ground-factory" => AssemblerBlock::new(3, false, GROUND_UNITS); - AIR_FACTORY: "air-factory" => AssemblerBlock::new(3, false, AIR_UNITS); - NAVAL_FACTORY: "naval-factory" => AssemblerBlock::new(3, false, NAVAL_UNITS); - ADDITIVE_RECONSTRUCTOR: "additive-reconstructor" => SimpleBlock::new(3, false); - MULTIPLICATIVE_RECONSTRUCTOR: "multiplicative-reconstructor" => SimpleBlock::new(5, false); - EXPONENTIAL_RECONSTRUCTOR: "exponential-reconstructor" => SimpleBlock::new(7, false); - TETRATIVE_RECONSTRUCTOR: "tetrative-reconstructor" => SimpleBlock::new(9, false); - REPAIR_POINT: "repair-point" => SimpleBlock::new(1, true); - REPAIR_TURRET: "repair-turret" => SimpleBlock::new(2, true); - PAYLOAD_CONVEYOR: "payload-conveyor" => SimpleBlock::new(3, false); - PAYLOAD_ROUTER: "payload-router" => SimpleBlock::new(3, false); + GROUND_FACTORY: "ground-factory" => AssemblerBlock::new(3, false, cost!(Copper: 50, Lead: 120, Silicon: 80), GROUND_UNITS); + AIR_FACTORY: "air-factory" => AssemblerBlock::new(3, false, cost!(Copper: 60, Lead: 70), AIR_UNITS); + NAVAL_FACTORY: "naval-factory" => AssemblerBlock::new(3, false, cost!(Copper: 150, Lead: 130, Metaglass: 120), NAVAL_UNITS); + ADDITIVE_RECONSTRUCTOR: "additive-reconstructor" => SimpleBlock::new(3, false, cost!(Copper: 200, Lead: 120, Silicon: 90)); + MULTIPLICATIVE_RECONSTRUCTOR: "multiplicative-reconstructor" => SimpleBlock::new(5, false, cost!(Lead: 650, Titanium: 350, Thorium: 650, Silicon: 450)); + EXPONENTIAL_RECONSTRUCTOR: "exponential-reconstructor" => SimpleBlock::new(7, false, + cost!(Lead: 2000, Titanium: 2000, Thorium: 750, Silicon: 1000, Plastanium: 450, PhaseFabric: 600)); + TETRATIVE_RECONSTRUCTOR: "tetrative-reconstructor" => SimpleBlock::new(9, false, + cost!(Lead: 4000, Thorium: 1000, Silicon: 3000, Plastanium: 600, PhaseFabric: 600, SurgeAlloy: 800)); + REPAIR_POINT: "repair-point" => SimpleBlock::new(1, true, cost!(Copper: 30, Lead: 30, Silicon: 20)); + REPAIR_TURRET: "repair-turret" => SimpleBlock::new(2, true, cost!(Thorium: 80, Silicon: 90, Plastanium: 60)); + PAYLOAD_CONVEYOR: "payload-conveyor" => SimpleBlock::new(3, false, cost!(Copper: 10, Graphite: 10)); + PAYLOAD_ROUTER: "payload-router" => SimpleBlock::new(3, false, cost!(Copper: 10, Graphite: 15)); // sandbox only - PAYLOAD_SOURCE: "payload-source" => PayloadBlock::new(5, false); - PAYLOAD_VOID: "payload-void" => SimpleBlock::new(5, true); + PAYLOAD_SOURCE: "payload-source" => PayloadBlock::new(5, false, &[]); + PAYLOAD_VOID: "payload-void" => SimpleBlock::new(5, true, &[]); ); pub struct AssemblerBlock { size: u8, symmetric: bool, + build_cost: BuildCost, valid: &'static [unit::Type], } impl AssemblerBlock { - pub const fn new(size: u8, symmetric: bool, valid: &'static [unit::Type]) -> Self + pub const fn new(size: u8, symmetric: bool, build_cost: BuildCost, valid: &'static [unit::Type]) -> Self { if size == 0 { @@ -54,7 +58,7 @@ impl AssemblerBlock { panic!("too many valid units"); } - Self{size, symmetric, valid} + Self{size, symmetric, build_cost, valid} } state_impl!(pub Option<unit::Type>); @@ -72,6 +76,20 @@ impl BlockLogic for AssemblerBlock self.symmetric } + fn create_build_cost(&self) -> Option<Storage> + { + if !self.build_cost.is_empty() + { + let mut storage = Storage::new(); + for (ty, cnt) in self.build_cost + { + storage.add(*ty, *cnt, u32::MAX); + } + Some(storage) + } + else {None} + } + fn data_from_i32(&self, _: i32, _: GridPos) -> Result<DynData, DataConvertError> { Ok(DynData::Int(-1)) @@ -169,17 +187,18 @@ pub struct PayloadBlock { size: u8, symmetric: bool, + build_cost: BuildCost, } impl PayloadBlock { - pub const fn new(size: u8, symmetric: bool) -> Self + pub const fn new(size: u8, symmetric: bool, build_cost: BuildCost) -> Self { if size == 0 { panic!("invalid size"); } - Self{size, symmetric} + Self{size, symmetric, build_cost} } state_impl!(pub Payload); @@ -197,6 +216,20 @@ impl BlockLogic for PayloadBlock self.symmetric } + fn create_build_cost(&self) -> Option<Storage> + { + if !self.build_cost.is_empty() + { + let mut storage = Storage::new(); + for (ty, cnt) in self.build_cost + { + storage.add(*ty, *cnt, u32::MAX); + } + Some(storage) + } + else {None} + } + fn data_from_i32(&self, _: i32, _: GridPos) -> Result<DynData, DataConvertError> { Ok(DynData::Empty) |