Package horizons :: Package world :: Package units :: Module movingobject :: Class MovingObject
[hide private]
[frames] | no frames]

Class MovingObject

source code

 component.componentholder.ComponentHolder --+
                                             |
util.changelistener.ChangeListener --+       |
                                     |       |
          util.worldobject.WorldObject --+   |
                                         |   |
             concreteobject.ConcreteObject --+
                                             |
                                            MovingObject

This class provides moving functionality and is to be inherited by Unit.
Its purpose is to provide a cleaner division of the code.

It provides:
*attributes:
- position, last_position: Point
- path: Pather

*moving methods:
- move
- stop
- add_move_callback

*getters/checkers:
- check_move
- get_move_target
- is_moving

Instance Methods [hide private]
 
__init__(self, x, y, **kwargs) source code
 
__init(self, x, y) source code
 
check_move(self, destination)
Tries to find a path to destination
source code
 
is_moving(self)
Returns whether unit is currently moving
source code
 
stop(self, callback=None)
Stops a unit with currently no possibility to continue the movement.
source code
 
_setup_move(self, action='move')
Executes necessary steps to begin a movement.
source code
 
move(self, destination, callback=None, destination_in_building=False, action='move', blocked_callback=None, path=None)
Moves unit to destination
source code
 
_movement_finished(self) source code
 
_move_tick(self, resume=False)
Called by the scheduler, moves the unit one step for this tick.
source code
 
teleport(self, destination, callback=None, destination_in_building=False)
Like move, but nearly instantaneous
source code
 
add_move_callback(self, callback)
Registers callback to be executed when movement of unit finishes.
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
 
get_unit_velocity(self)
Returns the number of ticks that it takes to do a straight (i.e.
source code
 
get_move_target(self) source code
 
save(self, db) source code
 
load(self, db, worldid) 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(self) 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
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]
  movable = True
  log = logging.getLogger("world.units")
  pather_class = None
hash(x)
    Inherited from component.componentholder.ComponentHolder
  class_mapping = {'AmbientSoundComponent': AmbientSoundComponen...
    Inherited from concreteobject.ConcreteObject
  is_building = False
  is_unit = False
Method Details [hide private]

__init__(self, x, y, **kwargs)
(Constructor)

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

check_move(self, destination)

source code 

Tries to find a path to destination

Parameters:
  • destination - destination supported by pathfinding
Returns:
object that can be used in boolean expressions (the path in case there is one)

stop(self, callback=None)

source code 

Stops a unit with currently no possibility to continue the movement. The unit actually stops moving when current move (to the next coord) is finished.

Parameters:
  • callback - a parameter supported by WeakMethodList. is executed immediately if unit isn't moving

_setup_move(self, action='move')

source code 

Executes necessary steps to begin a movement. Currently only the action is set.

move(self, destination, callback=None, destination_in_building=False, action='move', blocked_callback=None, path=None)

source code 

Moves unit to destination

Parameters:
  • destination - Point or Rect
  • callback - a parameter supported by WeakMethodList. Gets called when unit arrives.
  • action - action as string to use for movement
  • blocked_callback - a parameter supported by WeakMethodList. Gets called when unit gets blocked.
  • path - a precalculated path (return value of FindPath()())

add_move_callback(self, callback)

source code 

Registers callback to be executed when movement of unit finishes. This has no effect if the unit isn't moving.

add_conditional_callback(self, condition, callback)

source code 

Adds a callback, that gets called, if, at any time of the movement, the condition becomes True. The condition is checked every move_tick. After calling the callback, it is removed.

get_unit_velocity(self)

source code 

Returns the number of ticks that it takes to do a straight (i.e. vertical or horizontal) or diagonal movement as a tuple in this order.

Returns:
(int, int)

save(self, db)

source code 
Overrides: util.worldobject.WorldObject.save

load(self, db, worldid)

source code 
Overrides: util.changelistener.ChangeListener.load