Add multistation generation

This commit is contained in:
hal8174 2025-01-24 23:25:43 +01:00
parent 05f4edf83a
commit ce76626f79
7 changed files with 451 additions and 10 deletions

View file

@ -1,5 +1,6 @@
use factorio_core::{
beltoptions::Beltspeed,
direction,
pathfield::PathField,
prelude::{Direction, Position, PositionType, Transformable, Transformation},
};
@ -73,6 +74,32 @@ pub enum Quality {
Legendary,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RailType {
Straight,
CurvedA,
CurvedB,
RailSignal,
ChainSignal,
}
impl RailType {
fn string(&self) -> String {
match self {
RailType::Straight => "straight-rail",
RailType::CurvedA => "curved-rail-a",
RailType::CurvedB => "curved-rail-b",
RailType::RailSignal => "rail-signal",
RailType::ChainSignal => "rail-chain-signal",
}
.to_string()
}
fn size(&self) -> Position {
todo!()
}
}
pub struct Entity {
entity: EntityType,
position: Position,
@ -94,6 +121,10 @@ pub enum EntityType {
recipe: String,
size: Position,
},
Rail {
rail_type: RailType,
direction: u8,
},
Unknown {
name: String,
size: Position,
@ -174,6 +205,17 @@ impl Entity {
)
}
pub fn new_rail(rail_type: RailType, position: Position, direction: u8) -> Self {
Self::new(
EntityType::Rail {
rail_type,
direction,
},
position,
Direction::Up,
)
}
pub fn new_unknown(
name: impl AsRef<str>,
position: Position,
@ -218,6 +260,10 @@ impl Entity {
recipe: _,
size: _,
} => name.clone(),
EntityType::Rail {
rail_type,
direction: _,
} => rail_type.string(),
}
}
@ -266,6 +312,10 @@ impl Entity {
size,
} => *size,
EntityType::ElectricPole(electric_pole_type) => electric_pole_type.size(),
EntityType::Rail {
rail_type,
direction: _,
} => rail_type.size(),
_ => Position::new(2, 2),
}
}
@ -343,8 +393,14 @@ impl Blueprint {
}
pub fn add_blueprint(&mut self, other: Self) {
let previous_entities = self.entities.len();
self.entities.extend(other.entities);
self.keys.extend(other.keys);
self.keys.extend(
other
.keys
.into_iter()
.map(|(k, v)| (k, v + previous_entities)),
);
self.wires.extend(other.wires);
}
@ -359,11 +415,17 @@ impl Blueprint {
i as u32 + 1,
BlueprintPosition::new(0.5 * e.position.x as f64, 0.5 * e.position.y as f64),
)
.direction(match e.direction {
Direction::Up => 0,
Direction::Right => 4,
Direction::Down => 8,
Direction::Left => 12,
.direction(match &e.entity {
&EntityType::Rail {
rail_type: _,
direction,
} => direction,
_ => match e.direction {
Direction::Up => 0,
Direction::Right => 4,
Direction::Down => 8,
Direction::Left => 12,
},
})
.maybe_underground_type(e.get_maybe_underground_type_string())
.maybe_override_stack_size(e.get_maybe_override_stack_size())