コード例 #1
0
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)
コード例 #2
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)
コード例 #3
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