1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

How do I show floating integers in Civilopedia

Discussion in 'Civ4 - SDK/Python' started by CaptainMidnight, Aug 28, 2011.

  1. CaptainMidnight

    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:



    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!
     

    Attached Files:

  2. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Oh, just to clarify, I'm pretty sure I've added all the other necessary parts to gametextmgr, the above code is just the part which is giving me grief.
     
  3. Pickly

    Pickly Prince

    Joined:
    Jun 5, 2009
    Messages:
    535
    Did you change whichever game text XML file this will be included in?
     
  4. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Yes, the XML is there too.
     
  5. Asaf

    Asaf Sleep Deprived

    Joined:
    Mar 22, 2010
    Messages:
    1,326
    Can you post the updated value of TXT_KEY_CIVIC_FEATURE_HAPPINESS?
     
  6. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    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.
     
  7. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    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);
    		}
     
  8. Asaf

    Asaf Sleep Deprived

    Joined:
    Mar 22, 2010
    Messages:
    1,326
    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? ;)
     
  9. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    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.
     
  10. The_J

    The_J Say No 2 Net Validations Retired Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    32,458
    Location:
    DE/NL/FR
    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)
     
  11. Asaf

    Asaf Sleep Deprived

    Joined:
    Mar 22, 2010
    Messages:
    1,326
    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).
     
  12. deepwater

    deepwater Chieftain

    Joined:
    Apr 17, 2011
    Messages:
    30
    Without looking deeper: Maybe an Overflow?
     
  13. TheLadiesOgre

    TheLadiesOgre Aspiring Codesmith

    Joined:
    Jan 16, 2009
    Messages:
    505
    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
     
  14. Nitram15

    Nitram15 Pro Libertate!

    Joined:
    Sep 15, 2009
    Messages:
    1,855
    Location:
    Hungary
    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. ;)
     
  15. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    For that to achieve anything, it should be:
     
  16. deepwater

    deepwater Chieftain

    Joined:
    Apr 17, 2011
    Messages:
    30
    But if you get an integer you will get an integer, not a floating variable.
    Edit: Oh, I forgot, Python is not type safe. :D
     
  17. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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.
     
  18. deepwater

    deepwater Chieftain

    Joined:
    Apr 17, 2011
    Messages:
    30
    But beside you have changed the getBuildingHappiness() return value you don't get a floating variable with this function.
     
  19. Tholal

    Tholal Emperor

    Joined:
    May 19, 2009
    Messages:
    1,676
    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.
     

Share This Page