Fog of War

by Forum_account
Fog of War
A library to create an RTS-style "fog of war" effect.
ID:119846
 
Keywords: fogofwar
This library has many things in common with the Dynamic Lighting and Visibility Groups libraries. It's essentially the same as dynamic lighting except the value of each tile isn't based on proximity to a light source, it's based on whether or not the player has explored a tile and whether or not they can currently see it.

It's also similar to visibility groups because it does use images to hide and show objects to certain players. This way you can only see mobs when they're standing on a tile that you can see. If a mob is standing on a tile that you haven't explored, or one that you have explored but have since moved away from, you won't be able to see that mob.

There are probably a few things you'd need to add to use it in a game, but it's fairly solid. You can have multiple mobs contribute to a player's sight (just like in an RTS how the player's sight is the combination of the sight of all units). If you delete a unit you lose its sight range. I tested that and it handles it okay, but I'm sure there are other cases it doesn't handle well.

There are also some things I'd like to add:

1. The library isn't exactly designed to be flexible. I can improve this more.

2. Add a proc that the user can call to check if a mob is visible to another mob or client.

3. Add an example of sight ranges with better visibility calculations. This relies on #1 but it'd also make this library function as a way to replace BYOND's built-in opacity/visibility system with something that's customizable.

4. Let mobs be able to contribute to the sight of multiple players (ex: so you can see what your ally's units can see too).

5. Check how well it runs and see if there's anything I can do to improve performance.
You beast. KEEP GOING DOOOD!
Love your work mate!
Yut Put wrote:
read my request on your side-blog. an instanced dungeon library would be amazing to have.

Doesn't SwapMaps do that? I've never used it, but it sounds like that does what you're asking for.

I think the bigger problem is designing objects in such a way that they work when inside of an instanced map. For example, you wouldn't be able to do something like this:

obj
dungeon_03_objects
switch_2
proc/use()
for(var/obj/dungeon_03_objects/door_2/d in world)
d.open()

door_2
proc/open()
icon_state = "open"
density = 0


You'd want to iterate over all instances of that door type in case the dungeon has multiple instances of the door, but if there are multiple instances of this dungeon it'd cause problems - it'd be opening doors in other people's dungeons. Part of the problem with handling instanced maps is creating and destroying instances as you need them, but a big part of it is also making maps work in such a way that they don't affect other instances. I'm not sure how a library would effectively cover both aspects of this problem.

i've been thinking of requesting a "world_ID" type client variable so that you can easily shift players between a single-user-esque mode while still being able to connect other players to it.

I'm not sure how you'd expect that to work, but you can use the visibility groups library to make a way for multiple players to inhabit the same area but have it look like they're in their own world - just add every object to a visibility group based on the "world_ID". If a player is in world named "world-123" all enemies that are spawned when that player enters a dungeon are added to the visibility group "world-123". All items dropped by those enemies are also added to the group "world-123". That way you'd only see objects in your world and wouldn't see objects in other people's worlds.

This is simple to do, but has some problems that'd be fixed by having separate map instances. For example, if you wanted to modify turfs the changes would be seen to all people in that world. If you're going to do elaborate modifications like that, instanced maps would work out better.

my solution was to ask you to solve this because I highly doubt the BYOND staff would want to implement that :)

I've heard Lummox talk about having some way to dynamically load/unload maps. I imagine it'd support this request, but I'd also bet that it'd be awful to use.
I second Yut Put's request for a map instancing library. I want to use this in my game Town Mall to instance stores for all of the players, and since the stores are maps that are completely customizable by the player, that visibility groups idea is not feasible. I've tried using SwapMaps, but not only is that library daunting to use, but it is highly inefficient and I was hoping you could possibly make a more efficient version.

I'm hoping that BYOND adds this in somehow, maybe by creating map datums, but I don't believe that is happening anytime soon. At the moment I'm not sure what do in my game because of this issue, make a limited amount of stores?
I'll see what I can come up with for instanced maps.
Combining this with Dynamic Lighting has some pretty awesome results.
Oooh. I'd love to see how you'd do map instancing, I've been wanting to be able to copy maps and SwapMaps is way too complicated to take the time to learn how to use it.
http://www.byond.com/developer/Forum_account/MapInstancing

It's easy to use but I have a feeling there's more that needs to be done when a map is copied.

It also requires that you have a copy of the map in the game, taking up space. It might be handy to be able to save maps to files and say "create this map from this file", but it doesn't currently support that.
Yut Put wrote:
............................................................................................................................................................................

i love you

edit: i really love you. this is even better than what i was asking for. thank you