def getNewWorldID(self):
nID = 0
continentList = list()
for a in self.areaList:
if a.water == False:
continentList.append(a)
totalLand = 0
for c in continentList:
totalLand += c.size
print totalLand
#sort all the continents by size, largest first
continentList.sort(lambda x,y:cmp(x.size,y.size))
continentList.reverse()
print ''
print "All continents"
print self.PrintList(continentList)
#now remove a percentage of the landmass to be considered 'Old World'
oldWorldSize = 0
#biggest continent is automatically 'Old World'
oldWorldSize += continentList[0].size
del continentList[0]
#get the next largest continent and temporarily remove from list
#add it back later and is automatically 'New World'
biggestNewWorld = continentList[0]
del continentList[0]
#sort list by ID rather than size to make things
#interesting and possibly bigger new worlds
continentList.sort(lambda x,y:cmp(x.ID,y.ID))
continentList.reverse()
oldWorldMinSize = max(12,totalLand * 0.025)
idealOldWorldSize = int(totalLand * 0.60)
oldWorldPercent = float(oldWorldSize)/float(totalLand)
print "Ideal Old World total size is %(w)2d" % {"w":idealOldWorldSize}
print "Current Old World size is %(w)2d" % {"w":oldWorldSize}
if oldWorldSize < idealOldWorldSize:
print "Minimum Old World continent size is %(w)2d" % {"w":oldWorldMinSize}
print "There are %(c)2d continents in the list." % {"c":len(continentList)}
o = len(continentList) - 1
n = 0
while n < o:
if oldWorldPercent > 0.60:
print "Old world continent selection complete, total size is %(t)2d" % {"t":oldWorldSize}
break
print "Evaluating %(c)2d, ID is %(d)2d." % {"c":n,"d":continentList[n].ID}
if continentList[n].size > oldWorldMinSize:
oldWorldSize += continentList[n].size
oldWorldPercent = float(oldWorldSize)/float(totalLand)
print "Adding continent %(c)2d to old world, total size is now %(t)2d" % {"c":continentList[n].ID,"t":oldWorldSize}
del continentList[n]
#decrease the list length (o) by one to prevent going out of bounds
#do not incriment the current count (n) here since that list item was removed
o -= 1
else: #incriment the counter if no continent was removed from the list
n += 1
#add back the biggestNewWorld continent
continentList.append(biggestNewWorld)
#what remains in the list will be considered 'New World'
print "New World Continents"
print self.PrintList(continentList)
#get ID for the next continent, we will use this ID for 'New World'
#designation
nID = continentList[0].ID
del continentList[0] #delete to avoid unnecessary overwrite
#now change all the remaining continents to also have nID as their ID
for i in range(self.mapHeight*self.mapWidth):
for c in continentList:
if c.ID == self.areaMap[i]:
self.areaMap[i] = nID
return nID