Line of Sight
Posted: Sun Aug 27, 2017 8:27 pm
Is it possible to have line of sight measure from the corners instead of the center is a token?
If yes how?
If yes how?
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)]
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)]
what do you mean with 'all 3' ?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.
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.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...
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...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.