sc2simulator/scenarioMgr/scenario.py
def addUnit(self, tag=0, newUnit=None, allowDuplicate=False, **attrs):
        """define a unit within a Scenario"""
        ############################################################################
        def genTag(minVal=150):
            usedUnits = self.units
            newTag = random.randint(minVal, c.MAX_TAG) # preselected tag for first unit
            while newTag in usedUnits: # new unit cannot share a tag with a known unit
                newTag = random.randint(minVal, c.MAX_TAG)
            return newTag
        ############################################################################
        if tag:     tag = int(tag) # ensure unit uid is always an integer
        else:       tag = genTag()
        if tag in self.units: # catch possible redundant definitions
            if not allowDuplicate:
                print("WARNING: unit tag %d already exists in %s as %s"%(
                    tag, self, self.units[tag]))
            return
        if newUnit:
            if not isinstance(newUnit, ScenarioUnit):
                newUnit = convertTechUnit(newUnit, tag=tag, **attrs) # allow tech units to be converted into ScenarioUnits too!
        else:
            newUnit = ScenarioUnit(tag)
            newUnit.update(**attrs)
        self.units[tag] = newUnit
        return newUnit
define a unit within a Scenario
define a unit within a Scenario
define a unit within a Scenario
def addUnit(self, tag=0, newUnit=None, allowDuplicate=False, **attrs):
        def genTag(minVal=150):
            usedUnits = self.units
            newTag = random.randint(minVal, c.MAX_TAG) 
            while newTag in usedUnits: 
                newTag = random.randint(minVal, c.MAX_TAG)
            return newTag
        if tag:     tag = int(tag) 
        else:       tag = genTag()
        if tag in self.units: 
            if not allowDuplicate:
                print("WARNING: unit tag %d already exists in %s as %s"%(
                    tag, self, self.units[tag]))
            return
        if newUnit:
            if not isinstance(newUnit, ScenarioUnit):
                newUnit = convertTechUnit(newUnit, tag=tag, **attrs) 
        else:
            newUnit = ScenarioUnit(tag)
            newUnit.update(**attrs)
        self.units[tag] = newUnit
        return newUnit
def addUnit ( self , tag = 0 , newUnit = None , allowDuplicate = False , ** attrs ) : def genTag ( minVal = 150 ) : usedUnits = self . units newTag = random . randint ( minVal , c . MAX_TAG ) while newTag in usedUnits : newTag = random . randint ( minVal , c . MAX_TAG ) return newTag if tag : tag = int ( tag ) else : tag = genTag ( ) if tag in self . units : if not allowDuplicate : print ( "WARNING: unit tag %d already exists in %s as %s" % ( tag , self , self . units [ tag ] ) ) return if newUnit : if not isinstance ( newUnit , ScenarioUnit ) : newUnit = convertTechUnit ( newUnit , tag = tag , ** attrs ) else : newUnit = ScenarioUnit ( tag ) newUnit . update ( ** attrs ) self . units [ tag ] = newUnit return newUnit
define a unit within a Scenario
define a unit within a Scenario
"""define a unit within a Scenario""" ############################################################################ # preselected tag for first unit # new unit cannot share a tag with a known unit ############################################################################ # ensure unit uid is always an integer # catch possible redundant definitions # allow tech units to be converted into ScenarioUnits too!
self
tag
newUnit
allowDuplicate