ID:268922   Dec 28 2004, 3:56 pm Erm, well, seeing if a mob is in a mob's sight...a straight line infront of him...is there a proc for that already? Or is there another way to do it? Well, thanks for reading.
 Dec 28 2004, 4:02 pm Hell Ramen wrote: Erm, well, seeing if a mob is in a mob's sight...a straight line infront of him...is there a proc for that already? Or is there another way to do it? Well, thanks for reading. I believe AbyssDragon has a math library that contains a proc that does just this.
 Dec 28 2004, 4:08 pm In response to Teh Governator Oh...thanks!
 Dec 28 2004, 4:25 pm Hell Ramen wrote: Erm, well, seeing if a mob is in a mob's sight...a straight line infront of him...is there a proc for that already? Or is there another way to do it? Well, thanks for reading. Directly in front is probably not what you want, since it's a 0° field of view. A mob standing 2 tiles north and 1 east, for example, would be completely invisible. You probably want something more along the lines of a slightly wider field of view. Try these out: ```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 datom/proc/fov45(atom/target) return dir==get_approx_dir(src,target)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 ``` If you use these procs, you should also use view(src) to see if the target is actually visible. Using them would look something like this: ```if(fov45(target) && (target in view(src))) ... ``` The parentheses around (target in view(src)) are very important. Lummox JR
 Dec 28 2004, 4:40 pm In response to Lummox JR "The parentheses around (target in view(src)) are very important." :p because usr is its default, right? Well, thanks Lummox. That helps. :)
 Dec 28 2004, 4:41 pm In response to Hell Ramen Hell Ramen wrote: "The parentheses around (target in view(src)) are very important." :p because usr is its default, right? Well, thanks Lummox. That helps. :) Actually, it's because, it's checking to see if "target" is in the view of src, which is a list. And, since he's comparing to variable checks in that if(), he needs to place them around it, or else its precedent will misunderstand it.