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)
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)
def generate_airbase_defense_group(airbase_defense_group_id: int, ground_obj: SamGroundObject, faction: str, game: Game) -> None: if airbase_defense_group_id == 0: group = generate_armor_group(faction, game, ground_obj) elif airbase_defense_group_id == 1 and random.randint(0, 1) == 0: group = generate_anti_air_group(game, ground_obj, faction) elif random.randint(0, 2) == 1: group = generate_shorad_group(game, ground_obj, faction) else: group = generate_armor_group(faction, game, ground_obj) ground_obj.groups = [] if group is not None: ground_obj.groups.append(group)
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)
def generate_airbase_defense_group(airbase_defense_group_id, ground_obj:TheaterGroundObject, faction, game, cp): logging.info("GENERATE AIR DEFENSE GROUP") logging.info(faction) logging.info(airbase_defense_group_id) if airbase_defense_group_id == 0: group = generate_armor_group(faction, game, ground_obj) elif airbase_defense_group_id == 1 and random.randint(0, 1) == 0: group = generate_anti_air_group(game, cp, ground_obj, faction) elif random.randint(0, 2) == 1: group = generate_shorad_group(game, cp, ground_obj, faction) else: group = generate_armor_group(faction, game, ground_obj) ground_obj.groups = [] if group is not None: ground_obj.groups.append(group)
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)
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