Skip to content

Commit

Permalink
Fix for spawning env vehicles on ALC
Browse files Browse the repository at this point in the history
  • Loading branch information
pziecina committed May 7, 2020
1 parent 1a811a8 commit 6cc5b7d
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ def _spawn_env_vehicles(self, n: int):
blueprints = self._world.get_blueprint_library().filter('vehicle.*')
blueprints = [b for b in blueprints if int(b.get_attribute('number_of_wheels')) == 4]
spawn_points = self._world_map.get_spawn_points()
max_ticks = 4

def _get_env_vehicles():
return [
v for v in self._world.get_actors().filter('vehicle.*')
if v.attributes.get('role_name') != 'hero' and v.is_alive
]

def _wait_for_env_vehicles(total_number, max_ticks):
env_vehicles = _get_env_vehicles()
while len(env_vehicles) < total_number and max_ticks > 0:
self._world.tick()
max_ticks -= 1
env_vehicles = _get_env_vehicles()
return env_vehicles

env_vehicles = _get_env_vehicles()
missing_vehicles = n - len(env_vehicles)
while missing_vehicles:
Expand All @@ -131,7 +140,7 @@ def _get_env_vehicles():
random.sample(spawn_points, k=missing_vehicles))
]
self._client.apply_batch_sync(cmds, do_tick=True)
env_vehicles = _get_env_vehicles()
env_vehicles = _wait_for_env_vehicles(n, max_ticks)
missing_vehicles = n - len(env_vehicles)
return env_vehicles

Expand Down

0 comments on commit 6cc5b7d

Please sign in to comment.