Package horizons :: Package world :: Package units :: Package collectors :: Module collector :: Class Collector
[hide private]
[frames] | no frames]

Class Collector

source code

 component.componentholder.ComponentHolder --+        
                                             |        
util.changelistener.ChangeListener --+       |        
                                     |       |        
          util.worldobject.WorldObject --+   |        
                                         |   |        
             concreteobject.ConcreteObject --+        
                                             |        
                     movingobject.MovingObject --+    
                                                 |    
       resourcehandler.ResourceTransferHandler --+    
                                                 |    
                                         unit.Unit --+
                                                     |
                                                    Collector

Base class for every collector. Does not depend on any home building.

Timeline:
 * search_job
 * * get_job
 * * handle_no_possible_job
 * * begin_current_job
 * * * setup_new_job
 * * * move to target
 on arrival there:
 * begin_working
 after some pretended working:
 * finish_working
 * * transfer_res
 after subclass has done actions to finish job:
 * end_job

Instance Methods [hide private]
 
__init__(self, x, y, slots=1, start_hidden=True, **kwargs) source code
 
__init(self, state, start_hidden) source code
 
remove(self)
Removes the instance.
source code
 
_abort_collector_job(self) source code
 
save(self, db) source code
 
load(self, db, worldid) source code
 
apply_state(self, state, remaining_ticks=None)
Takes actions to set collector to a state.
source code
 
get_home_inventory(self)
Returns inventory where collected res will be stored.
source code
 
get_colleague_collectors(self)
Returns a list of collectors, that work for the same "inventory".
source code
 
get_collectable_res(self)
Return all resources the collector can collect
source code
 
get_job(self)
Returns the next job or None
source code
 
search_job(self)
Search for a job, only called if the collector does not have a job.
source code
 
handle_no_possible_job(self)
Called when we can't find a job.
source code
 
setup_new_job(self)
Executes the necessary actions to begin a new job
source code
 
check_possible_job_target(self, target)
Checks if we "are allowed" and able to pick up from the target
source code
 
check_possible_job_target_for(self, target, res)
Checks out if we could get res from target.
source code
 
get_best_possible_job(self, jobs)
Return best possible job from jobs.
source code
 
begin_current_job(self, job_location=None)
Starts executing the current job by registering itself and moving to target.
source code
 
resume_movement(self)
Try to resume movement after getting blocked.
source code
 
handle_path_to_job_blocked(self)
Called when we get blocked while trying to move to the job location.
source code
 
begin_working(self)
Pretends that the collector works by waiting some time.
source code
 
finish_working(self)
Called when collector has stayed at the target for a while.
source code
 
transfer_res_from_target(self)
Transfers resources from target to collector inventory
source code
 
transfer_res_to_home(self, res, amount)
Transfer resources from collector to the home inventory
source code
 
end_job(self)
Contrary to setup_new_job
source code
 
cancel(self, continue_action)
Aborts the current job.
source code
 
__str__(self) source code
    Inherited from unit.Unit
 
_on_damage(self, caller=None)
Called when health has changed
source code
 
classname(self) source code
 
draw_health(self, remove_only=False, auto_remove=False)
Draws the units current health as a healthbar over the unit.
source code
 
get_random_location(self, in_range)
Returns a random location in walking_range, that we can find a path to Does not check every point, only a few samples are tried.
source code
 
go(self, x, y) source code
 
hide(self)
Hides the unit.
source code
 
onInstanceActionCancelled(self, instance, action) source code
 
onInstanceActionFinished(self, instance, action) source code
 
show(self) source code
    Inherited from movingobject.MovingObject
 
_move_tick(self, resume=False)
Called by the scheduler, moves the unit one step for this tick.
source code
 
_movement_finished(self) source code
 
_setup_move(self, action='move')
Executes necessary steps to begin a movement.
source code
 
add_blocked_callback(self, blocked_callback)
Registers callback to be executed when movement of the unit gets blocked.
source code
 
add_conditional_callback(self, condition, callback)
Adds a callback, that gets called, if, at any time of the movement, the condition becomes True.
source code
 
add_move_callback(self, callback)
Registers callback to be executed when movement of unit finishes.
source code
 
check_move(self, destination)
Tries to find a path to destination
source code
 
get_move_target(self) source code
 
get_unit_velocity(self)
Returns the number of ticks that it takes to do a straight (i.e.
source code
 
is_moving(self)
Returns whether unit is currently moving
source code
 
move(self, destination, callback=None, destination_in_building=False, action='move', blocked_callback=None, path=None)
Moves unit to destination
source code
 
stop(self, callback=None)
Stops a unit with currently no possibility to continue the movement.
source code
 
teleport(self, destination, callback=None, destination_in_building=False)
Like move, but nearly instantaneous
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
 
initialize(self, **kwargs)
Has to be called every time a componentholder is created.
source code
 
remove_component(self, component_class)
Removes component from holder.
source code
    Inherited from concreteobject.ConcreteObject
 
act(self, action, facing_loc=None, repeating=False, force_restart=True) source code
 
fife_instance(self) source code
 
has_action(self, action)
Checks if this unit has a certain action.
source code
 
name(self) 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
 
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
    Inherited from resourcehandler.ResourceTransferHandler
 
transfer_to_storageholder(self, amount, res_id, transfer_to, signal_errors=False)
Transfers amount of res_id to transfer_to.
source code
Class Methods [hide private]
    Inherited from component.componentholder.ComponentHolder
 
get_component_template(cls, component)
Returns the component template data given a component NAME
source code
    Inherited from concreteobject.ConcreteObject
 
get_random_action_set(cls, level=0, exact_level=False)
Returns an action set for an object of type object_id in a level <= the specified level.
source code
 
weighted_choice(cls, weighted_dict)
http://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/
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("world.units.collector")
  work_duration = 16
  destination_always_in_building = False
  states = Enum('idle', 'moving_to_target', 'working', 'moving_h...
    Inherited from unit.Unit
  AUTOMATIC_HEALTH_DISPLAY_TIMEOUT = 10
  health_bar_y = -30
  is_ship = False
  is_unit = True
    Inherited from movingobject.MovingObject
  movable = True
  pather_class = None
hash(x)
    Inherited from component.componentholder.ComponentHolder
  class_mapping = {'AmbientSoundComponent': AmbientSoundComponen...
    Inherited from concreteobject.ConcreteObject
  is_building = False
Method Details [hide private]

__init__(self, x, y, slots=1, start_hidden=True, **kwargs)
(Constructor)

source code 
Parameters:
  • session - Session instance this obj belongs to
Overrides: util.changelistener.ChangeListener.__init__

remove(self)

source code 

Removes the instance. Useful when the home building is destroyed

Overrides: util.changelistener.ChangeListener.remove

save(self, db)

source code 
Overrides: util.worldobject.WorldObject.save

load(self, db, worldid)

source code 
Overrides: util.changelistener.ChangeListener.load

apply_state(self, state, remaining_ticks=None)

source code 

Takes actions to set collector to a state. Useful after loading.

Parameters:
  • state - EnumValue from states
  • remaining_ticks - ticks after which current state is finished

get_home_inventory(self)

source code 

Returns inventory where collected res will be stored. This could be the inventory of a home_building, or it's own.

search_job(self)

source code 

Search for a job, only called if the collector does not have a job. If no job is found, a new search will be scheduled in a few ticks.

handle_no_possible_job(self)

source code 

Called when we can't find a job. default is to wait and try again in a few secs

check_possible_job_target_for(self, target, res)

source code 

Checks out if we could get res from target. Does _not_ check for anything else (e.g. if we are able to walk there).

Parameters:
  • target - possible target. buildings are supported, support for more can be added.
  • res - resource id
Returns:
instance of Job or None, if we can't collect anything

get_best_possible_job(self, jobs)

source code 

Return best possible job from jobs. "Best" means that the job is highest when the job list was sorted. "Possible" means that we can find a path there.

Parameters:
  • jobs - unsorted JobList instance
Returns:
selected Job instance from list or None if no jobs are possible.

begin_current_job(self, job_location=None)

source code 

Starts executing the current job by registering itself and moving to target.

Parameters:
  • job_location - Where collector should work. default: job.object.loading_area

resume_movement(self)

source code 

Try to resume movement after getting blocked. If that fails then wait and try again.

handle_path_to_job_blocked(self)

source code 

Called when we get blocked while trying to move to the job location. The default action is to resume movement in a few seconds.

begin_working(self)

source code 

Pretends that the collector works by waiting some time. finish_working is called after that time.

finish_working(self)

source code 

Called when collector has stayed at the target for a while. Picks up the resources. Should be overridden to specify what the collector should do after this.

cancel(self, continue_action)

source code 
Aborts the current job.
@param continue_action: Callback, gets called after cancel. Specifies what collector
                        is supposed to do now.
NOTE: Subclasses set this to a proper action that makes the collector continue to work.
      If the collector is supposed to be remove, use a noop.

__str__(self)
(Informal representation operator)

source code 
Overrides: unit.Unit.__str__

Class Variable Details [hide private]

states

Value:
Enum('idle', 'moving_to_target', 'working', 'moving_home', 'waiting_fo\
r_animal_to_stop', 'waiting_for_herder', 'no_job_walking_randomly', 'n\
o_job_waiting', 'decommissioned',)