public static void SuperFormula(double m, double n1, double n2, double n3, double phi, double radius, int leftright, out float x, out float y)
{
const double a = 1;
const double b = 1;
var t1 = Math.Cos(m * phi / 4) / a;
t1 = Math.Abs(t1);
t1 = Math.Pow(t1, n2);
var t2 = Math.Sin(m * phi / 4) / b;
t2 = Math.Abs(t2);
t2 = Math.Pow(t2, n3);
var r = Math.Pow(t1 + t2, 1 / n1);
if (Math.Abs(Math.Abs(r)) < .01)
{
x = 0;
y = 0;
}
else
{
r = 1 / r;
x = (float)(leftright * radius * r * Math.Cos(phi));
y = (float)(leftright * radius * r * Math.Sin(phi));
}
}
public static void ChoosePattern(out double m, out double n1, out double n2, out double n3, out double radius, out int leftright)
{
// [URL="http://paulbourke.net/geometry/supershape/"]Supershapes / SuperFormula[/URL]
var rnd = new Random();
var number2 = rnd.NextDouble();
if (number2 < 0.5)
{ leftright = -1; }
else leftright = 1;
switch (WhichPattern)
{
case 0: // Concave Pentamer
m = 5;
n1 = 1;
n2 = 1;
n3 = 1;
radius = 10;
break;
case 1: // Pinched
m = 1;
n1 = 0.8;
n2 = 0.8;
n3 = 0.8;
radius = 10;
break;
case 2: // Pinched
m = 3;
n1 = 0.8;
n2 = 0.8;
n3 = 0.8;
radius = 14;
break;
case 3: // Dog Bone [URL="http://en.wikipedia.org/wiki/Superformula"]Superformula - Wikipedia, the free encyclopedia[/URL]
m = 4;
n1 = 2;
n2 = 4;
n3 = 13;
radius = 6;
break;
case 4: // Oblong pie shape [URL="http://en.wikipedia.org/wiki/Superformula"]Superformula - Wikipedia, the free encyclopedia[/URL]
m = 3;
n1 = 3;
n2 = 14;
n3 = 2;
radius = 5;
break;
case 5: // Sharp Starfish [URL="http://en.wikipedia.org/wiki/Superformula"]Superformula - Wikipedia, the free encyclopedia[/URL]
m = 6;
n1 = 1;
n2 = 7;
n3 = 8;
radius = 5;
break;
default: // Starfish
m = 5;
n1 = 1;
n2 = 4;
n3 = 5;
radius = 5;
break;
}
}
public static Composite LookingBusy()
{
return new Sequence(
new Action(r =>
{
if (Me.Name == Tank.Name )
return RunStatus.Failure;
return FollowCircuit(false) ? RunStatus.Failure : RunStatus.Failure;
}
));
}
public static Composite CircuitTank(bool runAway = false, string message = "")
{
return new Sequence(
new Action(r =>
{
if (Me.Dazed || Me.Fleeing || Me.Stunned || Me.Rooted
|| Me.Pacified || Me.Possessed) // Don't bother-- stunned
return RunStatus.Failure;
if (Me.Name == Tank.Name)
return RunStatus.Failure;
if (Tank != null && Tank.Mounted && (Tank.IsFlying || Tank.IsSwimming))
{
Flightor.MoveTo(MakeItSoPoint);
return RunStatus.Success;
}
//Log("Move: CircuitTank {0}", message);
return FollowCircuit(runAway, message) ? RunStatus.Failure : RunStatus.Failure;
}
));
}
public static bool FollowCircuit(bool runAway, string message = "")
{
CountCheck();
GetNewPoint();
var canNav = false;
Vector3 mePoint = Me.Location;
if (!Me.IsMoving || Math.Abs(VectorLength(mePoint - MakeItSoPoint)) <= 5)
{
_phi = Count * 2 * Math.PI / NumPoints;
try
{
canNav = Navigator.CanNavigateFully(Me.Location, MakeItSoPoint);
}
catch (Exception)
{
throw;
}
while (!canNav) // Search for a spot to which I can move
{
CountCheck();
GetNewPoint();
try
{
canNav = Navigator.CanNavigateFully(Me.Location, MakeItSoPoint);
}
catch (Exception)
{
throw;
}
}
}
return canNav && MoveTo(runAway, message);
}
private static void CountCheck()
{
// Change the pattern if Count is 0 and only allow this change every 2 seconds.
if (Count != 0 || TimeUp(LastTimeChoosePattern) <= 2000) return;
Random rnd = new Random();
WhichPattern = rnd.Next(0, 6);
LastTimeChoosePattern = DateTime.Now.Ticks;
ChoosePattern(out M, out N1, out N2, out N3, out Radius, out Leftright);
}
private static void GetNewPoint()
{
float xLoc;
float yLoc;
IncreaseCount(NumPoints);
SuperFormula(M, N1, N2, N3, _phi, Radius, Leftright, out xLoc, out yLoc);
MakeItSoPoint = Tank.Location;
MakeItSoPoint.X += xLoc; MakeItSoPoint.Y += yLoc;
}
public static bool MoveTo(bool runAway, string message = "")
{
// if too close, don't move.
Vector3 mePoint = Me.Location;
//Log("Move: MoveTo_1 {0}", message);
if (!(Math.Abs(VectorLength(mePoint - MakeItSoPoint)) > 2)) return false;
//if (runAway)
//Log(Colors.Red, "Move: MoveTo_2 {0}", message);
Navigator.MoveTo(MakeItSoPoint);
LastCtmTime = DateTime.Now.Ticks;
return true;
}
public static void IncreaseCount(int numPoints)
{
Count++;
if (Count > numPoints)
Count = 0;
}
public static int Count;
public static double M;
public static double N1;
public static double N2;
public static double N3;
public static double Radius;
public static int WhichPattern;
public static int ActualPattern;
public static int Leftright;
public const int NumPoints = 15;
public static long LastTimeChoosePattern = DateTime.Now.Ticks;
private static double _phi;