static private UpdateSection ( int SectionIndex ) : void | ||
SectionIndex | int | |
리턴 | void |
internal static void UpdateSection(int SectionIndex) {
// preparations
int zeroaspect;
bool settored = false;
if (Sections[SectionIndex].Type == SectionType.ValueBased) {
// value-based
zeroaspect = int.MaxValue;
for (int i = 0; i < Sections[SectionIndex].Aspects.Length; i++) {
if (Sections[SectionIndex].Aspects[i].Number < zeroaspect) {
zeroaspect = Sections[SectionIndex].Aspects[i].Number;
}
}
if (zeroaspect == int.MaxValue) {
zeroaspect = -1;
}
} else {
// index-based
zeroaspect = 0;
}
// hold station departure signal at red
int d = Sections[SectionIndex].StationIndex;
if (d >= 0) {
// look for train in previous blocks
//int l = Sections[SectionIndex].PreviousSection;
if (Stations[d].StationType != StationType.Normal) {
settored = true;
}
}
// train in block
if (Sections[SectionIndex].Trains.Length != 0) {
settored = true;
}
// free sections
int newaspect = -1;
if (settored) {
Sections[SectionIndex].FreeSections = 0;
newaspect = zeroaspect;
} else {
int n = Sections[SectionIndex].NextSection;
if (n >= 0) {
if (Sections[n].FreeSections == -1) {
Sections[SectionIndex].FreeSections = -1;
} else {
Sections[SectionIndex].FreeSections = Sections[n].FreeSections + 1;
}
} else {
Sections[SectionIndex].FreeSections = -1;
}
}
// change aspect
if (newaspect == -1) {
if (Sections[SectionIndex].Type == SectionType.ValueBased) {
// value-based
int n = Sections[SectionIndex].NextSection;
int a = Sections[SectionIndex].Aspects[Sections[SectionIndex].Aspects.Length - 1].Number;
if (n >= 0 && Sections[n].CurrentAspect >= 0) {
a = Sections[n].Aspects[Sections[n].CurrentAspect].Number;
}
for (int i = Sections[SectionIndex].Aspects.Length - 1; i >= 0; i--) {
if (Sections[SectionIndex].Aspects[i].Number > a) {
newaspect = i;
}
} if (newaspect == -1) {
newaspect = Sections[SectionIndex].Aspects.Length - 1;
}
} else {
// index-based
if (Sections[SectionIndex].FreeSections >= 0 & Sections[SectionIndex].FreeSections < Sections[SectionIndex].Aspects.Length) {
newaspect = Sections[SectionIndex].FreeSections;
} else {
newaspect = Sections[SectionIndex].Aspects.Length - 1;
}
}
}
Sections[SectionIndex].CurrentAspect = newaspect;
// update previous section
if (Sections[SectionIndex].PreviousSection >= 0) {
UpdateSection(Sections[SectionIndex].PreviousSection);
}
}
private void UpdateFrontBackward(TrainManager.Train Train, bool UpdateTrain) { // update sections if (this.PreviousSectionIndex >= 0) { Game.Sections[this.PreviousSectionIndex].Enter(Train); Game.UpdateSection(this.PreviousSectionIndex); } if (this.NextSectionIndex >= 0) { Game.Sections[this.NextSectionIndex].Leave(Train); Game.UpdateSection(this.NextSectionIndex); } if (UpdateTrain) { // update train if (this.PreviousSectionIndex >= 0) { if (!Game.Sections[this.PreviousSectionIndex].Invisible) { Train.CurrentSectionIndex = this.PreviousSectionIndex; } } else { Train.CurrentSectionLimit = double.PositiveInfinity; Train.CurrentSectionIndex = -1; } } }