ID:170815
 
Anyone know of a demo with enemy vision, like on METAL GEAR SOLID where each enemy has a radar, and when he moves it aims a different direction?
Siientx wrote:
Anyone know of a demo with enemy vision, like on METAL GEAR SOLID where each enemy has a radar, and when he moves it aims a different direction?

Could you be a bit more specific? I hate obscure little references to game that not everyone has played, so please try to be more general. Perhaps some screenshot linkage would help.
In response to Malver


P.S. Don't mind the "!" on the bottom left picture, i forgot to remove it.
In response to Siientx
It seems to me what you're trying to accomplish could be done with a simple view(radar_range,src) and an approximate directional test. Here's one example:
proc/get_approx_dir(atom/ref,atom/target)
var/d=get_dir(ref,target)
if(d&d-1) // diagonal
var/ax=abs(ref.x-target.x)
var/ay=abs(ref.y-target.y)
if(ax>=(ay<<1)) return d&12 // keep east/west (4 and 8)
if(ay>=(ax<<1)) return d&3 // keep north/south (1 and 2)
return d

mob/proc/CanSee45(atom/target, rng=world.view)
return (get_approx_dir(src,target)==dir && (target in view(rng,src)))

That gives the enemy about a 45° field of view. For a full 90° field of view like in your diagram, it'd be a tad different:
mob/proc/CanSee90(atom/target, rng=world.view)
var/d = get_dir(src,target)
if(d & turn(dir,180)) return 0 // see nothing behind me
if(!(d & dir)) return 0 // must have some common dir
/*
If src faces a diagonal, the above tests are enough and all we need
now is view(). Otherwise, the target may be just out of the 90° FOV,
so check for a "dominant" direction. E.g. if src faces south, target
must be mostly south or exactly diagonal to be visible.
*/

if(!(dir & dir-1)) // if facing a cardinal direction
var/ax=abs(x-target.x)
var/ay=abs(y-target.y)
if(dir&3)
if(ax>ay) return 0 // facing north/south but enemy is east/westish
else
if(ay>ax) return 0 // facing east/west but enemy is north/southish
return (target in view(rng,src))

Hopefully that'll make some sense.

Lummox JR
In response to Lummox JR
Thanks Lummoxy. ;) too bad i don't know how in god's name to put it into my game..
In response to Siientx
Siientx wrote:
Thanks Lummoxy. ;) too bad i don't know how in god's name to put it into my game..

That part should be child's play. Taking either proc, just plug in something like this:
if(enemy.CanSee90(src))
...


If you want to loop through all enemies in view, I have an alternative format to show you:
atom/proc/fov90(atom/target)
var/d=get_dir(src,target)
// rule 1: Must share common cardinal direction
// rule 2: Must not have opposite cardinal direction(s)
if(!(d & dir) || (d & turn(dir,180))) return 0
if(dir&dir-1) return 1 // if facing diagonal, above tests suffice
// rule 3: If facing a cardinal direction, target must not be mostly in another
var/ax=abs(x-target.x)
var/ay=abs(y-target.y)
if(ax>ay) return dir&12 // keep east/west (4 and 8)
if(ay>ax) return dir&3 // keep north/south (1 and 2)
return dir

With the fov90() proc, you can simply have each enemy check to see if it can see you.
for(var/mob/M in view(src))
if(M.team != src.team) // just one possible way of knowing an enemy
if(M.fov90(src))
M.Chase(src)

Lummox JR
In response to Lummox JR
Okay dokie, but where do i plug all of this IN? i can't just throw it into the game and hope it to work?
In response to Siientx
Siientx wrote:
Okay dokie, but where do i plug all of this IN? i can't just throw it into the game and hope it to work?

The procs I gave you should plug right in without a hitch. The only thing you have to do is make sure to call them the way you want.

Lummox JR