Add fuel to train schedules
This commit is contained in:
parent
3beab0c64d
commit
7fd42f45c7
3 changed files with 55 additions and 3 deletions
|
|
@ -31,10 +31,11 @@ fn main() {
|
||||||
BlueprintBook::builder()
|
BlueprintBook::builder()
|
||||||
.blueprints(b)
|
.blueprints(b)
|
||||||
.active_index(0)
|
.active_index(0)
|
||||||
.version(562949954797573)
|
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// let b = BlueprintString::Blueprint(generate_train(1, 2, false, false));
|
||||||
|
|
||||||
println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,12 @@ use bon::Builder;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
static VERSION: u64 = calculate_version(2, 0, 19, 173);
|
||||||
|
|
||||||
|
const fn calculate_version(major: u16, minor: u16, patch: u16, dev: u16) -> u64 {
|
||||||
|
((major as u64) << 48) | ((minor as u64) << 32) | ((patch as u64) << 16) | (dev as u64)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum BlueprintString {
|
pub enum BlueprintString {
|
||||||
#[serde(rename = "blueprint_book")]
|
#[serde(rename = "blueprint_book")]
|
||||||
|
|
@ -22,6 +28,7 @@ pub struct BlueprintBook {
|
||||||
label_color: Option<BlueprintColor>,
|
label_color: Option<BlueprintColor>,
|
||||||
blueprints: Vec<BlueprintBookEntry>,
|
blueprints: Vec<BlueprintBookEntry>,
|
||||||
active_index: i32,
|
active_index: i32,
|
||||||
|
#[builder(skip = VERSION)]
|
||||||
version: u64,
|
version: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,6 +75,7 @@ pub struct Blueprint {
|
||||||
absolute_snapping: Option<bool>,
|
absolute_snapping: Option<bool>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
position_relative_to_grid: Option<BlueprintPosition>,
|
position_relative_to_grid: Option<BlueprintPosition>,
|
||||||
|
#[builder(skip = VERSION)]
|
||||||
version: u64,
|
version: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,55 @@ pub fn generate_train(locomotives: u32, wagons: u32, rails: bool, fluid: bool) -
|
||||||
"[virtual-signal=signal-C]"
|
"[virtual-signal=signal-C]"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut fuel_conditions = Vec::new();
|
||||||
|
|
||||||
|
fuel_conditions.push(serde_json::json!({
|
||||||
|
"compare_type": "and",
|
||||||
|
"station": format!("[virtual-signal=signal-F][virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}]"),
|
||||||
|
"type": "specific_destination_not_full"
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (fuel, min) in [
|
||||||
|
("coal", 50),
|
||||||
|
("solid-fuel", 50),
|
||||||
|
("rocket-fuel", 20),
|
||||||
|
("nuclear-fuel", 1),
|
||||||
|
] {
|
||||||
|
fuel_conditions.push(serde_json::json!({
|
||||||
|
"compare_type": "and",
|
||||||
|
"type": "fuel_item_count_any",
|
||||||
|
"condition": {
|
||||||
|
"comparator": "≤",
|
||||||
|
"constant": min,
|
||||||
|
"first_signal": {
|
||||||
|
"name": fuel,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
let schedule = serde_json::json!({
|
let schedule = serde_json::json!({
|
||||||
"locomotives": [1],
|
"locomotives": [1],
|
||||||
"schedule": {
|
"schedule": {
|
||||||
"group": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}]"),
|
"group": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}]"),
|
||||||
"interrupts": [
|
"interrupts": [
|
||||||
|
{
|
||||||
|
"name": format!("[virtual-signal=signal-F][virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}]"),
|
||||||
|
"conditions": fuel_conditions,
|
||||||
|
"inside_interrupt": true,
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"station": format!("[virtual-signal=signal-F][virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}]"),
|
||||||
|
"wait_conditions": [
|
||||||
|
{
|
||||||
|
"compare_type": "and",
|
||||||
|
"ticks": 120,
|
||||||
|
"type": "inactivity"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}][virtual-signal=signal-L]"),
|
"name": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}][virtual-signal=signal-L]"),
|
||||||
"conditions": [
|
"conditions": [
|
||||||
|
|
@ -145,7 +189,7 @@ pub fn generate_train(locomotives: u32, wagons: u32, rails: bool, fluid: bool) -
|
||||||
],
|
],
|
||||||
"records": [
|
"records": [
|
||||||
{
|
{
|
||||||
"station": "Depot"
|
"station": format!("[virtual-signal=signal-D][virtual-signal=signal-{}]", locomotives + wagons),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +200,6 @@ pub fn generate_train(locomotives: u32, wagons: u32, rails: bool, fluid: bool) -
|
||||||
.entities(e)
|
.entities(e)
|
||||||
.stock_connections(stock_connections)
|
.stock_connections(stock_connections)
|
||||||
.schedules(vec![schedule])
|
.schedules(vec![schedule])
|
||||||
.version(562949954797573)
|
|
||||||
.snap_to_grid(BlueprintPosition::new(
|
.snap_to_grid(BlueprintPosition::new(
|
||||||
4.0,
|
4.0,
|
||||||
2.0 * ((locomotives + wagons) * 7).div_ceil(2) as f64,
|
2.0 * ((locomotives + wagons) * 7).div_ceil(2) as f64,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue