Map visibility, fog of war, &c in SDK

hooj

Chieftain
Joined
Apr 27, 2006
Messages
5
Location
Idaho
I've been looking through the SDK trying to figure out how tile visibility/revealedness works, and how to change it. I've found CvPlot::isRevealed() and CvCity::isRevealed(), as well as CvPlot::isVisible() and CvCity::isVisible(). The problem is, I'm not sure I'm using them properly.

The idea is to share vision with a friendly civ, something like in Starcraft or whatnot. So in CvPlot::isVisible() I put:
Code:
   for (int iI = 0; iI < MAX_PLAYERS; iI++)
    {
      if (GET_PLAYER(GET_TEAM(eTeam).getLeaderID()).isFriendOf((PlayerTypes)iI))
      {
        if ((getVisibilityCount(GET_PLAYER((PlayerTypes)iI).getTeam()) > 0) || (getStolenVisibilityCount(GET_PLAYER((PlayerTypes)iI).getTeam()) > 0))
          return true;
      }
    }

and in CvPlot::isRevealed() & CvCity::isRevealed():

Code:
    for (int iI = 0; iI < MAX_PLAYERS; iI++)
    {
      if (GET_PLAYER(GET_TEAM(eIndex).getLeaderID()).isFriendOf((PlayerTypes)iI))
      {
        if (m_abRevealed[GET_PLAYER((PlayerTypes)iI).getTeam()])
          return true;
      }
    }

This has the interesting effect of showing friends' units as they explore the map, but not actually 'revealing' the map, meaning units wander about over black tiles. When mousing over, the terrain info is revealed, but the map itself isn't (see the pic). Also, once the 'friendship' is broken (isFriendOf() no longer returns true for the player), all the benefits are lost: any territory previously visible only to the friend vanishes from the player's map.

Changing isRevealed() and isVisible() is a poor solution to this problem. Ideally, whenever a friend moves a unit, expands culture, etc.--anything that reveals/makes visible a map square--I'd like to also update the *player's* actual map. But I can't figure out how to do this, in Python or the SDK. Any suggestions?
 

Attachments

  • wackyeffect.JPG
    wackyeffect.JPG
    60.8 KB · Views: 91
I think the problem is that isVisible() and isRevealed() just check to see if the plot is revealed, returning true if it is, and false if it isn't. They don't actually change the state of the plot.

I think the function you are after may be called CvPlot::changeVisibilityCount(...) but I can't be certain as I don't have a copy of the files with me.
 
That format looks very similar to java code, and their naming conventions for functions/methods is either:

is/get.*something*() which gets something's state

and

set.*something*()

You might want to try those if what TGA suggested doesn't work.

On a side note, this would be a wonderful new diplomacy action, like trading world maps, but trading espionage info instead. This would let people know what their friends are doing to help coordinate strategies and stuff, without the need to put one of your three spies in their territory.
 
After playing around with changeVisibilityCount and all that, I discovered a much better way to implement shared vision. The Civ engine already supports it through "stolen visibility". So setting stolenVisibilityTimer to some arbitrarily high number and preventing it from being changed automatically enables shared vision. Very simple & easy to implement.
 
Back
Top Bottom