@@ -156,8 +156,8 @@ public override void Update(Task caller)
156156 // Try to deploy a pending spawns
157157 if ( spawnInProgress )
158158 {
159- TryPlacement ( ) ;
160- GameManager . Instance . RaiseOnEncounterEvent ( ) ;
159+ if ( TryPlacement ( ) )
160+ GameManager . Instance . RaiseOnEncounterEvent ( ) ;
161161 }
162162 }
163163
@@ -180,7 +180,7 @@ void CreatePendingFoeSpawn(Foe foe)
180180 pendingFoesSpawned = 0 ;
181181 }
182182
183- void TryPlacement ( )
183+ bool TryPlacement ( )
184184 {
185185 PlayerEnterExit playerEnterExit = GameManager . Instance . PlayerEnterExit ;
186186
@@ -189,25 +189,25 @@ void TryPlacement()
189189 if ( isSendAction )
190190 {
191191 if ( ! GameManager . Instance . PlayerGPS . IsPlayerInLocationRect )
192- return ;
192+ return false ;
193193 }
194194
195195 // Place in world near player depending on local area
196196 if ( playerEnterExit . IsPlayerInsideBuilding )
197197 {
198- PlaceFoeBuildingInterior ( pendingFoeGameObjects , playerEnterExit . Interior ) ;
198+ return PlaceFoeBuildingInterior ( pendingFoeGameObjects , playerEnterExit . Interior ) ;
199199 }
200200 else if ( playerEnterExit . IsPlayerInsideDungeon )
201201 {
202- PlaceFoeDungeonInterior ( pendingFoeGameObjects , playerEnterExit . Dungeon ) ;
202+ return PlaceFoeDungeonInterior ( pendingFoeGameObjects , playerEnterExit . Dungeon ) ;
203203 }
204204 else if ( ! playerEnterExit . IsPlayerInside && GameManager . Instance . PlayerGPS . IsPlayerInLocationRect )
205205 {
206- PlaceFoeExteriorLocation ( pendingFoeGameObjects , GameManager . Instance . StreamingWorld . CurrentPlayerLocationObject ) ;
206+ return PlaceFoeExteriorLocation ( pendingFoeGameObjects , GameManager . Instance . StreamingWorld . CurrentPlayerLocationObject ) ;
207207 }
208208 else
209209 {
210- PlaceFoeWilderness ( pendingFoeGameObjects ) ;
210+ return PlaceFoeWilderness ( pendingFoeGameObjects ) ;
211211 }
212212 }
213213
@@ -217,7 +217,7 @@ void TryPlacement()
217217
218218 // Place foe somewhere near player when inside a building
219219 // Building interiors have spawn nodes for this placement so we can roll out foes all at once
220- void PlaceFoeBuildingInterior ( GameObject [ ] gameObjects , DaggerfallInterior interiorParent )
220+ bool PlaceFoeBuildingInterior ( GameObject [ ] gameObjects , DaggerfallInterior interiorParent )
221221 {
222222 // Must have a DaggerfallLocation parent
223223 if ( interiorParent == null )
@@ -229,43 +229,42 @@ void PlaceFoeBuildingInterior(GameObject[] gameObjects, DaggerfallInterior inter
229229 // Always place foes around player rather than use spawn points
230230 // Spawn points work well for "interior hunt" quests but less so for "directly attack the player"
231231 // Feel just placing freely will yield best results overall
232- PlaceFoeFreely ( gameObjects , interiorParent . transform ) ;
233- return ;
232+ return PlaceFoeFreely ( gameObjects , interiorParent . transform ) ;
234233 }
235234
236235 // Place foe somewhere near player when inside a dungeon
237236 // Dungeons interiors are complex 3D environments with no navgrid/navmesh or known spawn nodes
238- void PlaceFoeDungeonInterior ( GameObject [ ] gameObjects , DaggerfallDungeon dungeonParent )
237+ bool PlaceFoeDungeonInterior ( GameObject [ ] gameObjects , DaggerfallDungeon dungeonParent )
239238 {
240- PlaceFoeFreely ( gameObjects , dungeonParent . transform ) ;
239+ return PlaceFoeFreely ( gameObjects , dungeonParent . transform ) ;
241240 }
242241
243242 // Place foe somewhere near player when outside a location navgrid is available
244243 // Navgrid placement helps foe avoid getting tangled in geometry like buildings
245- void PlaceFoeExteriorLocation ( GameObject [ ] gameObjects , DaggerfallLocation locationParent )
244+ bool PlaceFoeExteriorLocation ( GameObject [ ] gameObjects , DaggerfallLocation locationParent )
246245 {
247- PlaceFoeFreely ( gameObjects , locationParent . transform ) ;
246+ return PlaceFoeFreely ( gameObjects , locationParent . transform ) ;
248247 }
249248
250249 // Place foe somewhere near player when outside and no navgrid available
251250 // Wilderness environments are currently open so can be placed on ground anywhere within range
252- void PlaceFoeWilderness ( GameObject [ ] gameObjects )
251+ bool PlaceFoeWilderness ( GameObject [ ] gameObjects )
253252 {
254253 // TODO this false will need to be true when start caching enemies
255254 GameManager . Instance . StreamingWorld . TrackLooseObject ( gameObjects [ pendingFoesSpawned ] , false , - 1 , - 1 , true ) ;
256- PlaceFoeFreely ( gameObjects , null , 8f , 25f ) ;
255+ return PlaceFoeFreely ( gameObjects , null , 8f , 25f ) ;
257256 }
258257
259258 // Uses raycasts to find next spawn position just outside of player's field of view
260- void PlaceFoeFreely ( GameObject [ ] gameObjects , Transform parent , float minDistance = 5f , float maxDistance = 20f )
259+ bool PlaceFoeFreely ( GameObject [ ] gameObjects , Transform parent , float minDistance = 5f , float maxDistance = 20f )
261260 {
262261 const float overlapSphereRadius = 0.65f ;
263262 const float separationDistance = 1.25f ;
264263 const float maxFloorDistance = 4f ;
265264
266265 // Must have received a valid array
267266 if ( gameObjects == null || gameObjects . Length == 0 )
268- return ;
267+ return false ;
269268
270269 // Set parent - otherwise caller must set a parent
271270 if ( parent )
@@ -288,17 +287,17 @@ void PlaceFoeFreely(GameObject[] gameObjects, Transform parent, float minDistanc
288287 // Check for a hit
289288 Vector3 currentPoint ;
290289 RaycastHit initialHit ;
291- if ( Physics . Raycast ( ray , out initialHit , maxDistance , DFULayerMasks . CorporealMask ) )
290+ if ( Physics . Raycast ( ray , out initialHit , maxDistance ) )
292291 {
293292 float cos_normal = Vector3 . Dot ( - spawnDirection , initialHit . normal . normalized ) ;
294293 if ( cos_normal < 1e-6 )
295- return ;
294+ return false ;
296295 float separationForward = separationDistance / cos_normal ;
297296
298297 // Must be greater than minDistance
299298 float distanceSlack = initialHit . distance - separationForward - minDistance ;
300299 if ( distanceSlack < 0f )
301- return ;
300+ return false ;
302301
303302 // Separate out from hit point
304303 float extraDistance = UnityEngine . Random . Range ( 0f , Mathf . Min ( 2f , distanceSlack ) ) ;
@@ -313,14 +312,14 @@ void PlaceFoeFreely(GameObject[] gameObjects, Transform parent, float minDistanc
313312 // Must be able to find a surface below
314313 RaycastHit floorHit ;
315314 ray = new Ray ( currentPoint , Vector3 . down ) ;
316- if ( ! Physics . Raycast ( ray , out floorHit , maxFloorDistance , DFULayerMasks . CorporealMask ) )
317- return ;
315+ if ( ! Physics . Raycast ( ray , out floorHit , maxFloorDistance ) )
316+ return false ;
318317
319318 // Ensure this is open space
320319 Vector3 testPoint = floorHit . point + Vector3 . up * separationDistance ;
321320 Collider [ ] colliders = Physics . OverlapSphere ( testPoint , overlapSphereRadius ) ;
322321 if ( colliders . Length > 0 )
323- return ;
322+ return false ;
324323
325324 // This looks like a good spawn position
326325 pendingFoeGameObjects [ pendingFoesSpawned ] . transform . position = testPoint ;
@@ -336,6 +335,7 @@ void PlaceFoeFreely(GameObject[] gameObjects, Transform parent, float minDistanc
336335
337336 // Increment count
338337 pendingFoesSpawned ++ ;
338+ return true ;
339339 }
340340
341341 // Fine tunes foe position slightly based on mobility and enables GameObject
0 commit comments