Package horizons :: Package ai :: Package aiplayer :: Module trademanager :: Class TradeManager
[hide private]
[frames] | no frames]

Class TradeManager

source code

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


An object of this class manages the continuous domestic resource import process of one settlement.

This class keeps track of how much of each resource it is importing, what the purpose
of each import request is, and organizes the missions to transport the resources
from the producing settlements to the one it is managing.

The process for determining how much can be imported:
* find out how much of each resource every other settlement can export, reserve all of it
* run the settlement's production capacity reserve process which tries to use the local
        capacity as much as possible and if that isn't enough then ask this object for
        more: these requests get approved if we can import the required amount
* finalize the amount and source of the imported resources, release the remaining
        amount to let the trade managers of other settlements do their work

The process for actually getting the resources
For this example settlement A imports from settlement B
* TradeManager of A reserves production at the ResourceManager of B as described above
* ResourceManager of B keeps track of how much resources it is producing for A
* TradeManager of A sends a ship to B to pick up some resources (a DomesticTrade mission)
* the ship arrives at the warehouse of B and calls A's TradeManager.load_resources
        which loads the ship and adjusts the data of B's ResourceManager
* the ship arrives at the warehouse of A and unloads the resources

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
 
refresh(self)
Reserve the total remaining production in every other settlement and adjust quotas if necessary.
source code
 
finalize_requests(self)
Release the unnecessarily reserved production capacity and decide which settlements will be providing the resources.
source code
 
request_quota_change(self, quota_holder, resource_id, amount)
Request that the quota of quota_holder be changed to the given amount.
source code
 
get_quota(self, quota_holder, resource_id)
Return the current quota in units per tick.
source code
 
get_total_import(self, resource_id)
Return the total amount of the given resource imported per tick.
source code
 
load_resources(self, mission)
A ship we sent out to retrieve our resources has reached the source settlement so load the resources.
source code
 
_get_source_settlement_manager(self)
Return the settlement manager of the settlement from which we should pick up resources next or None if none are needed.
source code
 
organize_shipping(self)
Try to send another ship to retrieve resources from one of the settlements we import from.
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]
  log = logging.getLogger("ai.aiplayer.trademanager")
  legal_resources = [RES.FOOD, RES.TEXTILE, RES.LIQUOR, RES.BRIC...
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

Class Variable Details [hide private]

legal_resources

Value:
[RES.FOOD, RES.TEXTILE, RES.LIQUOR, RES.BRICKS, RES.TOBACCO_PRODUCTS, \
RES.SALT, RES.MEDICAL_HERBS]