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
seaCheck = map.getSeaLevel()
if (seaCheck == 0):
checkFood = doesBFCHaveFood(x, y)
if not checkFood:
return false
gc = CyGlobalContext()
if (CyMap().getCustomMapOption(3) == 1):
check20Copper = isResourceInRange(x, y, 2, 2)
check40Copper = isResourceInRange(x, y, 2, 3)
check20Iron = isResourceInRange(x, y, 4, 2)
check20Horse = isResourceInRange(x, y, 3, 2)
check40Horse = isResourceInRange(x, y, 3, 3)
if check20Copper or check20Horse:
return false
if not (check40Copper or check40Horse or check20Iron):
return false
if teamID == 0 and shuffle and y >= iH * 0.6:
addExtraGoodies(x, y, playerID)
return true
if teamID == 1 and not shuffle and y >= iH * 0.6:
addExtraGoodies(x, y, playerID)
return true
if teamID == 0 and not shuffle and y <= iH * 0.4:
addExtraGoodies(x, y, playerID)
return true
if teamID == 1 and shuffle and y <= iH * 0.4:
addExtraGoodies(x, y, playerID)
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
seaCheck = map.getSeaLevel()
if (seaCheck == 0):
checkFood = doesBFCHaveFood(x, y)
if not checkFood:
return false
gc = CyGlobalContext()
if (CyMap().getCustomMapOption(3) == 1):
check20Copper = isResourceInRange(x, y, 2, 2)
check40Copper = isResourceInRange(x, y, 2, 3)
check20Iron = isResourceInRange(x, y, 4, 2)
check20Horse = isResourceInRange(x, y, 3, 2)
check40Horse = isResourceInRange(x, y, 3, 3)
if check20Copper or check20Horse:
return false
if not (check40Copper or check40Horse or check20Iron):
return false
if teamID == 0 and side and y >= iH * 0.625 and y <= iH * 0.825:
addExtraGoodies(x, y, playerID)
return true
if teamID == 1 and not side and y >= iH * 0.625 and y <= iH * 0.825:
addExtraGoodies(x, y, playerID)
return true
if teamID == 0 and not side and y <= iH * 0.375 and y >= iH * 0.175:
addExtraGoodies(x, y, playerID)
return true
if teamID == 1 and side and y <= iH * 0.375 and y >= iH * 0.175:
addExtraGoodies(x, y, playerID)
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)