Пример #1
0
 def _handle_death(self):
     status(str(self) + ' was killed!')
     # The game_map attribute should be set directly after the map is
     # generated.  I know this is ugly and fragile, but I currently have no
     # better idea.  Please forgive me.
     score = textcom.fragments + textcom.elerium + textcom.meld            \
             + textcom.alloy + self.xp + game_map.current_room
     if not self.lastname == "Bradford":
         print('Bradford: Commander, our unit was killed.')
         print('Bradford: We were able to recover some materials, however.')
         print("Fragments:", textcom.fragments)
         print("Elerium:", textcom.elerium)
         print("Meld:", textcom.meld)
         print("Alloy:", textcom.alloy)
         print('Total Score: ' + str(score))
     else:
         print("Council Speaker: Commander...you 'volunteered' your Central"
              'Officer to fight on the front lines.')
         print('Council Speaker: This was a foolish endeavour, and as a'
               'result, you lost him.')
         print('Monthly Rating: F')
         print('Council Speaker: We have negotiated...a deal with the'
               'aliens, and so...your services are no longer required.')
         print('Council Speaker: We are...terminating the XCOM Project,'
               'effective...immediately.')
     #doesn't want to stop the whole game straight away for some reason
     quit
Пример #2
0
def move(alien, cover, soldier):
    if alien.alive == True:
        time.sleep(0.5)
        if cover == 40:
            # if an alien has no cover, it will run to full cover.
            # same goes if it's flanked
            status(str(alien) + ' runs to Full cover!')
        elif cover == 20:
            status(str(alien) + ' runs to Half cover!')
        time.sleep(0.5)
        soldier.overwatch(alien)
        alien.on_overwatch = False
        alien.cover = cover
Пример #3
0
def fire(alien, soldier):
    hit_chance = alien.aim_at(soldier)
    if hit_chance > 0:
        status(str(alien) + ' fires at ' + str(soldier) + ' ('            \
               + str(hit_chance) + '%)' + '('                  \
               + alien.weapon.name + ')')
        alien.shoot_at(soldier)
    else:
        if random.randrange(0,100) < 80:
            ow(alien)
        else:
            if ITEM_ALIEN_GRENADE in alien.items:
                nade(alien, soldier)
Пример #4
0
def nade(alien, soldier):
    if ITEM_ALIEN_GRENADE not in alien.items:
        raise Exception('No grenade in inventory')
    if alien.alive == True:
        status(str(alien) + ' uses Alien Grenade!')
        time.sleep(0.5)
        print('**BLAM!**')
        time.sleep(0.5)
        del alien.items[alien.items.index(ITEM_ALIEN_GRENADE)]
        #sets the aliens item to 'none', no more grenades for you
        status('3 damage!')
        soldier.cover = 20
        soldier.hp -= 3
        soldier.check_death()
Пример #5
0
    def overwatch(self, target):
        """Perform overwatch reaction if unit is on overwatch.

        If the unit is on overwatch, the `_handle_overwatch` method is
        called (overwrite this to customize the overwatch handling) and
        `True` is returned, else `False` is returned and nothing
        happens.
        """
        if self.on_overwatch:
            self.on_overwatch = False
            status(str(self) + ' reacts!')
            self._handle_overwatch(target)
            return True
        return False
Пример #6
0
 def drop(self):
     itemdrop = random.randrange(0, 5)
     if random.randrange(1, 100) <= 5:
         ui.status('Recovered a ' + drops[itemdrop] + '!')
         if itemdrop == 0:
             self.soldier.items.append(ITEM_FRAG_GRENADE)
         elif itemdrop == 1:
             self.soldier.items.append(ITEM_MEDKIT)
         elif itemdrop == 3:
             self.soldier.weapon = PlasmaCarbine()
         elif itemdrop == 4:
             self.soldier.weapon = PlasmaRifle()
         elif itemdrop == 5:
             self.soldier.items.append(ITEM_ALIEN_GRENADE)
Пример #7
0
    def shoot_at(self, target, situation_modificator=0):
        """Perform an attack at the target.

        Returns `True` if the target was hit, `False` otherwise.  If the
        target was hit, hit points are discounted and the death check is
        performed.
        """
        hit_chance = self.aim_at(target) + situation_modificator
        damage = self.weapon.shoot()
        if random.randrange(0, 100) < hit_chance:
            status(str(damage) + ' damage!')
            target.hp -= damage
            if target.check_death():
                self._handle_kill(target)
            return True
        status(' Missed!')
        return False
Пример #8
0
def playerTurn(game_map):
    soldier = game_map.soldier
    pod = game_map.get_current_room()
    soldier.ap = soldier.mobility
    soldier.on_overwatch = False
    soldier.hunkerbonus = 0

    # currently redundant and inefficient
    advance_action = AdvanceAction(game_map)
    end_turn_action = EndTurnAction(game_map)
    hunker_down_action = HunkerDownAction(game_map)
    overwatch_action = OverwatchAction(game_map)
    reload_action = ReloadAction(game_map)
    reposition_action = RepositionAction(game_map)

    #maybe just have these as def's instead of classes?

    # while the player has spare action points left
    while soldier.ap > 0 and soldier.alive == True:
        # displays stats
        status('HP: ' + str(soldier.hp) + '\tAP: ' + str(soldier.ap))
        if soldier.cover >= 40:
            status(str(soldier) + ' is in FULL cover.')
        else:
            status(str(soldier) + ' is in HALF cover.')
        actions = []
        if len(pod) == 0:
            actions.append(advance_action)
            if soldier.ap >= reload_action.ap_costs:
                actions.append(reload_action)
            actions.append(end_turn_action)
        else:
            if soldier.weapon.ammo > 0:
                if soldier.ap >= 6: # TODO make the ap_cost a static member
                    for alien in pod:
                        actions.append(FireAction(game_map, alien))
                if soldier.ap >= overwatch_action.ap_costs:
                    actions.append(overwatch_action)
            if soldier.weapon.ammo < soldier.weapon.clip_size                 \
               and soldier.ap >= reload_action.ap_costs:
                actions.append(reload_action)
            for item in soldier.items:
                if item.use_ap_costs > 0 and soldier.ap >= item.use_ap_costs:
                    actions.append(UseItemAction(game_map, item))
            if soldier.ap >= reposition_action.ap_costs:
                actions.append(reposition_action)
            if soldier.cover > COVER_NONE                                     \
               and soldier.ap >= hunker_down_action.ap_costs:
                    actions.append(hunker_down_action)
            actions.append(end_turn_action)
        prompt_player(actions).perform()
Пример #9
0
 def enter_room(self):
     for alien in self.rooms[self.current_room]:
         ui.status(str(alien) + ' spotted!')
     time.sleep(0.5)
     # Scatter the aliens in a room, some won't find any cover.
     for alien in self.rooms[self.current_room]:
         cover = textcom.COVER_NONE
         cover_str = ''
         rnd = random.randrange(100)
         if rnd > 75:
             cover = textcom.COVER_FULL
             cover_str = 'full'
         elif rnd > 10:
             cover = textcom.COVER_HALF
             cover_str = 'half'
         alien.cover = cover
         if not alien.cover == textcom.COVER_NONE:
             ui.status(str(alien) + ' moves to ' + cover_str + ' cover!')
         else:
             ui.status(str(alien) + " can't find any cover!")
     time.sleep(0.5)
     print()
Пример #10
0
def main():
    textcom.globals_hack_init()

    print("Bradford: Welcome Commander. We've discovered an Alien Base, and "
          "it's your job to send someone out to deal with it.")
    print('Bradford: Choose a soldier from the 3 below to go on the mission.')

    barracks = []
    #generates soldiers
    for i in range(3):
        x = create_soldier(i)
        barracks.append(x)

    #displays a list of the soldiers
    for i in range(len(barracks)):
        print(str(i + 1) + ': ')
        barracks[i].print_summary()
        print()

    #forces you to pick only one soldier
    soldier = barracks[get_int_input('# ', 1, 3) - 1]

    if soldier.lastname == "Bradford":
        soldier.say("What? There must have been a mistake on the sheet, "
                    "Commander! You can't send --")
    elif soldier.lastname == "Van Doorn":
        soldier.say("I'm the Ops team?")
    else:
        soldier.say('Ready for duty, Commander!')

    scripted_levels = {
        1:  [create_alien(1, 1, 'Sectoid', nrank=0)],
        2:  [
                create_alien(1, 2, 'Sectoid', nrank=0),
                create_alien(1, 2, 'Sectoid', nrank=0)
            ],
        3:  [
                create_alien(1, 3, 'Sectoid', nrank=0),
                create_alien(1, 3, 'Sectoid', nrank=1)
            ],
        5:  ["Drop Zone"],
        10: ["Drop Zone"],
        15: ["Drop Zone"],
        20: ["Drop Zone"],
        30: [create_alien(1, 1, 'Muton', nrank=8, hp=50)]
    }

    game_map = create_map(NUMBER_OF_ROOMS, soldier, scripted_levels)
    # dump_map(game_map)

    # Yeah, I feel pretty bad about this, but currently I have no idea how to
    # make the current room index available for the death handler score
    # .calculation.  Maybe everything works out fine if components are
    # introduced.  I hope so.
    soldier.game_map = game_map

    #game loop, runs until your soldier is killed
    while soldier.alive == True:
        try:
            old_room = game_map.get_current_room()
            playerTurn(game_map)
            status(str(soldier) + ' is out of AP!')

            current_room = game_map.get_current_room()
            # Aliens are not allowed to act after the room was changed,
            # because they already scattered when the player entered the new
            # room.  Also, there is no need for an alien turn if there are
            # no more aliens in the room.
            if soldier.alive == True and old_room == current_room             \
               and len(current_room) > 0:
                print()
                print("--------------Alien Activity!--------------")
                print()
                time.sleep(1)
                alienTurn(game_map)
                print()
                print("--------------XCOM Turn--------------")
                print()
        except ( ValueError or IndexError ):
            pass
        if game_map.current_room == len(game_map.rooms):
            print("You have won the game!")
            break
Пример #11
0
def ow(alien):
    status(str(alien) + ' went on overwatch!')
    alien.on_overwatch = True
Пример #12
0
 def check_promotion(self):
     was_promoted = False
     if self.xp >= 25 and self.nrank < RANK_SQUADDIE:
         self.nrank = RANK_SQUADDIE
         self.hp += 1
         self.aim += 2
         self.mobility += 1
         for _ in range(2):
             self.game_map.drop(self)
         was_promoted = True
     elif self.xp >= 100 and self.nrank < RANK_CORPORAL:
         self.nrank = RANK_CORPORAL
         self.hp += 1
         self.aim += 2
         self.mobility += 1
         for _ in range(2):
             self.game_map.drop(self)
         was_promoted = True
     elif self.xp >= 300 and self.nrank < RANK_SERGEANT:
         nicknames = XCOM_UNISEX_NICKNAMES_ASSAULT                         \
                     + XCOM_UNISEX_NICKNAMES_HEAVY                         \
                     + XCOM_UNISEX_NICKNAMES_SNIPER                        \
                     + XCOM_UNISEX_NICKNAMES_SUPPORT
         if self.sex == SEX_FEMALE:
             nicknames += XCOM_FEMALE_NICKNAMES_ASSAULT                    \
                          + XCOM_FEMALE_NICKNAMES_HEAVY                    \
                          + XCOM_FEMALE_NICKNAMES_MEC                      \
                          + XCOM_FEMALE_NICKNAMES_SNIPER                   \
                          + XCOM_FEMALE_NICKNAMES_SUPPORT
         else:
             nicknames += XCOM_MALE_NICKNAMES_ASSAULT                      \
                          + XCOM_MALE_NICKNAMES_HEAVY                      \
                          + XCOM_MALE_NICKNAMES_MEC                        \
                          + XCOM_MALE_NICKNAMES_SNIPER                     \
                          + XCOM_MALE_NICKNAMES_SUPPORT
         self.nickname = random.choice(nicknames)
         status(XCOM_RANKS[self.nrank] + ' ' + self.firstname + ' '        \
                + self.lastname  + " earned the nickname '" + self.nickname\
                + "'")
         self.nrank = RANK_SERGEANT
         self.hp += 2
         self.aim += 1
         self.mobility += 1
         for _ in range(2):
             self.game_map.drop(self)
         was_promoted = True
     elif self.xp >= 900 and self.nrank < RANK_LIEUTENANT:
         self.nrank = RANK_LIEUTENANT
         self.hp += 1
         self.aim += 1
         for _ in range(2):
             self.game_map.drop(self)
         was_promoted = True
     elif self.xp >= 1500 and self.nrank < RANK_CAPTAIN:
         self.nrank = RANK_CAPTAIN
         self.hp += 2
         self.aim += 1
         for _ in range(4):
             self.game_map.drop(self)
         was_promoted = True
     elif self.xp >= 2000 and self.nrank < RANK_MAJOR:
         self.nrank = RANK_MAJOR
         self.hp += 1
         self.aim += 1
         self.mobility += 1
         for _ in range(4):
             self.game_map.drop(self)
         was_promoted = True
     elif self.xp >= 3000 and self.nrank < RANK_COLONEL:
         self.nrank = RANK_COLONEL
         self.hp += 1
         self.aim += 1
         for _ in range(6):
             self.game_map.drop(self)
         was_promoted = True
     if was_promoted:
         status(str(self) + ' was promoted to ' + XCOM_RANKS[self.nrank])
Пример #13
0
 def _handle_death(self):
     status(str(self) + ' died!')