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

Class SingleResourceManager

source code

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

An object of this class keeps track of the production capacity of a single resource/building type pair of a settlement.

Instance Methods [hide private]
 
__init__(self, settlement_manager, resource_id, building_id) source code
 
__init(self, settlement_manager, resource_id, building_id) source code
 
save(self, db, resource_manager_id) source code
 
_load(self, db, settlement_manager, worldid) source code
 
_get_current_production(self)
Return the current amount of resource per tick being produced at buildings of this type.
source code
 
refresh(self)
Adjust the quotas to take into account the current production levels.
source code
 
get_quota(self, quota_holder)
Return the current quota of the given quota holder.
source code
 
request_quota_change(self, quota_holder, priority, amount)
Request that the quota of quota_holder be changed to the given amount.
source code
 
get_total_export(self)
Return the total amount of capacity that is reserved by quota holders in other settlements.
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, worldid) 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]
  epsilon = 1e-7
  virtual_resources = {RES.FISH, RES.RAW_CLAY, RES.RAW_IRON}
  virtual_production = 9999
    Inherited from util.worldobject.WorldObject
  log = logging.getLogger("util.worldobject")
Method Details [hide private]

__init__(self, settlement_manager, resource_id, building_id)
(Constructor)

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

save(self, db, resource_manager_id)

source code 
Overrides: util.worldobject.WorldObject.save

load(cls, db, settlement_manager, worldid)
Class Method

source code 
Overrides: util.changelistener.ChangeListener.load

request_quota_change(self, quota_holder, priority, amount)

source code 

Request that the quota of quota_holder be changed to the given amount.

The algorithm:
* if the new amount is less than before: set the new quota to the requested value
* else if there is enough spare capacity to raise the quota: do it
* else assign all the spare capacity
        * if this is a high priority request:
                * reduce the low priority quotas to get the maximum possible amount for this quota holder

@param quota_holder: a string identifying the quota holder (persistent over save/load cycles)
@param priority: boolean showing whether this quota has high priority (high priority means that low priority quotas can be lowered if necessary)
@param amount: the amount of resource per tick that is needed