Package horizons :: Package ai :: Package aiplayer :: Module productionbuilder :: Class ProductionBuilder
[hide private]
[frames] | no frames]

Class ProductionBuilder

source code

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


An object of this class manages the production area of a settlement.

Important attributes:
* plan: a dictionary of the form {(x, y): (purpose, extra data), ...} where purpose is one of the BUILDING_PURPOSE constants.
        Coordinates being in the plan means that the tile doesn't belong to another player.
* collector_buildings: a list of every building in the settlement that provides general collectors (warehouse, storages)
* production_buildings: a list of buildings in the settlement where productions should be paused and resumed at appropriate times
* unused_fields: a dictionary where the key is a BUILDING_PURPOSE constant of a field and the value is a deque that holds the
        coordinates of unused field spots. {building purpose: deque([(x, y), ...]), ...}
* last_collector_improvement_storage: the last tick when a storage was built to improve collector coverage
* last_collector_improvement_road: the last tick when a new road connection was built to improve collector coverage

Instance Methods [hide private]
 
__init__(self, settlement_manager) source code
 
__init(self, settlement_manager, last_collector_improvement_storage, last_collector_improvement_road) source code
 
_init_buildability_cache(self) source code
 
_init_simple_collector_area_cache(self) source code
 
_init_road_connectivity_cache(self) source code
 
save(self, db) source code
 
_load(self, db, settlement_manager) source code
 
have_deposit(self, resource_id)
Returns True if there is a resource deposit of the relevant type inside the settlement.
source code
 
extend_settlement_with_storage(self, target_position)
Build a storage to extend the settlement towards the given position.
source code
 
get_collector_area(self)
Return the set of all coordinates that are reachable from at least one collector by road or open space.
source code
 
count_available_squares(self, size, max_num=None)
Count the number of available and usable (covered by collectors) size x size squares.
source code
 
_refresh_unused_fields(self)
Refresh the unused_fields object to make sure no impossible fields spots are in the list.
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 possible buildability change of a rectangle on this island.
source code
 
register_change_list(self, coords_list, purpose, data) source code
 
handle_lost_area(self, coords_list)
Handle losing the potential land in the given coordinates list.
source code
 
handle_new_area(self)
Handle receiving more land to the production area (this can happen when the village area gives some up).
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
 
_handle_lumberjack_removal(self, building)
Release the unused trees around the lumberjack building being removed.
source code
 
_handle_farm_removal(self, building)
Handle farm removal by removing planned fields and tearing existing ones that can't be serviced by another farm.
source code
 
remove_building(self, building)
Called when a building is removed from the area (the building still exists during the call).
source code
 
manage_production(self)
Pauses and resumes production buildings when they have full input and output inventories.
source code
 
handle_mine_empty(self, mine) source code
 
__str__(self) source code
    Inherited from areabuilder.AreaBuilder
 
_get_road_to_builder(self, builder)
Return a path from the builder to a building with general collectors (None if impossible).
source code
 
build_best_option(self, options, purpose)
Try to build the highest valued option.
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
 
extend_settlement(self, position)
Build a storage to extend the settlement towards the given position.
source code
 
get_path_nodes(self)
Return a dict {(x, y): penalty, ...
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
 
get_road_cost(self, path)
Return the cost of building a road on the given path as {resource_id: amount, ...
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
 
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
    Inherited from util.worldobject.WorldObject
 
__lt__(self, other) source code
 
remove(self) 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]
    Inherited from areabuilder.AreaBuilder
 
load(cls, db, settlement_manager) 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]
  coastal_building_classes = [BUILDINGS.FISHER, BUILDINGS.BOAT_B...
  collector_building_classes = [BUILDINGS.WAREHOUSE, BUILDINGS.S...
  field_building_classes = [BUILDINGS.POTATO_FIELD, BUILDINGS.PA...
  production_building_classes = {BUILDINGS.FISHER, BUILDINGS.LUM...
    Inherited from areabuilder.AreaBuilder
  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__

save(self, db)

source code 
Overrides: util.worldobject.WorldObject.save

_load(self, db, settlement_manager)

source code 
Overrides: areabuilder.AreaBuilder._load

extend_settlement_with_storage(self, target_position)

source code 

Build a storage to extend the settlement towards the given position. Return a BUILD_RESULT constant.

count_available_squares(self, size, max_num=None)

source code 

Count the number of available and usable (covered by collectors) size x size squares.

Parameters:
  • size - the square side length
  • max_num - if non-None then stop counting once the number of total squares is max_num
Returns:
(available squares, total squares)

display(self)

source code 

Show the plan on the map unless it is disabled in the settings.

Overrides: areabuilder.AreaBuilder.display

_init_cache(self)

source code 

Initialize the cache that knows the last time the buildability of a rectangle may have changed in this area.

Overrides: areabuilder.AreaBuilder._init_cache

register_change(self, x, y, purpose, data)

source code 

Register the possible buildability change of a rectangle on this island.

Overrides: areabuilder.AreaBuilder.register_change

register_change_list(self, coords_list, purpose, data)

source code 
Overrides: areabuilder.AreaBuilder.register_change_list

handle_lost_area(self, coords_list)

source code 

Handle losing the potential land in the given coordinates list.

Overrides: areabuilder.AreaBuilder.handle_lost_area

add_building(self, building)

source code 

Called when a new building is added in the area (the building already exists during the call).

Overrides: areabuilder.AreaBuilder.add_building

remove_building(self, building)

source code 

Called when a building is removed from the area (the building still exists during the call).

Overrides: areabuilder.AreaBuilder.remove_building

Class Variable Details [hide private]

coastal_building_classes

Value:
[BUILDINGS.FISHER, BUILDINGS.BOAT_BUILDER, BUILDINGS.SALT_PONDS]

collector_building_classes

Value:
[BUILDINGS.WAREHOUSE, BUILDINGS.STORAGE]

field_building_classes

Value:
[BUILDINGS.POTATO_FIELD, BUILDINGS.PASTURE, BUILDINGS.SUGARCANE_FIELD,\
 BUILDINGS.TOBACCO_FIELD]

production_building_classes

Value:
{BUILDINGS.FISHER, BUILDINGS.LUMBERJACK, BUILDINGS.FARM, BUILDINGS.CLA\
Y_PIT, BUILDINGS.BRICKYARD, BUILDINGS.WEAVER, BUILDINGS.DISTILLERY, BU\
ILDINGS.MINE, BUILDINGS.SMELTERY, BUILDINGS.TOOLMAKER, BUILDINGS.CHARC\
OAL_BURNER, BUILDINGS.TOBACCONIST, BUILDINGS.SALT_PONDS}