Package horizons :: Package util :: Module buildingindexer :: Class BuildingIndexer
[hide private]
[frames] | no frames]

Class BuildingIndexer

source code

Indexes a subset of the buildings on an island to improve nearby building lookup performance.

Used to answer queries of the form 'I am at (x, y), where is the closest / random building that provides resource X in my range'.

Instance Methods [hide private]
 
__init__(self, radius, coords_list, random=None, buildings=None)
Create a BuildingIndexer
source code
 
add(self, building) source code
 
remove(self, building) source code
 
_update(self, add_buildings=None, initial=False) source code
 
get_buildings_in_range(self, coords)
Returns all buildings in range in the form of a Building generator
source code
 
get_random_building_in_range(self, coords)
Returns a random building in range or None if one doesn't exist Don't use this for user interactions unless you want to break multiplayer
source code
 
get_num_buildings_in_range(self, coords)
Returns the number of buildings in range of the position
source code
Method Details [hide private]

__init__(self, radius, coords_list, random=None, buildings=None)
(Constructor)

source code 

Create a BuildingIndexer

Parameters:
  • radius - int, maximum required radius of the buildings
  • coords_list - list of tuples, the coordinates of the island
  • random - the rng of the session
  • buildings - initial list of buildings. Will only be read.

_update(self, add_buildings=None, initial=False)

source code 
Parameters:
  • add_buildings - Don't use unless you know why.
  • initial - can be set on first call as optimization

get_buildings_in_range(self, coords)

source code 

Returns all buildings in range in the form of a Building generator

Parameters:
  • coords - tuple, the point around which to get the buildings

get_random_building_in_range(self, coords)

source code 

Returns a random building in range or None if one doesn't exist Don't use this for user interactions unless you want to break multiplayer

Parameters:
  • coords - tuple, the point around which to get the building

get_num_buildings_in_range(self, coords)

source code 

Returns the number of buildings in range of the position

Parameters:
  • coords - tuple, the center point