コード例 #1
0
ファイル: planetbase.py プロジェクト: robotota/planetbase
    def perform_mission(self):
        our_units = [unit for unit in state.units if unit.attacking]
        attackers = [unit for unit in state.enemy_units if random.random() < 0.01]

        if our_units and attackers:
            state.warning("Encountered " +str(len(attackers)) + " unit(s)")
            real_attackers = attackers[:]
            defenders = state.units[:]
            combat.play(our_units, real_attackers)
            for unit in attackers:
                if unit not in real_attackers:
                    state.enemy_units.remove(unit)
            for unit in state.units:
                if unit not in our_units:
                    state.badnews(unit.name + " KIA in a mission")
                    state.units.remove(unit)
コード例 #2
0
ファイル: planetbase.py プロジェクト: robotota/planetbase
    def defend_base(self):
        attackers = [unit for unit in state.enemy_units if random.random() < 0.005]

        if len(attackers) >0:
            state.warning("We were attacked by " +str(len(attackers)) + " unit(s)")
            real_attackers = attackers[:]

            defenders = state.units[:]
            combat.play(defenders, real_attackers)
            for unit in attackers:
                if unit not in real_attackers:
                    state.enemy_units.remove(unit)
            for unit in state.units:
                if unit not in defenders:
                    state.badnews(unit.name + " KIA")
                    state.units.remove(unit)

            if not state.units:
                state.badnews("Enemy broke through!")
                for i in range(len(real_attackers)):
                    b = random.choice(state.buildings)
                    if random.random()<0.1:
                        state.badnews(str(b) + " was destroyed")
                        state.buildings.remove(b)