Package horizons :: Package component :: Module tradepostcomponent :: Class TradePostComponent
[hide private]
[frames] | no frames]

Class TradePostComponent

source code

util.changelistener.ChangeListener --+
                                     |
                         Component --+
                                     |
                                    TradePostComponent

This Class has to be inherited by every class that wishes to use BuySellTab and trade with the free trader.

Instance Methods [hide private]
 
__init__(self)
Used for initialization code that does not require any other components.
source code
 
initialize(self)
This is called by the ComponentHolder after it set the instance.
source code
 
set_slot(self, slot_id, resource_id, selling, limit) source code
 
clear_slot(self, slot_id, trigger_changed) source code
 
get_free_slot(self, resource_id) source code
 
save(self, db)
Will do nothing, but will be always called in componentholder code, even if not implemented.
source code
 
load(self, db, worldid)
This does on load what __init() and initalize() together do on constructions at runtime.
source code
 
get_owner_inventory(self) source code
 
get_inventory(self) source code
 
buy(self, res, amount, price, player_id)
Buy from the free trader.
source code
 
sell(self, res, amount, price, player_id)
Sell to the free trader.
source code
 
sell_resource(self, ship_worldid, resource_id, amount, add_error_type=False, suppress_messages=False)
Attempt to sell the given amount of resource to the ship, returns the amount sold.
source code
 
buy_resource(self, ship_worldid, resource_id, amount, add_error_type=False, suppress_messages=False)
Attempt to buy the given amount of resource from the ship, return the amount bought
source code
 
sell_income(self)
Returns sell income of last month.
source code
 
buy_expenses(self)
Returns last months buy expenses.
source code
 
total_earnings(self)
Returns the entire earning of this settlement total_earnings = sell_income - buy_expenses
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(self) source code
 
remove_change_listener(self, listener) source code
 
remove_remove_listener(self, listener) source code
    Inherited from Component
 
__gt__(self, other) source code
 
__lt__(self, other) source code
 
session(self) source code
Class Methods [hide private]
    Inherited from Component
 
get_instance(cls, arguments=None)
This function is used to instantiate classes from yaml data.
source code
Class Variables [hide private]
  NAME = 'tradepostcomponent'
hash(x)
  yaml_tag = '!TradePostComponent'
    Inherited from util.changelistener.ChangeListener
  log = logging.getLogger('changelistener')
    Inherited from Component
  DEPENDENCIES = []
Method Details [hide private]

__init__(self)
(Constructor)

source code 

Used for initialization code that does not require any other components. This is always called first, on construction and on load.

Overrides: Component.__init__
(inherited documentation)

initialize(self)

source code 

This is called by the ComponentHolder after it set the instance. Use this to initialize any needed infrastructure. When this is called, it is guaranteed that all other components this one has a dependency on have been added, but initalize may not have been called on them, only __init__. It is only called after construction, not on load().

Overrides: Component.initialize
(inherited documentation)

save(self, db)

source code 

Will do nothing, but will be always called in componentholder code, even if not implemented.

Overrides: Component.save
(inherited documentation)

load(self, db, worldid)

source code 

This does on load what __init() and initalize() together do on constructions at runtime. Has to set up everything that is not setup in __init__(). Note that on loading __init__() is called with the data needed by the component through get_instance(), but initialize() is not, so any work needed for loading as well should be moved to a separate method and called here.

Overrides: Component.load
(inherited documentation)

buy(self, res, amount, price, player_id)

source code 

Buy from the free trader.

Parameters:
  • res
  • amount
  • price - cumulative price for whole amount of res
  • player_id - the worldid of the trade partner @return bool, whether we did buy it

sell(self, res, amount, price, player_id)

source code 

Sell to the free trader.

Parameters:
  • res
  • amount
  • price - cumulative price for whole amount of res
  • player_id - the worldid of the trade partner @return bool, whether we did sell it

sell_resource(self, ship_worldid, resource_id, amount, add_error_type=False, suppress_messages=False)

source code 

Attempt to sell the given amount of resource to the ship, returns the amount sold.

Parameters:
  • add_error_type - if True, return tuple where second item is ERROR_TYPE

buy_resource(self, ship_worldid, resource_id, amount, add_error_type=False, suppress_messages=False)

source code 

Attempt to buy the given amount of resource from the ship, return the amount bought

Parameters:
  • add_error_type - if True, return tuple where second item is ERROR_TYPE

sell_income(self)

source code 

Returns sell income of last month. Deletes older entries of the sell list.

Decorators:
  • @property

buy_expenses(self)

source code 

Returns last months buy expenses. Deletes older entries of the buy list.

Decorators:
  • @property

total_earnings(self)

source code 

Returns the entire earning of this settlement total_earnings = sell_income - buy_expenses

Decorators:
  • @property