23
23
using Orts . Simulation ;
24
24
using Orts . Simulation . Physics ;
25
25
using Orts . Simulation . RollingStocks ;
26
+ using Orts . Simulation . RollingStocks . SubSystems ;
26
27
using Orts . Simulation . Signalling ;
27
28
using ORTS . Common ;
28
29
using ORTS . Scripting . Api ;
@@ -278,8 +279,9 @@ public class MSGPlayer : MSGRequired
278
279
public string leadingID ;
279
280
public string [ ] cars ;
280
281
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 ;
283
285
public string url ;
284
286
public int version ;
285
287
public string MD5 = "" ;
@@ -361,6 +363,7 @@ private void ParseTrainCars(string m)
361
363
ids = new string [ numCars ] ;
362
364
flipped = new int [ numCars ] ;
363
365
lengths = new int [ numCars ] ;
366
+ fadiscretes = new string [ numCars ] ;
364
367
int index , last ;
365
368
for ( var i = 0 ; i < numCars ; i ++ )
366
369
{
@@ -373,6 +376,7 @@ private void ParseTrainCars(string m)
373
376
ids [ i ] = carinfo [ 0 ] ;
374
377
flipped [ i ] = int . Parse ( carinfo [ 1 ] ) ;
375
378
lengths [ i ] = int . Parse ( carinfo [ 2 ] ) ;
379
+ fadiscretes [ i ] = carinfo [ 3 ] ;
376
380
}
377
381
378
382
}
@@ -414,13 +418,17 @@ public MSGPlayer(string n, string cd, string c, string p, Train t, int tn, strin
414
418
ids = new string [ t . Cars . Count ] ;
415
419
flipped = new int [ t . Cars . Count ] ;
416
420
lengths = new int [ t . Cars . Count ] ;
421
+ fadiscretes = new string [ t . Cars . Count ] ;
417
422
for ( var i = 0 ; i < t . Cars . Count ; i ++ )
418
423
{
419
424
cars [ i ] = t . Cars [ i ] . RealWagFilePath ;
420
425
ids [ i ] = t . Cars [ i ] . CarID ;
421
426
if ( t . Cars [ i ] . Flipped == true ) flipped [ i ] = 1 ;
422
427
else flipped [ i ] = 0 ;
423
428
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 ( ) ;
424
432
}
425
433
if ( t . LeadLocomotive != null ) leadingID = t . LeadLocomotive . CarID ;
426
434
else leadingID = "NA" ;
@@ -438,13 +446,12 @@ public override string ToString()
438
446
for ( var i = 0 ; i < cars . Length ; i ++ )
439
447
{
440
448
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 ) ;
443
450
{
444
451
c = c . Remove ( 0 , index + 17 ) ;
445
452
} //c: wagon path without folder name
446
453
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 ";
448
455
}
449
456
450
457
tmp += "\r " + MPManager . Instance ( ) . version + "\r " + MD5 ;
@@ -523,6 +530,8 @@ public override void HandleMsg()
523
530
{
524
531
MPManager . OnlineTrains . Players . Add ( user , p1 ) ;
525
532
p1 . CreatedTime = MPManager . Simulator . GameTime ;
533
+ // re-insert train reference in cars
534
+ InsertTrainReference ( p1Train ) ;
526
535
MPManager . Instance ( ) . AddOrRemoveTrain ( p1Train , true ) ;
527
536
if ( MPManager . IsServer ( ) ) MPManager . Instance ( ) . AddOrRemoveLocomotives ( user , p1Train , true ) ;
528
537
MPManager . Instance ( ) . lostPlayer . Remove ( user ) ;
@@ -674,6 +683,8 @@ public void HandleMsg(OnlinePlayer p)
674
683
p . path = p1 . path ;
675
684
p . Username = p1 . Username ;
676
685
MPManager . OnlineTrains . Players . Add ( user , p ) ;
686
+ // re-insert train reference in cars
687
+ InsertTrainReference ( p1Train ) ;
677
688
MPManager . Instance ( ) . AddOrRemoveTrain ( p . Train , true ) ;
678
689
if ( MPManager . IsServer ( ) ) MPManager . Instance ( ) . AddOrRemoveLocomotives ( user , p . Train , true ) ;
679
690
MPManager . Instance ( ) . lostPlayer . Remove ( user ) ;
@@ -722,6 +733,16 @@ public void HandleMsg(OnlinePlayer p)
722
733
723
734
}
724
735
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
+
725
746
public void SendToPlayer ( OnlinePlayer p , string msg )
726
747
{
727
748
#if DEBUG_MULTIPLAYER
@@ -1224,6 +1245,7 @@ public class MSGTrain : Message
1224
1245
string [ ] ids ;
1225
1246
int [ ] flipped ; //if a wagon is engine
1226
1247
int [ ] lengths ;
1248
+ string [ ] fadiscretes ;
1227
1249
int TrainNum ;
1228
1250
int direction ;
1229
1251
int TileX , TileZ ;
@@ -1263,6 +1285,7 @@ public MSGTrain(string m)
1263
1285
ids = new string [ areas . Length - 2 ] ;
1264
1286
flipped = new int [ areas . Length - 2 ] ;
1265
1287
lengths = new int [ areas . Length - 2 ] ;
1288
+ fadiscretes = new string [ areas . Length - 2 ] ;
1266
1289
for ( var i = 0 ; i < cars . Length ; i ++ )
1267
1290
{
1268
1291
index = areas [ i ] . IndexOf ( '\" ' ) ;
@@ -1274,6 +1297,7 @@ public MSGTrain(string m)
1274
1297
ids [ i ] = carinfo [ 0 ] ;
1275
1298
flipped [ i ] = int . Parse ( carinfo [ 1 ] ) ;
1276
1299
lengths [ i ] = int . Parse ( carinfo [ 2 ] ) ;
1300
+ fadiscretes [ i ] = carinfo [ 3 ] ;
1277
1301
}
1278
1302
index = areas [ areas . Length - 2 ] . IndexOf ( '\n ' ) ;
1279
1303
last = areas [ areas . Length - 2 ] . Length ;
@@ -1289,13 +1313,17 @@ public MSGTrain(Train t, int n)
1289
1313
ids = new string [ t . Cars . Count ] ;
1290
1314
flipped = new int [ t . Cars . Count ] ;
1291
1315
lengths = new int [ t . Cars . Count ] ;
1316
+ fadiscretes = new string [ t . Cars . Count ] ;
1292
1317
for ( var i = 0 ; i < t . Cars . Count ; i ++ )
1293
1318
{
1294
1319
cars [ i ] = t . Cars [ i ] . RealWagFilePath ;
1295
1320
ids [ i ] = t . Cars [ i ] . CarID ;
1296
1321
lengths [ i ] = ( int ) t . Cars [ i ] . CarLengthM ;
1297
1322
if ( t . Cars [ i ] . Flipped == true ) flipped [ i ] = 1 ;
1298
1323
else flipped [ i ] = 0 ;
1324
+ fadiscretes [ i ] = "0" ;
1325
+ if ( t . Cars [ i ] . FreightAnimations != null )
1326
+ fadiscretes [ i ] = t . Cars [ i ] . FreightAnimations . FADiscretesString ( ) ;
1299
1327
}
1300
1328
TrainNum = n ;
1301
1329
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
1324
1352
direction == 1 ? Traveller . TravellerDirection . Forward : Traveller . TravellerDirection . Backward )
1325
1353
} ;
1326
1354
1355
+ string [ ] faDiscreteSplit ;
1356
+ List < LoadData > loadDataList = new List < LoadData > ( ) ;
1327
1357
for ( var i = 0 ; i < cars . Length ; i ++ )
1328
1358
{
1329
1359
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
1332
1362
{
1333
1363
car = RollingStock . Load ( MPManager . Simulator , train , wagonFilePath ) ;
1334
1364
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
+ }
1335
1383
}
1336
1384
catch ( Exception error )
1337
1385
{
@@ -1395,7 +1443,7 @@ public override string ToString()
1395
1443
c = c . Remove ( 0 , index + 17 ) ;
1396
1444
} //c: wagon path without folder name
1397
1445
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 ";
1399
1447
}
1400
1448
tmp += "\n " + name + "\t " ;
1401
1449
return " " + tmp . Length + ": " + tmp ;
@@ -1413,6 +1461,7 @@ public class MSGUpdateTrain : Message
1413
1461
string [ ] ids ;
1414
1462
int [ ] flipped ; //if a wagon is engine
1415
1463
int [ ] lengths ; //if a wagon is engine
1464
+ string [ ] fadiscretes ;
1416
1465
int TrainNum ;
1417
1466
int direction ;
1418
1467
int TileX , TileZ ;
@@ -1456,6 +1505,7 @@ public MSGUpdateTrain(string m)
1456
1505
ids = new string [ areas . Length - 1 ] ;
1457
1506
flipped = new int [ areas . Length - 1 ] ;
1458
1507
lengths = new int [ areas . Length - 1 ] ;
1508
+ fadiscretes = new string [ areas . Length - 1 ] ;
1459
1509
for ( var i = 0 ; i < cars . Length ; i ++ )
1460
1510
{
1461
1511
index = areas [ i ] . IndexOf ( '\" ' ) ;
@@ -1467,6 +1517,7 @@ public MSGUpdateTrain(string m)
1467
1517
ids [ i ] = carinfo [ 0 ] ;
1468
1518
flipped [ i ] = int . Parse ( carinfo [ 1 ] ) ;
1469
1519
lengths [ i ] = int . Parse ( carinfo [ 2 ] ) ;
1520
+ fadiscretes [ i ] = carinfo [ 3 ] ;
1470
1521
}
1471
1522
1472
1523
//System.Console.WriteLine(this.ToString());
@@ -1479,13 +1530,17 @@ public MSGUpdateTrain(string u, Train t, int n)
1479
1530
ids = new string [ t . Cars . Count ] ;
1480
1531
flipped = new int [ t . Cars . Count ] ;
1481
1532
lengths = new int [ t . Cars . Count ] ;
1533
+ fadiscretes = new string [ t . Cars . Count ] ;
1482
1534
for ( var i = 0 ; i < t . Cars . Count ; i ++ )
1483
1535
{
1484
1536
cars [ i ] = t . Cars [ i ] . RealWagFilePath ;
1485
1537
ids [ i ] = t . Cars [ i ] . CarID ;
1486
1538
lengths [ i ] = ( int ) t . Cars [ i ] . CarLengthM ;
1487
1539
if ( t . Cars [ i ] . Flipped == true ) flipped [ i ] = 1 ;
1488
1540
else flipped [ i ] = 0 ;
1541
+ fadiscretes [ i ] = "0" ;
1542
+ if ( t . Cars [ i ] . FreightAnimations != null )
1543
+ fadiscretes [ i ] = t . Cars [ i ] . FreightAnimations . FADiscretesString ( ) ;
1489
1544
}
1490
1545
TrainNum = n ;
1491
1546
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
1524
1579
Traveller traveller = new Traveller ( MPManager . Simulator . TSectionDat , MPManager . Simulator . TDB . TrackDB . TrackNodes , TileX , TileZ , X , Z , direction == 1 ? Traveller . TravellerDirection . Forward : Traveller . TravellerDirection . Backward ) ;
1525
1580
List < TrainCar > tmpCars = new List < TrainCar > ( ) ;
1526
1581
1582
+ string [ ] faDiscreteSplit ;
1583
+ List < LoadData > loadDataList = new List < LoadData > ( ) ;
1527
1584
for ( var i = 0 ; i < cars . Length ; i ++ )
1528
1585
{
1529
1586
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
1534
1591
if ( car == null )
1535
1592
car = RollingStock . Load ( MPManager . Simulator , train , wagonFilePath ) ;
1536
1593
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
+ }
1537
1612
}
1538
1613
catch ( Exception error )
1539
1614
{
@@ -1639,7 +1714,7 @@ public override string ToString()
1639
1714
c = c . Remove ( 0 , index + 17 ) ;
1640
1715
} //c: wagon path without folder name
1641
1716
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 ";
1643
1718
}
1644
1719
return " " + tmp . Length + ": " + tmp ;
1645
1720
}
@@ -3882,4 +3957,4 @@ public override string ToString()
3882
3957
3883
3958
#endregion MSGFlip
3884
3959
3885
- }
3960
+ }
0 commit comments