Problems with setting features back after a random event.

Terradive

Warlord
Joined
Jun 4, 2009
Messages
186
I have a random event that adds fertility and droughts to plots. That is done in python, and works well. Everything works the way I want. I'm wanting to let the idisappearance tag remove the feature. I made these changes in cvplot.cpp. It changes everything back to ice. I'm apparently not doing thise correct. Any help?

Code:
/* original bts code
			if (GC.getGameINLINE().getSorenRandNum(10000, "Feature Disappearance") < iProbability)
*/
			int iOdds = (10000*GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getVictoryDelayPercent())/100;
			if (GC.getGameINLINE().getSorenRandNum(iOdds, "Feature Disappearance") < iProbability)
/************************************************************************************************/
/* UNOFFICIAL_PATCH                        END                                                  */
/************************************************************************************************/
			{
				if (GC.getInfoTypeForString("FEATURE_JUNGLEDROUGHT", true)) 
				{
					setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_JUNGLE")));
				}
				else if (GC.getInfoTypeForString("FEATURE_JUNGLEFERTILE", true)) 
				{
					setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_JUNGLE")));
				}
				else if (GC.getInfoTypeForString("FEATURE_JUNGLEFERTILEMINOR", true)) 
				{
					setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_JUNGLE")));
				}
				else if (GC.getInfoTypeForString("FEATURE_JUNGLEDROUGHTMINOR", true)) 
				{
					setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_JUNGLE")));
				}
				else if (GC.getInfoTypeForString("FEATURE_FORESTDROUGHT", true))				
				{
					setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_FOREST")));
				}
				else if (GC.getInfoTypeForString("FEATURE_FORESTFERTILE", true))				
				{
					setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_FOREST")));
				}
				else if (GC.getInfoTypeForString("FEATURE_FORESTDROUGHTMINOR", true))				
				{
					setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_FOREST")));
				}
				else if (GC.getInfoTypeForString("FEATURE_FORESTFERTILEMINOR", true))				
				{
					setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_FOREST")));
				}
				else 
				{
					setFeatureType(NO_FEATURE);
				} 
			}
		}
	}
else
 
The GC.getInfoTypeForString function returns a number. You are not doing anything with this number except checking to see if the value should be interpreted as true or false. When dealing with integers, generally the value 0 is evaluated as false and any other value is evaluated as true.

What you want to do is compare the feature type number for the feature that is actually on the plot with the various numbers for the various feature types that you are interested in. Something like this:
Code:
iFeature = getFeatureType();
if (iFeature == GC.getInfoTypeForString("FEATURE_JUNGLEDROUGHT", true))
{
  setFeatureType((FeatureTypes)(GC.getDefineINT("FEATURE_JUNGLE")));
}
else if (iFeature == etc...

I also have to wonder why in the setFeatureType calls you are using GC.getDefineINT instead of GC.getInfoTypeForString. Depending on what you have defined in your GlobalDefines.xml this might be correct. But if the things you are looking for are not defined in there (or in an equivalent file) then it is probably returning -1, in which case it is just removing the feature since -1 is NO_FEATURE. So this should probably be using GC.getInfoTypeForString.

If by "It changes everything back to ice" you meant "always just removes the feature" then that is why. Your code is using as a conditional expression the value returned for FEATURE_JUNGLEDROUGHT which is probably not 0 and therefore evaluates as True. It then looks for a defined integer called FEATURE_JUNGLE which does not exist and therefore gets a value of -1. So it sets the plot's feature to be -1, or NO_FEATURE. So you always end up with a featureless plot.
 
Back
Top Bottom