示例#1
0
    def add_garrison_unit(self):
        garrison = self.hex_loc.get_garrison()

        for i in range(len(self.group_unit_types)):
            if i >= garrison.num_units() or not garrison.get_unit(
                    i).is_alive():
                garrison.add_unit(unit.Unit(self.group_unit_types[i]))
                return

            desired_unit_name = self.group_unit_types[i].name
            actual_unit_name = garrison.get_unit(i).get_name()
            if desired_unit_name != actual_unit_name:
                garrison.add_unit(unit.Unit(self.group_unit_types[i]), index=i)
                return
示例#2
0
    def summon_unit(self, summon_type):
        if self.is_full():
            return

        new_unit = unit.Unit(unit.unit_types_by_name[summon_type])
        new_unit.set_trait(trait.SUMMONED, 2)
        self.add_unit(new_unit, index=0)  # put summoned unit at front
示例#3
0
    def fill_for_hire_units(self):
        if self.owner.is_monster():
            return

        curr_candidates = self.site_type.get_units(self.level, True)
        for i in range(HIRE_SIZE):
            unit_type = random.choice(curr_candidates)
            self.for_hire.add_unit(unit.Unit(unit_type))
            if i >= (HIRE_SIZE / 2 - 1):
                curr_candidates = self.site_type.get_units(self.level, False)

        non_combatants = self.site_type.get_non_combatants(self.level)
        if len(non_combatants) > 0:
            self.for_hire.add_unit(unit.Unit(random.choice(non_combatants)))
        self.for_hire.add_unit(
            unit.Unit(unit.unit_types_by_name["Supply Wagon"]))
示例#4
0
    def refresh_for_hire_units(self):
        if self.owner.is_monster():
            return

        if self.for_hire.num_units() == group.MAX_UNITS:
            return

        has_wagon = any([
            curr_unit.type_name == "Supply Wagon"
            for curr_unit in self.for_hire.units
        ])

        if not has_wagon:
            self.for_hire.add_unit(
                unit.Unit(unit.unit_types_by_name["Supply Wagon"]))

        num_armies = [
            curr_unit.is_army() for curr_unit in self.for_hire.units
        ].count(True) - 1  # subtract one for the wagon
        num_chars = self.for_hire.num_units() - 1 - num_armies

        last_char_index = num_armies + num_chars - 1
        last_char_unit = self.for_hire.get_unit(last_char_index)
        if last_char_unit == None or last_char_unit.is_combatant():
            # need to add a non-combatant
            non_combatants = self.site_type.get_non_combatants(self.level)
            if len(non_combatants) > 0:
                self.for_hire.add_unit(unit.Unit(
                    random.choice(non_combatants)),
                                       index=last_char_index + 1)
        else:
            num_chars -= 1

        for i in range(1 + self.trait_value(site_upgrade.RECRUIT)):
            if num_armies < HIRE_SIZE / 2:
                new_unit = unit.Unit(
                    random.choice(self.site_type.get_units(self.level, True)))
                self.for_hire.add_unit(new_unit, index=num_armies)
                num_armies += 1
            if num_chars < HIRE_SIZE / 2:
                new_unit = unit.Unit(
                    random.choice(self.site_type.get_units(self.level, False)))
                self.for_hire.add_unit(new_unit, index=num_armies + num_chars)
                num_chars += 1
示例#5
0
def sea_monster(game):
    monster_type = unit.random_type_with_trait(trait.AQUATIC)

    start_hex = game.get_map().get_random_hex(
        lambda curr_hex: curr_hex.hex_type.is_water(
        ) and not curr_hex.has_occupants())

    if start_hex == None:
        # no water on this map!
        return None, None

    sea_monster = unit.Unit(monster_type)
    sea_monster.set_trait(trait.SUMMONED, random.randint(4, 8))
    monster_group = group.Wanderer(game.npc_table["Chaos"])
    monster_group.add_unit(sea_monster)
    monster_group.set_reputation_value(sea_monster.get_level())
    monster_group.initialize(start_hex)

    return "A sea monster has been sighted near ", game.get_map().get_zone(
        start_hex.x, start_hex.y)
示例#6
0
def questing_beast(game):
    monster_type = unit.random_type_with_trait(trait.QUEST)

    start_hex = game.get_map().get_random_hex(
        lambda curr_hex: curr_hex.hex_type.is_forest(
        ) and not curr_hex.has_occupants())

    if start_hex == None:
        # no available hex!
        return None, None

    beast = unit.Unit(monster_type)
    beast.set_trait(trait.SUMMONED, random.randint(5, 10))
    monster_group = group.QuestingBeast(game.npc_table["Chaos"])
    monster_group.add_unit(beast)
    monster_group.set_reputation_value(beast.get_level())
    monster_group.initialize(start_hex)

    return "A questing beast has been sighted in ", game.get_map().get_zone(
        start_hex.x, start_hex.y)
示例#7
0
def agent_of_chaos(game):
    def is_valid_agent_hex(curr_hex):
        if curr_hex.active_group != None:
            return False

        if curr_hex.has_site():
            return False

        if curr_hex.hex_type.name != "Settled Plain":
            return False

        map_data = game.get_map()
        if map_data.get_zone(curr_hex.x,
                             curr_hex.y).zone_type.name != "Civilized":
            return False

        return True

    agent_hex = game.get_map().get_random_hex(is_valid_agent_hex)
    if agent_hex == None:
        print "couldn't find hex for agent of chaos!"
        return None, None

    target_player = random.choice([
        curr_player for curr_player in game.get_players()
        if curr_player.is_actor()
    ])
    target_unit = random.choice(target_player.get_heroes())

    agent = unit.Unit(unit.unit_types_by_name["Agent of Chaos"])
    agent.set_trait(trait.SUMMONED, random.randint(10, 20))
    monster_group = group.Assassin(game.npc_table["Chaos"], target_unit)
    monster_group.add_unit(agent)
    monster_group.initialize(agent_hex)

    return "An agent of chaos is on the loose in ", game.get_map().get_zone(
        agent_hex.x, agent_hex.y)
示例#8
0
    def spawn_group(self, game):
        spawn_info = self.site_type.spawn_info
        if spawn_info == None or self.active_spawn or random.random(
        ) > spawn_info.chance_per_day:
            return None

        # compute aggression range
        aggression_range = self.site_type.aggression_range_func(self)

        if spawn_info.type == site_type.HORDE:
            if not horde.horde_spawnable(self.level, game.get_turn()):
                return None
            spawned = horde.Horde(self, game.get_map(), game.get_actors())
        else:
            if spawn_info.type == site_type.ZONE_PATROL:
                spawned = group.ZonePatrol(self, spawn_info.range,
                                           aggression_range)
            elif spawn_info.type == site_type.WANDERER:
                spawned = group.Wanderer(self, spawn_info.range,
                                         aggression_range)
            else:
                assert (False)

            if spawn_info.units == None:
                # copy garrison units to form spawn group
                self.fill_site_group(spawned)
            else:
                for unit_type_name in spawn_info.units:
                    spawned.add_unit(
                        unit.Unit(unit.unit_types_by_name[unit_type_name]))

        spawned.initialize(self.hex_loc)
        if spawned.get_site():
            self.active_spawn = spawned

        return spawned
示例#9
0
 def fill_site_group(self, new_group):
     for new_unit_type in self.group_unit_types:
         new_group.add_unit(unit.Unit(new_unit_type))
     return new_group
示例#10
0
    def __init__(self, game_params):
        '''
        Constructor
        '''
        random.seed(game_params.seed)

        # create map
        hex_width, hex_height = game_params.dimensions
        map_generator = map_maker.ProceduralMapmaker(hex_width, hex_height)

        # keep creating maps until we find one that can be 'zoned' successfully
        def make_map():
            reject_count = 0
            while True:
                self.hex_map = map_generator.generate()
                if self.hex_map.assign_zones():
                    break
                reject_count += 1

            print "rejected " + str(reject_count) + " maps"

        import cProfile
        cProfile.runctx('make_map()', globals(), locals(), 'make_map.profile')

        # set up players
        self.players = []
        self.npc_table = {}
        for npc_type in player_type.npc_player_types:
            npc_player = player.NPCPlayer(npc_type)
            self.npc_table[npc_type.name] = npc_player
            self.players.append(npc_player)

        human = player.Player(game_params.player_name, player.HUMAN,
                              (0, 0, 200))
        self.players.append(human)

        # assign visibility masks to players
        for curr_player in self.players:
            curr_player.set_mask(mask.Mask(curr_player, self.hex_map))
        self.mask = human.get_mask()
        self.debug_mask = mask.Mask(human, self.hex_map, True)

        # populate map with sites
        self.hex_map.populate(self.npc_table)

        #        clairs = self.hex_map.get_sites(filter_func = lambda curr_site : curr_site.site_type.name == "Captain's Lair" or
        #                                                        curr_site.site_type.name == "Overlord's Lair")
        #        clair_map = {i : 0 for i in range(1, 8)}
        #        for clair in clairs:
        #            clair_map[clair.level] += 1
        #        print clair_map

        # find starting location
        start_zone = self.hex_map.get_start_zone()
        self.start_hex = self.hex_map.find_site("Rogue's Den", (1, 1),
                                                start_zone).get_hex()
        self.start_hex.site.transfer(
            human, conquered=False)  # player starts in control of Rogue's Den

        starting_party = group.Group(human)
        my_hero = hero.Hero(unit.unit_types_by_name["Classic Hero"])

        starting_party.add_unit(my_hero)
        starting_party.add_unit(unit.Unit(unit.unit_types_by_name["Warrior"]))
        starting_party.add_unit(unit.Unit(unit.unit_types_by_name["Bowman"]))
        starting_party.add_unit(unit.Unit(unit.unit_types_by_name["Longbows"]))
        starting_party.add_unit(unit.Unit(unit.unit_types_by_name["Longbows"]))
        starting_party.add_unit(unit.Unit(unit.unit_types_by_name["Longbows"]))
        #        starting_party.add_unit(unit.Unit(unit.unit_types_by_name["Mason"]))
        self.start_hex.add_group(starting_party)

        #my_hero.equip_item(item.Item(item.type_by_name("Cloak"), base_only = True))
        #        for i in range(3):
        #            my_hero.add_item(item.random_item(random.randint(1, 6), item.NORMAL_QUALITY))

        # initialize settled area
        for curr_player in self.players:
            for curr_site in curr_player.get_sites():
                if curr_site.settles():
                    for i in range(4):
                        curr_site.spread_settlement(self.hex_map)

        random_event.seed_map(self.hex_map)

        self.curr_player_index = 0
        self.turn = Turn(1, 1)
        self.hex_map.start_day(self.turn)
        self.terminated = False