Package horizons :: Package ai :: Package aiplayer :: Module resourcemanager :: Class ResourceManager
[hide private]
[frames] | no frames]

Class ResourceManager

source code

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

An object of this class manages production capacity and keeps track of over/under stock.

The main task of this class is to keep track of the available and used production capacity. That knowledge is used to figure out how much of the settlement's production capacity is being exported and the relevant data is saved accordingly.

The other important task of this class is to keep track of how much resources the settlement should have in inventory and how much it actually has. That data is used by this class to make buy/sell decisions in this settlement, by InternationalTradeManager to decide which resources to buy/sell at other players' warehouses and by SpecialDomesticTradeManager to decide which resources to transfer between the player's settlements in order to make best use of them.

Currently the quota priority system works by assigning local requests a high priority and the export requests a low priority which should minimize the amount of resources that have to be transferred.

The division of resources and production capacities is purely logical and does not affect the way the actual game works.

Instance Methods [hide private]
 
__init__(self, settlement_manager) source code
 
__init(self, settlement_manager) source code
 
save(self, db) source code
 
_load(self, db, settlement_manager) source code
 
_get_chain(self, resource_id, resource_producer, production_ratio)
Return a SimpleProductionChainSubtreeChoice or None if it impossible to produce the resource.
source code
 
_make_chain(self, resource_id)
Return a SimpleProductionChainSubtreeChoice that knows how to produce the resource.
source code
 
refresh(self)
Refresh the actual production capacity of the buildings and lower quotas if necessary.
source code
 
request_quota_change(self, quota_holder, priority, resource_id, building_id, amount)
Request that the quota of quota_holder be changed to the given amount for the specific resource/building pair.
source code
 
get_quota(self, quota_holder, resource_id, building_id)
Return the current quota given the resource and the type of building that should produce it.
source code
 
request_deep_quota_change(self, quota_holder, priority, resource_id, amount)
Request that the quota of quota_holder be changed to the given amount recursively.
source code
 
get_deep_quota(self, quota_holder, resource_id)
Return the current quota at the bottleneck.
source code
 
replay_deep_low_priority_requests(self)
Retry adding low priority quota requests.
source code
 
record_expected_exportable_production(self, ticks)
Record the amount of production that should be transferred to other islands.
source code
 
get_total_export(self, resource_id)
Return the total amount of the given resource being (logically) exported per tick.
source code
 
get_total_trade_storage(self, resource_id)
Return the amount of the given resource that should be kept aside for other settlements.
source code
 
get_default_resource_requirement(self, resource_id)
Return the default amount of resource that should be in the settlement inventory.
source code
 
get_unit_building_costs(self, resource_id) source code
 
get_required_upgrade_resources(self, resource_id, upgrade_limit)
Return the amount of resource still needed to upgrade at most upgrade_limit residences.
source code
 
get_required_building_resources(self, resource_id) source code
 
get_current_resource_requirement(self, resource_id)
Return the amount of resource that should be in the settlement inventory to provide for all needs.
source code
 
manager_buysell(self)
Calculate the required inventory levels and make buy/sell decisions based on that.
source code
 
finish_tick(self)
Clear data used during a single tick.
source code
 
__str__(self) 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]
 
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]
    Inherited from util.worldobject.WorldObject
  log = logging.getLogger("util.worldobject")
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(cls, db, settlement_manager)
Class Method

source code 
Overrides: util.changelistener.ChangeListener.load

request_quota_change(self, quota_holder, priority, resource_id, building_id, amount)

source code 

Request that the quota of quota_holder be changed to the given amount for the specific resource/building pair.

Parameters:
  • quota_holder - a string identifying the quota holder (persistent over save/load cycles)
  • priority - boolean showing whether this quota has high priority (high priority means that low priority quotas can be lowered if necessary)
  • resource_id - the required resource
  • building_id - the type of building where this capacity should be gotten from
  • amount - the amount of resource per tick that is needed

replay_deep_low_priority_requests(self)

source code 

Retry adding low priority quota requests. This is required to make the feeder island mechanism work.