sc2simulator/scenarioMgr/bank.py
def initPlayers(self):
        """all players must define their initial starting positions and races"""
        ########################################################################
        def findUnitRace(unit):
            """locate the race in predefined data of unit given its name"""
            name = unit.nametype
            for race, data in codeMap.items():
                for uType, codes in data.items():
                    for code, target in codes.items():
                        if name != target:  continue
                        unit.code = code # also update the unit's code type
                        return race
            print("WARNING: failed to locate the race of unit '%s'."%name)
            return None
        ########################################################################
        unitsToIgnore = { # ignore these units which are saved in the XML, but not placed
            "BroodlingEscort",
            "Broodling",
        }
        for s in self.scenarios.values():
            for u in list(s.units.values()):
                if u.nametype in unitsToIgnore:
                      del s.units[u.tag] # unit is ignored
                else: u.tag = 0 # unit tag is reset for general use
            for p in s.players.values():
                if p.position == None: # player's location is not already defined
                    units = p.units
                    x, y = (0, 0)
                    for u in units:
                        uX, uY = u.position[:2]
                        x += uX
                        y += uY
                    numUnits = len(units)
                    p.position = (x / numUnits, y / numUnits) # average position is calculated as the player's starting location
                if p.race == None: # pick the appropriate race for this player
                    allowed = list(c.types.ActualRaces.ALLOWED_TYPES)
                    try:    allowed.remove(None)
                    except: pass
                    allowed = dict(zip(allowed, [0]*len(allowed))) # unit counter is initialized
                    for u in p.units:
                        race = findUnitRace(u)
                        if race:
                            allowed[race] += 1
                    count, p.race = max([
                        (count, r) for r, count in allowed.items()
                    ])
all players must define their initial starting positions and races
all players must define their initial starting positions and races
all players must define their initial starting positions and races
def initPlayers(self):
        def findUnitRace(unit):
            name = unit.nametype
            for race, data in codeMap.items():
                for uType, codes in data.items():
                    for code, target in codes.items():
                        if name != target:  continue
                        unit.code = code 
                        return race
            print("WARNING: failed to locate the race of unit '%s'."%name)
            return None
        unitsToIgnore = { 
            "BroodlingEscort",
            "Broodling",
        }
        for s in self.scenarios.values():
            for u in list(s.units.values()):
                if u.nametype in unitsToIgnore:
                      del s.units[u.tag] 
                else: u.tag = 0 
            for p in s.players.values():
                if p.position == None: 
                    units = p.units
                    x, y = (0, 0)
                    for u in units:
                        uX, uY = u.position[:2]
                        x += uX
                        y += uY
                    numUnits = len(units)
                    p.position = (x / numUnits, y / numUnits) 
                if p.race == None: 
                    allowed = list(c.types.ActualRaces.ALLOWED_TYPES)
                    try:    allowed.remove(None)
                    except: pass
                    allowed = dict(zip(allowed, [0]*len(allowed))) 
                    for u in p.units:
                        race = findUnitRace(u)
                        if race:
                            allowed[race] += 1
                    count, p.race = max([
                        (count, r) for r, count in allowed.items()
                    ])
def initPlayers ( self ) : def findUnitRace ( unit ) : """locate the race in predefined data of unit given its name""" name = unit . nametype for race , data in codeMap . items ( ) : for uType , codes in data . items ( ) : for code , target in codes . items ( ) : if name != target : continue unit . code = code return race print ( "WARNING: failed to locate the race of unit '%s'." % name ) return None unitsToIgnore = { "BroodlingEscort" , "Broodling" , } for s in self . scenarios . values ( ) : for u in list ( s . units . values ( ) ) : if u . nametype in unitsToIgnore : del s . units [ u . tag ] else : u . tag = 0 for p in s . players . values ( ) : if p . position == None : units = p . units x , y = ( 0 , 0 ) for u in units : uX , uY = u . position [ : 2 ] x += uX y += uY numUnits = len ( units ) p . position = ( x / numUnits , y / numUnits ) if p . race == None : allowed = list ( c . types . ActualRaces . ALLOWED_TYPES ) try : allowed . remove ( None ) except : pass allowed = dict ( zip ( allowed , [ 0 ] * len ( allowed ) ) ) for u in p . units : race = findUnitRace ( u ) if race : allowed [ race ] += 1 count , p . race = max ( [ ( count , r ) for r , count in allowed . items ( ) ] )
all players must define their initial starting positions and races
all players must define their initial starting positions and races
"""all players must define their initial starting positions and races""" ######################################################################## """locate the race in predefined data of unit given its name""" # also update the unit's code type ######################################################################## # ignore these units which are saved in the XML, but not placed # unit is ignored # unit tag is reset for general use # player's location is not already defined # average position is calculated as the player's starting location # pick the appropriate race for this player # unit counter is initialized
self