Package horizons :: Package ai :: Package aiplayer :: Package combat :: Module fleet :: Class Fleet
[hide private]
[frames] | no frames]

Class Fleet

source code

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

Fleet object is responsible for moving a group of ship around the map in an ordered manner, that is:
1. provide a single move callback for a fleet as a whole,
2. resolve self-blocks in a group of ships
3. resolve MoveNotPossible exceptions.

Instance Methods [hide private]
__init__(self, ships, destroy_callback=None) source code
__init(self, ships, destroy_callback=None) source code
save(self, db) source code
_load(self, worldid, owner, db, destroy_callback) source code
get_ships(self) source code
destroy(self) source code
_lost_ship(self, ship)
Used when fleet was on the move and one of the ships was killed during that.
source code
Returns Counter about how many ships are in state idle, moving, reached.
source code
Checks whether required ratio of ships reached the target.
source code
_ship_reached(self, ship)
Called when a single ship reaches destination.
source code
Called when whole fleet reaches destination.
source code
_move_ship(self, ship, destination, callback) source code
Destination circle size for movement calls that involve more than one ship.
source code
_retry_moving_blocked_ships(self) source code
move(self, destination, callback=None, ratio=1.0)
Move fleet to a destination.
source code
size(self) 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
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
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, worldid, owner, db, destroy_callback=None) 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.fleet")
  shipStates = Enum('idle', 'moving', 'blocked', 'reached')
  fleetStates = Enum('idle', 'moving')
Method Details [hide private]

__init__(self, ships, destroy_callback=None)

source code 
  • worldid - worldid to assign. Use None to get an autogenerated one.
Overrides: util.changelistener.ChangeListener.__init__

save(self, db)

source code 

load(cls, worldid, owner, db, destroy_callback=None)
Class Method

source code 
Overrides: util.changelistener.ChangeListener.load

_lost_ship(self, ship)

source code 

Used when fleet was on the move and one of the ships was killed during that. This way fleet has to check whether the target point was reached.

move(self, destination, callback=None, ratio=1.0)

source code 

Move fleet to a destination.

  • ratio - what percentage of ships has to reach destination in order for the move to be considered done: 0.0 - None (not really useful, executes the callback right away) 0.0001 - effectively ANY ship 1.0 - ALL of the ships 0.5 - at least half of the ships etc.