All pastes #516412 Raw Edit

Sna4x8

public text v1 · immutable
#516412 ·published 2007-05-28 17:53 UTC
rendered paste body
;== This function plots a point hypotenuse feet directly ahead of me.
function plotXY(float hypotenuse)
{
	;other 2 sides of the triangle
	declare a float local
	declare b float local
	;angle c of a triangle
	declare c int local
	;x,y loc hypotenuse ahead of me
	if (!${Variable[plotX](exists)})
		declare plotX float script
	if (!${Variable[plotY](exists)})
		declare plotY float script
	
	if (${debug}==1)
		echo X Y: ${Me.X} ${Me.Y}
	if (${debug}==1)
		echo Heading: ${Me.Heading}
	c:Set[${Math.Calc[${Me.Heading}%90]}]
	if (${debug}==1)
		echo Heading mod 90 (angle c of a right triangle): ${c}
	
	a:Set[${Math.Cos[${c}]}]
	a:Set[${Math.Calc[${a}*${hypotenuse}]}]
	if (${debug}==1)
		echo Length of side a: ${a}
	
	b:Set[${Math.Sin[${c}]}]
	b:Set[${Math.Calc[${b}*${hypotenuse}]}]
	if (${debug}==1)
		echo Length of side b: ${b}
	
	;Select which way to face
	if (${Me.Heading} >= 0 && ${Me.Heading} <= 90)
	{
		if (${debug}==1)
			echo Heading between 0 and 90
		plotX:Set[${Math.Calc[${Me.X}+${a}]}]
		plotY:Set[${Math.Calc[${Me.Y}-${b}]}]
		if (${debug}==1)
			echo plotX plotY: ${plotX} ${plotY}
	}
	elseif (${Me.Heading} >= 91 && ${Me.Heading} <= 180)
	{
		if (${debug}==1)
			echo Heading between 91 and 180
		plotX:Set[${Math.Calc[${Me.X}-${b}]}]
		plotY:Set[${Math.Calc[${Me.Y}-${a}]}]
		if (${debug}==1)
			echo plotX plotY: ${plotX} ${plotY}
	}
	elseif (${Me.Heading} >= 181 && ${Me.Heading} <= 270)
	{
		if (${debug}==1)
			echo Heading between 181 and 270
		plotX:Set[${Math.Calc[${Me.X}-${a}]}]
		plotY:Set[${Math.Calc[${Me.Y}+${b}]}]
		if (${debug}==1)
			echo plotX plotY: ${plotX} ${plotY}
	}
	elseif (${Me.Heading} >= 271 && ${Me.Heading} <= 359)
	{
		if (${debug}==1)
			echo Heading between 271 and 359
		plotX:Set[${Math.Calc[${Me.X}+${b}]}]
		plotY:Set[${Math.Calc[${Me.Y}+${a}]}]
		if (${debug}==1)
			echo plotX plotY: ${plotX} ${plotY}
	}
}

;== Plot a line from me to a point.  For instance plots a stright
;== line between me and a merchant, or me and a corpse, regardless of
;== which way I am facing.
function plotLine(float pLToX, float pLToY)
{
	declare debug int local 0
	;== the new point on the line
	if (!${Variable[pLX](exists)})
		declare pLX float script
	if (!${Variable[pLY](exists)})
		declare pLY float script
	;== slope of the line
	declare pLRise float local
	declare pLRun float local
	declare pLSlope float local
	;== hypotenuse of the triangle
	declare pLHypotenuse float local
	;== sine and cosine of the triangle
	declare pLSin float local
	declare pLCos float local
	;== How far away to check for obstacles
	declare pLNewHypotenuse int local 30
	
	;== determine the slope (rise/run) of the line
	if (${debug}==1)
		echo My X,Y: ${Me.X},${Me.Y}	\tTrying to get to X,Y: ${pLToX},${pLToY}
	pLRise:Set[${Math.Calc[${pLToY}-${Me.Y}]}]
	pLRun:Set[${Math.Calc[${pLToX}-${Me.X}]}]
	if (${pLRun})
		pLSlope:Set[${Math.Calc[${pLRise}/${pLRun}]}]
	if (${debug}==1)
		echo Rise: ${pLRise}	\tRun: ${pLRun}		\tSlope: ${pLSlope}
	;== Make a right triangle from the line and solve for hypot.  The hpot is 
	;== the same as the distance from my loc to the point we're trying to get to.
	;== a^2 + b^2 = c^2
	pLHypotenuse:Set[${Math.Sqrt[${Math.Calc[${pLRun}^^2+${pLRise}^^2]}]}]
	if (${debug}==1)
		echo Hypotenuse: ${pLHypotenuse}	\tDistance: ${Math.Distance[${Me.X},${Me.Y},${pLToX},${pLToY}]}
	;== Make a new triange with the same sine/cosine, make hypot pLNewHypot
	if (${pLHypotenuse})
	{
		pLSin:Set[${Math.Calc[${pLRise}/${pLHypotenuse}]}]
		pLCos:Set[${Math.Calc[${pLRun}/${pLHypotenuse}]}]
		if (${debug}==1)
			echo sin: ${pLSin}	\tcos: ${pLCos}
	}
	pLX:Set[${Math.Calc[${pLCos}*${pLNewHypotenuse}]}]
	pLY:Set[${Math.Calc[${pLSin}*${pLNewHypotenuse}]}]
	if (${debug}==1)
		echo New point pLNewHypot feet away X,Y: ${pLX},${pLY}	\tDistance: ${Math.Distance[${Me.X},${Me.Y},${pLX},${pLY}]}
	pLX:Set[${Math.Calc[${Me.X}+${pLX}]}]
	pLY:Set[${Math.Calc[${Me.Y}+${pLY}]}]
	if (${debug}==1)
		echo New point + my loc X,Y: ${Math.Calc[${Me.X}+${pLX}]},${Math.Calc[${Me.Y}+${pLY}]}
	;== if the distance to the point we're trying to reach is closer
	;== then the new point then set pLXY to the point we're trying to reafch
	if (${Math.Distance[${Me.X},${Me.Y},${pLX},${pLY}]} > ${pLNewHypotenuse})
	{
		if (${debug}==1)
			echo Distance to new point is further than new hypot.
		pLX:Set[${pLToX}]
		pLY:Set[${pLToY}]
	}
}