Ejemplo n.º 1
0
 def research_manager(self, weighted_techs):
     """ weighted_techs is dictionary, with weight:list_of_techs pairs
     """
     if len(self.player.rsrchQueue) >= 2:
         return
     researchable = self._get_researchable()
     weights = []
     tech_choices = []
     for weight, techs in weighted_techs.iteritems():
         for tech in researchable.intersection(techs):
             weights.append(weight)
             tech_choices.append(tech)
     if sum(weights):
         tech = Utils.weightedRandom(tech_choices, weights)
         self.player.rsrchQueue = self.client.cmdProxy.startResearch(self.player.oid, tech)
Ejemplo n.º 2
0
 def research_manager(self, weighted_techs):
     """ weighted_techs is dictionary, with weight:list_of_techs pairs
     """
     if len(self.player.rsrchQueue) >= 2:
         return
     researchable = self._get_researchable()
     weights = []
     tech_choices = []
     for weight, techs in weighted_techs.iteritems():
         for tech in researchable.intersection(techs):
             weights.append(weight)
             tech_choices.append(tech)
     if sum(weights):
         tech = Utils.weightedRandom(tech_choices, weights)
         self.player.rsrchQueue = self.client.cmdProxy.startResearch(
             self.player.oid, tech)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def _get_attack_fleets(self):
     attack_fleets = set()
     for fleet_id in copy.copy(self.data.myFleets):
         fleet = self.db.get(fleet_id, None)
         # minimal size of attack fleet is determined by size of originating system - larger
         # more developed systems will stage stronger attack fleets
         try:
             system = self.db[fleet.orbiting]
         except KeyError:
             # this fleet is not on orbit, set legacy value
             minimum = 12
         else:
             minimum = self._system_worthiness(system, [8,5,3,2]) + 10
         if getattr(fleet, 'target', Const.OID_NONE) == Const.OID_NONE and getattr(fleet, 'ships', []):
             # this also covers fleets fighting over enemy systems - in that case, there
             # is slight chance the fleet will continue to the next system without conquering
             # the system first
             if fleet.orbiting in self.data.enemySystems and Utils.weightedRandom([True, False], [9,1]):
                 continue
             if tool.fleetContains(fleet, {1:minimum, 4:minimum}):
                 attack_fleets.add(fleet_id)
     return attack_fleets
Ejemplo n.º 5
0
    def _system_manager(self):
        for planet_id in self.data.myPlanets:
            tool.sortStructures(self.client, self.db, planet_id)
        for system_id in self.data.mySystems:
            system = self.db[system_id]
            # creation of final system plans
            system_blueprint = self._create_system_blueprint(system)
            idle_planets = tool.buildSystem(self.data, self.client, self.db, system_id, self.data.myProdPlanets & set(system.planets), system_blueprint)
            # rest of the planets build ships
            # first get all our ships in the system
            system_fleet = {}
            for fleet_id in getattr(system, 'fleets', []):
                fleet = self.db[fleet_id]
                if getattr(fleet, 'owner', Const.OID_NONE) == self.player.oid:
                    system_fleet = Utils.dictAddition(system_fleet, tool.getFleetSheet(fleet))
            hasSeeders = False
            hasSeekers = False
            try:
                if system_fleet[2] >= 2: hasSeeders = True
            except KeyError:
                pass
            try:
                if system_fleet[3] >= 2: hasSeekers = True
            except KeyError:
                pass
            # this variable will gather how valuable system is in regards of fighter defense
            # in general, mutant has quite significant planetary defense, so our target is
            # to have only about 10 % production spend on support
            fighters_to_defend = self._system_worthiness(system, [15,8,5,3])

            for planet_id in idle_planets:
                planet = self.db[planet_id]
                shipDraw = random.randint(1, 10)
                if (not hasSeeders or not hasSeekers) and shipDraw < 9:
                    # there is 20% chance it won't build civilian ships, but military one
                    if not hasSeeders:
                        planet.prodQueue, self.player.stratRes = self.client.cmdProxy.startConstruction(planet_id, 2, 1, planet_id, True, False, Const.OID_NONE)
                        continue
                    elif not hasSeekers:
                        planet.prodQueue, self.player.stratRes = self.client.cmdProxy.startConstruction(planet_id, 3, 1, planet_id, True, False, Const.OID_NONE)
                        continue
                # rest is creation of ships based on current state + expected guard fighters
                try:
                    fighters = system_fleet[1]
                except KeyError:
                    fighters = 0
                try:
                    bombers = system_fleet[4]
                except KeyError:
                    bombers = 0
                expected_fighters = bombers * 1.5 + fighters_to_defend
                weight_fighter = 3
                weight_bomber = 2
                if expected_fighters > fighters:
                    # we have to build more fighters
                    weight_fighter += 1
                elif expected_fighters < fighters:
                    # we have too many fighters - let's prefer bombers for now
                    weight_bomber += 1
                choice = Utils.weightedRandom([1,4], [weight_fighter, weight_bomber])
                planet.prodQueue, self.player.stratRes = self.client.cmdProxy.startConstruction(planet_id, choice, 2, planet_id, True, False, Const.OID_NONE)