Fog of War


This is part of a series on how this game was implemented technically, as part of the Game Jam it was developed for. It is recommended to read them roughly in-order as later blog entries may refer to earlier ones.

Technical:

  1. State Machine
  2. Pathfinding/Movement
  3. Isometric Rendering
  4. API
  5. Control Sources
  6. AI
  7. Networking
  8. Fog of War
  9. Bit Packing
  10. Palette Shifting

Other:

----

Fog of War

Fog of war was implemented in multiplayer game modes.

Briefly mentioned in the "AI" blog post, if two units are equally balanced, then depending on the map, whoever moves first will either always win, or always lose.  This makes PvP uninteresting. 

To resolve this, we use Fog of War.

Fog obscures enemy units until you move into it. Once you clear fog, you can attack units that are revealed. If you try and move through a unit hidden in fog, you'll immediately be set to "wait" without being able to attack. This means there's some element of risk moving into fog.

------

how fog is implemented:

The API will has a function that can return a character at a given cell. If fog is enabled, all we have to do is change this one check to block out units hidden in fog. All down-stream code will simply work as usual, not knowing there's a unit in the fog.

The only major catch is that when you're playing PvP, when fog should only be revealed if it's your turn. The enemy needs their own fog revealed/not revealed so they can do their actions, but you shouldn't be able to see that.

So the renderer is made aware, if you're playing on the network & it's not your turn do the following:

  • back up the current game state
    • set the fog as though it's your turn
    • render the game
  • restore the backup

you'll only ever see fog rendered as though it's your turn, and the game will see fog as though it's the enemy's turn.

------

The other check is that fog needs to be revealed step-wise as your unit moves along its path. If your unit tries to move into an occupied cell, it needs to know if that cell is taken.

In PvP you can use this movement path to clear fog and come up with some creative scouting techniques.

Leave a comment

Log in with itch.io to leave a comment.