5E Character Create Playlist
  1. #1

    Join Date
    Apr 2010
    Location
    Australia
    Posts
    900

    Overriding ImageControl.onMeasurePointer(...)

    I'm overriding the onMeasurePointer event in order to apply some custom calculations to the pointer label. Specifically, I need to get the pointer length. Previously I have done this by defining a measureVector function to calculate the pointer length and then going from there.

    Does the API expose the underlining measureVector function which the base CoreRPG uses to calculate pointer lengths? A custom measureVector function works, but it would better to utilise the built-in version if available.

    Thanks.
    Timezone: Australian EST (GMT +10).
    Systems/Rulesets: GURPS 4th Edition.
    Campaigns (Ultimate License Holder)
    GURPS Traveller - The Empty Peace
    GURPS Shadowrun - Power Plays
    GURPS Banestorm - Dark Clouds Rising

  2. #2
    The API does not expose a measureVector function. If you override the onMeasurePointer event, the client assumes you are handling all the calculations.

    There's probably some older Lua code from v2.x time frame that is already written to handle this. I might be able to find an old copy to pass you, if you need.

    Cheers,
    JPG

  3. #3

    Join Date
    Apr 2010
    Location
    Australia
    Posts
    900
    If you have some code, that would be great.

    Would it be possible to call the inherited onMeasurePointer from the overridden onMeasurePointer and get the pointer length that way?
    Timezone: Australian EST (GMT +10).
    Systems/Rulesets: GURPS 4th Edition.
    Campaigns (Ultimate License Holder)
    GURPS Traveller - The Empty Peace
    GURPS Shadowrun - Power Plays
    GURPS Banestorm - Dark Clouds Rising

  4. #4
    Wow, apparently it's been included for longer than I remember; since I had to go back to rulesets prior to v2.9.4.

    Here's the MeasurePointer code from my d20_JPG ruleset back in 2009:

    Code:
    function onMeasureVector(token, vector)
    	if hasGrid() then
    		local diagonals = 0;
    		local straights = 0;
    		local gridsize = getGridSize();
    	
    		for i = 1, #vector do
    			local gx = math.abs(math.floor(vector[i].x / gridsize));
    			local gy = math.abs(math.floor(vector[i].y / gridsize));
    			
    			if gx > gy then
    				diagonals = diagonals + gy;
    				straights = straights + gx - gy;
    			else
    				diagonals = diagonals + gx;
    				straights = straights + gy - gx;
    			end
    		end
    		
    		local squares = math.floor(diagonals * 1.5) + straights;
    		local feet = squares * 5;
    		
    		return feet .. "\'";
    	else
    		return "";
    	end
    end
    Cheers,
    JPG

  5. #5
    There's no base function or default function to call in the API. If the event function doesn't exist, the client just handles internally.

    Cheers,
    JPG

  6. #6

    Join Date
    Apr 2010
    Location
    Australia
    Posts
    900
    Quote Originally Posted by Moon Wizard View Post
    Wow, apparently it's been included for longer than I remember; since I had to go back to rulesets prior to v2.9.4.

    Here's the MeasurePointer code from my d20_JPG ruleset back in 2009:

    Cheers,
    JPG
    Many thanks, however, I'm working with hex grids not squares. I have some code I used pre-core, but I was hoping to avoid that as I seem to recall it had rounding issues with hex grids of uneven gridsize. The internal calculation used post core seems to get this right. Is it possible to share the code/method used internally to get the pointer/vector length, then I could migrate this to lua and hopefully arrive at the same calculation?
    Timezone: Australian EST (GMT +10).
    Systems/Rulesets: GURPS 4th Edition.
    Campaigns (Ultimate License Holder)
    GURPS Traveller - The Empty Peace
    GURPS Shadowrun - Power Plays
    GURPS Banestorm - Dark Clouds Rising

  7. #7
    That's a little more complicated, since it's all C++ code. I don't think there ever was hex specific Lua code (that I remember).

    Code:
    string MeasureTokenVector(CTokenInstance* pToken)
    {
    	float fDist = floor(MeasureVector(pToken->m_iVector));
    	stringstream ssDist;
    	if (fDist > 0)
    		ssDist << (fDist * s_fBaseUnit) << CImageValue::s_sDistanceSuffix;
    	return ssDist.str();
    }
    
    float MeasureVector(list<POINT>& iVector)
    {
    	if (m_nGridSize <= 0)
    		return 0;
    
    	float fDist = 0;
    	if ((m_nGridType == IVGT_HEXROW) || (m_nGridType == IVGT_HEXCOLUMN))
    	{
    		int qw = (int)(m_nGridSize * tan(3.14159/6) / 2.0f);
    		int hh = m_nGridSize / 2;
    
    		if ((qw > 0) && (hh > 0))
    		{
    			for (auto it = iVector.begin(); it != iVector.end(); ++it)
    			{
    				POINT& pt = *it;
    
    				float fColumn, fRow;
    				if (m_nGridType == IVGT_HEXCOLUMN)
    				{
    					fColumn = (float)pt.x / (float)(qw * 3);
    					fRow = ((float)pt.y / (float)(hh*2)) - (float)(fColumn * 0.5);
    				}
    				else
    				{
    					fRow = (float)pt.y / (float)(qw*3);
    					fColumn = ((float)pt.x / (float)(hh*2)) - (float)(fRow * 0.5);
    				}
    
    				if	((fRow >= 0 && fColumn >= 0) || (fRow < 0 && fColumn < 0))
    					fDist += fabs(fColumn) + fabs(fRow);
    				else
    					fDist += max(fabs(fColumn), fabs(fRow));
    			}
    		}
    	}
    	// m_nGridType == IVGT_GRID
    	else
    	{
    		float fDiagonals = 0;
    		float fStraights = 0;
    
    		for (auto it = iVector.begin(); it != iVector.end(); ++it)
    		{
    			POINT& pt = *it;
    
    			float gx = (float)fabs((float)pt.x / (float)m_nGridSize);
    			float gy = (float)fabs((float)pt.y / (float)m_nGridSize);
    
    			fDiagonals += min(gx, gy);
    			fStraights += fabs(gx - gy);
    		}
    
    		fDist = fStraights + (fDiagonals * s_fDiagMult);
    	}
    
    	return fDist;
    }
    Cheers,
    JPG

  8. #8

    Join Date
    Apr 2010
    Location
    Australia
    Posts
    900
    Quote Originally Posted by Moon Wizard View Post
    That's a little more complicated, since it's all C++ code. I don't think there ever was hex specific Lua code (that I remember).
    Thanks! That's perfect.
    Timezone: Australian EST (GMT +10).
    Systems/Rulesets: GURPS 4th Edition.
    Campaigns (Ultimate License Holder)
    GURPS Traveller - The Empty Peace
    GURPS Shadowrun - Power Plays
    GURPS Banestorm - Dark Clouds Rising

Thread Information

Users Browsing this Thread

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

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