Author Topic: Line Of Sight  (Read 1589 times)

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Line Of Sight
« on: July 08, 2013, 02:34:04 PM »
Does anyone around have any experience with calculating line of sight on a grid between two points? I've done some research on the matter, and it seems a lot of people talk about ray tracing, but I'm not sure if that could entirely be applied towards MUDs and the Dead Souls grid system. Really all I'm hoping to accomplish is figuring line of sight from point A to point B. Ultimately I'm looking for a reliable 'scan' function that users can use as a limited view distance in a generalised cardinal direction. IE, scanning north will yield objects in view inside a cone pattern up to, say, five rooms in that general direction..

I'm thinking of just finding the slope from A to B and then finding any rooms that intersect, within reason, to the line. If there is a non room, or a room deemed as blockable, the remainder of the line is obscured from vision. This method seems crude but probably is all that's needed for something like a MUD.

Any thoughts or experiences on this?

Offline quixadhal

  • BFF
  • ***
  • Posts: 631
    • View Profile
    • WileyMUD
Re: Line Of Sight
« Reply #1 on: July 08, 2013, 05:54:26 PM »
Line of sight doesn't fully make sense in a room based MUD.  Here's why...

Normally, an LOS calculation is just finding a line segment between the observer and the target, and then checking for obstructions along that line.

In a room based MUD, how do you detect obstructions?  If rooms have walls, then each room is, itself going to kill LOS except through the perfect 90 or 45 degree angles of the room exits.  If it's an outdoors area, how do you handle geometries that aren't quite normal?

If you restrict it to ONLY a pure grid-based wilderness area, then you have the issue of how to determine what counts as an obstruction.  In short, if you don't provide a cover mechanic of some sort, there's not much value in LOS, since you could really say "everything in a 120 degree arc of the direction you're facing is visible".

If you do have cover, how do you determine the values?  You could try to use terrain types and percentages... basically, if the LOS is checking a path that intersects 5 rooms, and 3 of them are forest, you could give each forest room a 50% cover rating.  Meaning, you'd do 3 dice rolls and if any of them failed, the LOS is blocked.

If you don't have terrain, how else would you try to handle it?  Perhaps you could try to parse the descriptions for keywords, but that seems doomed to failure.

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: Line Of Sight
« Reply #2 on: July 09, 2013, 08:04:57 AM »
I think he is trying to duplicate the old ROM command 'scan', which lets you view livings in adjacent rooms with open doors and good light.

eg.
Code: [Select]
> scan east

due east is Entrance of Dungeon:
1 ugly orc

further east is Hall of Dungeon:
2 armored orcs

far east is Gates of Doom:
3 goblins

This is pretty easy to code. You just need to check each adjacent room using the exit paths, if a) the door is open and b) the light is sufficient. If the door is closed, then you get no further information from that direction. Then just display the RoomShorts and living lists.

-Detah

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: Line Of Sight
« Reply #3 on: July 09, 2013, 12:45:48 PM »
Well, in a sense, yes, but not exactly. That would limit the area scanned to be rooms along a straight line. For example, you could never scan a room that was 3 east and 1 north of you.

Sure, I could just code it so that when you 'scan east' you see e, ne, se, nne, sse, sese, etc... But it wouldn't take long for players to wonder why they are able to see that orc through a building.

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: Line Of Sight
« Reply #4 on: July 09, 2013, 01:09:37 PM »
So you want to be able to see the room which is 2e and 1n of your current position or not? If you do want to report that location, that is easy. It is the exact same code as I outlined earlier, except instead of just checking each 'east' Exit in the room for the next room, you would also report other exits (in this case north Exits) from adjacent rooms and post those results also. This is not difficult to code. But it will, as you mentioned, often produce odd results when you are reporting monsters from rooms which have multiple walls in between your line of sight.  I am not sure what you want to accomplish.

-Detah