本文整理汇总了Python中horizons.world.diplomacy.Diplomacy.are_allies方法的典型用法代码示例。如果您正苦于以下问题:Python Diplomacy.are_allies方法的具体用法?Python Diplomacy.are_allies怎么用?Python Diplomacy.are_allies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.world.diplomacy.Diplomacy
的用法示例。
在下文中一共展示了Diplomacy.are_allies方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from horizons.world.diplomacy import Diplomacy [as 别名]
# 或者: from horizons.world.diplomacy.Diplomacy import are_allies [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):
islands.add(island)
break
return islands
def get_warehouses(self, position=None, radius=None, owner=None, include_allied=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_allied also list the warehouses belonging to allies
@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_allied and self.diplomacy.are_allies(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)
ships = []
for ship in self.ships:
if circle.contains(ship.position):
ships.append(ship)
return ships
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)
units = []
for unit in self.ground_units:
if circle.contains(unit.position):
units.append(unit)
return units
else:
return self.ground_units
示例2: World
# 需要导入模块: from horizons.world.diplomacy import Diplomacy [as 别名]
# 或者: from horizons.world.diplomacy.Diplomacy import are_allies [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):
islands.add(island)
break
return islands
def get_warehouses(self, position=None, radius=None, owner=None, include_allied=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_allied also list the warehouses belonging to allies
@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_allied and self.diplomacy.are_allies(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)
ships = []
for ship in self.ships:
if circle.contains(ship.position):
ships.append(ship)
return ships
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)
units = []
for unit in self.ground_units:
if circle.contains(unit.position):
units.append(unit)
return units
else:
return self.ground_units