Resolve runtime factions through typed galaxy projection
This commit is contained in:
parent
de36150dc2
commit
c43d7b8f67
5 changed files with 47 additions and 9 deletions
|
|
@ -90,7 +90,7 @@ public static class EntitySerializer
|
|||
private static void Restore(ItemManager itemManager, Zone zone, EntityPack pack, Entity entity, bool instantiate = false)
|
||||
{
|
||||
entity.Name = pack.Name;
|
||||
entity.Faction = itemManager.GetCatalogEntry<Faction>(pack.Faction);
|
||||
entity.Faction = zone?.Galaxy?.ResolveFaction(pack.Faction);
|
||||
entity.Children = pack.Children.Select(c =>
|
||||
{
|
||||
var child = Unpack(itemManager, zone, c, instantiate);
|
||||
|
|
|
|||
|
|
@ -467,6 +467,22 @@ public class Galaxy
|
|||
return _containedFactions.Contains(factionID);
|
||||
}
|
||||
|
||||
public Faction ResolveFaction(Guid factionID)
|
||||
{
|
||||
if (factionID == Guid.Empty)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var faction = Factions.FirstOrDefault(f => f.ID == factionID);
|
||||
if (faction != null)
|
||||
{
|
||||
return faction;
|
||||
}
|
||||
|
||||
return _allFactions.FirstOrDefault(f => f.ID == factionID);
|
||||
}
|
||||
|
||||
class DijkstraVertex
|
||||
{
|
||||
public float Cost;
|
||||
|
|
|
|||
|
|
@ -137,13 +137,26 @@ public class LoadoutGenerator
|
|||
.WeightedRandomElements(ref Random, item =>
|
||||
Faction == null ? 1 :
|
||||
(item.Manufacturer == Faction.ID ? 1 : Faction.Allegiance.ContainsKey(item.Manufacturer) ? Faction.Allegiance[item.Manufacturer] : 0.0f / // Prioritize items from allied manufacturers
|
||||
(Galaxy?.ContainsFaction(item.Manufacturer) ?? false ? Zone?.Distance[Galaxy.HomeZones[ItemManager.GetCatalogEntry<Faction>(item.Manufacturer)]] ?? 1 : 1)) * // Penalize distance to manufacturer headquarters
|
||||
ManufacturerDistancePenalty(item.Manufacturer)) * // Penalize distance to manufacturer headquarters
|
||||
pow(item.Shape.Coordinates.Length, sizeExponent) / // Prioritize larger items
|
||||
pow(item.Price, PriceExponent), // Penalize item price to a controllable degree
|
||||
count
|
||||
);
|
||||
}
|
||||
|
||||
private float ManufacturerDistancePenalty(Guid manufacturer)
|
||||
{
|
||||
if (Galaxy == null || Zone == null || !Galaxy.ContainsFaction(manufacturer))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var faction = Galaxy.ResolveFaction(manufacturer);
|
||||
return faction != null && Galaxy.HomeZones.TryGetValue(faction, out var homeZone)
|
||||
? Zone.Distance[homeZone]
|
||||
: 1;
|
||||
}
|
||||
|
||||
public T RandomItem<T>(float sizeExponent, Predicate<T> filter = null) where T : EquippableItemData
|
||||
{
|
||||
return RandomItems(1, sizeExponent, filter).FirstOrDefault();
|
||||
|
|
|
|||
Loading…
Reference in a new issue