How do I show floating integers in Civilopedia

CaptainMidnight

Warlord
Joined
Apr 16, 2006
Messages
141
I recently merged the Vehem's floating integer for happiness from Xienwolf's Fall Further 0.51. This includes floating integers for feature happiness, military unit happiness (Civicinfos), and improvement happiness (improvementinfos). Everything is fine in the actual game itself and Improvement happiness displays correctly but I get a weird number in the civilopedia for Military unit happiness and feature Happiness:

attachment.php


I'm aware Fall Further has a different Civics screen layout but I'm not sure how this affects the code. I want to retain the original civic screen layout. In Gametextmgr this part of the code I have edited for feature happiness:

Code:
//	Feature Happiness
	iLast = 0;

	for (iI = 0; iI < GC.getNumFeatureInfos(); ++iI)
	{
		if (GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI) != 0)
		{
[B]/************************************************************************************************/
/* UNOFFICIAL_PATCH                       08/28/09                             jdog5000         */
/*                                                                                              */
/* Bugfix                                                                                       */
/************************************************************************************************/[/B]
// original bts code
//			szFirstBuffer.Format(L"%s%s", NEWLINE, gDLL->getText("TXT_KEY_CIVIC_FEATURE_HAPPINESS", GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI), ((GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI) > 0) ? gDLL->getSymbolID(HAPPY_CHAR) : gDLL->getSymbolID(UNHAPPY_CHAR))).c_str());

			// Use absolute value with unhappy face
			[B]// CMEDIT FLOATING INTEGERS (VEHEM & XIANWOLF)[/B]

			CvWString szHappyString;
            if (GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI) * 0.01f == int(GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI) * 0.01f))
            {
                szHappyString.Format(L"%.0f", 0.01f * GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI));
            }
            else
            {
                szHappyString.Format(L"%.2f", 0.01f * GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI));
            }
			//<Original COde> szFirstBuffer.Format(L"%s%s", NEWLINE, gDLL->getText("TXT_KEY_CIVIC_FEATURE_HAPPINESS", abs(GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI)), ((GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI) > 0) ? gDLL->getSymbolID(HAPPY_CHAR) : gDLL->getSymbolID(UNHAPPY_CHAR))).c_str());
			szFirstBuffer.Format(L"%s%s", NEWLINE, gDLL->getText("TXT_KEY_CIVIC_FEATURE_HAPPINESS", szHappyString.GetCString(), (GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI) > 0 ? gDLL->getSymbolID(HAPPY_CHAR) : gDLL->getSymbolID(UNHAPPY_CHAR))).c_str());
			[B]// CMEDIT End[/B]
[B]/************************************************************************************************/
/* UNOFFICIAL_PATCH                        END                                                  */
/************************************************************************************************/[/B]
				CvWString szFeature;
			szFeature.Format(L"<link=literal>%s</link>", GC.getFeatureInfo((FeatureTypes)iI).getDescription());
			setListHelp(szHelpText, szFirstBuffer, szFeature, L", ", (GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI) != iLast));
			iLast = GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI);
		}
	}

Gametextmgr confuses the hell out of me so any help would be godsend!
 

Attachments

  • Civ4ScreenShot0000.JPG
    Civ4ScreenShot0000.JPG
    163.1 KB · Views: 245
Did you change whichever game text XML file this will be included in?
 
Sure, here it is:

Code:
<TEXT>
		<Tag>TXT_KEY_CIVIC_FEATURE_HAPPINESS</Tag>
		<English>[ICON_BULLET]+%s1%F2 from[SPACE]</English>
		<French>[ICON_BULLET]+%s1%F2[SPACE]</French>
		<German>[ICON_BULLET]+%s1%F2 durch Geländeart[SPACE]</German>
		<Italian>[ICON_BULLET]+%s1%F2 per[SPACE]</Italian>
		<Spanish>[ICON_BULLET]+%s1%F2 por[SPACE]</Spanish>
	</TEXT>


The desire effect is 0.50 Happiness per forest feature.
 
Oh sorry Asaf do you mean this in GameTxtmgr?:

Code:
/*************************************************************************************************/
/**	DecimalHappiness						07/18/08								Vehem		**/
/**																								**/
/**						Transforms Float Value to INT for display								**/
/*************************************************************************************************/
/**								---- Start Original Code ----									**
		iNewAnger -= std::min(0, city.getFeatureBadHappiness());
/**								----  End Original Code  ----									**/
		iNewAnger -= int(std::min(0.0f, city.getFeatureBadHappiness()));
/*************************************************************************************************/
/**	DecimalHappiness							END												**/
/*************************************************************************************************/
		iAnger = ((iNewAnger - iOldAnger) + std::min(0, iOldAnger));
		if (iAnger > 0)
		{
			szBuffer.append(gDLL->getText("TXT_KEY_ANGER_FEATURES", iAnger));
			szBuffer.append(NEWLINE);

and this?:

Code:
/*************************************************************************************************/
/**	DecimalHappiness						07/18/08								Vehem		**/
/**																								**/
/**				Replaces INT values with Float Values for Feature Happiness						**/
/*************************************************************************************************/
/**								---- Start Original Code ----									**
		iHappy = city.getFeatureGoodHappiness();
/**								----  End Original Code  ----									**/
		iHappy = int(city.getFeatureGoodHappiness());
/*************************************************************************************************/
/**	DecimalHappiness							END												**/
/*************************************************************************************************/
		if (iHappy > 0)
		{
			iTotalHappy += iHappy;
			szBuffer.append(gDLL->getText("TXT_KEY_HAPPY_FEATURES", iHappy));
			szBuffer.append(NEWLINE);
		}
 
I meant the first one.
The code seems to be fine, but I might be missing something. Can you post the XML for this civic?

BTW, is this my Unique Civics mod comp peeking in the screen shot? ;)
 
That's it alright right, and an excellent mod it is too. Also using your DLL with BBAI as a base. I'm currently busy coming up with different unique civic for each of the 84 civs in my mod (an exapansion on Thomas' War) so I'm grabbing civic functionality from various mods and also copying tags and writing a few simple ones myself. One day I might even get it finished...;)

The XML for Druidism
Code:
<CivicInfo>
			<CivicClass>CIVICCLASS_ORGANIZED_RELIGION</CivicClass>
			<Type>CIVIC_DRUIDISM</Type>
			<Description>TXT_KEY_CIVIC_DRUIDISM</Description>
			<Civilopedia>TXT_KEY_CIVIC_DRUIDISM_PEDIA</Civilopedia>
			<Strategy>TXT_KEY_CIVIC_ORGANIZED_RELIGION_STRATEGY</Strategy>
			
			<Button>Art\Interface\Buttons\Civics/druidism.dds</Button>
			<TechPrereq>TECH_MONOTHEISM</TechPrereq>
			<iAnarchyLength>1</iAnarchyLength>
			<Upkeep>UPKEEP_HIGH</Upkeep>
			<iAIWeight>0</iAIWeight>
			<iGreatPeopleRateModifier>0</iGreatPeopleRateModifier>
			<iGreatGeneralRateModifier>0</iGreatGeneralRateModifier>
			<iDomesticGreatGeneralRateModifier>0</iDomesticGreatGeneralRateModifier>
			<iStateReligionGreatPeopleRateModifier>0</iStateReligionGreatPeopleRateModifier>
			<iDistanceMaintenanceModifier>0</iDistanceMaintenanceModifier>
			<iNumCitiesMaintenanceModifier>0</iNumCitiesMaintenanceModifier>
			<iCorporationMaintenanceModifier>0</iCorporationMaintenanceModifier>
			<iExtraHealth>0</iExtraHealth>
			<iFreeExperience>0</iFreeExperience>
			<iWorkerSpeedModifier>0</iWorkerSpeedModifier>
			<iImprovementUpgradeRateModifier>0</iImprovementUpgradeRateModifier>
			<iMilitaryProductionModifier>0</iMilitaryProductionModifier>
			<iBaseFreeUnits>0</iBaseFreeUnits>
			<iBaseFreeMilitaryUnits>0</iBaseFreeMilitaryUnits>
			<iFreeUnitsPopulationPercent>0</iFreeUnitsPopulationPercent>
			<iFreeMilitaryUnitsPopulationPercent>0</iFreeMilitaryUnitsPopulationPercent>
			<iGoldPerUnit>0</iGoldPerUnit>
			<iGoldPerMilitaryUnit>0</iGoldPerMilitaryUnit>
			<iHappyPerMilitaryUnit>0</iHappyPerMilitaryUnit>
			<bMilitaryFoodProduction>0</bMilitaryFoodProduction>
			<iMaxConscript>0</iMaxConscript>
			<bNoUnhealthyPopulation>0</bNoUnhealthyPopulation>
			<iExpInBorderModifier>0</iExpInBorderModifier>
			<bBuildingOnlyHealthy>0</bBuildingOnlyHealthy>
			<iLargestCityHappiness>0</iLargestCityHappiness>
			<iWarWearinessModifier>0</iWarWearinessModifier>
			<iFreeSpecialist>0</iFreeSpecialist>
			<iTradeRoutes>0</iTradeRoutes>
			<bNoForeignTrade>0</bNoForeignTrade>
			<bNoCorporations>0</bNoCorporations>
			<bNoForeignCorporations>0</bNoForeignCorporations>
			
			<bStateReligion>1</bStateReligion>
			<bNoNonStateReligionSpread>0</bNoNonStateReligionSpread>
			<iStateReligionHappiness>0</iStateReligionHappiness>
			<iNonStateReligionHappiness>0</iNonStateReligionHappiness>
			<iStateReligionUnitProductionModifier>0</iStateReligionUnitProductionModifier>
			<iStateReligionBuildingProductionModifier>25</iStateReligionBuildingProductionModifier>
			<iStateReligionFreeExperience>0</iStateReligionFreeExperience>
			<YieldModifiers/>
			<CapitalYieldModifiers/>
			<TradeYieldModifiers/>
			<CommerceModifiers/>
			<CapitalCommerceModifiers/>
			<SpecialistExtraCommerces/>
			<Hurrys/>
			<SpecialBuildingNotRequireds>
				<SpecialBuildingNotRequired>
					<SpecialBuildingType>SPECIALBUILDING_MONASTERY</SpecialBuildingType>
					<bNotRequired>1</bNotRequired>
				</SpecialBuildingNotRequired>
			</SpecialBuildingNotRequireds>
			<SpecialistValids/>
			<BuildingHappinessChanges/>
			<BuildingHealthChanges/>
			<FeatureHappinessChanges>
				<FeatureHappinessChange>
					<FeatureType>FEATURE_FOREST</FeatureType>
					<iHappinessChange>50</iHappinessChange>
				</FeatureHappinessChange>
			</FeatureHappinessChanges>
			<ImprovementYieldChanges/>
			<WeLoveTheKing/>
		</CivicInfo>

I haven't changed the Gameinfo.xml
If I leave the Gamestextmgr unedited the civiliopedia shows +50 Happiness per forest.
 
Not sure if i see that correct (and i really don't have any clue about C++), but the formattings show everywhere a %s, while you're dealing with floats, right?

(if i were you i would not think about this question unless someone with more knowledge has said anything about it)
 
Thanks for the compliment :)

Well, everything's seems fine :dunno: It should display '+0.50'.

Did you try debugging it? Place a breakpoint in the line with szFirstBuffer.Format and see what the value of szHappyString is.

@The_J - It's OK. There are strings there. The floats are handled before that (in the lines with szHappyString.Format).
 
Not sure if you still are having this problem, but did you try the Python file where it handles the Civlopedia?

I think it's CvMainInterface.py, keep in mind I am potentially wrong as I avoid Python like the plague

Whatever file it is, if you don't change it to a float there, then it'll return all kinds of wackiness
 
Actually, I don't know if this helps, but I made a quick search on iHappiness in the Python directory, and found something which can have some use. There is a code in CvPediaBuilding.py (starts on line 181, and ends on line 192) which is the following:
Code:
		iHappiness = buildingInfo.getHappiness()
		if self.top.iActivePlayer != -1:
			if (self.iBuilding == gc.getCivilizationInfo(gc.getPlayer(self.top.iActivePlayer).getCivilizationType()).getCivilizationBuildings(buildingInfo.getBuildingClassType())):
				iHappiness += gc.getPlayer(self.top.iActivePlayer).getExtraBuildingHappiness(self.iBuilding)
			
		if (iHappiness > 0):
			szText = localText.getText("TXT_KEY_PEDIA_HAPPY", (iHappiness,)).upper()
			screen.appendListBoxStringNoUpdate(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.HAPPY_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
			
		elif (iHappiness < 0):
			szText = localText.getText("TXT_KEY_PEDIA_UNHAPPY", (-iHappiness,)).upper()
			screen.appendListBoxStringNoUpdate(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.UNHAPPY_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)

I changed the above code to this:
Code:
		iHappiness = buildingInfo.getHappiness()
		if self.top.iActivePlayer != -1:
			if (self.iBuilding == gc.getCivilizationInfo(gc.getPlayer(self.top.iActivePlayer).getCivilizationType()).getCivilizationBuildings(buildingInfo.getBuildingClassType())):
				iHappiness += gc.getPlayer(self.top.iActivePlayer).getExtraBuildingHappiness(self.iBuilding)
			
		if (iHappiness > 0):
			[COLOR="Red"]float(iHappiness)[/COLOR]
			szText = localText.getText("TXT_KEY_PEDIA_HAPPY", (iHappiness,)).upper()
			screen.appendListBoxStringNoUpdate(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.HAPPY_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
			
		elif (iHappiness < 0):
			[COLOR="Red"]float(iHappiness)[/COLOR]
			szText = localText.getText("TXT_KEY_PEDIA_UNHAPPY", (-iHappiness,)).upper()
			screen.appendListBoxStringNoUpdate(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.UNHAPPY_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)

EDIT: Actually, I don't think this will help. It seems to be something with buildings, but you should give it a try. ;)
 
For that to achieve anything, it should be:
iHappiness = float(iHappiness)
 
But if you get an integer you will get an integer, not a floating variable.
suchen.gif

Edit: Oh, I forgot, Python is not type safe. :D
 
Yeah, so it could be fHappiness (or whatever), but then you'd have to implement the change globally. Just keeping the confusing iHappiness name is clearly the easy path.
 
But beside you have changed the getBuildingHappiness() return value you don't get a floating variable with this function.
 
Most of the civ code dealing with these sorts of things multiplies and divides the numbers by 100 to generate decimal points rather than using floats directly. I've had success following that method.
 
Back
Top Bottom