CvLuaPlot::lChangeVisibilityCount() bug - fix

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,697
Location
Near Portsmouth, UK
Anyone who's ever tried directly manipulating the visibility of a tile via Lua knows it's broken - in that once a plot is visible to a team you can never hide it again.

Code:
> pPlot:GetVisibilityCount()
2
> pPlot:ChangeVisibilityCount(0, 10); pPlot:GetVisibilityCount()
3
> pPlot:ChangeVisibilityCount(0, -1); pPlot:GetVisibilityCount()
4
> pPlot:ChangeVisibilityCount(0, 0); pPlot:GetVisibilityCount()
5
> pPlot:ChangeVisibilityCount(0); pPlot:GetVisibilityCount()
5
> pPlot:ChangeVisibilityCount(0, false); pPlot:GetVisibilityCount()
5
> pPlot:ChangeVisibilityCount(0, true); pPlot:GetVisibilityCount()
6

The bug is in the CvLuaPlot.cpp file

Code:
//void changeVisibilityCount(TeamTypes eTeam, int iChange, InvisibleTypes eSeeInvisibleType = false, bool bInformExplorationTracking = false, bool bAlwaysSeeInvisible = false);
int CvLuaPlot::lChangeVisibilityCount(lua_State* L)
{
	CvPlot* pkPlot = GetInstance(L);
	const TeamTypes eTeam = (TeamTypes)lua_tointeger(L, 2);
	const int iChange = [B][COLOR="Red"]lua_toboolean[/COLOR][/B](L, 3); // This is a bug, it should be lua_tointeger
	const int eSeeInvisible = lua_tointeger(L, 4);
	const bool bInformExplorationTracking = lua_toboolean(L, 5);
	const bool bAlwaysSeeInvisible = lua_toboolean(L, 6);

	pkPlot->changeVisibilityCount(eTeam, iChange, static_cast<InvisibleTypes>(eSeeInvisible), bInformExplorationTracking, bAlwaysSeeInvisible);

	return 0;
}

One simple change and tiles can be made invisible again!

Code:
> pPlot:GetVisibilityCount()
0
> pPlot:ChangeVisibilityCount(0, 1); pPlot:GetVisibilityCount()
1
> pPlot:ChangeVisibilityCount(0, -1); pPlot:GetVisibilityCount()
0
> pPlot:ChangeVisibilityCount(0, true); pPlot:GetVisibilityCount()
0
> pPlot:ChangeVisibilityCount(0, false); pPlot:GetVisibilityCount()
0

Fortunately the lua method is only used by the debug code (in InGame.lua) and the LiveTuner Map panel, so the change won't affect anything in the core game - but it could break mods
 
Cool. Firaxis should include this in their next patch that's large enough to do something with the dll.
 
Forgive me for necro'ing a thread from way back when, but since you referenced me here... :lol:

I have a question. In the OP, there are two lines that look like this:

Code:
> pPlot:ChangeVisibilityCount(0, -1); pPlot:GetVisibilityCount()

In the first instance, the result was an increase of 1 in the GetVis result. In the second instance, the result was a decrease of 1. As I understand it, LUA toboolean considers anything not FALSE or NIL to be true, but that doesn't explain all the results above, based on the data fed into the function.

I know I'm dense, and definitely before coffee this morning, but I didn't see what exactly was the simple change?

Again, forgive me - have been working on this simple problem for a couple of days now and it's starting to irritate me greatly. I hate to admit it, but most of that first day was screwing around with "fog" when what I really wanted was to change "visibility..."

Thanks!
 
The first set of results is from the standard Firaxis (buggy) DLL. The second set of results are from my patched DLL.

Short answer, if you're not using a modded DLL, it is IMPOSSIBLE to decrease the visibility level of a hex via Lua
 
Top Bottom