Package horizons :: Package ai :: Module trader :: Class Trader
[hide private]
[frames] | no frames]

Class Trader

source code

component.componentholder.ComponentHolder --+        
                                            |        
   util.changelistener.ChangeListener --+   |        
                                        |   |        
             util.worldobject.WorldObject --+        
                                            |        
                          world.player.Player --+    
                                                |    
                                generic.GenericAI --+
                                                    |
                                                   Trader

A trader represents the free trader that travels around the map with its trading ship(s) and sells resources to players and buys resources from them. This is a very simple form of AI, as it doesn't do any more then drive to a place on water or a warehouse randomly and then buys and sells resources. A game should not have more then one free trader (it could though)

Instance Methods [hide private]
 
__init__(self, session, id, name, color, **kwargs) source code
 
create_ship(self)
Create a ship and place it randomly
source code
 
__init(self) source code
 
_on_new_settlement(self, msg) source code
 
save(self, db) source code
 
_load(self, db, worldid)
This function makes it possible to load playerdata into an already allocated Player instance, which is used e.g.
source code
 
load_ship_states(self, db) source code
 
get_ship_count(self)
Returns number of ships
source code
 
send_ship_random(self, ship)
Sends a ship to a random position on the map.
source code
 
_check_for_signal_fire_in_ship_range(self, ship)
Returns the signal fire instance, if there is one in the ships range, else False
source code
 
_ship_found_signal_fire(self, ship) source code
 
send_ship_random_warehouse(self, ship, warehouse=None)
Sends a ship to a random warehouse on the map
source code
 
is_warehouse_safe(self, warehouse)
Checkes whether a warehouse is safe to visit
source code
 
reached_warehouse(self, ship)
Actions that need to be taken when reaching a warehouse: Sell demanded res, buy offered res, simulate load/unload, continue route.
source code
 
ship_idle(self, ship)
Called if a ship is idle.
source code
 
end(self) source code
    Inherited from generic.GenericAI
 
send_ship(self, ship) source code
    Inherited from world.player.Player
 
get_balance_estimation(self)
This takes a while to calculate, so only do it every 2 seconds at most
source code
 
get_latest_stats(self) source code
 
get_statistics(self)
Returns a namedtuple containing player-wide statistics
source code
 
initialize(self, inventory)
Has to be called every time a componentholder is created.
source code
 
is_local_player(self) source code
 
notify_settler_reached_level(self, message)
Settler calls this to notify the player.
source code
 
settlements(self)
Calculate settlements dynamically to save having a redundant list here
source code
    Inherited from component.componentholder.ComponentHolder
 
add_component(self, component)
Adds new component to holder and sets the instance attribute on the component
source code
 
get_component(self, component) source code
 
get_component_by_name(self, name) source code
 
has_component(self, component_class)
Check if holder has component with component name
source code
 
remove(self) source code
 
remove_component(self, component_class)
Removes component from holder.
source code
    Inherited from util.worldobject.WorldObject
 
__lt__(self, other) 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
 
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 world.player.Player
 
load(cls, session, db, worldid) source code
    Inherited from component.componentholder.ComponentHolder
 
get_component_template(cls, component)
Returns the component template data given a component NAME
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]
  shipStates = Enum.get_extended(GenericAI.shipStates, 'moving_t...
  log = logging.getLogger("ai.trader")
  regular_player = False
    Inherited from world.player.Player
  STATS_UPDATE_INTERVAL = 3
  component_templates = {'StorageComponent': {'PositiveStorage':...
    Inherited from component.componentholder.ComponentHolder
  class_mapping = {'AmbientSoundComponent': AmbientSoundComponen...
Method Details [hide private]

__init__(self, session, id, name, color, **kwargs)
(Constructor)

source code 
Parameters:
  • id - int - player id, every Player needs a unique id, as the free trader is a Player instance, it also does.
  • name - Traders name, also needed for the Player class.
  • color - util.Color instance with the traders banner color, also needed for the Player class
Overrides: util.changelistener.ChangeListener.__init__

save(self, db)

source code 
Overrides: util.worldobject.WorldObject.save

_load(self, db, worldid)

source code 

This function makes it possible to load playerdata into an already allocated Player instance, which is used e.g. in Trader.load

Overrides: world.player.Player._load
(inherited documentation)

send_ship_random(self, ship)

source code 

Sends a ship to a random position on the map.

Parameters:
  • ship - Ship instance that is to be used
Overrides: generic.GenericAI.send_ship_random

send_ship_random_warehouse(self, ship, warehouse=None)

source code 

Sends a ship to a random warehouse on the map

Parameters:
  • ship - Ship instance that is to be used
  • warehouse - warehouse instance to move to. Random one is selected on None.

reached_warehouse(self, ship)

source code 

Actions that need to be taken when reaching a warehouse: Sell demanded res, buy offered res, simulate load/unload, continue route.

Parameters:
  • ship - ship instance

ship_idle(self, ship)

source code 

Called if a ship is idle. Sends ship to either a random place or warehouse. Probability for 'random warehouse' in percent: TRADER.BUSINESS_SENSE.

Parameters:
  • ship - ship instance
Overrides: generic.GenericAI.ship_idle

end(self)

source code 
Overrides: util.changelistener.ChangeListener.end

Class Variable Details [hide private]

shipStates

Value:
Enum.get_extended(GenericAI.shipStates, 'moving_to_warehouse', 'reache\
d_warehouse')