Detect Magic Macro

Show off your RPG maps, campaigns, and tokens. Share your gaming experiences and stories under General Discussion and save this forum for things you've created that may help others run their own games. Use the subforums when appropriate.

Moderators: dorpond, trevor, Azhrei, Gamerdude

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

Detect Magic Macro

Post by JamzTheMan »

Ok, so I thought I'd create a simple macro that would expose "Magical Auras". There seems to be some oddities (I'd call it a bug) in the canSeeToken() function. Could a macro expert or someone that knows this function confirm? (I may have to look into a bug fix for it in that case).

That macro finds all tokens on the hidden layer with state "isMagical" up to 60 feet. I then pass each macro through a canSeeToken() function and hide any auras the token can't see due to FoW (I know you can see through some material but since thickness is unknown, I assume FoW is blocking aura just the same).

As you can see, tokens 1 & 3 were exposed, where I would expect 2 and 3 instead. All the tokens are either medium or tiny size, but not snapped to grid. It looks like the function is using the Cell of the x,y location of the token so if the upper left pixel of the token is in another cell, it uses that cell which throws everything off. It should use the footprint of the token instead should it not?

Is there a better way of doing this?
Macro code

Code: Select all

[h: cond = '{ range: {upto:12, distancePerCell:0, metric:"ONE_TWO_ONE"}, setStates:["isMagical"], layer:["HIDDEN"] }']
[h: tokenList = getTokenNames("json", cond)]
[h, FOREACH (token, tokenList): setLayer("TOKEN", token)]
[h: count = json.length(tokenList)]

[h, FOREACH(token, tokenList, "<BR>"), CODE:{
	[cantSee = json.isEmpty(canSeeToken(token))]
	[layer = if(cantSee == 1, "HIDDEN", "OBJECT")]
	[setLayer(layer, token)]
	[count = if(cantSee == 1, count - 1, count)]
}]

Exposed {count} magical auras.
For Reference
detect_magic_locations.jpg
detect_magic_locations.jpg (124.38 KiB) Viewed 1190 times
Macro Results
detect_magic_1.jpg
detect_magic_1.jpg (131.09 KiB) Viewed 1190 times
What was detected
detect_magic_2.jpg
detect_magic_2.jpg (308.33 KiB) Viewed 1190 times
What was not detected
detect_magic_3.jpg
detect_magic_3.jpg (314.41 KiB) Viewed 1190 times
-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

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

Re: Detect Magic Macro

Post by aliasmask »

Interesting. I don't think there is much you can do about it other than just being aware of where the upper left corner is and knowing it'll return the whole grid square. You may want to try free size and see what it does.

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

Re: Detect Magic Macro

Post by JamzTheMan »

Ya, I tried freesize as well. If it had just returned a true/false I'd accept that it would use the cell, but since it actually detects/returns a json array of any of the 4 corners + center if seen, using the cell could be way off on what is truly seen.

I'll dig into the code and see if it's an easy fix.
-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

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: Detect Magic Macro

Post by jfrazierjr »

JamzTheMan wrote: As you can see, tokens 1 & 3 were exposed, where I would expect 2 and 3 instead. All the tokens are either medium or tiny size, but not snapped to grid. It looks like the function is using the Cell of the x,y location of the token so if the upper left pixel of the token is in another cell, it uses that cell which throws everything off. It should use the footprint of the token instead should it not?
Well.. technically, tokens that are not snap to grid really don't have footprints, or should not anyway. The whole point of the footprint is in contextual relationship to a grid cell... Now... perhaps the java code is doing the wrong thing, but I think that's the way it was written based upon snap to grid tokens....
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

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

Re: Detect Magic Macro

Post by JamzTheMan »

jfrazierjr wrote:
JamzTheMan wrote: As you can see, tokens 1 & 3 were exposed, where I would expect 2 and 3 instead. All the tokens are either medium or tiny size, but not snapped to grid. It looks like the function is using the Cell of the x,y location of the token so if the upper left pixel of the token is in another cell, it uses that cell which throws everything off. It should use the footprint of the token instead should it not?
Well.. technically, tokens that are not snap to grid really don't have footprints, or should not anyway. The whole point of the footprint is in contextual relationship to a grid cell... Now... perhaps the java code is doing the wrong thing, but I think that's the way it was written based upon snap to grid tokens....
Ya, it was I suspected. It was coded to grab the bounds of the footprint of the token, which like you said, in a grid environment makes sense as the token is assumed to occupy all the cells it's snapped to (so a tiny token is still seen even if just the corner of the cell is seen).

Code: Select all

Rectangle bounds = target.getFootprint(grid).getBounds(grid, grid.convert(new ZonePoint(target.getX(),target.getY())));
A quick fix was to add:

Code: Select all

if(!target.isSnapToGrid())
  bounds = target.getBounds(zone);
This correctly uses the exact bounds of the token when not snapped to the grid as it should not have a "footprint" as it were.

I'll submit a patch for this as I consider it a bug, unless someone advises otherwise.
-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

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: Detect Magic Macro

Post by jfrazierjr »

JamzTheMan wrote:
jfrazierjr wrote:
JamzTheMan wrote: As you can see, tokens 1 & 3 were exposed, where I would expect 2 and 3 instead. All the tokens are either medium or tiny size, but not snapped to grid. It looks like the function is using the Cell of the x,y location of the token so if the upper left pixel of the token is in another cell, it uses that cell which throws everything off. It should use the footprint of the token instead should it not?
Well.. technically, tokens that are not snap to grid really don't have footprints, or should not anyway. The whole point of the footprint is in contextual relationship to a grid cell... Now... perhaps the java code is doing the wrong thing, but I think that's the way it was written based upon snap to grid tokens....
Ya, it was I suspected. It was coded to grab the bounds of the footprint of the token, which like you said, in a grid environment makes sense as the token is assumed to occupy all the cells it's snapped to (so a tiny token is still seen even if just the corner of the cell is seen).

Code: Select all

Rectangle bounds = target.getFootprint(grid).getBounds(grid, grid.convert(new ZonePoint(target.getX(),target.getY())));
A quick fix was to add:

Code: Select all

if(!target.isSnapToGrid())
  bounds = target.getBounds(zone);
This correctly uses the exact bounds of the token when not snapped to the grid as it should not have a "footprint" as it were.

I'll submit a patch for this as I consider it a bug, unless someone advises otherwise.

Jamz, please do lot's of testing, including different grid types(hex, etc), freesize, gridless(no map grid). Though I won't say with 100% certainty that I did not just "forget", I am usually fairly good about thinking this sort of thing through and testing, so I am leaning toward there being an intentional reason why I did not put that in and left it as only working for snap to grid tokens.
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

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

Re: Detect Magic Macro

Post by JamzTheMan »

jfrazierjr wrote: Jamz, please do lot's of testing, including different grid types(hex, etc), freesize, gridless(no map grid). Though I won't say with 100% certainty that I did not just "forget", I am usually fairly good about thinking this sort of thing through and testing, so I am leaning toward there being an intentional reason why I did not put that in and left it as only working for snap to grid tokens.
Sure, will do. So far I tested on both hex grids and no grids and so far it's working as expected. Hexs are hard to see the footprint sometimes so I'll do some more testing to make sure. A good test seems to use a token of 1/6 as you can clearly set VBL to touch the cell and not the token. But I've been testing with 1/6, medium, and large tokens, turning the patch on and off to verify the results don't change (for snapToGrid tokens at least).
-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 “User Creations”