本文整理匯總了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