Hostility Fix + Story Work

Fixed various bugs caused by triggering wormhole animation multiple times
Sector -> Galaxy
Fixed bug in hostility system; deserialized entities' PresencePermitted was silently throwing an exception (due to Faction being null during initialization) and thus never updating in response to security level changes
Worked a bit on story processing
This commit is contained in:
Reinier Vens 2021-05-14 03:03:28 +01:00
commit 2f98904614
26 changed files with 301 additions and 255 deletions

BIN
Asset Sources/Alakrita1.blend (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View file

@ -15960,12 +15960,12 @@ MonoBehaviour:
Credits: 100000000
TargetSpottedBlinkFrequency: 20
TargetSpottedBlinkOffset: -0.25
DeathPPTransitionTime: 1
DeathPP: {fileID: 803284856}
HeatstrokePP: {fileID: 1404901906}
HypothermiaPP: {fileID: 1800086610}
SevereHeatstrokePP: {fileID: 837424435}
SevereHypothermiaPP: {fileID: 694183021}
DeathPostTransitionTime: 1
DeathPost: {fileID: 803284856}
HeatstrokePost: {fileID: 1404901906}
HypothermiaPost: {fileID: 1800086610}
SevereHeatstrokePost: {fileID: 837424435}
SevereHypothermiaPost: {fileID: 694183021}
UiRoot: {fileID: 761574177}
HelpScreen: {fileID: 1210651002}
InputDisplayLayout: {fileID: 1088218870}
@ -16151,8 +16151,6 @@ MonoBehaviour:
CompassIconPrototype: {fileID: 336445422}
OrbitalIcon: {fileID: 21300000, guid: 97bce58bfe43bfa40870ca062cfb7ec1, type: 3}
WormholeIcon: {fileID: 21300000, guid: 6d0b27330fdcc8347b1e09a2d17a0673, type: 3}
PlanetoidIcon: {fileID: 2800000, guid: 823d8a1c4e071994087624c39f62b319, type: 3}
PlanetIcon: {fileID: 2800000, guid: 0d2acbd593b7fd349b0b26b4844733ef, type: 3}
--- !u!114 &1009503735
MonoBehaviour:
m_ObjectHideFlags: 0

View file

@ -121,7 +121,7 @@ public class ActionGameManager : MonoBehaviour
return settings;
}
public static Sector CurrentSector;
public static Galaxy CurrentGalaxy;
public static bool IsTutorial;
public GameSettings Settings;
@ -132,12 +132,12 @@ public class ActionGameManager : MonoBehaviour
public float TargetSpottedBlinkOffset = -.25f;
[Header("Postprocessing")]
public float DeathPPTransitionTime;
public PostProcessVolume DeathPP;
public PostProcessVolume HeatstrokePP;
public PostProcessVolume HypothermiaPP;
public PostProcessVolume SevereHeatstrokePP;
public PostProcessVolume SevereHypothermiaPP;
public float DeathPostTransitionTime;
public PostProcessVolume DeathPost;
public PostProcessVolume HeatstrokePost;
public PostProcessVolume HypothermiaPost;
public PostProcessVolume SevereHeatstrokePost;
public PostProcessVolume SevereHypothermiaPost;
[Header("Scene Links")]
public GameObject UiRoot;
@ -262,7 +262,7 @@ public class ActionGameManager : MonoBehaviour
public void SaveState()
{
PlayerSettings.SavedRun = CurrentSector == null ? null : new SavedGame(CurrentSector, Zone, DockedEntity ?? CurrentEntity);
PlayerSettings.SavedRun = CurrentGalaxy == null ? null : new SavedGame(CurrentGalaxy, Zone, DockedEntity ?? CurrentEntity);
if(PlayerSettings.SavedRun != null)
{
PlayerSettings.SavedRun.IsTutorial = IsTutorial;
@ -499,9 +499,9 @@ public class ActionGameManager : MonoBehaviour
ConsoleController.AddCommand("revealzones",
_ =>
{
foreach (var zones in CurrentSector.Zones
.Where(z=>!CurrentSector.DiscoveredZones.Contains(z))
.GroupBy(z=>z.Distance[CurrentSector.Entrance])
foreach (var zones in CurrentGalaxy.Zones
.Where(z=>!CurrentGalaxy.DiscoveredZones.Contains(z))
.GroupBy(z=>z.Distance[CurrentGalaxy.Entrance])
.OrderBy(g=>g.Key))
{
SectorMap.QueueZoneReveal(zones);
@ -541,13 +541,13 @@ public class ActionGameManager : MonoBehaviour
ConsoleController.AddCommand("spawnturret",
_ =>
{
var nearestFaction = CurrentSector.Factions.MinBy(f => CurrentSector.HomeZones[f].Distance[Zone.SectorZone]);
var nearestFaction = CurrentGalaxy.Factions.MinBy(f => CurrentGalaxy.HomeZones[f].Distance[Zone.GalaxyZone]);
var loadoutGenerator = IsTutorial ? new LoadoutGenerator(
ref ItemManager.Random,
ItemManager,
CurrentSector,
Zone.SectorZone,
CurrentGalaxy,
Zone.GalaxyZone,
nearestFaction,
.5f) : new LoadoutGenerator(
ref ItemManager.Random,
@ -644,7 +644,7 @@ public class ActionGameManager : MonoBehaviour
private void EnterWormhole(Wormhole wormhole)
{
if (!(CurrentEntity is Ship ship)) return;
if (!(CurrentEntity is Ship ship) || ship.WormholeAnimationInProgress) return;
// var wormholeCameraFollow = new GameObject("Wormhole Camera Follow").transform;
// wormholeCameraFollow.position = new Vector3(wormhole.Position.x, -50, wormhole.Position.y);
// wormholeCameraFollow.rotation = Quaternion.LookRotation(Vector3.down, ship.LookDirection);
@ -657,31 +657,31 @@ public class ActionGameManager : MonoBehaviour
var oldZone = Zone;
PopulateLevel(wormhole.Target);
foreach (var zone in wormhole.Target.AdjacentZones)
CurrentSector.DiscoveredZones.Add(zone);
CurrentGalaxy.DiscoveredZones.Add(zone);
SectorMap.QueueZoneReveal(wormhole.Target.AdjacentZones);
ship.ExitWormhole(ZoneRenderer.WormholeInstances.Keys.First(w => w.Target == oldZone.SectorZone).Position,
ship.ExitWormhole(ZoneRenderer.WormholeInstances.Keys.First(w => w.Target == oldZone.GalaxyZone).Position,
Settings.GameplaySettings.WormholeExitVelocity * ItemManager.Random.NextFloat2Direction());
CurrentEntity.Zone = Zone;
SaveState();
};
}
public void PopulateLevel(SectorZone sectorZone)
public void PopulateLevel(GalaxyZone galaxyZone)
{
if (sectorZone == null) throw new ArgumentNullException(nameof(sectorZone));
if (galaxyZone == null) throw new ArgumentNullException(nameof(galaxyZone));
if (sectorZone.Contents == null)
if (galaxyZone.Contents == null)
{
sectorZone.PackedContents ??= ZoneGenerator.GenerateZone(
galaxyZone.PackedContents ??= ZoneGenerator.GenerateZone(
ItemManager,
Settings.ZoneSettings,
CurrentSector,
sectorZone,
CurrentGalaxy,
galaxyZone,
IsTutorial
);
sectorZone.Contents = new Zone(ItemManager, Settings.PlanetSettings, sectorZone.PackedContents, sectorZone, CurrentSector);
galaxyZone.Contents = new Zone(ItemManager, Settings.PlanetSettings, galaxyZone.PackedContents, galaxyZone, CurrentGalaxy);
}
Zone = sectorZone.Contents;
Zone = galaxyZone.Contents;
PlayMusic(MusicType.Overworld);
Zone.Log = s => Debug.Log($"Zone: {s}");
@ -756,14 +756,14 @@ public class ActionGameManager : MonoBehaviour
private void StartGame()
{
if (CurrentSector != null)
if (CurrentGalaxy != null)
{
if (PlayerSettings.SavedRun == null)
{
SectorMap.QueueZoneReveal(CurrentSector.Entrance.AdjacentZones.Prepend(CurrentSector.Entrance));
PopulateLevel(CurrentSector.Entrance);
SectorMap.QueueZoneReveal(CurrentGalaxy.Entrance.AdjacentZones.Prepend(CurrentGalaxy.Entrance));
PopulateLevel(CurrentGalaxy.Entrance);
var loadoutGenerator = IsTutorial ? new LoadoutGenerator(ref ItemManager.Random, ItemManager, null, 2) :
new LoadoutGenerator(ref ItemManager.Random, ItemManager, CurrentSector, Zone.SectorZone, null, 2);
new LoadoutGenerator(ref ItemManager.Random, ItemManager, CurrentGalaxy, Zone.GalaxyZone, null, 2);
var ship = EntitySerializer.Unpack(
ItemManager,
Zone,
@ -779,10 +779,10 @@ public class ActionGameManager : MonoBehaviour
}
else
{
foreach(var group in CurrentSector.DiscoveredZones
.GroupBy(dz=>dz.Distance[CurrentSector.Entrance]))
foreach(var group in CurrentGalaxy.DiscoveredZones
.GroupBy(dz=>dz.Distance[CurrentGalaxy.Entrance]))
SectorMap.QueueZoneReveal(group);
PopulateLevel(CurrentSector.Zones[PlayerSettings.SavedRun.CurrentZone]);
PopulateLevel(CurrentGalaxy.Zones[PlayerSettings.SavedRun.CurrentZone]);
var targetEntity = Zone.Entities[PlayerSettings.SavedRun.CurrentZoneEntity];
if (targetEntity is OrbitalEntity orbitalEntity)
{
@ -944,7 +944,7 @@ public class ActionGameManager : MonoBehaviour
}
CurrentEntity = entity;
DeathPP.weight = 0;
DeathPost.weight = 0;
ZoneRenderer.PerspectiveEntity = CurrentEntity;
Menu.gameObject.SetActive(false);
@ -1090,32 +1090,32 @@ public class ActionGameManager : MonoBehaviour
VolumeRenderer.EnableDepth = false;
MainMenu.gameObject.SetActive(true);
Menu.gameObject.SetActive(false);
CurrentSector = null;
CurrentGalaxy = null;
SavePlayerSettings();
Observable.EveryUpdate()
.Where(_ => Time.time - deathTime < DeathPPTransitionTime)
.Where(_ => Time.time - deathTime < DeathPostTransitionTime)
.Subscribe(_ =>
{
var t = (Time.time - deathTime) / DeathPPTransitionTime;
var t = (Time.time - deathTime) / DeathPostTransitionTime;
if(cause==CauseOfDeath.Heatstroke)
{
HeatstrokePP.weight = 1 - t;
SevereHeatstrokePP.weight = 1 - t;
HeatstrokePost.weight = 1 - t;
SevereHeatstrokePost.weight = 1 - t;
}
else if (cause == CauseOfDeath.Hypothermia)
{
HypothermiaPP.weight = 1 - t;
SevereHypothermiaPP.weight = 1 - t;
HypothermiaPost.weight = 1 - t;
SevereHypothermiaPost.weight = 1 - t;
}
DeathPP.weight = t;
DeathPost.weight = t;
},
() =>
{
HeatstrokePP.weight = 0;
SevereHeatstrokePP.weight = 0;
HypothermiaPP.weight = 0;
SevereHypothermiaPP.weight = 0;
DeathPP.weight = 1;
HeatstrokePost.weight = 0;
SevereHeatstrokePost.weight = 0;
HypothermiaPost.weight = 0;
SevereHypothermiaPost.weight = 0;
DeathPost.weight = 1;
});
}
@ -1155,9 +1155,9 @@ public class ActionGameManager : MonoBehaviour
{
var soundbank = type switch
{
MusicType.Overworld => Zone.SectorZone.Owner?.OverworldMusic ?? 0,
MusicType.Combat => Zone.SectorZone.Owner?.CombatMusic ?? 0,
MusicType.Boss => Zone.SectorZone.Owner?.BossMusic ?? 0,
MusicType.Overworld => Zone.GalaxyZone.Owner?.OverworldMusic ?? 0,
MusicType.Combat => Zone.GalaxyZone.Owner?.CombatMusic ?? 0,
MusicType.Boss => Zone.GalaxyZone.Owner?.BossMusic ?? 0,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
if (soundbank == 0)
@ -1213,9 +1213,9 @@ public class ActionGameManager : MonoBehaviour
_entityYawPitch = float2(_entityYawPitch.x + look.x * Sensitivity.x, clamp(_entityYawPitch.y + look.y * Sensitivity.y, -.45f * PI, .45f * PI));
_viewDirection = mul(float3(0, 0, 1), Unity.Mathematics.float3x3.Euler(float3(_entityYawPitch.yx, 0), RotationOrder.YXZ));
CurrentEntity.LookDirection = _viewDirection;
HeatstrokePP.weight = saturate(unlerp(0, Settings.GameplaySettings.SevereHeatstrokeRiskThreshold, CurrentEntity.Heatstroke));
HeatstrokePost.weight = saturate(unlerp(0, Settings.GameplaySettings.SevereHeatstrokeRiskThreshold, CurrentEntity.Heatstroke));
var severeHeatstrokeLerp = saturate(unlerp(Settings.GameplaySettings.SevereHeatstrokeRiskThreshold, 1, CurrentEntity.Heatstroke));
SevereHeatstrokePP.weight =
SevereHeatstrokePost.weight =
severeHeatstrokeLerp + severeHeatstrokeLerp * (1 - severeHeatstrokeLerp) *
max(Settings.HeatstrokePhasingFloor, sin(Time.time * Settings.HeatstrokePhasingFrequency));

View file

@ -146,6 +146,15 @@ public abstract class Entity
//ItemManager.Log($"Entity {Name} is activating!");
_active = true;
Heatstroke = 0;
// The entity's presence is permitted when its faction owns the zone, or the current security level at its location is low enough
PresencePermitted = new ReadOnlyReactiveProperty<bool>(CurrentSecurityLevel.Select(security =>
{
var factionRelationship = GetFactionRelationship(Zone.GalaxyZone.Owner);
var presencePermitted = IsPresencePermitted(factionRelationship, security);
return presencePermitted;
}), initialValue: true);
foreach (var item in Equipment)
foreach (var behavior in item.Behaviors)
{
@ -269,9 +278,7 @@ public abstract class Entity
.Merge(HypothermiaDeath.Select(_ => CauseOfDeath.Hypothermia))
.Merge(ItemDestroyed.Where(i=>i.GetBehavior<Cockpit>()!=null).Select(_ => CauseOfDeath.CockpitDestroyed));
// The entity's presence is permitted when its faction owns the zone, or the current security level at its location is low enough
PresencePermitted = new ReadOnlyReactiveProperty<bool>(CurrentSecurityLevel.Select(security =>
IsPresencePermitted(GetFactionRelationship(Zone.SectorZone.Owner), security)), true);
//CurrentSecurityLevel.Value = SecurityLevel.Open;
}
public bool IsHostileTo(Entity other, bool recursive = false)
@ -281,8 +288,8 @@ public abstract class Entity
// TODO: Inter-faction hostility
// When the entity faction owns the zone, they are hostile to trespassers or those hostile to them
if (Faction.ID == Zone.SectorZone.Owner.ID)
return recursive ? !other.PresencePermitted.Value : !other.PresencePermitted.Value || other.IsHostileTo(this, true);
if (Faction.ID == Zone.GalaxyZone.Owner.ID)
return recursive ? !(other.PresencePermitted?.Value ?? true) : !(other.PresencePermitted?.Value ?? true)|| other.IsHostileTo(this, true);
return !recursive && other.IsHostileTo(this, true);
}
@ -293,7 +300,7 @@ public abstract class Entity
if (faction == null)
return FactionRelationship.Neutral;
if (this is Ship {IsPlayerShip: true})
return Zone.Sector.FactionRelationships[faction];
return Zone.Galaxy.FactionRelationships[faction];
return faction.ID == Faction.ID ? FactionRelationship.Beloved : FactionRelationship.Neutral;
}

View file

@ -165,6 +165,12 @@ public enum CompoundCommodityCategory
Assemblies = 5
}
public enum LocationType
{
Station,
Planet
}
public enum FactionRelationship
{
Hated = 0, // Kill on sight

View file

@ -5,6 +5,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DataStructures.ViliWonka.Heap;
using Ink.Runtime;
using MIConvexHull;
using JM.LinqFaster;
using UniRx;
@ -12,25 +13,25 @@ using Unity.Mathematics;
using static Unity.Mathematics.math;
using Random = Unity.Mathematics.Random;
public class Sector
public class Galaxy
{
public Dictionary<Faction, SectorZone> HomeZones = new Dictionary<Faction, SectorZone>();
public Dictionary<Faction, SectorZone> BossZones = new Dictionary<Faction, SectorZone>();
public HashSet<SectorZone> DiscoveredZones = new HashSet<SectorZone>();
public Dictionary<Faction, GalaxyZone> HomeZones = new Dictionary<Faction, GalaxyZone>();
public Dictionary<Faction, GalaxyZone> BossZones = new Dictionary<Faction, GalaxyZone>();
public HashSet<GalaxyZone> DiscoveredZones = new HashSet<GalaxyZone>();
public SectorBackgroundSettings Background { get; }
public NameGeneratorSettings NameGeneratorSettings { get; }
public Faction[] Factions { get; }
public SectorZone[] Zones { get; }
public SectorZone Entrance { get; }
public SectorZone Exit { get; }
public GalaxyZone[] Zones { get; }
public GalaxyZone Entrance { get; }
public GalaxyZone Exit { get; }
public Dictionary<Faction, FactionRelationship> FactionRelationships { get; } = new Dictionary<Faction, FactionRelationship>();
private HashSet<Guid> _containedFactions;
private SectorZone[] _exitPath;
private GalaxyZone[] _exitPath;
private Dictionary<Faction, MarkovNameGenerator> _nameGenerators = new Dictionary<Faction, MarkovNameGenerator>();
public SectorZone[] ExitPath
public GalaxyZone[] ExitPath
{
get
{
@ -40,7 +41,7 @@ public class Sector
}
}
public Sector(CultCache cultCache, SavedGame savedGame)
public Galaxy(CultCache cultCache, SavedGame savedGame)
{
Background = savedGame.Background;
@ -52,7 +53,7 @@ public class Sector
Zones = savedGame.Zones.Select(zone =>
{
return new SectorZone
return new GalaxyZone
{
Name = zone.Name,
Position = zone.Position,
@ -82,7 +83,7 @@ public class Sector
CalculateDistanceMatrix();
}
public Sector(
public Galaxy(
SectorGenerationSettings settings,
SectorBackgroundSettings background,
NameGeneratorSettings nameGeneratorSettings,
@ -121,7 +122,7 @@ public class Sector
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
}
public Sector(
public Galaxy(
TutorialGenerationSettings settings,
SectorBackgroundSettings background,
NameGeneratorSettings nameGeneratorSettings,
@ -229,14 +230,14 @@ public class Sector
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
}
private SectorZone[] GenerateZones(int zoneCount, ref Random random, Action<string> progressCallback = null)
private GalaxyZone[] GenerateZones(int zoneCount, ref Random random, Action<string> progressCallback = null)
{
var outputSamples = WeightedSampleElimination.GeneratePoints(zoneCount,
ref random,
Background.CloudDensity,
v => (.2f - lengthsq(v - float2(.5f))) * 4,
progressCallback);
return outputSamples.Select(v => new SectorZone {Position = v}).ToArray();
return outputSamples.Select(v => new GalaxyZone {Position = v}).ToArray();
}
private void PlaceFactionsMain(int bossCount, Action<string> progressCallback = null)
@ -343,9 +344,9 @@ public class Sector
if (progressCallback != null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
// Create a delaunay triangulation to connect adjacent sectors
var triangulation = DelaunayTriangulation<Vertex2<SectorZone>, Cell2<SectorZone>>
.Create(Zones.Select(z => new Vertex2<SectorZone>(z.Position, z)).ToList(), 1e-7f);
var links = new HashSet<(SectorZone, SectorZone)>();
var triangulation = DelaunayTriangulation<Vertex2<GalaxyZone>, Cell2<GalaxyZone>>
.Create(Zones.Select(z => new Vertex2<GalaxyZone>(z.Position, z)).ToList(), 1e-7f);
var links = new HashSet<(GalaxyZone, GalaxyZone)>();
foreach (var cell in triangulation.Cells)
{
if (!links.Contains((cell.Vertices[0].StoredObject, cell.Vertices[1].StoredObject)) &&
@ -377,14 +378,14 @@ public class Sector
link.Item2.AdjacentZones.Add(link.Item1);
}
float LinkWeight((SectorZone, SectorZone) link)
float LinkWeight((GalaxyZone, GalaxyZone) link)
{
return 1 / saturate(Background.CloudDensity((link.Item1.Position + link.Item2.Position) / 2)) *
lengthsq(link.Item1.Position - link.Item2.Position) *
(link.Item1.AdjacentZones.Count - 1) * (link.Item2.AdjacentZones.Count - 1);
}
var heap = new MaxHeap<(SectorZone, SectorZone)>(links.Count);
var heap = new MaxHeap<(GalaxyZone, GalaxyZone)>(links.Count);
foreach (var link in links) heap.PushObj(link, LinkWeight(link));
while (heap.Count > linkDensity * links.Count)
{
@ -430,12 +431,12 @@ public class Sector
{
public float Cost;
public DijkstraVertex Parent;
public SectorZone Zone;
public GalaxyZone Zone;
}
public Dictionary<SectorZone, int> ConnectedRegionDistance(SectorZone v)
public Dictionary<GalaxyZone, int> ConnectedRegionDistance(GalaxyZone v)
{
var members = new Dictionary<SectorZone, int> {{v, 0}};
var members = new Dictionary<GalaxyZone, int> {{v, 0}};
int cost = 1;
while (true)
{
@ -455,36 +456,36 @@ public class Sector
}
}
public HashSet<SectorZone> ConnectedRegion(
SectorZone v,
SectorZone ignoreLinkSource,
SectorZone ignoreLinkTarget,
public HashSet<GalaxyZone> ConnectedRegion(
GalaxyZone v,
GalaxyZone ignoreLinkSource,
GalaxyZone ignoreLinkTarget,
int maxDistance = int.MaxValue)
{
return ConnectedRegion(v, x => x.Item1 != ignoreLinkSource || x.Item2 != ignoreLinkTarget, maxDistance);
}
public HashSet<SectorZone> ConnectedRegion(
SectorZone v,
SectorZone ignoreZone,
public HashSet<GalaxyZone> ConnectedRegion(
GalaxyZone v,
GalaxyZone ignoreZone,
int maxDistance = int.MaxValue)
{
return ConnectedRegion(v, x => x.Item2 != ignoreZone, maxDistance);
}
public HashSet<SectorZone> ConnectedRegion(
SectorZone v,
public HashSet<GalaxyZone> ConnectedRegion(
GalaxyZone v,
int maxDistance = int.MaxValue)
{
return ConnectedRegion(v, x => true, maxDistance);
}
public HashSet<SectorZone> ConnectedRegion(
SectorZone v,
Predicate<(SectorZone source, SectorZone target)> linkFilter,
public HashSet<GalaxyZone> ConnectedRegion(
GalaxyZone v,
Predicate<(GalaxyZone source, GalaxyZone target)> linkFilter,
int maxDistance = int.MaxValue)
{
var visited = new HashSet<SectorZone> {v};
var visited = new HashSet<GalaxyZone> {v};
int cost = 1;
while (true)
{
@ -504,12 +505,12 @@ public class Sector
}
}
public SectorZone[] FindPath(SectorZone source, SectorZone target, bool bestFirst = false)
public GalaxyZone[] FindPath(GalaxyZone source, GalaxyZone target, bool bestFirst = false)
{
MinHeap<DijkstraVertex> unsearchedNodes = new MinHeap<DijkstraVertex>();
unsearchedNodes.PushObj(new DijkstraVertex{Zone = source}, 0);
//SortedList<float,DijkstraVertex> members = new SortedList<float,DijkstraVertex>{{0, new DijkstraVertex{Zone = source}}};
var searched = new HashSet<SectorZone>();
var searched = new HashSet<GalaxyZone>();
while (true)
{
if(unsearchedNodes.Count == 0) return null; // No nodes left unsearched
@ -523,7 +524,7 @@ public class Sector
return path.Select(dv => dv.Zone).ToArray();
}
// For each adjacent star (filter already visited stars unless heuristic is in use)
IEnumerable<SectorZone> zonesToSearch = s.Zone.AdjacentZones;
IEnumerable<GalaxyZone> zonesToSearch = s.Zone.AdjacentZones;
if (!bestFirst) zonesToSearch = zonesToSearch.Where(z => !searched.Contains(z));
foreach (var dijkstraStar in zonesToSearch
// Cost is parent cost plus distance squared
@ -535,15 +536,33 @@ public class Sector
}
}
public class SectorZone
public class GalaxyZone
{
public string Name;
public float2 Position;
public List<SectorZone> AdjacentZones = new List<SectorZone>();
public List<GalaxyZone> AdjacentZones = new List<GalaxyZone>();
public int Isolation;
public Dictionary<SectorZone, int> Distance;
public Dictionary<GalaxyZone, int> Distance;
public Faction[] Factions;
public Faction Owner;
public Zone Contents;
public ZonePack PackedContents;
public bool NamedZone;
public List<LocationStory> Locations = new List<LocationStory>();
}
public class GalaxyQuest
{
public Story Story;
public Dictionary<string, LocationStory> Locations = new Dictionary<string, LocationStory>();
}
public class LocationStory
{
public string FileName;
public string Name;
public Story Story;
public Faction Faction;
public SecurityLevel Security;
public LocationType Type;
}

View file

@ -10,22 +10,22 @@ public class LoadoutGenerator
{
public Random Random;
public ItemManager ItemManager { get; }
public Sector Sector { get; }
public SectorZone Zone { get; }
public Galaxy Galaxy { get; }
public GalaxyZone Zone { get; }
public Faction Faction { get; }
public float PriceExponent { get; }
public LoadoutGenerator(
ref Random random,
ItemManager itemManager,
Sector sector,
SectorZone zone,
Galaxy galaxy,
GalaxyZone zone,
Faction faction,
float priceExponent)
{
Random = random;
ItemManager = itemManager;
Sector = sector;
Galaxy = galaxy;
Zone = zone;
Faction = faction;
PriceExponent = priceExponent;
@ -107,12 +107,12 @@ public class LoadoutGenerator
(hullFilter?.Invoke(item) ?? true) &&
item.HullType == type &&
item.Manufacturer != Guid.Empty &&
(Sector?.ContainsFaction(item.Manufacturer) ?? true) &&
(Galaxy?.ContainsFaction(item.Manufacturer) ?? true) &&
(Faction == null || item.Manufacturer == Faction.ID || Faction.Allegiance.ContainsKey(item.Manufacturer)))
.WeightedRandomElements(ref Random,
item =>
(Faction == null || item.Manufacturer == Faction.ID ? 1 : Faction.Allegiance[item.Manufacturer]) / // Prioritize items from allied manufacturers
(Zone?.Distance[Sector.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1) / // Penalize distance to manufacturer headquarters
(Zone?.Distance[Galaxy.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1) / // Penalize distance to manufacturer headquarters
pow(item.Price, PriceExponent), // Penalize item price to a controllable degree
1
).FirstOrDefault();
@ -124,13 +124,13 @@ public class LoadoutGenerator
.Where(item =>
item.Price > 0 &&
item.Manufacturer != Guid.Empty &&
(Sector?.ContainsFaction(item.Manufacturer) ?? true) &&
(Galaxy?.ContainsFaction(item.Manufacturer) ?? true) &&
(Faction == null || Faction.Allegiance.ContainsKey(item.Manufacturer)) &&
(filter?.Invoke(item) ?? true))
.WeightedRandomElements(ref Random, item =>
(Faction == null || item.Manufacturer == Faction.ID ? 1 : Faction.Allegiance[item.Manufacturer]) * // Prioritize items from allied manufacturers
pow(item.Shape.Coordinates.Length, sizeExponent) / // Prioritize larger items
(Zone?.Distance[Sector.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1) / // Penalize distance to manufacturer headquarters
(Zone?.Distance[Galaxy.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1) / // Penalize distance to manufacturer headquarters
pow(item.Price, PriceExponent), // Penalize item price to a controllable degree
count
);

View file

@ -4,10 +4,11 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Ink;
using Ink.Runtime;
using Ink.Parsed;
using MessagePack;
using Path = System.IO.Path;
using Random = Unity.Mathematics.Random;
using Story = Ink.Runtime.Story;
public class StoryProcessor : IZoneResolver, IFactionResolver
{
@ -24,62 +25,67 @@ public class StoryProcessor : IZoneResolver, IFactionResolver
public string LoadInkFileContents (string fullFilename) => File.ReadAllText (fullFilename);
}
private Dictionary<Story, SectorZone> _placedStories = new Dictionary<Story, SectorZone>();
private Dictionary<Story, string[]> _storyKnotPaths = new Dictionary<Story, string[]>();
private Dictionary<Story, GalaxyZone> _storyLocations = new Dictionary<Story, GalaxyZone>();
private Dictionary<string, Story> _processedStories = new Dictionary<string, Story>();
private DirectoryInfo _locationsPath;
private DirectoryInfo _questsPath;
private IFileHandler _inkFileHandler;
public DirectoryInfo NarrativeDirectory { get; }
private Random _random;
public Sector Sector { get; }
public Galaxy Galaxy { get; }
public PlayerSettings Settings { get; }
public StoryProcessor(PlayerSettings settings, DirectoryInfo narrativeDirectory, Sector sector, ref Random random)
public StoryProcessor(PlayerSettings settings, DirectoryInfo narrativeDirectory, Galaxy galaxy, ref Random random)
{
NarrativeDirectory = narrativeDirectory;
Sector = sector;
Galaxy = galaxy;
_random = random;
Settings = settings;
_inkFileHandler = new AetheriaInkFileHandler(narrativeDirectory);
_locationsPath = narrativeDirectory.CreateSubdirectory("Locations");
_questsPath = narrativeDirectory.CreateSubdirectory("Quests");
}
public Dictionary<Story, SectorZone> PlaceStories()
public void ProcessStories()
{
var locationFiles = _locationsPath.EnumerateFiles("*.ink");
foreach(var inkFile in locationFiles) PlaceStory(GetStory(inkFile));
return _placedStories;
foreach(var inkFile in locationFiles) ProcessLocation(GetStory(inkFile), inkFile);
var questFiles = _questsPath.EnumerateFiles("*ink");
foreach(var inkFile in questFiles) ProcessQuest(GetStory(inkFile));
}
public SectorZone ResolveZone(string path)
public GalaxyZone ResolveZone(string path)
{
// Handle special cases: "start" and "end"
if (path.Equals("start", StringComparison.InvariantCultureIgnoreCase))
return Sector.Entrance;
return Galaxy.Entrance;
if (path.Equals("end", StringComparison.InvariantCultureIgnoreCase))
return Sector.Exit;
return Galaxy.Exit;
// Handle faction home reference: format = "home.<faction>"
if(path.StartsWith("home"))
{
var factionString = path.Substring(5);
var faction = ResolveFaction(factionString);
return !Sector.HomeZones.ContainsKey(faction) ? null : Sector.HomeZones[faction];
return !Galaxy.HomeZones.ContainsKey(faction) ? null : Galaxy.HomeZones[faction];
}
var locationInkFile = new FileInfo(Path.Combine(_locationsPath.FullName, $"{path}.ink"));
if (!locationInkFile.Exists) return null;
var story = GetStory(locationInkFile);
PlaceStory(story);
return _placedStories.ContainsKey(story) ? _placedStories[story] : null;
ProcessLocation(story, locationInkFile);
return _storyLocations.ContainsKey(story) ? _storyLocations[story] : null;
}
public Faction ResolveFaction(string name)
{
return Sector.Factions.FirstOrDefault(f => f.Name.StartsWith(name, StringComparison.InvariantCultureIgnoreCase));
return Galaxy.Factions.FirstOrDefault(f => f.Name.StartsWith(name, StringComparison.InvariantCultureIgnoreCase));
}
Story GetStory(FileInfo inkFile)
@ -109,16 +115,30 @@ public class StoryProcessor : IZoneResolver, IFactionResolver
fileHandler = _inkFileHandler
});
var story = compiler.Compile();
var knots = compiler.parsedStory.FindAll<Knot>().Select(k=>k.runtimePath.ToString()).ToArray();
_storyKnotPaths[story] = knots;
File.WriteAllText(compiledFileName, story.ToJson());
return story;
}
public void PlaceStory(Story story)
{
if (_placedStories.ContainsKey(story)) return; // Don't place already placed stories, idiot!
_placedStories[story] = null; // Avoids potential for infinite loops when evaluating constraints
var contentTags = GetContentTags(story);
public void ProcessQuest(Story story)
{
var quest = new GalaxyQuest();
quest.Story = story;
foreach (var knot in _storyKnotPaths[story])
{
var tags = GetContentTags(story.TagsForContentAtPath(knot));
}
}
public void ProcessLocation(Story story, FileInfo inkFile)
{
if (_storyLocations.ContainsKey(story)) return; // Don't place already placed stories, idiot!
_storyLocations[story] = null; // Avoids potential for infinite loops when evaluating constraints
var fileName = Path.GetFileNameWithoutExtension(inkFile.FullName);
var contentTags = GetContentTags(story.globalTags);
var constraints = new List<ZoneConstraint>();
if(contentTags.ContainsKey("constraint"))
@ -157,16 +177,34 @@ public class StoryProcessor : IZoneResolver, IFactionResolver
else
selector = new RandomSelector(ref _random);
var zoneCandidates = new List<SectorZone>();
zoneCandidates.AddRange(Sector.Zones.Where(z=>constraints.All(c=>c.Test(z))));
_placedStories[story] = selector.SelectZone(zoneCandidates);
var zoneCandidates = new List<GalaxyZone>();
zoneCandidates.AddRange(Galaxy.Zones.Where(z=>!z.NamedZone && constraints.All(c=>c.Test(z))));
var zone = selector.SelectZone(zoneCandidates);
var location = new LocationStory
{
FileName = fileName,
Name = contentTags.ContainsKey("name") ? contentTags["name"].First() : fileName,
Faction = contentTags.ContainsKey("faction") ? ResolveFaction(contentTags["faction"].First()) : zone.Owner,
Security = contentTags.ContainsKey("security")
? (SecurityLevel) Enum.Parse(typeof(SecurityLevel), contentTags["security"].First(), true)
: SecurityLevel.Open,
Story = story,
Type = contentTags.ContainsKey("type")
? (LocationType) Enum.Parse(typeof(LocationType), contentTags["type"].First(), true)
: LocationType.Station
};
zone.Locations.Add(location);
_storyLocations[story] = zone;
}
// Parse all tags of the format X:Y into a dictionary with a list of every Y for each X
public static Dictionary<string, List<string>> GetContentTags(Story story)
public static Dictionary<string, List<string>> GetContentTags(List<string> tags)
{
var contentTags = new Dictionary<string, List<string>>();
foreach (var tag in story.globalTags)
foreach (var tag in tags)
{
if (tag.IndexOf(':') == -1) continue;

View file

@ -4,7 +4,7 @@ using System.Linq;
public interface IZoneResolver
{
public SectorZone ResolveZone(string path);
public GalaxyZone ResolveZone(string path);
}
public interface IFactionResolver
@ -16,12 +16,12 @@ public abstract class ZoneConstraint
{
public bool Flip = false;
public bool Test(SectorZone zone)
public bool Test(GalaxyZone zone)
{
return Flip ^ TestZone(zone);
}
protected abstract bool TestZone(SectorZone zone);
protected abstract bool TestZone(GalaxyZone zone);
}
public class FactionPresenceConstraint : ZoneConstraint
@ -32,7 +32,7 @@ public class FactionPresenceConstraint : ZoneConstraint
TargetFaction = resolver.ResolveFaction(args[0]);
}
protected override bool TestZone(SectorZone zone)
protected override bool TestZone(GalaxyZone zone)
{
return zone.Factions.Any(f=>f.ID == TargetFaction?.ID);
}
@ -47,7 +47,7 @@ public class FactionOwnerConstraint : ZoneConstraint
TargetFaction = resolver.ResolveFaction(args[0]);
}
protected override bool TestZone(SectorZone zone)
protected override bool TestZone(GalaxyZone zone)
{
return zone.Owner.ID == TargetFaction?.ID;
}
@ -55,7 +55,7 @@ public class FactionOwnerConstraint : ZoneConstraint
public class DistanceConstraint : ZoneConstraint
{
private SectorZone _targetZone;
private GalaxyZone _targetZone;
private Predicate<int> _test;
public DistanceConstraint(string[] args, IZoneResolver zoneResolver)
@ -82,7 +82,7 @@ public class DistanceConstraint : ZoneConstraint
}
}
protected override bool TestZone(SectorZone zone)
protected override bool TestZone(GalaxyZone zone)
{
return _targetZone != null && _test(zone.Distance[_targetZone]);
}

View file

@ -6,16 +6,16 @@ using Random = Unity.Mathematics.Random;
public abstract class ZoneSelector
{
public abstract SectorZone SelectZone(List<SectorZone> candidates);
public abstract GalaxyZone SelectZone(List<GalaxyZone> candidates);
}
public abstract class OrderedZoneSelector : ZoneSelector
{
public bool Flip = false;
protected abstract Func<SectorZone, IComparable> Comparison { get; }
protected abstract Func<GalaxyZone, IComparable> Comparison { get; }
public override SectorZone SelectZone(List<SectorZone> candidates)
public override GalaxyZone SelectZone(List<GalaxyZone> candidates)
{
var sorted = candidates.OrderBy(Comparison);
return Flip ? sorted.Last() : sorted.First();
@ -24,7 +24,7 @@ public abstract class OrderedZoneSelector : ZoneSelector
public class DistanceSelector : OrderedZoneSelector
{
private SectorZone Target { get; }
private GalaxyZone Target { get; }
public DistanceSelector(string[] args, IZoneResolver zoneResolver)
@ -32,7 +32,7 @@ public class DistanceSelector : OrderedZoneSelector
Target = zoneResolver.ResolveZone(args[0].Trim());
}
protected override Func<SectorZone, IComparable> Comparison => zone => Target?.Distance[zone] ?? 0;
protected override Func<GalaxyZone, IComparable> Comparison => zone => Target?.Distance[zone] ?? 0;
}
public class RandomSelector : ZoneSelector
@ -44,7 +44,7 @@ public class RandomSelector : ZoneSelector
Random = random;
}
public override SectorZone SelectZone(List<SectorZone> candidates)
public override GalaxyZone SelectZone(List<GalaxyZone> candidates)
{
return candidates[Random.NextInt(candidates.Count)];
}

View file

@ -37,7 +37,7 @@ public class OrbitalEntity : Entity
{
if (SecurityRadius < 1) return false;
if (Faction == null) return false;
return !IsPresencePermitted(Zone.Sector.FactionRelationships[Faction], SecurityLevel);
return !IsPresencePermitted(Zone.Galaxy.FactionRelationships[Faction], SecurityLevel);
}
}
}

View file

@ -49,35 +49,35 @@ public class SavedGame
public SavedGame() { }
public SavedGame(Sector sector, Zone currentZone, Entity currentEntity)
public SavedGame(Galaxy galaxy, Zone currentZone, Entity currentEntity)
{
DiscoveredZones = sector.DiscoveredZones.Select(dz => Array.IndexOf(sector.Zones, dz)).ToArray();
Background = sector.Background;
Factions = sector.HomeZones.Keys.Select(f => f.ID).ToArray();
Relationships = sector.Factions.Select(f => sector.FactionRelationships[f]).ToArray();
DiscoveredZones = galaxy.DiscoveredZones.Select(dz => Array.IndexOf(galaxy.Zones, dz)).ToArray();
Background = galaxy.Background;
Factions = galaxy.HomeZones.Keys.Select(f => f.ID).ToArray();
Relationships = galaxy.Factions.Select(f => galaxy.FactionRelationships[f]).ToArray();
HomeZones = sector.HomeZones.ToDictionary(
HomeZones = galaxy.HomeZones.ToDictionary(
x => Array.IndexOf(Factions, x.Key.ID),
x => Array.IndexOf(sector.Zones, x.Value));
BossZones = sector.BossZones.ToDictionary(
x => Array.IndexOf(galaxy.Zones, x.Value));
BossZones = galaxy.BossZones.ToDictionary(
x => Array.IndexOf(Factions, x.Key.ID),
x => Array.IndexOf(sector.Zones, x.Value));
x => Array.IndexOf(galaxy.Zones, x.Value));
Zones = sector.Zones.Select(zone => new SavedZone
Zones = galaxy.Zones.Select(zone => new SavedZone
{
Name = zone.Name,
Position = zone.Position,
AdjacentZones = zone.AdjacentZones.Select(az=> Array.IndexOf(sector.Zones, az)).ToArray(),
AdjacentZones = zone.AdjacentZones.Select(az=> Array.IndexOf(galaxy.Zones, az)).ToArray(),
Factions = zone.Factions.Select(f=> Array.IndexOf(Factions, f.ID)).ToArray(),
Contents = zone.Contents?.PackZone(),
Owner = zone.Owner == null ? -1 : Array.IndexOf(Factions, zone.Owner.ID)
}).ToArray();
CurrentZone = Array.FindIndex(sector.Zones, zone => zone.Contents == currentZone);
CurrentZone = Array.FindIndex(galaxy.Zones, zone => zone.Contents == currentZone);
CurrentZoneEntity = currentZone.Entities.IndexOf(currentEntity);
Entrance = Array.IndexOf(sector.Zones, sector.Entrance);
Exit = Array.IndexOf(sector.Zones, sector.Exit);
Entrance = Array.IndexOf(galaxy.Zones, galaxy.Entrance);
Exit = Array.IndexOf(galaxy.Zones, galaxy.Exit);
}
}

View file

@ -46,6 +46,7 @@ public class Ship : Entity
private float2 _wormholePosition;
private float2 _wormholeExitVelocity;
public bool WormholeAnimationInProgress => _enteringWormhole || _exitingWormhole;
public float ForwardThrust { get; private set; }
public float ReverseThrust { get; private set; }
public float LeftStrafeThrust { get; private set; }

View file

@ -3,5 +3,5 @@ using Unity.Mathematics;
public class Wormhole
{
public float2 Position;
public SectorZone Target;
public GalaxyZone Target;
}

View file

@ -41,18 +41,18 @@ public class Zone
get => (float) _time;
}
public ZonePack Pack { get; }
public SectorZone SectorZone { get; }
public Sector Sector { get; }
public GalaxyZone GalaxyZone { get; }
public Galaxy Galaxy { get; }
public Zone(ItemManager itemManager, PlanetSettings settings, ZonePack pack, SectorZone sectorZone, Sector sector)
public Zone(ItemManager itemManager, PlanetSettings settings, ZonePack pack, GalaxyZone galaxyZone, Galaxy galaxy)
{
_time = pack.Time;
SectorZone = sectorZone;
Sector = sector;
GalaxyZone = galaxyZone;
Galaxy = galaxy;
Pack = pack;
_itemManager = itemManager;
Settings = settings;
_random = new Random(Convert.ToUInt32(abs(sectorZone?.Name.GetHashCode() ?? 1337)));
_random = new Random(Convert.ToUInt32(abs(galaxyZone?.Name.GetHashCode() ?? 1337)));
foreach (var orbit in pack.Orbits)
{
@ -311,12 +311,12 @@ public class Zone
public SecurityLevel GetSecurityLevel(float2 pos)
{
if (SectorZone.Owner==null) return SecurityLevel.Open;
if (GalaxyZone.Owner==null) return SecurityLevel.Open;
var security = SecurityLevel.Open;
foreach (var entity in Entities)
{
if (entity is OrbitalEntity orbitalEntity && orbitalEntity.SecurityRadius > 1 && entity.Faction.ID == SectorZone.Owner.ID)
if (entity is OrbitalEntity orbitalEntity && orbitalEntity.SecurityRadius > 1 && entity.Faction.ID == GalaxyZone.Owner.ID)
{
if (orbitalEntity.SecurityLevel > security && length(orbitalEntity.Position.xz - pos) < orbitalEntity.SecurityRadius * Settings.SecureAreaRadiusMultiplier)
security = orbitalEntity.SecurityLevel;

View file

@ -38,15 +38,15 @@ public static class ZoneGenerator
public static ZonePack GenerateZone(
ItemManager itemManager,
ZoneGenerationSettings zoneSettings,
Sector sector,
SectorZone sectorZone,
Galaxy galaxy,
GalaxyZone galaxyZone,
bool isTutorial = false)
{
var pack = new ZonePack();
var random = new Random(unchecked((uint) sectorZone.Name.GetHashCode()) ^ hash(sectorZone.Position));
var random = new Random(unchecked((uint) galaxyZone.Name.GetHashCode()) ^ hash(galaxyZone.Position));
var density = saturate(sector.Background.CloudDensity(sectorZone.Position)/2);
var density = saturate(galaxy.Background.CloudDensity(galaxyZone.Position)/2);
pack.Radius = zoneSettings.ZoneRadius.Evaluate(density);
pack.Mass = zoneSettings.ZoneMass.Evaluate(density);
var targetSubzoneCount = zoneSettings.SubZoneCount.Evaluate(density);
@ -222,9 +222,9 @@ public static class ZoneGenerator
return planetData;
}).ToList();
var nearestFaction = sector.Factions.MinBy(f => sector.HomeZones[f].Distance[sectorZone]);
var nearestFactionHomeZone = sector.HomeZones[nearestFaction];
var factionPresence = nearestFaction.InfluenceDistance - nearestFactionHomeZone.Distance[sectorZone] + 1;
var nearestFaction = galaxy.Factions.MinBy(f => galaxy.HomeZones[f].Distance[galaxyZone]);
var nearestFactionHomeZone = galaxy.HomeZones[nearestFaction];
var factionPresence = nearestFaction.InfluenceDistance - nearestFactionHomeZone.Distance[galaxyZone] + 1;
var stationCount = (int)(random.NextFloat() * (factionPresence + 1));
var potentialLagrangePoints = planets
@ -240,7 +240,7 @@ public static class ZoneGenerator
.ToArray();
var loadoutGenerator = isTutorial ? new LoadoutGenerator(ref random, itemManager, nearestFaction, .5f) :
new LoadoutGenerator(ref random, itemManager, sector, sectorZone, nearestFaction, .5f);
new LoadoutGenerator(ref random, itemManager, galaxy, galaxyZone, nearestFaction, .5f);
foreach (var orbit in selectedStationOrbits)
{

View file

@ -1,15 +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 TMPro;
using UnityEngine;
public class GalaxyZone : MonoBehaviour
{
public MeshRenderer Background;
public MeshRenderer Icon;
public TextMeshPro Label;
}

View file

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

View file

@ -98,7 +98,7 @@ public class MainMenu : MonoBehaviour
() =>
{
ActionGameManager.IsTutorial = ActionGameManager.PlayerSettings.SavedRun.IsTutorial;
ActionGameManager.CurrentSector = new Sector(
ActionGameManager.CurrentGalaxy = new Galaxy(
ActionGameManager.CultCache,
ActionGameManager.PlayerSettings.SavedRun);
SceneManager.LoadScene("ARPG");
@ -125,7 +125,7 @@ public class MainMenu : MonoBehaviour
ActionGameManager.IsTutorial = false;
Task.Run(() =>
{
var sector = new Sector(
var sector = new Galaxy(
Settings.SectorGenerationSettings,
Settings.SectorBackgroundSettings,
Settings.NameGeneratorSettings,
@ -134,7 +134,7 @@ public class MainMenu : MonoBehaviour
Observable.NextFrame().Subscribe(_ =>
{
ActionGameManager.PlayerSettings.SavedRun = null;
ActionGameManager.CurrentSector = sector;
ActionGameManager.CurrentGalaxy = sector;
SceneManager.LoadScene("ARPG");
});
}).WrapErrors();
@ -151,7 +151,7 @@ public class MainMenu : MonoBehaviour
ActionGameManager.IsTutorial = true;
Task.Run(() =>
{
var sector = new Sector(
var sector = new Galaxy(
Settings.TutorialGenerationSettings,
Settings.TutorialBackgroundSettings,
Settings.NameGeneratorSettings,
@ -162,7 +162,7 @@ public class MainMenu : MonoBehaviour
Observable.NextFrame().Subscribe(_ =>
{
ActionGameManager.PlayerSettings.SavedRun = null;
ActionGameManager.CurrentSector = sector;
ActionGameManager.CurrentGalaxy = sector;
SceneManager.LoadScene("ARPG");
});
}).WrapErrors();

View file

@ -48,7 +48,7 @@ public class MapRenderer : MonoBehaviour
GravityCamera.gameObject.SetActive(true);
TintCamera.gameObject.SetActive(true);
InfluenceCamera.gameObject.SetActive(true);
Title.text = $"Zone: {GameManager.Zone.SectorZone.Name}";
Title.text = $"Zone: {GameManager.Zone.GalaxyZone.Name}";
}
private void OnDisable()

View file

@ -42,19 +42,19 @@ public class SectorMap : MonoBehaviour
public Color PlayerLocationLabelColor;
public float PlayerLocationIconSize = 1.25f;
public Subject<SectorZone> ZoneClicked = new Subject<SectorZone>();
public Subject<GalaxyZone> ZoneClicked = new Subject<GalaxyZone>();
private SectorZone _currentPlayerLocation;
private HashSet<SectorZone> _revealedZones = new HashSet<SectorZone>();
private HashSet<(SectorZone, SectorZone)> _revealedLinks = new HashSet<(SectorZone, SectorZone)>();
private GalaxyZone _currentPlayerLocation;
private HashSet<GalaxyZone> _revealedZones = new HashSet<GalaxyZone>();
private HashSet<(GalaxyZone, GalaxyZone)> _revealedLinks = new HashSet<(GalaxyZone, GalaxyZone)>();
private Dictionary<Faction, (MeshRenderer influenceRenderer, RenderTexture influence, Material primaryMaterial, Material secondaryMaterial, Material linkMaterial)> _factionMaterials =
new Dictionary<Faction, (MeshRenderer influenceRenderer, RenderTexture influence, Material primaryMaterial, Material secondaryMaterial, Material linkMaterial)>();
private Dictionary<SectorZone, SectorZoneUI> _zoneInstances = new Dictionary<SectorZone, SectorZoneUI>();
private Queue<IEnumerable<SectorZone>> _queuedZoneReveals = new Queue<IEnumerable<SectorZone>>();
private Dictionary<GalaxyZone, SectorZoneUI> _zoneInstances = new Dictionary<GalaxyZone, SectorZoneUI>();
private Queue<IEnumerable<GalaxyZone>> _queuedZoneReveals = new Queue<IEnumerable<GalaxyZone>>();
public void MarkPlayerLocation(SectorZone zone)
public void MarkPlayerLocation(GalaxyZone zone)
{
if (_currentPlayerLocation != null)
{
@ -77,7 +77,7 @@ public class SectorMap : MonoBehaviour
zoneUI.IconContainer.localScale = new Vector3(PlayerLocationIconSize, PlayerLocationIconSize, 1);
}
public void QueueZoneReveal(IEnumerable<SectorZone> zones)
public void QueueZoneReveal(IEnumerable<GalaxyZone> zones)
{
_queuedZoneReveals.Enqueue(zones);
}
@ -90,7 +90,7 @@ public class SectorMap : MonoBehaviour
}
}
public IEnumerator RevealZone(IEnumerable<SectorZone> zones, float linkDuration, float iconDuration)
public IEnumerator RevealZone(IEnumerable<GalaxyZone> zones, float linkDuration, float iconDuration)
{
var linksToReveal = new List<(float2 start, float2 end, Transform linkInstance, bool critical)>();
var zoneTransforms = new List<Transform>();
@ -112,7 +112,7 @@ public class SectorMap : MonoBehaviour
{
zoneInstance.Primary.sharedMaterial = _factionMaterials[zone.Owner].primaryMaterial;
zoneInstance.Secondary.sharedMaterial = _factionMaterials[zone.Owner].secondaryMaterial;
if(zone == ActionGameManager.CurrentSector.HomeZones[zone.Owner])
if(zone == ActionGameManager.CurrentGalaxy.HomeZones[zone.Owner])
zoneInstance.Secondary.transform.localScale = Vector3.one * 4;
}
else
@ -120,7 +120,7 @@ public class SectorMap : MonoBehaviour
zoneInstance.Secondary.gameObject.SetActive(false);
}
var isOnCriticalPath = ActionGameManager.CurrentSector.ExitPath?.Contains(zone) ?? false;
var isOnCriticalPath = ActionGameManager.CurrentGalaxy.ExitPath?.Contains(zone) ?? false;
foreach (var adjacentZone in zone.AdjacentZones)
{
// If the adjacent zone is in the set already revealed, then show the link
@ -129,7 +129,7 @@ public class SectorMap : MonoBehaviour
_revealedLinks.Contains((adjacentZone, zone))))
{
var link = LinkPrototype.Instantiate<Transform>();
var critical = isOnCriticalPath && (ActionGameManager.CurrentSector.ExitPath?.Contains(adjacentZone) ?? false);
var critical = isOnCriticalPath && (ActionGameManager.CurrentGalaxy.ExitPath?.Contains(adjacentZone) ?? false);
linksToReveal.Add((zone.Position, adjacentZone.Position, link, critical));
if (zone.Owner != null && zone.Owner == adjacentZone.Owner)
link.GetComponent<MeshRenderer>().sharedMaterial = _factionMaterials[zone.Owner].linkMaterial;
@ -152,7 +152,7 @@ public class SectorMap : MonoBehaviour
zoneTextTransform.pivot = new Vector2(sign(linkDirection.x)/2+.5f,sign(linkDirection.y)/2+.5f);
zoneTextTransform.localPosition = new Vector3(-linkDirection.x * LabelDistance, -linkDirection.y * LabelDistance, -1);
if (zone == ActionGameManager.CurrentSector.Entrance)
if (zone == ActionGameManager.CurrentGalaxy.Entrance)
{
var iconInstance = IconPrototype.Instantiate<MeshRenderer>();
iconInstance.material.mainTexture = EntranceIcon;
@ -162,7 +162,7 @@ public class SectorMap : MonoBehaviour
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
}
if (zone == ActionGameManager.CurrentSector.Exit)
if (zone == ActionGameManager.CurrentGalaxy.Exit)
{
var iconInstance = IconPrototype.Instantiate<MeshRenderer>();
iconInstance.material.mainTexture = ExitIcon;
@ -172,8 +172,8 @@ public class SectorMap : MonoBehaviour
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
}
var homeMega = ActionGameManager.CurrentSector.HomeZones.Keys
.FirstOrDefault(m => ActionGameManager.CurrentSector.HomeZones[m] == zone);
var homeMega = ActionGameManager.CurrentGalaxy.HomeZones.Keys
.FirstOrDefault(m => ActionGameManager.CurrentGalaxy.HomeZones[m] == zone);
if (homeMega != null)
{
var backgroundInstance = IconBackgroundPrototype.Instantiate<MeshRenderer>();
@ -196,8 +196,8 @@ public class SectorMap : MonoBehaviour
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
}
var bossMega = ActionGameManager.CurrentSector.BossZones.Keys
.FirstOrDefault(m => ActionGameManager.CurrentSector.BossZones[m] == zone);
var bossMega = ActionGameManager.CurrentGalaxy.BossZones.Keys
.FirstOrDefault(m => ActionGameManager.CurrentGalaxy.BossZones[m] == zone);
if (bossMega != null)
{
var backgroundInstance = IconBackgroundPrototype.Instantiate<MeshRenderer>();
@ -269,12 +269,12 @@ public class SectorMap : MonoBehaviour
public void Start()
{
if (ActionGameManager.CurrentSector == null)
if (ActionGameManager.CurrentGalaxy == null)
{
gameObject.SetActive(false);
return;
}
foreach (var mega in ActionGameManager.CurrentSector.Factions)
foreach (var mega in ActionGameManager.CurrentGalaxy.Factions)
{
var influenceTexture = new RenderTexture(1024, 1024, 0, RenderTextureFormat.RHalf);
var influenceRenderer = InfluenceRendererPrototype.Instantiate<MeshRenderer>();
@ -301,22 +301,22 @@ public class SectorMap : MonoBehaviour
legendElement.Label.text = mega.ShortName;
}
SectorRenderer.material.SetFloat("CloudAmplitude", ActionGameManager.CurrentSector.Background.CloudAmplitude);
SectorRenderer.material.SetFloat("CloudExponent", ActionGameManager.CurrentSector.Background.CloudExponent);
SectorRenderer.material.SetFloat("NoisePosition", ActionGameManager.CurrentSector.Background.NoisePosition);
SectorRenderer.material.SetFloat("NoiseAmplitude", ActionGameManager.CurrentSector.Background.NoiseAmplitude);
SectorRenderer.material.SetFloat("NoiseOffset", ActionGameManager.CurrentSector.Background.NoiseOffset);
SectorRenderer.material.SetFloat("NoiseGain", ActionGameManager.CurrentSector.Background.NoiseGain);
SectorRenderer.material.SetFloat("NoiseLacunarity", ActionGameManager.CurrentSector.Background.NoiseLacunarity);
SectorRenderer.material.SetFloat("NoiseFrequency", ActionGameManager.CurrentSector.Background.NoiseFrequency);
SectorRenderer.material.SetFloat("CloudAmplitude", ActionGameManager.CurrentGalaxy.Background.CloudAmplitude);
SectorRenderer.material.SetFloat("CloudExponent", ActionGameManager.CurrentGalaxy.Background.CloudExponent);
SectorRenderer.material.SetFloat("NoisePosition", ActionGameManager.CurrentGalaxy.Background.NoisePosition);
SectorRenderer.material.SetFloat("NoiseAmplitude", ActionGameManager.CurrentGalaxy.Background.NoiseAmplitude);
SectorRenderer.material.SetFloat("NoiseOffset", ActionGameManager.CurrentGalaxy.Background.NoiseOffset);
SectorRenderer.material.SetFloat("NoiseGain", ActionGameManager.CurrentGalaxy.Background.NoiseGain);
SectorRenderer.material.SetFloat("NoiseLacunarity", ActionGameManager.CurrentGalaxy.Background.NoiseLacunarity);
SectorRenderer.material.SetFloat("NoiseFrequency", ActionGameManager.CurrentGalaxy.Background.NoiseFrequency);
}
private void RenderInfluence()
{
// Render Influence Textures
foreach (var mega in ActionGameManager.CurrentSector.Factions)
foreach (var mega in ActionGameManager.CurrentGalaxy.Factions)
{
foreach (var zone in ActionGameManager.CurrentSector.Zones)
foreach (var zone in ActionGameManager.CurrentGalaxy.Zones)
{
if(_zoneInstances.ContainsKey(zone))
{

View file

@ -66,7 +66,7 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
.Select(f=>f.Name).ToArray();
if (otherFactions.Length > 0)
Properties.AddProperty("Factions Present", () => string.Join(", ", otherFactions));
var density = saturate(ActionGameManager.CurrentSector.Background.CloudDensity(zone.Position)/2);
var density = saturate(ActionGameManager.CurrentGalaxy.Background.CloudDensity(zone.Position)/2);
var radius = GameManager.Settings.ZoneSettings.ZoneRadius.Evaluate(density);
var mass = GameManager.Settings.ZoneSettings.ZoneMass.Evaluate(density);
Properties.AddProperty("Mass", () => ActionGameManager.PlayerSettings.Format(mass));
@ -145,11 +145,11 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
{
_init = true;
SectorCamera.gameObject.SetActive(true);
_position = GameManager.Zone.SectorZone.Position;
_position = GameManager.Zone.GalaxyZone.Position;
_viewSize = .25f;
Map.StartReveal(LinkAnimationDuration, IconAnimationDuration);
Map.MarkPlayerLocation(GameManager.CurrentEntity.Zone.SectorZone);
Map.MarkPlayerLocation(GameManager.CurrentEntity.Zone.GalaxyZone);
}
private void OnDisable()

View file

@ -197,11 +197,11 @@ public class ZoneRenderer : MonoBehaviour
UnloadEntity(e.Value);
}));
if (zone.SectorZone != null)
if (zone.GalaxyZone != null)
{
foreach (var adjacentZone in zone.SectorZone.AdjacentZones)
foreach (var adjacentZone in zone.GalaxyZone.AdjacentZones)
{
var dir = normalize(adjacentZone.Position - zone.SectorZone.Position);
var dir = normalize(adjacentZone.Position - zone.GalaxyZone.Position);
AddWormhole(new Wormhole
{
Target = adjacentZone,

BIN
GameData/PlayerSettings.msgpack (Stored with Git LFS)

Binary file not shown.