Main Menu
Added Main Menu scene Tweaked world map to incorporate secondary colors in zone icons + glowing links Entity Serialization is now generic Zone Serialization now includes entities Fixed bug where wormhole traversal would unbind from player entity Game Manager no longer spawns entities (loadout file format changed) Wrote extension to randomly select weighted items from collections (for generating enemies)
This commit is contained in:
parent
1aef932162
commit
e6181c11dc
53 changed files with 3763 additions and 49169 deletions
|
|
@ -135,7 +135,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
PlayerSettings = MessagePackSerializer.Deserialize<PlayerSettings>(
|
||||
File.ReadAllBytes(playerSettingsFile.FullName));
|
||||
|
||||
Loadouts.AddRange(_loadoutPath.EnumerateFiles("*.preset")
|
||||
Loadouts.AddRange(_loadoutPath.EnumerateFiles("*.loadout")
|
||||
.Select(fi => MessagePackSerializer.Deserialize<EntityPack>(File.ReadAllBytes(fi.FullName))));
|
||||
|
||||
var names = new HashSet<string>();
|
||||
|
|
@ -449,7 +449,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
radius: Settings.DefaultZoneRadius
|
||||
);
|
||||
|
||||
Zone = new Zone(Settings.PlanetSettings, zonePack);
|
||||
Zone = new Zone(ItemManager, Settings.PlanetSettings, zonePack);
|
||||
Zone.Log = s => Debug.Log($"Zone: {s}");
|
||||
|
||||
if (CurrentEntity != null)
|
||||
|
|
@ -468,7 +468,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
if (CurrentEntity != null)
|
||||
{
|
||||
DisposeEntityBinding();
|
||||
UnbindEntity();
|
||||
BindToEntity(CurrentEntity);
|
||||
}
|
||||
|
||||
|
|
@ -477,50 +477,32 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
private void GenerateZoneEntities(Zone zone)
|
||||
{
|
||||
var testCorp = new MegaCorporation();
|
||||
testCorp.Name = "TestCorp";
|
||||
testCorp.PlayerHostile = true;
|
||||
|
||||
var stationType = ItemData.GetAll<HullData>().First(x=>x.HullType==HullType.Station);
|
||||
var stationHull = ItemManager.CreateInstance(stationType) as EquippableItem;
|
||||
var stationParent = Zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(3);
|
||||
var stationParentOrbit = stationParent.Orbit.Data.ID;
|
||||
var stationParentPos = Zone.GetOrbitPosition(stationParentOrbit);
|
||||
var stationPos = stationParentPos + ItemManager.Random.NextFloat2Direction() * stationParent.GravityWellRadius.Value * .1f;
|
||||
var stationOrbit = Zone.CreateOrbit(stationParentOrbit, stationPos);
|
||||
var station = new OrbitalEntity(ItemManager, Zone, stationHull, stationOrbit.ID);
|
||||
//station.Faction = testCorp;
|
||||
zone.Entities.Add(station);
|
||||
var dockingBayData = ItemData.GetAll<DockingBayData>().First();
|
||||
var dockingBay = ItemManager.CreateInstance(dockingBayData) as EquippableItem;
|
||||
station.TryEquip(dockingBay);
|
||||
station.Activate();
|
||||
|
||||
var turretLoadout = Loadouts.First(x => x.Name == "Turret");
|
||||
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
var planet = zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(4+i);
|
||||
var planetOrbit = planet.Orbit.Data.ID;
|
||||
var planetPos = zone.GetOrbitPosition(planetOrbit);
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
var pos = planetPos + ItemManager.Random.NextFloat2Direction() * planet.GravityWellRadius.Value * (.1f + .1f * j);
|
||||
var orbit = zone.CreateOrbit(planetOrbit, pos);
|
||||
var turret = EntityPack.Unpack(ItemManager, Zone, turretLoadout, orbit.ID, true);
|
||||
turret.Activate();
|
||||
turret.Name = $"Turret {i}-{(char) ('A' + j)}";
|
||||
turret.Faction = testCorp;
|
||||
zone.Entities.Add(turret);
|
||||
}
|
||||
}
|
||||
|
||||
var enemyShipLoadout = Loadouts.First(x => ((HullData) ItemManager.GetData(x.Hull)).HullType == HullType.Ship);
|
||||
var enemyShip = EntityPack.Unpack(ItemManager, Zone, enemyShipLoadout, true);
|
||||
enemyShip.Faction = testCorp;
|
||||
enemyShip.Activate();
|
||||
zone.Entities.Add(enemyShip);
|
||||
zone.Agents.Add(CreateAgent(enemyShip));
|
||||
//
|
||||
// var turretLoadout = Loadouts.First(x => x.Name == "Turret");
|
||||
//
|
||||
// for(int i=0; i<3; i++)
|
||||
// {
|
||||
// var planet = zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(4+i);
|
||||
// var planetOrbit = planet.Orbit.Data.ID;
|
||||
// var planetPos = zone.GetOrbitPosition(planetOrbit);
|
||||
// for (int j = 0; j < 2; j++)
|
||||
// {
|
||||
// var pos = planetPos + ItemManager.Random.NextFloat2Direction() * planet.GravityWellRadius.Value * (.1f + .1f * j);
|
||||
// var orbit = zone.CreateOrbit(planetOrbit, pos);
|
||||
// var turret = EntityPack.Unpack(ItemManager, Zone, turretLoadout, orbit.ID, true);
|
||||
// turret.Activate();
|
||||
// turret.Name = $"Turret {i}-{(char) ('A' + j)}";
|
||||
// turret.Faction = testCorp;
|
||||
// zone.Entities.Add(turret);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// var enemyShipLoadout = Loadouts.First(x => ((HullData) ItemManager.GetData(x.Hull)).HullType == HullType.Ship);
|
||||
// var enemyShip = EntityPack.Unpack(ItemManager, Zone, enemyShipLoadout, true);
|
||||
// enemyShip.Faction = testCorp;
|
||||
// enemyShip.Activate();
|
||||
// zone.Entities.Add(enemyShip);
|
||||
// zone.Agents.Add(CreateAgent(enemyShip));
|
||||
}
|
||||
|
||||
private Agent CreateAgent(Ship ship)
|
||||
|
|
@ -535,17 +517,31 @@ public class ActionGameManager : MonoBehaviour
|
|||
private void StartGame()
|
||||
{
|
||||
GenerateLevel();
|
||||
// var turret = Zone.Entities.First(e => e.Name.StartsWith("Turret"));
|
||||
// BindToEntity(turret);
|
||||
var ship = EntityPack.Unpack(ItemManager, Zone, Loadouts.First(x => x.Name == StarterShipTemplate), true);
|
||||
ship.Zone = Zone;
|
||||
Zone.Entities.Add(ship);
|
||||
ship.Activate();
|
||||
BindToEntity(ship);
|
||||
ship.ExitWormhole(
|
||||
SectorRenderer.WormholeInstances.Keys.First().Position,
|
||||
ItemManager.Random.NextFloat2Direction() * Settings.GameplaySettings.WormholeExitVelocity);
|
||||
EnterOverworld();
|
||||
|
||||
var stationType = ItemData.GetAll<HullData>().First(x=>x.HullType==HullType.Station);
|
||||
var stationHull = ItemManager.CreateInstance(stationType) as EquippableItem;
|
||||
var stationParent = Zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(3);
|
||||
var stationParentOrbit = stationParent.Orbit.Data.ID;
|
||||
var stationParentPos = Zone.GetOrbitPosition(stationParentOrbit);
|
||||
var stationPos = stationParentPos + ItemManager.Random.NextFloat2Direction() * stationParent.GravityWellRadius.Value * .1f;
|
||||
var stationOrbit = Zone.CreateOrbit(stationParentOrbit, stationPos);
|
||||
var station = new OrbitalEntity(ItemManager, Zone, stationHull, stationOrbit.ID);
|
||||
Zone.Entities.Add(station);
|
||||
var dockingBayData = ItemData.GetAll<DockingBayData>().First();
|
||||
var dockingBay = ItemManager.CreateInstance(dockingBayData) as EquippableItem;
|
||||
station.TryEquip(dockingBay);
|
||||
station.Activate();
|
||||
|
||||
DoDock(station, station.DockingBays.First());
|
||||
|
||||
// var ship = EntityPack.Unpack(ItemManager, Zone, Loadouts.First(x => x.Name == StarterShipTemplate), true);
|
||||
// ship.Zone = Zone;
|
||||
// Zone.Entities.Add(ship);
|
||||
// ship.Activate();
|
||||
// BindToEntity(ship);
|
||||
// ship.ExitWormhole(
|
||||
// SectorRenderer.WormholeInstances.Keys.First().Position,
|
||||
// ItemManager.Random.NextFloat2Direction() * Settings.GameplaySettings.WormholeExitVelocity);
|
||||
}
|
||||
|
||||
public void Dock()
|
||||
|
|
@ -561,18 +557,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
var bay = entity.TryDock(ship);
|
||||
if (bay != null)
|
||||
{
|
||||
DisposeEntityBinding();
|
||||
DockedEntity = entity;
|
||||
SectorRenderer.PerspectiveEntity = DockedEntity;
|
||||
DockingBay = bay;
|
||||
DockCamera.enabled = true;
|
||||
FollowCamera.enabled = false;
|
||||
var orbital = (OrbitalEntity) entity;
|
||||
DockCamera.Follow = SectorRenderer.EntityInstances[orbital].transform;
|
||||
var parentOrbit = Zone.Orbits[orbital.OrbitData].Data.Parent;
|
||||
var parentPlanet = SectorRenderer.Planets[Zone.Planets.FirstOrDefault(p => p.Value.Orbit == parentOrbit).Key];
|
||||
DockCamera.LookAt = parentPlanet.Body.transform;
|
||||
Menu.ShowTab(MenuTab.Inventory);
|
||||
UnbindEntity();
|
||||
DoDock(entity, bay);
|
||||
AkSoundEngine.PostEvent("Dock", gameObject);
|
||||
return;
|
||||
}
|
||||
|
|
@ -582,6 +568,21 @@ public class ActionGameManager : MonoBehaviour
|
|||
AkSoundEngine.PostEvent("Dock_Fail", gameObject);
|
||||
}
|
||||
|
||||
private void DoDock(Entity entity, EquippedDockingBay dockingBay)
|
||||
{
|
||||
DockedEntity = entity;
|
||||
SectorRenderer.PerspectiveEntity = DockedEntity;
|
||||
DockingBay = dockingBay;
|
||||
DockCamera.enabled = true;
|
||||
FollowCamera.enabled = false;
|
||||
var orbital = (OrbitalEntity) entity;
|
||||
DockCamera.Follow = SectorRenderer.EntityInstances[orbital].transform;
|
||||
var parentOrbit = Zone.Orbits[orbital.OrbitData].Data.Parent;
|
||||
var parentPlanet = SectorRenderer.Planets[Zone.Planets.FirstOrDefault(p => p.Value.Orbit == parentOrbit).Key];
|
||||
DockCamera.LookAt = parentPlanet.Body.transform;
|
||||
Menu.ShowTab(MenuTab.Inventory);
|
||||
}
|
||||
|
||||
public void Undock()
|
||||
{
|
||||
if (CurrentEntity.Parent == null) return;
|
||||
|
|
@ -611,8 +612,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
else if (CurrentEntity.Parent.TryUndock(ship))
|
||||
{
|
||||
BindToEntity(ship);
|
||||
|
||||
EnterOverworld();
|
||||
AkSoundEngine.PostEvent("Undock", gameObject);
|
||||
}
|
||||
else
|
||||
|
|
@ -624,7 +623,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private void DisposeEntityBinding()
|
||||
private void UnbindEntity()
|
||||
{
|
||||
foreach (var indicator in _visibleHostileIndicators)
|
||||
{
|
||||
|
|
@ -642,8 +641,18 @@ public class ActionGameManager : MonoBehaviour
|
|||
_shipSubscriptions.Clear();
|
||||
}
|
||||
|
||||
private void EnterOverworld()
|
||||
private void BindToEntity(Entity entity)
|
||||
{
|
||||
if (!SectorRenderer.EntityInstances.ContainsKey(entity))
|
||||
{
|
||||
Debug.LogError($"Attempted to bind to entity {entity.Name}, but SectorRenderer has no such instance!");
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentEntity = entity;
|
||||
DeathPP.weight = 0;
|
||||
SectorRenderer.PerspectiveEntity = CurrentEntity;
|
||||
|
||||
Menu.gameObject.SetActive(false);
|
||||
DockedEntity = null;
|
||||
DockingBay = null;
|
||||
|
|
@ -655,17 +664,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
_input.Player.Enable();
|
||||
ShipPanel.Display(CurrentEntity, true);
|
||||
SchematicDisplay.ShowShip(CurrentEntity);
|
||||
}
|
||||
|
||||
private void BindToEntity(Entity entity)
|
||||
{
|
||||
if (!SectorRenderer.EntityInstances.ContainsKey(entity))
|
||||
{
|
||||
Debug.LogError($"Attempted to bind to entity {entity.Name}, but SectorRenderer has no such instance!");
|
||||
return;
|
||||
}
|
||||
CurrentEntity = entity;
|
||||
SectorRenderer.PerspectiveEntity = CurrentEntity;
|
||||
|
||||
FollowCamera.LookAt = SectorRenderer.EntityInstances[CurrentEntity].LookAtPoint;
|
||||
FollowCamera.Follow = SectorRenderer.EntityInstances[CurrentEntity].transform;
|
||||
|
|
@ -717,7 +715,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
_shipSubscriptions.Add(CurrentEntity.Death.Subscribe(_ =>
|
||||
{
|
||||
var deathTime = Time.time;
|
||||
DisposeEntityBinding();
|
||||
UnbindEntity();
|
||||
CurrentEntity = null;
|
||||
ConfirmationDialog.Clear();
|
||||
ConfirmationDialog.Title.text = "You have died!";
|
||||
|
|
|
|||
46
Assets/Scripts/MainMenu.cs
Normal file
46
Assets/Scripts/MainMenu.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Title;
|
||||
public Prototype ButtonPrototype;
|
||||
|
||||
private List<Prototype> _contents = new List<Prototype>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
ShowMain();
|
||||
}
|
||||
|
||||
private void ShowMain()
|
||||
{
|
||||
Title.text = "aetheria\n<smallcaps><size=50%>terminus";
|
||||
Clear();
|
||||
AddButton("Continue", null);
|
||||
AddButton("New Game", null);
|
||||
AddButton("Load Game", null);
|
||||
AddButton("Settings", null);
|
||||
AddButton("Quit", Application.Quit);
|
||||
}
|
||||
|
||||
private void Clear()
|
||||
{
|
||||
foreach(var item in _contents)
|
||||
item.ReturnToPool();
|
||||
_contents.Clear();
|
||||
}
|
||||
|
||||
private void AddButton(string label, Action onPress)
|
||||
{
|
||||
var button = ButtonPrototype.Instantiate<Button>();
|
||||
button.GetComponent<TextMeshProUGUI>().text = label;
|
||||
button.onClick.RemoveAllListeners();
|
||||
button.onClick.AddListener(() => onPress?.Invoke());
|
||||
_contents.Add(button.GetComponent<Prototype>());
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MainMenu.cs.meta
Normal file
11
Assets/Scripts/MainMenu.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3d7c7b928d043a3449b93bce9de03d1c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -16,58 +16,13 @@ using static Unity.Mathematics.noise;
|
|||
[RequireComponent( typeof( Camera ) ), ImageEffectAllowedInSceneView]
|
||||
public class VolumeSampling : MonoBehaviour
|
||||
{
|
||||
// public int Octaves = 4;
|
||||
// public float Frequency = 1;
|
||||
// public float Lacunarity = 2;
|
||||
// public float Gain = .5f;
|
||||
// public int NoiseTextureCount = 16;
|
||||
// public int NoiseTextureSize = 32;
|
||||
public Material _volMaterial;
|
||||
public Transform GridTransform;
|
||||
private Camera _camera;
|
||||
// private Texture3D[] _noiseTextures;
|
||||
// private int _currentNoiseTexture;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_camera = GetComponent<Camera>();
|
||||
// _noiseTextures = new Texture3D[NoiseTextureCount];
|
||||
// var samples = new Color[NoiseTextureSize * NoiseTextureSize * NoiseTextureSize];
|
||||
// for (int i = 0; i < NoiseTextureCount; i++)
|
||||
// {
|
||||
// var iv = (float) i / NoiseTextureCount;
|
||||
// var tex = new Texture3D(NoiseTextureSize,NoiseTextureSize,NoiseTextureSize, GraphicsFormat.R8_UNorm, TextureCreationFlags.None);
|
||||
// tex.filterMode = FilterMode.Bilinear;
|
||||
// for (int z = 0; z < NoiseTextureSize; z++)
|
||||
// {
|
||||
// var zf = (float) z / NoiseTextureSize;
|
||||
// int zOffset = z * NoiseTextureSize * NoiseTextureSize;
|
||||
// for (int y = 0; y < NoiseTextureSize; y++)
|
||||
// {
|
||||
// var yf = (float) y / NoiseTextureSize;
|
||||
// int yOffset = y * NoiseTextureSize;
|
||||
// for (int x = 0; x < NoiseTextureSize; x++)
|
||||
// {
|
||||
// var xf = (float) x / NoiseTextureSize;
|
||||
// var index = x + yOffset + zOffset;
|
||||
// float freq = Frequency, amp = 1;
|
||||
// float sum = 0;
|
||||
// var p = float4(xf, yf, zf, iv);
|
||||
// for(int o = 0; o < Octaves; o++)
|
||||
// {
|
||||
// sum += (pnoise(p * freq, 1 / freq) + 1) / 2 * amp;
|
||||
// freq *= Lacunarity;
|
||||
// amp *= Gain;
|
||||
// }
|
||||
//
|
||||
// samples[index] = Color.white * sum;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// tex.SetPixels(samples);
|
||||
// tex.Apply();
|
||||
// _noiseTextures[i] = tex;
|
||||
// }
|
||||
}
|
||||
|
||||
[ImageEffectOpaque]
|
||||
|
|
@ -79,10 +34,6 @@ public class VolumeSampling : MonoBehaviour
|
|||
Graphics.Blit(source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
// _currentNoiseTexture = (_currentNoiseTexture + 1) % NoiseTextureCount;
|
||||
//
|
||||
// _volMaterial.SetTexture("_NoiseTex", _noiseTextures[_currentNoiseTexture]);
|
||||
|
||||
// Shader needs this matrix to generate world space rays
|
||||
_volMaterial.SetMatrix("_CamProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
|
||||
|
|
|
|||
|
|
@ -5,19 +5,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using JsonKnownTypes;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using int2 = Unity.Mathematics.int2;
|
||||
|
||||
[MessagePackObject,
|
||||
Union(0, typeof(Ship)),
|
||||
Union(1, typeof(OrbitalEntity)),
|
||||
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<Entity>))]
|
||||
public abstract class Entity
|
||||
{
|
||||
public Zone Zone;
|
||||
|
|
|
|||
|
|
@ -6,53 +6,15 @@ using MessagePack;
|
|||
using RethinkDb.Driver.Ast;
|
||||
using Unity.Mathematics;
|
||||
|
||||
[MessagePackObject]
|
||||
public class EntityPack
|
||||
public static class EntitySerializer
|
||||
{
|
||||
[Key(0)]
|
||||
public string Name;
|
||||
|
||||
[Key(1)]
|
||||
public EquippableItem Hull;
|
||||
|
||||
[Key(2)]
|
||||
public (int2 position, EquippableItem item)[] Equipment;
|
||||
|
||||
[Key(3)]
|
||||
public (int2 position, EquippableItem item)[] CargoBays;
|
||||
|
||||
[Key(4)]
|
||||
public (int2 position, EquippableItem item)[] DockingBays;
|
||||
|
||||
[Key(5)]
|
||||
public Dictionary<int2, PersistentBehaviorData[]> PersistedBehaviors;
|
||||
|
||||
[Key(6)]
|
||||
public float[,] Temperature;
|
||||
|
||||
[Key(7)]
|
||||
public float[,] Armor;
|
||||
|
||||
[Key(8)]
|
||||
public bool2[,] Conductivity;
|
||||
|
||||
[Key(10)]
|
||||
public int[] DockingBayAssignments;
|
||||
|
||||
[Key(11)]
|
||||
public (int2 position, ItemInstance item)[][] CargoContents;
|
||||
|
||||
[Key(12)]
|
||||
public (int2 position, ItemInstance item)[][] DockingBayContents;
|
||||
|
||||
[Key(13)]
|
||||
public EntityPack[] Children;
|
||||
|
||||
private int _price;
|
||||
|
||||
public static EntityPack Pack(Entity entity)
|
||||
{
|
||||
var pack = new EntityPack();
|
||||
EntityPack pack;
|
||||
if (entity is OrbitalEntity orbital)
|
||||
pack = new OrbitalEntityPack {Orbit = orbital.OrbitData};
|
||||
else pack = new ShipPack();
|
||||
|
||||
// Filter item behavior collections by those with any persistent behaviors
|
||||
// For each item create an object containing the item position and a list of persistent behaviors
|
||||
|
|
@ -80,16 +42,27 @@ public class EntityPack
|
|||
return pack;
|
||||
}
|
||||
|
||||
public static Ship Unpack(ItemManager itemManager, Zone zone, EntityPack pack, bool instantiate = false)
|
||||
public static Entity Unpack(ItemManager itemManager, Zone zone, EntityPack pack, bool instantiate = false)
|
||||
{
|
||||
return pack switch
|
||||
{
|
||||
ShipPack shipPack => Unpack(itemManager, zone, shipPack, instantiate),
|
||||
OrbitalEntityPack orbitalEntityPack => Unpack(itemManager, zone, orbitalEntityPack, instantiate),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static Ship Unpack(ItemManager itemManager, Zone zone, ShipPack pack, bool instantiate = false)
|
||||
{
|
||||
var entity = new Ship(itemManager, zone, instantiate ? (EquippableItem) itemManager.Instantiate(pack.Hull) : pack.Hull);
|
||||
Restore(itemManager, zone, pack, entity, instantiate);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static OrbitalEntity Unpack(ItemManager itemManager, Zone zone, EntityPack pack, Guid orbit, bool instantiate = false)
|
||||
public static OrbitalEntity Unpack(ItemManager itemManager, Zone zone, OrbitalEntityPack pack, bool instantiate = false)
|
||||
{
|
||||
var entity = new OrbitalEntity(itemManager, zone, instantiate ? (EquippableItem) itemManager.Instantiate(pack.Hull) : pack.Hull, orbit);
|
||||
var entity = new OrbitalEntity(itemManager, zone, instantiate ? (EquippableItem) itemManager.Instantiate(pack.Hull) : pack.Hull, pack.Orbit);
|
||||
Restore(itemManager, zone, pack, entity, instantiate);
|
||||
return entity;
|
||||
}
|
||||
|
|
@ -144,6 +117,63 @@ public class EntityPack
|
|||
foreach(var v in hullData.Shape.Coordinates)
|
||||
entity.HullConductivity[v.x,v.y] = pack.Conductivity[v.x,v.y];
|
||||
}
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class ShipPack : EntityPack { }
|
||||
|
||||
[MessagePackObject]
|
||||
public class OrbitalEntityPack : EntityPack
|
||||
{
|
||||
[Key(14)]
|
||||
public Guid Orbit;
|
||||
}
|
||||
|
||||
[MessagePackObject,
|
||||
Union(0, typeof(OrbitalEntityPack)),
|
||||
Union(1, typeof(ShipPack))]
|
||||
public class EntityPack
|
||||
{
|
||||
[Key(0)]
|
||||
public string Name;
|
||||
|
||||
[Key(1)]
|
||||
public EquippableItem Hull;
|
||||
|
||||
[Key(2)]
|
||||
public (int2 position, EquippableItem item)[] Equipment;
|
||||
|
||||
[Key(3)]
|
||||
public (int2 position, EquippableItem item)[] CargoBays;
|
||||
|
||||
[Key(4)]
|
||||
public (int2 position, EquippableItem item)[] DockingBays;
|
||||
|
||||
[Key(5)]
|
||||
public Dictionary<int2, PersistentBehaviorData[]> PersistedBehaviors;
|
||||
|
||||
[Key(6)]
|
||||
public float[,] Temperature;
|
||||
|
||||
[Key(7)]
|
||||
public float[,] Armor;
|
||||
|
||||
[Key(8)]
|
||||
public bool2[,] Conductivity;
|
||||
|
||||
[Key(10)]
|
||||
public int[] DockingBayAssignments;
|
||||
|
||||
[Key(11)]
|
||||
public (int2 position, ItemInstance item)[][] CargoContents;
|
||||
|
||||
[Key(12)]
|
||||
public (int2 position, ItemInstance item)[][] DockingBayContents;
|
||||
|
||||
[Key(13)]
|
||||
public EntityPack[] Children;
|
||||
|
||||
private int _price;
|
||||
|
||||
public int Price(ItemManager itemManager)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,12 +30,34 @@ public static class Extensions
|
|||
peer.Send(MessagePackSerializer.Serialize(message as Message), method);
|
||||
}
|
||||
|
||||
// public static float Performance(this EquippableItemData itemData, float temperature)
|
||||
// {
|
||||
// return saturate(itemData.HeatPerformanceCurve.Evaluate(saturate(
|
||||
// (temperature - itemData.MinimumTemperature) /
|
||||
// (itemData.MaximumTemperature - itemData.MinimumTemperature))));
|
||||
// }
|
||||
public static T[] WeightedRandomElements<T>(this IEnumerable<T> collection, ref Random random, Func<T, float> weightFunction, int count)
|
||||
{
|
||||
var weights = new Dictionary<T, float>(collection.Count());
|
||||
var totalWeight = 0f;
|
||||
foreach (var x in collection)
|
||||
{
|
||||
weights[x] = weightFunction(x);
|
||||
totalWeight += weights[x];
|
||||
}
|
||||
|
||||
var elements = new T[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var targetWeight = random.NextFloat(totalWeight);
|
||||
var accumWeight = 0f;
|
||||
foreach (var x in collection)
|
||||
{
|
||||
accumWeight += weights[x];
|
||||
if (accumWeight > targetWeight)
|
||||
{
|
||||
elements[i] = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
// Thanks, https://stackoverflow.com/a/48599119
|
||||
public static bool ByteArrayCompare(ReadOnlySpan<byte> a1, ReadOnlySpan<byte> a2)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class Zone
|
|||
|
||||
private HashSet<Guid> _updatedOrbits = new HashSet<Guid>();
|
||||
|
||||
private ItemManager _itemManager;
|
||||
private float _time;
|
||||
private Random _random;
|
||||
public List<Agent> Agents = new List<Agent>();
|
||||
|
|
@ -36,8 +37,9 @@ public class Zone
|
|||
public ZoneData Data { get; }
|
||||
private List<Task> BeltUpdates = new List<Task>();
|
||||
|
||||
public Zone(PlanetSettings settings, ZonePack pack)
|
||||
public Zone(ItemManager itemManager, PlanetSettings settings, ZonePack pack)
|
||||
{
|
||||
_itemManager = itemManager;
|
||||
Data = pack.Data;
|
||||
Settings = settings;
|
||||
_random = new Random(Convert.ToUInt32(abs(Data.ID.GetHashCode())));
|
||||
|
|
@ -63,8 +65,11 @@ public class Zone
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var entity in pack.Entities) Entities.Add(entity);
|
||||
|
||||
foreach (var entity in pack.Entities)
|
||||
{
|
||||
Entities.Add(EntitySerializer.Unpack(_itemManager, this, entity));
|
||||
}
|
||||
|
||||
// TODO: Associate planets with stored entities for planetary colonies
|
||||
}
|
||||
|
|
@ -74,7 +79,7 @@ public class Zone
|
|||
return new ZonePack
|
||||
{
|
||||
Data = Data,
|
||||
//Entities = Entities.ToList(),
|
||||
Entities = Entities.Select(EntitySerializer.Pack).ToList(),
|
||||
Orbits = Orbits.Values.Select(o=>o.Data).ToList(),
|
||||
Planets = Planets.Values.ToList()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class ZonePack : INamedEntry
|
|||
public List<OrbitData> Orbits = new List<OrbitData>();
|
||||
|
||||
[JsonProperty("entities"), Key(3)]
|
||||
public List<Entity> Entities = new List<Entity>();
|
||||
public List<EntityPack> Entities = new List<EntityPack>();
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
|
|||
ContextMenu.AddOption("Save Loadout",
|
||||
() =>
|
||||
{
|
||||
GameManager.SaveLoadout(EntityPack.Pack(_displayedEntity));
|
||||
GameManager.SaveLoadout(EntitySerializer.Pack(_displayedEntity));
|
||||
});
|
||||
|
||||
if (GameManager.Loadouts.Any())
|
||||
|
|
@ -155,13 +155,16 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
|
|||
(
|
||||
$"{pack.Name} - {pack.Price(GameManager.ItemManager):n0}", () =>
|
||||
{
|
||||
var ship = EntityPack.Unpack(GameManager.ItemManager, GameManager.Zone, pack, true);
|
||||
ship.SetParent(GameManager.DockedEntity);
|
||||
GameManager.PlayerEntities.Add(ship);
|
||||
var entity = EntitySerializer.Unpack(GameManager.ItemManager, GameManager.Zone, pack, true);
|
||||
entity.SetParent(GameManager.DockedEntity);
|
||||
GameManager.PlayerEntities.Add(entity);
|
||||
GameManager.Credits -= pack.Price(GameManager.ItemManager);
|
||||
GameManager.CurrentEntity = ship;
|
||||
GameManager.DockingBay.DockedShip = ship;
|
||||
Display(ship);
|
||||
GameManager.CurrentEntity = entity;
|
||||
if(entity is Ship ship)
|
||||
{
|
||||
GameManager.DockingBay.DockedShip = ship;
|
||||
}
|
||||
Display(entity);
|
||||
}, pack.Price(GameManager.ItemManager) < GameManager.Credits
|
||||
)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,18 +20,24 @@ public class SectorMap : MonoBehaviour
|
|||
public Prototype ZonePrototype;
|
||||
public Prototype LinkPrototype;
|
||||
public Prototype IconPrototype;
|
||||
public Material ZonePrimaryMaterial;
|
||||
public Material ZoneSecondaryMaterial;
|
||||
public Material ZoneLinkMaterial;
|
||||
public float MegaPrimaryBoost = .75f;
|
||||
public float MegaSecondaryBoost = 2f;
|
||||
public float MegaLinkBoost = 2f;
|
||||
public Texture2D EntranceIcon;
|
||||
public Texture2D ExitIcon;
|
||||
public Texture2D BossIcon;
|
||||
public Texture2D HomeIcon;
|
||||
public Prototype LegendPrototype;
|
||||
public float IconDistance = 1;
|
||||
public float MegaColorBoost = 2.5f;
|
||||
public int ZoneCount = 64;
|
||||
public float LinkDensity = .5f;
|
||||
public float LabelDistance = .4f;
|
||||
|
||||
private RenderTexture[] _influenceTextures;
|
||||
private Dictionary<MegaCorporation, (RenderTexture influence, Material primaryMaterial, Material secondaryMaterial, Material linkMaterial)> _factionMaterials =
|
||||
new Dictionary<MegaCorporation, (RenderTexture influence, Material primaryMaterial, Material secondaryMaterial, Material linkMaterial)>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
|
@ -45,6 +51,13 @@ public class SectorMap : MonoBehaviour
|
|||
var sectorMegas = megas.OrderBy(x => Random.value).Take(Settings.MegaCount).ToArray();
|
||||
foreach (var mega in sectorMegas)
|
||||
{
|
||||
var primary = Instantiate(ZonePrimaryMaterial);
|
||||
primary.SetColor("_TintColor", (mega.PrimaryColor * MegaPrimaryBoost).ToColor());
|
||||
var secondary = Instantiate(ZoneSecondaryMaterial);
|
||||
secondary.SetColor("_TintColor", (mega.SecondaryColor * MegaSecondaryBoost).ToColor());
|
||||
var link = Instantiate(ZoneLinkMaterial);
|
||||
link.SetColor("_TintColor", (mega.PrimaryColor * MegaLinkBoost).ToColor());
|
||||
_factionMaterials.Add(mega, (new RenderTexture(1024, 1024, 1, RenderTextureFormat.RHalf), primary, secondary, link));
|
||||
mega.NameGenerator = new MarkovNameGenerator(ref random, UnityHelpers.LoadAsset<TextAsset>(mega.GeonameFile).text, Settings);
|
||||
var legendElement = LegendPrototype.Instantiate<LegendElement>();
|
||||
legendElement.Primary.color = mega.PrimaryColor.ToColor();
|
||||
|
|
@ -56,6 +69,7 @@ public class SectorMap : MonoBehaviour
|
|||
var sector = SectorGenerator.GenerateSector(Settings, sectorMegas, ref random);
|
||||
var visitedZones = new HashSet<SectorZone>();
|
||||
Debug.Log($"Found {sector.Zones.Count(z=>!z.AdjacentZones.Any())} orphaned zones!");
|
||||
|
||||
var zoneInstances = new Dictionary<SectorZone, SectorZoneUI>();
|
||||
foreach (var zone in sector.Zones)
|
||||
{
|
||||
|
|
@ -64,7 +78,10 @@ public class SectorMap : MonoBehaviour
|
|||
var zoneInstanceTransform = zoneInstance.transform;
|
||||
zoneInstanceTransform.localPosition = new Vector3(zone.Position.x, zone.Position.y);
|
||||
if(zone.Owner != null)
|
||||
zoneInstance.Background.material.SetColor("_TintColor", zone.Owner.PrimaryColor.ToColor() * MegaColorBoost);
|
||||
{
|
||||
zoneInstance.Primary.sharedMaterial = _factionMaterials[zone.Owner].primaryMaterial;
|
||||
zoneInstance.Secondary.sharedMaterial = _factionMaterials[zone.Owner].secondaryMaterial;
|
||||
}
|
||||
//zoneInstance.Background.transform.localScale = Vector3.one * (sector.HomeZones.Values.Any(os=>os==zone) ? 4 : 2);
|
||||
var linkDirection = float2.zero;
|
||||
foreach (var link in zone.AdjacentZones)
|
||||
|
|
@ -76,10 +93,8 @@ public class SectorMap : MonoBehaviour
|
|||
var pos = (zone.Position + link.Position) / 2;
|
||||
linkInstance.localPosition = new Vector3(pos.x, pos.y);
|
||||
if (zone.Owner != null && zone.Owner == link.Owner)
|
||||
{
|
||||
linkInstance.GetComponent<MeshRenderer>().material.SetColor("_TintColor", zone.Owner.PrimaryColor.ToColor());
|
||||
}
|
||||
|
||||
linkInstance.GetComponent<MeshRenderer>().sharedMaterial = _factionMaterials[zone.Owner].linkMaterial;
|
||||
|
||||
var localScale = linkInstance.localScale;
|
||||
localScale = new Vector3(length(zone.Position - link.Position), localScale.y, localScale.z);
|
||||
linkInstance.localScale = localScale;
|
||||
|
|
@ -145,10 +160,8 @@ public class SectorMap : MonoBehaviour
|
|||
}
|
||||
|
||||
// Render Influence Textures
|
||||
_influenceTextures = new RenderTexture[sectorMegas.Length];
|
||||
for (var i = 0; i < sectorMegas.Length; i++)
|
||||
foreach (var mega in sectorMegas)
|
||||
{
|
||||
_influenceTextures[i] = new RenderTexture(1024, 1024, 1, RenderTextureFormat.RHalf);
|
||||
var influenceRenderer = InfluenceRendererPrototype.Instantiate<MeshRenderer>();
|
||||
foreach (var zone in sector.Zones)
|
||||
{
|
||||
|
|
@ -156,10 +169,10 @@ public class SectorMap : MonoBehaviour
|
|||
var influence = 0f;
|
||||
if (zone.Megas.Length > 0)
|
||||
{
|
||||
if (zone.Megas.Contains(sectorMegas[i]))
|
||||
if (zone.Megas.Contains(mega))
|
||||
{
|
||||
influence = 10;
|
||||
if (zone.Owner != sectorMegas[i])
|
||||
if (zone.Owner != mega)
|
||||
influence *= .5f;
|
||||
}
|
||||
else influence = -10;
|
||||
|
|
@ -167,12 +180,12 @@ public class SectorMap : MonoBehaviour
|
|||
instance.Influence.material.SetFloat("_Depth", influence);
|
||||
}
|
||||
|
||||
InfluenceCamera.targetTexture = _influenceTextures[i];
|
||||
InfluenceCamera.targetTexture = _factionMaterials[mega].influence;
|
||||
InfluenceCamera.Render();
|
||||
|
||||
influenceRenderer.material.mainTexture = _influenceTextures[i];
|
||||
influenceRenderer.material.SetColor("_Color1", sectorMegas[i].PrimaryColor.ToColor());
|
||||
influenceRenderer.material.SetColor("_Color2", sectorMegas[i].SecondaryColor.ToColor());
|
||||
influenceRenderer.material.mainTexture = _factionMaterials[mega].influence;
|
||||
influenceRenderer.material.SetColor("_Color1", mega.PrimaryColor.ToColor());
|
||||
influenceRenderer.material.SetColor("_Color2", mega.SecondaryColor.ToColor());
|
||||
influenceRenderer.material.SetFloat("_FillTilt", random.NextFloat(PI));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ using UnityEngine.UI;
|
|||
|
||||
public class SectorZoneUI : MonoBehaviour
|
||||
{
|
||||
public MeshRenderer Background;
|
||||
public MeshRenderer Primary;
|
||||
public MeshRenderer Secondary;
|
||||
public MeshRenderer Influence;
|
||||
public TextMeshPro Label;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue