@@ -42,6 +42,11 @@ public class Transfertable : MovingTable
4242 {
4343 public float Span ; // horizontal or vertical
4444 public List < float > Offsets = new List < float > ( ) ;
45+ private bool VerticalTransfer = false ;
46+ public float CenterOffsetComponent
47+ {
48+ get => VerticalTransfer ? CenterOffset . Y : CenterOffset . X ;
49+ }
4550 // Dynamic data
4651 public bool Forward ; // forward motion on
4752 public bool Reverse ; // reverse motion on
@@ -53,49 +58,32 @@ public class Transfertable : MovingTable
5358
5459 public Signals signalRef { get ; protected set ; }
5560
56- public virtual float CenterOffsetComponent { get => CenterOffset . X ; }
57-
58- protected Transfertable ( STFReader stf , Simulator simulator ) : base ( stf , simulator ) { }
59-
60- public static Transfertable CreateFrom ( STFReader stf , Simulator simulator )
61+ public Transfertable ( STFReader stf , Simulator simulator ) : base ( stf , simulator )
6162 {
62- var worldPosition = new WorldPosition ( ) ;
63- worldPosition . XNAMatrix . M44 = 100000000 ; //WorlPosition not yet defined, will be loaded when loading related tile
64- var wFile = "" ;
65- var uid = - 1 ;
66- var animations = new List < string > ( ) ;
67- var isVertical = false ;
68- var length = 0f ;
69- var centerOffset = new Vector3 ( ) ;
70- var trackShapeIndex = - 1 ;
71-
63+ signalRef = Simulator . Signals ;
64+ string animation ;
65+ WorldPosition . XNAMatrix . M44 = 100000000 ; //WorlPosition not yet defined, will be loaded when loading related tile
7266 stf . MustMatch ( "(" ) ;
7367 stf . ParseBlock ( new [ ] {
7468 new STFReader . TokenProcessor ( "wfile" , ( ) => {
75- wFile = stf . ReadStringBlock ( null ) ;
76- worldPosition . TileX = int . Parse ( wFile . Substring ( 1 , 7 ) ) ;
77- worldPosition . TileZ = int . Parse ( wFile . Substring ( 8 , 7 ) ) ;
69+ WFile = stf . ReadStringBlock ( null ) ;
70+ WorldPosition . TileX = int . Parse ( WFile . Substring ( 1 , 7 ) ) ;
71+ WorldPosition . TileZ = int . Parse ( WFile . Substring ( 8 , 7 ) ) ;
72+ } ) ,
73+ new STFReader . TokenProcessor ( "uid" , ( ) => { UID = stf . ReadIntBlock ( - 1 ) ; } ) ,
74+ new STFReader . TokenProcessor ( "animation" , ( ) => { animation = stf . ReadStringBlock ( null ) ;
75+ Animations . Add ( animation . ToLower ( ) ) ; } ) ,
76+ new STFReader . TokenProcessor ( "verticaltransfer" , ( ) => { VerticalTransfer = stf . ReadBoolBlock ( false ) ; } ) ,
77+ new STFReader . TokenProcessor ( "length" , ( ) => { Length = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
78+ new STFReader . TokenProcessor ( "xoffset" , ( ) => { CenterOffset . X = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
79+ new STFReader . TokenProcessor ( "zoffset" , ( ) => { CenterOffset . Z = - stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
80+ new STFReader . TokenProcessor ( "yoffset" , ( ) => { CenterOffset . Y = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
81+ new STFReader . TokenProcessor ( "trackshapeindex" , ( ) =>
82+ {
83+ TrackShapeIndex = stf . ReadIntBlock ( - 1 ) ;
84+ InitializeOffsetsAndTrackNodes ( ) ;
7885 } ) ,
79- new STFReader . TokenProcessor ( "uid" , ( ) => { uid = stf . ReadIntBlock ( null ) ; } ) ,
80- new STFReader . TokenProcessor ( "animation" , ( ) => { var animation = stf . ReadStringBlock ( null ) ;
81- animations . Add ( animation . ToLower ( ) ) ; } ) ,
82- new STFReader . TokenProcessor ( "verticaltransfer" , ( ) => { isVertical = stf . ReadBoolBlock ( isVertical ) ; } ) ,
83- new STFReader . TokenProcessor ( "length" , ( ) => { length = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
84- new STFReader . TokenProcessor ( "xoffset" , ( ) => { centerOffset . X = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
85- new STFReader . TokenProcessor ( "zoffset" , ( ) => { centerOffset . Z = - stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
86- new STFReader . TokenProcessor ( "yoffset" , ( ) => { centerOffset . Y = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
87- new STFReader . TokenProcessor ( "trackshapeindex" , ( ) => { trackShapeIndex = stf . ReadIntBlock ( null ) ; } ) ,
8886 } ) ;
89-
90- var table = isVertical ? new VerticalTransfertable ( null , simulator ) : new Transfertable ( null , simulator ) ;
91- table . signalRef = table . Simulator . Signals ;
92- table . WorldPosition = worldPosition ;
93- table . UID = uid ;
94- table . Animations . AddRange ( animations ) ;
95- table . CenterOffset = centerOffset ;
96- table . TrackShapeIndex = trackShapeIndex ;
97- table . InitializeOffsetsAndTrackNodes ( ) ;
98- return table ;
9987 }
10088
10189 /// <summary>
@@ -131,7 +119,7 @@ public override void Restore(BinaryReader inf, Simulator simulator)
131119 TargetOffset = inf . ReadSingle ( ) ;
132120 }
133121
134- protected virtual void InitializeOffsetsAndTrackNodes ( )
122+ protected void InitializeOffsetsAndTrackNodes ( )
135123 {
136124 var trackShape = Simulator . TSectionDat . TrackShapes . Get ( ( uint ) TrackShapeIndex ) ;
137125 var nSections = trackShape . SectionIdxs [ 0 ] . NoSections ;
@@ -141,7 +129,7 @@ protected virtual void InitializeOffsetsAndTrackNodes()
141129 var iMyTrackNodes = 0 ;
142130 foreach ( var sectionIdx in trackShape . SectionIdxs )
143131 {
144- Offsets . Add ( ( float ) sectionIdx . X ) ;
132+ Offsets . Add ( VerticalTransfer ? ( float ) sectionIdx . Y : ( float ) sectionIdx . X ) ;
145133 MyTrackNodesIndex [ iMyTrackNodes ] = - 1 ;
146134 MyTrVectorSectionsIndex [ iMyTrackNodes ] = - 1 ;
147135 iMyTrackNodes ++ ;
@@ -167,9 +155,16 @@ protected virtual void InitializeOffsetsAndTrackNodes()
167155 }
168156 }
169157 }
170- OffsetPos = CenterOffset . X ;
171- // Compute width of transfer table
172- Span = ( float ) ( trackShape . SectionIdxs [ trackShape . SectionIdxs . Length - 1 ] . X - trackShape . SectionIdxs [ 0 ] . X ) ;
158+ if ( VerticalTransfer )
159+ {
160+ OffsetPos = CenterOffset . Y ;
161+ Span = ( float ) ( trackShape . SectionIdxs [ trackShape . SectionIdxs . Length - 1 ] . Y - trackShape . SectionIdxs [ 0 ] . Y ) ;
162+ }
163+ else
164+ {
165+ OffsetPos = CenterOffset . X ;
166+ Span = ( float ) ( trackShape . SectionIdxs [ trackShape . SectionIdxs . Length - 1 ] . X - trackShape . SectionIdxs [ 0 ] . X ) ;
167+ }
173168 }
174169
175170 /// <summary>
@@ -308,10 +303,13 @@ public override void StartContinuous(bool isForward)
308303 Continuous = true ;
309304 }
310305
311- public virtual void ComputeCenter ( WorldPosition worldPosition )
306+ public void ComputeCenter ( WorldPosition worldPosition )
312307 {
313308 Vector3 movingCenterOffset = CenterOffset ;
314- movingCenterOffset . X = OffsetPos ;
309+ if ( VerticalTransfer )
310+ movingCenterOffset . Y = OffsetPos ;
311+ else
312+ movingCenterOffset . X = OffsetPos ;
315313 Vector3 originCoordinates ;
316314 Vector3 . Transform ( ref movingCenterOffset , ref worldPosition . XNAMatrix , out originCoordinates ) ;
317315 WorldPosition = new WorldPosition ( worldPosition ) ;
@@ -440,67 +438,4 @@ public void PerformUpdateActions ( Matrix absAnimationMatrix, WorldPosition worl
440438 }
441439 }
442440
443- /// <summary>
444- /// A transfer table that moves vertically.
445- /// </summary>
446- public class VerticalTransfertable : Transfertable
447- {
448- public override float CenterOffsetComponent { get => CenterOffset . Y ; }
449-
450- internal VerticalTransfertable ( STFReader stf , Simulator simulator ) : base ( stf , simulator ) { }
451-
452- protected override void InitializeOffsetsAndTrackNodes ( )
453- {
454- var trackShape = Simulator . TSectionDat . TrackShapes . Get ( ( uint ) TrackShapeIndex ) ;
455- var nSections = trackShape . SectionIdxs [ 0 ] . NoSections ;
456- MyTrackNodesIndex = new int [ trackShape . SectionIdxs . Length ] ;
457- MyTrackNodesOrientation = new bool [ MyTrackNodesIndex . Length ] ;
458- MyTrVectorSectionsIndex = new int [ MyTrackNodesIndex . Length ] ;
459- var iMyTrackNodes = 0 ;
460- foreach ( var sectionIdx in trackShape . SectionIdxs )
461- {
462- Offsets . Add ( ( float ) sectionIdx . Y ) ;
463- MyTrackNodesIndex [ iMyTrackNodes ] = - 1 ;
464- MyTrVectorSectionsIndex [ iMyTrackNodes ] = - 1 ;
465- iMyTrackNodes ++ ;
466- }
467- var trackNodes = Simulator . TDB . TrackDB . TrackNodes ;
468- int iTrackNode = 0 ;
469- for ( iTrackNode = 1 ; iTrackNode < trackNodes . Length ; iTrackNode ++ )
470- {
471- if ( trackNodes [ iTrackNode ] . TrVectorNode != null && trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections != null )
472- {
473- var iTrVectorSection = Array . FindIndex ( trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections , trVectorSection =>
474- ( trVectorSection . WFNameX == WorldPosition . TileX && trVectorSection . WFNameZ == WorldPosition . TileZ && trVectorSection . WorldFileUiD == UID ) ) ;
475- if ( iTrVectorSection >= 0 )
476- {
477- if ( trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections . Length > ( int ) nSections )
478- {
479- iMyTrackNodes = trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections [ iTrVectorSection ] . Flag1 / 2 ;
480- MyTrackNodesIndex [ iMyTrackNodes ] = iTrackNode ;
481- MyTrVectorSectionsIndex [ iMyTrackNodes ] = iTrVectorSection ;
482- MyTrackNodesOrientation [ iMyTrackNodes ] = trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections [ iTrVectorSection ] . Flag1 % 2 == 0 ? true : false ;
483-
484- }
485- }
486- }
487- }
488- OffsetPos = CenterOffset . Y ;
489- // Compute height of transfer table
490- Span = ( float ) ( trackShape . SectionIdxs [ trackShape . SectionIdxs . Length - 1 ] . Y - trackShape . SectionIdxs [ 0 ] . Y ) ;
491- }
492-
493- public override void ComputeCenter ( WorldPosition worldPosition )
494- {
495- Vector3 movingCenterOffset = CenterOffset ;
496- movingCenterOffset . Y = OffsetPos ;
497- Vector3 originCoordinates ;
498- Vector3 . Transform ( ref movingCenterOffset , ref worldPosition . XNAMatrix , out originCoordinates ) ;
499- WorldPosition = new WorldPosition ( worldPosition ) ;
500- WorldPosition . XNAMatrix . M41 = originCoordinates . X ;
501- WorldPosition . XNAMatrix . M42 = originCoordinates . Y ;
502- WorldPosition . XNAMatrix . M43 = originCoordinates . Z ;
503- }
504- }
505-
506441}
0 commit comments