本文整理汇总了Python中horizons.ai.trader.Trader.create_ship方法的典型用法代码示例。如果您正苦于以下问题:Python Trader.create_ship方法的具体用法?Python Trader.create_ship怎么用?Python Trader.create_ship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.ai.trader.Trader
的用法示例。
在下文中一共展示了Trader.create_ship方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from horizons.ai.trader import Trader [as 别名]
# 或者: from horizons.ai.trader.Trader import create_ship [as 别名]
#.........这里部分代码省略.........
os.unlink(island_db_path) # the process relies on having an empty file
db('INSERT INTO island (x, y, file) VALUES(?, ?, ?)', island.origin.x, island.origin.y, 'content/islands/' + island_name)
island_db = DbReader(island_db_path)
island.save_map(island_db)
island_db.close()
db('COMMIT')
db.close()
def get_checkup_hash(self):
dict = {
'rngvalue': self.session.random.random(),
'settlements': [],
'ships': [],
}
for island in self.islands:
for settlement in island.settlements:
entry = {
'owner': str(settlement.owner.worldid),
'tax_settings': str(settlement.tax_settings),
'inhabitants': str(settlement.inhabitants),
'cumulative_running_costs': str(settlement.cumulative_running_costs),
'cumulative_taxes': str(settlement.cumulative_taxes),
'inventory': str(settlement.get_component(StorageComponent).inventory._storage),
}
dict['settlements'].append(entry)
for ship in self.ships:
entry = {
'owner': str(ship.owner.worldid),
'position': ship.position.to_tuple(),
}
dict['ships'].append(entry)
return dict
def notify_new_settlement(self):
"""Called when a new settlement is created"""
# make sure there's a trader ship for 2 settlements
if self.trader and len(self.settlements) > self.trader.get_ship_count() * 2:
self.trader.create_ship()
def toggle_owner_highlight(self):
renderer = self.session.view.renderer['InstanceRenderer']
self.owner_highlight_active = not self.owner_highlight_active
if self.owner_highlight_active: #show
for player in self.players:
red = player.color.r
green = player.color.g
blue = player.color.b
for settlement in player.settlements:
for tile in settlement.ground_map.itervalues():
renderer.addColored(tile._instance, red, green, blue)
else: # 'hide' functionality
renderer.removeAllColored()
def toggle_translucency(self):
"""Make certain building types translucent"""
if not hasattr(self, "_translucent_buildings"):
self._translucent_buildings = set()
if not self._translucent_buildings: # no translucent buildings saved => enable
building_types = self.session.db.get_translucent_buildings()
add = self._translucent_buildings.add
from weakref import ref as create_weakref
def get_all_buildings(world):
for island in world.islands:
for b in island.buildings:
yield b
for s in island.settlements:
for b in s.buildings:
yield b
for b in get_all_buildings(self):
if b.id in building_types:
fife_instance = b._instance
add( create_weakref(fife_instance) )
fife_instance.keep_translucency = True
fife_instance.get2dGfxVisual().setTransparency( BUILDINGS.TRANSPARENCY_VALUE )
else: # undo translucency
for inst in self._translucent_buildings:
try:
inst().get2dGfxVisual().setTransparency( 0 )
inst().keep_translucency = False
except AttributeError:
pass # obj has been deleted, inst() returned None
self._translucent_buildings.clear()
def toggle_health_for_all_health_instances(self):
"""Show health bar of every instance with an health component, which isnt selected already"""
self.health_visible_for_all_health_instances = not self.health_visible_for_all_health_instances
if self.health_visible_for_all_health_instances:
for instance in self.session.world.get_health_instances():
if not instance.get_component(SelectableComponent).selected:
instance.draw_health()
self.session.view.add_change_listener(instance.draw_health)
else:
for instance in self.session.world.get_health_instances():
if self.session.view.has_change_listener(instance.draw_health) and not instance.get_component(SelectableComponent).selected:
instance.draw_health(remove_only=True)
self.session.view.remove_change_listener(instance.draw_health)
示例2: World
# 需要导入模块: from horizons.ai.trader import Trader [as 别名]
# 或者: from horizons.ai.trader.Trader import create_ship [as 别名]
#.........这里部分代码省略.........
# this optimisation pays of if water tiles are frequently queried
return None
for island in self.islands:
if tup in island.ground_map:
return island
return None
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
@decorators.make_constants()
def get_branch_offices(self, position=None, radius=None, owner=None):
"""Returns all branch offices 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 branch offices belonging to this player.
@return: List of branch offices.
"""
branchoffices = []
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 self.islands:
for settlement in island.settlements:
bo = settlement.branch_office
if (radius is None or position is None or \
bo.position.distance(position) <= radius) and \
(owner is None or bo.owner == owner):
branchoffices.append(bo)
return branchoffices
@decorators.make_constants()
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 save(self, db):
"""Saves the current game to the specified db.
@param db: DbReader object of the db the game is saved to."""
super(World, self).save(db)
for name, value in self.properties.iteritems():
db("INSERT INTO map_properties (name, value) VALUES (?, ?)", name, value)
for island in self.islands:
island.save(db)
for player in self.players:
player.save(db)
if self.trader is not None:
self.trader.save(db)
if self.pirate is not None:
self.pirate.save(db)
for ship in self.ships:
ship.save(db)
def get_checkup_hash(self):
dict = {
'rngvalue': self.session.random.random(),
'settlements': [],
}
for island in self.islands:
for settlement in island.settlements:
entry = {
'owner': str(settlement.owner.worldid),
'tax_settings': str(settlement.tax_setting),
'inhabitants': str(settlement.inhabitants),
'cumulative_running_costs': str(settlement.cumulative_running_costs),
'cumulative_taxes': str(settlement.cumulative_taxes),
'inventory' : str(settlement.inventory._storage),
}
dict['settlements'].append(entry)
return dict
def notify_new_settlement(self):
"""Called when a new settlement is created"""
# make sure there's a trader ship for 2 settlements
if len(self.settlements) > self.trader.get_ship_count() * 2:
self.trader.create_ship()
示例3: World
# 需要导入模块: from horizons.ai.trader import Trader [as 别名]
# 或者: from horizons.ai.trader.Trader import create_ship [as 别名]
#.........这里部分代码省略.........
for s in island.settlements:
for b in s.buildings:
yield b
def get_health_instances(self, position=None, radius=None):
"""Returns all instances that have health"""
instances = []
for instance in self.get_ships(position, radius)+\
self.get_ground_units(position, radius):
if instance.has_component(HealthComponent):
instances.append(instance)
return instances
def save(self, db):
"""Saves the current game to the specified db.
@param db: DbReader object of the db the game is saved to."""
super(World, self).save(db)
for name, value in self.properties.iteritems():
db("INSERT INTO map_properties (name, value) VALUES (?, ?)", name, value)
for island in self.islands:
island.save(db)
for player in self.players:
player.save(db)
if self.trader is not None:
self.trader.save(db)
if self.pirate is not None:
self.pirate.save(db)
for ship in self.ships:
ship.save(db)
for ground_unit in self.ground_units:
ground_unit.save(db)
for bullet in self.bullets:
bullet.save(db)
self.diplomacy.save(db)
Weapon.save_attacks(db)
self.disaster_manager.save(db)
def save_map(self, path, prefix):
"""Save the current map as map file + island files"""
worldutils.save_map(self, path, prefix)
def get_checkup_hash(self):
"""Returns a collection of important game state values. Used to check if two mp games have diverged.
Not designed to be reliable."""
# NOTE: don't include float values, they are represented differently in python 2.6 and 2.7
# and will differ at some insignificant place. Also make sure to handle them correctly in the game logic.
data = {
'rngvalue': self.session.random.random(),
'settlements': [],
'ships': [],
}
for island in self.islands:
# dicts usually aren't hashable, this makes them
# since defaultdicts appear, we discard values that can be autogenerated
# (those are assumed to default to something evaluating False)
dict_hash = lambda d : sorted( i for i in d.iteritems() if i[1] )
for settlement in island.settlements:
storage_dict =settlement.get_component(StorageComponent).inventory._storage
entry = {
'owner': str(settlement.owner.worldid),
'inhabitants': str(settlement.inhabitants),
'cumulative_running_costs': str(settlement.cumulative_running_costs),
'cumulative_taxes': str(settlement.cumulative_taxes),
'inventory': str( dict_hash(storage_dict) )
}
data['settlements'].append(entry)
for ship in self.ships:
entry = {
'owner': str(ship.owner.worldid),
'position': ship.position.to_tuple(),
}
data['ships'].append(entry)
return data
def notify_new_settlement(self):
"""Called when a new settlement is created"""
# make sure there's a trader ship for 2 settlements
if self.trader and len(self.settlements) > self.trader.get_ship_count() * 2:
self.trader.create_ship()
def toggle_owner_highlight(self):
renderer = self.session.view.renderer['InstanceRenderer']
self.owner_highlight_active = not self.owner_highlight_active
if self.owner_highlight_active: #show
for player in self.players:
red = player.color.r
green = player.color.g
blue = player.color.b
for settlement in player.settlements:
for tile in settlement.ground_map.itervalues():
renderer.addColored(tile._instance, red, green, blue)
else: # 'hide' functionality
renderer.removeAllColored()
def toggle_translucency(self):
"""Make certain building types translucent"""
worldutils.toggle_translucency(self)
def toggle_health_for_all_health_instances(self):
worldutils.toggle_health_for_all_health_instances(self)