コード例 #1
0
ファイル: Ring_World.py プロジェクト: AP-ML/DTM
def findStartingPlot(argsList):
	[playerID] = argsList

	def isValid(playerID, x, y):

		return true

	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #2
0
def findStartingPlot(argsList):
    [playerID] = argsList

    def isValid(playerID, x, y):

        return true

    return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #3
0
def findStartingPlot(argsList):
    [playerID] = argsList

    def isValid(playerID, x, y):
        map = CyMap()
        pPlot = map.plot(x, y)

        if (pPlot.getArea() != map.findBiggestArea(False).getID()):
            return False

        return True

    return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #4
0
def findStartingPlot(argsList):
	[playerID] = argsList

	def isValid(playerID, x, y):
		map = CyMap()
		pPlot = map.plot(x, y)
		
		if (pPlot.getArea() != map.findBiggestArea(False).getID()):
			return False

		return True
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #5
0
def findStartingPlot(argsList):
    [playerID] = argsList

    def isValid(playerID, x, y):
        global isTeamGame
        map = CyMap()
        pPlot = map.plot(x, y)

        pWaterArea = pPlot.waterArea()
        if (pWaterArea.isNone()):
            return false
        return not pWaterArea.isLake()

    return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #6
0
def findStartingPlot(argsList):
	[playerID] = argsList

	def isValid(playerID, x, y):
		global isTeamGame
		map = CyMap()
		pPlot = map.plot(x, y)

		pWaterArea = pPlot.waterArea()
		if (pWaterArea.isNone()):
			return false
		return not pWaterArea.isLake()
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #7
0
def findStartingPlot(argsList):
	[playerID] = argsList

	def isValid(playerID, x, y):
		
		if x <45:
			return False
  
		if x >81:
			return False

		return True
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #8
0
def findStartingPlot(argsList):
	# Set up for maximum of 18 players! If more, use default implementation.
	global bSuccessFlag
	if bSuccessFlag == False:
		return CvMapGeneratorUtil.findStartingPlot(playerID, true)
		
	[playerID] = argsList

	def isValid(playerID, x, y):
		gc = CyGlobalContext()
		map = CyMap()
		pPlot = map.plot(x, y)
		# Check to ensure the plot is on the main landmass.
		if (pPlot.getArea() != map.findBiggestArea(False).getID()):
			return false

		iW = map.getGridWidth()
		iH = map.getGridHeight()
		iPlayers = gc.getGame().countCivPlayersEverAlive()
		global start_plots
		global iPlotShift
		global shuffledPlayers
		playerTemplateAssignment = shuffledPlayers[playerID]
		[iStartX, iStartY] = start_plots[playerTemplateAssignment]
		
		# Now check for eligibility according to the defintions found in the template.
		westX = max(2, iStartX - iPlotShift)
		eastX = min(iW - 3, iStartX + iPlotShift)
		southY = max(2, iStartY - iPlotShift)
		northY = min(iH - 3, iStartY + iPlotShift)
		if x < westX or x > eastX or y < southY or y > northY:
			return false
		else:
			return true

	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #9
0
def findStartingPlot(argsList):
    # This function is only called for Snaky Continents (or if an entire region should fail to produce a valid start plot via the regional method).
    [playerID] = argsList

    # Check to see if a region failed. If so, try the default implementation. (The rest of this process could get stuck in an infinite loop, so don't risk it!)
    global bSuccessFlag
    if bSuccessFlag == False:
        CyPythonMgr().allowDefaultImpl()
        return

    # Identify the best land area available to this player.
    global areas
    global area_values
    global iBestArea
    gc = CyGlobalContext()
    map = CyMap()
    iBestValue = 0
    iBestArea = -1
    areas = CvMapGeneratorUtil.getAreas()

    for area in areas:
        if area.isWater(): continue  # Don't want to start "in the drink"!
        iNumPlayersOnArea = area.getNumStartingPlots(
        ) + 1  # Number of players starting on the area, plus this player.

        iTileValue = area.calculateTotalBestNatureYield(
        ) + area.getNumRiverEdges(
        ) + 2 * area.countCoastalLand() + 3 * area.countNumUniqueBonusTypes()
        iValue = iTileValue / iNumPlayersOnArea
        if (iNumPlayersOnArea == 1):
            iValue *= 4
            iValue /= 3
        if (iValue > iBestValue):
            iBestValue = iValue
            iBestArea = area.getID()

    # Ensure that starting plot is in chosen Area and is along the coast.
    def isValid(playerID, x, y):
        global iBestArea
        pPlot = CyMap().plot(x, y)
        if pPlot.getArea() != iBestArea:
            return false
        pWaterArea = pPlot.waterArea()
        if (pWaterArea.isNone()):
            return false
        return not pWaterArea.isLake()

    return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #10
0
def findStartingPlot(argsList):
	"""
	Find starting plot for a certain player. Civilizations are only allowed to start in the main continent or in the
	counterweight continent.
	:param argsList: List that contains the playerID of the player.
	:return: Starting plot
	"""
	[playerID] = argsList

	def isInsidePlayableRegion(pID, iX, iY):
		global lStartingPlotAreas
		for mapAreaPolygon in lStartingPlotAreas:
			if mapAreaPolygon.isInside(iX, iY):
				return True

		return False

	return CvMapGeneratorUtil.findStartingPlot(playerID, isInsidePlayableRegion)
コード例 #11
0
def findStartingPlot(argsList):
	# This function is only called for Snaky Continents (or if an entire region should fail to produce a valid start plot via the regional method).
	[playerID] = argsList

	# Check to see if a region failed. If so, try the default implementation. (The rest of this process could get stuck in an infinite loop, so don't risk it!)
	global bSuccessFlag
	if bSuccessFlag == False:
		CyPythonMgr().allowDefaultImpl()
		return
	
	# Identify the best land area available to this player.
	global areas
	global area_values
	global iBestArea
	gc = CyGlobalContext()
	map = CyMap()
	iBestValue = 0
	iBestArea = -1
	areas = CvMapGeneratorUtil.getAreas()
	
	for area in areas:
		if area.isWater(): continue # Don't want to start "in the drink"!
		iNumPlayersOnArea = area.getNumStartingPlots() + 1 # Number of players starting on the area, plus this player.
		
		iTileValue = area.calculateTotalBestNatureYield() + area.getNumRiverEdges() + 2 * area.countCoastalLand() + 3 * area.countNumUniqueBonusTypes()
		iValue = iTileValue / iNumPlayersOnArea
		if (iNumPlayersOnArea == 1):
			iValue *= 4; iValue /= 3
		if (iValue > iBestValue):
			iBestValue = iValue
			iBestArea = area.getID()

	# Ensure that starting plot is in chosen Area and is along the coast.
	def isValid(playerID, x, y):
		global iBestArea
		pPlot = CyMap().plot(x, y)
		if pPlot.getArea() != iBestArea:
			return false
		pWaterArea = pPlot.waterArea()
		if (pWaterArea.isNone()):
			return false
		return not pWaterArea.isLake()
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #12
0
def findStartingPlot(argsList):
	[playerID] = argsList

	def isValid(playerID, x, y):
		global isTeamGame
		map = CyMap()
		pPlot = map.plot(x, y)

		if (pPlot.getArea() != map.findBiggestArea(False).getID()):
			return false

		if isTeamGame:
			pWaterArea = pPlot.waterArea()
			if (pWaterArea.isNone()):
				return false
			return not pWaterArea.isLake()
		else:
			return true
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #13
0
def findStartingPlot(argsList):
	[playerID] = argsList

	def isValid(playerID, x, y):
		global isTeamGame
		map = CyMap()
		pPlot = map.plot(x, y)

		if (pPlot.getArea() != map.findBiggestArea(False).getID()):
			return false

		if isTeamGame:
			pWaterArea = pPlot.waterArea()
			if (pWaterArea.isNone()):
				return false
			return not pWaterArea.isLake()
		else:
			return true

	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #14
0
def findStartingPlot(argsList):
	[playerID] = argsList

	def isValid(playerID, x, y):
		teamID = CyGlobalContext().getPlayer(playerID).getTeam()
		iH = CyMap().getGridHeight()
		
		if int(teamID/2) * 2 == teamID: # Even-numbered team.
			isOdd = False
		else:
			isOdd = True
		
		if isOdd and y >= iH * 0.7:
			return true
		
		if not isOdd and y <= iH * 0.3:
			return true
			
		return false
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #15
0
def findStartingPlot(argsList):
    [playerID] = argsList

    def isValid(playerID, x, y):
        global am
        global am2
        global newWorldID

        if am == None:
            setupAreaMap()
        if am.areaMap[am.getIndex(x, y)] == newWorldID:
            return False

        #also disallow starting on small islands
        if am2 == None:
            setupAreaMap2()
        if am2.getAreaByID(am2.areaMap[am2.getIndex(x, y)]).size < 70:
            return False

        return True

    return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #16
0
def findStartingPlot(argsList):
    gc = CyGlobalContext()
    map = CyMap()
    dice = gc.getGame().getMapRand()
    iPlayers = gc.getGame().countCivPlayersEverAlive()
    areas = CvMapGeneratorUtil.getAreas()
    areaValue = [0] * map.getIndexAfterLastArea()

    isolatedStarts = false
    userInputLandmass = CyMap().getCustomMapOption(0)
    if (userInputLandmass == 4):  #                 "Islands"
        isolatedStarts = true

    if iPlayers < 2 or iPlayers > 18:
        bSuccessFlag = False
        CyPythonMgr().allowDefaultImpl()
        return

    for area in areas:
        if area.isWater(): continue
        areaValue[area.getID(
        )] = area.calculateTotalBestNatureYield() + area.getNumRiverEdges(
        ) + 2 * area.countCoastalLand() + 3 * area.countNumUniqueBonusTypes()

    # Shuffle players so the same player doesn't always get the first pick.
    player_list = []
    for plrCheckLoop in range(18):
        if CyGlobalContext().getPlayer(plrCheckLoop).isEverAlive():
            player_list.append(plrCheckLoop)
    shuffledPlayers = []
    for playerLoop in range(iPlayers):
        iChoosePlayer = dice.get(len(player_list),
                                 "Shuffling Players - Highlands PYTHON")
        shuffledPlayers.append(player_list[iChoosePlayer])
        del player_list[iChoosePlayer]

    # Loop through players, assigning starts for each.
    for assign_loop in range(iPlayers):
        playerID = shuffledPlayers[assign_loop]
        player = gc.getPlayer(playerID)
        bestAreaValue = 0
        global bestArea
        bestArea = None
        for area in areas:
            if area.isWater(): continue
            players = 2 * area.getNumStartingPlots()
            #Avoid single players on landmasses:
            if (false == isolatedStarts and players == 0):
                if (assign_loop == iPlayers - 1):
                    players = 4
                else:
                    players = 2
            value = areaValue[area.getID()] / (1 +
                                               2 * area.getNumStartingPlots())
            if (value > bestAreaValue):
                bestAreaValue = value
                bestArea = area

        def isValid(playerID, x, y):
            global bestArea
            plot = CyMap().plot(x, y)
            if (plot.getArea() != bestArea):
                return false
            if (self.getLatitudeAtPlot(x, y) >= 75):
                return false
            return true

        findstart = CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
        sPlot = map.plotByIndex(findstart)
        player.setStartingPlot(sPlot, true)


#	return None
    return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #17
0
def findStartingPlot(argsList):
    [playerID] = argsList
    global assignedPlayers
    global team_num
    thisTeamID = CyGlobalContext().getPlayer(playerID).getTeam()
    teamID = team_num[thisTeamID]

    assignedPlayers[teamID] += 1

    def isValid(playerID, x, y):
        global biggest_areas
        global terrainRoll
        userInputTerrain = CyMap().getCustomMapOption(2)
        if userInputTerrain < 3 or (userInputTerrain == 5 and terrainRoll < 6):
            pPlot = CyMap().plot(x, y)
            areaID = pPlot.getArea()
            if areaID not in biggest_areas:
                return false

        map = CyMap()
        numTeams = CyGlobalContext().getGame().countCivTeamsAlive()
        if numTeams > 4 or numTeams < 2:  # Put em anywhere, and let the normalizer sort em out.
            return true
        userInputProximity = map.getCustomMapOption(1)
        if userInputProximity == 2:  # Start anywhere!
            return true
        global shuffle
        global shuffledTeams
        global team_num
        thisTeamID = CyGlobalContext().getPlayer(playerID).getTeam()
        teamID = team_num[thisTeamID]
        iW = map.getGridWidth()
        iH = map.getGridHeight()

        # Two Teams, Start Together
        if numTeams == 2 and userInputProximity == 0:  # Two teams, Start Together
            if teamID == 0 and shuffle and x >= iW * 0.6:
                return true
            if teamID == 1 and not shuffle and x >= iW * 0.6:
                return true
            if teamID == 0 and not shuffle and x <= iW * 0.4:
                return true
            if teamID == 1 and shuffle and x <= iW * 0.4:
                return true
            return false

        # Three or Four Teams
        elif (numTeams == 3 or numTeams == 4
              ) and userInputProximity == 0:  # 3 or 4 teams, Start Together
            corner = shuffledTeams[teamID]
            if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
                return true
            if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
                return true
            if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
                return true
            if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
                return true
            return false
        elif (numTeams == 3 or numTeams == 4
              ) and userInputProximity == 1:  # 3 or 4 teams, Start Separated
            corner = shuffledTeams[teamID] + assignedPlayers[teamID]
            while corner >= 4:
                corner -= 4
            if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
                return true
            if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
                return true
            if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
                return true
            if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
                return true
            return false

        # Two Teams, Start Separated
        elif numTeams == 2 and userInputProximity == 1:  # Two teams, Start Separated
            if (shuffle and teamID == 0) or (not shuffle and teamID == 1):
                side = assignedPlayers[teamID]
            else:
                side = 1 + assignedPlayers[teamID]
            while side >= 2:
                side -= 2
            if teamID == 0 and side and x >= iW * 0.6:
                return true
            if teamID == 1 and not side and x >= iW * 0.6:
                return true
            if teamID == 0 and not side and x <= iW * 0.4:
                return true
            if teamID == 1 and side and x <= iW * 0.4:
                return true
            return false

        # All conditions have failed? Wow. Is that even possible? :)
        return true

    return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #18
0
def assignStartingPlots():
    gc = CyGlobalContext()
    dice = gc.getGame().getMapRand()
    global shuffle
    global shuffledTeams
    global assignedPlayers
    assignedPlayers = [0] * gc.getGame().countCivTeamsEverAlive()
    print assignedPlayers
    shuffle = gc.getGame().getMapRand().get(2,
                                            "Start Location Shuffle - PYTHON")
    if gc.getGame().countCivTeamsEverAlive() < 5:
        team_list = [0, 1, 2, 3]
        shuffledTeams = []
        for teamLoop in range(gc.getGame().countCivTeamsEverAlive()):
            iChooseTeam = dice.get(len(team_list),
                                   "Shuffling Regions - TBG PYTHON")
            shuffledTeams.append(team_list[iChooseTeam])
            del team_list[iChooseTeam]

    # For Lakes and Continents settings, ensure that starts are all placed on the biggest landmass on each side.
    global biggest_areas
    biggest_areas = []
    areas = CvMapGeneratorUtil.getAreas()
    area_sizes = [(area.getNumTiles(), area.getID()) for area in areas
                  if not area.isWater()]
    area_sizes.sort()  # sort by size -- biggest areas last.

    # pop the biggest two areas off the list.
    area_size, area_ID = area_sizes.pop()
    biggest_areas.append(area_ID)
    if area_sizes != []:
        area_size, area_ID = area_sizes.pop()
        biggest_areas.append(area_ID)

    # First check to see if teams chose to "Start Separated" or "Start Anywhere".
    map = CyMap()
    userInputProximity = map.getCustomMapOption(1)
    if userInputProximity == 1:  # Teams set to Start Separated. Use default impl.
        CyPythonMgr().allowDefaultImpl()
        return

    # Shuffle the players.
    global playersOnTeamOne
    global playersOnTeamTwo
    iPlayers = gc.getGame().countCivPlayersEverAlive()
    playersOnTeamOne = []
    playersOnTeamTwo = []

    player_list = []
    for plrCheckLoop in range(18):
        if CyGlobalContext().getPlayer(plrCheckLoop).isEverAlive():
            player_list.append(plrCheckLoop)
    shuffledPlayers = []
    for playerLoopTwo in range(iPlayers):
        iChoosePlayer = dice.get(len(player_list),
                                 "Shuffling Player Order - Mirror PYTHON")
        shuffledPlayers.append(player_list[iChoosePlayer])
        del player_list[iChoosePlayer]

    if userInputProximity == 2:  # Teams set to Start Anywhere!

        def isValidToStartAnywhere(playerID, x, y):
            global biggest_areas
            global terrainRoll
            userInputTerrain = CyMap().getCustomMapOption(2)
            if userInputTerrain < 3 or (userInputTerrain == 5
                                        and terrainRoll < 6):
                pPlot = CyMap().plot(x, y)
                areaID = pPlot.getArea()
                if areaID not in biggest_areas:
                    return false
            return true

        # Since the default alternates by team, must use the shuffled players list to assign starting locs.
        # This will provide a truly random order, which may or may not be "fair". But hey, starting anywhere means ANYwhere. OK?
        for playerID in shuffledPlayers:
            player = gc.getPlayer(playerID)
            startPlot = CvMapGeneratorUtil.findStartingPlot(
                playerID, isValidToStartAnywhere)
            sPlot = map.plotByIndex(startPlot)
            player.setStartingPlot(sPlot, true)
        # All done.
        return None

    # OK, so the teams have chosen to Start Together.
    #
    # Check for the special case of two teams with even players.
    # If found, force perfect mirrorization of start plots!
    #
    # (This is necessary because the default start plot process
    # resolves "ties" differently on each side due to minor
    # differences in the order of operations. Odd but true!)
    #
    iTeams = gc.getGame().countCivTeamsEverAlive()
    if iTeams != 2:
        CyPythonMgr().allowDefaultImpl()
        return
    team_one = gc.getTeam(0)
    team_two = gc.getTeam(1)
    if team_one.getNumMembers() != team_two.getNumMembers():
        CyPythonMgr().allowDefaultImpl()
        return

    # We are dealing with two teams who are evenly matched.
    # Assign all start plots for the first team, then mirrorize the locations for the second team!
    # Start by determining which players are on which teams.
    for iLoop in range(iPlayers):
        thisPlayerID = shuffledPlayers[iLoop]
        this_player = gc.getPlayer(thisPlayerID)
        teamID = gc.getPlayer(thisPlayerID).getTeam()
        print("Player: ", thisPlayerID, " Team: ", teamID)
        if teamID == 1:
            playersOnTeamTwo.append(shuffledPlayers[iLoop])
        else:
            playersOnTeamOne.append(shuffledPlayers[iLoop])

    # Now we pick a team to assign to the left side and assign them there.
    userInputPlots = map.getCustomMapOption(0)
    iW = map.getGridWidth()
    iH = map.getGridHeight()
    if userInputPlots == 0:  # Reflection
        reflect_x = lambda x: iW - iX - 1
        reflect_y = lambda y: iY
    elif userInputPlots == 1:  # Inversion
        reflect_x = lambda x: iW - iX - 1
        reflect_y = lambda y: iH - iY - 1
    elif userInputPlots == 2:  # Copy
        reflect_x = lambda x: iX + (iW / 2)
        reflect_y = lambda y: iY
    else:  # userInputPlots == 3: Opposite
        reflect_x = lambda x: iX + (iW / 2)
        reflect_y = lambda y: iH - iY - 1

    def isValidForMirror(playerID, x, y):
        global biggest_areas
        global terrainRoll
        userInputTerrain = CyMap().getCustomMapOption(2)
        if userInputTerrain < 3 or (userInputTerrain == 5 and terrainRoll < 6):
            pPlot = CyMap().plot(x, y)
            areaID = pPlot.getArea()
            if areaID not in biggest_areas:
                return false

        userInputPlots = CyMap().getCustomMapOption(0)
        iPlayers = CyGlobalContext().getGame().countCivPlayersEverAlive()
        teamID = CyGlobalContext().getPlayer(playerID).getTeam()
        iW = CyMap().getGridWidth()

        # Two Evenly-Matched Teams, Start Together
        if iPlayers > 2 and userInputPlots <= 1 and x <= iW * 0.4:
            return true
        if iPlayers > 2 and userInputPlots >= 2 and x >= iW * 0.1 and x <= iW * 0.4:
            return true
        # 1 vs 1 game, so make sure the players start farther apart!
        if iPlayers == 2 and userInputPlots <= 1 and x <= iW * 0.2:
            return true
        if iPlayers == 2 and userInputPlots >= 2 and x >= iW * 0.2 and x <= iW * 0.3:
            return true
        # if not true, then false! (Duh? Well, the program still has to be told.)
        return false

    if shuffle:  # We will put team two on the left.
        teamOneIndex = 0
        for thisPlayer in playersOnTeamTwo:
            player = gc.getPlayer(thisPlayer)
            startPlot = CvMapGeneratorUtil.findStartingPlot(
                thisPlayer, isValidForMirror)
            sPlot = map.plotByIndex(startPlot)
            player.setStartingPlot(sPlot, true)
            iX = sPlot.getX()
            iY = sPlot.getY()
            mirror_x = reflect_x(iX)
            mirror_y = reflect_y(iY)
            opposite_player = gc.getPlayer(playersOnTeamOne[teamOneIndex])
            oppositePlot = map.plot(mirror_x, mirror_y)
            opposite_player.setStartingPlot(oppositePlot, true)
            teamOneIndex += 1
    else:  # will put team one on the left.
        teamTwoIndex = 0
        for thisPlayer in playersOnTeamOne:
            player = gc.getPlayer(thisPlayer)
            startPlot = CvMapGeneratorUtil.findStartingPlot(
                thisPlayer, isValidForMirror)
            sPlot = map.plotByIndex(startPlot)
            player.setStartingPlot(sPlot, true)
            iX = sPlot.getX()
            iY = sPlot.getY()
            mirror_x = reflect_x(iX)
            mirror_y = reflect_y(iY)
            opposite_player = gc.getPlayer(playersOnTeamTwo[teamTwoIndex])
            oppositePlot = map.plot(mirror_x, mirror_y)
            opposite_player.setStartingPlot(oppositePlot, true)
            teamTwoIndex += 1

    # All done.
    return None
コード例 #19
0
ファイル: DQ3.py プロジェクト: gforestshade/touhou-jojisi-SDK
def findStartingPlot(argsList):
	gc = CyGlobalContext()
	map = CyMap()
	dice = gc.getGame().getMapRand()
	iPlayers = gc.getGame().countCivPlayersEverAlive()
	areas = CvMapGeneratorUtil.getAreas()
	areaValue = [0] * map.getIndexAfterLastArea()	

	isolatedStarts = false
	userInputLandmass = CyMap().getCustomMapOption(0)
	if (userInputLandmass == 4):     #                 "Islands"
		isolatedStarts = true

	if iPlayers < 2 or iPlayers > 18:
		bSuccessFlag = False
		CyPythonMgr().allowDefaultImpl()
		return

	for area in areas:
		if area.isWater(): continue 
		areaValue[area.getID()] = area.calculateTotalBestNatureYield() + area.getNumRiverEdges() + 2 * area.countCoastalLand() + 3 * area.countNumUniqueBonusTypes()

	# Shuffle players so the same player doesn't always get the first pick.
	player_list = []
	for plrCheckLoop in range(18):
		if CyGlobalContext().getPlayer(plrCheckLoop).isEverAlive():
			player_list.append(plrCheckLoop)
	shuffledPlayers = []
	for playerLoop in range(iPlayers):
		iChoosePlayer = dice.get(len(player_list), "Shuffling Players - Highlands PYTHON")
		shuffledPlayers.append(player_list[iChoosePlayer])
		del player_list[iChoosePlayer]

	# Loop through players, assigning starts for each.
	for assign_loop in range(iPlayers):
		playerID = shuffledPlayers[assign_loop]
		player = gc.getPlayer(playerID)
		bestAreaValue = 0
		global bestArea
		bestArea = None
		for area in areas:
			if area.isWater(): continue 
			players = 2*area.getNumStartingPlots()
			#Avoid single players on landmasses:
			if (false == isolatedStarts and players == 0):
				if (assign_loop == iPlayers - 1):
					players = 4
				else:
					players = 2
			value = areaValue[area.getID()] / (1 + 2*area.getNumStartingPlots() )
			if (value > bestAreaValue):
				bestAreaValue = value;
				bestArea = area
		def isValid(playerID, x, y):
			global bestArea
			plot = CyMap().plot(x,y)
			if (plot.getArea() != bestArea):
				return false
			if (self.getLatitudeAtPlot(x,y) >= 75):
				return false
			return true
		findstart = CvMapGeneratorUtil.findStartingPlot(playerID,isValid)
		sPlot = map.plotByIndex(findstart)
		player.setStartingPlot(sPlot,true)
#	return None
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #20
0
def assignStartingPlots():
    # This function borrowed from Highlands. Just as insurance against duds.
    # Lake fill-ins changed to tundra instead of plains.
    # - Sirian - June 2, 2007
    #
    #
    # In order to prevent "pockets" from forming, where civs can be blocked in
    # by Peaks or lakes, causing a "dud" map, pathing must be checked for each
    # new start plot before it hits the map. Any pockets that are detected must
    # be opened. The following process takes care of this need. Soren created a
    # useful function that already lets you know how far a given plot is from
    # the closest nearest civ already on the board. MinOriginalStartDist is that
    # function. You can get-- or setMinoriginalStartDist() as a value attached
    # to each plot. Any value of -1 means no valid land-hills-only path exists to
    # a civ already placed. For Highlands, that means we have found a pocket
    # and it must be opened. A valid legal path from all civs to all other civs
    # is required for this map to deliver reliable, fun games every time.
    #
    # - Sirian - 2005
    #
    gc = CyGlobalContext()
    map = CyMap()
    dice = gc.getGame().getMapRand()
    iW = map.getGridWidth()
    iH = map.getGridHeight()
    iPlayers = gc.getGame().countCivPlayersEverAlive()
    iNumStartsAllocated = 0
    start_plots = []
    print "==="
    print "Number of players:", iPlayers
    print "==="

    terrainTundra = gc.getInfoTypeForString("TERRAIN_TUNDRA")

    # Obtain player numbers. (Account for possibility of Open slots!)
    player_list = []
    for plrCheckLoop in range(18):
        if CyGlobalContext().getPlayer(plrCheckLoop).isEverAlive():
            player_list.append(plrCheckLoop)
            # Shuffle players so that who goes first (and gets the best start location) is randomized.
    shuffledPlayers = []
    for playerLoopTwo in range(gc.getGame().countCivPlayersEverAlive()):
        iChoosePlayer = dice.get(len(player_list), "Shuffling Players - Highlands PYTHON")
        shuffledPlayers.append(player_list[iChoosePlayer])
        del player_list[iChoosePlayer]

        # Loop through players, assigning starts for each.
    for assign_loop in range(iPlayers):
        playerID = shuffledPlayers[assign_loop]
        player = gc.getPlayer(playerID)

        # Use the absolute approach for findStart from CvMapGeneratorUtil, which
        # ignores areaID quality and finds the best local situation on the board.
        findstart = CvMapGeneratorUtil.findStartingPlot(playerID)
        sPlot = map.plotByIndex(findstart)

        # Record the plot number to the data array for use if needed to open a "pocket".
        iStartX = sPlot.getX()
        iStartY = sPlot.getY()

        # If first player placed, no need to check for pathing yet.
        if assign_loop == 0:
            start_plots.append([iStartX, iStartY])
            player.setStartingPlot(
                sPlot, true
            )  # True flag causes data to be refreshed for MinOriginalStartDist data cells in plots on the same land mass.
            print "-+-+-"
            print "Player"
            print playerID
            print "First player assigned."
            print "-+-+-"
            continue

            # Check the pathing in the start plot.
        if sPlot.getMinOriginalStartDist() != -1:
            start_plots.append([iStartX, iStartY])
            player.setStartingPlot(sPlot, true)
            print "-+-+-"
            print "Player"
            print playerID
            print "Open Path, no problems."
            print "-+-+-"
            continue

            # If the process has reached this point, then this player is stuck
            # in a "pocket". This could be an island, a valley surrounded by peaks,
            # or an area blocked off by peaks. Could even be that a major line
            # of peaks and lakes combined is bisecting the entire map.
        print "-----"
        print "Player"
        print playerID
        print "Pocket detected, attempting to resolve..."
        print "-----"
        #
        # First step is to identify which existing start plot is closest.
        print "Pocket Plot"
        print iStartX, iStartY
        print "---"
        [iEndX, iEndY] = start_plots[0]
        fMinDistance = sqrt(((iStartX - iEndX) ** 2) + ((iStartY - iEndY) ** 2))
        for check_loop in range(1, len(start_plots)):
            [iX, iY] = start_plots[check_loop]
            if fMinDistance > sqrt(((iStartX - iX) ** 2) + ((iStartY - iY) ** 2)):
                # Closer start plot found!
                [iEndX, iEndY] = start_plots[check_loop]
                fMinDistance = sqrt(((iStartX - iX) ** 2) + ((iStartY - iY) ** 2))
        print "Nearest player (path destination)"
        print iEndX, iEndY
        print "---"
        print "Absolute distance:"
        print fMinDistance
        print "-----"

        # Now we draw an invisible line, plot by plot, one plot wide, from
        # the current start to the nearest start, converting peaks along the
        # way in to hills, and lakes in to flatlands, until a path opens.

        # Bulldoze the path until it opens!
        startPlot = map.plot(iStartX, iStartY)
        endPlot = map.plot(iEndX, iEndY)
        if abs(iEndY - iStartY) < abs(iEndX - iStartX):
            # line is closer to horizontal
            if iStartX > iEndX:
                startX, startY, endX, endY = iEndX, iEndY, iStartX, iStartY  # swap start and end
                bReverseFlag = True
                print "Path reversed, working from the end plot."
            else:  # don't swap
                startX, startY, endX, endY = iStartX, iStartY, iEndX, iEndY
                bReverseFlag = False
                print "Path not reversed."
            dx = endX - startX
            dy = endY - startY
            if dx == 0 or dy == 0:
                slope = 0
            else:
                slope = float(dy) / float(dx)
            print ("Slope: ", slope)
            y = startY
            for x in range(startX, endX):
                print "Checking plot"
                print x, int(round(y))
                print "---"
                if map.isPlot(x, int(round(y))):
                    i = map.plotNum(x, int(round(y)))
                    pPlot = map.plotByIndex(i)
                    y += slope
                    print ("y plus slope: ", y)
                    if pPlot.isHills() or pPlot.isFlatlands():
                        continue  # on to next plot!
                    if pPlot.isPeak():
                        print "Peak found! Bulldozing this plot."
                        print "---"
                        pPlot.setPlotType(PlotTypes.PLOT_HILLS, true, true)
                        if bReverseFlag:
                            currentDistance = map.calculatePathDistance(pPlot, startPlot)
                        else:
                            currentDistance = map.calculatePathDistance(pPlot, endPlot)
                        if currentDistance != -1:  # The path has been opened!
                            print "Pocket successfully opened!"
                            print "-----"
                            break
                    elif pPlot.isWater():
                        print "Lake found! Filling in this plot."
                        print "---"
                        pPlot.setPlotType(PlotTypes.PLOT_LAND, true, true)
                        pPlot.setTerrainType(terrainTundra, true, true)
                        if pPlot.getBonusType(-1) != -1:
                            print "########################"
                            print "A sea-based Bonus is now present on the land! EEK!"
                            print "########################"
                            pPlot.setBonusType(-1)
                            print "OK, nevermind. The resource has been removed."
                            print "########################"
                        if bReverseFlag:
                            currentDistance = map.calculatePathDistance(pPlot, startPlot)
                        else:
                            currentDistance = map.calculatePathDistance(pPlot, endPlot)
                        if currentDistance != -1:  # The path has been opened!
                            print "Pocket successfully opened!"
                            print "-----"
                            break

        else:
            # line is closer to vertical
            if iStartY > iEndY:
                startX, startY, endX, endY = iEndX, iEndY, iStartX, iStartY  # swap start and end
                bReverseFlag = True
                print "Path reversed, working from the end plot."
            else:  # don't swap
                startX, startY, endX, endY = iStartX, iStartY, iEndX, iEndY
                bReverseFlag = False
                print "Path not reversed."
            dx, dy = endX - startX, endY - startY
            if dx == 0 or dy == 0:
                slope = 0
            else:
                slope = float(dx) / float(dy)
            print ("Slope: ", slope)
            x = startX
            for y in range(startY, endY + 1):
                print "Checking plot"
                print int(round(x)), y
                print "---"
                if map.isPlot(int(round(x)), y):
                    i = map.plotNum(int(round(x)), y)
                    pPlot = map.plotByIndex(i)
                    x += slope
                    print ("x plus slope: ", x)
                    if pPlot.isHills() or pPlot.isFlatlands():
                        continue  # on to next plot!
                    if pPlot.isPeak():
                        print "Peak found! Bulldozing this plot."
                        print "---"
                        pPlot.setPlotType(PlotTypes.PLOT_HILLS, true, true)
                        if bReverseFlag:
                            currentDistance = map.calculatePathDistance(pPlot, startPlot)
                        else:
                            currentDistance = map.calculatePathDistance(pPlot, endPlot)
                        if currentDistance != -1:  # The path has been opened!
                            print "Pocket successfully opened!"
                            print "-----"
                            break
                    elif pPlot.isWater():
                        print "Lake found! Filling in this plot."
                        print "---"
                        pPlot.setPlotType(PlotTypes.PLOT_LAND, true, true)
                        pPlot.setTerrainType(terrainTundra, true, true)
                        if pPlot.getBonusType(-1) != -1:
                            print "########################"
                            print "A sea-based Bonus is now present on the land! EEK!"
                            print "########################"
                            pPlot.setBonusType(-1)
                            print "OK, nevermind. The resource has been removed."
                            print "########################"
                        if bReverseFlag:
                            currentDistance = map.calculatePathDistance(pPlot, startPlot)
                        else:
                            currentDistance = map.calculatePathDistance(pPlot, endPlot)
                        if currentDistance != -1:  # The path has been opened!
                            print "Pocket successfully opened!"
                            print "-----"
                            break

                            # Now that all the pathing for this player is resolved, set the start plot.
        start_plots.append([iStartX, iStartY])
        player.setStartingPlot(sPlot, true)

        # All done!
    print "**********"
    print "All start plots assigned!"
    print "**********"
    return None
コード例 #21
0
def findStartingPlot(argsList):
	[playerID] = argsList
	global assignedPlayers
	global team_num

	map = CyMap()
	userInputPlots = map.getCustomMapOption(0)
	if (userInputPlots == 4   # round
	or  userInputPlots == 5): # donut ... starting position already set - return plotnum
		pPlot = CyGlobalContext().getPlayer(playerID).getStartingPlot()
		return map.plotNum(pPlot.getX(), pPlot.getY())

	thisTeamID = CyGlobalContext().getPlayer(playerID).getTeam()
	teamID = team_num[thisTeamID]
	
	assignedPlayers[teamID] += 1

	def isValid(playerID, x, y):
		map = CyMap()
		numTeams = CyGlobalContext().getGame().countCivTeamsAlive()
		if numTeams > 4 or numTeams < 2: # Put em anywhere, and let the normalizer sort em out.
			return true
		userInputProximity = map.getCustomMapOption(1)
		if userInputProximity == 2: # Start anywhere!
			return true

		global shuffle
		global shuffledTeams
		global team_num
		global shuffledPlayers
		global player_num

		thisTeamID = CyGlobalContext().getPlayer(playerID).getTeam()
		teamID = team_num[thisTeamID]
		userInputPlots = map.getCustomMapOption(0)
		iW = map.getGridWidth()
		iH = map.getGridHeight()

		# Two Teams, Start Together
		if numTeams == 2 and userInputProximity == 0: # Two teams, Start Together
			if userInputPlots == 1: # TvB
				if teamID == 0 and shuffle and y >= iH * 0.6:
					return true
				if teamID == 1 and not shuffle and y >= iH * 0.6:
					return true
				if teamID == 0 and not shuffle and y <= iH * 0.4:
					return true
				if teamID == 1 and shuffle and y <= iH * 0.4:
					return true
				return false

			elif (userInputPlots == 0   # LvR
			or    userInputPlots == 3): # LvR with land bridge
				if teamID == 0 and shuffle and x >= iW * 0.6:
					return true
				if teamID == 1 and not shuffle and x >= iW * 0.6:
					return true
				if teamID == 0 and not shuffle and x <= iW * 0.4:
					return true
				if teamID == 1 and shuffle and x <= iW * 0.4:
					return true
				return false

			else: # 4C
				corner = shuffledTeams[teamID]
				if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
					return true
				if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
					return true
				if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
					return true
				if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
					return true
				return false

		# Three or Four Teams
		elif (numTeams == 3 or numTeams == 4) and userInputProximity == 0: # 3 or 4 teams, Start Together
			corner = shuffledTeams[teamID]
			if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
				return true
			if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
				return true
			if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
				return true
			if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
				return true
			return false
		elif (numTeams == 3 or numTeams == 4) and userInputProximity == 1: # 3 or 4 teams, Start Separated
			corner = shuffledTeams[teamID] + assignedPlayers[teamID]
			while corner >= 4:
				corner -= 4
			if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
				return true
			if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
				return true
			if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
				return true
			if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
				return true
			return false

		# Two Teams, Start Separated
		elif numTeams == 2 and userInputProximity == 1: # Two teams, Start Separated
			if (shuffle and teamID == 0) or (not shuffle and teamID == 1):
				side = assignedPlayers[teamID]
			else:
				side = 1 + assignedPlayers[teamID]
			while side >= 2:
				side -= 2
			if userInputPlots == 1: # TvB
				if teamID == 0 and side and y >= iH * 0.6:
					return true
				if teamID == 1 and not side and y >= iH * 0.6:
					return true
				if teamID == 0 and not side and y <= iH * 0.4:
					return true
				if teamID == 1 and side and y <= iH * 0.4:
					return true
				return false

			elif (userInputPlots == 0   # LvR
			or    userInputPlots == 3): # LvR with land bridge
				if teamID == 0 and side and x >= iW * 0.6:
					return true
				if teamID == 1 and not side and x >= iW * 0.6:
					return true
				if teamID == 0 and not side and x <= iW * 0.4:
					return true
				if teamID == 1 and side and x <= iW * 0.4:
					return true
				return false

			else: # 4C
				corner = shuffledTeams[side]
				if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
					return true
				if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
					return true
				if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
					return true
				if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
					return true
				return false

		# All conditions have failed? Wow. Is that even possible? :)
		return true
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #22
0
ファイル: Team_Battleground.py プロジェクト: AP-ML/DTM
def findStartingPlot(argsList):
#	BugUtil.debug("Team_Battleground: findStartingPlot1")
	[playerID] = argsList
	global assignedPlayers
	global team_num

#	BugUtil.debug("Team_Battleground: findStartingPlot2")
	map = CyMap()
	userInputPlots = map.getCustomMapOption(0)
	if (userInputPlots == 4   # round
	or  userInputPlots == 5): # donut ... starting position already set - return plotnum
		pPlot = CyGlobalContext().getPlayer(playerID).getStartingPlot()
		return map.plotNum(pPlot.getX(), pPlot.getY())

#	BugUtil.debug("Team_Battleground: findStartingPlot3")

	thisTeamID = CyGlobalContext().getPlayer(playerID).getTeam()
	teamID = team_num[thisTeamID]
	
	assignedPlayers[teamID] += 1

#	BugUtil.debug("Team_Battleground: findStartingPlot4")

	def isValid(playerID, x, y):
#		BugUtil.debug("Team_Battleground: isValid")
		map = CyMap()
		numTeams = CyGlobalContext().getGame().countCivTeamsAlive()
		if numTeams > 4 or numTeams < 2: # Put em anywhere, and let the normalizer sort em out.
			return true
		userInputProximity = map.getCustomMapOption(1)
		if userInputProximity == 2: # Start anywhere!
			return true

		global shuffle
		global shuffledTeams
		global team_num
		global shuffledPlayers
		global player_num

		thisTeamID = CyGlobalContext().getPlayer(playerID).getTeam()
		teamID = team_num[thisTeamID]
		userInputPlots = map.getCustomMapOption(0)
		iW = map.getGridWidth()
		iH = map.getGridHeight()

#		BugUtil.debug("Team_Battleground: isValid teams %i, prox %i", numTeams, userInputProximity)

		# Two Teams, Start Together
		if numTeams == 2 and userInputProximity == 0: # Two teams, Start Together
			if userInputPlots == 1: # TvB
				if teamID == 0 and shuffle and y >= iH * 0.6:
					return true
				if teamID == 1 and not shuffle and y >= iH * 0.6:
					return true
				if teamID == 0 and not shuffle and y <= iH * 0.4:
					return true
				if teamID == 1 and shuffle and y <= iH * 0.4:
					return true
				return false

			elif (userInputPlots == 0   # LvR
			or    userInputPlots == 3): # LvR with land bridge
				if teamID == 0 and shuffle and x >= iW * 0.6:
					return true
				if teamID == 1 and not shuffle and x >= iW * 0.6:
					return true
				if teamID == 0 and not shuffle and x <= iW * 0.4:
					return true
				if teamID == 1 and shuffle and x <= iW * 0.4:
					return true
				return false

			else: # 4C
				corner = shuffledTeams[teamID]
				if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
					return true
				if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
					return true
				if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
					return true
				if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
					return true
				return false

		# Three or Four Teams
		elif (numTeams == 3 or numTeams == 4) and userInputProximity == 0: # 3 or 4 teams, Start Together
			corner = shuffledTeams[teamID]
			if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
				return true
			if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
				return true
			if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
				return true
			if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
				return true
			return false
		elif (numTeams == 3 or numTeams == 4) and userInputProximity == 1: # 3 or 4 teams, Start Separated
			corner = shuffledTeams[teamID] + assignedPlayers[teamID]
			while corner >= 4:
				corner -= 4
			if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
				return true
			if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
				return true
			if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
				return true
			if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
				return true
			return false

		# Two Teams, Start Separated
		elif numTeams == 2 and userInputProximity == 1: # Two teams, Start Separated
			if (shuffle and teamID == 0) or (not shuffle and teamID == 1):
				side = assignedPlayers[teamID]
			else:
				side = 1 + assignedPlayers[teamID]
			while side >= 2:
				side -= 2
			if userInputPlots == 1: # TvB
				if teamID == 0 and side and y >= iH * 0.6:
					return true
				if teamID == 1 and not side and y >= iH * 0.6:
					return true
				if teamID == 0 and not side and y <= iH * 0.4:
					return true
				if teamID == 1 and side and y <= iH * 0.4:
					return true
				return false

			elif (userInputPlots == 0   # LvR
			or    userInputPlots == 3): # LvR with land bridge
				if teamID == 0 and side and x >= iW * 0.6:
					return true
				if teamID == 1 and not side and x >= iW * 0.6:
					return true
				if teamID == 0 and not side and x <= iW * 0.4:
					return true
				if teamID == 1 and side and x <= iW * 0.4:
					return true
				return false

			else: # 4C
				corner = shuffledTeams[side]
				if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
					return true
				if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
					return true
				if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
					return true
				if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
					return true
				return false

		# All conditions have failed? Wow. Is that even possible? :)
		return true
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #23
0
def findStartingPlot(argsList):
	[playerID] = argsList
	global assignedPlayers
	global team_num
	thisTeamID = CyGlobalContext().getPlayer(playerID).getTeam()
	teamID = team_num[thisTeamID]
	
	assignedPlayers[teamID] += 1

	def isValid(playerID, x, y):
		global biggest_areas
		global terrainRoll
		userInputTerrain = CyMap().getCustomMapOption(2)
		if userInputTerrain < 3 or (userInputTerrain == 5 and terrainRoll < 6):
			pPlot = CyMap().plot(x, y)
			areaID = pPlot.getArea()
			if areaID not in biggest_areas:
				return false

		map = CyMap()
		numTeams = CyGlobalContext().getGame().countCivTeamsAlive()
		if numTeams > 4 or numTeams < 2: # Put em anywhere, and let the normalizer sort em out.
			return true
		userInputProximity = map.getCustomMapOption(1)
		if userInputProximity == 2: # Start anywhere!
			return true
		global shuffle
		global shuffledTeams
		global team_num
		thisTeamID = CyGlobalContext().getPlayer(playerID).getTeam()
		teamID = team_num[thisTeamID]
		iW = map.getGridWidth()
		iH = map.getGridHeight()
		
		# Two Teams, Start Together
		if numTeams == 2 and userInputProximity == 0: # Two teams, Start Together
			if teamID == 0 and shuffle and x >= iW * 0.6:
				return true
			if teamID == 1 and not shuffle and x >= iW * 0.6:
				return true
			if teamID == 0 and not shuffle and x <= iW * 0.4:
				return true
			if teamID == 1 and shuffle and x <= iW * 0.4:
				return true
			return false

		# Three or Four Teams
		elif (numTeams == 3 or numTeams == 4) and userInputProximity == 0: # 3 or 4 teams, Start Together
			corner = shuffledTeams[teamID]
			if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
				return true
			if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
				return true
			if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
				return true
			if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
				return true
			return false
		elif (numTeams == 3 or numTeams == 4) and userInputProximity == 1: # 3 or 4 teams, Start Separated
			corner = shuffledTeams[teamID] + assignedPlayers[teamID]
			while corner >= 4:
				corner -= 4
			if corner == 0 and x <= iW * 0.4 and y <= iH * 0.4:
				return true
			if corner == 1 and x >= iW * 0.6 and y <= iH * 0.4:
				return true
			if corner == 2 and x <= iW * 0.4 and y >= iH * 0.6:
				return true
			if corner == 3 and x >= iW * 0.6 and y >= iH * 0.6:
				return true
			return false

		# Two Teams, Start Separated
		elif numTeams == 2 and userInputProximity == 1: # Two teams, Start Separated
			if (shuffle and teamID == 0) or (not shuffle and teamID == 1):
				side = assignedPlayers[teamID]
			else:
				side = 1 + assignedPlayers[teamID]
			while side >= 2:
				side -= 2
			if teamID == 0 and side and x >= iW * 0.6:
				return true
			if teamID == 1 and not side and x >= iW * 0.6:
				return true
			if teamID == 0 and not side and x <= iW * 0.4:
				return true
			if teamID == 1 and side and x <= iW * 0.4:
				return true
			return false

		# All conditions have failed? Wow. Is that even possible? :)
		return true
	
	return CvMapGeneratorUtil.findStartingPlot(playerID, isValid)
コード例 #24
0
def assignStartingPlots():
	gc = CyGlobalContext()
	dice = gc.getGame().getMapRand()
	global shuffle
	global shuffledTeams
	global assignedPlayers
	assignedPlayers = [0] * gc.getGame().countCivTeamsEverAlive()
	print assignedPlayers
	shuffle = gc.getGame().getMapRand().get(2, "Start Location Shuffle - PYTHON")
	if gc.getGame().countCivTeamsEverAlive() < 5:
		team_list = [0, 1, 2, 3]
		shuffledTeams = []
		for teamLoop in range(gc.getGame().countCivTeamsEverAlive()):
			iChooseTeam = dice.get(len(team_list), "Shuffling Regions - TBG PYTHON")
			shuffledTeams.append(team_list[iChooseTeam])
			del team_list[iChooseTeam]

	# For Lakes and Continents settings, ensure that starts are all placed on the biggest landmass on each side.
	global biggest_areas
	biggest_areas = []
	areas = CvMapGeneratorUtil.getAreas()
	area_sizes = [(area.getNumTiles(), area.getID()) for area in areas if not area.isWater()]
	area_sizes.sort() # sort by size -- biggest areas last.
	
	# pop the biggest two areas off the list.
	area_size, area_ID = area_sizes.pop()
	biggest_areas.append(area_ID)
	if area_sizes != []:
		area_size, area_ID = area_sizes.pop()
		biggest_areas.append(area_ID)

	# First check to see if teams chose to "Start Separated" or "Start Anywhere".
	map = CyMap()
	userInputProximity = map.getCustomMapOption(1)
	if userInputProximity == 1: # Teams set to Start Separated. Use default impl.
		CyPythonMgr().allowDefaultImpl()
		return

	# Shuffle the players.
	global playersOnTeamOne
	global playersOnTeamTwo
	iPlayers = gc.getGame().countCivPlayersEverAlive()
	playersOnTeamOne = []
	playersOnTeamTwo = []
	
	player_list = []
	for plrCheckLoop in range(18):
		if CyGlobalContext().getPlayer(plrCheckLoop).isEverAlive():
			player_list.append(plrCheckLoop)
	shuffledPlayers = []
	for playerLoopTwo in range(iPlayers):
		iChoosePlayer = dice.get(len(player_list), "Shuffling Player Order - Mirror PYTHON")
		shuffledPlayers.append(player_list[iChoosePlayer])
		del player_list[iChoosePlayer]

	if userInputProximity == 2: # Teams set to Start Anywhere!
		def isValidToStartAnywhere(playerID, x, y):
			global biggest_areas
			global terrainRoll
			userInputTerrain = CyMap().getCustomMapOption(2)
			if userInputTerrain < 3 or (userInputTerrain == 5 and terrainRoll < 6):
				pPlot = CyMap().plot(x, y)
				areaID = pPlot.getArea()
				if areaID not in biggest_areas:
					return false
			return true

		# Since the default alternates by team, must use the shuffled players list to assign starting locs.
		# This will provide a truly random order, which may or may not be "fair". But hey, starting anywhere means ANYwhere. OK?
		for playerID in shuffledPlayers:
			player = gc.getPlayer(playerID)
			startPlot = CvMapGeneratorUtil.findStartingPlot(playerID, isValidToStartAnywhere)
			sPlot = map.plotByIndex(startPlot)
			player.setStartingPlot(sPlot, true)
		# All done.
		return None

	# OK, so the teams have chosen to Start Together.
	#
	# Check for the special case of two teams with even players.
	# If found, force perfect mirrorization of start plots!
	#
	# (This is necessary because the default start plot process 
	# resolves "ties" differently on each side due to minor
	# differences in the order of operations. Odd but true!)
	#
	iTeams = gc.getGame().countCivTeamsEverAlive()
	if iTeams != 2:
		CyPythonMgr().allowDefaultImpl()
		return
	team_one = gc.getTeam(0)
	team_two = gc.getTeam(1)
	if team_one.getNumMembers() != team_two.getNumMembers():
		CyPythonMgr().allowDefaultImpl()
		return

	# We are dealing with two teams who are evenly matched.
	# Assign all start plots for the first team, then mirrorize the locations for the second team!
	# Start by determining which players are on which teams.
	for iLoop in range(iPlayers):
		thisPlayerID = shuffledPlayers[iLoop]
		this_player = gc.getPlayer(thisPlayerID)
		teamID = gc.getPlayer(thisPlayerID).getTeam()
		print("Player: ", thisPlayerID, " Team: ", teamID)
		if teamID == 1:
			playersOnTeamTwo.append(shuffledPlayers[iLoop])
		else:
			playersOnTeamOne.append(shuffledPlayers[iLoop])
	
	# Now we pick a team to assign to the left side and assign them there.
	userInputPlots = map.getCustomMapOption(0)
	iW = map.getGridWidth()
	iH = map.getGridHeight()
	if userInputPlots == 0: # Reflection
		reflect_x = lambda x: iW - iX - 1
		reflect_y = lambda y: iY
	elif userInputPlots == 1: # Inversion
		reflect_x = lambda x: iW - iX - 1
		reflect_y = lambda y: iH - iY - 1
	elif userInputPlots == 2: # Copy
		reflect_x = lambda x: iX + (iW / 2)
		reflect_y = lambda y: iY
	else: # userInputPlots == 3: Opposite
		reflect_x = lambda x: iX + (iW / 2)
		reflect_y = lambda y: iH - iY - 1

	def isValidForMirror(playerID, x, y):
		global biggest_areas
		global terrainRoll
		userInputTerrain = CyMap().getCustomMapOption(2)
		if userInputTerrain < 3 or (userInputTerrain == 5 and terrainRoll < 6):
			pPlot = CyMap().plot(x, y)
			areaID = pPlot.getArea()
			if areaID not in biggest_areas:
				return false

		userInputPlots = CyMap().getCustomMapOption(0)
		iPlayers = CyGlobalContext().getGame().countCivPlayersEverAlive()
		teamID = CyGlobalContext().getPlayer(playerID).getTeam()
		iW = CyMap().getGridWidth()

		# Two Evenly-Matched Teams, Start Together
		if iPlayers > 2 and userInputPlots <= 1 and x <= iW * 0.4:
			return true
		if iPlayers > 2 and userInputPlots >= 2 and x >= iW * 0.1 and x <= iW * 0.4:
			return true
		# 1 vs 1 game, so make sure the players start farther apart!
		if iPlayers == 2 and userInputPlots <= 1 and x <= iW * 0.2:
			return true
		if iPlayers == 2 and userInputPlots >= 2 and x >= iW * 0.2 and x <= iW * 0.3:
			return true
		# if not true, then false! (Duh? Well, the program still has to be told.)
		return false

	if shuffle: # We will put team two on the left.
		teamOneIndex = 0
		for thisPlayer in playersOnTeamTwo:
			player = gc.getPlayer(thisPlayer)
			startPlot = CvMapGeneratorUtil.findStartingPlot(thisPlayer, isValidForMirror)
			sPlot = map.plotByIndex(startPlot)
			player.setStartingPlot(sPlot, true)
			iX = sPlot.getX()
			iY = sPlot.getY()
			mirror_x = reflect_x(iX)
			mirror_y = reflect_y(iY)
			opposite_player = gc.getPlayer(playersOnTeamOne[teamOneIndex])
			oppositePlot = map.plot(mirror_x, mirror_y)
			opposite_player.setStartingPlot(oppositePlot, true)
			teamOneIndex += 1
	else: # will put team one on the left.
		teamTwoIndex = 0
		for thisPlayer in playersOnTeamOne:
			player = gc.getPlayer(thisPlayer)
			startPlot = CvMapGeneratorUtil.findStartingPlot(thisPlayer, isValidForMirror)
			sPlot = map.plotByIndex(startPlot)
			player.setStartingPlot(sPlot, true)
			iX = sPlot.getX()
			iY = sPlot.getY()
			mirror_x = reflect_x(iX)
			mirror_y = reflect_y(iY)
			opposite_player = gc.getPlayer(playersOnTeamTwo[teamTwoIndex])
			oppositePlot = map.plot(mirror_x, mirror_y)
			opposite_player.setStartingPlot(oppositePlot, true)
			teamTwoIndex += 1
			
	# All done.
	return None