Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class BruteForcer
- {
- public static (float x, float y, float z) teleporterPos = (-6612, 1024, -3351);
- public static (float x, float y, float z) elevatorStartPos = (1813.50732421875f, 768, 4472.35693359375f);
- public static (float x, float y, float z) target1Pos = (-5789.0634765625f, 1024, -1558.23718261719f);
- public static (float x, float y, float z) inCornerPos = (7013.36474609375f, 908.641296386719f, -3849.3798828125f);
- public static (float x, float y, float z) target2Pos = (4445.69482421875f, 3439.88891601563f, -6623.66259765625f);
- public static List<TriangleDataModel> allFloorTris;
- public static List<TriangleDataModel> flatFloorTris;
- public static void Run()
- {
- Config.Print("START");
- allFloorTris = TriangleUtilities.GetLevelTriangles().FindAll(tri => tri.IsFloor());
- flatFloorTris = TriangleUtilities.GetLevelTriangles().FindAll(tri => tri.IsFloor() && tri.NormY == 1);
- //Test(-200_000_000, -100_000_000, 100_000, elevatorStartPos, target1Pos);
- Run(-61_095_980, -60_000_000, 200, inCornerPos, target2Pos);
- Config.Print("END");
- }
- public static void Run(double startSpeed, double endSpeed, double speedIncrement, (float x, float y, float z) startPos, (float x, float y, float z) endPos)
- {
- //for (double speed0 = startSpeed; speed0 <= endSpeed; speed0 += speedIncrement)
- List<double> hSpeeds = GetSuccessiveHSpeeds2(startSpeed);
- hSpeeds.Sort();
- foreach (double speed0 in hSpeeds)
- {
- for (int angle0 = 0; angle0 < 65536; angle0 += 16)
- {
- MarioPuState state0 = new MarioPuState(startPos.x, startPos.y, startPos.z, speed0, angle0, 0.99834132194519f, null, 0);
- MarioPuState state1 = TestOverflowJump(state0, angle0);
- if (state1 != null)
- {
- List<MarioPuState> state1Bs = GetSuccessiveStates(state1);
- foreach (MarioPuState state1B in state1Bs)
- {
- for (int angle1 = 0; angle1 < 65536; angle1 += 16)
- {
- MarioPuState state2 = TestOverflowJump(state1B, angle1);
- if (state2 != null)
- {
- List<MarioPuState> state2Bs = GetSuccessiveStates(state2);
- foreach (MarioPuState state2B in state2Bs)
- {
- double angle2 = MoreMath.AngleTo_AngleUnits(endPos.x, endPos.z, state2B.X, state2B.Z);
- ushort angle2Truncated = MoreMath.NormalizeAngleTruncated(Math.Round(angle2));
- MarioPuState state3 = TestOverflowJump(state2B, angle2Truncated);
- if (state3 != null && state3.GetPuX() == 0 && state3.GetPuZ() == 0)
- {
- double distToStart = MoreMath.GetDistanceBetween(state3.X, state3.Y, state3.Z, startPos.x, startPos.y, startPos.z);
- double yDistToEnd = state3.Y - endPos.y;
- if (distToStart < 5000 && yDistToEnd >= -1000)
- {
- Config.Print("state0 = " + state0);
- Config.Print("state1 = " + state1);
- Config.Print("state1B = " + state1B);
- Config.Print("state2 = " + state2);
- Config.Print("state2B = " + state2B);
- Config.Print("state3 = " + state3);
- Config.Print("dist to start = " + distToStart);
- Config.Print("yDist to end = " + yDistToEnd);
- Config.Print();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- public static MarioPuState TestOverflowJump(MarioPuState state, int angle)
- {
- (double testX, double testZ) = MoreMath.AddVectorToPoint(state.HSpeed / 4 * state.YNorm, angle, state.X, state.Z);
- double testY = state.Y;
- double modTestX = MoreMath.MaybeNegativeModulus(testX, 65536);
- double modTestY = MoreMath.MaybeNegativeModulus(testY, 65536);
- double modTestZ = MoreMath.MaybeNegativeModulus(testZ, 65536);
- foreach (TriangleDataModel tri in allFloorTris)
- {
- if (tri.IsPointInsideAndAboveTriangle(modTestX, modTestY, modTestZ))
- {
- return null; // would prematurely go to PU
- }
- }
- double hSpeed = state.HSpeed * 0.8;
- double hDist = hSpeed / 4;
- double vSpeed = 42 + state.HSpeed / 4;
- double vDist = vSpeed / 4;
- (double x, double z) = MoreMath.AddVectorToPoint(hDist, angle, state.X, state.Z);
- double y = state.Y + vDist;
- double modX = MoreMath.MaybeNegativeModulus(x, 65536);
- double modY = MoreMath.MaybeNegativeModulus(y, 65536);
- double modZ = MoreMath.MaybeNegativeModulus(z, 65536);
- if (modX < -8192 || modX > 8192) return null;
- if (modZ < -8192 || modZ > 8192) return null;
- if (modY < -8192) return null;
- double? bestFloorY = null;
- float yNorm = 1;
- foreach (TriangleDataModel tri in allFloorTris)
- {
- if (tri.IsPointInsideAndAboveTriangle(modX, modY, modZ))
- {
- double floorY = tri.GetHeightOnTriangle(modX, modZ);
- if (bestFloorY == null || floorY > bestFloorY)
- {
- bestFloorY = floorY;
- yNorm = tri.NormY;
- }
- }
- }
- if (bestFloorY.HasValue && bestFloorY.Value > state.Y - 3000)
- {
- (double test2X, double test2Z) = MoreMath.AddVectorToPoint(hSpeed / 4 * yNorm, angle, x, z);
- double test2Y = bestFloorY.Value;
- double modTest2X = MoreMath.MaybeNegativeModulus(test2X, 65536);
- double modTest2Y = MoreMath.MaybeNegativeModulus(test2Y, 65536);
- double modTest2Z = MoreMath.MaybeNegativeModulus(test2Z, 65536);
- foreach (TriangleDataModel tri in allFloorTris)
- {
- if (tri.IsPointInsideAndAboveTriangle(modTest2X, modTest2Y, modTest2Z))
- {
- return null; // would go to PU immediately after
- }
- }
- return new MarioPuState(x, bestFloorY.Value, z, hSpeed, angle, yNorm, state, state.Index + 1);
- }
- return null;
- }
- public class MarioPuState
- {
- public readonly double X;
- public readonly double Y;
- public readonly double Z;
- public readonly double HSpeed;
- public readonly double Angle;
- public readonly double YNorm;
- public readonly MarioPuState Predecessor;
- public readonly int Index;
- public MarioPuState(double x, double y, double z, double hSpeed, double angle, double yNorm, MarioPuState predecessor, int index)
- {
- X = x;
- Y = y;
- Z = z;
- HSpeed = hSpeed;
- Angle = angle;
- YNorm = yNorm;
- Predecessor = predecessor;
- Index = index;
- }
- public int GetPuX()
- {
- return PuUtilities.GetPuIndex(X);
- }
- public int GetPuZ()
- {
- return PuUtilities.GetPuIndex(Z);
- }
- public string GetLineage()
- {
- double deltaY = Predecessor == null ? 0 : Y - Predecessor.Y;
- string past = Predecessor == null ? "" : Predecessor.GetLineage();
- string current = ToString() + " " + deltaY + "\r\n";
- return past + current;
- }
- public override string ToString()
- {
- return string.Format(
- "X={0} Y={1} Z={2} HSpeed={3} Angle={4}",
- (int)X, (int)Y, (int)Z, (int)HSpeed, Angle);
- }
- }
- public static List<double> GetSuccessiveHSpeeds(double hSpeed)
- {
- List<double> output = new List<double>();
- for (int numJumps = 1; numJumps <= 3; numJumps++)
- {
- for (int numDusts = 0; numDusts <= numJumps * 3 + 3; numDusts++)
- {
- double value = hSpeed * Math.Pow(0.8, numJumps) * Math.Pow(0.98, numDusts);
- if (value > -200_000) continue;
- output.Add(value);
- }
- }
- return output;
- }
- public static List<double> GetSuccessiveHSpeeds2(double hSpeed)
- {
- List<double> output = new List<double>();
- for (int numJumps = 0; numJumps <= 4; numJumps++)
- {
- for (int numDusts = 0; numDusts <= numJumps * 3 + 3; numDusts++)
- {
- double value = hSpeed * Math.Pow(0.8, numJumps) * Math.Pow(0.98, numDusts);
- if (value > -200_000) continue;
- output.Add(value);
- }
- }
- return output;
- }
- public static List<MarioPuState> GetSuccessiveStates(MarioPuState state)
- {
- List<double> hSpeeds = GetSuccessiveHSpeeds(state.HSpeed);
- return hSpeeds.ConvertAll(
- hSpeed => new MarioPuState(state.X, state.Y, state.Z, hSpeed, state.Angle, state.YNorm, state, state.Index));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement