[Lua Bug] Plot:ChangeVisibilityCount() fails to behave correctly

lilgamefreek

Warlord
Joined
Oct 30, 2014
Messages
229
When Plot:ChangeVisibilityCount() is called, it increments the plot's visibility counter no matter the arguments, making it impossible for the plot's to become rehidden. The reason for this is well documented by whoward69 here with reference to the bug's location in the source. It would be fantastic for modder's to have this feature working as intended.

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
 
Top Bottom