예제 #1
0
 def _logistics_manager(self):
     for system_id in self.data.mySystems - self.data.myRelevantSystems:
         system = self.db[system_id]
         for fleet_id in set(system.fleets) & self.data.idleFleets:
             fleet = self.db[fleet_id]
             subfleet = tool.getSubfleet(fleet, {1:0, 4:0}, False)
             if len(subfleet):
                 fleet_range = tool.subfleetMarange(self.client, self.db, {1:0, 4:0}, fleet_id)
                 relevant_sys_id = tool.findNearest(self.db, system, self.data.myRelevantSystems, fleet_range)
                 if relevant_sys_id:
                     relevant_sys_id = relevant_sys_id[0]
                     fleet, new_fleet, my_fleets = tool.orderPartFleet(self.client, self.db,
                         {1:0, 4:0}, True, fleet_id, Const.FLACTION_MOVE, relevant_sys_id, None)
                     self.data.idleFleets -= set([fleet_id])
                 else:
                     min_dist = fleet_range
                     min_dist_sys_id = None
                     min_dist_rel = self.data.distanceToRelevance[system_id]
                     for temp_id, dist in self.data.distanceToRelevance.items():
                         temp = self.db[temp_id]
                         distance = math.hypot(temp.x - system.x, temp.y - system.y)
                         if distance < min_dist and dist < min_dist_rel:
                             min_dist = distance
                             min_dist_sys_id = temp_id
                             min_dist_rel = dist
                     if min_dist_sys_id:
                         fleet, new_fleet, my_fleets = tool.orderPartFleet(self.client, self.db,
                             {1:0, 4:0}, True, fleet_id, Const.FLACTION_MOVE, min_dist_sys_id, None)
                         self.data.idleFleets -= set([fleet_id])
예제 #2
0
 def _commence_attack(self, fleet):
     sheet = tool.getFleetSheet(fleet)
     ships = {}
     ships[3] = min(sheet[1], sheet[2], sheet[3])
     ships[1] = ships[2] = ships[3]
     ships[4] = 1
     max_range = tool.subfleetMaxRange(self.client, self.db, ships, fleet.oid)
     nearest_sys_ids = tool.findNearest(self.db, fleet, self.data.enemySystems & self.data.relevantSystems, max_range * 0.45)
     if len(nearest_sys_ids):
         nearestSys = nearest_sys_ids[0]
         tool.orderPartFleet(self.client, self.db, ships, False, fleet.oid, Const.FLACTION_MOVE, nearestSys, None)
예제 #3
0
 def _commence_attack(self, fleet):
     sheet = tool.getFleetSheet(fleet)
     ships = {}
     ships[3] = min(sheet[1], sheet[2], sheet[3])
     ships[1] = ships[2] = ships[3]
     ships[4] = 1
     max_range = tool.subfleetMarange(self.client, self.db, ships, fleet.oid)
     nearest_sys_ids = tool.findNearest(self.db, fleet, self.data.enemySystems & self.data.relevantSystems, max_range * 0.45)
     if len(nearest_sys_ids):
         nearestSys = nearest_sys_ids[0]
         tool.orderPartFleet(self.client, self.db, ships, False, fleet.oid, Const.FLACTION_MOVE, nearestSys, None)
예제 #4
0
파일: ai.py 프로젝트: taislin/outerspace
 def _colonize_free_systems(self, valid_systems, colony_design_id):
     should_repeat = False
     colony_fleets = self.data.myFleetsWithDesign.get(
         colony_design_id, set())
     for fleet_id in copy.copy(colony_fleets & self.data.idleFleets):
         max_range = tool.subfleetMarange(self.client, self.db,
                                          {colony_design_id: 1}, fleet_id)
         nearest = tool.findNearest(self.db, self.db[fleet_id],
                                    valid_systems, max_range)
         if len(nearest) > 0:
             system_id = nearest[0]
             system = self.db[system_id]
             target_id = self._find_best_planet(system.planets)
             fleet, new_fleet, my_fleets = tool.orderPartFleet(
                 self.client, self.db, {colony_design_id: 1}, True,
                 fleet_id, Const.FLACTION_DEPLOY, target_id,
                 colony_design_id)
             self.data.myFleetSheets[fleet_id][colony_design_id] -= 1
             if self.data.myFleetSheets[fleet_id][colony_design_id] == 0:
                 del self.data.myFleetSheets[fleet_id][colony_design_id]
                 colony_fleets.remove(fleet_id)
             else:
                 should_repeat = True
             self.data.freeSystems.remove(system_id)
             valid_systems.remove(system_id)
     return should_repeat
예제 #5
0
 def _recall_to_upgrade(self, service_centers, outdated_fleets, obsolete_designs):
     for fleet in outdated_fleets:
         if fleet.orbiting in service_centers: continue
         subfleet_sheet = {}.fromkeys(obsolete_designs, 0)
         max_range = tool.subfleetMaxRange(self.client, self.db, subfleet_sheet, fleet.oid)
         nearest = tool.findNearest(self.db, fleet, service_centers, max_range)
         if not nearest: continue
         nearest_service = nearest[0]
         fleet, new_fleet, my_fleets = tool.orderPartFleet(self.client, self.db,
             subfleet_sheet, True, fleet.oid, Const.FLACTION_MOVE, nearest_service, None)
예제 #6
0
 def _recall_to_upgrade(self, service_centers, outdated_fleets,
                        obsolete_designs):
     for fleet in outdated_fleets:
         if fleet.orbiting in service_centers: continue
         subfleet_sheet = {}.fromkeys(obsolete_designs, 0)
         max_range = tool.subfleetMarange(self.client, self.db,
                                          subfleet_sheet, fleet.oid)
         nearest = tool.findNearest(self.db, fleet, service_centers,
                                    max_range)
         if not nearest: continue
         nearest_service = nearest[0]
         fleet, new_fleet, my_fleets = tool.orderPartFleet(
             self.client, self.db, subfleet_sheet, True, fleet.oid,
             Const.FLACTION_MOVE, nearest_service, None)
예제 #7
0
 def _colonize_occupied_systems(self, seeder_id):
     seeder_fleets = self.data.myFleetsWithDesign.get(seeder_id, set())
     should_repeat = False
     for fleet_id in copy.copy(seeder_fleets & self.data.idleFleets):
         fleet = self.db[fleet_id]
         orbit_id = fleet.orbiting
         if orbit_id != Const.OID_NONE:
             orbit = self.db[orbit_id]
             if set(orbit.planets) & self.data.freePlanets and orbit_id in self.data.otherSystems:
                 target_id = self._find_best_planet(set(orbit.planets) & self.data.freePlanets)
                 fleet, new_fleet, my_fleets = tool.orderPartFleet(self.client, self.db,
                     {seeder_id:1}, True, fleet_id, Const.FLACTION_DEPLOY, target_id, seeder_id)
                 self.data.myFleetSheets[fleet_id][seeder_id] -= 1
                 if self.data.myFleetSheets[fleet_id][seeder_id] == 0:
                     del self.data.myFleetSheets[fleet_id][seeder_id]
                     seeder_fleets.remove(fleet_id)
     return should_repeat
예제 #8
0
    def _attack_manager(self):
        for fleet_id in self._get_attack_fleets():
            fleet = self.db[fleet_id]
            # send the attack fleet, if in range
            sheet = tool.getFleetSheet(fleet)
            sowers = sheet[4]
            swarmers = min(sheet[1], math.ceil(sowers * 1.5))
            max_range = 0.8 * tool.subfleetMarange(self.client, self.db, {1:swarmers, 4:sowers}, fleet_id)
            # four nearest systems are considered, with probability to be chosen based on order
            nearest = tool.findNearest(self.db, fleet, self.data.enemySystems, max_range, 4)
            if len(nearest):
                # range is adjusted to flatten probabilities a bit
                probability_map = map(lambda x: x ** 2, range(2 + len(nearest), 2, -1))
                target = Utils.weightedRandom(nearest, probability_map)

                fleet, new_fleet, my_fleets = tool.orderPartFleet(self.client, self.db,
                    {1:swarmers, 4:sowers}, True,
                    fleet_id, Const.FLACTION_MOVE, target, None)
예제 #9
0
파일: ai.py 프로젝트: ospaceteam/outerspace
 def _explore(self, explorer_design_id):
     should_repeat = False
     explorer_fleets = self.data.myFleetsWithDesign.get(explorer_design_id, set())
     for fleet_id in copy.copy(explorer_fleets & self.data.idleFleets):
         max_range = tool.subfleetMaxRange(self.client, self.db, {explorer_design_id:1}, fleet_id)
         nearest = tool.findNearest(self.db, self.db[fleet_id], self.data.unknownSystems, max_range)
         if len(nearest) > 0:
             system_id = nearest[0]
             # send the fleet
             fleet, new_fleet, my_fleets = tool.orderPartFleet(self.client, self.db,
                 {explorer_design_id:1}, True, fleet_id, Const.FLACTION_MOVE, system_id, None)
             self.data.myFleetSheets[fleet_id][explorer_design_id] -= 1
             if self.data.myFleetSheets[fleet_id][explorer_design_id] == 0:
                 del self.data.myFleetSheets[fleet_id][explorer_design_id]
                 explorer_fleets.remove(fleet_id)
             else:
                 should_repeat = True
             self.data.unknownSystems.remove(system_id)
     return should_repeat
예제 #10
0
파일: ai.py 프로젝트: ospaceteam/outerspace
 def _colonize_free_systems(self, valid_systems, colony_design_id):
     should_repeat = False
     colony_fleets = self.data.myFleetsWithDesign.get(colony_design_id, set())
     for fleet_id in copy.copy(colony_fleets & self.data.idleFleets):
         max_range = tool.subfleetMaxRange(self.client, self.db, {colony_design_id:1}, fleet_id)
         nearest = tool.findNearest(self.db, self.db[fleet_id], valid_systems, max_range)
         if len(nearest) > 0:
             system_id = nearest[0]
             system = self.db[system_id]
             target_id = self._find_best_planet(system.planets)
             fleet, new_fleet, my_fleets = tool.orderPartFleet(self.client, self.db,
                 {colony_design_id:1}, True, fleet_id, Const.FLACTION_DEPLOY, target_id, colony_design_id)
             self.data.myFleetSheets[fleet_id][colony_design_id] -= 1
             if self.data.myFleetSheets[fleet_id][colony_design_id] == 0:
                 del self.data.myFleetSheets[fleet_id][colony_design_id]
                 colony_fleets.remove(fleet_id)
             else:
                 should_repeat = True
             self.data.freeSystems.remove(system_id)
             valid_systems.remove(system_id)
     return should_repeat
예제 #11
0
파일: ai.py 프로젝트: taislin/outerspace
 def _explore(self, explorer_design_id):
     should_repeat = False
     explorer_fleets = self.data.myFleetsWithDesign.get(
         explorer_design_id, set())
     for fleet_id in copy.copy(explorer_fleets & self.data.idleFleets):
         max_range = tool.subfleetMarange(self.client, self.db,
                                          {explorer_design_id: 1}, fleet_id)
         nearest = tool.findNearest(self.db, self.db[fleet_id],
                                    self.data.unknownSystems, max_range)
         if len(nearest) > 0:
             system_id = nearest[0]
             # send the fleet
             fleet, new_fleet, my_fleets = tool.orderPartFleet(
                 self.client, self.db, {explorer_design_id: 1}, True,
                 fleet_id, Const.FLACTION_MOVE, system_id, None)
             self.data.myFleetSheets[fleet_id][explorer_design_id] -= 1
             if self.data.myFleetSheets[fleet_id][explorer_design_id] == 0:
                 del self.data.myFleetSheets[fleet_id][explorer_design_id]
                 explorer_fleets.remove(fleet_id)
             else:
                 should_repeat = True
             self.data.unknownSystems.remove(system_id)
     return should_repeat