Skip to content

Commit

Permalink
Merge branch 'master' into firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
andylippitt committed Mar 3, 2019
2 parents 1f86ef9 + d65f0d3 commit 08725b8
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 125 deletions.
10 changes: 5 additions & 5 deletions Game.API.Common/Models/Hook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public static Hook Default
{
WorldSize = 8000,
WorldResizeEnabled = true,
WorldSizeBasic = 4000,
WorldSizeBasic = 8000,
WorldSizeDeltaPerPlayer = 400,
WorldResizeSpeed = 5,
WorldMinPlayersToResize = 2,
WorldMinPlayersToResize = 4,

FollowFirstShip = false,
FiringSequenceDelay = 0,
Expand Down Expand Up @@ -62,8 +62,8 @@ public static Hook Default
Wormholes = 0,
WormholesDestination = null,

Obstacles = 10,
ObstaclesMultiplier = 0.0005,
Obstacles = 10, // ignored if WorldResizeEnabled = true
ObstaclesMultiplier = 0.0005, // used when WorldResizeEnabled = true
ObstacleMaxMomentum = 0.1f,
ObstacleMaxMomentumWeatherMultiplier = 1.0f,
ObstacleMinSize = 300,
Expand Down Expand Up @@ -128,7 +128,7 @@ public static Hook Default
PointsPerKillFleetMax = 55,
PointsPerKillFleetStep = 5,
PointsPerKillFleetPerStep = 50,
ComboDelay = 3000,
ComboDelay = 4000,
ComboPointsStep = 5,

PlayerCountGracePeriodMS = 15000,
Expand Down
2 changes: 1 addition & 1 deletion Game.Engine/wwwroot/js/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ for (var i = 0; i < messages.length; i++) {
chat.innerHTML += `<tr><td>${i < 9 ? 1 + ~~i : 0}</td><td>${messages[i]}</td></tr>`;
}
window.addEventListener("keydown", e => {
if (e.keyCode == 84) {
if (e.keyCode == 84 && document.body.classList.contains("alive")) {
chat.classList.toggle("open");
}
if (e.keyCode < 58 && e.keyCode > 47 && document.body.classList.contains("alive")) {
Expand Down
2 changes: 1 addition & 1 deletion Game.Engine/wwwroot/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ document.getElementById("settingsReset").addEventListener("click", () => {

let minimapChanged = false;
window.addEventListener("keydown", function(e) {
if ((e.keyCode == 77 && !minimapChanged && document.body.classList.contains("alive")) || document.body.classList.contains("spectating")) {
if (e.keyCode == 77 && !minimapChanged && (document.body.classList.contains("alive") || document.body.classList.contains("spectating"))) {
Settings.displayMinimap = !Settings.displayMinimap;
minimapChanged = true;
}
Expand Down
80 changes: 80 additions & 0 deletions Game.Robots/ParallelRoboMath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace Game.Robots
{
using Game.Robots.Models;
using System;
using System.Numerics;
using System.Threading.Tasks;

public static class ParallelRoboMath
{
public static Vector2[] ProjectClosest(HookComputer hook, float maxTime, Vector2[] fromPosition, Vector2[] targetPosition, int[] fleetSize)
{
var boostSpeed = hook.Hook.BoostThrust;
int N = fromPosition.Length;
Vector2[] vout = new Vector2[N];
for (int i = 0; i < N; i++)
{
var bulletSpeed = hook.ShotThrust(fleetSize[i]) * 10;
var path = targetPosition[i] - fromPosition[i];
var pLen = path.Length();
var maxD = bulletSpeed * maxTime + boostSpeed * hook.Hook.BoostDuration;
vout[i] = fromPosition[i] + path * (1.0f / pLen) * MathF.Min(pLen - 10.0f, maxD);
}
return vout;
}
public static float[] ProjectClosestIntersectionDist(HookComputer hook, float maxTime, Robot r, Vector2 start, Vector2 destination, API.Client.Body[] bullet)
{
var path = destination - start;
var pLen = path.Length();
var targetPosition = start;
int N = bullet.Length;
float[] fout = new float[N];
Parallel.For(0,N,i=>{
var bS = bullet[i].Position;
var bM = bullet[i].Momentum;

var fromPosition = bS;
var toTarget = targetPosition - fromPosition;

var bulletSpeed = bullet[i].Momentum.Length();
var targetMomentum = (destination - start) / ((float)maxTime);

var a = Vector2.Dot(targetMomentum, targetMomentum) - (bulletSpeed * bulletSpeed);
var b = 2 * Vector2.Dot(targetMomentum, toTarget);
var c = Vector2.Dot(toTarget, toTarget);

var p = -b / (2 * a);
var q = MathF.Sqrt((b * b) - 4 * a * c) / (2 * a);

var t1 = p - q;
var t2 = p + q;
var t = 0f;

if (t1 > t2 && t2 > 0)
t = t2;
else
t = t1;
t = MathF.Max(MathF.Min(maxTime + 10.0f, t), 0.0f);

var aimSpot = targetPosition + targetMomentum * t;
var aimMinusS = aimSpot - start;
var desMinusS = destination - start;
var disss = float.MaxValue;
var bulletPath = aimSpot - fromPosition;
var timeToImpact = (int)(bulletPath.Length() / bulletSpeed);//speed must be in units per second

if (timeToImpact > hook.Hook.BulletLife || (timeToImpact > maxTime + 10))
{
timeToImpact = int.MaxValue;
}
else
{
var themS = start + targetMomentum * ((float)timeToImpact);
disss = (themS - aimSpot).Length();
}
fout[i] = disss;
});
return fout;
}
}
}
Loading

0 comments on commit 08725b8

Please sign in to comment.