Promotions Displayed with Unit Icon

I mod you and you mod me?
At least the rest of us can benefit from your mod duel here.

Thanks you both! :D

PS: Yes, I'd also like to see that in Thal's Combo Mod. There is only Copasetic UI Tweaks interfering AFAIK. But what do I know compared to you mod magicians!
 
there's a bug with strategic view:
Code:
    if InStrategicView() then
        self.m_IsFlagDisplayed = self.m_IsFlagDisplayed and (g_GarrisonedUnitFlagsInStrategicView or not self.m_IsGarrisoned)

this should be

Code:
    if InStrategicView() then
        self.m_IsFlagDisplayed = self.m_IsFlagDisplayed and g_GarrisonedUnitFlagsInStrategicView and self.m_IsGarrisoned

(this bug was introduced due to wrong negation of negation of original formula)

And maybe it is no more a good idea to hide promotions with icons (initial it was looking ugly enough, but with your small icons w/o background it looks good), user can than have the promotion icons also in strategic view.
 
That was a rather confusing line to figure out, for sure, since there's so many variables controlling visibility scattered throughout UnitFlagManager.lua. I was trying to deduce what the cumulative logic might be since we can't always be 100% sure the game's base code is error-free, which is why I didn't do a straightforward logic combination. In this case I think you're right. I traced back the variables while writing that line of code, I believe the first version says:

show unit icon if (in strategic view) AND (is visible - not in combat) AND (not invisible - not in fog of war) AND (city banners displayed in strategic view OR is not in a city)

Second version:

show unit icon if (in strategic view) AND (is visible - not in combat) AND (not invisible - not in fog of war) AND (city banners displayed in strategic view) AND (is in a city)

Checking ingame I believe the second version is what they intended, so you're right. This is why I created 1 variable to track if a flag is displayed in the UI... with no central location for this status in the vanilla game code, it was real head-on-keyboard frustration to figure out how they determine visibility through all the different functions altering a half-dozen variables, most with ambiguous names.

I mean seriously, Firaxis has it set up where things can be IsCurrentlyVisible and IsInvisible at the same time! :lol:


Are the promotion icons tied to the unit icon in any way? I didn't experiment with that much because I haven't fully familiarized myself with UnitFlagManager.xml. I agree entirely it makes sense to give the checkboxes independent functionality. If all that's necessary is to add a "Hidden=" field to UnitIconAnim and code to handle it, would be a superb improvement.
 
Are the promotion icons tied to the unit icon in any way? I didn't experiment with that much because I haven't fully familiarized myself with UnitFlagManager.xml. I agree entirely it makes sense to give the checkboxes independent functionality. If all that's necessary is to add a "Hidden=" field to UnitIconAnim and code to handle it, would be a superb improvement.

Well, it's a bit strange, but the code
Code:
    --self.m_Instance.Anchor:SetHide(not self.m_IsFlagDisplayed);
    self.m_Instance.FlagShadow:SetHide(not self.m_IsFlagDisplayed);
seems to work ;)

There is now a positioning problem: promotions on garrisoned units shown over cities defense. May be put the iconstacks to the left of unit icon, with vertical growth?
 
I think we can use these variables to alter the offset value of the promotions on the fly when a unit icon moves around:

Code:
local GarrisonOffset = Vector2( -43, -39 );
local GarrisonOtherOffset = Vector2( -55, -34 );
local CityNonGarrisonOffset = Vector2( 45, -45 );
local CivilianOffset = Vector2( 35, 0 );

So if we override the UpdateFlagOffset function, call it from the override function and then do the same algorithm for the promotions... testing..

It took a few more small edits to completely decouple the unit icons from promotions, but I seem to have gotten it to work now. In addition, I also stored the offset values locally in the lua code (instead of the xml), which allowed the inclusion of a rather nifty feature: if promotions are displayed but not unit icons, the promotions take the spot of the unit icon.
 

Attachments

Okay, so this is just crazy! :badcomp:

Not only do they have so many variables for visibility with no central control, sometimes they ignore the variables entirely and other times they use them. For example, when going into combat they directly hide the anchor without updating the variables or calling UpdateVisibility. When coming out of combat, they DO then call UpdateVisibility, which relies on those variables!

  • Local, manual control in one place without updating central variables
  • Use the central function and central variables to undo it for another task
This basically means that since we changed the function to deal with the flagshadow instead, the anchor never gets re-hidden. Why create a centralized visibility-handling function if it's not even used most of the time?

It feels like this code was written by multiple people with multiple programming styles, in a rush or with loose style guidelines...

Anyway... enough of my rant :crazyeye:

The reason I even mention it at all is it actually surprises me. I learned a lot about good programming style from years looking at Civilization 4's c++ and python code, and most of Civilization 5 code (that I've seen) is decently well done... but this UnitFlagManager file is just a mess.

I did get that problem solved though, I think - if anyone notices any issues please point it out.
 
the bottom left command bar is missing with this mod turned on for me... anyone else have this problem?
 
Awesome work Erendir and Thalassicus.

And I don't mind if either or both of you take this mod and put it into a pack or even distribute JUST this mod with your enhancements. The entire thing was just me getting familiar with an area of code which I identified as being the most painful to work with. Seeing the end product developed so much further is quite a delight :)

I am not sure if I can remove the mod I have in the ModBrowser completely (so that if you post this mod as a standalone the older version isn't present to confuse people) or re-assign the ownership of it to one of you guys. If neither of those are possible, I'll request permission to just list you two as co-authors and upload your latest version to the Browser.


It is semi-rare that I remember to pop over here and check on the status of this thread. I like writing in LUA only slightly more than writing in Python, so I've been ignoring Civ5 for the most part while I wait to have access to the C++ code :D
 
the bottom left command bar is missing with this mod turned on for me... anyone else have this problem?

Do a search in your /MODS folder for "UnitPanel.lua" and check for duplicates. Two mods altering a core game file simultaneously usually causes stuff related to the file to crash.

@xienwolf
It's possible to set versions to 'private', hiding the old version. Erendir could then upload a version with a different mod ID and slightly different name (such as "Flag Promotions" instead of "FlagPromotions").
 
@Thalassicus, xienwolf:

i'm trying to properly build up promotions tooltips for those with levels from database. This is the very beginnig:
Code:
local someP = DB.Query'SELECT * FROM UnitPromotions'()
local skip = {ID=true, PortraitIndex = true, OrderPriority = true} -- ignore these rows
for id, P in pairs(isPromotionwithlevels) do if type(id)=='number' then -- ipairs doesn't like holes in the array part of table
		-- generate ID List to ask, like: `(1,2)`
		local IDList = '('..isPromotionwithlevels[P.Pclass][1]
		local TypeList = '("'..PromotionIDlist[isPromotionwithlevels[P.Pclass][1]]..'"'
		for i = 2, P.suffix do
			IDList = IDList..','..isPromotionwithlevels[P.Pclass][i]
			TypeList = TypeList..',"'..PromotionIDlist[isPromotionwithlevels[P.Pclass][i]]..'"'
		end
		IDList = IDList..')'
		TypeList = TypeList..')'
		
		-- for every number valued row
		for k,v in pairs(someP) do if not skip[k] and type(v)~='string' then
			local sql = 'SELECT SUM('..k..') AS sum FROM UnitPromotions WHERE ID IN '..IDList
			local sum = DB.Query(sql)().sum --@!: this can be nil
			if sum and sum>0 then
				if type(v)=='boolean' then sum = true end
				P.Tooltip = (P.Tooltip or '')..'[NEWLINE]'..k..' '..tostring(sum)
			end
		end end
		
		-- some info is in other tables
		local r = DB.Query('SELECT SUM(Modifier) AS sum, UnitCombatType FROM UnitPromotions_UnitCombatMods WHERE PromotionType IN '..TypeList..' GROUP BY UnitCombatType' )()
		if r then
			P.Tooltip = (P.Tooltip or '')..'[NEWLINE]'..r.UnitCombatType..' '..tostring(r.sum)
		end
end end

My question: are there any stored values for translation of things like "OpenDefense" or at least "UNITCOMBAT_MOUNTED", and/or some icons for them?
 
If I understand you correctly, I'm working on extending autotips to promotions, which should help a lot with that. I've had some people help me out with translations. In the unofficial patch you can take a look at these functions in InfoTooltipInclude.lua:

SetDefaultBuildingStatData
GetDefaultBuildingStatText
GetHelpTextForBuilding

I'm applying the same methods to promotions as I used for building tooltips. Very little of this stuff has translations, so I'm creating them in the UP - Tips - Language...*.xml files. :thumbsup:

It was a good find to discover names with a roman numeral are consistently leveled promotions. You might try something... one straightforward way to indicate which promotions are leveled is by adding that very stat to the promotions themselves. Something like:

ALTER TABLE UnitPromotions ADD PreviousLevel text default "";

Then scan through the database to set this for promotions with a previous level (using the roman numeral algorithm you devised, translated to sql). Separating the data from the primary lua code algorithms allows for very easy lua statements like "if (promotion1.PreviousLevel == promotion2) then". Check out the buildingStats table in InfoTooltipInclude to see an example of this. On lines 136 and 175 are custom-added stats, "CulturePerPop" and "LocalPlotCultureCostModifier." The second one is the fix for the Krepost bug, both handled with things like pBuildingInfo.LocalPlotCultureCostModifier.

These custom stats are added in UP - General.sql. I discovered it's also important database alterations like this be first in the load order.
 

Attachments

Do a search in your /MODS folder for "UnitPanel.lua" and check for duplicates. Two mods altering a core game file simultaneously usually causes stuff related to the file to crash.

@xienwolf
It's possible to set versions to 'private', hiding the old version. Erendir could then upload a version with a different mod ID and slightly different name (such as "Flag Promotions" instead of "FlagPromotions").


Cool, I'll look to install Steam on my computer sometime soon so I can swap this thing over to Private, if Erendir is interested in posting a mod himself :)


As for the tooltips, that is one of those things which I prefer to wait for the C++ code to be available to tackle, so that I can approach it from the insides with data compilation and simplification. Not that it can't be done with LUA, or wouldn't work as well/fast. I just don't know LUA well enough to belt it out as fast as I suspect I can with C++
 
I don't know anything about modding except how to download through the in game browser. I like Thal's small version of the icons, as they appear in his unofficial patch, but I don't want the entire unofficial patch. I've download the zip file from the link in his post, but don't know what to do with those files.
Can someone help me get Thal's version (v3) to work as a stand alone mod?
 
The way Civ's lua files work it's difficult to separate files from one another. Most of the unofficial patch relies on other parts of the patch.

TBC is different from CiVUP because TBC is xml and sql files... parts of TBC is mostly independent of one another and can be disabled. If a modder wants to separate out just the flag promotions part of the unofficial patch I'd be entirely supportive of that effort.

I hope that makes sense... basically, it can be done but would require a lot of work.
 
the options table does not work with right-click
i don't know how to access it.
i am updated to the latest patch from steam.
please help. =)
 
the bottom left command bar is missing with this mod turned on for me... anyone else have this problem?

i also have this problem. aside from not being able to access the option menu through rightclick the promotions icon button
 
the bottom left command bar is missing with this mod turned on for me... anyone else have this problem?

I am getting this problem too, I have searched in my /MODS folder but I only have RED modpack and a couple others that have no UnitPanel.lua

This is one of my favourite mods so any help would be much appeciated.

It seems to be only Settlers and Workers that are the problem as I my soldiers are unaffected.
 
the mod is incompatible with one of the latest patch.
 
Back
Top Bottom