本文整理匯總了Python中horizons.world.diplomacy.Diplomacy.can_trade方法的典型用法代碼示例。如果您正苦於以下問題:Python Diplomacy.can_trade方法的具體用法?Python Diplomacy.can_trade怎麽用?Python Diplomacy.can_trade使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類horizons.world.diplomacy.Diplomacy
的用法示例。
在下文中一共展示了Diplomacy.can_trade方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: World
# 需要導入模塊: from horizons.world.diplomacy import Diplomacy [as 別名]
# 或者: from horizons.world.diplomacy.Diplomacy import can_trade [as 別名]
#.........這裏部分代碼省略.........
def get_islands_in_radius(self, point, radius):
"""Returns all islands in a certain radius around a point.
@return set of islands in radius"""
islands = set()
for island in self.islands:
for tile in island.get_surrounding_tiles(point, radius=radius,
include_corners=False):
islands.add(island)
break
return islands
def get_warehouses(self, position=None, radius=None, owner=None, include_tradeable=False):
"""Returns all warehouses on the map, optionally only those in range
around the specified position.
@param position: Point or Rect instance.
@param radius: int radius to use.
@param owner: Player instance, list only warehouses belonging to this player.
@param include_tradeable also list the warehouses the owner can trade with
@return: List of warehouses.
"""
warehouses = []
islands = []
if radius is not None and position is not None:
islands = self.get_islands_in_radius(position, radius)
else:
islands = self.islands
for island in islands:
for settlement in island.settlements:
warehouse = settlement.warehouse
if (radius is None or position is None or
warehouse.position.distance(position) <= radius) and \
(owner is None or warehouse.owner == owner or
(include_tradeable and self.diplomacy.can_trade(warehouse.owner, owner))):
warehouses.append(warehouse)
return warehouses
def get_ships(self, position=None, radius=None):
"""Returns all ships on the map, optionally only those in range
around the specified position.
@param position: Point or Rect instance.
@param radius: int radius to use.
@return: List of ships.
"""
if position is not None and radius is not None:
circle = Circle(position, radius)
return [ship for ship in self.ships if circle.contains(ship.position)]
else:
return self.ships
def get_ground_units(self, position=None, radius=None):
"""@see get_ships"""
if position is not None and radius is not None:
circle = Circle(position, radius)
return [unit for unit in self.ground_units if circle.contains(unit.position)]
else:
return self.ground_units
def get_buildings(self, position=None, radius=None):
"""@see get_ships"""
buildings = []
if position is not None and radius is not None:
circle = Circle(position, radius)
for island in self.islands:
for building in island.buildings:
if circle.contains(building.position.center):