Fog of War

by Forum_account
Fog of War
A library to create an RTS-style "fog of war" effect.
ID:755652
 
This is a great library and in every way what I am looking for. However I have a few questions about minor alterations I am looking to make:


1.

Instead of a view range of "3" (or any given number) giving you 3 steps of view in every direction including diagnal, I am looking for it to not include diagnal view steps. Instead, the view would just be that of how far a mob could move in those 3 steps without diagnal movement. Here's an example of what I want it to look like:

Photobucket



2. Is there anyway to remove the blackness? I am looking for the map to always be uncovered, but mobs cannot see eachother without being in their specified view ranges.


Thanks!
I haven't looked at this library in a while so I can't give you am answer off the top of my head. I'll give you a better answer later.

The first part should be easy. For the second part (removing the blackness) do you want to get rid of the gray part too? If so, there might be an easier way to accomplish that effect.
Nope, the gray part is great, as long as people can get an idea of what the general map looks like without knowing where other mobs on the map are.

Another issue that has just arisen though as well that I want to look into:

3. I want certain turfs where a mob could be, but even if another mob would have the vision range to see this other mob, the turf would prevent the mob from seeing the mob hidden in the turf, even though the mob in the turf can see the one that isn't hidden. Please let me know if this needs clarification!

Thanks for your time and quick responses!
In response to Speedro
Speedro wrote:
1. Instead of a view range of "3" (or any given number) giving you 3 steps of view in every direction including diagnal, I am looking for it to not include diagnal view steps. Instead, the view would just be that of how far a mob could move in those 3 steps without diagnal movement.

The library comes with a demo in the sight-demo folder which shows how to do this. You create a new type of FogSight object and make the player use that instead of the default /FogSight type:

FogSight
diamond
sight()
var/list/L = list()

for(var/turf/t in range(radius, mob))
var/dx = abs(t.x - mob.x)
var/dy = abs(t.y - mob.y)

if(dx + dy <= radius)
L += t

return L

mob
Login()
..()

client.fog = new(client)
client.fog.init()

fog_sight = new /FogSight/diamond(src, client, 3)

2. Is there anyway to remove the blackness? I am looking for the map to always be uncovered, but mobs cannot see eachother without being in their specified view ranges.

Change line 58 in fog-of-war.dm:

// change it from this:
image = image('fog-of-war.dmi', tile, "0000", FOG_LAYER)

// to this:
image = image('fog-of-war.dmi', tile, "[value][value][value][value]", FOG_LAYER)

Then add this to your project:

FogTile
value = 1

The value var can have a value of 0, 1, or 2. 0 means the player hasn't explored it (show it as black), 1 means they've explored it but can't currently see it (show it as gray), 2 means they can currently see it.

3. I want certain turfs where a mob could be, but even if another mob would have the vision range to see this other mob, the turf would prevent the mob from seeing the mob hidden in the turf, even though the mob in the turf can see the one that isn't hidden. Please let me know if this needs clarification!

What are you using that for? Are you trying to use opaque walls? Or create elevation (ex: the mob standing on top of the cliff can see mobs at the bottom, but the mobs at the bottom can't see the one on top)?
In response to Forum_account


3. I want certain turfs where a mob could be, but even if another mob would have the vision range to see this other mob, the turf would prevent the mob from seeing the mob hidden in the turf, even though the mob in the turf can see the one that isn't hidden. Please let me know if this needs clarification!

What are you using that for? Are you trying to use opaque walls? Or create elevation (ex: the mob standing on top of the cliff can see mobs at the bottom, but the mobs at the bottom can't see the one on top)?

Yes, much like a cliff. For example, if a mob enters a 1-tile building, then it can still see outside, but the mob outside cannot see the mob inside.

Also thanks for the quick and helpful replies on the other one!


Speedro wrote:
Yes, much like a cliff. For example, if a mob enters a 1-tile building, then it can still see outside, but the mob outside cannot see the mob inside.

The easiest way to do that is similar to making the diamond-shaped view. You're just changing the set of turfs the mob can see so it's really the same thing. It just depends on how exactly you want this to work and how you want this to work:

turf
var
outside = 1

FogSight
sight()
var/list/L = list()

var/turf/mob_loc = mob.loc

for(var/turf/t in range(radius, mob))

// if you're outside you can't see inside
if(mob_loc.outside && !t.outside)
continue

// also make sure the turf is within the diamond-shaped range
var/dx = abs(t.x - mob.x)
var/dy = abs(t.y - mob.y)

if(dx + dy <= radius)
L += t

The turf's outside var is used to determine which turfs you can see. If you're inside you can see any turf, but if you're outside you can only see other outside turfs.
Hmm, i've got a wierd question - I'm trying to make it so that instead of the fog updating every tick, i can manually control when it updates - But your tick proc which causes the update is in FogSight, rather than being a global system - So i'm having some difficulty figuring out what/where to pass if I wanted, say, a mob/proc to cause the update.

I know that was poorly worded, so i'll be more specific - I would like to make it so that the fog and sight are not updated for a client until AFTER it moves, not during. So, lets say you have 4 "movements" in your turn. I don't want you to be able to "see" whats around you until you confirm your movement.


Ideally, i would like to have a global proc/Update_Fog(), which would update every client, and not have anyhting update until then.


I can easily take care of removing the tick update - it's passing the proc it uses to a mob, or obj, etc that's causing me trouble.


(Hopefully i've given you enough to understand what i'm trying to do.)
That's an interesting use. I think the easiest way to handle this is for the library to give you a way to pause updates for a mob. That way you'll just need to pause updates for a mob when their turn starts and resume them once their move is confirmed. It'll require some changes to the library, maybe I'll have time tomorrow to post an update.
Alright then :)

Gotta say, you are by far the most helpful person in byond - Way above and beyond. Thanks mate :)
Anyways, that hint's enough that I should be able to get this to work fine :)
All I did was add a "paused" var on the FogSight object that's either 0 or 1 and I changed line 287 of fog-of-war.dm to this:

if(changed && !paused)

I don't think I'll bother posting an update if this is the only change, but it'll be included in future versions.
That's pretty much exactly what I did :)