Created control module abstraction, vastly simplifying current and future control module code
Created context menu option for creating towing tasks
This commit is contained in:
hyperion51 2020-05-27 02:23:25 +01:00
commit 139c593ccd
21 changed files with 685 additions and 291 deletions

View file

@ -1243,9 +1243,7 @@
<e p="ActionCollection.cs" t="Include" />
<e p="Agents" t="Include">
<e p="AgentBehavior.cs" t="Include" />
<e p="AgentController.cs" t="Include" />
<e p="AgentTask.cs" t="Include" />
<e p="EntityAgent.cs" t="Include" />
<e p="Locomotion.cs" t="Include" />
<e p="StationTowing.cs" t="Include" />
<e p="VelocityMatch.cs" t="Include" />

View file

@ -0,0 +1,98 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Orbit Curve
m_Shader: {fileID: 203, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 019f08636fbf0e743a83fb33922ea1d4, type: 3}
m_Scale: {x: 4, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BlendOp: 0
- _BumpScale: 1
- _CameraFadingEnabled: 0
- _CameraFarFadeDistance: 2
- _CameraNearFadeDistance: 1
- _ColorMode: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DistortionBlend: 0.5
- _DistortionEnabled: 0
- _DistortionStrength: 1
- _DistortionStrengthScaled: 0
- _DstBlend: 0
- _EmissionEnabled: 0
- _FlipbookMode: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _InvFade: 1
- _LightingEnabled: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SoftParticlesEnabled: 0
- _SoftParticlesFarFadeDistance: 1
- _SoftParticlesNearFadeDistance: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _ColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}
- _TintColor: {r: 0.39760002, g: 0.4638667, b: 0.497, a: 1}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f6540f65a203d4c409d75342582efbd3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Resources/Sprites/Flat UI/line.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,110 @@
fileFormatVersion: 2
guid: 019f08636fbf0e743a83fb33922ea1d4
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 9
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 6caf356040dd1114691b02ee197c9eb6
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -3413,6 +3413,7 @@ Transform:
m_Children:
- {fileID: 548600403}
- {fileID: 1956833087}
- {fileID: 1718013116}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -11180,6 +11181,7 @@ MonoBehaviour:
type: 3}
CorpMenuContinueButton: {fileID: 148866027}
CorpNameInputField: {fileID: 896210412}
OrbitLineRenderer: {fileID: 1718013118}
PrimaryTabGroup: {fileID: 143833105}
GalaxyTabButton: {fileID: 646091942}
ZoneTabButton: {fileID: 618245060}
@ -11215,6 +11217,7 @@ MonoBehaviour:
ChildEntityDistance: 0.66
ChildEntityScale: 0.25
ChildEntityOffsetDegrees: 30
OrbitCircleSegments: 128
--- !u!4 &1126386501
Transform:
m_ObjectHideFlags: 0
@ -16496,6 +16499,148 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1713239317}
m_CullTransparentMesh: 0
--- !u!1 &1718013115
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1718013116}
- component: {fileID: 1718013118}
- component: {fileID: 1718013117}
m_Layer: 0
m_Name: OrbitCurve
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1718013116
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1718013115}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 435654367}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1718013117
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1718013115}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1281fe44325f9b548aa42dc331b17266, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!120 &1718013118
LineRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1718013115}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 0
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: f6540f65a203d4c409d75342582efbd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Positions:
- {x: -2, y: 1, z: 0}
- {x: -1.36923, y: 3.016669, z: 0}
- {x: -0.042671, y: 4.492466, z: 0}
- {x: 3.472713, y: 4.52563, z: 0}
- {x: 4.301812, y: 3.447801, z: 0}
m_Parameters:
serializedVersion: 3
widthMultiplier: 1
widthCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0.0066223145
value: 0.06841591
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
colorGradient:
serializedVersion: 2
key0: {r: 1, g: 1, b: 1, a: 1}
key1: {r: 1, g: 1, b: 1, a: 1}
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 0
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
numCornerVertices: 0
numCapVertices: 0
alignment: 0
textureMode: 1
shadowBias: 0.5
generateLightingData: 0
m_UseWorldSpace: 1
m_Loop: 1
--- !u!1 &1723832126
GameObject:
m_ObjectHideFlags: 0

View file

@ -1,64 +0,0 @@
// using System;
// using System.Collections;
// using System.Collections.Generic;
// using System.Linq;
// using static Unity.Mathematics.math;
// using Random = Unity.Mathematics.Random;
//
// public class AgentController
// {
// public Guid Entity { get; }
// public EntityAgent EntityAgent { get; }
// public GameContext Context { get; }
// public Guid Zone { get; set; }
//
// private Locomotion _locomotion;
// private VelocityMatch _velocityMatch;
// private Random _random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue));
// private Guid _targetOrbit;
//
// public AgentController(GameContext context, Guid zone, Guid entity)
// {
// Entity = entity;
// Zone = zone;
// Context = context;
// EntityAgent = new EntityAgent(context, entity, zone, Guid.Empty);
// _locomotion = new Locomotion(context, entity);
// _velocityMatch = new VelocityMatch(context, entity);
// _velocityMatch.OnMatch += () =>
// {
// EntityAgent.CurrentBehavior = _locomotion;
// RandomTarget();
// };
// EntityAgent.CurrentBehavior = _locomotion;
// RandomTarget();
// }
//
// public void Update(float delta)
// {
// EntityAgent.Update(delta);
// // Context.Log(
// // $"Agent Mode: {EntityAgent.CurrentBehavior.GetType()} " +
// // $"Agent Distance: {distance} " +
// // $"Turnaround Distance: {_stoppingDistance + _turnaroundDistance} " +
// // $"Objective: {_objective.Key.ID.ToString().Substring(0, 8)}");
// var entity = Context.Cache.Get<Entity>(Entity);
//
// if (EntityAgent.CurrentBehavior == _locomotion)
// {
// var orbitData = Context.Cache.Get<OrbitData>(_targetOrbit);
// _velocityMatch.TargetOrbit = _targetOrbit;
// var matchDistanceTime = _velocityMatch.MatchDistanceTime;
// _locomotion.Objective = Context.GetOrbitPosition(_targetOrbit) + Context.GetOrbitVelocity(_targetOrbit) * matchDistanceTime.y;
// var distance = length(_locomotion.Objective - entity.Position);
// if (distance < matchDistanceTime.x)
// EntityAgent.CurrentBehavior = _velocityMatch;
// }
// }
//
// private void RandomTarget()
// {
// var entities = Context.ZonePlanets[Zone];
// _targetOrbit = Context.Cache.Get<PlanetData>(entities[_random.NextInt(entities.Length)]).Orbit;
// }
// }

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ee1e3350676acb044bd87c1d76c535a4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,29 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using JsonKnownTypes;
using MessagePack;
using Newtonsoft.Json;
[MessagePackObject,
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<Entity>))]
public class EntityAgent
{
[IgnoreMember] public AgentBehavior CurrentBehavior;
[IgnoreMember] public Guid Entity;
[IgnoreMember] public GameContext Context;
[JsonProperty("homeZone"), Key(0)] public Guid HomeZone;
[JsonProperty("homeColony"), Key(0)] public Guid HomeColony;
public EntityAgent(GameContext context, Guid entity, Guid homeZone, Guid homeColony)
{
Entity = entity;
HomeZone = homeZone;
Context = context;
}
public void Update(float delta)
{
CurrentBehavior?.Update(delta);
}
}

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: fdefbc1e15541d8448061e9d97e44648
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -20,11 +20,11 @@ public class StationTowing : AgentTask
[JsonProperty("orbitDistance"), Key(6)]
public float OrbitDistance;
public StationTowing(Guid zone, Guid station, Guid orbitParent, float orbitDistance)
{
Zone = zone;
Station = station;
OrbitParent = orbitParent;
OrbitDistance = orbitDistance;
}
// public StationTowing(Guid zone, Guid station, Guid orbitParent, float orbitDistance)
// {
// Zone = zone;
// Station = station;
// OrbitParent = orbitParent;
// OrbitDistance = orbitDistance;
// }
}

View file

@ -52,7 +52,7 @@ public interface IController
bool Available { get; }
TaskType TaskType { get; }
Guid Zone { get; }
void AssignTask(Guid task, List<SimplifiedZoneData> path);
void AssignTask(Guid task);
}
[MessagePackObject,

View file

@ -3,6 +3,9 @@ using System.Collections;
using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using float2 = Unity.Mathematics.float2;
[Union(0, typeof(TowingControllerData))]
public abstract class ControllerData : BehaviorData
@ -18,27 +21,171 @@ public abstract class ControllerData : BehaviorData
[InspectableField, JsonProperty("tangentSensitivity"), Key(4)]
public float TangentSensitivity = 4;
[InspectableField, JsonProperty("targetDistance"), Key(5)]
public float TargetDistance = 10;
}
// public abstract class Controller : IController
// {
// public abstract bool Available { get; }
// public abstract TaskType TaskType { get; }
// public Guid Zone { get; }
//
// private GameContext _context;
// private Entity _entity;
// private Guid _task;
// private List<SimplifiedZoneData> _path;
//
// public Controller(GameContext context, Entity entity)
// {
//
// }
//
// public void AssignTask(Guid task, List<SimplifiedZoneData> path)
// {
// _task = task;
// _path = path;
// }
// }
public abstract class ControllerBase : IBehavior, IController, IInitializableBehavior
{
public Guid HomeEntity;
public bool Available => Task == Guid.Empty;
public abstract TaskType TaskType { get; }
public Guid Zone => _entity.Zone;
public BehaviorData Data => _controllerData;
protected Locomotion Locomotion;
protected VelocityMatch VelocityMatch;
protected Func<float2> TargetPosition;
protected Func<float2> TargetVelocity;
protected bool MatchVelocity;
protected List<SimplifiedZoneData> Path;
protected Guid Task;
private GameContext _context;
private Entity _entity;
private ControllerData _controllerData;
private MovementPhase _movementPhase;
private bool _moving;
private Action _onFinishMoving;
public ControllerBase(GameContext context, ControllerData data, Entity entity)
{
_context = context;
_controllerData = data;
_entity = entity;
}
public void Initialize()
{
Locomotion = new Locomotion(_context, _entity, _controllerData);
VelocityMatch = new VelocityMatch(_context, _entity, _controllerData);
_context.CorporationControllers[_entity.Corporation].Add(this);
}
public void AssignTask(Guid task)
{
Task = task;
_moving = false;
}
public bool Update(float delta)
{
if (Available)
{
// No task is assigned and we're at home, do nothing!
if (_entity.Parent == HomeEntity)
return false;
// No task is assigned, but we're not home, go home!
var homeEntity = _context.Cache.Get<Entity>(HomeEntity);
if (!_moving)
{
if (Zone == homeEntity.Zone) MoveTo(homeEntity, true, () =>
_context.SetParent(_entity, homeEntity));
else MoveTo(homeEntity.Zone, () => MoveTo(homeEntity, true, () =>
_context.SetParent(_entity, homeEntity)));
}
}
if (_moving)
{
var distance = length(TargetPosition() - _entity.Position);
if (MatchVelocity)
{
VelocityMatch.TargetVelocity = TargetVelocity();
if (_movementPhase == MovementPhase.Locomotion)
{
var matchDistanceTime = VelocityMatch.MatchDistanceTime;
Locomotion.Objective = TargetPosition() + TargetVelocity() * matchDistanceTime.y;
Locomotion.Update(delta);
if (distance < matchDistanceTime.x)
{
_movementPhase = MovementPhase.Slowdown;
_context.Log($"Controller {_entity.Name} has entered slowdown phase.");
VelocityMatch.Clear();
VelocityMatch.OnMatch += () =>
{
_moving = false;
_onFinishMoving();
};
}
}
else
{
VelocityMatch.Update(delta);
}
}
else
{
Locomotion.Objective = TargetPosition();
Locomotion.Update(delta);
if (distance < _controllerData.TargetDistance)
{
_moving = false;
_onFinishMoving();
}
}
}
return true;
}
public void MoveTo(Entity entity, bool matchVelocity = true, Action onFinish = null)
{
TargetPosition = () => entity.Position;
TargetVelocity = () => entity.Velocity;
MatchVelocity = matchVelocity;
_movementPhase = MovementPhase.Locomotion;
_moving = true;
_onFinishMoving = onFinish;
}
public void MoveTo(float2 position, bool matchVelocity = true, Action onFinish = null)
{
TargetPosition = () => position;
TargetVelocity = () => float2.zero;
MatchVelocity = matchVelocity;
_movementPhase = MovementPhase.Locomotion;
_moving = true;
_onFinishMoving = onFinish;
}
public void MoveTo(Func<float2> position, Func<float2> velocity, Action onFinish = null)
{
TargetPosition = position;
TargetVelocity = velocity;
MatchVelocity = true;
_movementPhase = MovementPhase.Locomotion;
_moving = true;
_onFinishMoving = onFinish;
}
public void MoveTo(Guid zone, Action onFinish = null)
{
var path = _context.FindPath(_context.GalaxyZones[Zone], _context.GalaxyZones[zone]);
void OnNextZone()
{
path.RemoveAt(0);
if (path.Count > 0)
{
MoveTo(_context.WormholePosition(_entity.Zone, Path[0].ZoneID), false, OnNextZone);
}
else
{
onFinish?.Invoke();
}
}
OnNextZone();
}
}
public enum MovementPhase
{
Locomotion,
Slowdown
}

View file

@ -9,9 +9,6 @@ using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
public class PatrolControllerData : ControllerData
{
[InspectableField, JsonProperty("targetDistance"), Key(5)]
public float TargetDistance = 10;
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new PatrolController(context, this, entity, item);
@ -58,7 +55,7 @@ public class PatrolController : IBehavior, IController, IInitializableBehavior
return true;
}
public void AssignTask(Guid task, List<SimplifiedZoneData> path)
public void AssignTask(Guid task)
{
throw new NotImplementedException();
}

View file

@ -16,156 +16,84 @@ public class TowingControllerData : ControllerData
}
}
public class TowingController : IBehavior, IPersistentBehavior, IController, IInitializableBehavior
public class TowingController : ControllerBase, IBehavior, IPersistentBehavior
{
public TaskType TaskType => TaskType.Tow;
public bool Available => _towingTask != Guid.Empty;
public Guid Zone => _entity.Zone;
public override TaskType TaskType => TaskType.Tow;
public BehaviorData Data => _data;
private TowingControllerData _data;
private GameContext _context;
private Entity _entity;
private Gear _item;
private Guid _towingTask;
private List<SimplifiedZoneData> _path;
private TowingPhase _towingPhase = TowingPhase.Pickup;
private MovementPhase _movementPhase = MovementPhase.Locomotion;
private Locomotion _locomotion;
private VelocityMatch _velocityMatch;
private bool _taskStarted;
public TowingController(GameContext context, TowingControllerData data, Entity entity, Gear item)
public TowingController(GameContext context, TowingControllerData data, Entity entity, Gear item) : base(context, data, entity)
{
_context = context;
_data = data;
_entity = entity;
_item = item;
}
public void Initialize()
public new bool Update(float delta)
{
_locomotion = new Locomotion(_context, _entity, _data);
_velocityMatch = new VelocityMatch(_context, _entity, _data);
}
public bool Update(float delta)
{
var towingTask = _context.Cache.Get<StationTowing>(_towingTask);
if (towingTask == null)
return false;
if (_path.Any())
var towingTask = _context.Cache.Get<StationTowing>(Task);
if (towingTask != null)
{
_locomotion.Update(delta);
if(_entity.Parent!=Guid.Empty)
_context.RemoveParent(_entity);
if (length(_entity.Position - _locomotion.Objective) < _context.GlobalData.WarpDistance)
if (!_taskStarted)
{
_context.Warp(_entity, _path[0].ZoneID);
_path.RemoveAt(0);
if(_path.Any())
SetWormholeDestination();
}
}
else
{
var destination = float2(0);
var velocity = float2(0);
if (_towingPhase == TowingPhase.Pickup)
{
destination = _context.ZoneEntities[_entity.Zone][towingTask.Station].Position;
velocity = _context.ZoneEntities[_entity.Zone][towingTask.Station].Velocity;
}
else
{
var orbitParent = _context.GetOrbitPosition(towingTask.OrbitParent);
var parentToUs = _entity.Position - orbitParent;
var nearestPointInOrbit = orbitParent + normalize(parentToUs) * towingTask.OrbitDistance;
destination = nearestPointInOrbit;
velocity = _context.GetOrbitVelocity(towingTask.OrbitParent);
}
_velocityMatch.TargetVelocity = velocity;
if (_movementPhase == MovementPhase.Locomotion)
{
var matchDistanceTime = _velocityMatch.MatchDistanceTime;
_locomotion.Objective = destination + velocity * matchDistanceTime.y;
_locomotion.Update(delta);
var distance = length(destination - _entity.Position);
if (distance < matchDistanceTime.x)
MoveTo(towingTask.Zone, () =>
{
_movementPhase = MovementPhase.Slowdown;
_velocityMatch.Clear();
if (_towingPhase == TowingPhase.Pickup)
_velocityMatch.OnMatch += () =>
_context.Log($"Towing Controller {_entity.Name} has entered pickup phase.");
MoveTo(_context.Cache.Get<Entity>(towingTask.Station), true, () =>
{
var target = _context.ZoneEntities[_entity.Zone][towingTask.Station] as OrbitalEntity;
_context.SetParent(target, _entity);
_context.Log($"Towing Controller {_entity.Name} has entered delivery phase.");
MoveTo(() =>
{
var target = _context.ZoneEntities[_entity.Zone][towingTask.Station];
_context.SetParent(target, _entity);
_towingPhase = TowingPhase.Delivery;
_movementPhase = MovementPhase.Locomotion;
};
else
_velocityMatch.OnMatch += () =>
var orbitParent = _context.GetOrbitPosition(towingTask.OrbitParent);
var parentToUs = _entity.Position - orbitParent;
return orbitParent + normalize(parentToUs) * towingTask.OrbitDistance;
}, () => _context.GetOrbitVelocity(towingTask.OrbitParent), () =>
{
var target = _context.ZoneEntities[_entity.Zone][towingTask.Station] as OrbitalEntity;
_context.RemoveParent(target);
_context.Log($"Towing Controller {_entity.Name} has delivered the target. Returning Home.");
var orbit = _context.CreateOrbit(towingTask.OrbitParent, _entity.Position);
target.OrbitData = orbit.ID;
};
}
}
else
{
_velocityMatch.Update(delta);
Task = Guid.Empty;
_taskStarted = false;
});
});
});
_taskStarted = true;
}
}
return true;
return base.Update(delta);
}
public PersistentBehaviorData Store()
{
return new TowingControllerPersistence
{
TowingTask = _towingTask
Task = Task
};
}
public void Restore(PersistentBehaviorData data)
{
var towingControllerPersistence = data as TowingControllerPersistence;
_towingTask = towingControllerPersistence.TowingTask;
}
public void AssignTask(Guid task, List<SimplifiedZoneData> path)
{
_towingTask = task;
_path = path;
_path.RemoveAt(0);
if(_path.Any())
SetWormholeDestination();
}
private void SetWormholeDestination()
{
_locomotion.Objective = _context.WormholePosition(_entity.Zone, _path[0].ZoneID);
Task = towingControllerPersistence.Task;
}
}
public class TowingControllerPersistence : PersistentBehaviorData
{
[JsonProperty("towingTask"), Key(0)]
public Guid TowingTask;
}
public enum TowingPhase
{
Pickup,
Delivery
}
public enum MovementPhase
{
Locomotion,
Slowdown
[JsonProperty("task"), Key(0)]
public Guid Task;
}

View file

@ -53,10 +53,11 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
}
public Entity(GameContext context, Guid hull, IEnumerable<Guid> items, IEnumerable<Guid> cargo, Guid zone)
public Entity(GameContext context, Guid hull, IEnumerable<Guid> items, IEnumerable<Guid> cargo, Guid zone, Guid corporation)
{
Context = context;
Zone = zone;
Corporation = corporation;
EquippedItems = items.ToList();
Cargo = cargo.ToList();

View file

@ -134,7 +134,7 @@ public class GameContext
}
}
task.Reserved = true;
nearestController.AssignTask(task.ID, nearestControllerPath);
nearestController.AssignTask(task.ID);
}
}
}
@ -257,7 +257,8 @@ public class GameContext
var distance = length(delta);
var period = OrbitalPeriod(distance);
var phase = atan2(delta.y, delta.x) / (PI * 2);
var storedPhase = (float) frac(Time / -period * GlobalData.OrbitSpeedMultiplier - phase);
var currentPhase = frac(Time / -period * GlobalData.OrbitSpeedMultiplier);
var storedPhase = (float) frac(phase - currentPhase);
var orbit = new OrbitData
{
@ -644,7 +645,7 @@ public class GameContext
if (hullData.HullType == HullType.Ship)
{
var entity = new Ship(this, hull.ID, gear.Select(g => g.ID),
cargo.Select(c => c.ID).Concat(simpleCargo.Select(c => c.ID)), zone)
cargo.Select(c => c.ID).Concat(simpleCargo.Select(c => c.ID)), zone, corporation)
{
Name = $"{loadoutData.Name} {Random.NextInt(1,255):X}"
};
@ -671,7 +672,7 @@ public class GameContext
Cache.Add(orbit);
var entity = new OrbitalEntity(this, hull.ID, gear.Select(g => g.ID),
cargo.Select(c => c.ID).Concat(simpleCargo.Select(c => c.ID)), orbit.ID, zone)
cargo.Select(c => c.ID).Concat(simpleCargo.Select(c => c.ID)), orbit.ID, zone, corporation)
{
Name = $"{loadoutData.Name} {Random.NextInt(1,255):X}",
Temperature = 293
@ -800,6 +801,7 @@ public class GameContext
var parent = Cache.Get<Entity>(child.Parent);
parent.Children.Remove(child.ID);
parent.RecalculateMass();
child.Parent = Guid.Empty;
}
}

View file

@ -9,7 +9,7 @@ public class OrbitalEntity : Entity
{
public Guid OrbitData;
public OrbitalEntity(GameContext context, Guid hull, IEnumerable<Guid> items, IEnumerable<Guid> cargo, Guid orbit, Guid zone) : base(context, hull, items, cargo, zone)
public OrbitalEntity(GameContext context, Guid hull, IEnumerable<Guid> items, IEnumerable<Guid> cargo, Guid orbit, Guid zone, Guid corporation) : base(context, hull, items, cargo, zone, corporation)
{
OrbitData = orbit;
}

View file

@ -19,7 +19,7 @@ public class Ship : Entity
// [IgnoreMember] public Dictionary<Targetable, float> Contacts = new Dictionary<Targetable, float>();
// [IgnoreMember] public Targetable Target;
public Ship(GameContext context, Guid hull, IEnumerable<Guid> items, IEnumerable<Guid> cargo, Guid zone) : base(context, hull, items, cargo, zone)
public Ship(GameContext context, Guid hull, IEnumerable<Guid> items, IEnumerable<Guid> cargo, Guid zone, Guid corporation) : base(context, hull, items, cargo, zone, corporation)
{
}

View file

@ -33,6 +33,7 @@ public class StrategyGameManager : MonoBehaviour
public CorporationMenuItem CorpOptionPrefab;
public TabButton CorpMenuContinueButton;
public TMP_InputField CorpNameInputField;
public LineRenderer OrbitLineRenderer;
[Section("Tab Links")]
public TabGroup PrimaryTabGroup;
@ -71,6 +72,7 @@ public class StrategyGameManager : MonoBehaviour
public float ChildEntityDistance = .66f;
public float ChildEntityScale = .25f;
public float ChildEntityOffsetDegrees = 30f;
public int OrbitCircleSegments = 128;
private DatabaseCache _cache;
private GameContext _context;
@ -97,6 +99,10 @@ public class StrategyGameManager : MonoBehaviour
private Dictionary<CorporationMenuItem, Guid> _corpOptionMap = new Dictionary<CorporationMenuItem, Guid>();
private CorporationMenuItem _selectedParent;
private Dictionary<int, float2[]> _childEntityPositions = new Dictionary<int, float2[]>();
private bool _orbitSelectMode;
private Guid _selectedOrbit = Guid.Empty;
private Guid _selectedTowingTarget = Guid.Empty;
private float _orbitRadius;
void Start()
{
@ -183,7 +189,9 @@ public class StrategyGameManager : MonoBehaviour
Parent = _corpOptionMap[_selectedParent]
};
_cache.Add(newCorp);
_context.CorporationControllers[newCorp.ID] = new List<IController>();
player.Corporation = newCorp.ID;
_playerCorporation = newCorp.ID;
GameMenuRoot.gameObject.SetActive(true);
CorpMenuRoot.gameObject.SetActive(false);
@ -198,7 +206,12 @@ public class StrategyGameManager : MonoBehaviour
entities.Add(_context.CreateEntity(_selectedZone, newCorp.ID, loadout.Key));
var colony = entities.First(e => e is OrbitalEntity);
foreach (var ship in entities.Where(e => e is Ship))
{
foreach (var controller in ship.GetBehaviors<ControllerBase>())
controller.HomeEntity = colony.ID;
_context.SetParent(ship, colony);
}
}
};
}
@ -232,7 +245,7 @@ public class StrategyGameManager : MonoBehaviour
foreach (var entry in zone.Contents) _cache.Add(entry);
if(_currentTab==GalaxyTabButton && _selectedZone == zone.Zone.ID)
PopulatePropertiesPanel(_selectedZone);
Select(_selectedZone);
if (_currentTab == ZoneTabButton && _populatedZone != zone.Zone.ID) PopulateZone();
});
@ -256,7 +269,7 @@ public class StrategyGameManager : MonoBehaviour
var zone = _cache.Get<ZoneData>(_selectedZone);
if (_populatedZone != _selectedZone && zone != null)
PopulateZone();
PopulatePropertiesPanel(_populatedZone);
Select(_populatedZone);
Camera.transform.position = -Vector3.forward;
if (zone != null)
Camera.orthographicSize = zone.Radius * ZoneSizeScale;
@ -286,12 +299,36 @@ public class StrategyGameManager : MonoBehaviour
else if (_currentTab == ZoneTabButton)
{
if (data.button == PointerEventData.InputButton.Left)
PopulatePropertiesPanel(_populatedZone);
{
if (_orbitSelectMode)
{
var playerCorp = _cache.Get<Corporation>(_playerCorporation);
var towingTask = new StationTowing
{
Context = _context,
OrbitDistance = _orbitRadius,
OrbitParent = _selectedOrbit,
Priority = 0,
Reserved = false,
Station = _selectedTowingTarget,
Zone = _populatedZone
};
_cache.Add(towingTask);
playerCorp.Tasks.Add(towingTask.ID);
_orbitSelectMode = false;
OrbitLineRenderer.gameObject.SetActive(false);
}
else
Select(_populatedZone);
}
else if (data.button == PointerEventData.InputButton.Right)
ShowContextMenu(_populatedZone);
}
else if (_currentTab == TechTabButton) PopulateTechProperties();
};
OrbitLineRenderer.positionCount = OrbitCircleSegments;
OrbitLineRenderer.gameObject.SetActive(false);
}
private void PopulateGalaxyProperties()
@ -369,7 +406,7 @@ public class StrategyGameManager : MonoBehaviour
childGameObject.GetComponent<ClickableCollider>().OnClick += (collider, data) =>
{
if (data.button == PointerEventData.InputButton.Left)
PopulatePropertiesPanel(child);
Select(child);
else if (data.button == PointerEventData.InputButton.Right)
ShowContextMenu(child);
};
@ -389,7 +426,7 @@ public class StrategyGameManager : MonoBehaviour
zoneShip.Icon.GetComponent<ClickableCollider>().OnClick += (collider, data) =>
{
if (data.button == PointerEventData.InputButton.Left)
PopulatePropertiesPanel(ship.ID);
Select(ship.ID);
else if (data.button == PointerEventData.InputButton.Right)
ShowContextMenu(ship.ID);
};
@ -425,7 +462,7 @@ public class StrategyGameManager : MonoBehaviour
zoneOrbital.Icon.GetComponent<ClickableCollider>().OnClick += (collider, data) =>
{
if (data.button == PointerEventData.InputButton.Left)
PopulatePropertiesPanel(orbital.ID);
Select(orbital.ID);
else if (data.button == PointerEventData.InputButton.Right)
ShowContextMenu(orbital.ID);
};
@ -446,6 +483,22 @@ public class StrategyGameManager : MonoBehaviour
Destroy(_zoneOrbitals[orbital].gameObject);
_zoneOrbitals.Remove(orbital);
}
if (_orbitSelectMode)
{
var center = _context.GetOrbitPosition(_selectedOrbit) * ZoneSizeScale;
var mousePos = Camera.ScreenToWorldPoint(Input.mousePosition);
var radius = length(float2(mousePos.x, mousePos.y) - center);
_orbitRadius = radius / ZoneSizeScale;
var positions = new Vector3[OrbitCircleSegments];
for (int i = 0; i < OrbitCircleSegments; i++)
{
var deg = ((float) i) / OrbitCircleSegments * 2 * PI;
positions[i] = float3(float2(sin(deg), cos(deg)) * radius + center, 0);
}
OrbitLineRenderer.gameObject.SetActive(true);
OrbitLineRenderer.SetPositions(positions);
}
}
}
@ -500,6 +553,20 @@ public class StrategyGameManager : MonoBehaviour
});
ContextMenu.AddOption("Test Option 3", () => Debug.Log("Test Option 3 Selected"));
}
else if (targetObject is Ship ship)
{
}
else if (targetObject is OrbitalEntity orbital)
{
ContextMenu.AddOption("Create Towing Task", () =>
{
_selectedOrbit = Guid.Empty;
_selectedTowingTarget = orbital.ID;
_orbitSelectMode = true;
OrbitLineRenderer.gameObject.SetActive(true);
});
}
else
{
ContextMenu.gameObject.SetActive(false);
@ -508,28 +575,35 @@ public class StrategyGameManager : MonoBehaviour
ContextMenu.Show();
}
void PopulatePropertiesPanel(Guid clickTarget)
void Select(Guid clickTarget)
{
var targetObject = _context.Cache.Get(clickTarget);
if (targetObject is PlanetData planet)
{
PropertiesPanel.Clear();
PropertiesPanel.Title.text = planet.Name;
if(planet.Belt)
PropertiesPanel.AddSection("Asteroid Belt");
else
PropertiesPanel.AddSection(
planet.Mass > _context.GlobalData.SunMass ? "Star" :
planet.Mass > _context.GlobalData.GasGiantMass ? "Gas Giant" :
planet.Mass > _context.GlobalData.PlanetMass ? "Planet" :
"Planetoid");
PropertiesPanel.AddProperty("Mass", () => $"{planet.Mass}");
PropertiesPanel.AddList("Resources", planet.Resources.Select(resource =>
if (_orbitSelectMode)
{
var itemData = _context.Cache.Get<SimpleCommodityData>(resource.Key);
return new Tuple<string, string>(itemData.Name, $"{resource.Value:0}");
}));
_selectedOrbit = planet.Orbit;
}
else
{
PropertiesPanel.Clear();
PropertiesPanel.Title.text = planet.Name;
if(planet.Belt)
PropertiesPanel.AddSection("Asteroid Belt");
else
PropertiesPanel.AddSection(
planet.Mass > _context.GlobalData.SunMass ? "Star" :
planet.Mass > _context.GlobalData.GasGiantMass ? "Gas Giant" :
planet.Mass > _context.GlobalData.PlanetMass ? "Planet" :
"Planetoid");
PropertiesPanel.AddProperty("Mass", () => $"{planet.Mass}");
PropertiesPanel.AddList("Resources", planet.Resources.Select(resource =>
{
var itemData = _context.Cache.Get<SimpleCommodityData>(resource.Key);
return new Tuple<string, string>(itemData.Name, $"{resource.Value:0}");
}));
}
}
if (targetObject is Entity entity)
@ -599,7 +673,7 @@ public class StrategyGameManager : MonoBehaviour
CultClient.Send(new ZoneRequestMessage{ZoneID = zone.ZoneID});
if (TestMode)
{
PopulatePropertiesPanel(zone.ZoneID);
Select(zone.ZoneID);
}
_selectedZone = zone.ZoneID;
_selectedGalaxyZone = instanceZone;
@ -700,7 +774,7 @@ public class StrategyGameManager : MonoBehaviour
planetObject.Icon.GetComponent<ClickableCollider>().OnClick += (collider, data) =>
{
if (data.button == PointerEventData.InputButton.Left)
PopulatePropertiesPanel(planetData.ID);
Select(planetData.ID);
else if (data.button == PointerEventData.InputButton.Right)
ShowContextMenu(planetData.ID);
};
@ -714,7 +788,7 @@ public class StrategyGameManager : MonoBehaviour
beltObject.GetComponent<ClickableCollider>().OnClick += (_, data) =>
{
if (data.button == PointerEventData.InputButton.Left)
PopulatePropertiesPanel(planetData.ID);
Select(planetData.ID);
else if (data.button == PointerEventData.InputButton.Right)
ShowContextMenu(planetData.ID);
};

View file

@ -62,9 +62,7 @@
<ItemGroup>
<Compile Include="Assets\Scripts\ServerShared\ActionCollection.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\AgentBehavior.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\AgentController.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\AgentTask.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\EntityAgent.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\Locomotion.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\StationTowing.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\VelocityMatch.cs" />