Skip to content

Commit

Permalink
simplify config spawnablearea to just a sphere at 0/0/0 for now
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidArgument3 committed Jun 16, 2024
1 parent 7e42ddd commit a3af308
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ public static class AsteroidSettings
new SpawnableArea
{
CenterPosition = new Vector3D(148001024.50, 1024.50, 1024.50),
Normal = new Vector3D(1, 10, 0.5).Normalized(),
Radius = 60268000 * 2.5,
InnerRadius = 60268000 * 1.2,
HeightFromCenter = 1000,
Radius = 60268000 * 2.5
}
};

Expand Down Expand Up @@ -199,6 +196,11 @@ public static void SaveSettings()
WriteIntArray(writer, "GoldDropRange", GoldDropRange);
WriteIntArray(writer, "PlatinumDropRange", PlatinumDropRange);
WriteIntArray(writer, "UraniniteDropRange", UraniniteDropRange);

writer.WriteLine("[SpawnableArea]");
var spawnLocation = ValidSpawnLocations[0];
writer.WriteLine($"CenterPosition={spawnLocation.CenterPosition.X},{spawnLocation.CenterPosition.Y},{spawnLocation.CenterPosition.Z}");
writer.WriteLine($"Radius={spawnLocation.Radius}");
}
}
catch (Exception ex)
Expand Down Expand Up @@ -380,6 +382,13 @@ public static void LoadSettings()
case "UraniniteDropRange":
UraniniteDropRange = ReadIntArray(value);
break;
case "CenterPosition":
var coords = value.Split(',');
ValidSpawnLocations[0].CenterPosition = new Vector3D(double.Parse(coords[0]), double.Parse(coords[1]), double.Parse(coords[2]));
break;
case "Radius":
ValidSpawnLocations[0].Radius = double.Parse(value);
break;
}
}
}
Expand Down Expand Up @@ -411,25 +420,17 @@ private static int[] ReadIntArray(string value)
public class SpawnableArea
{
public Vector3D CenterPosition;
public Vector3D Normal;
public double Radius;
public double InnerRadius;
public double HeightFromCenter;

public bool ContainsPoint(Vector3D point)
{
point -= CenterPosition;
double pointDistanceSq = point.LengthSquared();
if (pointDistanceSq > Radius * Radius || pointDistanceSq < InnerRadius * InnerRadius)
return false;
if (Math.Abs(Vector3D.Dot(point, Normal)) > HeightFromCenter)
return false;
return true;
double distanceSquared = (point - CenterPosition).LengthSquared();
return distanceSquared <= Radius * Radius;
}

public Vector3D VelocityAtPoint(Vector3D point)
{
return -(point - CenterPosition).Cross(Normal).Normalized() * AsteroidSettings.AsteroidVelocityBase;
return (point - CenterPosition).Normalized() * AsteroidSettings.AsteroidVelocityBase;
}
}
}

0 comments on commit a3af308

Please sign in to comment.