Starfinder Playlist
  1. #1

    Calculating FG distance

    Hi! I am trying to write an extension that needs the distance between two actors, same as the one calculated by Fantast Grounds, when targetting or moving (see arrows in FG distance.PNG). However, I have a really hard time to wrap my head around the distance they have implemented.
    I have not found any functions that would do the calculation for me, so I'm afraid I will have to do it myself, but I wanted to ask here first, because what I am going to do is complicated, and it would be a shame to reinvent the wheel.

    I am planning on using the Bresenhams algorithm(https://en.wikipedia.org/wiki/Bresen...line_algorithm), possible in combination with the 1-2-1-2 rule (which states that diagonal movement costs 1 square of movement normally, and 2 squares every second diagonal movement).

    So do any of you know:
    • Whether or not this is already provided as a function somewhere?
    • Is there a defined (by FG team) algorithm for doing this?
    • Does the algorithm from above makes sense to implement?

  2. #2
    That’s already supported using the settings in the 3.5E/PFRPG rulesets, as well as a house rule in there 5E ruleset.

    There is an imagecontrol function to return the distance between two tokens (see Developer Guide APIs). It calculates distance using center of closest grid square of source token to center of closest square of target token.

    Regards,
    JPG

  3. #3
    Hi! Thank you for the answer, it looks very promising! However after trying around, I can not get it to work. The errors say that the function doesn't exist and I cant find in the documentation how to access it. I have tried:
    • ImageControl.onMeasurePointer
    • srcImage.onMeasurePointer (where srcImage is what I got from calling ImageManager.getImageControl)


    The docs also state that "Distances will be automatically calculated for pointers and token paths based on the values specified in the distance tag, unless onMeasurePointer or onMeasureVector are defined (respectively).", but I don't really know what that means. When are they defined and when are they not?
    I am writing the plugin for 5E, however I do not see any house rule, that would enable extensions to use this function. I feel like I dont fully understand what you mean with the house rule in your response.

  4. #4
    onMeasurePointer and onMeasureVector are event functions that are called by client when we need to draw a distance on a token path or user pointer object. If they don't exist, then the existing settings are used. They are not "function calls" to get information, but events that can be overridden to replace internal client distance measurements.

    If you need to get distances between tokens in your script, you would use imagecontrol.getDistanceBetween function call.
    https://fantasygroundsunity.atlassia...0/imagecontrol

    Again, the 1-2 (i.e. 5-15) grid measurement used in Pathfinder and in 5E optional rules is already natively supported, and does not need any custom scripts. Applying the correct distance settings are all that is needed.

    From 3.5E/Pathfinder:
    Code:
    	<distance>
    		<base>5</base>
    		<diagmult>1.5</diagmult>
    		<suffix>'</suffix>
    	</distance>
    Regards,
    JPG

  5. #5
    Oooh I see! Also, I now see that the docs I've been using (https://www.fantasygrounds.com/refdoc/imagecontrol.xcp), which is terribly outdated. Thank you for a new refdoc! I will try it and come back with results.

  6. #6
    That works like a charm, thank you! However, what concerns me is the [FGU] in the function description. I assume its not supported in the non-unity version? Why? I remember that FG was capable of doing the same calculation.

  7. #7
    At this point, we are only supporting updates to FGU as of August. I don’t remember without researching the code whether it works at all in FGC. Given that FGC is being phased out, it shouldn’t make much difference. Just build for FGU.

    Regards,
    JPG

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in