Sign in to follow this  

Fog of war

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there! I'm planning to create some sort of strategy game (like C&C?). One thing I'm not sure about is the fog of war. What I'd like to have: Every unit has a line of sight (like in Commandos). A cone or triangle, which starts at the unit and spreads out in a certain direction until a maximum range is reached. (Bad explaination, I know. But you know what I mean?) ;-) My problem: What if there are hundreds of units? I can't calculate that stuff for EVERY one of them, can I? And how would I actually render that fog of war? I have some experience with OpenGL, but drawing a smooth arbitrary shape all over the screen? Hummm?!? Thanks for your help!

Share this post


Link to post
Share on other sites
I would some kind of list stating what is currently hidden (or not) by fog of war. You could use this list every loop without having to update it. The only times you'd need to update it are when a unit or building is destroyed, created, or moved.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sartak
I would some kind of list stating what is currently hidden (or not) by fog of war. You could use this list every loop without having to update it. The only times you'd need to update it are when a unit or building is destroyed, created, or moved.


i duuno bout that, you dont want your game to start lagging when everyone decides to move all their units,so you should calculate it every loop, or if its too slow, you can just calculate say a quarter of all units, and then the next loop do the other ones that havent been calculated...or just calculate it for one unit per closely grouped units

and i think a los circle would be an idea, as your men may turn their heads...
and you dont get that annoying cant see behind the unit

Share this post


Link to post
Share on other sites
If you look at most RTS of today they seem to have a circular field-of-vision area around each unit. That's because it's faster to use than a cone (or triangle) and also a lot easier. You just mark the tiles within the radius of the FOV as visible.
However if you look at a game like the original Commandos, they use a triangle which rotates based on the viewing direction of the unit. This is much slower, but it's ok since Commandos does not have hundreds of units on screen every frame.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The problem is that the simplest implementation is an n-squared algorithm where every unit tests every other unit. Luckily you can do better. Actually this is the same problem as physics collision, or scene visibility. What you want to do is keep the units in a data structure that allows you to very quickly rule out most of the units, then go through the remainder one by one. These structures and algorithms come under the heading "spatial partitioning". Lots of stuff on the web about them. Quadtrees, octrees, whatever the non-hierarchical grid one is called etc.

There is also a good chance that you don't need ai units to test visibility every frame. As long as they react within half a second or so when not directly controlled nobody will notice.

RTS's use lots of tricks with lag like that. You tell a unit to go someplace and it immediately says "yes sir" and maybe plays an animation so you know it got the message, but doesn't actually move or change course for a little while. During that time it may be doing its pathfinding.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think that you would have to do a lot of work to do a simple fog of war, you'd have to change the AI, some c or c++ or whatever language you have chosen and opengl or directX well you can do it I am sure you can :) but I think that you will have to work a lot anyways I just wish you goodluck :D

Share this post


Link to post
Share on other sites

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this