本文整理汇总了Python中horizons.world.traderoute.TradeRoute.disable方法的典型用法代码示例。如果您正苦于以下问题:Python TradeRoute.disable方法的具体用法?Python TradeRoute.disable怎么用?Python TradeRoute.disable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.world.traderoute.TradeRoute
的用法示例。
在下文中一共展示了TradeRoute.disable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ship
# 需要导入模块: from horizons.world.traderoute import TradeRoute [as 别名]
# 或者: from horizons.world.traderoute.TradeRoute import disable [as 别名]
class Ship(Unit):
"""Class representing a ship
@param x: int x position
@param y: int y position
"""
pather_class = ShipPather
health_bar_y = -150
is_ship = True
in_ship_map = True # (#1023)
def __init__(self, x, y, **kwargs):
super(Ship, self).__init__(x=x, y=y, **kwargs)
self.__init()
def save(self, db):
super(Ship, self).save(db)
if hasattr(self, 'route'):
self.route.save(db)
def load(self, db, worldid):
super(Ship, self).load(db, worldid)
self.__init()
# if ship did not have route configured, do not add attribute
if TradeRoute.has_route(db, worldid):
self.create_route()
self.route.load(db)
def __init(self):
# register ship in world
self.session.world.ships.append(self)
if self.in_ship_map:
self.session.world.ship_map[self.position.to_tuple()] = weakref.ref(self)
def set_name(self, name):
self.get_component(ShipNameComponent).set_name(name)
def remove(self):
self.session.world.ships.remove(self)
if self.session.view.has_change_listener(self.draw_health):
self.session.view.remove_change_listener(self.draw_health)
if self.in_ship_map:
del self.session.world.ship_map[self.position.to_tuple()]
if self._next_target.to_tuple() in self.session.world.ship_map:
del self.session.world.ship_map[self._next_target.to_tuple()]
self.in_ship_map = False
super(Ship, self).remove()
def create_route(self):
self.route = TradeRoute(self)
def _move_tick(self, resume = False):
"""Keeps track of the ship's position in the global ship_map"""
if self.in_ship_map:
del self.session.world.ship_map[self.position.to_tuple()]
try:
super(Ship, self)._move_tick(resume)
except PathBlockedError:
# if we fail to resume movement then the ship should still be on the map but the exception has to be raised again.
if resume:
if self.in_ship_map:
self.session.world.ship_map[self.position.to_tuple()] = weakref.ref(self)
raise
if self.in_ship_map:
# save current and next position for ship, since it will be between them
self.session.world.ship_map[self.position.to_tuple()] = weakref.ref(self)
self.session.world.ship_map[self._next_target.to_tuple()] = weakref.ref(self)
def _movement_finished(self):
if self.in_ship_map:
# if the movement somehow stops, the position sticks, and the unit isn't at next_target any more
if self._next_target is not None:
ship = self.session.world.ship_map.get(self._next_target.to_tuple())
if ship is not None and ship() is self:
del self.session.world.ship_map[self._next_target.to_tuple()]
super(Ship, self)._movement_finished()
def go(self, x, y):
#disable the trading route
if hasattr(self, 'route'):
self.route.disable()
if self.get_component(CommandableComponent).go(x, y) is None:
self._update_buoy()
def move(self, *args, **kwargs):
super(Ship, self).move(*args, **kwargs)
if self.has_component(SelectableComponent) and \
self.get_component(SelectableComponent).selected and \
self.owner.is_local_player: # handle buoy
# if move() is called as move_callback, tmp() from above might
# be executed after this, so draw the new buoy after move_callbacks have finished.
Scheduler().add_new_object(self._update_buoy, self, run_in=0)
def _update_buoy(self, remove_only=False):
"""Draw a buoy at the move target if the ship is moving."""
if self.owner is None or not self.owner.is_local_player:
return
#.........这里部分代码省略.........