Example #1
0
    def __update_supply(self):
        """
        Update information about supply.
        """
        self.__system_supply.update(fo.getEmpire().supplyProjections())
        for sys_id, supply_val in self.__system_supply.iteritems():
            self.__systems_by_jumps_to_supply.setdefault(
                min(0, supply_val), []).append(sys_id)

        # By converting the lists to immutable tuples now, we don't have to return copies when queried.
        for key in self.__systems_by_jumps_to_supply:
            self.__systems_by_jumps_to_supply[key] = tuple(
                self.__systems_by_jumps_to_supply[key])

        enemies = [
            fo.getEmpire(_id) for _id in fo.allEmpireIDs()
            if _id != fo.empireID()
        ]
        for enemy in enemies:
            if enemy is None:
                error('Got None for enemy empire!')
                continue

            for sys_id, supply_val in enemy.supplyProjections().items():
                self.__distance_to_enemy_supply[sys_id] = min(
                    self.get_distance_to_enemy_supply(sys_id), -supply_val)
Example #2
0
def declare_war_on_all():  # pylint: disable=invalid-name
    """Used to declare war on all other empires (at start of game)"""
    my_emp_id = fo.empireID()
    for emp_id in fo.allEmpireIDs():
        if emp_id != my_emp_id:
            msg = fo.diplomaticMessage(my_emp_id, emp_id, fo.diplomaticMessageType.warDeclaration)
            fo.sendDiplomaticMessage(msg)
Example #3
0
def galaxy_is_sparse():
    setup_data = fo.getGalaxySetupData()
    avg_empire_systems = setup_data.size // len(fo.allEmpireIDs())
    return (setup_data.monsterFrequency <=
            fo.galaxySetupOptionMonsterFreq.veryLow) and (
                (avg_empire_systems >= 40) or
                ((avg_empire_systems >= 35) and
                 (setup_data.shape != fo.galaxyShape.elliptical)))
Example #4
0
def get_empire_detection(empire_id: int) -> float:
    """
    Returns the detection strength for the provided empire ID.

    If passed the ALL_EMPIRES ID, then it returns the max detection strength across
    all empires except for the current AI's empire.
    """
    if empire_id == ALL_EMPIRES:
        return get_max_empire_detection(fo.allEmpireIDs())

    empire = fo.getEmpire(empire_id)
    if empire:
        return empire.getMeter(EmpireMeters.DETECTION_STRENGTH).initial
    else:
        warning(
            "AI failed to retrieve empire ID %d, in game with %d empires." %
            (empire_id, len(fo.allEmpireIDs())))
        return default_empire_detection_strength()
Example #5
0
def _get_enemy_supply_distance_map() -> Mapping[int, int]:
    enemies = [
        fo.getEmpire(_id) for _id in fo.allEmpireIDs() if _id != fo.empireID()
    ]
    distance_to_enemy_supply = {}

    for enemy in enemies:
        if enemy is None:
            error("Got None for enemy empire!")
            continue

        for sys_id, supply_val in enemy.supplyProjections().items():
            distance_to_enemy_supply[sys_id] = min(
                distance_to_enemy_supply.get(sys_id, 999), -supply_val)

    return distance_to_enemy_supply
Example #6
0
def get_empire_detection(empire_id):
    """
    Returns the detection strength for the provided empire ID.

    If passed the ALL_EMPIRES ID, then it returns the max detection strength across
    all empires except for the current AI's empire.

    :rtype: float
    """
    if empire_id == ALL_EMPIRES:
        return get_max_empire_detection(fo.allEmpireIDs())

    empire = fo.getEmpire(empire_id)
    if empire:
        return empire.getMeter(EmpireMeters.DETECTION_STRENGTH).initial
    else:
        warn("AI failed to retrieve empire ID %d, in game with %d empires." % (empire_id, len(fo.allEmpireIDs())))
        return default_empire_detection_strength()
Example #7
0
 def assess_enemy_supply(self):
     """
     Assesses where enemy empires have Supply
     :return:a tuple of 2 dicts, each of which is keyed by system id, and each of which is a list of empire ids
     1st dict-- enemies that actually have supply at this system
     2nd dict-- enemies that have supply within 2 jumps from this system (if they clear obstructions)
     """
     enemy_ids = [_id for _id in fo.allEmpireIDs() if _id != fo.empireID()]
     actual_supply = {}
     near_supply = {}
     for enemy_id in enemy_ids:
         this_enemy = fo.getEmpire(enemy_id)
         if not this_enemy:
             print "Could not retrieve empire for empire id %d" % enemy_id  # do not spam chat_error with this
             continue
         for sys_id in this_enemy.fleetSupplyableSystemIDs:
             actual_supply.setdefault(sys_id, []).append(enemy_id)
         for sys_id, supply_val in this_enemy.supplyProjections().items():
             if supply_val >= -2:
                 near_supply.setdefault(sys_id, []).append(enemy_id)
     return actual_supply, near_supply
Example #8
0
 def assess_enemy_supply(self):
     """
     Assesses where enemy empires have Supply
     :return:a tuple of 2 dicts, each of which is keyed by system id, and each of which is a list of empire ids
     1st dict-- enemies that actually have supply at this system
     2nd dict-- enemies that have supply within 2 jumps from this system (if they clear obstructions)
     """
     enemy_ids = [_id for _id in fo.allEmpireIDs() if _id != fo.empireID()]
     actual_supply = {}
     near_supply = {}
     for enemy_id in enemy_ids:
         this_enemy = fo.getEmpire(enemy_id)
         if not this_enemy:
             print "Could not retrieve empire for empire id %d" % enemy_id  # do not spam chat_error with this
             continue
         for sys_id in this_enemy.fleetSupplyableSystemIDs:
             actual_supply.setdefault(sys_id, []).append(enemy_id)
         for sys_id, supply_val in this_enemy.supplyProjections().items():
             if supply_val >= -2:
                 near_supply.setdefault(sys_id, []).append(enemy_id)
     return actual_supply, near_supply
Example #9
0
def declareWarOnAll():
    my_emp_id = fo.empireID()
    for emp_id in fo.allEmpireIDs():
        if emp_id != my_emp_id:
            msg = fo.diplomaticMessage(my_emp_id, emp_id, fo.diplomaticMessageType.warDeclaration)
            fo.sendDiplomaticMessage(msg)