Line of Sight

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
Raknor
Kobold
Posts: 9
Joined: Sun Aug 27, 2017 8:19 pm

Line of Sight

Post by Raknor »

Is it possible to have line of sight measure from the corners instead of the center is a token?

If yes how?

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Line of Sight

Post by aliasmask »

Not really. You can move the token to the corners and check line of sight, but that's not really practical.

Raknor
Kobold
Posts: 9
Joined: Sun Aug 27, 2017 8:19 pm

Re: Line of Sight

Post by Raknor »

I would recommend this be added as some game system calculate this way.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Line of Sight

Post by wolph42 »

didn't rumble created something like that? I recall a distance function doing this, but I've never used it. You might want to have a look in the wiki.

edit: ah yes Wiki: canSeeToken() has an ability to look at corners.

anyway, Wiki: getDistance() doesn't have that ability, but you could create a macro that does this. What you require is:
Wiki: getTokenX()/Y
Wiki: getTokenWidth()
Wiki: getTokenHeight() and
[h: gridSize = json.get(json.get(getInfo("map"), "grid"), "size")]

gettokenXY gets you the upper left corner of the token. getWidth/heigth wil give you the entire boundary of the token so you can calculate the 4 coords that make up the token.
Do the same for the target and, depending on the request, you can calculate the distance between the requested corner.If you work with pixels/cell only you can use the gridSize to change this into cells and your there!

That is, I'm assuming that you are looking for a function like: getTokenCornerDistance("Dragon", "Bottom_left", "Elf", "Top_Right", 0)
where '0' stands for 'distance in cells' with the other options: '1' for 'distance per cell units' and '2' amount of pixels.

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Line of Sight

Post by aliasmask »

You can calculate distance but I think he wants line of site. For example if you have a huge creature 5ft in to a 5ft corridor they can't see up the hall just the angle from the center to the corner of wall in to the hall. What ends up happening is creatures can see you but you can't see them.

I thought I recall some discussion a LONG time ago about being able to change the vision point to the front of the token or any of the 8 cardinal places of the token but I don't think anything was done about that.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Line of Sight

Post by wolph42 »

so you're talking more about an option in maptools to change vision from centre to vision from boundary? Which I'm guessing will be a MFPITA to program/calculate as instead of one point of vision from where the calculation is done, you need four...for each token, making the calculation load thus 4 times as heavy.

That and I created a 'dependability matrix' for the devs concerning light/fow/vbl and that thing is staggeringly complex (and incomplete). The amount of permutations to test everything probably lies close to 1000 required test every time you change something. Adding another layer of complexity might lead to heads of devs that spontaneously explode...

cause changing that would impact all three: light, fow and vbl...

with functions however (like the one I described above) I think you can do quite a bit.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Line of Sight

Post by wolph42 »

pure for the fun of it, here's the function:

not fully tested:
getTokenCornerDistance()

Code: Select all

<!-- getTokenCornerDistance("Dragon", "Bottom_left", "Elf", "Top_Right", 0) -->
[h:'<!-- returns a json: {"dx":12,"dy":15} -->']

[h:assert(argCount()==5, "ERROR: getTokenCornerDistance requires exactly 5 parameter, amount given: " + argCount(),0)]

[h:token1    = arg(0)]
[h:corner1    = lower(arg(1))]
[h:token2    = arg(2)]
[h:corner2    = lower(arg(3))]
[h:dpu        = arg(4)] <!-- distance returned in:  0: cells,  1: pixels per cell, 2: distance per cell -->

[h:gridSize    = json.get(json.get(getInfo("map"), "grid"), "size")]
[h:upc        = json.get(json.get(getInfo("map"), "grid"), "units per cell")]

[h:switchToken(token1)]
[h:x1    = getTokenX(1)]
[h:y1    = getTokenY(1)]
[h:w1    = getTokenWidth()]
[h:h1    = getTokenHeight()]

[h:switchToken(token2)]
[h:x2    = getTokenX(1)]
[h:y2    = getTokenY(1)]
[h:w2    = getTokenWidth()]
[h:h2    = getTokenHeight()]

[h,switch(corner1),code:
    case "top_left": {
        <!-- do nothing -->
    };
    case "top_right": {
        [x1    = x1 + w1]
    };
    case "bottom_right": {
        [x1    = x1 + w1]
        [y1    = y1 + h1]
    };
    case "bottom_left": {
        [y1    = y1 + h1]
    };
    default: {
        [error_message    = "ERROR in getTokenCornerDistance, unknown corner: " + corner1]
        [pause("error_message")]
    }
]

[h,switch(corner2),code:
    case "top_left": {
        <!-- do nothing -->
    };
    case "top_right": {
        [x2    = x2 + w2]
    };
    case "bottom_right": {
        [x2    = x2 + w2]
        [y2    = y2 + h2]
    };
    case "bottom_left": {
        [y2    = y2 + h2]
    };
    default: {
        [error_message    = "ERROR in getTokenCornerDistance, unknown corner: " + corner2]
        [pause("error_message")]
    }
]

[h:dx    = abs(x2 - x1)]
[h:dy    = abs(y2 - y1)]

[h,switch(dpu),code:
    case 0: {
        <!-- distance in cells -->
        [dx    = round(dx/gridSize,0)]
        [dy    = round(dy/gridSize,0)]
    };
    case 1: {
        <!-- distance in pixels -->
    };
    case 2: {
        <!-- distance in cells -->
        [dx    = round(dx/gridSize,0) * upc]
        [dy    = round(dy/gridSize,0) * upc]
    };
    default: {
        [error_message    = "ERROR in getTokenCornerDistance, unknown distance per cellunit: " + dpu]
        [pause("error_message")]
    }
]

[h:macro.return =    json.set("{}", "dx", dx, "dy", dy)] 
this could be done much more efficient and compact, but this gives a good overview of what is happening while running the code. As I'm on a roll, here the compact version:
getTokenCornerDistance() compact

Code: Select all

<!-- getTokenCornerDistance("Dragon", "Bottom_left", "Elf", "Top_Right", 0) -->
[h:'<!-- returns a json: {"dx":12,"dy":15} -->']

[h:assert(argCount()==5, "ERROR: getTokenCornerDistance requires exactly 5 parameter, amount given: " + argCount(),0)]
<!-- arg(4): distance returned in:  0: cells,  1: pixels per cell, 2: distance per cell -->

[h:gs    = json.get(json.get(getInfo("map"), "grid"), "size")]
[h:upc    = json.get(json.get(getInfo("map"), "grid"), "units per cell")]

[h:dx    = 
    round(
        abs(
            getTokenX(1, arg(0)) + 
            if(indexOf( lower(arg(1)),"right")+1, getTokenWidth(arg(0)), 0) 
                - 
            getTokenX(1, arg(2)) - 
            if(indexOf( lower(arg(3)),"right")+1, getTokenWidth(arg(2)), 0)
        ) / if(arg(4)==0 || arg(4)==2, gs, 1) * if(arg(4)==2, upc, 1),0
    )
]

[h:dy    = 
    round(
        abs(
            getTokenY(1, arg(0)) + 
            if(indexOf( lower(arg(1)),"bottom")+1, getTokenHeight(arg(0)), 0) 
                - 
            getTokenY(1, arg(2)) - 
            if(indexOf( lower(arg(3)),"bottom")+1, getTokenHeight(arg(2)), 0)
        ) / if(arg(4)==0 || arg(4)==2, gs, 1) * if(arg(4)==2, upc, 1),0
    )
]

[h:macro.return =    json.set("{}", "dx", dx, "dy", dy)] 
edit: I've implemented this function in the BoT as bot_getTokCDistance(), but as AM said, probly not what you're looking for :)

Raknor
Kobold
Posts: 9
Joined: Sun Aug 27, 2017 8:19 pm

Re: Line of Sight

Post by Raknor »

thank you I will see if I can make the functions work.

and set the intent is to work with all 3.

I am playing a game what you can see and attack if you have a direct line from any corner of your square to any corner of there square. common method in games I find.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Line of Sight

Post by wolph42 »

Raknor wrote:thank you I will see if I can make the functions work.

and set the intent is to work with all 3.

I am playing a game what you can see and attack if you have a direct line from any corner of your square to any corner of there square. common method in games I find.
what do you mean with 'all 3' ?

as for the 'canSee' function, I *think* it works from 'centre of token' to 'any corner of other token', so its not entirely what you're looking for.
The function I created simply calculates *distance* between two corners of two token.

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: Line of Sight

Post by JamzTheMan »

Yea, I would actually like to include that and will look at it when the time comes...

FWIW, Pathfinder (and probably other DnD grid based games) do count all squares for LOS. Say a large (2x2) creature is standing with 1 square exposed around a corner, he can see down the hall. Furthermore, he can "attack" from any of those squares. You also can calculate "flanking" from any of those squares...

Now, does that mean a token can "see" from the center of any of those 4 squares or from ANY point in those squares? The later may be correct but the former is probably the closest solution attainable...
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

Raknor
Kobold
Posts: 9
Joined: Sun Aug 27, 2017 8:19 pm

Re: Line of Sight

Post by Raknor »

all 3 meaning fog of war, light, and line of site

if this is added I still would like to see it count from the corners of the token as an option. as this would work no mater the size of the token and some games describe it working from corner to corner.

User avatar
metatheurgist
Dragon
Posts: 363
Joined: Mon Oct 26, 2009 5:51 am

Re: Line of Sight

Post by metatheurgist »

JamzTheMan wrote:Yea, I would actually like to include that and will look at it when the time comes...

FWIW, Pathfinder (and probably other DnD grid based games) do count all squares for LOS. Say a large (2x2) creature is standing with 1 square exposed around a corner, he can see down the hall. Furthermore, he can "attack" from any of those squares. You also can calculate "flanking" from any of those squares...

Now, does that mean a token can "see" from the center of any of those 4 squares or from ANY point in those squares? The later may be correct but the former is probably the closest solution attainable...
3.5 and possibly 4th, line of sight is determined from a token's corners. If an unobstructed line can be drawn from one token's corner to another token's corner they can be "seen", that doesn't mean they don't have cover. I didn't notice those rules in 5th and I don't know about Pathfinder.

Personally though, I don't think we should be getting so hung up on grid mechanics when the visual presentation of Maptool is far superior. I think WotC and other game companies need to step up and embrace the present world of computer based gaming instead of living in the 70s.

Raknor
Kobold
Posts: 9
Joined: Sun Aug 27, 2017 8:19 pm

Re: Line of Sight

Post by Raknor »

pathfinder generally goes by the game mechanics of 3.5 and 5th edition leaves much of the "small stuff" up to the DM (DM decision if it is center or corner)
I think corner makes more since and you are not standing still in your square.

one of the benefits on using the line of site options afforded by a digital tabletop is to answer the question can I see the target quickly and accurately. by no means is this a make or break point.

my group just likes to be tactical when in combat and little things count.

PS. many companies have embraced the digital gaming trend and some even have there on digital options if you want to pay for them

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: Line of Sight

Post by JamzTheMan »

Raknor wrote:all 3 meaning fog of war, light, and line of site

if this is added I still would like to see it count from the corners of the token as an option. as this would work no mater the size of the token and some games describe it working from corner to corner.
Well, you would *still* want center as well, so draw from 5 points basically. It could probably be done but performance is going to take a hit until I can rewrite the fow engine, hopefully with libgdx to take advantage of the video card...
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

Post Reply

Return to “MapTool”