ID:154587
 
fog of war has been mentioned before in several threads. i was wondering if the following idea for it could be implemented in byond, one copied from rogue-like games, but could also be used for strategy games.

when run, the game would have two maps in its memory. a "master map" with all of the normal information, and each player would have their own "player map". everything shown on the screen (if graphical) would come from the player map, which is absolutely empty in the beginning. the game would continously scan what is in "view range" and copy the information into the player map.

this would mean that in the beginning, the player would see nothing of the "main map" except for what is within sight. when he leaves an area, items and so may still appear to be there in his player map, but if moved or altered, this will automatically be updated with he comes within sight... a simulation of (inaccurate ;-) "memory". only changes within the range of sight will be noticed (and updated)

the problem would be saving objs and mobs into this player map as well, but it is not impossible, and a seperate function allowing a player to save his map on a local directory when logging off.

do you think it is possible to code this without getting TOO resource-intensive? and the problems with line of sight, capturing all of items within view... well, i would love to know what you think of it.
do you think it is possible to code this without getting TOO resource-intensive? and the problems with line of sight, capturing all of items within view... well, i would love to know what you think of it.

Well, the short answer is "yes." It should be fairly manageable. It could be a fair amount of coding to include all the things you want, but that's just because you have a lot of things planned, not because any of them is especially hard to do in BYOND...

One way to handle it would be to put the player's mob on the player's own private map level, and put a "dummy" mob on the "real" map level. Something like this (warning -- this is untested pseudo-code):

#define REAL_MAP_LEVEL 2

mob
player
var/mob/falsePlayer/dummy

New()
// Call whatever other New() procs have been defined for higher-level nodes:
. = ..()
// Create the player's "ghost" on the real map, at the same X, Y coordinates but using the real map's Z level:
dummy = new(locate(x, y, REAL_MAP_LEVEL))
spawn UpdatePrivateView()

proc/UpdatePrivateView()
while(src) // Do this as long as the mob is alive
var/tempItem

for(tempItem in view(dummy, 5))
var/turf/T = locate(tempItem:x, tempItem:y, z) // Find the turf that will need to be updated on the private view

if(isobj(tempItem) || ismob(tempItem))
T.overlays += tempItem

else if(isturf(tempItem))
var/turf/T = locate(tempItem:x, tempItem:y, z)
T.icon = tempItem:icon
T.icon_state = tempItem:icon_state

sleep(10) // Sleep 1 second, then repeat

This is very incomplete--for one thing, it doesn't address getting rid of obsolete overlays--but it might give you some ideas, anyway. Good luck!
In response to Guy T.
On 12/26/00 3:17 pm Guy T. wrote:
do you think it is possible to code this without getting TOO resource-intensive? and the problems with line of sight, capturing all of items within view... well, i would love to know what you think of it.

Well, the short answer is "yes." It should be fairly manageable. It could be a fair amount of coding to include all the things you want, but that's just because you have a lot of things planned, not because any of them is especially hard to do in BYOND...

I've been working on a fog-of-war library for a while, actually, and the results look promising on a small map. Unfortunately, due to BYOND's load-while-you-go method of getting images and overlays when they appear in your view range, it is possible to see the fringe of a new region when a player moves into it.

Since that problem won't go away, and there's no workaround, I'll release the code as-is sooner or later.
In response to Spuzzum
On 12/27/00 11:30 pm Spuzzum wrote:
I've been working on a fog-of-war library for a while, actually, and the results look promising on a small map. Unfortunately, due to BYOND's load-while-you-go method of getting images and overlays when they appear in your view range, it is possible to see the fringe of a new region when a player moves into it.

Can't you extend the fog to world.view+1, if you're using range() to test things?

/Andreas
In response to Gazoot
On 12/28/00 12:29 pm Gazoot. wrote:
On 12/27/00 11:30 pm Spuzzum wrote:
I've been working on a fog-of-war library for a while, actually, and the results look promising on a small map. Unfortunately, due to BYOND's load-while-you-go method of getting images and overlays when they appear in your view range, it is possible to see the fringe of a new region when a player moves into it.

Can't you extend the fog to world.view+1, if you're using range() to test things?

Nope; images don't appear on the client's screen until they are in the visible range, regardless of when they are created.
In response to Spuzzum
On 12/28/00 12:31 pm Spuzzum wrote:
On 12/28/00 12:29 pm Gazoot. wrote:
On 12/27/00 11:30 pm Spuzzum wrote:
I've been working on a fog-of-war library for a while, actually, and the results look promising on a small map. Unfortunately, due to BYOND's load-while-you-go method of getting images and overlays when they appear in your view range, it is possible to see the fringe of a new region when a player moves into it.

Can't you extend the fog to world.view+1, if you're using range() to test things?

Nope; images don't appear on the client's screen until they are in the visible range, regardless of when they are created.

I'm using that method and it works for me. I tried without world.view+1 and got the same glitches as you. But if you move really fast that doesn't matter either. Lucky for me my game screen doesn't move fast.

/Andreas