Visibility problem

Geekob

Chieftain
Joined
Apr 30, 2017
Messages
20
Hi guys,
I have a small problem. Im making outpost mode where forts get adjacent territory. I added feature where if fort is pillaged or removed and its territory is not directly connected to any city, it will lose it. But I have problem with visibility. It removes owner, but area keeps visible. I tried to use RevealAll and then UnrevealAll in case there is some update problem or something, but it keeps visible even after that. Only when someone builds city in that area it gets removed. I tried to look for some functions or events that handle this but I found only some get functions and UI functions responsible for Icon/panel visibility or something. Does anyone have experience with this problem? I would be thankful for any responses.
Spoiler active improvement :

Spoiler pillaged improvement :

This is code im using for that operation
Code:
function OnImprovementChanged(locationX, locationY, improvementType, improvementOwner, resource, isPillaged, isWorked)
    local plot = Map.GetPlot(locationX, locationY);
    local adjacentPlots = GetPlotsNotNearCity(plot);

    if (adjacentPlots ~= nil) then
        for _,plt in ipairs(adjacentPlots) do
            plt:SetOwner(-1);
        end
    end
end
 
Tile visibility is handled by a separate set of functions. Basically each tile is given a counter that says from how many 'sources' it is seen. When counter is 0 it means that you can't see it. Important thing is that owned tile also counts as 1.
Functions are in PlayerVisibility object: GetVisibilityCount and ChangeVisibilityCount.
 
oh, thanks man. Could you tell me what arguments it takes? I tried PlayerVisibility[0]:ChangeVisibilityCount(plot,0) but lua throws error.
 
1. To get PV object you can use either PlayersVisibility[iPlayer] (plural form) or PlayerVisibilityManager:GetPlayerVisibility[iPlayer].
2. Change function changes a count, doesn't set it. You need to to use Get first.
I don't think however that setting count to 0 is right approach. You might break internal counters if e.g. There's a unit that sees those tiles. I have not used those functions in a mod yet, just playing around. You need to do some testing first.
 
Oh, another hint. Try to find out / understand first why those tiles remain visible in the first place. It's probably connected to SetOwner. Somewhere in the process visibility counter is increased and needs to be decreased respectively when improvement is e.g. pillaged or destroyed.
 
I think its somehow connected to that improvement. Outer borders lose visibility (since you cant see 2 tiles wide area after border removal) but that improvement tile keeps its visibility even after border removal. I tried to add some more improvements around fort and then pillage it and those improvement tiles also keep visibility. Oh, I just found out that vanilla forts also keep visibility around tile, and all improvements I put to not owned area too.
Spoiler improvement visibility :


I thought it works like in civ 5, where forts didnt have visibility on their own. Ok nevermind, I will keep it this way then. It looks like its internal. I thought its just bugged.
 
Thanks for the insight regarding player visibility! Is there a similar handling for exploration? I'm writing a tuner panel that identifies resource locations and I would like to filter out those that located in unexplored plots.
 
Great suggestion. PlayersVisibility[playerID]:IsRevealed(x, y) return true iff the player designated by playerID has revealed the plot designated by x, y. Since I don't want to change the 'revealed' state it is exactly what I needed. Thank you! Thank you!!

In the vein of teaching me to fish, how did you know about the function?
 
Oh you didnt ask me. I just saw post on my thread so I thought you asked me :D
 
Didn't really intend to direct the question and I appreciate the answer. The spreadsheet appears to be very useful. Thanks for the pointer!
 
You can also do it by plotID:
Code:
pPlayerVis:IsRevealed(plotId)
Also there is this
Code:
	if pLocalPlayerVis:IsVisible(locX, locY) then
		return true;
	elseif pLocalPlayerVis:IsRevealed(locX, locY) then
		return true;
	end
But you have to test such things are valid in GameplayScripts because implementations are not the same between what is valid lua function(s) in UI files and what is valid in GameplayScripts.
 
Top Bottom