Add quaterdirection and fix multistation off by one errors
This commit is contained in:
parent
1af9712bcb
commit
c3bb980fcf
5 changed files with 137 additions and 47 deletions
|
|
@ -23,7 +23,7 @@ fn main() {
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(move |beltspeed| {
|
.flat_map(move |beltspeed| {
|
||||||
(0..6).flat_map(move |i| {
|
(0..2).flat_map(move |i| {
|
||||||
(0..=i).map(move |j| StationSpec {
|
(0..=i).map(move |j| StationSpec {
|
||||||
locomotives: 1,
|
locomotives: 1,
|
||||||
wagons: 1 << i,
|
wagons: 1 << i,
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::CurvedA,
|
RailType::CurvedA,
|
||||||
Position::new(
|
Position::new(
|
||||||
inrail_x,
|
inrail_x,
|
||||||
total_stacker_height + 4 + previous_station_heights,
|
total_stacker_height + 6 + previous_station_heights,
|
||||||
),
|
),
|
||||||
8,
|
8,
|
||||||
));
|
));
|
||||||
|
|
@ -160,7 +160,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::CurvedB,
|
RailType::CurvedB,
|
||||||
Position::new(
|
Position::new(
|
||||||
inrail_x + 4,
|
inrail_x + 4,
|
||||||
total_stacker_height + 14 + previous_station_heights,
|
total_stacker_height + 16 + previous_station_heights,
|
||||||
),
|
),
|
||||||
8,
|
8,
|
||||||
));
|
));
|
||||||
|
|
@ -168,7 +168,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::CurvedB,
|
RailType::CurvedB,
|
||||||
Position::new(
|
Position::new(
|
||||||
inrail_x + 12,
|
inrail_x + 12,
|
||||||
total_stacker_height + 22 + previous_station_heights,
|
total_stacker_height + 24 + previous_station_heights,
|
||||||
),
|
),
|
||||||
14,
|
14,
|
||||||
));
|
));
|
||||||
|
|
@ -176,7 +176,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::CurvedA,
|
RailType::CurvedA,
|
||||||
Position::new(
|
Position::new(
|
||||||
inrail_x + 22,
|
inrail_x + 22,
|
||||||
total_stacker_height + 26 + previous_station_heights,
|
total_stacker_height + 28 + previous_station_heights,
|
||||||
),
|
),
|
||||||
14,
|
14,
|
||||||
));
|
));
|
||||||
|
|
@ -194,7 +194,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::CurvedA,
|
RailType::CurvedA,
|
||||||
Position::new(
|
Position::new(
|
||||||
outrail_x,
|
outrail_x,
|
||||||
total_stacker_height + 4 + previous_station_heights,
|
total_stacker_height + 6 + previous_station_heights,
|
||||||
),
|
),
|
||||||
10,
|
10,
|
||||||
));
|
));
|
||||||
|
|
@ -202,7 +202,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::CurvedB,
|
RailType::CurvedB,
|
||||||
Position::new(
|
Position::new(
|
||||||
outrail_x - 4,
|
outrail_x - 4,
|
||||||
total_stacker_height + 14 + previous_station_heights,
|
total_stacker_height + 16 + previous_station_heights,
|
||||||
),
|
),
|
||||||
10,
|
10,
|
||||||
));
|
));
|
||||||
|
|
@ -210,7 +210,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::CurvedB,
|
RailType::CurvedB,
|
||||||
Position::new(
|
Position::new(
|
||||||
outrail_x - 12,
|
outrail_x - 12,
|
||||||
total_stacker_height + 22 + previous_station_heights,
|
total_stacker_height + 24 + previous_station_heights,
|
||||||
),
|
),
|
||||||
4,
|
4,
|
||||||
));
|
));
|
||||||
|
|
@ -218,7 +218,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::CurvedA,
|
RailType::CurvedA,
|
||||||
Position::new(
|
Position::new(
|
||||||
outrail_x - 22,
|
outrail_x - 22,
|
||||||
total_stacker_height + 26 + previous_station_heights,
|
total_stacker_height + 28 + previous_station_heights,
|
||||||
),
|
),
|
||||||
4,
|
4,
|
||||||
));
|
));
|
||||||
|
|
@ -237,7 +237,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
blueprint.add_entity(Entity::new_rail(
|
blueprint.add_entity(Entity::new_rail(
|
||||||
RailType::Straight,
|
RailType::Straight,
|
||||||
Position::new(
|
Position::new(
|
||||||
inrail_x + 26 + 4 * j as PositionType,
|
inrail_x + 28 + 4 * j as PositionType,
|
||||||
28 + total_stacker_height + previous_station_heights,
|
28 + total_stacker_height + previous_station_heights,
|
||||||
),
|
),
|
||||||
4,
|
4,
|
||||||
|
|
@ -529,7 +529,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::Straight,
|
RailType::Straight,
|
||||||
Position::new(
|
Position::new(
|
||||||
inrail_x,
|
inrail_x,
|
||||||
total_stacker_height + 2 + previous_station_heights + 4 * j as PositionType,
|
total_stacker_height + 4 + previous_station_heights + 4 * j as PositionType,
|
||||||
),
|
),
|
||||||
0,
|
0,
|
||||||
));
|
));
|
||||||
|
|
@ -537,7 +537,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::Straight,
|
RailType::Straight,
|
||||||
Position::new(
|
Position::new(
|
||||||
outrail_x,
|
outrail_x,
|
||||||
total_stacker_height + 2 + previous_station_heights + 4 * j as PositionType,
|
total_stacker_height + 4 + previous_station_heights + 4 * j as PositionType,
|
||||||
),
|
),
|
||||||
0,
|
0,
|
||||||
));
|
));
|
||||||
|
|
@ -567,12 +567,12 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
// output rails
|
// output rails
|
||||||
blueprint.add_entity(Entity::new_rail(
|
blueprint.add_entity(Entity::new_rail(
|
||||||
RailType::CurvedA,
|
RailType::CurvedA,
|
||||||
Position::new(outrail_x, total_stacker_height - 4),
|
Position::new(outrail_x, total_stacker_height - 2),
|
||||||
0,
|
0,
|
||||||
));
|
));
|
||||||
blueprint.add_entity(Entity::new_rail(
|
blueprint.add_entity(Entity::new_rail(
|
||||||
RailType::CurvedB,
|
RailType::CurvedB,
|
||||||
Position::new(outrail_x - 4, total_stacker_height - 14),
|
Position::new(outrail_x - 4, total_stacker_height - 12),
|
||||||
0,
|
0,
|
||||||
));
|
));
|
||||||
let out_diagonal_length = (outrail_x - 54) / 4;
|
let out_diagonal_length = (outrail_x - 54) / 4;
|
||||||
|
|
@ -581,7 +581,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
RailType::Straight,
|
RailType::Straight,
|
||||||
Position::new(
|
Position::new(
|
||||||
outrail_x - 10 - 4 * i as PositionType,
|
outrail_x - 10 - 4 * i as PositionType,
|
||||||
total_stacker_height - 20 - 4 * i as PositionType,
|
total_stacker_height - 18 - 4 * i as PositionType,
|
||||||
),
|
),
|
||||||
6,
|
6,
|
||||||
));
|
));
|
||||||
|
|
@ -627,5 +627,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blueprint.transform(Transformation::new(Direction::Right, Position::new(0, 0)));
|
||||||
|
|
||||||
blueprint
|
blueprint
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use factorio_core::{
|
||||||
direction,
|
direction,
|
||||||
pathfield::PathField,
|
pathfield::PathField,
|
||||||
prelude::{Direction, Position, PositionType, Transformable, Transformation},
|
prelude::{Direction, Position, PositionType, Transformable, Transformation},
|
||||||
|
quaterdirection::QuaterDirection,
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, sync::atomic::AtomicUsize};
|
use std::{collections::HashMap, sync::atomic::AtomicUsize};
|
||||||
|
|
||||||
|
|
@ -101,10 +102,15 @@ impl RailType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum DirectionType {
|
||||||
|
Dir(Direction),
|
||||||
|
QuarterDir(QuaterDirection),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Entity {
|
pub struct Entity {
|
||||||
entity: EntityType,
|
entity: EntityType,
|
||||||
position: Position,
|
position: Position,
|
||||||
direction: Direction,
|
direction: DirectionType,
|
||||||
quality: Quality,
|
quality: Quality,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +130,6 @@ pub enum EntityType {
|
||||||
},
|
},
|
||||||
Rail {
|
Rail {
|
||||||
rail_type: RailType,
|
rail_type: RailType,
|
||||||
direction: u8,
|
|
||||||
},
|
},
|
||||||
Unknown {
|
Unknown {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
@ -138,7 +143,20 @@ impl Entity {
|
||||||
Self {
|
Self {
|
||||||
entity,
|
entity,
|
||||||
position,
|
position,
|
||||||
direction,
|
direction: DirectionType::Dir(direction),
|
||||||
|
quality: Quality::Normal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_quarter_direction(
|
||||||
|
entity: EntityType,
|
||||||
|
position: Position,
|
||||||
|
direction: QuaterDirection,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
entity,
|
||||||
|
position,
|
||||||
|
direction: DirectionType::QuarterDir(direction),
|
||||||
quality: Quality::Normal,
|
quality: Quality::Normal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -206,15 +224,12 @@ impl Entity {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_rail(rail_type: RailType, position: Position, direction: u8) -> Self {
|
pub fn new_rail(
|
||||||
Self::new(
|
rail_type: RailType,
|
||||||
EntityType::Rail {
|
position: Position,
|
||||||
rail_type,
|
direction: impl Into<QuaterDirection>,
|
||||||
direction,
|
) -> Self {
|
||||||
},
|
Self::new_quarter_direction(EntityType::Rail { rail_type }, position, direction.into())
|
||||||
position,
|
|
||||||
Direction::Up,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_unknown(
|
pub fn new_unknown(
|
||||||
|
|
@ -261,10 +276,7 @@ impl Entity {
|
||||||
recipe: _,
|
recipe: _,
|
||||||
size: _,
|
size: _,
|
||||||
} => name.clone(),
|
} => name.clone(),
|
||||||
EntityType::Rail {
|
EntityType::Rail { rail_type } => rail_type.string(),
|
||||||
rail_type,
|
|
||||||
direction: _,
|
|
||||||
} => rail_type.string(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -313,17 +325,19 @@ impl Entity {
|
||||||
size,
|
size,
|
||||||
} => *size,
|
} => *size,
|
||||||
EntityType::ElectricPole(electric_pole_type) => electric_pole_type.size(),
|
EntityType::ElectricPole(electric_pole_type) => electric_pole_type.size(),
|
||||||
EntityType::Rail {
|
EntityType::Rail { rail_type } => rail_type.size(),
|
||||||
rail_type,
|
|
||||||
direction: _,
|
|
||||||
} => rail_type.size(),
|
|
||||||
_ => Position::new(2, 2),
|
_ => Position::new(2, 2),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transform(&mut self, transform: Transformation) {
|
pub fn transform(&mut self, transform: Transformation) {
|
||||||
self.position = self.position.transform(transform);
|
self.position = self.position.transform(transform);
|
||||||
self.direction = self.direction.transform(transform);
|
self.direction = match self.direction {
|
||||||
|
DirectionType::Dir(direction) => DirectionType::Dir(direction.transform(transform)),
|
||||||
|
DirectionType::QuarterDir(quater_direction) => {
|
||||||
|
DirectionType::QuarterDir(quater_direction.transform(transform))
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -416,17 +430,11 @@ impl Blueprint {
|
||||||
i as u32 + 1,
|
i as u32 + 1,
|
||||||
BlueprintPosition::new(0.5 * e.position.x as f64, 0.5 * e.position.y as f64),
|
BlueprintPosition::new(0.5 * e.position.x as f64, 0.5 * e.position.y as f64),
|
||||||
)
|
)
|
||||||
.direction(match &e.entity {
|
.direction(match e.direction {
|
||||||
&EntityType::Rail {
|
DirectionType::Dir(direction) => 4 * direction.get_index(),
|
||||||
rail_type: _,
|
DirectionType::QuarterDir(quater_direction) => {
|
||||||
direction,
|
quater_direction.to_int_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_underground_type(e.get_maybe_underground_type_string())
|
||||||
.maybe_override_stack_size(e.get_maybe_override_stack_size())
|
.maybe_override_stack_size(e.get_maybe_override_stack_size())
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ pub mod color;
|
||||||
pub mod direction;
|
pub mod direction;
|
||||||
pub mod pathfield;
|
pub mod pathfield;
|
||||||
pub mod position;
|
pub mod position;
|
||||||
|
pub mod quaterdirection;
|
||||||
pub mod transformation;
|
pub mod transformation;
|
||||||
pub mod visualize;
|
pub mod visualize;
|
||||||
|
|
||||||
|
|
@ -14,6 +15,7 @@ pub mod prelude {
|
||||||
block::Block,
|
block::Block,
|
||||||
direction::Direction,
|
direction::Direction,
|
||||||
position::{Position, PositionType},
|
position::{Position, PositionType},
|
||||||
|
quaterdirection::QuaterDirection,
|
||||||
transformation::{Transformable, Transformation},
|
transformation::{Transformable, Transformation},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
78
factorio-core/src/quaterdirection.rs
Normal file
78
factorio-core/src/quaterdirection.rs
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
use crate::prelude::{Transformable, Transformation};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
|
||||||
|
pub enum QuaterDirection {
|
||||||
|
N,
|
||||||
|
NNE,
|
||||||
|
NE,
|
||||||
|
ENE,
|
||||||
|
E,
|
||||||
|
ESE,
|
||||||
|
SE,
|
||||||
|
SSE,
|
||||||
|
S,
|
||||||
|
SSW,
|
||||||
|
SW,
|
||||||
|
WSW,
|
||||||
|
W,
|
||||||
|
WNW,
|
||||||
|
NW,
|
||||||
|
NNW,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl QuaterDirection {
|
||||||
|
pub fn to_int_direction(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
QuaterDirection::N => 0,
|
||||||
|
QuaterDirection::NNE => 1,
|
||||||
|
QuaterDirection::NE => 2,
|
||||||
|
QuaterDirection::ENE => 3,
|
||||||
|
QuaterDirection::E => 4,
|
||||||
|
QuaterDirection::ESE => 5,
|
||||||
|
QuaterDirection::SE => 6,
|
||||||
|
QuaterDirection::SSE => 7,
|
||||||
|
QuaterDirection::S => 8,
|
||||||
|
QuaterDirection::SSW => 9,
|
||||||
|
QuaterDirection::SW => 10,
|
||||||
|
QuaterDirection::WSW => 11,
|
||||||
|
QuaterDirection::W => 12,
|
||||||
|
QuaterDirection::WNW => 13,
|
||||||
|
QuaterDirection::NW => 14,
|
||||||
|
QuaterDirection::NNW => 15,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_int_direction(x: u8) -> Self {
|
||||||
|
match x {
|
||||||
|
0 => QuaterDirection::N,
|
||||||
|
1 => QuaterDirection::NNE,
|
||||||
|
2 => QuaterDirection::NE,
|
||||||
|
3 => QuaterDirection::ENE,
|
||||||
|
4 => QuaterDirection::E,
|
||||||
|
5 => QuaterDirection::ESE,
|
||||||
|
6 => QuaterDirection::SE,
|
||||||
|
7 => QuaterDirection::SSE,
|
||||||
|
8 => QuaterDirection::S,
|
||||||
|
9 => QuaterDirection::SSW,
|
||||||
|
10 => QuaterDirection::SW,
|
||||||
|
11 => QuaterDirection::WSW,
|
||||||
|
12 => QuaterDirection::W,
|
||||||
|
13 => QuaterDirection::WNW,
|
||||||
|
14 => QuaterDirection::NW,
|
||||||
|
15 => QuaterDirection::NNW,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Transformable for QuaterDirection {
|
||||||
|
fn transform(&self, t: Transformation) -> Self {
|
||||||
|
Self::from_int_direction((self.to_int_direction() + 4 * t.rot().get_index()) % 16)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u8> for QuaterDirection {
|
||||||
|
fn from(value: u8) -> Self {
|
||||||
|
Self::from_int_direction(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue