Code submission: $sqrt() function

A forum for feature requests/discussions and user submitted patches that improve MQ2

Moderator: MacroQuest Developers

alcibiades
decaying skeleton
decaying skeleton
Posts: 1
Joined: Sat Sep 06, 2003 2:07 pm

Code submission: $sqrt() function

Post by alcibiades » Sat Sep 06, 2003 6:51 pm

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.

Valerian
a grimling bloodguard
a grimling bloodguard
Posts: 709
Joined: Sun Jul 28, 2002 3:29 am

Post by Valerian » Sat Sep 06, 2003 7:43 pm

Now in CVS.