Murder Satellites
Created TurretController, which performs basic combat for fixed orbital installations Projectiles self-destruct at maximum range Created turret prefab Outfitted turret in game manager Entity position is now 3D Entities responsible for updating their own position and orientation Barrel positions and orientations available from entity code Inventory code will display modal dialog for invalid item moves instead of breaking Yaw articulation working (full 360 rotation still borked)
This commit is contained in:
parent
8aaccac2b5
commit
ef816cc7e0
60 changed files with 2536 additions and 244 deletions
|
|
@ -1,34 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class Aim : AgentBehavior
|
||||
{
|
||||
public float2 Objective;
|
||||
|
||||
private Thruster _thrust;
|
||||
private Turning _turning;
|
||||
private VelocityLimit _velocityLimit;
|
||||
|
||||
public Aim(ItemManager context, Entity entity, ControllerData controllerData) : base(context, entity, controllerData)
|
||||
{
|
||||
_velocityLimit = Entity.GetBehaviors<VelocityLimit>().FirstOrDefault();
|
||||
_thrust = Entity.GetBehavior<Thruster>();
|
||||
_turning = Entity.GetBehavior<Turning>();
|
||||
}
|
||||
public override void Update(float delta)
|
||||
{
|
||||
if (_thrust != null && _turning != null)
|
||||
{
|
||||
float2 diff = Objective - Entity.Position;
|
||||
_turning.Axis = TurningInput(diff);
|
||||
_thrust.Axis = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,45 +14,45 @@ public class Locomotion : AgentBehavior
|
|||
public float2 Objective;
|
||||
private const float TangentSensitivity = 2;
|
||||
|
||||
private Thruster _thrust;
|
||||
private Turning _turning;
|
||||
private VelocityLimit _velocityLimit;
|
||||
private Thruster[] _thrusters;
|
||||
private float _thrust;
|
||||
|
||||
public Locomotion(ItemManager context, Entity entity, ControllerData controllerData) : base(context, entity, controllerData)
|
||||
{
|
||||
_velocityLimit = Entity.GetBehaviors<VelocityLimit>().FirstOrDefault();
|
||||
_thrust = Entity.GetBehavior<Thruster>();
|
||||
_turning = Entity.GetBehavior<Turning>();
|
||||
_velocityLimit = Entity.GetBehavior<VelocityLimit>();
|
||||
_thrusters = entity.GetBehaviors<Thruster>()
|
||||
.Where(t => t.Item.EquippableItem.Rotation == ItemRotation.Reversed)
|
||||
.ToArray();
|
||||
_thrust = _thrusters.Sum(t => t.Thrust);
|
||||
}
|
||||
|
||||
public override void Update(float delta)
|
||||
{
|
||||
if (_thrust != null && _turning != null)
|
||||
{
|
||||
float2 diff = Objective - Entity.Position;
|
||||
|
||||
// We want to go top speed in the direction of our target
|
||||
var topSpeed = _velocityLimit?.Limit ?? 1000;
|
||||
float2 desiredVelocity = normalize(diff) * topSpeed;
|
||||
|
||||
var accelerationTime = length(desiredVelocity - Entity.Velocity) / (_thrust.Thrust / Entity.Mass);
|
||||
var accelerationDistance = accelerationTime * length((desiredVelocity + Entity.Velocity) / 2);
|
||||
var diff = Objective - Entity.Position.xz;
|
||||
|
||||
// We want to go top speed in the direction of our target
|
||||
var topSpeed = _velocityLimit?.Limit ?? 1000;
|
||||
float2 desiredVelocity = normalize(diff) * topSpeed;
|
||||
|
||||
var accelerationTime = length(desiredVelocity - Entity.Velocity) / (_thrust / Entity.Mass);
|
||||
var accelerationDistance = accelerationTime * length((desiredVelocity + Entity.Velocity) / 2);
|
||||
|
||||
// We do not have enough space to get to full speed, use approximate maneuvering
|
||||
if (accelerationDistance > length(diff))
|
||||
{
|
||||
float2 tangential = Entity.Velocity - dot(normalize(diff), normalize(Entity.Velocity)) * Entity.Velocity;
|
||||
float2 adjustedDirection = normalize(diff) - tangential * TangentSensitivity;
|
||||
_turning.Axis = TurningInput(adjustedDirection);
|
||||
_thrust.Axis = 1;
|
||||
}
|
||||
// We have plenty of space, use exact maneuvering
|
||||
else
|
||||
{
|
||||
var deltaV = desiredVelocity - Entity.Velocity;
|
||||
_turning.Axis = TurningInput(deltaV);
|
||||
_thrust.Axis = ThrustInput(deltaV);
|
||||
}
|
||||
}
|
||||
// We do not have enough space to get to full speed, use approximate maneuvering
|
||||
// if (accelerationDistance > length(diff))
|
||||
// {
|
||||
// float2 tangential = Entity.Velocity - dot(normalize(diff), normalize(Entity.Velocity)) * Entity.Velocity;
|
||||
// float2 adjustedDirection = normalize(diff) - tangential * TangentSensitivity;
|
||||
//
|
||||
// _turning.Axis = TurningInput(adjustedDirection);
|
||||
// _thrust.Axis = 1;
|
||||
// }
|
||||
// // We have plenty of space, use exact maneuvering
|
||||
// else
|
||||
// {
|
||||
// var deltaV = desiredVelocity - Entity.Velocity;
|
||||
// _turning.Axis = TurningInput(deltaV);
|
||||
// _thrust.Axis = ThrustInput(deltaV);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(31, typeof(CapacitorData)),
|
||||
Union(32, typeof(CockpitData)),
|
||||
Union(33, typeof(HeatsinkData)),
|
||||
Union(34, typeof(TurretControllerData)),
|
||||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
|
||||
protected Locomotion Locomotion;
|
||||
protected VelocityMatch VelocityMatch;
|
||||
protected Aim Aim;
|
||||
protected Func<float2> TargetPosition;
|
||||
protected Func<float2> TargetVelocity;
|
||||
protected bool MatchVelocity;
|
||||
|
|
@ -80,7 +79,6 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
{
|
||||
Locomotion = new Locomotion(ItemManager, Entity, _controllerData);
|
||||
VelocityMatch = new VelocityMatch(ItemManager, Entity, _controllerData);
|
||||
Aim = new Aim(ItemManager, Entity, _controllerData);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
|
|
@ -128,7 +126,7 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
Entity.RemoveParent();
|
||||
|
||||
var targetPosition = TargetPosition();
|
||||
var distance = length(targetPosition - Entity.Position);
|
||||
var distance = length(targetPosition - Entity.Position.xz);
|
||||
if (MatchVelocity)
|
||||
{
|
||||
var targetVelocity = TargetVelocity();
|
||||
|
|
@ -203,7 +201,7 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
|
||||
public void MoveTo(Entity entity, bool matchVelocity = true, Action onFinish = null)
|
||||
{
|
||||
TargetPosition = () => entity.Position;
|
||||
TargetPosition = () => entity.Position.xz;
|
||||
TargetVelocity = () => entity.Velocity;
|
||||
MatchVelocity = matchVelocity;
|
||||
_movementPhase = MovementPhase.Locomotion;
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public class MiningController : ControllerBase<Mining>, IBehavior, IPersistentBe
|
|||
|
||||
private void NextAsteroid()
|
||||
{
|
||||
_asteroid = Zone.NearestAsteroid(Task.Asteroids, Entity.Position);
|
||||
_asteroid = Zone.NearestAsteroid(Task.Asteroids, Entity.Position.xz);
|
||||
Entity.SetMessage("Selecting new asteroid.");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class MiningTool : IBehavior
|
|||
var asteroidTransform = Entity.Zone.GetAsteroidTransform(AsteroidBelt, Asteroid);
|
||||
if (AsteroidBelt != Guid.Empty &&
|
||||
Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid) &&
|
||||
length(Entity.Position - asteroidTransform.xy) - asteroidTransform.w < Range)
|
||||
length(Entity.Position.xz - asteroidTransform.xz) - asteroidTransform.w < Range)
|
||||
{
|
||||
Entity.Zone.MineAsteroid(
|
||||
Entity,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class PatrolController : IBehavior, IInitializableBehavior
|
|||
_locomotion.Objective = Entity.Zone.GetOrbitPosition(_targetOrbit);
|
||||
_locomotion.Update(delta);
|
||||
|
||||
if(length(Entity.Position - _locomotion.Objective) < _data.TargetDistance)
|
||||
if(length(Entity.Position.xz - _locomotion.Objective) < _data.TargetDistance)
|
||||
RandomTarget();
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
{
|
||||
if(Asteroid > -1 &&
|
||||
Asteroid < beltData.Asteroids.Length &&
|
||||
length(Entity.Position - Entity.Zone.GetAsteroidTransform(ScanTarget, Asteroid).xy) < Range)
|
||||
length(Entity.Position.xz - Entity.Zone.GetAsteroidTransform(ScanTarget, Asteroid).xy) < Range)
|
||||
{
|
||||
_scanTime += delta;
|
||||
if (_scanTime > ScanDuration)
|
||||
|
|
@ -88,7 +88,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
}
|
||||
else
|
||||
{
|
||||
if(length(Entity.Position - Entity.Zone.GetOrbitPosition(planetData.Orbit)) < Range)
|
||||
if(length(Entity.Position.xz - Entity.Zone.GetOrbitPosition(planetData.Orbit)) < Range)
|
||||
{
|
||||
_scanTime += delta;
|
||||
if (_scanTime > ScanDuration)
|
||||
|
|
|
|||
|
|
@ -109,8 +109,8 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
private void NextPlanet()
|
||||
{
|
||||
var planets = Task.Planets.Select(id => Zone.Planets[id]);
|
||||
var nearestPlanet = planets.MinBy(p => lengthsq(Entity.Position - GetPosition(p)));
|
||||
_asteroid = nearestPlanet is AsteroidBeltData ? Zone.NearestAsteroid(nearestPlanet.ID, Entity.Position) : -1;
|
||||
var nearestPlanet = planets.MinBy(p => lengthsq(Entity.Position.xz - GetPosition(p)));
|
||||
_asteroid = nearestPlanet is AsteroidBeltData ? Zone.NearestAsteroid(nearestPlanet.ID, Entity.Position.xz) : -1;
|
||||
_targetPlanet = nearestPlanet.ID;
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position);
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position.xz);
|
||||
return Zone.GetAsteroidTransform(planet.ID, asteroid).xy;
|
||||
}
|
||||
return Zone.GetOrbitPosition(planet.Orbit);
|
||||
|
|
@ -128,7 +128,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position);
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position.xz);
|
||||
return Zone.GetAsteroidVelocity(planet.ID, asteroid);
|
||||
}
|
||||
return Zone.GetOrbitVelocity(planet.Orbit);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class TowingController : ControllerBase<StationTowing>, IBehavior, IPersi
|
|||
MoveTo(() =>
|
||||
{
|
||||
var orbitParent = Zone.GetOrbitPosition(Task.OrbitParent);
|
||||
var parentToUs = Entity.Position - orbitParent;
|
||||
var parentToUs = Entity.Position.xz - orbitParent;
|
||||
return orbitParent + normalize(parentToUs) * Task.OrbitDistance;
|
||||
}, () => Zone.GetOrbitVelocity(Task.OrbitParent), OnDelivery);
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ public class TowingController : ControllerBase<StationTowing>, IBehavior, IPersi
|
|||
|
||||
Entity.SetMessage("Target delivered. Returning Home.");
|
||||
|
||||
var orbit = Zone.CreateOrbit(Task.OrbitParent, Entity.Position);
|
||||
var orbit = Zone.CreateOrbit(Task.OrbitParent, Entity.Position.xz);
|
||||
Task.Station.OrbitData = orbit.ID;
|
||||
|
||||
FinishTask();
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ public class Trigger : IBehavior
|
|||
{
|
||||
private TriggerData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
|
|
|
|||
93
Assets/Scripts/ServerShared/Behaviors/TurretController.cs
Normal file
93
Assets/Scripts/ServerShared/Behaviors/TurretController.cs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class TurretControllerData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new TurretController(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class TurretController : IBehavior
|
||||
{
|
||||
private TurretControllerData _data;
|
||||
private Dictionary<Trigger, WeaponData> _triggers = new Dictionary<Trigger, WeaponData>();
|
||||
|
||||
public Entity EquippedEntity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public TurretController(ItemManager context, TurretControllerData data, Entity equippedEntity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
EquippedEntity = equippedEntity;
|
||||
Item = item;
|
||||
var weapons = equippedEntity.Equipment.Where(e => e.Behaviors.Any(b => b.Data is WeaponData));
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
CheckWeapon(item);
|
||||
}
|
||||
|
||||
equippedEntity.Equipment.ObserveAdd().Subscribe(add => CheckWeapon(add.Value));
|
||||
equippedEntity.Equipment.ObserveRemove().Subscribe(remove =>
|
||||
{
|
||||
foreach (var bg in remove.Value.BehaviorGroups)
|
||||
if (_triggers.ContainsKey(bg.Trigger))
|
||||
_triggers.Remove(bg.Trigger);
|
||||
});
|
||||
}
|
||||
|
||||
private void CheckWeapon(EquippedItem item)
|
||||
{
|
||||
foreach (var bg in item.BehaviorGroups)
|
||||
{
|
||||
if (bg.Trigger != null)
|
||||
{
|
||||
foreach (var b in bg.Behaviors)
|
||||
{
|
||||
if(b.Data is WeaponData weaponData)
|
||||
_triggers.Add(bg.Trigger, weaponData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
if (EquippedEntity.Target != null)
|
||||
{
|
||||
var diff = EquippedEntity.Target.Position - EquippedEntity.Position;
|
||||
EquippedEntity.LookDirection = normalize(diff);
|
||||
var dist = length(diff);
|
||||
|
||||
foreach (var x in _triggers)
|
||||
{
|
||||
if (Context.Evaluate(x.Value.Range, x.Key.Item.EquippableItem, EquippedEntity) > dist &&
|
||||
dot(EquippedEntity.HardpointTransforms[EquippedEntity.Hardpoints[x.Key.Item.Position.x, x.Key.Item.Position.y]].direction,
|
||||
EquippedEntity.LookDirection) > .9f)
|
||||
{
|
||||
x.Key.Pull();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EquippedEntity.Target = EquippedEntity.Zone.Entities.FirstOrDefault(e => e is Ship);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4daff8784b3444a4ab5466da3368cd7a
|
||||
guid: c19f106bac321f34bab3c83bf64e7e77
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -23,7 +23,7 @@ public abstract class Entity
|
|||
public Zone Zone;
|
||||
public EquippableItem Hull;
|
||||
|
||||
public float2 Position;
|
||||
public float3 Position;
|
||||
public float2 Direction = float2(0,1);
|
||||
public float2 Velocity;
|
||||
|
||||
|
|
@ -49,6 +49,7 @@ public abstract class Entity
|
|||
|
||||
public readonly Dictionary<string, float> Messages = new Dictionary<string, float>();
|
||||
public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
|
||||
public readonly Dictionary<HardpointData, (float3 position, float3 direction)> HardpointTransforms = new Dictionary<HardpointData, (float3 position, float3 direction)>();
|
||||
|
||||
public readonly List<EquippedItem>[] TriggerGroups;
|
||||
|
||||
|
|
@ -337,9 +338,9 @@ public abstract class Entity
|
|||
|
||||
if (!ItemFits(itemData, hullData, item, hullCoord)) return false;
|
||||
|
||||
EquippedItem equippedItem;
|
||||
if (itemData.HardpointType == HardpointType.Tool || itemData.HardpointType == HardpointType.Thermal)
|
||||
{
|
||||
EquippedItem equippedItem;
|
||||
if(itemData is CargoBayData)
|
||||
{
|
||||
if (itemData is DockingBayData)
|
||||
|
|
@ -358,34 +359,25 @@ public abstract class Entity
|
|||
equippedItem = new EquippedItem(ItemManager, item, hullCoord, this);
|
||||
Equipment.Add(equippedItem);
|
||||
}
|
||||
|
||||
foreach (var i in itemData.Shape.Coordinates)
|
||||
{
|
||||
var occupiedCoord = hullCoord + itemData.Shape.Rotate(i, item.Rotation);
|
||||
(itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[occupiedCoord.x, occupiedCoord.y] = equippedItem;
|
||||
}
|
||||
|
||||
Mass += itemData.Mass;
|
||||
_orderedEquipment = Equipment.OrderBy(x => x.SortPosition).ToArray();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var equippedItem = new EquippedItem(ItemManager, item, hullCoord, this);
|
||||
equippedItem = new EquippedItem(ItemManager, item, hullCoord, this);
|
||||
Equipment.Add(equippedItem);
|
||||
|
||||
foreach (var i in itemData.Shape.Coordinates)
|
||||
{
|
||||
var occupiedCoord = hullCoord + itemData.Shape.Rotate(i, item.Rotation);
|
||||
ThermalMass[occupiedCoord.x, occupiedCoord.y] += ItemManager.GetThermalMass(item) / itemData.Shape.Coordinates.Length;
|
||||
Conductivity[occupiedCoord.x, occupiedCoord.y] *= itemData.Conductivity;
|
||||
(itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[occupiedCoord.x, occupiedCoord.y] = equippedItem;
|
||||
}
|
||||
|
||||
Mass += itemData.Mass;
|
||||
_orderedEquipment = Equipment.OrderBy(x => x.SortPosition).ToArray();
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var i in itemData.Shape.Coordinates)
|
||||
{
|
||||
var occupiedCoord = hullCoord + itemData.Shape.Rotate(i, item.Rotation);
|
||||
// TODO: Track thermal mass of cargo bay contents as reactive property
|
||||
ThermalMass[occupiedCoord.x, occupiedCoord.y] += ItemManager.GetThermalMass(item) / itemData.Shape.Coordinates.Length;
|
||||
Conductivity[occupiedCoord.x, occupiedCoord.y] *= itemData.Conductivity;
|
||||
(itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[occupiedCoord.x, occupiedCoord.y] = equippedItem;
|
||||
}
|
||||
|
||||
Mass += itemData.Mass;
|
||||
_orderedEquipment = Equipment.OrderBy(x => x.SortPosition).ToArray();
|
||||
return true;
|
||||
}
|
||||
|
||||
public EquippedDockingBay TryDock(Ship ship)
|
||||
|
|
@ -553,6 +545,7 @@ public abstract class Entity
|
|||
Position = Parent.Position;
|
||||
Velocity = Parent.Velocity;
|
||||
}
|
||||
else Position.y = Zone.GetHeight(Position.xz) + hullData.GridOffset;
|
||||
}
|
||||
|
||||
public void SetMessage(string message)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class OrbitalEntity : Entity
|
|||
{
|
||||
if (OrbitData != Guid.Empty)
|
||||
{
|
||||
Position = Zone.GetOrbitPosition(OrbitData);
|
||||
Position.xz = Zone.GetOrbitPosition(OrbitData);
|
||||
Velocity = Zone.GetOrbitVelocity(OrbitData);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using MessagePack;
|
|||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using quaternion = Unity.Mathematics.quaternion;
|
||||
|
||||
[MessagePackObject]
|
||||
public class Ship : Entity
|
||||
|
|
@ -31,6 +32,8 @@ public class Ship : Entity
|
|||
private Thruster[] _leftThrusters;
|
||||
private Thruster[] _clockwiseThrusters;
|
||||
private Thruster[] _counterClockwiseThrusters;
|
||||
|
||||
public quaternion Rotation { get; private set; }
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
|
|
@ -49,7 +52,7 @@ public class Ship : Entity
|
|||
|
||||
public override void Update(float delta)
|
||||
{
|
||||
Position += Velocity * delta;
|
||||
Position.xz += Velocity * delta;
|
||||
if (_active)
|
||||
{
|
||||
foreach (var thruster in _allThrusters) thruster.Axis = 0;
|
||||
|
|
@ -65,6 +68,18 @@ public class Ship : Entity
|
|||
foreach (var thruster in _clockwiseThrusters) thruster.Axis += deltaRot;
|
||||
foreach (var thruster in _counterClockwiseThrusters) thruster.Axis += -deltaRot;
|
||||
}
|
||||
var normal = Zone.GetNormal(Position.xz);
|
||||
var f = new float2(normal.x, normal.z);
|
||||
var fl = lengthsq(f);
|
||||
if (fl > .001)
|
||||
{
|
||||
var fa = 1 / (1 - fl) - 1;
|
||||
Velocity += normalize(f) * Zone.Settings.GravityStrength * fa;
|
||||
}
|
||||
var shipRight = Direction.Rotate(ItemRotation.Clockwise);
|
||||
var forward = cross(float3(shipRight.x, 0, shipRight.y), normal);
|
||||
Rotation = quaternion.LookRotation(forward, normal);
|
||||
|
||||
base.Update(delta);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class Zone
|
|||
|
||||
private HashSet<Guid> _updatedOrbits = new HashSet<Guid>();
|
||||
|
||||
private PlanetSettings _settings;
|
||||
public PlanetSettings Settings;
|
||||
private float _time;
|
||||
private Random _random;
|
||||
|
||||
|
|
@ -34,12 +34,12 @@ public class Zone
|
|||
public Zone(PlanetSettings settings, ZonePack pack)
|
||||
{
|
||||
Data = pack.Data;
|
||||
_settings = settings;
|
||||
Settings = settings;
|
||||
_random = new Random(Convert.ToUInt32(abs(Data.ID.GetHashCode())));
|
||||
|
||||
foreach (var orbit in pack.Orbits)
|
||||
{
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(Settings, orbit));
|
||||
}
|
||||
|
||||
foreach (var planet in pack.Planets)
|
||||
|
|
@ -77,7 +77,7 @@ public class Zone
|
|||
|
||||
public void AddOrbit(OrbitData orbit)
|
||||
{
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(Settings, orbit));
|
||||
}
|
||||
|
||||
public void Update(float time, float deltaTime)
|
||||
|
|
@ -194,14 +194,14 @@ public class Zone
|
|||
if(belt.RespawnTimers.ContainsKey(i)) size = 0;
|
||||
else if (belt.Damage.ContainsKey(i))
|
||||
{
|
||||
var asteroidHitpoints = _settings.AsteroidHitpoints.Evaluate(beltData.Asteroids[i].Size);
|
||||
var asteroidHitpoints = Settings.AsteroidHitpoints.Evaluate(beltData.Asteroids[i].Size);
|
||||
var damage = (asteroidHitpoints - belt.Damage[i]) / asteroidHitpoints;
|
||||
size = _settings.AsteroidSize.Evaluate(damage * beltData.Asteroids[i].Size);
|
||||
size = Settings.AsteroidSize.Evaluate(damage * beltData.Asteroids[i].Size);
|
||||
}
|
||||
else size = _settings.AsteroidSize.Evaluate(beltData.Asteroids[i].Size);
|
||||
else size = Settings.AsteroidSize.Evaluate(beltData.Asteroids[i].Size);
|
||||
|
||||
belt.Transforms[i] = float4(
|
||||
OrbitData.Evaluate((float) frac(_time / _settings.OrbitPeriod.Evaluate(beltData.Asteroids[i].Distance) +
|
||||
OrbitData.Evaluate((float) frac(_time / Settings.OrbitPeriod.Evaluate(beltData.Asteroids[i].Distance) +
|
||||
beltData.Asteroids[i].Phase)) * beltData.Asteroids[i].Distance + orbitPosition,
|
||||
(float) (_time * beltData.Asteroids[i].RotationSpeed % (PI * 2)), size);
|
||||
}
|
||||
|
|
@ -212,7 +212,7 @@ public class Zone
|
|||
var parentPosition = GetOrbitPosition(parent);
|
||||
var delta = position - parentPosition;
|
||||
var distance = length(delta);
|
||||
var period = _settings.OrbitPeriod.Evaluate(distance);
|
||||
var period = Settings.OrbitPeriod.Evaluate(distance);
|
||||
var phase = atan2(delta.y, delta.x) / (PI * 2);
|
||||
var currentPhase = frac(_time / period);
|
||||
var storedPhase = (float) frac(phase - currentPhase);
|
||||
|
|
@ -224,7 +224,7 @@ public class Zone
|
|||
Parent = parent,
|
||||
Phase = storedPhase
|
||||
};
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(Settings, orbit));
|
||||
return orbit;
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +235,7 @@ public class Zone
|
|||
var asteroidTransform = belt.Transforms[asteroid];
|
||||
|
||||
var size = beltData.Asteroids[asteroid].Size;
|
||||
var asteroidHitpoints = _settings.AsteroidHitpoints.Evaluate(size);
|
||||
var asteroidHitpoints = Settings.AsteroidHitpoints.Evaluate(size);
|
||||
|
||||
if (!belt.Damage.ContainsKey(asteroid))
|
||||
belt.Damage[asteroid] = 0;
|
||||
|
|
@ -247,7 +247,7 @@ public class Zone
|
|||
|
||||
if (belt.Damage[asteroid] > asteroidHitpoints)
|
||||
{
|
||||
belt.RespawnTimers[asteroid] = _settings.AsteroidRespawnTime.Evaluate(size);
|
||||
belt.RespawnTimers[asteroid] = Settings.AsteroidRespawnTime.Evaluate(size);
|
||||
belt.Damage.Remove(asteroid);
|
||||
belt.MiningAccumulator.Remove((miner, asteroid));
|
||||
return;
|
||||
|
|
@ -255,7 +255,7 @@ public class Zone
|
|||
|
||||
var resourceCount = beltData.Resources.Sum(x => x.Value);
|
||||
var resource = beltData.Resources.MaxBy(x => pow(x.Value, 1f / penetration) * _random.NextFloat());
|
||||
if (efficiency * _random.NextFloat() * belt.MiningAccumulator[(miner, asteroid)] * resourceCount / _settings.MiningDifficulty > 1)
|
||||
if (efficiency * _random.NextFloat() * belt.MiningAccumulator[(miner, asteroid)] * resourceCount / Settings.MiningDifficulty > 1)
|
||||
{
|
||||
belt.MiningAccumulator.Remove((miner, asteroid));
|
||||
// var newSimpleCommodity = new SimpleCommodity
|
||||
|
|
@ -269,7 +269,7 @@ public class Zone
|
|||
}
|
||||
public float GetHeight(float2 position)
|
||||
{
|
||||
float result = -PowerPulse(length(position)/(Data.Radius*2), _settings.ZoneDepthExponent) * _settings.ZoneDepth;
|
||||
float result = -PowerPulse(length(position)/(Data.Radius*2), Settings.ZoneDepthExponent) * Settings.ZoneDepth;
|
||||
foreach (var body in PlanetInstances.Values)
|
||||
{
|
||||
var p = (position - body.Orbit.Position); //GetOrbitPosition(body.BodyData.Orbit)
|
||||
|
|
@ -287,7 +287,7 @@ public class Zone
|
|||
if(distSqr < waveRadius*waveRadius)
|
||||
{
|
||||
var depth = gas.GravityWavesDepth.Value;
|
||||
var frequency = _settings.WaveFrequency.Evaluate(body.BodyData.Mass.Value);
|
||||
var frequency = Settings.WaveFrequency.Evaluate(body.BodyData.Mass.Value);
|
||||
var speed = gas.GravityWavesSpeed.Value;
|
||||
result -= RadialWaves(sqrt(distSqr) / waveRadius, 8, 1.25f, frequency, _time * speed) * depth;
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@ public class Zone
|
|||
{
|
||||
var normal = GetNormal(position);
|
||||
var f = new float2(normal.x, normal.z);
|
||||
return f * _settings.GravityStrength * lengthsq(f);// * Mathf.Abs(GetHeight(position));
|
||||
return f * Settings.GravityStrength * lengthsq(f);// * Mathf.Abs(GetHeight(position));
|
||||
}
|
||||
|
||||
public static float PowerPulse(float x, float exponent)
|
||||
|
|
|
|||
Loading…
Reference in a new issue