[BTS] Plant Forest Mod - Cant get it to work

Pir Lan Tota

Warlord
Joined
Jan 28, 2008
Messages
276
Location
Manchester
Hi guys,

trying to get a plant forest mod to work, following the guide here:

https://forums.civfanatics.com/threads/request-simple-plant-forest-mod.360619/page-2

So it all works, up-until triggering the conversion from tree-nursery to forest (e.g. the python bit).

Got this as code:

## Terraform Begin (CREDIT to avain)

def onImprovementBuilt(self, argsList):
'Improvement Built'
#pPlot = CyMap().plot(iX, iY)
iForesteType = CvUtil.findInfoTypeNum(gc.getFeatureInfo, gc.getNumFeatureInfos(),'FEATURE_FOREST')
iNursery = CvUtil.findInfoTypeNum(gc.getImprovementInfo,gc.getNumImprovementInfos(),'IMPROVEMENT_TREE_NURSERY')
iImprovement, iX, iY = argsList
if (not self.__LOG_IMPROVEMENT):
return
CvUtil.pyPrint('Improvement %s was built at %d, %d'
%(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))
if (iImprovement == iNursery):
pPlot.setFeatureType(gc.getInfoTypeForString( "FEATURE_FOREST" ), 1, 1)


Unfortunately, it doesnt seem to trigger. Any idea whats going wrong?
 
Where did you put this method? Can you upload the entire file?
 
the vanilla code is as following:
PHP:
    def onImprovementBuilt(self, argsList):
       'Improvement Built'
       iImprovement, iX, iY = argsList
       if (not self.__LOG_IMPROVEMENT):
           return
       CvUtil.pyPrint('Improvement %s was built at %d, %d'
           %(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))
It consists of 3 parts
  1. reading arguments (iImprovement, iX, iY = argsList)
  2. stop if logging is disabled
  3. write to log
Your code consists of
  1. commented out finding pPlot
  2. setting some constant values (IForesteType etc)
  3. read arguments
  4. stop if logging is disabled
  5. write to log
  6. plant forest on (1,1) if improvement is Nursery
It would be best if 3 goes first because if you look around, setting the variables is the first thing done in all the other functions. It means that's where people will look for it.
6 needs to go before 4. As it is right now, if logging is disabled, it will never reach the build the forest.
The build line should be using iX and iY, not 1 and 1.
The improvement should be destroyed. That will allow building a forest again if it is cut down or otherwise destroyed (fire random event or similar)
The arguments for setFeatureType are wrong. They should be featureID (iForestType) followed by which version you want. Using -1 means it's up to the DLL to determine this value.

It would likely work if it is written like this.
def onImprovementBuilt(self, argsList):
'Improvement Built'
#pPlot = CyMap().plot(iX, iY)
iImprovement, iX, iY = argsList
iForestType = CvUtil.findInfoTypeNum(gc.getFeatureInfo, gc.getNumFeatureInfos(),'FEATURE_FOREST')
iNursery = CvUtil.findInfoTypeNum(gc.getImprovementInfo,gc.getNumImprovementInfos(),'IMPROVEMENT_TREE_NURSERY')
iImprovement, iX, iY = argsList
if (iImprovement == iNursery):
pPlot = CyMap().plot(iX, iY)
pPlot.setFeatureType(iForestType, -1)
pPlot.setImprovementType(-1)

if (not self.__LOG_IMPROVEMENT):
return
CvUtil.pyPrint('Improvement %s was built at %d, %d'
%(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))
if (iImprovement == iNursery):
pPlot.setFeatureType(gc.getInfoTypeForString( "FEATURE_FOREST" ), 1, 1)
or correctly indented (without marked changed)
PHP:
def onImprovementBuilt(self, argsList):
  'Improvement Built'
  iImprovement, iX, iY = argsList
  iForestType = CvUtil.findInfoTypeNum(gc.getFeatureInfo, gc.getNumFeatureInfos(),'FEATURE_FOREST')
  iNursery = CvUtil.findInfoTypeNum(gc.getImprovementInfo,gc.getNumImprovementInfos(),'IMPROVEMENT_TREE_NURSERY')
  if (iImprovement == iNursery):
    pPlot = CyMap().plot(iX, iY)
    pPlot.setFeatureType(iForestType, -1)
    pPlot.setImprovementType(-1)
  if (not self.__LOG_IMPROVEMENT):
    return
  CvUtil.pyPrint('Improvement %s was built at %d, %d'
    %(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))
 
Top Bottom