Пример #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
    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()
Пример #2
0
    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)
Пример #3
0
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
Пример #4
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()
Пример #5
0
def test_noncombat_units(s, p):
    (p0, s0), (p1, s1) = setup_combat(s, UNITS.HUKER_SHIP)

    # healthy before
    assert health(s0) == max_health(s0)
    assert health(s1) == max_health(s1)

    assert len(s.world.ships) == 3  # trader also has a ship
    Attack(s0, s1).execute(s)

    s.run(seconds=60)

    # healthy after
    assert health(s0) == max_health(s0)
    assert health(s1) == max_health(s1)
Пример #6
0
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)
Пример #7
0
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