Page 3 of 3 First 123
  1. #21
    celestian's Avatar
    Join Date
    Jan 2017
    Location
    DFW, Texas
    Posts
    2,050
    Quote Originally Posted by Moon Wizard View Post
    The measurements were always supposed to be measured by grid blocks, wherein the actual displayed distance would be modified by the units and suffix. This is the way that FGC has worked for many years; and mirrors what I've seen as the intended behavior of most game systems from a tactical perspective. (i.e. if it's more than 1 block distance, than it counts as two blocks distance.)

    So this will not function in FGU (this is current FGC)?

    ---
    Coding the Official AD&D Ruleset
    My Twitch Channel for AD&D and FG related streams (See schedule for live days)
    My YouTube for FG related Tutorials and AD&D Actual Plays

  2. #22
    It's supposed to be in whole grid units (multiplied by base units). If not, then FGC is not working as intended.

    Also, I'm not sure how you got that to appear like that in your version, since it does not do that when I try in CoreRPG, 3.5E or 5E on FGC.

    Thanks,
    JPG
    Attached Images Attached Images
    Last edited by Moon Wizard; December 2nd, 2019 at 00:36.

  3. #23
    celestian's Avatar
    Join Date
    Jan 2017
    Location
    DFW, Texas
    Posts
    2,050
    Quote Originally Posted by Moon Wizard View Post
    It's supposed to be in whole grid units (multiplied by base units). If not, then FGC is not working as intended.

    Also, I'm not sure how you got that to appear like that in your version, since it does not do that when I try in CoreRPG, 3.5E or 5E on FGC.

    Thanks,
    JPG
    Only bringing this up because you told me to not make kludges around FGU when FGC works another way.

    To be clear this is not untouched ruleset, it's related to the unit/suffix code. I had it already in the AD&D ruleset. I updated the code to function within FGU (with your new API functions) and FGC.

    I added this script to the image_record class.

    Code:
      <!-- standard image template -->
      <template name="image_record">
        <image_record_step>
          <bounds>21,63,-27,-29</bounds>
          <script file="campaign/scripts/image_record.lua"/>
        </image_record_step>
      </template>
    Code:
    --
    -- Please see the license.html file included with this distribution for
    -- attribution and copyright information.
    --
    
    function onInit()
    --
      if Interface.getVersion() >= 4 then
        if User.isHost() then
          local node = getDatabaseNode();
          DB.addHandler(DB.getPath(node.getParent(), "muse_unitsize_number"), "onUpdate", onUnitSizeUpdates);
          DB.addHandler(DB.getPath(node.getParent(), "muse_suffix_string"), "onUpdate", onUnitSizeUpdates);
          DB.addHandler(DB.getPath(node.getParent(), "locked"), "onUpdate", onLockChanged);
          onUnitSizeUpdates(node);
          onLockChanged(node);    
        end
      end
    
      -- when the map is loaded setup these.
      TokenManagerADND.updateCTEntries();
    end
    
    function onClose()
      if Interface.getVersion() >= 4 then
        if User.isHost() then
          local node = getDatabaseNode();
          DB.removeHandler(DB.getPath(node.getParent(), "muse_unitsize_number"), "onUpdate", onUnitSizeUpdates);
          DB.removeHandler(DB.getPath(node.getParent(), "muse_suffix_string"), "onUpdate", onUnitSizeUpdates);
          DB.removeHandler(DB.getPath(node.getParent(), "locked"), "onUpdate", onLockChanged);
        end
      end
    end
    
    -- update size/suffix on the map when they are reconfigured.
    function onUnitSizeUpdates(node)
      node = node.getParent();
      --local node = getDatabaseNode().getParent();
      setDistanceBaseUnits(tostring(DB.getValue(node,"muse_unitsize_number","5")));
      setDistanceSuffix(DB.getValue(node,"muse_suffix_string","ft"));
    --getDistanceBaseUnits() = current base units (override if >0; otherwise ruleset value)
    --getDistanceSuffix() = current suffix value (override if not nil; otherwise ruleset value)
    --Debug.console("image_record.lua","onUnitSizeUpdates","getDistanceBaseUnits()",getDistanceBaseUnits());
    --Debug.console("image_record.lua","onUnitSizeUpdates","getDistanceSuffix()",getDistanceSuffix());
    end
    
    -- when the map unlocked show the size/suffix fields.
    function onLockChanged()
      local node = getDatabaseNode().getParent();
    --Debug.console("image_record.lua","onLockChanged","node",node);
      local bUnLocked = DB.getValue(node, "locked", 0) == 0;
      window.header.subwindow.muse_unitsize_label.setVisible(bUnLocked);
      window.header.subwindow.muse_unitsize_number.setVisible(bUnLocked);
      window.header.subwindow.muse_suffix_label.setVisible(bUnLocked);
      window.header.subwindow.muse_suffix_string.setVisible(bUnLocked);
    end
    
    -- get the unit scale and measurement
    function getUnitControlSetting()
      local sValue = '5ft';
      if Interface.getVersion() < 4 then
        local node = getDatabaseNode().getChild("..");
        sValue = DB.getValue(node,"scale","10ft"); -- default to 10ft here but we should never see this.
      else
        sValue = getDistanceBaseUnit() .. getDistanceSuffix();
      end
      return sValue;
    end
    
    -- is the scale value VALID?
    function getUnitControlisValid()
      local bValid = false;
      if Interface.getVersion() < 4 then
        bValid = getUnitControlSetting():find("^[%d%.]+") ~= nil
      else
        bValid = true;
      end
      return bValid;
    end
    
    -- get the size of each unit
    function getUnitControlValue()
      local nScaleValue = 0;
      if Interface.getVersion() < 4 then
        if getUnitControlisValid() then
          nScaleValue = tonumber(getUnitControlSetting():match("^([%d%.]+)")) or 0
        end
      else
        nScaleValue = getDistanceBaseUnit() or 5;
      end
      return nScaleValue;
    end
    
    -- get the scale measurement name/string
    function getUnitControlLabel()
      local sValue = "ft";
      if Interface.getVersion() < 4 then
        sValue = StringManager.trim(getUnitControlSetting():gsub("^[%d%.]+%s*", ""))
      else
        sValue = getDistanceSuffix();
      end
      return sValue;
    end
    
    -- measureVector
    function measureVector(nVectorX, nVectorY, sGridType, nGridSize, nGridHexWidth, nGridHexHeight)
      local nDiag = 1;
        if OptionsManager.isOption("HRDD", "variant") then
        nDiag = 1.5;
      end
      local nDistance = 0
    
      if sGridType == "hexrow" or sGridType == "hexcolumn" then
        local nCol, nRow = 0, 0
        if sGridType == "hexcolumn" then
          nCol = nVectorX / (nGridHexWidth*3)
          nRow = (nVectorY / (nGridHexHeight*2)) - (nCol * 0.5)
        else
          nRow = nVectorY / (nGridHexWidth*3)
          nCol = (nVectorX / (nGridHexHeight*2)) - (nRow * 0.5)
        end
    
        if  ((nRow >= 0 and nCol >= 0) or (nRow < 0 and nCol < 0)) then
          nDistance = math.abs(nCol) + math.abs(nRow)
        else
          nDistance = math.max(math.abs(nCol), math.abs(nRow))
        end
    
      else -- if sGridType == "square" then
        local nDiagonals = 0
        local nStraights = 0
    
        local nGridX = math.abs(nVectorX / nGridSize)
        local nGridY = math.abs(nVectorY / nGridSize)
    
        if nGridX > nGridY then
          nDiagonals = nDiagonals + nGridY
          nStraights = nStraights + nGridX - nGridY
        else
          nDiagonals = nDiagonals + nGridX
          nStraights = nStraights + nGridY - nGridX
        end
    
        nDistance = nDiagonals * nDiag + nStraights
      end
    
      return nDistance
    end
    
    -- when measuring a vector distance
    function onMeasureVector(token, aVector)
      if hasGrid() then
        local sGridType = getGridType()
        local nGridSize = getGridSize()
    
        local nDistance = 0
        if sGridType == "hexrow" or sGridType == "hexcolumn" then
          local nGridHexWidth, nGridHexHeight = getGridHexElementDimensions()
          for i = 1, #aVector do
            local nVector = measureVector(aVector[i].x, aVector[i].y, sGridType, nGridSize, nGridHexWidth, nGridHexHeight)
            nDistance = nDistance + nVector
          end
        else -- if sGridType == "square" then
          for i = 1, #aVector do
            local nVector = measureVector(aVector[i].x, aVector[i].y, sGridType, nGridSize)
            nDistance = nDistance + nVector
          end
        end
    
        if getUnitControlisValid() then
          --return (nDistance * getUnitControlValue()) .. getUnitControlLabel();
          return (UtilityManagerADND.round(nDistance * getUnitControlValue())) .. getUnitControlLabel()
        else
          return ""
        end
      else
        return ""
      end
    end
    
    -- when measuring a pointer distance
    function onMeasurePointer(nLength, sPointerType, nStartX, nStartY, nEndX, nEndY)
      if hasGrid() then
        local sGridType = getGridType()
        local nGridSize = getGridSize()
    
        if sGridType == "hexrow" or sGridType == "hexcolumn" then
          local nGridHexWidth, nGridHexHeight = getGridHexElementDimensions()
          nDistance = measureVector(nEndX - nStartX, nEndY - nStartY, sGridType, nGridSize, nGridHexWidth, nGridHexHeight)
        else -- if sGridType == "square" then
          nDistance = measureVector(nEndX - nStartX, nEndY - nStartY, sGridType, nGridSize)
        end
    
        if getUnitControlisValid() then
          return (UtilityManagerADND.round(nDistance * getUnitControlValue())) .. getUnitControlLabel()
        else
          return ""
        end
      else
        return ""
      end
    end
    All I added recently was the round bit to get rid of that large float value.

    It now looks like this. If I updated the MUSE extension it would do the same for CoreRPG/etc.

    ---
    Coding the Official AD&D Ruleset
    My Twitch Channel for AD&D and FG related streams (See schedule for live days)
    My YouTube for FG related Tutorials and AD&D Actual Plays

  4. #24
    It's because you are measuring your own vectors that you were seeing the large numbers; and the half measures.

    The built-in measuring and the way the original onMeasureVector was supposed to work before we built it into the client is that it was based on grid squares first, then multiplied by base units.

    Regards,
    JPG

Thread Information

Users Browsing this Thread

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

Posting Permissions

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

Log in

Log in