def test_diplo1(s, p): (p0, s0), (p1, s1) = setup_combat(s, UNITS.FRIGATE) assert health(s0) == max_health(s0) assert health(s1) == max_health(s1) # declare war AddEnemyPair(p0, p1).execute(s) # declare peace AddAllyPair(p0, p1).execute(s) s.run(seconds=60) assert health(s0) == max_health(s0) assert health(s1) == max_health(s1) # declare war AddEnemyPair(p0, p1).execute(s) # declare peace AddNeutralPair(p0, p1).execute(s) s.run(seconds=60) assert health(s0) == max_health(s0) assert health(s1) == max_health(s1) # declare war AddEnemyPair(p0, p1).execute(s) s.run(seconds=60) assert health(s0) != max_health(s0) assert health(s1) != max_health(s1)
def neutral_player(self, **environment): """ Start war with neutral player -make a SurpriseAttack if possible. -break diplomacy otherwise. """ idle_ships = environment['idle_ships'] enemy_player = environment['player'] # Nothing to do when AI or enemy don't have a settlement yet if not enemy_player.settlements or not self.owner.settlements: return None # Send a surprise attack if there are ships available, otherwise simply declare war if idle_ships: target_point = self.unit_manager.get_warehouse_area( enemy_player.settlements[0]) return_point = self.unit_manager.get_warehouse_area( self.owner.settlements[0], 15) mission = SurpriseAttack.create( self.owner.strategy_manager.report_success, self.owner.strategy_manager.report_failure, idle_ships, target_point, return_point, enemy_player) return mission else: AddEnemyPair(self.owner, enemy_player).execute(self.session)
def test_combat_save_load(): """ create a savegame with combat units and actual combat, then save/load it """ session, player = new_session() (p0, s0), (p1, s1) = setup_combat(session, UNITS.FRIGATE) s0_worldid, s1_worldid = s0.worldid, s1.worldid session.run(seconds=1) # saveload session = saveload(session) s0 = WorldObject.get_object_by_id(s0_worldid) s1 = WorldObject.get_object_by_id(s1_worldid) # fight AddEnemyPair(p0, p1).execute(session) Attack(s0, s1).execute(session) Attack(s1, s0).execute(session) session.run(seconds=20) # saveload session = saveload(session) assert one_dead(s0_worldid, s1_worldid) session.end()
def mousePressed(self, evt): if evt.getButton( ) == fife.MouseEvent.RIGHT and not evt.isConsumedByWidgets(): target_mapcoord = self.session.view.cam.toMapCoordinates( fife.ScreenPoint(evt.getX(), evt.getY()), False) target = self._get_attackable_instance(evt) if target: if not self.session.world.diplomacy.are_enemies( self.session.world.player, target.owner): AddEnemyPair(self.session.world.player, target.owner).execute(self.session) for i in self.session.selected_instances: if hasattr(i, 'attack'): Attack(i, target).execute(self.session) else: for i in self.session.selected_instances: if i.movable: Act(i, target_mapcoord.x, target_mapcoord.y).execute(self.session) evt.consume() else: self.deselect_at_end = False super().mousePressed(evt)
def add_enemy(self): """ Callback for setting enemy status between local player and tab's player """ AddEnemyPair(self.player, self.local_player).execute(self.player.session) # check the correct checkbox self.check_diplomacy_state()
def fighting_ships_in_sight(self, **environment): enemies = environment['enemies'] ship_group = environment['ship_group'] if not self.session.world.diplomacy.are_enemies(self.owner, enemies[0].owner): AddEnemyPair(self.owner, enemies[0].owner).execute(self.session) BehaviorComponent.log.info('Player:%s broke diplomacy with %s' % (self.owner.name, enemies[0].owner.name))
def break_diplomacy(self): self.state = self.missionStates.breaking_diplomacy self.log.debug( "Player %s, Mission %s, 2/4 breaking diplomacy with Player %s", self.owner.name, self.__class__.__name__, self.enemy_player.name) if not self.session.world.diplomacy.are_enemies( self.owner, self.enemy_player): AddEnemyPair(self.owner, self.enemy_player).execute(self.session) self.in_combat()
def pirate_ships_in_sight(self, **environment): """Breaks diplomacy and attacks pirates. """ enemies = environment['enemies'] ship_group = environment['ship_group'] power_balance = environment['power_balance'] if not self.session.world.diplomacy.are_enemies(self.owner, enemies[0].owner): AddEnemyPair(self.owner, enemies[0].owner).execute(self.session) BehaviorComponent.log.info('I feel urgent need to wipe out them pirates.')
def test_dying(s, p): """ Check if units actually are gone when they have died """ (p0, s0), (p1, s1) = setup_combat(s, UNITS.FRIGATE) AddEnemyPair(p0, p1).execute(s) Attack(s0, s1).execute(s) s.run(seconds=60) assert health(s0) < max_health(s0) assert health(s1) < max_health(s1) # it's not specified which one should lose assert one_dead(s0.worldid, s1.worldid)
def test_unfair(s, p): (p0, s0), (p1, s1) = setup_combat(s, UNITS.FRIGATE) # two against one s0_1 = CreateUnit(p0.worldid, UNITS.FRIGATE, 5, 5)(issuer=p0) AddEnemyPair(p0, p1).execute(s) Attack(s0, s1).execute(s) Attack(s0_1, s1).execute(s) s.run(seconds=60) assert health(s1) == 0 assert health(s0) > 0 assert health(s0_1) > 0
def test_combat_save_load(): """ create a savegame with combat units and actual combat, then save/load it """ session, player = new_session() (p0, s0), (p1, s1) = setup_combat(session, UNITS.FRIGATE) s0_worldid, s1_worldid = s0.worldid, s1.worldid session.run(seconds=1) # saveload fd, filename = tempfile.mkstemp() os.close(fd) assert session.save(savegamename=filename) session.end(keep_map=True) session = load_session(filename) s0 = WorldObject.get_object_by_id(s0_worldid) s1 = WorldObject.get_object_by_id(s1_worldid) # fight AddEnemyPair(p0, p1).execute(session) Attack(s0, s1).execute(session) Attack(s1, s0).execute(session) session.run(seconds=20) # saveload fd, filename = tempfile.mkstemp() os.close(fd) assert session.save(savegamename=filename) session.end(keep_map=True) session = load_session(filename) assert one_dead(s0_worldid, s1_worldid) session.end()
def test_diplo0(s, p): (p0, s0), (p1, s1) = setup_combat(s, UNITS.FRIGATE) Attack(s0, s1).execute(s) # attack without war s.run(seconds=60) assert health(s0) == max_health(s0) assert health(s1) == max_health(s1) # declare war AddEnemyPair(p0, p1).execute(s) s.run(seconds=60) assert health(s0) < max_health(s0) assert health(s1) < max_health(s1) # it's not specified which one should lose assert health(s0) == 0 or health(s1) == 0