Unit Promotion -> UnitPanel Mod Bug

Aquilai

Chieftain
Joined
Nov 3, 2012
Messages
7
This is a bug that involves any mod that adds a Promotion. It has been mentioned in the Mods section of the forum but I wanted to bring this bug up a bit more formally.

I have created a mod for the simple purpose of demonstrating this bug. Please don't just dismiss this as something that is a "fringe case" because it's a mod and the mod might just be doing something complicated and unusual. The mod attached here, itself is straightforward xml and is only a demonstration. The bug persists with ANY mod that tries to add ANY unit promotions. Some modders have tried to bypass this problem by not using promotions at all but not all mods can be this limited.

The Problem
The promotions bug occurs when a new unit Promotion is added by xml (or sql). The mod I have attached here copies the existing PROMOTION_COMBAT_BOOST_4 in <UnitPromotions> to make a 5th unit combat promotion. The problem is that when CivBE starts up for the first time with a mod game, the database does not properly upload the new unit promotions. This causes a corruption that manifests as the unit panel being missing or unusual icons being displayed when you click on any unit:
Spoiler :
2e1UoQy.jpg

xHVH16H.jpg

(Turn 0, started a new game with mod)

Current Workaround
One of the reasons why this is a bug that modders can't fix is because the work around is simply to "Return to the Main Menu, click Mods and start a new/reload a saved game" without quitting CivBE. The gamer must return to the Main Menu and not just load/reload the saved game because it doesn't reset the database.

You're probably wondering, if it's such an easy work around why am I bringing this up? For someone doing a lot of playtesting and modding this work around is very time consuming. From a modder's perspective, if you have to tell players to "Start a game, Return to the Main Menu, Start a game again" that can be very awkward to promote your mod. Adding up the number of minutes per game load and number of times that a tester or gamer might have to do this, you will find you're wasting a lot of time waiting.

Conclusion
From the way that the bug can be worked around there is something subtly different with how CivBE first loads a Mod game and the way it loads the second and subsequent Mod games. Is there a hidden read database error the first time a mod game is played? Or is the database cleaned properly at the end of the first mod game thus making subsequent mod games read a cleaned version database.

Failed Investigation Notes
I have tried to look into the problem from a modder's perspective and below are some notes that may or likely may not help.
Spoiler :

(Error message found in "Lua.log" when the bug occurs. Separate instances.)
Note, due to commenting in the file (bad decision in hindsight) the line numbers may not match but the exact errors should be in your Lua.log file too.
Code:
UnitPanel: SPECIALIST_TRADER
UnitPanel: 4
Runtime Error: Assets\UI\InGame\WorldView\UnitPanel.lua:128: Could not find method to obtain action icon.
stack traceback:
	[C]: in function 'error'
	Assets\UI\InGame\WorldView\UnitPanel.lua:128: in function 'HookupActionIcon'
	Assets\UI\InGame\WorldView\UnitPanel.lua:316: in function 'UpdateUnitActions'
	Assets\UI\InGame\WorldView\UnitPanel.lua:1222: in function 'OnInfoPaneDirty'
	[C]: in function 'func'
	[C]: in function '(anonymous)'
Code:
UnitPanel: SPECIALIST_TRADER
UnitPanel: 4
Runtime Error: Assets\UI\InGame\WorldView\UnitPanel.lua:128: Could not find method to obtain action icon.
stack traceback:
	[C]: in function 'error'
	Assets\UI\InGame\WorldView\UnitPanel.lua:128: in function 'HookupActionIcon'
	Assets\UI\InGame\WorldView\UnitPanel.lua:316: in function 'UpdateUnitActions'
	Assets\UI\InGame\WorldView\UnitPanel.lua:1222: in function 'OnInfoPaneDirty'
	[C]: in function 'func'
	[C]: in function '(anonymous)'
UnitPanel: SPECIALIST_TRADER
UnitPanel: 4
Runtime Error: Assets\UI\InGame\WorldView\UnitPanel.lua:128: Could not find method to obtain action icon.
stack traceback:
	[C]: in function 'error'
	Assets\UI\InGame\WorldView\UnitPanel.lua:128: in function 'HookupActionIcon'
	Assets\UI\InGame\WorldView\UnitPanel.lua:316: in function 'UpdateUnitActions'
	Assets\UI\InGame\WorldView\UnitPanel.lua:1222: in function 'OnInfoPaneDirty'
	[C]: in function 'func'
	[C]: in function '(anonymous)'
UnitPanel: SPECIALIST_TRADER
UnitPanel: 4
Runtime Error: Assets\UI\InGame\WorldView\UnitPanel.lua:128: Could not find method to obtain action icon.
stack traceback:
	[C]: in function 'error'
	Assets\UI\InGame\WorldView\UnitPanel.lua:128: in function 'HookupActionIcon'
	Assets\UI\InGame\WorldView\UnitPanel.lua:316: in function 'UpdateUnitActions'
	Assets\UI\InGame\WorldView\UnitPanel.lua:1222: in function 'OnInfoPaneDirty'
	[C]: in function 'func'
	[C]: in function '(anonymous)'

These error message will not appear when you use the work around. Once again stressing that there is something very different in the way CivBE starts the first mod game and the second and subsequent mod games.

The error seems to indicate that there is a method missing but I decided to look into the action types to try and catch out the error. Inside UnitPanel.lua I added:
Code:
		if (action.Type == "SPECIALIST_SCIENTIST" or 
			action.Type == "SPECIALIST_LABORER" or 
			action.Type == "SPECIALIST_ENGINEER" or 
			action.Type == "SPECIALIST_GROWER" or 
			action.Type == "SPECIALIST_ARTIST" or 
			action.Type == "SPECIALIST_TRADER") then
			bShowActionButton = false;
		end
It removed the error messages but the problem didn't go away. The workaround was still required.

Still in the UnitPanel.lua file I added the following to the GetActionIconIndexAndAtlas array thinking that this was overlooked and could connect the missing method:
Code:
	[ActionSubTypes.ACTIONSUBTYPE_SPECIALIST] = function(action)
		local info = GameInfo.Specialists[action.Type];
		return info.PortraitIndex, info.IconAtlas;
Unfortunately, it too only removed the messages but the bug still persisted.

From that I added a for loop, debug print line to see all the action types. It turns out, there were X fewer action.types on first run of a modded game, than in the second run (bug workaround). Where X is the number of new unit promotions added. It indicates quite clearly that the database is ignoring the new unit promotions.

This is when I concluded that the promotions bug was something that a modder could not fix without inside knowledge of the game engine.

It seems obvious to say but there is something different with the first run of a mod game and the second and subsequent runs. The icons that are displayed on the first run seem to indicate that something is missing in the actions table so the game is filling in the promotions with the next row(s)/entries.


I hope that this bug report can help fix this because I personally don't feel comfortable releasing a mod where players are forced to start a game + leave to main menu again before they can properly start or continue their game.
 

Attachments

I would like to add, in case Firaxis monitors this subforum, this bug occurs when adding or removing any members that belong to the GameInfoActions Lua table. This would include build actions and specialists, making it a pain to implement things such as custom improvements and such.
 
Back
Top Bottom