def generate(self) -> bool: if not super().generate(): return False carrier_names = self.faction.carrier_names if not carrier_names: logging.info( f"Skipping generation of {self.control_point.name} because " f"{self.faction_name} has no carriers") return False # Create ground object group group_id = self.game.next_group_id() g = CarrierGroundObject(namegen.random_objective_name(), group_id, self.control_point) group = generate_carrier_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(carrier_names) return True
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)