@@ -70,58 +70,8 @@ private static void Init( )
7070 m_spawnGroupCumulativeFrequencies . Add ( m_spawnGroupTotalFrequencies ) ;
7171 }
7272 }
73-
74- public static bool DoesTrajectoryIntersect ( Vector3D start , Vector3D end , float spawnRadius )
75- {
76- Ray trajectory = new Ray ( start , ( end - start ) ) ;
77- return DoesTrajectoryIntersect ( trajectory , spawnRadius ) ;
78- }
79-
80- public static bool DoesTrajectoryIntersect ( Ray trajectory , float spawnRadius )
81- {
82- if ( ExtenderOptions . IsDebugging )
83- Essentials . Log . Info ( "Checking gravity intersect" ) ;
84-
85- foreach ( IMyGravityProvider provider in MyGravityProviderSystem . NaturalGravityProviders )
86- {
87- MyPlanet planet = provider as MyPlanet ;
88- if ( planet == null )
89- continue ;
90- BoundingSphereD gravitySphere = new BoundingSphereD ( planet . PositionComp . GetPosition ( ) , planet . GravityLimit + spawnRadius ) ;
91-
92- float ? intersect = trajectory . Intersects ( gravitySphere ) ;
93- if ( intersect . HasValue && intersect . Value > 0 )
94- return true ;
95- }
96- /*
97- foreach ( BoundingSphereD sphere in gravitySphereList )
98- {
99- if ( trajectory.Intersects( sphere ).HasValue )
100- return true;
101- }
102- */
103- return false ;
104- }
105-
106- public static bool IsPointInGravity ( Vector3D testPoint )
107- {
108- if ( ExtenderOptions . IsDebugging )
109- Essentials . Log . Info ( "Checking point gravity intersect" ) ;
110-
111- return ! Vector3D . IsZero ( MyGravityProviderSystem . CalculateNaturalGravityInPoint ( testPoint , true ) ) ;
112-
113- /*
114- foreach ( BoundingSphereD sphere in gravitySphereList )
115- {
116- if ( sphere.Contains( testPoint ) == ContainmentType.Contains)
117- return true;
118- }
119-
120- return false;
121- */
122- }
12373
124- public static void SpawnCargoShip ( )
74+ public static void SpawnCargoShip ( bool checkGravity )
12575 {
12676 Init ( ) ;
12777 Wrapper . GameAction ( ( ) =>
@@ -245,22 +195,26 @@ public static void SpawnCargoShip()
245195 Vector3D shipDestination = shipPosition + directionMult ;
246196 float radius = prefabDef == null ? 10.0f : prefabDef . BoundingSphere . Radius ;
247197
248- if ( IsPointInGravity ( shipPosition ) )
249- {
250- if ( ExtenderOptions . IsDebugging )
251- Essentials . Log . Info ( "Failed to spawn cargo ship: Spawn location is in gravity well" ) ;
252- return ;
253- }
254- if ( IsPointInGravity ( shipDestination ) )
198+ if ( checkGravity )
255199 {
256- if ( ExtenderOptions . IsDebugging )
257- Essentials . Log . Info ( "Failed to spawn cargo ship: Destination is in gravity well" ) ;
258- }
259- if ( DoesTrajectoryIntersect ( shipPosition , shipDestination , spawnGroup . SpawnRadius ) )
260- {
261- if ( ExtenderOptions . IsDebugging )
262- Essentials . Log . Info ( "Failed to spawn cargo ship: Ship path intersects gravity well" ) ;
263- return ;
200+ //these point checks could be done in the trajectory intersect, but checking points is faster than ray intersect
201+ if ( MyGravityProviderSystem . IsPositionInNaturalGravity ( shipPosition , spawnGroup . SpawnRadius ) )
202+ {
203+ if ( ExtenderOptions . IsDebugging )
204+ Essentials . Log . Info ( "Failed to spawn cargo ship: Spawn location is in gravity well" ) ;
205+ return ;
206+ }
207+ if ( MyGravityProviderSystem . IsPositionInNaturalGravity ( shipDestination , spawnGroup . SpawnRadius ) )
208+ {
209+ if ( ExtenderOptions . IsDebugging )
210+ Essentials . Log . Info ( "Failed to spawn cargo ship: Destination is in gravity well" ) ;
211+ }
212+ if ( MyGravityProviderSystem . DoesTrajectoryIntersectNaturalGravity ( shipPosition , shipDestination , spawnGroup . SpawnRadius + 500 ) )
213+ {
214+ if ( ExtenderOptions . IsDebugging )
215+ Essentials . Log . Info ( "Failed to spawn cargo ship: Ship path intersects gravity well" ) ;
216+ return ;
217+ }
264218 }
265219
266220 MyPhysics . CastRay ( shipPosition , shipDestination , m_raycastHits , MyPhysics . CollisionLayers . ObjectDetectionCollisionLayer ) ;
0 commit comments