Package horizons :: Package ai :: Package aiplayer :: Module areabuilder :: Class AreaBuilder
[hide private]
[frames] | no frames]

Class AreaBuilder

source code

util.changelistener.ChangeListener --+    
                                     |    
          util.worldobject.WorldObject --+
                                         |
                                        AreaBuilder

A class governing the use of a specific type of area of a settlement.

Instance Methods [hide private]
 
__init__(self, settlement_manager) source code
 
__init(self, settlement_manager) source code
 
_load(self, db, settlement_manager, worldid) source code
 
iter_neighbor_tiles(self, rect)
Iterate over the tiles that share a side with the given Rect.
source code
 
iter_possible_road_coords(self, rect, blocked_rect)
Iterate over the possible road tiles that share a side with the given Rect and are not in the blocked Rect.
source code
 
get_path_nodes(self)
Return a dict {(x, y): penalty, ...
source code
 
_get_road_to_builder(self, builder)
Return a path from the builder to a building with general collectors (None if impossible).
source code
 
build_road(self, path)
Build the road given a valid path or None.
source code
 
build_road_connection(self, builder)
Build a road connecting the builder to a building with general collectors.
source code
 
get_road_cost(self, path)
Return the cost of building a road on the given path as {resource_id: amount, ...
source code
 
get_road_connection_cost(self, builder)
Return the cost of building a road from the builder to a building with general collectors.
source code
 
have_resources(self, building_id)
Return a boolean showing whether we currently have the resources to build a building of the given type.
source code
 
build_best_option(self, options, purpose)
Try to build the highest valued option.
source code
 
extend_settlement(self, position)
Build a storage to extend the settlement towards the given position.
source code
 
handle_lost_area(self, coords_list)
Handle losing the potential land in the given coordinates list.
source code
 
add_building(self, building)
Called when a new building is added in the area (the building already exists during the call).
source code
 
remove_building(self, building)
Called when a building is removed from the area (the building still exists during the call).
source code
 
display(self)
Show the plan on the map unless it is disabled in the settings.
source code
 
_init_cache(self)
Initialize the cache that knows the last time the buildability of a rectangle may have changed in this area.
source code
 
register_change(self, x, y, purpose, data)
Register the (potential) change of the purpose of land at the given coordinates.
source code
 
register_change_list(self, coords_list, purpose, data) source code
    Inherited from util.worldobject.WorldObject
 
__lt__(self, other) source code
 
remove(self) source code
 
save(self, db) source code
    Inherited from util.changelistener.ChangeListener
 
_changed(self)
Calls every listener when an object changed
source code
 
add_change_listener(self, listener, call_listener_now=False, no_duplicates=False) source code
 
add_remove_listener(self, listener, no_duplicates=False)
A listener that listens for removal of the object
source code
 
clear_change_listeners(self)
Removes all change listeners
source code
 
discard_change_listener(self, listener)
Remove listener if it's there
source code
 
discard_remove_listener(self, listener) source code
 
end(self) source code
 
has_change_listener(self, listener) source code
 
has_remove_listener(self, listener) source code
 
remove_change_listener(self, listener) source code
 
remove_remove_listener(self, listener) source code
Class Methods [hide private]
 
load(cls, db, settlement_manager) source code
 
__fill_distance(cls, distance, nodes)
Fill the distance dict with the shortest distance from the starting nodes.
source code
    Inherited from util.worldobject.WorldObject
 
get_object_by_id(cls, id)
Returns the worldobject with id id Throws WorldObjectNotFound with the worldid as arg.
source code
 
get_objs(cls) source code
 
reset(cls) source code
Class Variables [hide private]
  log = logging.getLogger("ai.aiplayer.area_builder")
Method Details [hide private]

__init__(self, settlement_manager)
(Constructor)

source code 
Parameters:
  • worldid - worldid to assign. Use None to get an autogenerated one.
Overrides: util.changelistener.ChangeListener.__init__

load(cls, db, settlement_manager)
Class Method

source code 
Overrides: util.changelistener.ChangeListener.load

__fill_distance(cls, distance, nodes)
Class Method

source code 

Fill the distance dict with the shortest distance from the starting nodes.

Parameters:
  • distance - {(x, y): distance, ...}
  • nodes - {(x, y): penalty, ...}

get_path_nodes(self)

source code 

Return a dict {(x, y): penalty, ...} of current and possible future road tiles in the settlement.

build_road(self, path)

source code 

Build the road given a valid path or None. Return True if it worked, False if the path was None.

build_road_connection(self, builder)

source code 

Build a road connecting the builder to a building with general collectors.

Return True if it worked, False if the path was None.

get_road_cost(self, path)

source code 

Return the cost of building a road on the given path as {resource_id: amount, ...} or None if impossible.

get_road_connection_cost(self, builder)

source code 

Return the cost of building a road from the builder to a building with general collectors.

The returned format is {resource_id: amount, ...} if it is possible to build a road and None otherwise.

build_best_option(self, options, purpose)

source code 

Try to build the highest valued option. Return a BUILD_RESULT constant showing how it went.

Parameters:
  • options - [(value, builder), ...]
  • purpose - a BUILDING_PURPOSE constant

extend_settlement(self, position)

source code 

Build a storage to extend the settlement towards the given position.

Return a BUILD_RESULT constant.