示例#1
0
    def generate_aa_site(self) -> None:
        obj_name = namegen.random_objective_name()

        # Pick from preset locations
        location = self.pick_preset_location(False)

        # If no preset location, then try the old algorithm
        if location is None:
            position = find_location(True, self.control_point.position,
                                     self.game.theater, 10000, 40000,
                                     self.control_point.ground_objects)
        else:
            position = location.position

        if position is None:
            logging.error(
                f"Could not find point for {obj_name} at {self.control_point}")
            return

        group_id = self.game.next_group_id()

        g = SamGroundObject(namegen.random_objective_name(),
                            group_id,
                            position,
                            self.control_point,
                            for_airbase=False)
        group = generate_anti_air_group(self.game, g, self.faction_name)
        if group is not None:
            g.groups = [group]
        self.control_point.connected_objectives.append(g)
示例#2
0
    def generate_missile_site(self) -> None:

        # Pick from preset locations
        location = self.pick_preset_location(False)

        # If no preset location, then try the old algorithm
        if location is None:
            position = find_location(True, self.control_point.position,
                                     self.game.theater, 2500, 40000, [], False)
        else:
            position = location.position

        if position is None:
            logging.info(
                f"Could not find point for {self.control_point} missile site")
            return

        group_id = self.game.next_group_id()

        g = MissileSiteGroundObject(namegen.random_objective_name(), group_id,
                                    position, self.control_point)
        group = generate_missile_group(self.game, g, self.faction_name)
        g.groups = []
        if group is not None:
            g.groups.append(group)
            self.control_point.connected_objectives.append(g)
        return
示例#3
0
    def generate_strike_target_at(self, category: str,
                                  position: Point) -> None:

        obj_name = namegen.random_objective_name()
        template = random.choice(list(self.templates[category].values()))

        object_id = 0
        group_id = self.game.next_group_id()

        # TODO: Create only one TGO per objective, each with multiple units.
        for unit in template:
            object_id += 1

            template_point = Point(unit["offset"].x, unit["offset"].y)
            g = BuildingGroundObject(
                obj_name,
                category,
                group_id,
                object_id,
                position + template_point,
                unit["heading"],
                self.control_point,
                unit["type"],
            )

            self.control_point.connected_objectives.append(g)
示例#4
0
    def generate_tgo_for_scenery(self, scenery: SceneryGroup) -> None:

        obj_name = namegen.random_objective_name()
        category = scenery.category
        group_id = self.game.next_group_id()
        object_id = 0

        # Each nested trigger zone is a target/building/unit for an objective.
        for zone in scenery.zones:

            object_id += 1
            local_position = zone.position
            local_dcs_identifier = zone.name

            g = SceneryGroundObject(
                obj_name,
                category,
                group_id,
                object_id,
                local_position,
                self.control_point,
                local_dcs_identifier,
                zone,
            )

            self.control_point.connected_objectives.append(g)

        return
    def generate_shorad(self) -> None:
        position = self.location_finder.location_for(
            LocationType.BaseAirDefense)
        if position is None:
            return

        group_id = self.game.next_group_id()

        g = SamGroundObject(
            namegen.random_objective_name(),
            group_id,
            position,
            self.control_point,
            for_airbase=True,
        )

        groups = generate_anti_air_group(self.game,
                                         g,
                                         self.faction,
                                         ranges=[{AirDefenseRange.Short}])
        if not groups:
            logging.error(
                f"Could not generate SHORAD group at {self.control_point}")
            return
        g.groups = groups
        self.control_point.base_defenses.append(g)
示例#6
0
    def generate_ground_point(self) -> None:
        try:
            category = random.choice(self.faction.building_set)
        except IndexError:
            logging.exception("Faction has no buildings defined")
            return

        obj_name = namegen.random_objective_name()
        template = random.choice(list(self.templates[category].values()))

        if category == "oil":
            location_type = LocationType.OffshoreStrikeTarget
        else:
            location_type = LocationType.StrikeTarget

        # Pick from preset locations
        point = self.location_finder.location_for(location_type)
        if point is None:
            return

        object_id = 0
        group_id = self.game.next_group_id()

        # TODO: Create only one TGO per objective, each with multiple units.
        for unit in template:
            object_id += 1

            template_point = Point(unit["offset"].x, unit["offset"].y)
            g = BuildingGroundObject(obj_name, category, group_id, object_id,
                                     point + template_point, unit["heading"],
                                     self.control_point, unit["type"])

            self.control_point.connected_objectives.append(g)
示例#7
0
    def generate_missile_site_at(self, position: PointWithHeading) -> None:
        group_id = self.game.next_group_id()

        g = MissileSiteGroundObject(namegen.random_objective_name(), group_id,
                                    position, self.control_point)
        group = generate_missile_group(self.game, g, self.faction_name)
        g.groups = []
        if group is not None:
            g.groups.append(group)
            self.control_point.connected_objectives.append(g)
        return
示例#8
0
    def generate_factory_at(self, point: PointWithHeading) -> None:
        obj_name = namegen.random_objective_name()
        group_id = self.game.next_group_id()

        g = FactoryGroundObject(
            obj_name,
            group_id,
            point,
            point.heading,
            self.control_point,
        )

        self.control_point.connected_objectives.append(g)
示例#9
0
    def generate_missile_site(self) -> None:
        position = self.location_finder.location_for(LocationType.MissileSite)
        if position is None:
            return

        group_id = self.game.next_group_id()

        g = MissileSiteGroundObject(namegen.random_objective_name(), group_id,
                                    position, self.control_point)
        group = generate_missile_group(self.game, g, self.faction_name)
        g.groups = []
        if group is not None:
            g.groups.append(group)
            self.control_point.connected_objectives.append(g)
        return
示例#10
0
    def generate_aa_at(self, position: Point,
                       ranges: Iterable[Set[AirDefenseRange]]) -> None:
        group_id = self.game.next_group_id()

        g = SamGroundObject(namegen.random_objective_name(),
                            group_id,
                            position,
                            self.control_point,
                            for_airbase=False)
        group = generate_anti_air_group(self.game, g, self.faction, ranges)
        if group is None:
            logging.error("Could not generate air defense group for %s at %s",
                          g.name, self.control_point)
            return
        g.groups = [group]
        self.control_point.connected_objectives.append(g)
示例#11
0
    def generate_ship(self) -> None:
        point = self.location_finder.location_for(
            LocationType.OffshoreStrikeTarget)
        if point is None:
            return

        group_id = self.game.next_group_id()

        g = ShipGroundObject(namegen.random_objective_name(), group_id, point,
                             self.control_point)

        group = generate_ship_group(self.game, g, self.faction_name)
        g.groups = []
        if group is not None:
            g.groups.append(group)
            self.control_point.connected_objectives.append(g)
示例#12
0
    def generate_base_defense(self, index: int) -> None:
        position = self._find_location()
        if position is None:
            logging.error("Could not find position for "
                          f"{self.control_point} base defense")
            return

        group_id = self.game.next_group_id()

        g = SamGroundObject(namegen.random_objective_name(),
                            group_id,
                            position,
                            self.control_point,
                            for_airbase=True)

        generate_airbase_defense_group(index, g, self.faction_name, self.game)
        self.control_point.base_defenses.append(g)
示例#13
0
    def generate_ewr(self) -> None:
        position = self.location_finder.location_for(LocationType.Ewr)
        if position is None:
            return

        group_id = self.game.next_group_id()

        g = EwrGroundObject(namegen.random_objective_name(), group_id,
                            position, self.control_point)

        group = generate_ewr_group(self.game, g, self.faction)
        if group is None:
            logging.error(f"Could not generate EWR at {self.control_point}")
            return

        g.groups = [group]
        self.control_point.base_defenses.append(g)
示例#14
0
    def generate_ship(self) -> None:
        point = find_location(False, self.control_point.position,
                              self.game.theater, 5000, 40000, [], False)
        if point is None:
            logging.error(
                f"Could not find point for {self.control_point}'s navy")
            return

        group_id = self.game.next_group_id()

        g = ShipGroundObject(namegen.random_objective_name(), group_id, point,
                             self.control_point)

        group = generate_ship_group(self.game, g, self.faction_name)
        g.groups = []
        if group is not None:
            g.groups.append(group)
            self.control_point.connected_objectives.append(g)
示例#15
0
    def generate_ewr(self) -> None:
        position = self._find_location()
        if position is None:
            logging.error("Could not find position for "
                          f"{self.control_point} EWR")
            return

        group_id = self.game.next_group_id()

        g = EwrGroundObject(namegen.random_objective_name(), group_id,
                            position, self.control_point)

        group = generate_ewr_group(self.game, g, self.faction_name)
        if group is None:
            return

        g.groups = [group]
        self.control_point.base_defenses.append(g)
示例#16
0
    def generate_ewr_at(self, position: PointWithHeading) -> None:
        group_id = self.game.next_group_id()

        g = EwrGroundObject(
            namegen.random_objective_name(),
            group_id,
            position,
            self.control_point,
        )
        group = generate_ewr_group(self.game, g, self.faction)
        if group is None:
            logging.error(
                "Could not generate ewr group for %s at %s",
                g.name,
                self.control_point,
            )
            return
        g.groups = [group]
        self.control_point.connected_objectives.append(g)
示例#17
0
    def generate_sam(self) -> None:
        position = self.location_finder.location_for(
            LocationType.BaseAirDefense)
        if position is None:
            return

        group_id = self.game.next_group_id()

        g = SamGroundObject(namegen.random_objective_name(),
                            group_id,
                            position,
                            self.control_point,
                            for_airbase=True)

        group = generate_anti_air_group(self.game, g, self.faction)
        if group is None:
            logging.error(f"Could not generate SAM at {self.control_point}")
            return
        g.groups.append(group)
        self.control_point.base_defenses.append(g)
示例#18
0
    def generate_garrison(self) -> None:
        position = self.location_finder.location_for(LocationType.Garrison)
        if position is None:
            return

        group_id = self.game.next_group_id()

        g = VehicleGroupGroundObject(namegen.random_objective_name(),
                                     group_id,
                                     position,
                                     self.control_point,
                                     for_airbase=True)

        group = generate_armor_group(self.faction_name, self.game, g)
        if group is None:
            logging.error(
                f"Could not generate garrison at {self.control_point}")
            return
        g.groups.append(group)
        self.control_point.base_defenses.append(g)
示例#19
0
    def generate_ground_point(self) -> None:
        try:
            category = random.choice(self.faction.building_set)
        except IndexError:
            logging.exception("Faction has no buildings defined")
            return

        obj_name = namegen.random_objective_name()
        template = random.choice(list(self.templates[category].values()))

        offshore = category == "oil"

        # Pick from preset locations
        location = self.pick_preset_location(offshore)

        # Else try the old algorithm
        if location is None:
            point = find_location(not offshore, self.control_point.position,
                                  self.game.theater, 10000, 40000,
                                  self.control_point.ground_objects)
        else:
            point = location.position

        if point is None:
            logging.error(
                f"Could not find point for {obj_name} at {self.control_point}")
            return

        object_id = 0
        group_id = self.game.next_group_id()

        # TODO: Create only one TGO per objective, each with multiple units.
        for unit in template:
            object_id += 1

            template_point = Point(unit["offset"].x, unit["offset"].y)
            g = BuildingGroundObject(obj_name, category, group_id, object_id,
                                     point + template_point, unit["heading"],
                                     self.control_point, unit["type"])

            self.control_point.connected_objectives.append(g)
示例#20
0
    def generate(self) -> bool:
        if not super().generate():
            return False

        lha_names = self.faction.helicopter_carrier_names
        if not lha_names:
            logging.info(
                f"Skipping generation of {self.control_point.name} because "
                f"{self.faction_name} has no LHAs")
            return False

        # Create ground object group
        group_id = self.game.next_group_id()
        g = LhaGroundObject(namegen.random_objective_name(), group_id,
                            self.control_point)
        group = generate_lha_group(self.faction_name, self.game, g)
        g.groups = []
        if group is not None:
            g.groups.append(group)
        self.control_point.connected_objectives.append(g)
        self.control_point.name = random.choice(lha_names)
        return True
示例#21
0
def generate_groundobjects(theater: ConflictTheater, game):
    with open("resources/groundobject_templates.p", "rb") as f:
        tpls = pickle.load(f)

    group_id = 0
    cp_to_remove = []
    for cp in theater.controlpoints:
        group_id = generate_cp_ground_points(cp, theater, game, group_id, tpls)

        # CP
        if cp.captured:
            faction_name = game.player_name
        else:
            faction_name = game.enemy_name

        if cp.cptype == ControlPointType.AIRCRAFT_CARRIER_GROUP:
            # Create ground object group
            group_id = game.next_group_id()
            g = TheaterGroundObject("CARRIER")
            g.group_id = group_id
            g.object_id = 0
            g.cp_id = cp.id
            g.airbase_group = True
            g.dcs_identifier = "CARRIER"
            g.sea_object = True
            g.obj_name = namegen.random_objective_name()
            g.heading = 0
            g.position = Point(cp.position.x, cp.position.y)
            group = generate_carrier_group(faction_name, game, g)
            g.groups = []
            if group is not None:
                g.groups.append(group)
            cp.ground_objects.append(g)
            # Set new name :
            if "carrier_names" in db.FACTIONS[faction_name]:
                cp.name = random.choice(
                    db.FACTIONS[faction_name]["carrier_names"])
            else:
                cp_to_remove.append(cp)
        elif cp.cptype == ControlPointType.LHA_GROUP:
            # Create ground object group
            group_id = game.next_group_id()
            g = TheaterGroundObject("LHA")
            g.group_id = group_id
            g.object_id = 0
            g.cp_id = cp.id
            g.airbase_group = True
            g.dcs_identifier = "LHA"
            g.sea_object = True
            g.obj_name = namegen.random_objective_name()
            g.heading = 0
            g.position = Point(cp.position.x, cp.position.y)
            group = generate_lha_group(faction_name, game, g)
            g.groups = []
            if group is not None:
                g.groups.append(group)
            cp.ground_objects.append(g)
            # Set new name :
            if "lhanames" in db.FACTIONS[faction_name]:
                cp.name = random.choice(db.FACTIONS[faction_name]["lhanames"])
            else:
                cp_to_remove.append(cp)
        else:

            for i in range(random.randint(3, 6)):

                logging.info("GENERATE BASE DEFENSE")
                point = find_location(True, cp.position, theater, 800, 3200,
                                      [], True)
                logging.info(point)

                if point is None:
                    logging.info(
                        "Couldn't find point for {} base defense".format(cp))
                    continue

                group_id = game.next_group_id()

                g = TheaterGroundObject("aa")
                g.group_id = group_id
                g.object_id = 0
                g.cp_id = cp.id
                g.airbase_group = True
                g.dcs_identifier = "AA"
                g.sea_object = False
                g.obj_name = namegen.random_objective_name()
                g.heading = 0
                g.position = Point(point.x, point.y)

                generate_airbase_defense_group(i, g, faction_name, game, cp)
                cp.ground_objects.append(g)

            logging.info("---------------------------")
            logging.info("CP Generation : " + cp.name)
            for ground_object in cp.ground_objects:
                logging.info(ground_object.groups)

        # Generate navy groups
        if "boat" in db.FACTIONS[faction_name].keys():

            if cp.captured and game.settings.do_not_generate_player_navy:
                continue

            if not cp.captured and game.settings.do_not_generate_enemy_navy:
                continue

            boat_count = 1
            if "boat_count" in db.FACTIONS[faction_name].keys():
                boat_count = int(db.FACTIONS[faction_name]["boat_count"])

            for i in range(boat_count):

                point = find_location(False, cp.position, theater, 5000, 40000,
                                      [], False)

                if point is None:
                    logging.info("Couldn't find point for {} ships".format(cp))
                    continue

                group_id = game.next_group_id()

                g = TheaterGroundObject("aa")
                g.group_id = group_id
                g.object_id = 0
                g.cp_id = cp.id
                g.airbase_group = False
                g.dcs_identifier = "AA"
                g.sea_object = True
                g.obj_name = namegen.random_objective_name()
                g.heading = 0
                g.position = Point(point.x, point.y)

                group = generate_ship_group(game, g, faction_name)
                g.groups = []
                if group is not None:
                    g.groups.append(group)
                    cp.ground_objects.append(g)

        if "missiles" in db.FACTIONS[faction_name].keys():

            missiles_count = 1
            if "missiles_count" in db.FACTIONS[faction_name].keys():
                missiles_count = int(
                    db.FACTIONS[faction_name]["missiles_count"])

            for i in range(missiles_count):

                point = find_location(True, cp.position, theater, 2500, 40000,
                                      [], False)

                if point is None:
                    logging.info(
                        "Couldn't find point for {} missiles".format(cp))
                    continue

                group_id = game.next_group_id()

                g = TheaterGroundObject("aa")
                g.group_id = group_id
                g.object_id = 0
                g.cp_id = cp.id
                g.airbase_group = False
                g.dcs_identifier = "AA"
                g.sea_object = False
                g.obj_name = namegen.random_objective_name()
                g.heading = 0
                g.position = Point(point.x, point.y)

                group = generate_missile_group(game, g, faction_name)
                g.groups = []
                if group is not None:
                    g.groups.append(group)
                    cp.ground_objects.append(g)

    for cp in cp_to_remove:
        theater.controlpoints.remove(cp)
示例#22
0
def generate_cp_ground_points(cp: ControlPoint, theater, game, group_id,
                              templates):
    """
    Generate inital ground objects and AA site for given control point
    :param cp: Control point to initialize
    :param theater: Theater
    :param game: Game object
    :param group_id: Group id
    :param templates: Ground object templates
    :return: True if something was generated
    """
    # Reset cp ground objects
    cp.ground_objects = []

    if cp.is_global:
        return False

    if cp.captured:
        faction = game.player_name
    else:
        faction = game.enemy_name
    faction_data = db.FACTIONS[faction]

    available_categories = DEFAULT_AVAILABLE_BUILDINGS
    if "objects" in faction_data.keys():
        available_categories = faction_data["objects"]

    if len(available_categories) == 0:
        return False

    amount = random.randrange(3, 8)
    for i in range(0, amount):

        obj_name = namegen.random_objective_name()

        if i >= amount - 1:
            tpl_category = "aa"
        else:
            if random.randint(0, 3) == 0:
                tpl_category = "aa"
            else:
                tpl_category = random.choice(available_categories)

        tpl = random.choice(list(templates[tpl_category].values()))
        point = find_location(tpl_category != "oil", cp.position, theater,
                              10000, 40000, cp.ground_objects)

        if point is None:
            logging.info("Couldn't find point for {}".format(cp))
            continue

        object_id = 0
        group_id = game.next_group_id()

        logging.info("generated {} for {}".format(tpl_category, cp))

        for object in tpl:
            object_id += 1

            g = TheaterGroundObject(tpl_category)
            g.group_id = group_id
            g.object_id = object_id
            g.cp_id = cp.id
            g.airbase_group = False
            g.obj_name = obj_name

            g.dcs_identifier = object["type"]
            g.heading = object["heading"]
            g.sea_object = False
            g.position = Point(point.x + object["offset"].x,
                               point.y + object["offset"].y)

            if g.dcs_identifier == "AA":
                g.groups = []
                group = generate_anti_air_group(game, cp, g, faction)
                if group is not None:
                    g.groups.append(group)

            cp.ground_objects.append(g)
    return group_id