Page 1 of 1

Code submission: $sqrt() function

Posted: Sat Sep 06, 2003 6:51 pm
by alcibiades
Hi all,

I've added a $sqrt(<number>) function call to MQ that people here might want to use. This is useful when you want to calculate things like the distance between two things in the zone other than yourself (very useful for quad-kiting macros). What follows is the formula for calculating the distances between objects and the code for adding the $sqrt function to MQ. Maybe some kind developer will check this into CVS for me :)

example use: Two objects, one at location x1,y1, other at x2,y2:

/varset Distance = $sqrt($abs(($x1-$x2))^2 + $abs(($y1-$y2))^2)

NOTE: The MQ parser can't do the whole chunk in one shot so you have to break the formula down.

Changes:
EQLib_MacroParser.h
-add:

Code: Select all

PARMFUNC(parmSqrt)   //around line 76
-add:

Code: Select all

{"sqrt(",				"parmSqrt",			NULL}, //around line 160
EQLib_MacroParser.cpp
-add (at end of file):

Code: Select all

DWORD parmSqrt(PCHAR szVar, PCHAR szOutput, PSPAWNINFO pChar)
{
	DWORD i=0;

	// $sqrt(xxx)

	if (!strstr(szVar,")")) 
	{

		DebugSpew("PMP - Bad $sqrt() '%s'",szVar);

		return 10000;

	} 
	else 
	{

		CHAR Formula[MAX_STRING] = {0};

		while (szVar[i]!=')') i++;

		strcpy(Formula,szVar+5);

		Formula[strstr(Formula,")")-Formula] = 0;

		// have to convert argument from deg to rad and result from rad to deg

		sprintf(Formula,"%1.2f",(sqrt(Calculate(Formula))));

		strcat(szOutput,Formula);
	}

	return i;

}
Regards,
Alci

edit: Valerian likes code brackets.

Posted: Sat Sep 06, 2003 7:43 pm
by Valerian
Now in CVS.