本文整理汇总了Python中horizons.ai.aiplayer.behavior.BehaviorManager.save方法的典型用法代码示例。如果您正苦于以下问题:Python BehaviorManager.save方法的具体用法?Python BehaviorManager.save怎么用?Python BehaviorManager.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.ai.aiplayer.behavior.BehaviorManager
的用法示例。
在下文中一共展示了BehaviorManager.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AIPlayer
# 需要导入模块: from horizons.ai.aiplayer.behavior import BehaviorManager [as 别名]
# 或者: from horizons.ai.aiplayer.behavior.BehaviorManager import save [as 别名]
#.........这里部分代码省略.........
def start_mission(self, mission):
self.ships[mission.ship] = self.shipStates.on_a_mission
self.missions.add(mission)
mission.start()
def report_success(self, mission, msg):
if not self._enabled:
return
self.missions.remove(mission)
if mission.ship and mission.ship in self.ships:
self.ships[mission.ship] = self.shipStates.idle
if isinstance(mission, FoundSettlement):
settlement_manager = SettlementManager(self, mission.land_manager)
self.settlement_managers.append(settlement_manager)
self._settlement_manager_by_settlement_id[settlement_manager.settlement.worldid] = settlement_manager
self.add_building(settlement_manager.settlement.warehouse)
if settlement_manager.feeder_island:
self.need_feeder_island = False
elif isinstance(mission, PrepareFoundationShip):
self.settlement_founder.tick()
def report_failure(self, mission, msg):
if not self._enabled:
return
self.missions.remove(mission)
if mission.ship and mission.ship in self.ships:
self.ships[mission.ship] = self.shipStates.idle
if isinstance(mission, FoundSettlement):
del self.islands[mission.land_manager.island.worldid]
def save(self, db):
super(AIPlayer, self).save(db)
# save the player
db("UPDATE player SET client_id = 'AIPlayer' WHERE rowid = ?", self.worldid)
current_callback = Callback(self.tick)
calls = Scheduler().get_classinst_calls(self, current_callback)
assert len(calls) == 1, "got {0!s} calls for saving {1!s}: {2!s}".format(len(calls), current_callback, calls)
remaining_ticks = max(calls.values()[0], 1)
current_callback_long = Callback(self.tick_long)
calls = Scheduler().get_classinst_calls(self, current_callback_long)
assert len(calls) == 1, "got {0!s} calls for saving {1!s}: {2!s}".format(len(calls), current_callback_long, calls)
remaining_ticks_long = max(calls.values()[0], 1)
db("INSERT INTO ai_player(rowid, need_more_ships, need_more_combat_ships, need_feeder_island, remaining_ticks, remaining_ticks_long) VALUES(?, ?, ?, ?, ?, ?)",
self.worldid, self.need_more_ships, self.need_more_combat_ships, self.need_feeder_island, remaining_ticks, remaining_ticks_long)
# save the ships
for ship, state in self.ships.iteritems():
db("INSERT INTO ai_ship(rowid, owner, state) VALUES(?, ?, ?)", ship.worldid, self.worldid, state.index)
# save the land managers
for land_manager in self.islands.itervalues():
land_manager.save(db)
# save the settlement managers
for settlement_manager in self.settlement_managers:
settlement_manager.save(db)
# save the missions
for mission in self.missions:
示例2: Pirate
# 需要导入模块: from horizons.ai.aiplayer.behavior import BehaviorManager [as 别名]
# 或者: from horizons.ai.aiplayer.behavior.BehaviorManager import save [as 别名]
class Pirate(GenericAI):
"""A pirate ship moving randomly around. If another ship comes into the reach
of it, it will be followed for a short time."""
# TODO: Move on_a_mission to GenericAI
shipStates = Enum.get_extended(GenericAI.shipStates, 'on_a_mission', 'chasing_ship', 'going_home')
log = logging.getLogger("ai.pirate")
regular_player = False
caught_ship_radius = 5
home_radius = 2
ship_count = 1
tick_interval = 32
tick_long_interval = 128
def __init__(self, session, id, name, color, **kwargs):
super(Pirate, self).__init__(session, id, name, color, **kwargs)
# choose a random water tile on the coast and call it home
self.home_point = self.session.world.get_random_possible_coastal_ship_position()
# random sea tile if costal tile not found. Empty map?
if not self.home_point:
self.home_point = self.session.world.get_random_possible_ship_position()
self.log.debug("Pirate: home at (%d, %d), radius %d", self.home_point.x, self.home_point.y, self.home_radius)
self.__init()
# create a ship and place it randomly (temporary hack)
for i in xrange(self.ship_count):
self.create_ship_at_random_position()
Scheduler().add_new_object(Callback(self.tick), self, 1, -1, self.tick_interval)
Scheduler().add_new_object(Callback(self.tick_long), self, 1, -1, self.tick_long_interval)
def __init(self):
self.world = self.session.world
self.unit_manager = UnitManager(self)
self.combat_manager = PirateCombatManager(self)
self.strategy_manager = PirateStrategyManager(self)
self.behavior_manager = BehaviorManager(self)
@staticmethod
def get_nearest_player_ship(base_ship):
lowest_distance = None
nearest_ship = None
for ship in base_ship.find_nearby_ships():
if isinstance(ship, (PirateShip, TradeShip)) or not ship.has_component(SelectableComponent):
continue # don't attack these ships
distance = base_ship.position.distance(ship.position)
if lowest_distance is None or distance < lowest_distance:
lowest_distance = distance
nearest_ship = ship
return nearest_ship
def tick(self):
self.combat_manager.tick()
# Temporary function for pirates respawn
self.maintain_ship_count()
def tick_long(self):
self.strategy_manager.tick()
def get_random_profile(self, token):
return BehaviorProfileManager.get_random_pirate_profile(self, token)
def create_ship_at_random_position(self):
point = self.session.world.get_random_possible_ship_position()
ship = CreateUnit(self.worldid, UNITS.PIRATE_SHIP, point.x, point.y)(issuer=self.session.world.player)
self.ships[ship] = self.shipStates.idle
self.combat_manager.add_new_unit(ship)
def maintain_ship_count(self):
if len(self.ships.keys()) < self.ship_count:
self.create_ship_at_random_position()
def save(self, db):
super(Pirate, self).save(db)
db("UPDATE player SET is_pirate = 1 WHERE rowid = ?", self.worldid)
db("INSERT INTO pirate_home_point(x, y) VALUES(?, ?)", self.home_point.x, self.home_point.y)
current_callback = Callback(self.tick)
calls = Scheduler().get_classinst_calls(self, current_callback)
assert len(calls) == 1, "got %s calls for saving %s: %s" % (len(calls), current_callback, calls)
remaining_ticks = max(calls.values()[0], 1)
current_callback_long = Callback(self.tick_long)
calls = Scheduler().get_classinst_calls(self, current_callback_long)
assert len(calls) == 1, "got %s calls for saving %s: %s" % (len(calls), current_callback_long, calls)
remaining_ticks_long = max(calls.values()[0], 1)
db("INSERT INTO ai_pirate(rowid, remaining_ticks, remaining_ticks_long) VALUES(?, ?, ?)", self.worldid,
remaining_ticks, remaining_ticks_long)
for ship in self.ships:
ship_state = self.ships[ship]
db("INSERT INTO pirate_ships(rowid, state) VALUES(?, ?)",
ship.worldid, ship_state.index)
#.........这里部分代码省略.........