TC01
Deity
Now on problem 3... see post #11.
For my Final Frontier worldbuilder project, I attempted to make buildings be stored to planets in the WBS file. The way things currently are, all buildings in the WBS are created on the system's best world, no matter which building they were originally on.
So, I added code to CvWBDesc.py to loop through each planet, get buildings, write them to the WBS, then to read them, store them to lists, and then to build them on the respective planets.
Unfortunately, while Jon Shafer made solar system data be read and stored in the CvWBDesc.py file, he made the actual solar system be created in CvEventManager's onGameStart function. And it seems that onGameStart is called for scenarios after all the apply functions in CvWBDesc.py are called (these functions take the read data from the .WBS and build the map). So I was attempting to deal with a solar system that did not yet exist.
I decided to try moving this code, which builds a solar system by calling data from CvWBDesc.py:
to CvWBDesc.py's apply function, under CvPlotDesc:
However, it wasn't working. The print statements I added confirmed that the system was being made, but in the actual game, there was no solar system. (Just like what happens if you try to place a solar system in worldbuilder without using my FF worldbuilder utility). Here is the debug result for a sample system (the "adding planet to system" lines are debug statements from CvSolarSystem.py that I turned on):
The code seems to be fine. What it is doing is exactly the same as what the code in onGameStart is doing, except I don't need to loop through all plots that have a solar system on them, since the code in CvWBDesc.py would be triggered whenever a feature that is a solar system is placed.
If I can't get it to work, I can put the old code back in onGameStart and just add my building code there instead. But it seems to me it would be simpler to have the code here (look at how much less code I actually need- half of my added code is all print statements...).
For my Final Frontier worldbuilder project, I attempted to make buildings be stored to planets in the WBS file. The way things currently are, all buildings in the WBS are created on the system's best world, no matter which building they were originally on.
So, I added code to CvWBDesc.py to loop through each planet, get buildings, write them to the WBS, then to read them, store them to lists, and then to build them on the respective planets.
Unfortunately, while Jon Shafer made solar system data be read and stored in the CvWBDesc.py file, he made the actual solar system be created in CvEventManager's onGameStart function. And it seems that onGameStart is called for scenarios after all the apply functions in CvWBDesc.py are called (these functions take the read data from the .WBS and build the map). So I was attempting to deal with a solar system that did not yet exist.
I decided to try moving this code, which builds a solar system by calling data from CvWBDesc.py:
Code:
# Is this a scenario file?
if ('.CivBeyondSwordWBSave' in CyMap().getMapScriptName()):
import CvWBInterface
# Search through all plots on the map for Solar Systems to add content for
for pWBPlotLoop in CvWBInterface.WBDesc.plotDesc:
iX = pWBPlotLoop.iX
iY = pWBPlotLoop.iY
pPlot = CyMap().plot(iX, iY)
if (pPlot.getFeatureType() == self.iFeatureIDSolarSystem):
iStarType = getStarIndexFromTag(pWBPlotLoop.szStarType)
pSystem = CvSystem(iX,iY,iStarType)
for iPlanetLoop in range(pWBPlotLoop.iNumPlanets):
iPlanetType = getPlanetIndexFromTag(pWBPlotLoop.aszPlanetType[iPlanetLoop])
iOrbitRing = pWBPlotLoop.aiOrbitRing[iPlanetLoop]
iPlanetSize = pWBPlotLoop.aiPlanetSize[iPlanetLoop]
bMoon = pWBPlotLoop.aiMoon[iPlanetLoop]
bRings = pWBPlotLoop.aiRings[iPlanetLoop]
pSystem.addPlanet(iPlanetType, iPlanetSize, iOrbitRing, bMoon, bRings)
self.addSystem(pSystem)
to CvWBDesc.py's apply function, under CvPlotDesc:
Code:
if (self.featureType):
featureTypeNum = CvUtil.findInfoTypeNum(gc.getFeatureInfo, gc.getNumFeatureInfos(), self.featureType)
plot.setFeatureType(featureTypeNum, self.featureVariety)
if plot.getFeatureType() == gc.getInfoTypeForString('FEATURE_SOLAR_SYSTEM'):
print "Generating System"
FinalFrontier = CvEventInterface.getEventManager()
iSunType = getStarIndexFromTag(self.szStarType)
print (" System Sun = %d" % (iSunType))
pSystem = CvSystem(self.iX, self.iY, iSunType)
for iPlanetLoop in range(self.iNumPlanets):
print (" Planet %d" % (iPlanetLoop))
iPlanetType = getPlanetIndexFromTag(self.aszPlanetType[iPlanetLoop])
print (" Planet Type = %d" % (iPlanetType))
iOrbitRing = self.aiOrbitRing[iPlanetLoop]
print (" Orbit Ring = %d" % (iOrbitRing))
iPlanetSize = self.aiPlanetSize[iPlanetLoop]
print (" Planet Size = %d" % (iPlanetSize))
iMoon = self.aiMoon[iPlanetLoop]
print (" Moon = %d" % (iMoon))
iRings = self.aiRings[iPlanetLoop]
print (" Rings = %d" % (iRings))
pSystem.addPlanet(iPlanetType, iOrbitRing, iPlanetSize, iMoon, iRings)
print (" Planet Added")
FinalFrontier.addSystem(pSystem)
print ("System Generated")
However, it wasn't working. The print statements I added confirmed that the system was being made, but in the actual game, there was no solar system. (Just like what happens if you try to place a solar system in worldbuilder without using my FF worldbuilder utility). Here is the debug result for a sample system (the "adding planet to system" lines are debug statements from CvSolarSystem.py that I turned on):
Spoiler From PythonDbg.log :
Code:
Generating System
System Sun = 3
Planet 0
Planet Type = 3
Orbit Ring = 7
Planet Size = 2
Moon = 0
Rings = 0
Adding planet to (3, 6) system with: ORANGE_PLANET, 7, 2, 0, 0
Planet Added
Planet 1
Planet Type = 3
Orbit Ring = 2
Planet Size = 2
Moon = 0
Rings = 0
Adding planet to (3, 6) system with: ORANGE_PLANET, 2, 2, 0, 0
Planet Added
Planet 2
Planet Type = 5
Orbit Ring = 3
Planet Size = 1
Moon = 1
Rings = 0
Adding planet to (3, 6) system with: YELLOW_PLANET, 3, 1, 1, 0
Planet Added
Planet 3
Planet Type = 1
Orbit Ring = 8
Planet Size = 2
Moon = 0
Rings = 0
Adding planet to (3, 6) system with: GRAY_PLANET, 8, 2, 0, 0
Planet Added
Planet 4
Planet Type = 5
Orbit Ring = 5
Planet Size = 2
Moon = 0
Rings = 0
Adding planet to (3, 6) system with: YELLOW_PLANET, 5, 2, 0, 0
Planet Added
Planet 5
Planet Type = 2
Orbit Ring = 6
Planet Size = 0
Moon = 0
Rings = 0
Adding planet to (3, 6) system with: GREEN_PLANET, 6, 0, 0, 0
Planet Added
System Generated
The code seems to be fine. What it is doing is exactly the same as what the code in onGameStart is doing, except I don't need to loop through all plots that have a solar system on them, since the code in CvWBDesc.py would be triggered whenever a feature that is a solar system is placed.
If I can't get it to work, I can put the old code back in onGameStart and just add my building code there instead. But it seems to me it would be simpler to have the code here (look at how much less code I actually need- half of my added code is all print statements...).