TC01
Deity
For the Star Wars mod, I created a mapscript where instead of placing Solar Systems the way the Final Frontier places them, it places a 3x3 planet. I used the same code up to the point where it actually placed the Solar System, then I added this:
Now, I can't see anything wrong here. Except for the fact that the game gives this error:
Here is the corresponding code, the findStartingPlot function (up to the point where the error occurs):
It is filling g_apSolarSystemList with every plot that has a FEATURE_PLANET_CORE... or it should be. But what the error above means is that the list is not working- possibly never getting filled, since this error repeats itself quite a number of times in the log.
Then the game crashes (because it failed to place any civ, I assume).
Can anyone help solve this problem? Is something wrong with the randomly-assigning-planets part or the filling-g_apSolarSystemList part?
Spoiler :
Code:
game = CyGame()
iRnd = game.getSorenRandNum(9, "Place Planets")
pPlanetCore = self.map.sPlot(iX, iY)
if iRnd == 0:
pPlanetCore.setTerrainType(self.planetClassMCore,true,true)
pPlanetCore.setFeatureType(self.planetCore,0)
for iPlanetX in range(iX-1, iX+2, 1):
for iPlanetY in range(iY-1, iY+2, 1):
pPlanetEdge = self.map.sPlot(iPlanetX, iPlanetY)
if (iPlanetX == iX and iPlanetY == iY):
continue
else:
pPlanetEdge.setTerrainType(self.planetClassMEdge,true,true)
if 1 <= iRnd <= 3:
pPlanetCore.setFeatureType(self.planetCore,0)
for iPlanetX in range(iX-1, iX+2, 1):
for iPlanetY in range(iY-1, iY+2, 1):
pPlanetEdge = self.map.sPlot(iPlanetX, iPlanetY)
pPlanetEdge.setTerrainType(self.planetArctic,true,true)
if 4 <= iRnd <= 6:
pPlanetCore.setFeatureType(self.planetCore,0)
for iPlanetX in range(iX-1, iX+2, 1):
for iPlanetY in range(iY-1, iY+2, 1):
pPlanetEdge = self.map.sPlot(iPlanetX, iPlanetY)
pPlanetEdge.setTerrainType(self.planetDesert,true,true)
if 7 <= iRnd <= 9:
pPlanetCore.setFeatureType(self.planetCore,0)
for iPlanetX in range(iX-1, iX+2, 1):
for iPlanetY in range(iY-1, iY+2, 1):
pPlanetEdge = self.map.sPlot(iPlanetX, iPlanetY)
pPlanetEdge.setTerrainType(self.planetVolcanic,true,true)
Now, I can't see anything wrong here. Except for the fact that the game gives this error:
Code:
Traceback (most recent call last):
File "StarWars", line 571, in findStartingPlot
IndexError: list index out of range
ERR: Python function findStartingPlot failed, module StarWars
Here is the corresponding code, the findStartingPlot function (up to the point where the error occurs):
Spoiler :
Code:
def findStartingPlot(argsList):
[iPlayer] = argsList
gc = CyGlobalContext()
iStartPlotNum = -1
#print("Checking for player %d in" %(iPlayer))
#print(g_aiPickedPlotForPlayer)
# Don't find a starting location more than once for a player
if (iPlayer in g_aiPickedPlotForPlayer):
pStartPlot = gc.getPlayer(iPlayer).getStartingPlot()
#print("pStartPlot is already assigned to %d, %d" %(pStartPlot.getX(), pStartPlot.getY()))
iPlotNum = CyMap().plotNum(pStartPlot.getX(), pStartPlot.getY())
# Reset lists... would do this elsewhere but it appears there are multiple instances of these arrays floating around so I have to clear them in this function it seems
g_aiPickedPlotForPlayer.remove(iPlayer)
global g_apSolarSystemPlotList
g_apSolarSystemPlotList = []
return iPlotNum
#print("Solar System Plot List is of size %d" %(len(g_apSolarSystemPlotList)))
# Make list of valid plots (Solar Systems), but only once
if (len(g_apSolarSystemPlotList) == 0):
for iPlotLoop in range(CyMap().numPlots()):
pPlot = CyMap().plotByIndex(iPlotLoop)
iPlanetCore = gc.getInfoTypeForString("FEATURE_PLANET_CORE")
if (pPlot.getFeatureType() == iPlanetCore):
g_apSolarSystemPlotList.append(pPlot)
# Now pick a random solar system from this list to see if it should become the player's start location
iNumSolarSystems = len(g_apSolarSystemPlotList)
pPlayer = gc.getPlayer(iPlayer)
iRange = pPlayer.startingPlotRange()
iPass = 0
# Loop until we find a valid plot
while (true):
iRand = CyGame().getSorenRandNum(iNumSolarSystems, "Picking random solar system to start at for player %d" %(iPlayer))
pRandomPlot = g_apSolarSystemPlotList[iRand]
It is filling g_apSolarSystemList with every plot that has a FEATURE_PLANET_CORE... or it should be. But what the error above means is that the list is not working- possibly never getting filled, since this error repeats itself quite a number of times in the log.
Then the game crashes (because it failed to place any civ, I assume).
Can anyone help solve this problem? Is something wrong with the randomly-assigning-planets part or the filling-g_apSolarSystemList part?