2323using Orts . Simulation ;
2424using Orts . Simulation . Physics ;
2525using Orts . Simulation . RollingStocks ;
26+ using Orts . Simulation . RollingStocks . SubSystems ;
2627using Orts . Simulation . Signalling ;
2728using ORTS . Common ;
2829using ORTS . Scripting . Api ;
@@ -278,8 +279,9 @@ public class MSGPlayer : MSGRequired
278279 public string leadingID ;
279280 public string [ ] cars ;
280281 public string [ ] ids ;
281- public int [ ] flipped ; //if a wagon is engine
282- public int [ ] lengths ; //if a wagon is engine
282+ public int [ ] flipped ;
283+ public int [ ] lengths ;
284+ public string [ ] fadiscretes ;
283285 public string url ;
284286 public int version ;
285287 public string MD5 = "" ;
@@ -361,6 +363,7 @@ private void ParseTrainCars(string m)
361363 ids = new string [ numCars ] ;
362364 flipped = new int [ numCars ] ;
363365 lengths = new int [ numCars ] ;
366+ fadiscretes = new string [ numCars ] ;
364367 int index , last ;
365368 for ( var i = 0 ; i < numCars ; i ++ )
366369 {
@@ -373,6 +376,7 @@ private void ParseTrainCars(string m)
373376 ids [ i ] = carinfo [ 0 ] ;
374377 flipped [ i ] = int . Parse ( carinfo [ 1 ] ) ;
375378 lengths [ i ] = int . Parse ( carinfo [ 2 ] ) ;
379+ fadiscretes [ i ] = carinfo [ 3 ] ;
376380 }
377381
378382 }
@@ -414,13 +418,17 @@ public MSGPlayer(string n, string cd, string c, string p, Train t, int tn, strin
414418 ids = new string [ t . Cars . Count ] ;
415419 flipped = new int [ t . Cars . Count ] ;
416420 lengths = new int [ t . Cars . Count ] ;
421+ fadiscretes = new string [ t . Cars . Count ] ;
417422 for ( var i = 0 ; i < t . Cars . Count ; i ++ )
418423 {
419424 cars [ i ] = t . Cars [ i ] . RealWagFilePath ;
420425 ids [ i ] = t . Cars [ i ] . CarID ;
421426 if ( t . Cars [ i ] . Flipped == true ) flipped [ i ] = 1 ;
422427 else flipped [ i ] = 0 ;
423428 lengths [ i ] = ( int ) ( t . Cars [ i ] . CarLengthM * 100 ) ;
429+ fadiscretes [ i ] = "0" ;
430+ if ( t . Cars [ i ] . FreightAnimations != null )
431+ fadiscretes [ i ] = t . Cars [ i ] . FreightAnimations . FADiscretesString ( ) ;
424432 }
425433 if ( t . LeadLocomotive != null ) leadingID = t . LeadLocomotive . CarID ;
426434 else leadingID = "NA" ;
@@ -438,13 +446,12 @@ public override string ToString()
438446 for ( var i = 0 ; i < cars . Length ; i ++ )
439447 {
440448 var c = cars [ i ] ;
441- var index = c . LastIndexOf ( "\\ trains\\ trainset\\ " , StringComparison . OrdinalIgnoreCase ) ;
442- if ( index > 0 )
449+ var index = c . LastIndexOf ( "\\ trains\\ trainset\\ " , StringComparison . OrdinalIgnoreCase ) ;
443450 {
444451 c = c . Remove ( 0 , index + 17 ) ;
445452 } //c: wagon path without folder name
446453
447- tmp += "\" " + c + "\" " + " " + ids [ i ] + "\n " + flipped [ i ] + "\n " + lengths [ i ] + "\t " ;
454+ tmp += "\" " + c + "\" " + " " + ids [ i ] + "\n " + flipped [ i ] + "\n " + lengths [ i ] + "\n " + fadiscretes [ i ] + " \ t ";
448455 }
449456
450457 tmp += "\r " + MPManager . Instance ( ) . version + "\r " + MD5 ;
@@ -523,6 +530,8 @@ public override void HandleMsg()
523530 {
524531 MPManager . OnlineTrains . Players . Add ( user , p1 ) ;
525532 p1 . CreatedTime = MPManager . Simulator . GameTime ;
533+ // re-insert train reference in cars
534+ InsertTrainReference ( p1Train ) ;
526535 MPManager . Instance ( ) . AddOrRemoveTrain ( p1Train , true ) ;
527536 if ( MPManager . IsServer ( ) ) MPManager . Instance ( ) . AddOrRemoveLocomotives ( user , p1Train , true ) ;
528537 MPManager . Instance ( ) . lostPlayer . Remove ( user ) ;
@@ -674,6 +683,8 @@ public void HandleMsg(OnlinePlayer p)
674683 p . path = p1 . path ;
675684 p . Username = p1 . Username ;
676685 MPManager . OnlineTrains . Players . Add ( user , p ) ;
686+ // re-insert train reference in cars
687+ InsertTrainReference ( p1Train ) ;
677688 MPManager . Instance ( ) . AddOrRemoveTrain ( p . Train , true ) ;
678689 if ( MPManager . IsServer ( ) ) MPManager . Instance ( ) . AddOrRemoveLocomotives ( user , p . Train , true ) ;
679690 MPManager . Instance ( ) . lostPlayer . Remove ( user ) ;
@@ -722,6 +733,16 @@ public void HandleMsg(OnlinePlayer p)
722733
723734 }
724735
736+ private void InsertTrainReference ( Train train )
737+ {
738+ foreach ( var car in train . Cars )
739+ {
740+ car . Train = train ;
741+ car . IsPartOfActiveTrain = true ;
742+ car . FreightAnimations ? . ShowDiscreteFreightAnimations ( ) ;
743+ }
744+ }
745+
725746 public void SendToPlayer ( OnlinePlayer p , string msg )
726747 {
727748#if DEBUG_MULTIPLAYER
@@ -1224,6 +1245,7 @@ public class MSGTrain : Message
12241245 string [ ] ids ;
12251246 int [ ] flipped ; //if a wagon is engine
12261247 int [ ] lengths ;
1248+ string [ ] fadiscretes ;
12271249 int TrainNum ;
12281250 int direction ;
12291251 int TileX , TileZ ;
@@ -1263,6 +1285,7 @@ public MSGTrain(string m)
12631285 ids = new string [ areas . Length - 2 ] ;
12641286 flipped = new int [ areas . Length - 2 ] ;
12651287 lengths = new int [ areas . Length - 2 ] ;
1288+ fadiscretes = new string [ areas . Length - 2 ] ;
12661289 for ( var i = 0 ; i < cars . Length ; i ++ )
12671290 {
12681291 index = areas [ i ] . IndexOf ( '\" ' ) ;
@@ -1274,6 +1297,7 @@ public MSGTrain(string m)
12741297 ids [ i ] = carinfo [ 0 ] ;
12751298 flipped [ i ] = int . Parse ( carinfo [ 1 ] ) ;
12761299 lengths [ i ] = int . Parse ( carinfo [ 2 ] ) ;
1300+ fadiscretes [ i ] = carinfo [ 3 ] ;
12771301 }
12781302 index = areas [ areas . Length - 2 ] . IndexOf ( '\n ' ) ;
12791303 last = areas [ areas . Length - 2 ] . Length ;
@@ -1289,13 +1313,17 @@ public MSGTrain(Train t, int n)
12891313 ids = new string [ t . Cars . Count ] ;
12901314 flipped = new int [ t . Cars . Count ] ;
12911315 lengths = new int [ t . Cars . Count ] ;
1316+ fadiscretes = new string [ t . Cars . Count ] ;
12921317 for ( var i = 0 ; i < t . Cars . Count ; i ++ )
12931318 {
12941319 cars [ i ] = t . Cars [ i ] . RealWagFilePath ;
12951320 ids [ i ] = t . Cars [ i ] . CarID ;
12961321 lengths [ i ] = ( int ) t . Cars [ i ] . CarLengthM ;
12971322 if ( t . Cars [ i ] . Flipped == true ) flipped [ i ] = 1 ;
12981323 else flipped [ i ] = 0 ;
1324+ fadiscretes [ i ] = "0" ;
1325+ if ( t . Cars [ i ] . FreightAnimations != null )
1326+ fadiscretes [ i ] = t . Cars [ i ] . FreightAnimations . FADiscretesString ( ) ;
12991327 }
13001328 TrainNum = n ;
13011329 direction = t . RearTDBTraveller . Direction == Traveller . TravellerDirection . Forward ? 1 : 0 ;
@@ -1324,6 +1352,8 @@ public override void HandleMsg() //only client will get message, thus will set s
13241352 direction == 1 ? Traveller . TravellerDirection . Forward : Traveller . TravellerDirection . Backward )
13251353 } ;
13261354
1355+ string [ ] faDiscreteSplit ;
1356+ List < LoadData > loadDataList = new List < LoadData > ( ) ;
13271357 for ( var i = 0 ; i < cars . Length ; i ++ )
13281358 {
13291359 string wagonFilePath = MPManager . Simulator . BasePath + @"\trains\trainset\" + cars [ i ] ;
@@ -1332,6 +1362,24 @@ public override void HandleMsg() //only client will get message, thus will set s
13321362 {
13331363 car = RollingStock . Load ( MPManager . Simulator , train , wagonFilePath ) ;
13341364 car . CarLengthM = lengths [ i ] ;
1365+ if ( fadiscretes [ i ] [ 0 ] != '0' )
1366+ {
1367+ int numDiscretes = fadiscretes [ i ] [ 0 ] ;
1368+ // There are discrete freight animations, add them to wagon
1369+ faDiscreteSplit = fadiscretes [ i ] . Split ( '&' ) ;
1370+ loadDataList . Clear ( ) ;
1371+ for ( int j = 1 ; j < faDiscreteSplit . Length ; j ++ )
1372+ {
1373+ var faDiscrete = faDiscreteSplit [ j ] ;
1374+ string [ ] loadDataItems = faDiscrete . Split ( '%' ) ;
1375+ LoadData loadData = new LoadData ( ) ;
1376+ loadData . Name = loadDataItems [ 0 ] ;
1377+ loadData . Folder = loadDataItems [ 1 ] ;
1378+ Enum . TryParse ( loadDataItems [ 2 ] , out loadData . LoadPosition ) ;
1379+ loadDataList . Add ( loadData ) ;
1380+ }
1381+ car . FreightAnimations ? . Load ( loadDataList ) ;
1382+ }
13351383 }
13361384 catch ( Exception error )
13371385 {
@@ -1395,7 +1443,7 @@ public override string ToString()
13951443 c = c . Remove ( 0 , index + 17 ) ;
13961444 } //c: wagon path without folder name
13971445
1398- tmp += "\" " + c + "\" " + " " + ids [ i ] + "\n " + flipped [ i ] + "\n " + lengths [ i ] + "\t " ;
1446+ tmp += "\" " + c + "\" " + " " + ids [ i ] + "\n " + flipped [ i ] + "\n " + lengths [ i ] + "\n " + fadiscretes [ i ] + " \ t ";
13991447 }
14001448 tmp += "\n " + name + "\t " ;
14011449 return " " + tmp . Length + ": " + tmp ;
@@ -1413,6 +1461,7 @@ public class MSGUpdateTrain : Message
14131461 string [ ] ids ;
14141462 int [ ] flipped ; //if a wagon is engine
14151463 int [ ] lengths ; //if a wagon is engine
1464+ string [ ] fadiscretes ;
14161465 int TrainNum ;
14171466 int direction ;
14181467 int TileX , TileZ ;
@@ -1456,6 +1505,7 @@ public MSGUpdateTrain(string m)
14561505 ids = new string [ areas . Length - 1 ] ;
14571506 flipped = new int [ areas . Length - 1 ] ;
14581507 lengths = new int [ areas . Length - 1 ] ;
1508+ fadiscretes = new string [ areas . Length - 1 ] ;
14591509 for ( var i = 0 ; i < cars . Length ; i ++ )
14601510 {
14611511 index = areas [ i ] . IndexOf ( '\" ' ) ;
@@ -1467,6 +1517,7 @@ public MSGUpdateTrain(string m)
14671517 ids [ i ] = carinfo [ 0 ] ;
14681518 flipped [ i ] = int . Parse ( carinfo [ 1 ] ) ;
14691519 lengths [ i ] = int . Parse ( carinfo [ 2 ] ) ;
1520+ fadiscretes [ i ] = carinfo [ 3 ] ;
14701521 }
14711522
14721523 //System.Console.WriteLine(this.ToString());
@@ -1479,13 +1530,17 @@ public MSGUpdateTrain(string u, Train t, int n)
14791530 ids = new string [ t . Cars . Count ] ;
14801531 flipped = new int [ t . Cars . Count ] ;
14811532 lengths = new int [ t . Cars . Count ] ;
1533+ fadiscretes = new string [ t . Cars . Count ] ;
14821534 for ( var i = 0 ; i < t . Cars . Count ; i ++ )
14831535 {
14841536 cars [ i ] = t . Cars [ i ] . RealWagFilePath ;
14851537 ids [ i ] = t . Cars [ i ] . CarID ;
14861538 lengths [ i ] = ( int ) t . Cars [ i ] . CarLengthM ;
14871539 if ( t . Cars [ i ] . Flipped == true ) flipped [ i ] = 1 ;
14881540 else flipped [ i ] = 0 ;
1541+ fadiscretes [ i ] = "0" ;
1542+ if ( t . Cars [ i ] . FreightAnimations != null )
1543+ fadiscretes [ i ] = t . Cars [ i ] . FreightAnimations . FADiscretesString ( ) ;
14891544 }
14901545 TrainNum = n ;
14911546 direction = t . RearTDBTraveller . Direction == Traveller . TravellerDirection . Forward ? 1 : 0 ;
@@ -1524,6 +1579,8 @@ public override void HandleMsg() //only client will get message, thus will set s
15241579 Traveller traveller = new Traveller ( MPManager . Simulator . TSectionDat , MPManager . Simulator . TDB . TrackDB . TrackNodes , TileX , TileZ , X , Z , direction == 1 ? Traveller . TravellerDirection . Forward : Traveller . TravellerDirection . Backward ) ;
15251580 List < TrainCar > tmpCars = new List < TrainCar > ( ) ;
15261581
1582+ string [ ] faDiscreteSplit ;
1583+ List < LoadData > loadDataList = new List < LoadData > ( ) ;
15271584 for ( var i = 0 ; i < cars . Length ; i ++ )
15281585 {
15291586 string wagonFilePath = MPManager . Simulator . BasePath + @"\trains\trainset\" + cars [ i ] ;
@@ -1534,6 +1591,24 @@ public override void HandleMsg() //only client will get message, thus will set s
15341591 if ( car == null )
15351592 car = RollingStock . Load ( MPManager . Simulator , train , wagonFilePath ) ;
15361593 car . CarLengthM = lengths [ i ] ;
1594+ if ( fadiscretes [ i ] [ 0 ] != '0' )
1595+ {
1596+ int numDiscretes = fadiscretes [ i ] [ 0 ] ;
1597+ // There are discrete freight animations, add them to wagon
1598+ faDiscreteSplit = fadiscretes [ i ] . Split ( '&' ) ;
1599+ loadDataList . Clear ( ) ;
1600+ for ( int j = 1 ; j < faDiscreteSplit . Length ; j ++ )
1601+ {
1602+ var faDiscrete = faDiscreteSplit [ j ] ;
1603+ string [ ] loadDataItems = faDiscrete . Split ( '%' ) ;
1604+ LoadData loadData = new LoadData ( ) ;
1605+ loadData . Name = loadDataItems [ 0 ] ;
1606+ loadData . Folder = loadDataItems [ 1 ] ;
1607+ Enum . TryParse ( loadDataItems [ 2 ] , out loadData . LoadPosition ) ;
1608+ loadDataList . Add ( loadData ) ;
1609+ }
1610+ car . FreightAnimations ? . Load ( loadDataList ) ;
1611+ }
15371612 }
15381613 catch ( Exception error )
15391614 {
@@ -1639,7 +1714,7 @@ public override string ToString()
16391714 c = c . Remove ( 0 , index + 17 ) ;
16401715 } //c: wagon path without folder name
16411716
1642- tmp += "\" " + c + "\" " + " " + ids [ i ] + "\n " + flipped [ i ] + "\n " + lengths [ i ] + "\t " ;
1717+ tmp += "\" " + c + "\" " + " " + ids [ i ] + "\n " + flipped [ i ] + "\n " + lengths [ i ] + "\n " + fadiscretes [ i ] + " \ t ";
16431718 }
16441719 return " " + tmp . Length + ": " + tmp ;
16451720 }
@@ -3882,4 +3957,4 @@ public override string ToString()
38823957
38833958#endregion MSGFlip
38843959
3885- }
3960+ }
0 commit comments