Exemple #1
0
    def roam(self):
        flog.debug("deer is roaming")
        self.deer.recent_actions.append(f"{self.deer.entity_name} is roaming.")
        dist = self.deer.roam_distance
        unclamped_x = rng.range_int(self.deer.x - dist, self.deer.x + dist + 1)
        unclamped_y = rng.range_int(self.deer.y - dist, self.deer.y + dist + 1)

        self.deer.ai.action_queue.append(MovementAction(self.deer, self.deer.engine.game_map.clamp_coord(unclamped_x, unclamped_y)))
Exemple #2
0
    def roam(self):
        flog.debug("wolf is roaming")
        dist = stats.Stats.map()["wolf"]["roam-distance"]
        unclamped_x = rng.range_int(self.wolf.x - dist, self.wolf.x + dist + 1)
        unclamped_y = rng.range_int(self.wolf.y - dist, self.wolf.y + dist + 1)

        self.wolf.ai.action_queue.append(
            MovementAction(
                self.wolf,
                self.wolf.engine.game_map.clamp_coord(unclamped_x,
                                                      unclamped_y)))
Exemple #3
0
    def find_hunter_spawn_point(self):
        camp_x_min = round(self.game_map.width * 0.25)
        camp_x_max = round(self.game_map.width * 0.75)
        camp_y_min = round(self.game_map.height * 0.2)
        camp_y_max = round(self.game_map.height * 0.6)
        found = False

        # TODO make this smarter
        while (not found):
            x = rng.range_int(camp_x_min, camp_x_max)
            y = rng.range_int(camp_y_min, camp_y_max)

            if self.game_map.tiles[y][x].terrain.walkable:
                return [x, y]
Exemple #4
0
    def roam(self):
        dist = stats.Stats.map()["hunter"]["roam-distance"]
        forbidden = []  # prevent retrying the same tiles

        while (True):
            candidates = []

            # get 3 candidate distinations
            while (len(candidates) <
                   stats.Stats.map()["hunter"]["roam-candidates"]):
                unclamped_x = rng.range_int(self.hunter.x - dist,
                                            self.hunter.x + dist + 1)
                unclamped_y = rng.range_int(self.hunter.y - dist,
                                            self.hunter.y + dist + 1)
                dest = self.hunter.engine.game_map.clamp_coord(
                    unclamped_x, unclamped_y)

                if [dest.x, dest.y] not in forbidden:
                    if self.hunter.engine.game_map.tiles[dest.y][
                            dest.x].terrain.walkable:
                        explored = f"{dest.x},{dest.y}" in self.hunter.memory.map[
                            "explored-terrain"]
                        distance = math.get_distance(self.hunter.x,
                                                     self.hunter.y, dest.x,
                                                     dest.y)
                        candidates.append([dest.x, dest.y, explored, distance])
                    else:
                        forbidden.append([dest.x, dest.y])

            # sort by explored and distance
            candidates = sorted(candidates, key=lambda x: (-x[2], -x[3]))

            for dest in candidates:
                x = dest[0]
                y = dest[1]

                # prefer to take the first one that is in fog and farthest away
                # this way hunter will tend to travel longer distances and explore more fog
                path = deque(
                    pf.get_path(self.hunter.engine.game_map.path_map,
                                self.hunter.coord(), Coord(x, y)))

                if len(path) < stats.Stats.map(
                )["hunter"]["max-path-distance"]:
                    return [MovementAction(self.hunter, Coord(x, y), path)]
                else:
                    forbidden.append([x, y])
Exemple #5
0
    def spawn_entities(self):
        intelligent_entities = []
        static_entities = []
        self.berry_bush_count = 0

        # wolf = wlf.Wolf(self, 80, 20)
        # self.game_map.tiles[20][80].entities.append(wolf)
        # intelligent_entities.append(wolf)

        for y, row in enumerate(self.game_map.tiles):
            for x, tile in enumerate(row):
                if tile.terrain.walkable:
                    if rng.rand() < stats.Stats.map()["rabbit"]["spawn"]:
                        burrow = rbt.Burrow(x, y)
                        rabbit = rbt.Rabbit(self, x, y)
                        rabbit.burrow = burrow
                        self.game_map.tiles[y][x].add_entities(
                            [burrow, rabbit])
                        intelligent_entities.append(rabbit)
                    if rng.rand() < stats.Stats.map()["wolf"]["spawn"]:
                        wolf = wlf.Wolf(self, x, y)
                        self.game_map.tiles[y][x].entities.append(wolf)
                        intelligent_entities.append(wolf)
                    if rng.rand() < stats.Stats.map()["deer"]["spawn"]:
                        buck = dr.Buck(self, x, y)
                        self.game_map.tiles[y][x].entities.append(buck)
                        intelligent_entities.append(buck)

                        for i in range(rng.range_int(1, 4)):
                            doe = dr.Doe(self, x, y, buck)
                            self.game_map.tiles[y][x].entities.append(doe)
                            intelligent_entities.append(doe)
                            buck.herd.append(doe)
                if isinstance(tile.terrain, terrain.Grass) or isinstance(
                        tile.terrain, terrain.Forest):
                    if rng.rand() < stats.Stats.map()["berry-bush"]["spawn"]:
                        berry_bush = bb.BerryBush(self, x, y)
                        self.game_map.tiles[y][x].entities.append(berry_bush)
                        static_entities.append(berry_bush)
                        self.berry_bush_count += 1

        return intelligent_entities, static_entities
Exemple #6
0
 def grow_berry(self):
     if self.num_berries < self.berry_limit:
         self.num_berries += rng.range_int(stats.Stats.map()["berry-bush"]["grow-min-berries"], stats.Stats.map()["berry-bush"]["grow-max-berries"])
Exemple #7
0
 def __init__(self, engine, x, y):
     super().__init__(engine, x, y, stats.Stats.map()["berry-bush"]["update-interval"], "Berry Bush")
     self.name = "Berry Bush"
     self.bg_color = colors.dark_green
     self.berry_limit = rng.range_int(stats.Stats.map()["berry-bush"]["min-berry-limit"], stats.Stats.map()["berry-bush"]["max-berry-limit"])
     self.num_berries = rng.range_int(stats.Stats.map()["berry-bush"]["spawn-min-berries"], stats.Stats.map()["berry-bush"]["spawn-max-berries"])