@@ -496,7 +496,15 @@ public class SoundSource : SoundSourceBase
496496 /// Squared cutoff distance. No sound is audible above that, except for the actual player train,
497497 /// where cutoff occurs at a distance wich is higher than the train length
498498 /// </summary>
499- private const int CUTOFFDISTANCE = 4000000 ;
499+ private int CutOffDistanceM2
500+ {
501+ get
502+ {
503+ const int staticDistanceM2 = 4000000 ;
504+ var isPlayer = Car ? . Train ? . IsActualPlayerTrain ?? false ;
505+ return ( int ) Math . Max ( staticDistanceM2 , isPlayer ? Car . Train . Length * Car . Train . Length : 0 ) ;
506+ }
507+ }
500508 /// <summary>
501509 /// Max distance for OpenAL inverse distance model. Equals to Math.Sqrt(CUTOFFDISTANCE)
502510 /// </summary>
@@ -660,9 +668,9 @@ public override void Uninitialize()
660668 public bool MstsMonoTreatment ;
661669
662670 /// <summary>
663- /// Current distance to camera, squared meter. Is used for comparision to <see cref="CUTOFFDISTANCE "/>, to determine if is out-of-scope
671+ /// Current distance to camera, squared meter. Is used for comparision to <see cref="CutOffDistanceM2 "/>, to determine if is out-of-scope
664672 /// </summary>
665- public float DistanceSquared = CUTOFFDISTANCE + 1 ;
673+ public float DistanceSquared = float . MaxValue ;
666674 /// <summary>
667675 /// Out-of-scope state in previous <see cref="Update"/> loop
668676 /// </summary>
@@ -995,7 +1003,7 @@ public override bool Update()
9951003 } // Update
9961004
9971005 /// <summary>
998- /// Calculate current distance to camera, and compare it to <see cref="CUTOFFDISTANCE "/>
1006+ /// Calculate current distance to camera, and compare it to <see cref="CutOffDistanceM2 "/>
9991007 /// </summary>
10001008 /// <returns>True, if is now out-of-scope</returns>
10011009 public bool isOutOfDistance ( )
@@ -1010,15 +1018,13 @@ public bool isOutOfDistance()
10101018 float . IsNaN ( WorldLocation . Location . Y ) ||
10111019 float . IsNaN ( WorldLocation . Location . Z ) )
10121020 {
1013- DistanceSquared = ( Car != null && Car . Train != null && Car . Train . IsActualPlayerTrain ?
1014- Math . Max ( CUTOFFDISTANCE , Car . Train . Length * Car . Train . Length ) : CUTOFFDISTANCE ) + 1 ;
1021+ DistanceSquared = float . MaxValue ;
10151022 return true ;
10161023 }
10171024
10181025 DistanceSquared = WorldLocation . GetDistanceSquared ( WorldLocation , Viewer . Camera . CameraWorldLocation ) ;
10191026
1020- return DistanceSquared > ( Car != null && Car . Train != null && Car . Train . IsActualPlayerTrain ?
1021- Math . Max ( CUTOFFDISTANCE , Car . Train . Length * Car . Train . Length ) + 2500f : CUTOFFDISTANCE ) ;
1027+ return DistanceSquared > CutOffDistanceM2 ;
10221028 }
10231029
10241030 /// <summary>
@@ -1037,8 +1043,7 @@ public bool Activate()
10371043 {
10381044 // (ActivationConditions.Distance == 0) means distance checking disabled
10391045 if ( ( ActivationConditions . Distance == 0 || DistanceSquared < ActivationConditions . Distance * ActivationConditions . Distance ) &&
1040- DistanceSquared < ( Car != null && Car . Train != null && Car . Train . IsActualPlayerTrain ?
1041- Math . Max ( CUTOFFDISTANCE , Car . Train . Length * Car . Train . Length ) + 2500f : CUTOFFDISTANCE ) )
1046+ DistanceSquared < CutOffDistanceM2 )
10421047 return true ;
10431048 }
10441049 else
@@ -1063,8 +1068,7 @@ public bool DeActivate()
10631068 if ( WorldLocation != WorldLocation . None )
10641069 {
10651070 if ( DeactivationConditions . Distance != 0 && DistanceSquared > DeactivationConditions . Distance * DeactivationConditions . Distance ||
1066- DistanceSquared > ( Car != null && Car . Train != null && Car . Train . IsActualPlayerTrain ?
1067- Math . Max ( CUTOFFDISTANCE , Car . Train . Length * Car . Train . Length ) + 2500f : CUTOFFDISTANCE ) )
1071+ DistanceSquared > CutOffDistanceM2 )
10681072 return true ;
10691073 }
10701074
0 commit comments