Adding/removing features when improvement built/removed

Xyth

History Rewritten
Joined
Jul 14, 2004
Messages
4,106
Location
Aotearoa
This is what I've written:

Code:
	def onImprovementBuilt(self, argsList):
		'Improvement Built'
		iImprovement, iX, iY = argsList

		# BEGIN Pollution from Improvements
		pPlot = CyMap().plot(iX,iY)

		if iImprovement == gc.getInfoTypeForString('IMPROVEMENT_MINE') or gc.getInfoTypeForString('IMPROVEMENT_QUARRY') or gc.getInfoTypeForString('IMPROVEMENT_WELL') or gc.getInfoTypeForString('IMPROVEMENT_OFFSHORE_PLATFORM'):
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_POLLUTION'), 1)

		elif pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_POLLUTION'):
			pPlot.setFeatureType(-1, 1)
		# END Pollution from Improvements

		if (not self.__LOG_IMPROVEMENT):
			return
		CvUtil.pyPrint('Improvement %s was built at %d, %d'
			%(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))



	def onImprovementDestroyed(self, argsList):
		'Improvement Destroyed'
		iImprovement, iOwner, iX, iY = argsList

		# BEGIN Pollution from Improvements
		pPlot = CyMap().plot(iX,iY)

		if iImprovement == gc.getInfoTypeForString('IMPROVEMENT_MINE') or gc.getInfoTypeForString('IMPROVEMENT_QUARRY') or gc.getInfoTypeForString('IMPROVEMENT_WELL') or gc.getInfoTypeForString('IMPROVEMENT_OFFSHORE_PLATFORM'):
			if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_POLLUTION'):
				pPlot.setFeatureType(-1, 1)
		# END Pollution from Improvements

		if (not self.__LOG_IMPROVEMENT):
			return
		CvUtil.pyPrint('Improvement %s was Destroyed at %d, %d'
			%(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))

The problem is while the pollution feature is successfully placed it's placed when any improvement is built, not just the ones I specified. Also, the feature never gets removed when a different improvement is built over top of the polluting one.

I guess the "if Improvement ==" line is always being evaluated as true but I cannot figure out why. Anyone have any insight?
 
While this:
PHP:
iImprovement == gc.getInfoTypeForString('IMPROVEMENT_MINE') or gc.getInfoTypeForString('IMPROVEMENT_QUARRY')

seems logically, it's not valid in nearly every programming language.
You have to do
PHP:
iImprovement == gc.getInfoTypeForString('IMPROVEMENT_MINE') or iImprovement == gc.getInfoTypeForString('IMPROVEMENT_QUARRY')
etc

to make it work.
Else the first == is checked, then the second check is only if gc.getInfoTypeForString('IMPROVEMENT_QUARRY') exists, and that part does not get checked against anything. So you get always a number back, having a number is equal to not false, so that part is always true.
 
Gah I knew that! Always something obvious heh. Cheers.
 
Back
Top Bottom