use crate::system::System;
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum IndustryType {
Yard,
Industry,
Offline,
Unknown,
}
impl Default for IndustryType {
fn default() -> Self {
IndustryType::Unknown
}
}
impl IndustryType {
pub fn new(typeletter: char) -> Self {
match typeletter {
'Y' | 'y' => IndustryType::Yard,
'I' | 'i' => IndustryType::Industry,
'O' | 'o' => IndustryType::Offline,
_ => IndustryType::Unknown
}
}
}
use std::fmt;
impl fmt::Display for IndustryType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
IndustryType::Yard => write!(f, "<#IndustryType Yard (Y)>"),
IndustryType::Industry => write!(f, "<#IndustryType Industry (I)>"),
IndustryType::Offline => write!(f, "<#IndustryType Offline (O)>"),
IndustryType::Unknown => write!(f, "<#IndustryType Unknown>"),
}
}
}
#[derive(Debug, PartialEq, Default, Clone)]
pub struct IndustryFile {
station_index: u8,
mirror: usize,
name: String,
loadTypes: String,
emptyTypes: String,
divisionControlList: String,
trackLen: u32,
assignLen: u32,
priority: u8,
plate: u8,
weightclass: u8,
maxCarLen: u32,
reload: bool,
indtype: IndustryType,
hazard: char,
}
pub struct IndustryWorking {
name: String,
station_index: u8,
indtype: IndustryType,
cars: Vec<usize>,
carsNum: u32,
carsLen: u32,
statsLen: u32,
usedLen: u32,
remLen: u32,
}
impl IndustryFile {
pub fn new(station_index: u8, mirror: usize, name: String,
loadTypes: String, emptyTypes: String,
divisionControlList: String, trackLen: u32, assignLen: u32,
priority: u8, plate: u8, weightclass: u8, maxCarLen: u32,
reload: bool, indtype: char, hazard: char) -> Self {
Self {station_index: station_index, mirror: mirror,
name: name, loadTypes: loadTypes, emptyTypes: emptyTypes,
divisionControlList: divisionControlList, trackLen: trackLen,
assignLen: assignLen, priority: priority, plate: plate,
weightclass: weightclass, maxCarLen: maxCarLen, reload: reload,
indtype: IndustryType::new(indtype), hazard: hazard}
}
pub fn RipTrack() -> Self {
Self {station_index: System::WORKBENCH_CITY, mirror: 0,
name: String::from("REPAIR YARD"), loadTypes: String::from(""),
emptyTypes: String::from(""),
divisionControlList: String::from(""), trackLen: 0,
assignLen: 0, priority: 9, plate: 0, weightclass: 0,
maxCarLen: 999, reload: false, indtype: IndustryType::new('I'),
hazard: ' '}
}
pub fn Type(&self) -> IndustryType {
self.indtype
}
pub fn MyStationIndex(&self) -> u8 {
self.station_index
}
pub fn Name(&self) -> String {
self.name.clone()
}
pub fn TrackLen(&self) -> u32 {
self.trackLen
}
pub fn AssignLen(&self) -> u32 {
self.assignLen
}
pub fn Priority(&self) -> u8 {
self.priority
}
pub fn Reload(&self) -> bool {
self.reload
}
pub fn Hazard(&self) -> char {
self.hazard
}
pub fn MyMirrorIndex(&self) -> usize {
self.mirror
}
pub fn MaxPlate(&self) -> u8 {
self.plate
}
pub fn MaxWeightClass(&self) -> u8 {
self.weightclass
}
pub fn DivisionControlList(&self) -> String {
self.divisionControlList.clone()
}
pub fn MaxCarLen(&self) -> u32 {
self.maxCarLen
}
pub fn LoadsAccepted(&self) -> String {
self.loadTypes.clone()
}
pub fn EmptiesAccepted(&self) -> String {
self.emptyTypes.clone()
}
}
impl IndustryWorking {
pub fn new(station_index: u8, name: String, indtype: IndustryType)
-> Self {
Self {name: name, station_index: station_index, indtype: indtype,
cars: Vec::new(), carsNum: 0, carsLen: 0, statsLen: 0,
usedLen: 0, remLen: 0}
}
pub fn Name(&self) -> String {
self.name.clone()
}
pub fn MyStationIndex(&self) -> u8 {
self.station_index
}
pub fn Type(&self) -> IndustryType {
self.indtype
}
pub fn TheCar(&self, i: usize) -> Option<usize> {
if i < self.cars.len() {
Some(self.cars[i])
} else {
None
}
}
pub fn NumberOfCars(&self) -> usize {
self.cars.len()
}
pub fn AddCar(&mut self, carindex: usize) {
self.cars.push(carindex);
}
pub fn RemoveCar(&mut self,Cx: usize) {
for c in 0..self.cars.len() {
if self.cars[c] == Cx {
self.cars.remove(c);
return;
}
}
}
pub fn CarsNum(&self) -> u32 {self.carsNum}
pub fn SetCarsNum(&mut self, cn: u32) {self.carsNum = cn;}
pub fn IncrCarsNum(&mut self) { self.carsNum += 1; }
pub fn DecrCarsNum(&mut self) {
if self.carsNum > 1 {self.carsNum -= 1; }
}
pub fn CarsLen(&self) -> u32 {self.carsLen}
pub fn SetCarsLen(&mut self, cl: u32) {self.carsLen = cl;}
pub fn AddToCarsLen(&mut self, cl: u32) {self.carsLen += cl;}
pub fn SubFromCarsLen(&mut self, cl: u32) {
if self.carsLen < cl {
self.carsLen = 0;
} else {
self.carsLen -= cl;
}
}
pub fn StatsLen(&self) -> u32 {self.statsLen}
pub fn SetStatsLen(&mut self, sl: u32) {self.statsLen = sl;}
pub fn IncrementStatsLen(&mut self, i: u32) {
self.statsLen = self.statsLen + i;
}
pub fn IncrementStatsLen1(&mut self) {
self.statsLen = self.statsLen + 1;
}
pub fn UsedLen(&self) -> u32 {self.usedLen}
pub fn SetUsedLen(&mut self, ul: u32) {self.usedLen = ul;}
pub fn AddToUsedLen(&mut self, cl: u32) {self.usedLen += cl;}
pub fn SubFromUsedLen(&mut self, cl: u32) {
if self.usedLen < cl {
self.usedLen = 0;
} else {
self.usedLen -= cl;
}
}
pub fn RemLen(&self) -> u32 {self.remLen}
pub fn SetRemLen(&mut self, rl: u32) {self.remLen = rl;}
pub fn AddRemLen(&mut self, rl: u32) {self.remLen += rl;}
pub fn SubRemLen(&mut self, rl: u32) {
if self.remLen < rl {
self.remLen = 0;
} else {
self.remLen -= rl;
}
}
}
impl fmt::Display for IndustryFile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<#IndustryFile {}>", self.name)
}
}
impl fmt::Display for IndustryWorking {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<#IndustryWorking {}>", self.name)
}
}