Merge origin/master into the loot branch (Self's direction)
One conflict, Zone.cs death subscription against contact-reveals' _departures insert: kept both. The resolution already routes the death subscription through WatchDeath/UnwatchDeath (next commit's fix target is the same line, so this commit resolves it in that shape). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
8120419ecd
97 changed files with 8960 additions and 1118 deletions
|
|
@ -9,11 +9,16 @@ using UnityEngine;
|
|||
// Every single-code-point emoji of the pinned Unicode Emoji version that Twemoji draws, and the Pirates product
|
||||
// names read from the shipped catalog, render through an ordinary TMP text on the game's body font with no
|
||||
// missing code point, no blank glyph, ink in the emoji atlas, and each glyph served by the emoji asset or by the
|
||||
// body font itself, never by a third font. TMP Settings must route emoji by exactly one entry: the global
|
||||
// fallback (the emoji fallback list stays empty), so dropping that entry or re-adding the second route fails.
|
||||
// body font itself, never by a third font. TMP Settings must route emoji by two named routes (operator ruling
|
||||
// emoji-fallback-route): the global fallback names Emoji.asset and the emoji fallback list is exactly Emoji.asset,
|
||||
// so dropping either fails.
|
||||
// Run as -executeMethod EmojiCheck.Run (exit 1 on failure in batchmode, as EngineAssetCheck). Corpus:
|
||||
// tools/emoji/emoji-singles.txt (from emoji-test.txt); the emoji Twemoji lacks are listed in
|
||||
// tools/emoji/emoji-unsupported.txt and reported, not rendered; -emojiLimit N spreads N entries evenly for a spike.
|
||||
// Every fully-qualified multi-code-point sequence (tools/emoji/emoji-sequences.txt: ZWJ, skin tone, flag, keycap,
|
||||
// tag) must also render as exactly one visible character, which needs `liga` on the rendering component: every
|
||||
// TMP text in every prefab and scene must have it, and so must one added at runtime (as ActionGameManager's
|
||||
// FACE AIM mark is), or a family or flag would show as its pieces.
|
||||
public static class EmojiCheck
|
||||
{
|
||||
const string BodyFontPath = "Assets/Fonts/Ubuntu/Ubuntu-L Small SDF.asset";
|
||||
|
|
@ -41,14 +46,15 @@ public static class EmojiCheck
|
|||
return "nothing checked";
|
||||
}
|
||||
|
||||
// One route: the global fallback names the emoji asset, and the emoji fallback list is empty.
|
||||
if (TMP_Settings.emojiFallbackTextAssets != null && TMP_Settings.emojiFallbackTextAssets.Count > 0)
|
||||
failures.Add("TMP Settings' emoji fallback list is not empty: a second emoji route exists (EmojiFont.Build leaves it empty).");
|
||||
// Two routes (operator ruling emoji-fallback-route): the emoji fallback list is exactly Emoji.asset, and the global list below names it.
|
||||
if (TMP_Settings.emojiFallbackTextAssets == null || TMP_Settings.emojiFallbackTextAssets.Count != 1 || TMP_Settings.emojiFallbackTextAssets[0] != emoji)
|
||||
failures.Add("TMP Settings' emoji fallback list is not exactly Emoji.asset: FE0F-followed bases the body font draws will not reach Twemoji.");
|
||||
if (TMP_Settings.fallbackFontAssets == null || !TMP_Settings.fallbackFontAssets.Contains(emoji))
|
||||
failures.Add("TMP Settings' global fallback list does not name Emoji.asset: the only emoji route is gone.");
|
||||
failures.Add("TMP Settings' global fallback list does not name Emoji.asset: the route for every single code point is gone.");
|
||||
|
||||
var unsupported = new HashSet<int>(LoadCodePoints("emoji-unsupported.txt"));
|
||||
var corpus = LoadSingles().Where(cp => !unsupported.Contains(cp)).ToList();
|
||||
var sequences = LoadSequences();
|
||||
var missing = new HashSet<int>();
|
||||
TMP_Text.MissingCharacterEventCallback onMissing = (unicode, index, source, asset, component) => missing.Add(unicode);
|
||||
TMP_Text.OnMissingCharacter += onMissing;
|
||||
|
|
@ -60,7 +66,7 @@ public static class EmojiCheck
|
|||
text.textWrappingMode = TextWrappingModes.NoWrap;
|
||||
text.rectTransform.sizeDelta = new Vector2(100000, 100000);
|
||||
|
||||
int viaEmoji = 0, viaBody = 0, blank = 0, pirateNames = 0;
|
||||
int viaEmoji = 0, viaBody = 0, blank = 0, pirateNames = 0, notOne = 0, runtimeLiga = 0;
|
||||
var strays = new HashSet<string>();
|
||||
try
|
||||
{
|
||||
|
|
@ -90,6 +96,40 @@ public static class EmojiCheck
|
|||
Render(string.Join(" ", slice.Select(char.ConvertFromUtf32)), $"chunk {i}");
|
||||
}
|
||||
|
||||
// A text created at runtime inherits liga from TMP Settings, with no wiring of its own.
|
||||
var runtime = new GameObject("Runtime", typeof(RectTransform));
|
||||
runtime.transform.SetParent(canvas.transform, false);
|
||||
runtimeLiga = runtime.AddComponent<TextMeshProUGUI>().fontFeatures
|
||||
.Contains(UnityEngine.TextCore.OTL_FeatureTag.liga) ? 1 : 0;
|
||||
if (runtimeLiga == 0) failures.Add("a TextMeshProUGUI added at runtime does not have liga: TMP Settings' features are not inherited");
|
||||
|
||||
// Sequences: space-separated groups, each of which must end as one visible character.
|
||||
for (var i = 0; i < sequences.Count; i += Chunk)
|
||||
{
|
||||
var slice = sequences.Skip(i).Take(Chunk).ToList();
|
||||
text.text = string.Join(" ", slice.Select(ToText));
|
||||
text.ForceMeshUpdate();
|
||||
var visible = new List<int> { 0 };
|
||||
var shown = new List<string> { "" };
|
||||
for (var c = 0; c < text.textInfo.characterCount; c++)
|
||||
{
|
||||
var info = text.textInfo.characterInfo[c];
|
||||
if (info.character == ' ') { visible.Add(0); shown.Add(""); }
|
||||
else if (info.isVisible)
|
||||
{
|
||||
visible[visible.Count - 1]++;
|
||||
shown[shown.Count - 1] += $" U+{(int)info.character:X}:{info.fontAsset.name}";
|
||||
}
|
||||
}
|
||||
if (visible.Count != slice.Count) failures.Add($"sequence chunk {i}: {visible.Count} groups rendered for {slice.Count} sequences");
|
||||
for (var g = 0; g < Math.Min(visible.Count, slice.Count); g++)
|
||||
if (visible[g] != 1)
|
||||
{
|
||||
notOne++;
|
||||
failures.Add($"sequence {slice[g]} rendered {visible[g]} visible characters, not one:{shown[g]}");
|
||||
}
|
||||
}
|
||||
|
||||
// The Pirates names as the shipped catalog stores them, through the game's own catalog reader.
|
||||
var catalogPath = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "GameData", "Aetheria.cc");
|
||||
using (var catalog = AetheriaStores.Open(catalogPath))
|
||||
|
|
@ -116,6 +156,19 @@ public static class EmojiCheck
|
|||
|
||||
foreach (var cp in missing.OrderBy(c => c)) failures.Add($"missing code point U+{cp:X4}");
|
||||
|
||||
// Every serialized TMP text has liga (an instance inherits it from its prefab, so this reads the effective value).
|
||||
int texts = 0, withoutLiga = 0;
|
||||
EmojiFont.VisitSerializedTexts(component =>
|
||||
{
|
||||
texts++;
|
||||
if (!component.fontFeatures.Contains(UnityEngine.TextCore.OTL_FeatureTag.liga))
|
||||
{
|
||||
withoutLiga++;
|
||||
failures.Add($"TMP text {component.name} has no liga: {GetPath(component)}");
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// TMP over-allocates atlasTextures by doubling its capacity when a page is added, so entries past
|
||||
// atlasTextureCount are null by design (3 pages in a 4-slot array). Only the used pages count.
|
||||
long ink = 0, colour = 0;
|
||||
|
|
@ -136,11 +189,21 @@ public static class EmojiCheck
|
|||
if (unsupported.Count > 0)
|
||||
Debug.LogWarning($"EmojiCheck: Twemoji lacks {unsupported.Count} single-code-point emoji of the Emoji version: " +
|
||||
string.Join(" ", unsupported.OrderBy(c => c).Select(c => $"U+{c:X4}")));
|
||||
return $"checked {corpus.Count} single code points ({unsupported.Count} not drawn by Twemoji, listed in the warning) + {pirateNames} Pirates product names, " +
|
||||
return $"{sequences.Count} sequences ({notOne} not one visible character), {texts} serialized TMP texts ({withoutLiga} without liga), runtime text liga {runtimeLiga}; " +
|
||||
$"checked {corpus.Count} single code points ({unsupported.Count} not drawn by Twemoji, listed in the warning) + {pirateNames} Pirates product names, " +
|
||||
$"{missing.Count} missing, {viaEmoji} glyphs via the emoji asset, {viaBody} via the body font, {strays.Count} via other fonts, {blank} blank, " +
|
||||
$"{ink} atlas ink pixels of which {colour} coloured, {pages} atlas pages";
|
||||
}
|
||||
|
||||
static string GetPath(Component component) =>
|
||||
component.gameObject.scene.IsValid() ? component.gameObject.scene.path : AssetDatabase.GetAssetPath(component);
|
||||
|
||||
static string ToText(string sequence) => string.Concat(sequence.Split(' ').Select(cp => char.ConvertFromUtf32(Convert.ToInt32(cp, 16))));
|
||||
|
||||
static List<string> LoadSequences() =>
|
||||
File.ReadAllLines(Path.Combine(Directory.GetParent(Application.dataPath).FullName, "tools", "emoji", "emoji-sequences.txt"))
|
||||
.Where(l => l.Length > 0).ToList();
|
||||
|
||||
static List<int> LoadSingles()
|
||||
{
|
||||
var all = LoadCodePoints("emoji-singles.txt");
|
||||
|
|
|
|||
|
|
@ -1,15 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
|
||||
// The one writer of the emoji font asset and of TMP Settings' emoji routing. The font file is the
|
||||
// output of tools/emoji/fetch_emoji_font.py; the asset is a dynamic COLOR font asset whose atlas pages
|
||||
// are cache, filled on first use at runtime and cleared here. Every TMP text reaches emoji through ONE
|
||||
// route, TMP Settings' global fallback list; the emoji fallback list stays empty, and no component names
|
||||
// an emoji font. (Measured: the global list alone resolves every single code point; the emoji list alone
|
||||
// leaves 200 text-presentation emoji unresolved. A second route could only disagree with the first.)
|
||||
// are cache, filled on first use at runtime and cleared here. Every TMP text reaches emoji through TMP
|
||||
// Settings alone (no component names an emoji font), by two routes that both name only Emoji.asset (operator ruling
|
||||
// emoji-fallback-route): the global fallback serves every code point, including the 200 text-presentation emoji the
|
||||
// emoji list alone leaves unresolved; the emoji fallback list is what TMP tries first when FE0F follows, so a keycap
|
||||
// or FE0F/ZWJ sequence whose first code point the body font also draws reaches Twemoji, whose ligatures collapse it.
|
||||
// Sequences (ZWJ, skin tone, flag, keycap) resolve only through the emoji font's GSUB ligatures, and TMP applies
|
||||
// them per component, gated by that component's font features: EnableLigatures writes `liga` into every
|
||||
// serialized TMP text and into TMP Settings (so a text created later inherits it); there is no global switch.
|
||||
public static class EmojiFont
|
||||
{
|
||||
public const string FontPath = "Assets/Fonts/Emoji/Twemoji.ttf";
|
||||
|
|
@ -63,15 +71,97 @@ public static class EmojiFont
|
|||
// The atlas pages are cache: Build leaves them empty, the same state EmojiCheck restores.
|
||||
asset.ClearFontAssetData(true);
|
||||
|
||||
// One route: the global fallback. It also serves text-presentation emoji (U+263A without FE0F).
|
||||
TMP_Settings.emojiFallbackTextAssets = new List<TMP_Asset>();
|
||||
// Two routes: the global fallback serves every code point (text-presentation emoji too, U+263A without FE0F);
|
||||
// the emoji list is tried first when FE0F follows.
|
||||
TMP_Settings.emojiFallbackTextAssets = new List<TMP_Asset> { asset };
|
||||
TMP_Settings.fallbackFontAssets = new List<TMP_FontAsset> { asset };
|
||||
TMP_Settings.defaultSpriteAsset = null;
|
||||
|
||||
EditorUtility.SetDirty(asset);
|
||||
EditorUtility.SetDirty(TMP_Settings.instance);
|
||||
AssetDatabase.SaveAssets();
|
||||
message = "EmojiFont: built " + AssetPath + " and made it TMP Settings' only emoji route (the global fallback).";
|
||||
message = "EmojiFont: built " + AssetPath + " and named it in both of TMP Settings' emoji routes (the global fallback and the emoji fallback list).";
|
||||
return true;
|
||||
}
|
||||
|
||||
// Menu entry for interactive use; -executeMethod EmojiFont.EnableLigatures for batchmode, exit 1 on failure.
|
||||
// Idempotent: a second run changes nothing and saves nothing.
|
||||
[MenuItem("Aetheria/Text/Enable Ligatures")]
|
||||
public static void EnableLigatures()
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = TMP_Settings.fontFeatures;
|
||||
var settingsChanged = Enable(settings);
|
||||
if (settingsChanged) EditorUtility.SetDirty(TMP_Settings.instance);
|
||||
var (files, components) = VisitSerializedTexts(text =>
|
||||
{
|
||||
var features = text.fontFeatures.ToList();
|
||||
if (!Enable(features, new SerializedObject(text).FindProperty("m_enableKerning").boolValue)) return false;
|
||||
text.fontFeatures = features;
|
||||
EditorUtility.SetDirty(text);
|
||||
return true;
|
||||
});
|
||||
AssetDatabase.SaveAssets();
|
||||
Debug.Log($"EmojiFont: liga added to {components} TMP component(s) in {files} file(s)" +
|
||||
(settingsChanged ? " and to TMP Settings." : "; TMP Settings already had it."));
|
||||
if (Application.isBatchMode) EditorApplication.Exit(0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("EmojiFont.EnableLigatures failed: " + e);
|
||||
if (Application.isBatchMode) EditorApplication.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// A legacy list ([0], no feature serialized) is first converted to [kern] when kerning is on, as TMP does on load.
|
||||
static bool Enable(List<OTL_FeatureTag> features, bool kerning = true)
|
||||
{
|
||||
if (features.Contains(OTL_FeatureTag.liga)) return false;
|
||||
features.RemoveAll(tag => tag == 0);
|
||||
if (kerning && !features.Contains(OTL_FeatureTag.kern)) features.Add(OTL_FeatureTag.kern);
|
||||
features.Add(OTL_FeatureTag.liga);
|
||||
return true;
|
||||
}
|
||||
|
||||
// The one walk over every TMP text a serialized asset owns: each prefab and each scene under Assets/, skipping a
|
||||
// component that belongs to a prefab instance unless that instance overrides its font features (otherwise it
|
||||
// inherits from its source prefab, which is walked itself). `visit` returns whether it changed the component;
|
||||
// an asset that changed is saved. Returns the files and components changed.
|
||||
public static (int files, int components) VisitSerializedTexts(Func<TMP_Text, bool> visit)
|
||||
{
|
||||
int files = 0, components = 0;
|
||||
bool Owns(TMP_Text text) =>
|
||||
!PrefabUtility.IsPartOfPrefabInstance(text) ||
|
||||
new SerializedObject(text).FindProperty("m_ActiveFontFeatures")?.prefabOverride == true;
|
||||
int Visit(IEnumerable<TMP_Text> texts) => texts.Where(Owns).Count(visit);
|
||||
|
||||
foreach (var path in AssetDatabase.FindAssets("t:Prefab", new[] { "Assets" }).Select(AssetDatabase.GUIDToAssetPath))
|
||||
{
|
||||
var root = PrefabUtility.LoadPrefabContents(path);
|
||||
try
|
||||
{
|
||||
var changed = Visit(root.GetComponentsInChildren<TMP_Text>(true));
|
||||
if (changed == 0) continue;
|
||||
PrefabUtility.SaveAsPrefabAsset(root, path);
|
||||
files++;
|
||||
components += changed;
|
||||
}
|
||||
finally { PrefabUtility.UnloadPrefabContents(root); }
|
||||
}
|
||||
foreach (var path in AssetDatabase.FindAssets("t:Scene", new[] { "Assets" }).Select(AssetDatabase.GUIDToAssetPath))
|
||||
{
|
||||
var scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
|
||||
try
|
||||
{
|
||||
var changed = Visit(scene.GetRootGameObjects().SelectMany(root => root.GetComponentsInChildren<TMP_Text>(true)));
|
||||
if (changed == 0) continue;
|
||||
EditorSceneManager.SaveScene(scene);
|
||||
files++;
|
||||
components += changed;
|
||||
}
|
||||
finally { EditorSceneManager.CloseScene(scene, true); }
|
||||
}
|
||||
return (files, components);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ namespace Aetheria.EditorTools
|
|||
|
||||
static AbsorbEvent Absorb(Vector3 worldPos, Vector3 worldDir, float energy = 5f,
|
||||
DamageType type = DamageType.Kinetic)
|
||||
=> new AbsorbEvent(worldPos.ToCultMath(), worldDir.ToCultMath(), energy, type);
|
||||
=> new AbsorbEvent(worldPos.ToCultMath(), worldDir.ToCultMath(), energy, type, AbsorbLayer.Shield);
|
||||
|
||||
// ==============================================================
|
||||
// D17/D20: a panel struck in its own spawn frame must absorb that hit, not swallow it.
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ public class EntityInstance : MonoBehaviour
|
|||
|
||||
_subscriptions.Add(Entity.HullDamage.Subscribe(_ =>
|
||||
{
|
||||
if (Entity.Hull.Durability < .01f)
|
||||
if (Entity.Hull.IsDestroyed)
|
||||
{
|
||||
if (!this) return;
|
||||
_destroyed = true;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,12 @@
|
|||
using UnityEngine;
|
||||
using CultMath.UnityBridge;
|
||||
|
||||
// Cut 4 (docs/fire-control-cut.md): Hit, Splash, SendHit and SendSplash are deleted -- their last callers
|
||||
// (ConstantLaser, ConstantLightning, ConstantParticleWeapon, HitscanEffect) are gone too (see those
|
||||
// files and FireControl.Detonate, 12.4(b)'s renamed Splash). Nothing decides or applies damage through a Unity
|
||||
// collider any more (R8):
|
||||
// this component is now purely a physics surface for ship-on-ship collision impulse, not hit detection.
|
||||
// collider any more (R8), and no collision callback writes an Entity (cut sim-contact): ship contact is
|
||||
// Zone's, through Contacts.Step. This component holds the hull's collider for authoring, smokes and click
|
||||
// picking, and writes nothing.
|
||||
public class HullCollider : MonoBehaviour
|
||||
{
|
||||
public Entity Entity { get; set; }
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
Entity.Velocity += other.impulse.ToCultMath().xz / Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using CultMath;
|
||||
using CultMath.UnityBridge;
|
||||
using static CultMath.math;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShieldManager : MonoBehaviour
|
||||
|
|
@ -12,7 +13,29 @@ public class ShieldManager : MonoBehaviour
|
|||
public Prototype ShieldPrototype;
|
||||
public float CollisionHitDuration = 3;
|
||||
|
||||
public Entity Entity { get; set; }
|
||||
private Entity _entity;
|
||||
private IDisposable _contacts;
|
||||
|
||||
// Ship-on-ship contact is Zone's (Contacts.Step); this shield only presents it.
|
||||
public Entity Entity
|
||||
{
|
||||
get => _entity;
|
||||
set
|
||||
{
|
||||
_contacts?.Dispose();
|
||||
_entity = value;
|
||||
_contacts = value?.Zone.Contacted.Subscribe(Present);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy() => _contacts?.Dispose();
|
||||
|
||||
private void Present(ContactEvent contact)
|
||||
{
|
||||
if (contact.A != Entity && contact.B != Entity) return;
|
||||
if (Entity.Shield != null && Entity.Shield.Item.Active.Value)
|
||||
ShowHit(new Vector3(contact.Point.x, Entity.Position.y, contact.Point.y), CollisionHitDuration);
|
||||
}
|
||||
|
||||
private ShieldEnvelope _envelope;
|
||||
private bool _loggedMissingEnvelope;
|
||||
|
|
@ -60,24 +83,7 @@ public class ShieldManager : MonoBehaviour
|
|||
}
|
||||
else
|
||||
Debug.Log("Shield collision occurred, but other collider isn't a shield or a grid object!");
|
||||
return;
|
||||
}
|
||||
var contact = other.GetContact(0);
|
||||
var normal = normalize(float2(contact.normal.x, contact.normal.z));
|
||||
var tangent = normal.Rotate(ItemRotation.CounterClockwise);
|
||||
var v1n = dot(normal, Entity.Velocity);
|
||||
var v1t = dot(tangent, Entity.Velocity);
|
||||
var v2n = dot(normal, otherShield.Entity.Velocity);
|
||||
//var v2t = dot(tangent, otherShield.Entity.Velocity);
|
||||
|
||||
var v1np = PostCollisionVelocity(v1n, Entity.Mass, v2n, otherShield.Entity.Mass);
|
||||
Entity.Velocity = tangent * v1t + normal * v1np;
|
||||
if(Entity.Shield != null && Entity.Shield.Item.Active.Value) ShowHit(contact.point, CollisionHitDuration);
|
||||
}
|
||||
|
||||
private float PostCollisionVelocity(float v1, float m1, float v2, float m2)
|
||||
{
|
||||
return (v1 * (m1 - m2) + m2 * v2) / (m1 + m2);
|
||||
}
|
||||
|
||||
public void ShowHit(Vector3 point, float duration)
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class LockWeapon : InstantWeapon
|
|||
{
|
||||
var lerp = 1 - unlerp(0, 90, degrees);
|
||||
_lock = saturate(_lock + pow(lerp, DirectionImpact) * dt * LockSpeed * pow(Entity.EntityInfoGathered[target], SensorImpact));
|
||||
target.ReceivePaint(Entity.Position, Item?.Data, PaintMode.Track, Lock);
|
||||
target.ReceivePaint(Entity, Item, PaintMode.Track, Lock);
|
||||
}
|
||||
else _lock = saturate(_lock - dt * Decay);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ public class Sensor : Behavior, IEventBehavior, IPowerConsumer
|
|||
if (sweeping && dist < _pingRadius && _reached.Add(entity) && InBeam(diff, dist))
|
||||
{
|
||||
heard = true;
|
||||
entity.ReceivePaint(Entity.Position, Item?.Data, PaintMode.Search, 0);
|
||||
entity.ReceivePaint(Entity, Item, PaintMode.Search, 0);
|
||||
credit += Gain(entity.Visibility, sensitivity, response, dist, dt, true, obscuration);
|
||||
var pingReturn = new PingReturn(entity, dist, obscuration, Evaluate(_data.PingRange));
|
||||
foreach (var ally in Entity.Zone.Entities)
|
||||
|
|
|
|||
|
|
@ -7,30 +7,35 @@ using UniRx;
|
|||
using CultMath;
|
||||
|
||||
// Capability event contract (docs/headless-playground-cut.md fork L, operator ruling 2026-09-17):
|
||||
// pickup, impact absorption, melee blade and propulsion are separate item capabilities. Simulation
|
||||
// (not yet built -- this file only stands up the wire shape) will own each capability's rules and
|
||||
// emit these events; any number of presentations (the field shield today, later an IFS shatter
|
||||
// plane or an advected particle field) subscribe to the event kinds they visualize and decide
|
||||
// nothing about the rule. This file has no engine dependency: it compiles into the headless
|
||||
// Aetheria.Shared build (see Aetheria.Shared.csproj) with no publisher wired up yet.
|
||||
// pickup, impact absorption, melee blade and propulsion are separate item capabilities. Simulation owns
|
||||
// each capability's rules and emits these events (FireControl publishes Absorb; the others are not yet
|
||||
// built); any number of presentations (the field shield today, later an IFS shatter plane or an advected
|
||||
// particle field) subscribe to the event kinds they visualize and decide nothing about the rule. This file
|
||||
// has no engine dependency: it compiles into the headless Aetheria.Shared build (see Aetheria.Shared.csproj).
|
||||
|
||||
// One absorbed impact: a hit landing on the item's shield/armor capability. DamageType rides along
|
||||
// so presenters can vary visuals per type; the damage-type mask itself belongs to the absorb
|
||||
// capability's own data and is out of scope for this cut (operator, 2026-09-17) -- this struct only
|
||||
// carries the hit's existing type through, unfiltered.
|
||||
// Which layer of the receiver took an absorbed impact.
|
||||
public enum AbsorbLayer { Shield, Hull }
|
||||
|
||||
// One absorbed impact on a shield or a hull, published once per receiver by FireControl on that entity's
|
||||
// Entity.Capabilities. Position is a world point on the receiver's sim pose at the tick the impact lands (a
|
||||
// presenter draws it with DrawAhead.Carried); Direction is the way the impact travels. DamageType rides along
|
||||
// so presenters can vary visuals per type; the damage-type mask itself belongs to the absorb capability's own
|
||||
// data and is out of scope (operator, 2026-09-17) -- this struct only carries the hit's existing type through.
|
||||
public readonly struct AbsorbEvent
|
||||
{
|
||||
public readonly float3 Position;
|
||||
public readonly float3 Direction;
|
||||
public readonly float Magnitude;
|
||||
public readonly DamageType DamageType;
|
||||
public readonly AbsorbLayer Layer;
|
||||
|
||||
public AbsorbEvent(float3 position, float3 direction, float magnitude, DamageType damageType)
|
||||
public AbsorbEvent(float3 position, float3 direction, float magnitude, DamageType damageType, AbsorbLayer layer)
|
||||
{
|
||||
Position = position;
|
||||
Direction = direction;
|
||||
Magnitude = magnitude;
|
||||
DamageType = damageType;
|
||||
Layer = layer;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,10 +106,10 @@ public readonly struct ThrustEvent
|
|||
}
|
||||
}
|
||||
|
||||
// Per-entity (or per-item) source of capability events. One instance is owned by whatever will
|
||||
// eventually decide these rules; today the FieldShieldTest scene stands in for that owner. Follows
|
||||
// the Subject<T>-per-event-kind idiom already used on Entity (IncomingHit, HullDamage, etc): each
|
||||
// event kind gets its own stream, and a subscriber to one kind never sees another.
|
||||
// Per-entity source of capability events: one instance per Entity (Entity.Capabilities), published by
|
||||
// FireControl for Absorb; the FieldShieldTest scene keeps its own instance. Follows the Subject<T>-per-event-kind
|
||||
// idiom already used on Entity (IncomingHit, HullDamage, etc): each event kind gets its own stream, and a
|
||||
// subscriber to one kind never sees another.
|
||||
public class CapabilityEvents
|
||||
{
|
||||
private readonly Subject<AbsorbEvent> _absorb = new Subject<AbsorbEvent>();
|
||||
|
|
|
|||
79
Assets/Scripts/ServerShared/Contacts.cs
Normal file
79
Assets/Scripts/ServerShared/Contacts.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/* 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.Linq;
|
||||
using CultMath;
|
||||
using static CultMath.math;
|
||||
using float2 = CultMath.float2;
|
||||
|
||||
// A hull touching a hull (aetheria-release cut sim-contact; ruling unity-presents-only-r3): the simulation owns
|
||||
// contact between entities. Each hull is a disc about its centre of mass that bounds every occupied cell, and
|
||||
// two discs that touch while closing along the line between their centres take the normal impulse
|
||||
// j = -(1 + e)(v_rel . n) / (1/m1 + 1/m2) (ruling ship-bounce-restitution-setting): momentum is conserved, the
|
||||
// result is frame-independent, and a pair that has separated is not bounced again. e is
|
||||
// GameplaySettings.ContactRestitution.
|
||||
// Presentations read Zone.Contacted; no Unity collision callback writes an Entity.
|
||||
public readonly struct ContactEvent
|
||||
{
|
||||
public readonly Entity A;
|
||||
public readonly Entity B;
|
||||
public readonly float2 Point;
|
||||
// Unit vector from A to B.
|
||||
public readonly float2 Normal;
|
||||
|
||||
public ContactEvent(Entity a, Entity b, float2 point, float2 normal)
|
||||
{
|
||||
A = a;
|
||||
B = b;
|
||||
Point = point;
|
||||
Normal = normal;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Contacts
|
||||
{
|
||||
// The farthest corner of any occupied hull cell from the centre of mass the schematic frame uses, in world
|
||||
// units: a true bound on how far the hull reaches from Position (the half-diagonal of the bounding box is not,
|
||||
// as FireControl.Detonate's comment records). A cell at (x, y) spans x +/- .5 and y +/- .5.
|
||||
public static float Radius(Entity e)
|
||||
{
|
||||
var shape = e.HullData.Shape;
|
||||
var com = shape.CenterOfMass;
|
||||
var far = 0f;
|
||||
foreach (var c in shape.Coordinates)
|
||||
foreach (var (dx, dy) in new[] { (-.5f, -.5f), (.5f, -.5f), (-.5f, .5f), (.5f, .5f) })
|
||||
far = max(far, length(float2(c.x + dx, c.y + dy) - com));
|
||||
return far * e.ItemManager.GameplaySettings.SchematicCellSize;
|
||||
}
|
||||
|
||||
// For each unordered pair of the zone's entities, in list order: if their discs touch and are closing along
|
||||
// the normal, the impulse moves each one's velocity along the normal only (the tangent components are
|
||||
// untouched), and the contact is published. Pairs resolve one after another in list order, each from the
|
||||
// velocities the earlier pairs left, so a body touching two others in one tick depends on that order; the
|
||||
// total momentum does not. A docked entity (it has a Parent and takes its parent's pose) and an inactive one
|
||||
// are not hulls in the zone. No positional push-out.
|
||||
public static void Step(Zone zone)
|
||||
{
|
||||
var entities = zone.Entities.Where(e => e.Active && e.Parent == null).ToArray();
|
||||
var radii = entities.Select(Radius).ToArray();
|
||||
for (var i = 0; i < entities.Length; i++)
|
||||
for (var j = i + 1; j < entities.Length; j++)
|
||||
{
|
||||
var a = entities[i];
|
||||
var b = entities[j];
|
||||
var offset = b.Position.xz - a.Position.xz;
|
||||
var distance = length(offset);
|
||||
// Coincident centres have no normal.
|
||||
if (distance <= 0f || distance >= radii[i] + radii[j]) continue;
|
||||
var n = offset / distance;
|
||||
var closing = dot(n, b.Velocity - a.Velocity);
|
||||
if (closing >= 0f) continue;
|
||||
|
||||
var impulse = -(1f + a.ItemManager.GameplaySettings.ContactRestitution) * closing / (1f / a.Mass + 1f / b.Mass);
|
||||
a.Velocity -= n * (impulse / a.Mass);
|
||||
b.Velocity += n * (impulse / b.Mass);
|
||||
zone.Contacted.OnNext(new ContactEvent(a, b, a.Position.xz + n * radii[i], n));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Contacts.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Contacts.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7c1e5a3b9d4f4e2a8b6c0d1f2e3a4b5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -19,6 +19,10 @@ public static class DrawAhead
|
|||
? entity.Position
|
||||
: entity.Position + float3(entity.Velocity.x, 0, entity.Velocity.y) * lead;
|
||||
|
||||
// A free body (a vapour cloud) drawn where the frame falls lead sim seconds after the last step, by the velocity
|
||||
// that step moved it with: the launch velocity and the drift together.
|
||||
public static float2 Position(KinematicBody body, float lead) => body.Position + body.TotalVelocity * lead;
|
||||
|
||||
// The ship's rotation turned about its own up axis by the rate its last step turned, for lead seconds.
|
||||
public static quaternion Rotation(Ship ship, float lead) =>
|
||||
ship.WormholeAnimationInProgress ? ship.Rotation : Turned(ship.Rotation, ship.TurnRate * lead);
|
||||
|
|
@ -57,14 +61,22 @@ public static class DrawAhead
|
|||
return drawn + (end - drawn) * steer;
|
||||
}
|
||||
|
||||
// The impact cell's centre on the target's drawn pose: the cell at the sim pose, drawn ahead by the target's last
|
||||
// step velocity and turned by its last step turn for lead seconds, as Position and Rotation draw the entity.
|
||||
// The impact cell's centre on the target's drawn pose.
|
||||
public static float3 Impact(Entity target, int2 cell, float lead)
|
||||
{
|
||||
var world = target.ToWorldPoint((float2) cell);
|
||||
return Carried(target, float3(world.x, target.Position.y, world.y), lead);
|
||||
}
|
||||
|
||||
// A world point on the target's sim pose, moved and turned with the target for lead seconds exactly as Position and
|
||||
// Rotation draw the entity: the one owner of where a point on a hull is drawn, for the drawn round's end and for
|
||||
// impact presenters.
|
||||
public static float3 Carried(Entity target, float3 simPoint, float lead)
|
||||
{
|
||||
var at = Position(target, lead);
|
||||
var offset = target.ToWorldPoint((float2) cell) - target.Position.xz;
|
||||
var offset = float2(simPoint.x - target.Position.x, simPoint.z - target.Position.z);
|
||||
var turned = mul(offset, CultMath.float2x2.Rotate(Turn(target, lead)));
|
||||
return float3(at.x + turned.x, at.y, at.z + turned.y);
|
||||
return float3(at.x + turned.x, at.y + (simPoint.y - target.Position.y), at.z + turned.y);
|
||||
}
|
||||
|
||||
// Whether the drawn flight is over by time: only a published miss ends by the clock. A hit or burst ends on ShotResolved.
|
||||
|
|
|
|||
|
|
@ -173,6 +173,8 @@ public abstract class Entity
|
|||
VisibilitySources.Values.Where(s => s.Channel == channel).Sum(s => s.Strength);
|
||||
|
||||
public Subject<Entity> IncomingHit = new Subject<Entity>();
|
||||
// One per entity, created with it, never replaced: FireControl publishes each landed impact on it (Absorb).
|
||||
public readonly CapabilityEvents Capabilities = new CapabilityEvents();
|
||||
public Subject<(int2 pos, float damage)> ArmorDamage = new Subject<(int2, float)>();
|
||||
public Subject<(EquippedItem item, float damage)> ItemDamage = new Subject<(EquippedItem, float)>();
|
||||
// public Subject<EquippedItem> ItemOffline = new Subject<EquippedItem>();
|
||||
|
|
@ -189,7 +191,22 @@ public abstract class Entity
|
|||
// sweeping this ship (Sensor.Execute); a track paint is a lock (LockWeapon.Execute). Each reports into the
|
||||
// inbox the tick it paints; PublishInbox publishes the inbox once, so a warning lives exactly one tick after
|
||||
// its last paint.
|
||||
private readonly List<PaintWarning> _paintInbox = new List<PaintWarning>();
|
||||
// The inbox keeps who painted and with what beside the warning: the warning is all a reader of IncomingPaints
|
||||
// gets, the emitter and item are for PublishInbox, which records the emitter's reveal.
|
||||
private readonly struct PendingPaint
|
||||
{
|
||||
public readonly PaintWarning Warning;
|
||||
public readonly Entity Emitter;
|
||||
public readonly EquippedItem Item;
|
||||
|
||||
public PendingPaint(PaintWarning warning, Entity emitter, EquippedItem item)
|
||||
{
|
||||
Warning = warning;
|
||||
Emitter = emitter;
|
||||
Item = item;
|
||||
}
|
||||
}
|
||||
private readonly List<PendingPaint> _paintInbox = new List<PendingPaint>();
|
||||
private readonly List<PaintWarning> _incomingPaints = new List<PaintWarning>();
|
||||
public IReadOnlyList<PaintWarning> IncomingPaints => _incomingPaints;
|
||||
// An ally's sensor posts a return on the tick its ping crosses a subject; published with paints, read by this
|
||||
|
|
@ -197,6 +214,12 @@ public abstract class Entity
|
|||
private readonly List<PingReturn> _returnInbox = new List<PingReturn>();
|
||||
private readonly List<PingReturn> _pingReturns = new List<PingReturn>();
|
||||
internal IReadOnlyList<PingReturn> PingReturns => _pingReturns;
|
||||
// What this observer has seen each ship's items do (ruling visibility-per-capability-reveal), keyed (subject,
|
||||
// item). Written only by RecordReveal (an act enters) and EndReveals (an end the observer perceives, or a departed
|
||||
// subject's entries aged past BearingMemory), cleared by Deactivate (ruling reveal-ends-on-perception).
|
||||
private readonly Dictionary<Entity, Dictionary<EquippedItem, Reveal>> _reveals = new Dictionary<Entity, Dictionary<EquippedItem, Reveal>>();
|
||||
private readonly List<EquippedItem> _endedItems = new List<EquippedItem>();
|
||||
private readonly List<Entity> _agedSubjects = new List<Entity>();
|
||||
public ReactiveProperty<SecurityLevel> CurrentSecurityLevel = new ReactiveProperty<SecurityLevel>(SecurityLevel.Open);
|
||||
public ReadOnlyReactiveProperty<bool> PresencePermitted;
|
||||
|
||||
|
|
@ -395,22 +418,30 @@ public abstract class Entity
|
|||
|
||||
// Mining Cut 3 (Q14 A): this entity's info on a chunk, computed when asked and stored nowhere. It is the value
|
||||
// the per-tick sensor rule (Sensor.Execute, through Sensor.Gain) would settle at for a target this bright,
|
||||
// here, now. Each active sensor applies x <- saturate(x + G_i dt)(1 - k dt) every tick, so with n sensors the
|
||||
// info settles where the gain balances the decay: sum(G_i) / (n k), capped at 1. A ping adds nothing that
|
||||
// lasts, so only the passive gain enters.
|
||||
// here, now (PassiveInfo at the chunk's brightness), capped at 1.
|
||||
public float ChunkInfo(ChunkId chunk)
|
||||
{
|
||||
var visibility = Zone.ChunkVisibility(chunk);
|
||||
if (visibility <= 0f) return 0f;
|
||||
var position = Zone.ChunkPose(chunk.Field, chunk.Index).xy;
|
||||
return saturate(PassiveInfo(Zone.ChunkPose(chunk.Field, chunk.Index).xy, visibility));
|
||||
}
|
||||
|
||||
// The info a target of `signature` at `position` would settle at under this entity's passive sensing, before
|
||||
// the cap at 1. Each active sensor applies x <- saturate(x + G_i dt)(1 - k dt) every tick, so with n sensors the
|
||||
// info settles where the gain balances the decay: sum(G_i) / (n k). A ping adds nothing that lasts, so only the
|
||||
// passive gain enters. ChunkInfo asks it for a chunk's brightness; Sense asks it for a unit signature once per
|
||||
// ship, because it is linear in the signature below saturation and so answers for every act at a place. Zero
|
||||
// with no active sensor.
|
||||
public float PassiveInfo(float2 position, float signature)
|
||||
{
|
||||
var rate = 0f;
|
||||
var sensors = 0;
|
||||
foreach (var sensor in ActiveSensors())
|
||||
{
|
||||
rate += sensor.PassiveRate(visibility, position);
|
||||
rate += sensor.PassiveRate(signature, position);
|
||||
sensors++;
|
||||
}
|
||||
return sensors == 0 ? 0f : saturate(rate / (sensors * ItemManager.GameplaySettings.TargetInfoDecay));
|
||||
return sensors == 0 ? 0f : rate / (sensors * ItemManager.GameplaySettings.TargetInfoDecay);
|
||||
}
|
||||
|
||||
// Mining Cut 3: the detection threshold, read through the chunk path. A chunk is visible exactly as an entity
|
||||
|
|
@ -637,10 +668,25 @@ public abstract class Entity
|
|||
return max(gain, 0f) / (sensors * ItemManager.GameplaySettings.TargetInfoDecay * threshold) * 1.0001f;
|
||||
}
|
||||
|
||||
// Every sensor behaviour that runs this tick: those on active equipment, and those of active consumables.
|
||||
private IEnumerable<Sensor> ActiveSensors() =>
|
||||
Equipment.Where(item => item.Active.Value).SelectMany(item => item.Behaviors).OfType<Sensor>()
|
||||
.Concat(_activeConsumables.SelectMany(effect => effect.Behaviors).OfType<Sensor>());
|
||||
// Every sensor behaviour that runs this tick: those on active equipment, and those of active consumables. The
|
||||
// list is this entity's one buffer, refilled per call (Sense asks once per other ship per tick, allocating
|
||||
// nothing), so callers use it before asking again.
|
||||
private readonly List<Sensor> _activeSensors = new List<Sensor>();
|
||||
private List<Sensor> ActiveSensors()
|
||||
{
|
||||
_activeSensors.Clear();
|
||||
for (var i = 0; i < Equipment.Count; i++)
|
||||
{
|
||||
var item = Equipment[i];
|
||||
if (!item.Active.Value) continue;
|
||||
foreach (var behavior in item.Behaviors)
|
||||
if (behavior is Sensor sensor) _activeSensors.Add(sensor);
|
||||
}
|
||||
foreach (var effect in _activeConsumables)
|
||||
foreach (var behavior in effect.Behaviors)
|
||||
if (behavior is Sensor sensor) _activeSensors.Add(sensor);
|
||||
return _activeSensors;
|
||||
}
|
||||
|
||||
// Cut 12.3 (docs/fire-control-cut.md): "armour absorbs first" -- the per-cell armour phase, split out of
|
||||
// what used to be Absorb's own first half (moved verbatim from DamageSchematic's per-cell body, Cut 3) so
|
||||
|
|
@ -811,6 +857,7 @@ public abstract class Entity
|
|||
_incomingPaints.Clear();
|
||||
_returnInbox.Clear();
|
||||
_pingReturns.Clear();
|
||||
_reveals.Clear();
|
||||
}
|
||||
|
||||
// Zone.Update runs this on every entity before any entity updates, so a paint made during tick N is published
|
||||
|
|
@ -819,7 +866,11 @@ public abstract class Entity
|
|||
internal void PublishInbox()
|
||||
{
|
||||
_incomingPaints.Clear();
|
||||
_incomingPaints.AddRange(_paintInbox);
|
||||
foreach (var paint in _paintInbox)
|
||||
{
|
||||
_incomingPaints.Add(paint.Warning);
|
||||
RecordReveal(paint.Emitter, paint.Item, SignatureChannel.Emission);
|
||||
}
|
||||
_paintInbox.Clear();
|
||||
_pingReturns.Clear();
|
||||
_pingReturns.AddRange(_returnInbox);
|
||||
|
|
@ -833,11 +884,126 @@ public abstract class Entity
|
|||
}
|
||||
|
||||
// The callers are Sensor.Execute (a Search paint, Strength 0) and LockWeapon.Execute (a Track paint, Strength
|
||||
// the emitter's own Lock at that paint).
|
||||
internal void ReceivePaint(float3 emitterPosition, EquippableItemData emitterClass, PaintMode mode, float strength)
|
||||
// the emitter's own Lock at that paint). The emitter's class is the item's data (null with no item: a
|
||||
// consumable's effect, which has no item and so is never revealed).
|
||||
internal void ReceivePaint(Entity emitter, EquippedItem item, PaintMode mode, float strength)
|
||||
{
|
||||
if (!_active) return;
|
||||
_paintInbox.Add(new PaintWarning(normalize((emitterPosition - Position).xz), emitterClass, mode, strength));
|
||||
_paintInbox.Add(new PendingPaint(new PaintWarning(normalize((emitter.Position - Position).xz), item?.Data, mode, strength), emitter, item));
|
||||
}
|
||||
|
||||
// The reveal book's one way in and its one membership gate (callers: Sense and PublishInbox, both in this file):
|
||||
// this observer saw `item` of `subject` act on `channel`, now, from this bearing. An item-less act (hull
|
||||
// radiation, a consumable) reveals nothing, and neither does a subject that is not in the zone: a departed
|
||||
// subject's entries are never created or refreshed, from any caller, and neither does an item this observer
|
||||
// perceives destroyed (PerceivesDestroyed). A later act of the same item replaces the
|
||||
// earlier one.
|
||||
internal void RecordReveal(Entity subject, EquippedItem item, SignatureChannel channel)
|
||||
{
|
||||
if (!_active || item == null || !Zone.Entities.Contains(subject) || PerceivesDestroyed(subject, item)) return;
|
||||
if (!_reveals.TryGetValue(subject, out var book))
|
||||
_reveals[subject] = book = new Dictionary<EquippedItem, Reveal>();
|
||||
book[item] = new Reveal(item, channel, normalize((subject.Position - Position).xz), Zone.Time);
|
||||
}
|
||||
|
||||
// This observer resolves `subject`'s gear (ContactOf's Identified gate) and `item` of it is destroyed: the one rule
|
||||
// for a destroyed item an observer perceives, read by the book's entry (RecordReveal) and its end (Sense).
|
||||
private bool PerceivesDestroyed(Entity subject, EquippedItem item) =>
|
||||
item.EquippableItem.IsDestroyed
|
||||
&& EntityInfoGathered.TryGetValue(subject, out var info) && info >= ItemManager.GameplaySettings.TargetGearInfoThreshold;
|
||||
|
||||
// The book's one way out (caller: Sense): `item` null ends every reveal of `subject`, otherwise that item's.
|
||||
// The subject's key goes with its last entry.
|
||||
private void EndReveals(Entity subject, EquippedItem item)
|
||||
{
|
||||
if (!_reveals.TryGetValue(subject, out var book)) return;
|
||||
if (item != null) book.Remove(item);
|
||||
else book.Clear();
|
||||
if (book.Count == 0) _reveals.Remove(subject);
|
||||
}
|
||||
|
||||
// What this observer has seen `subject`'s items do: each item's latest act, and nothing the subject's present
|
||||
// gear or Durability says (ruling contact-reads-book-aim-reads-live). A reveal ends only on what this observer
|
||||
// perceives (ruling reveal-ends-on-perception): the destruction of an item of a ship it identifies, the death,
|
||||
// dock or warp of a subject its instruments could see leave, or, for a subject that has left the zone, the
|
||||
// freshest entry aging past BearingMemory; Deactivate clears it all. Whether an item can be aimed at now is
|
||||
// FireControl.IsRevealed's question, not this one.
|
||||
public IEnumerable<Reveal> RevealsOf(Entity subject) =>
|
||||
_reveals.TryGetValue(subject, out var book) ? book.Values : Enumerable.Empty<Reveal>();
|
||||
|
||||
// The one derivation of how much this observer holds of `subject`: see Contact.
|
||||
public Contact ContactOf(Entity subject)
|
||||
{
|
||||
var settings = ItemManager.GameplaySettings;
|
||||
var info = EntityInfoGathered.TryGetValue(subject, out var gathered) ? gathered : 0f;
|
||||
var tracked = VisibleEntities.Contains(subject);
|
||||
var any = false;
|
||||
var freshest = default(Reveal);
|
||||
foreach (var reveal in RevealsOf(subject))
|
||||
if (!any || reveal.Time > freshest.Time)
|
||||
{
|
||||
any = true;
|
||||
freshest = reveal;
|
||||
}
|
||||
var remembered = any && Zone.Time - freshest.Time < settings.BearingMemory;
|
||||
var detected = tracked || remembered;
|
||||
var bearing = tracked ? normalize((subject.Position - Position).xz) : remembered ? freshest.Bearing : default;
|
||||
return new Contact(detected, tracked, detected && any, info >= settings.TargetGearInfoThreshold, bearing, info);
|
||||
}
|
||||
|
||||
// What this observer's instruments receive of other ships' acts this tick (Zone.Update calls it once, after every
|
||||
// entity has updated): every light signature of an item that would alone settle this observer's passive info above
|
||||
// TargetDetectionInfoThreshold is revealed (ruling visibility-per-capability-reveal). Hull radiation names no
|
||||
// item and only feeds the track; an Emission entry is never light. One PassiveInfo per ship. Zone.Update calls it
|
||||
// for every entity after all of them have updated, so what a ship shows is what every observer receives on that
|
||||
// tick whatever order the zone lists them in.
|
||||
internal void Sense()
|
||||
{
|
||||
if (!_active) return;
|
||||
var threshold = ItemManager.GameplaySettings.TargetDetectionInfoThreshold;
|
||||
var entities = Zone.Entities;
|
||||
for (var i = 0; i < entities.Count; i++)
|
||||
{
|
||||
var other = entities[i];
|
||||
if (other == this) continue;
|
||||
var perSignature = -1f;
|
||||
foreach (var signature in other._visibilitySources.Values)
|
||||
{
|
||||
if (signature.Item == null || signature.Channel == SignatureChannel.Emission) continue;
|
||||
if (perSignature < 0f) perSignature = PassiveInfo(other.Position.xz, 1f);
|
||||
if (signature.Strength * perSignature > threshold) RecordReveal(other, signature.Item, signature.Channel);
|
||||
}
|
||||
// The observer resolves this ship's gear (PerceivesDestroyed), so it perceives an item of it destroyed and
|
||||
// that reveal ends here; RecordReveal refuses the same item's lingering flash.
|
||||
if (_reveals.TryGetValue(other, out var book))
|
||||
{
|
||||
foreach (var item in book.Keys)
|
||||
if (PerceivesDestroyed(other, item)) _endedItems.Add(item);
|
||||
for (var j = 0; j < _endedItems.Count; j++) EndReveals(other, _endedItems[j]);
|
||||
_endedItems.Clear();
|
||||
}
|
||||
}
|
||||
// A subject that left the zone (death, dock, warp, any removal) is perceived gone under the light-act gate: as
|
||||
// bright as its non-Emission signature was at removal, from where it was. A re-admitted subject did not leave.
|
||||
var departures = Zone.Departures;
|
||||
for (var i = 0; i < departures.Count; i++)
|
||||
{
|
||||
var departure = departures[i];
|
||||
if (!_reveals.ContainsKey(departure.Subject) || entities.Contains(departure.Subject)) continue;
|
||||
if (departure.Signature * PassiveInfo(departure.Position, 1f) > threshold) EndReveals(departure.Subject, null);
|
||||
}
|
||||
// What stays of a departed subject is memory: pruned once its freshest entry is as old as ContactOf stops
|
||||
// remembering it.
|
||||
var memory = ItemManager.GameplaySettings.BearingMemory;
|
||||
foreach (var pair in _reveals)
|
||||
{
|
||||
if (entities.Contains(pair.Key)) continue;
|
||||
var freshest = float.MinValue;
|
||||
foreach (var reveal in pair.Value.Values) freshest = Math.Max(freshest, reveal.Time);
|
||||
if (Zone.Time - freshest >= memory) _agedSubjects.Add(pair.Key);
|
||||
}
|
||||
for (var i = 0; i < _agedSubjects.Count; i++) EndReveals(_agedSubjects[i], null);
|
||||
_agedSubjects.Clear();
|
||||
}
|
||||
|
||||
public Entity(ItemManager itemManager, Zone zone, EquippableItem hull, EntitySettings settings)
|
||||
|
|
@ -854,10 +1020,10 @@ public abstract class Entity
|
|||
for(int i=0; i<itemManager.GameplaySettings.WeaponGroupCount; i++)
|
||||
WeaponGroups[i] = (new List<Weapon>(), new List<EquippedItem>());
|
||||
|
||||
ItemDestroyed = ItemDamage.Where(x => x.item.EquippableItem.Durability < .01f).Select(x=>x.item);
|
||||
ItemDestroyed = ItemDamage.Where(x => x.item.EquippableItem.IsDestroyed).Select(x=>x.item);
|
||||
WeaponDestroyed = ItemDestroyed.Select(x => x.Behaviors.FirstOrDefault(b => b is Weapon) as Weapon).Where(x => x != null);
|
||||
HullArmorDepleted = ArmorDamage.Where(x => Armor[x.pos.x, x.pos.y] < .01f).Select(x => x.pos);
|
||||
Death = HullDamage.Where(_ => Hull.Durability < .01f).Select(_ => CauseOfDeath.HullDestroyed)
|
||||
Death = HullDamage.Where(_ => Hull.IsDestroyed).Select(_ => CauseOfDeath.HullDestroyed)
|
||||
.Merge(HeatstrokeDeath.Select(_ => CauseOfDeath.Heatstroke))
|
||||
.Merge(HypothermiaDeath.Select(_ => CauseOfDeath.Hypothermia))
|
||||
.Merge(ItemDestroyed.Where(i=>i.GetBehavior<Cockpit>()!=null).Select(_ => CauseOfDeath.CockpitDestroyed))
|
||||
|
|
@ -2035,7 +2201,7 @@ public class EquippedItem : IStatContext
|
|||
deltaTemp * ItemManager.GameplaySettings.DeltaTempWearExponent
|
||||
) * Data.Durability / Data.ThermalResilience;
|
||||
ThermalOnline.Value = ThermalPerformance > performanceThreshold || Entity.OverrideShutdown && EquippableItem.OverrideShutdown;
|
||||
DurabilityOnline.Value = EquippableItem.Durability > .01f;
|
||||
DurabilityOnline.Value = !EquippableItem.IsDestroyed;
|
||||
oldTemperature = temp;
|
||||
}
|
||||
|
||||
|
|
|
|||
40
Assets/Scripts/ServerShared/Feedback.cs
Normal file
40
Assets/Scripts/ServerShared/Feedback.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* 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 CultMath;
|
||||
using static CultMath.math;
|
||||
|
||||
// What an impact presenter renders, derived once. Engine-free and never called by ServerShared: FireControl
|
||||
// publishes the fact (AbsorbEvent), this derives how it reads, and every presenter (visual, audio, camera) renders
|
||||
// the same cue instead of computing its own.
|
||||
public readonly struct ImpactCue
|
||||
{
|
||||
public readonly AbsorbLayer Layer;
|
||||
public readonly float3 Position;
|
||||
public readonly float3 Direction;
|
||||
public readonly float Intensity;
|
||||
public readonly float Shake;
|
||||
|
||||
public ImpactCue(AbsorbLayer layer, float3 position, float3 direction, float intensity, float shake)
|
||||
{
|
||||
Layer = layer;
|
||||
Position = position;
|
||||
Direction = direction;
|
||||
Intensity = intensity;
|
||||
Shake = shake;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Feedback
|
||||
{
|
||||
// Intensity is the hit's share of what the receiver's hull can take, scaled by the presenter and saturated to
|
||||
// 0..1; a receiver with no hull to measure against reads 0. Shake follows intensity for the player's own ship
|
||||
// only, scaled by the player's ScreenShake preference.
|
||||
public static ImpactCue Cue(AbsorbEvent e, float receiverMaxDurability, bool receiverIsPlayer, float shakePreference, float intensityScale)
|
||||
{
|
||||
var intensity = receiverMaxDurability > 0f ? saturate(e.Magnitude / receiverMaxDurability * intensityScale) : 0f;
|
||||
var shake = receiverIsPlayer ? intensity * saturate(shakePreference) : 0f;
|
||||
return new ImpactCue(e.Layer, e.Position, e.Direction, intensity, shake);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Feedback.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Feedback.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 51efa531176e4871835ae88104c92c85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -168,7 +168,7 @@ public static class FireControl
|
|||
// failing its own tier -- ranked.IndexOf(item) then returns -1 for it (the same "no longer on this
|
||||
// target" path below), and the survivors' tiers close up over the gap instead of leaving one.
|
||||
var ranked = target.Equipment
|
||||
.Where(e => e.Data.HardpointType != HardpointType.Hull && e.EquippableItem.Durability >= .01f)
|
||||
.Where(e => e.Data.HardpointType != HardpointType.Hull && !e.EquippableItem.IsDestroyed)
|
||||
.OrderByDescending(e => e.Data.HardpointType != HardpointType.Tool)
|
||||
.ThenByDescending(e => e.Data.Shape.Coordinates.Length)
|
||||
.ToList();
|
||||
|
|
@ -1163,6 +1163,8 @@ public static class FireControl
|
|||
|
||||
if (shot.Outcome.Shielded)
|
||||
{
|
||||
Publish(shot.Target, AbsorbLayer.Shield, ImpactPoint(shot.Target, shot.Outcome.Cell),
|
||||
float3(shot.TravelDirection.x, 0, shot.TravelDirection.y), shot.Damage, shot.DamageType);
|
||||
shot.Target.Shield.TakeHit(shot.DamageType, shot.Damage);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1206,9 +1208,31 @@ public static class FireControl
|
|||
|
||||
for (var li = 0; li < laneCount; li++) ArrayPool<LaneCell>.Shared.Return(buffers[li]);
|
||||
|
||||
Publish(target, AbsorbLayer.Hull, ImpactPoint(target, shot.Outcome.Cell),
|
||||
float3(shot.TravelDirection.x, 0, shot.TravelDirection.y), shot.Damage, shot.DamageType);
|
||||
target.DamageHull(hullDamage);
|
||||
}
|
||||
|
||||
// Where a landed direct hit meets the receiver: the impact cell's world point on its sim pose, at its height.
|
||||
private static float3 ImpactPoint(Entity target, int2 cell)
|
||||
{
|
||||
var world = target.ToWorldPoint((float2) cell);
|
||||
return float3(world.x, target.Position.y, world.y);
|
||||
}
|
||||
|
||||
// The one publisher of an absorbed impact: once per receiver, on its Capabilities, before the damage it reports.
|
||||
private static void Publish(Entity receiver, AbsorbLayer layer, float3 position, float3 direction, float magnitude, DamageType damageType) =>
|
||||
receiver.Capabilities.PublishAbsorb(new AbsorbEvent(position, direction, magnitude, damageType, layer));
|
||||
|
||||
// A blast's impact on one entity: at the blast point (on the entity's height), travelling from the blast out through
|
||||
// the entity's centre, or zero when they coincide.
|
||||
private static void PublishBlast(Entity entity, float2 blast, AbsorbLayer layer, float magnitude, DamageType damageType)
|
||||
{
|
||||
var away = entity.Position.xz - blast;
|
||||
var direction = lengthsq(away) > 0f ? normalize(away) : float2.zero;
|
||||
Publish(entity, layer, float3(blast.x, entity.Position.y, blast.y), float3(direction.x, 0, direction.y), magnitude, damageType);
|
||||
}
|
||||
|
||||
// Cut 12.4(b) (docs/fire-control-cut.md, "Where P is"): a contact or delayed blast needs a committed hit --
|
||||
// on a miss nothing happens, exactly like a direct hit's own gate. IncomingHit fires once, for the host,
|
||||
// before the blast is handed to Detonate (which then treats the host like any other entity in the radius:
|
||||
|
|
@ -1591,6 +1615,7 @@ public static class FireControl
|
|||
{
|
||||
if (shield.CanTakeHit(damageType, totalShare))
|
||||
{
|
||||
PublishBlast(entity, worldPlanar, AbsorbLayer.Shield, totalShare, damageType);
|
||||
shield.TakeHit(damageType, totalShare);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1620,6 +1645,7 @@ public static class FireControl
|
|||
for (var i = 0; i < amounts.Length; i++) hullTotal += amounts[i];
|
||||
}
|
||||
|
||||
PublishBlast(entity, worldPlanar, AbsorbLayer.Hull, totalShare, damageType);
|
||||
entity.DamageHull(hullTotal);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ public class EquippableItem : CraftedItemInstance
|
|||
[JsonProperty("durability"), Key(7)] public float Durability;
|
||||
[JsonProperty("override"), Key(8)] public bool OverrideShutdown;
|
||||
|
||||
// The one rule for a destroyed item: its wear is spent.
|
||||
[IgnoreMember] public bool IsDestroyed => Durability < .01f;
|
||||
|
||||
// Cut 5 (docs/stats-and-power-cut.md §1.3, §0b "A power tier"): a player choice, stored on the unit rather
|
||||
// than the design, so two units of the same design can be prioritized differently. PowerTiers.Unassigned
|
||||
// until the first equip seeds a behaviour-kind default (EquippedItem's constructor) or the player overrides
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ public class PlayerGraphicsSettings
|
|||
{
|
||||
[Key(0)] public Quality NebulaQuality = Quality.Normal;
|
||||
[Key(1)] public bool ShowAsteroidsInMinimap;
|
||||
// How hard the camera shakes when the player's ship takes an impact: 0 off, 1 full (Feedback.Cue).
|
||||
[Key(2)] public float ScreenShake = 1f;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
48
Assets/Scripts/ServerShared/Scenarios/Belt.cs
Normal file
48
Assets/Scripts/ServerShared/Scenarios/Belt.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System.Linq;
|
||||
using static CultMath.math;
|
||||
using static ItemRotation;
|
||||
|
||||
public sealed class Belt : Scenario
|
||||
{
|
||||
public override string Name => "Belt";
|
||||
public override string Brief => "The biggest asteroid belt the generator made, with the Longinus parked 100 m outside its ring, facing along it, " +
|
||||
"and nothing else in the arena. Verify: next and previous target step through the rocks and the reticle sweeps " +
|
||||
"across the belt without a hitch; Previous with nothing targeted takes the farthest rock; the target indicator " +
|
||||
"sits on the rock it names.";
|
||||
|
||||
// Seeds 1-256 scanned for the arena whose entrance zone holds the belt with the most asteroids: seed 24, a belt of
|
||||
// 615 rocks. The next four: 179 (553), 251 (548), 221 (532), 29 (515).
|
||||
public override uint Seed => 24;
|
||||
public override bool Ambient => false;
|
||||
|
||||
public override Galaxy Generate(GalaxyStage stage) => stage.Prelude(DemoTerminus.Cast);
|
||||
|
||||
public override void Stage(ScenarioStage stage)
|
||||
{
|
||||
var fighter = stage.Fit("Longinus",
|
||||
("Cockpit 2x2", int2(2, 6), None),
|
||||
("Large Drive", int2(1, 0), Reversed),
|
||||
("Large Drive", int2(3, 0), Reversed),
|
||||
("Talaria", int2(2, 14), CounterClockwise),
|
||||
("Talaria", int2(3, 14), Clockwise),
|
||||
("Core Power", int2(2, 4), None),
|
||||
("GT 3K", int2(0, 5), None),
|
||||
("GT 3K", int2(5, 5), None),
|
||||
("plight", int2(1, 8), None),
|
||||
("FastBlast+-", int2(4, 8), None),
|
||||
("Iapyx", int2(2, 2), CounterClockwise),
|
||||
("Iapyx", int2(3, 2), Clockwise),
|
||||
("not if i see you first", int2(3, 10), None),
|
||||
("Fire Control Array", int2(1, 6), Clockwise));
|
||||
|
||||
// The belt is a ring about its parent's position at the belt orbit's distance. The player stands 100 m outside
|
||||
// it, at the point nearest the origin, facing along the ring.
|
||||
var arena = stage.Arena;
|
||||
var belt = arena.Planets.Values.OfType<AsteroidBeltData>().OrderByDescending(candidate => candidate.Asteroids.Length).First();
|
||||
var orbit = arena.Orbits[belt.Orbit.Key].Data;
|
||||
var centre = arena.GetOrbitPosition(orbit.Parent.Key);
|
||||
var outward = lengthsq(centre) > 0f ? normalize(-centre) : float2(1, 0);
|
||||
var at = centre + outward * (orbit.Distance + 100f);
|
||||
stage.Player(fighter, at, facing: float2(-outward.y, outward.x));
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Scenarios/Belt.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Scenarios/Belt.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6177c598b87544d6bb0cefdfb4f01acc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -9,6 +9,6 @@ public static class Scenarios
|
|||
|
||||
public static readonly Scenario[] Tests =
|
||||
{
|
||||
new DjinniShakedown(), new StarvedReactor(), new Arcs(), new Duel(), new LauncherAngles(), new WeaponFeel(), new LongHaul(), new Pursuit(), new Crossing()
|
||||
new DjinniShakedown(), new StarvedReactor(), new Arcs(), new Duel(), new LauncherAngles(), new WeaponFeel(), new LongHaul(), new Pursuit(), new Crossing(), new Belt()
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,3 +73,63 @@ public readonly struct PaintWarning
|
|||
Strength = strength;
|
||||
}
|
||||
}
|
||||
|
||||
// What an observer has seen `Item` do (ruling visibility-per-capability-reveal): the channel it showed on, the
|
||||
// bearing at that act and the zone clock then. Held per (subject, item) in the observer's Entity; the latest act
|
||||
// replaces the earlier one. Position is never carried: only the track gives it.
|
||||
public readonly struct Reveal
|
||||
{
|
||||
public readonly EquippedItem Item;
|
||||
public readonly SignatureChannel Channel;
|
||||
public readonly float2 Bearing;
|
||||
public readonly float Time;
|
||||
|
||||
public Reveal(EquippedItem item, SignatureChannel channel, float2 bearing, float time)
|
||||
{
|
||||
Item = item;
|
||||
Channel = channel;
|
||||
Bearing = bearing;
|
||||
Time = time;
|
||||
}
|
||||
}
|
||||
|
||||
// A subject's removal from a zone as the zone recorded it (death, dock, warp, any removal): where it was and how
|
||||
// bright its light was (its signature outside the Emission channel). Judged by each observer's Sense under the
|
||||
// light-act gate; notification only, one tick long, it decides nothing.
|
||||
public readonly struct Departure
|
||||
{
|
||||
public readonly Entity Subject;
|
||||
public readonly float2 Position;
|
||||
public readonly float Signature;
|
||||
|
||||
public Departure(Entity subject, float2 position, float signature)
|
||||
{
|
||||
Subject = subject;
|
||||
Position = position;
|
||||
Signature = signature;
|
||||
}
|
||||
}
|
||||
|
||||
// How much an observer holds of one subject, derived on read by Entity.ContactOf from its track, its reveals and
|
||||
// the zone clock. Detected: tracked, or a reveal younger than GameplaySettings.BearingMemory. Tracked: exactly
|
||||
// membership of VisibleEntities. Classified: detected, with any reveal in the book. Identified: the track has reached
|
||||
// TargetGearInfoThreshold. Bearing is the true bearing while tracked, else the freshest reveal's.
|
||||
public readonly struct Contact
|
||||
{
|
||||
public readonly bool Detected;
|
||||
public readonly bool Tracked;
|
||||
public readonly bool Classified;
|
||||
public readonly bool Identified;
|
||||
public readonly float2 Bearing;
|
||||
public readonly float Info;
|
||||
|
||||
public Contact(bool detected, bool tracked, bool classified, bool identified, float2 bearing, float info)
|
||||
{
|
||||
Detected = detected;
|
||||
Tracked = tracked;
|
||||
Classified = classified;
|
||||
Identified = identified;
|
||||
Bearing = bearing;
|
||||
Info = info;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,9 +218,12 @@ public class GameplaySettings
|
|||
public ExponentialLerp LockSpinSpeed;
|
||||
public float TorqueMultiplier;
|
||||
public float VisibilityDecay;
|
||||
// Seconds a reveal's bearing keeps a ship Detected after its last act with no track (Entity.ContactOf).
|
||||
public float BearingMemory = 6;
|
||||
public float TargetInfoDecay;
|
||||
public float TargetDetectionInfoThreshold;
|
||||
public float TargetArmorInfoThreshold;
|
||||
// Also the Identified threshold: the track level at which a ship's hull class, and with it its layout, is known.
|
||||
public float TargetGearInfoThreshold;
|
||||
public float ConvergenceMinimumDistance;
|
||||
public float FiringArc = 120;
|
||||
|
|
@ -270,6 +273,10 @@ public class GameplaySettings
|
|||
// (pSpread) to turn a hull's cell footprint into a real-world silhouette size at range.
|
||||
public float SchematicCellSize = 2f;
|
||||
|
||||
// Restitution of a hull striking a hull (Contacts.Step): the speed at which a pair separates along the contact
|
||||
// normal is this times the speed at which it closed. 0 is perfectly inelastic, 1 perfectly elastic.
|
||||
public float ContactRestitution = .5f;
|
||||
|
||||
// The floor an AI's own predicted hit probability (FireControl.HitProbability) must clear before it counts
|
||||
// a firing solution worth taking (Combat.cs, TurretController.cs). Player fire is gated on arc alone
|
||||
// (Weapon.ArcAllowsFire, Q2) -- this threshold is an AI fire-discipline heuristic, not part of the roll.
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ public class Zone
|
|||
public List<PendingShot> PendingShots = new List<PendingShot>();
|
||||
public Subject<ShotOutcome> ShotCommitted = new Subject<ShotOutcome>();
|
||||
public Subject<ShotOutcome> ShotResolved = new Subject<ShotOutcome>();
|
||||
// Contacts.Step publishes each hull-on-hull contact it resolves; presentations are the only readers.
|
||||
public Subject<ContactEvent> Contacted = new Subject<ContactEvent>();
|
||||
private int _nextShotId;
|
||||
public int NextShotId() => ++_nextShotId;
|
||||
|
||||
|
|
@ -76,6 +78,9 @@ public class Zone
|
|||
return false;
|
||||
}
|
||||
|
||||
private readonly List<Departure> _departures = new List<Departure>();
|
||||
internal IReadOnlyList<Departure> Departures => _departures;
|
||||
|
||||
public float Time
|
||||
{
|
||||
get => (float) _time;
|
||||
|
|
@ -100,6 +105,21 @@ public class Zone
|
|||
// The death ordinal of the loot dice: the nth death in this zone rolls on SimulationDice.For(CombatSeed, LootStream, n).
|
||||
private uint _deaths;
|
||||
|
||||
// One death subscription per member entity, owned here: WatchDeath installs it, UnwatchDeath (the entity leaving
|
||||
// Entities) disposes it, and nothing else touches it.
|
||||
private readonly Dictionary<Entity, IDisposable> _deathWatches = new Dictionary<Entity, IDisposable>();
|
||||
|
||||
private void WatchDeath(Entity entity)
|
||||
{
|
||||
UnwatchDeath(entity);
|
||||
_deathWatches[entity] = entity.Death.Subscribe(_ => { DropLoot(entity); Entities.Remove(entity); entity.Deactivate(); });
|
||||
}
|
||||
|
||||
private void UnwatchDeath(Entity entity)
|
||||
{
|
||||
if (_deathWatches.Remove(entity, out var watch)) watch.Dispose();
|
||||
}
|
||||
|
||||
public Zone(ItemManager itemManager, PlanetSettings settings, ZonePack pack, GalaxyZone galaxyZone, Galaxy galaxy)
|
||||
{
|
||||
_time = pack.Time;
|
||||
|
|
@ -115,7 +135,13 @@ public class Zone
|
|||
// in the simulation, not only in Unity's own loot-drop subscription. One subscription point covers
|
||||
// every join, whichever caller admits the entity (deserialization below, a jump, a spawned turret) --
|
||||
// ObserveAdd fires for all of them. Forbidden writer: no presentation may remove an entity from Zone.
|
||||
Entities.ObserveAdd().Subscribe(add => add.Value.Death.Subscribe(_ => { DropLoot(add.Value); Entities.Remove(add.Value); add.Value.Deactivate(); }));
|
||||
// The death watch lives exactly as long as the entity's membership in this zone: installed on admission,
|
||||
// disposed on removal (death, dock, jump), so an entity admitted again never holds a second one.
|
||||
Entities.ObserveAdd().Subscribe(add => WatchDeath(add.Value));
|
||||
Entities.ObserveRemove().Subscribe(remove => UnwatchDeath(remove.Value));
|
||||
// The one record of a removal for observers (ruling reveal-ends-on-perception): read by the next Sense pass.
|
||||
Entities.ObserveRemove().Subscribe(remove => _departures.Add(new Departure(remove.Value, remove.Value.Position.xz,
|
||||
remove.Value.Visibility - remove.Value.SignatureOn(SignatureChannel.Emission))));
|
||||
|
||||
Targets.Add(new EntityTargets());
|
||||
|
||||
|
|
@ -236,11 +262,17 @@ public class Zone
|
|||
var entities = Entities.ToArray();
|
||||
foreach (var entity in entities) entity.PublishInbox();
|
||||
foreach (var entity in entities) entity.Update(deltaTime);
|
||||
foreach (var entity in entities) entity.Sense();
|
||||
_departures.Clear();
|
||||
|
||||
StepMines(deltaTime);
|
||||
StepClouds(deltaTime);
|
||||
StepFloatingItems(deltaTime);
|
||||
|
||||
// Hull contact (cut sim-contact): after every entity has moved and the mines and clouds have taken
|
||||
// their toll, so only hulls still in the zone touch, and before shots resolve against the result.
|
||||
Contacts.Step(this);
|
||||
|
||||
// Cut 3: after every entity has had its chance to fire this tick, age and resolve the shots that
|
||||
// firing queued. A shot fired this tick with a flight time shorter than CommitHorizon commits and
|
||||
// resolves in this same call.
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class FieldTester : MonoBehaviour
|
|||
{
|
||||
var damageType = DamageTypeCycle[_nextDamageTypeIndex];
|
||||
_nextDamageTypeIndex = (_nextDamageTypeIndex + 1) % DamageTypeCycle.Length;
|
||||
_capabilityEvents.PublishAbsorb(new AbsorbEvent(hit.point.ToCultMath(), ray.direction.ToCultMath(), TestField.TestMagnitude, damageType));
|
||||
_capabilityEvents.PublishAbsorb(new AbsorbEvent(hit.point.ToCultMath(), ray.direction.ToCultMath(), TestField.TestMagnitude, damageType, AbsorbLayer.Shield));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -386,7 +386,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
|
||||
private void AddEquippableItemProperties(EquippableItem item, Func<PerformanceStat, float> statValueFunction)
|
||||
{
|
||||
if (item.Durability < .01f)
|
||||
if (item.IsDestroyed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -473,7 +473,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
|
||||
var gearData = GameManager.ItemManager.GetData(item.EquippableItem);
|
||||
var statusSheet = AddStatSheet();
|
||||
if (item.EquippableItem.Durability < .01f)
|
||||
if (item.EquippableItem.IsDestroyed)
|
||||
statusSheet.AddStat("Durability", () => "Item Destroyed!");
|
||||
else statusSheet.AddStat("Durability", () => $"{(int)(item.EquippableItem.Durability / gearData.Durability * 100)}%");
|
||||
statusSheet.AddStat("Temperature", () => ActionGameManager.PlayerSettings.FormatTemperature(item.Temperature));
|
||||
|
|
|
|||
44
Assets/Scripts/Zone Display/VapourCloudInstance.cs
Normal file
44
Assets/Scripts/Zone Display/VapourCloudInstance.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using CultMath;
|
||||
using CultMath.UnityBridge;
|
||||
using UnityEngine;
|
||||
|
||||
// How one vented vapour cloud looks: a fog-bank brush painted into the Patch layer, which the volumetric pass reads as
|
||||
// patch thickness. Zone owns every cloud fact (existence, body, radius, opacity); this reads them and draws, and writes
|
||||
// nothing back (rulings vapour-cloud-obscuration, unity-presents-only-r3). The brush's depth scales with the sim's OpacityAt, so the bank fades to nothing at the cloud's lifetime.
|
||||
public class VapourCloudInstance : MonoBehaviour
|
||||
{
|
||||
// The world height the scene's patch brushes sit at (Depth Micro), inside the Patch camera's clip range.
|
||||
public float PatchHeight = -5f;
|
||||
|
||||
private static readonly int Depth = Shader.PropertyToID("_Depth");
|
||||
|
||||
private Zone _zone;
|
||||
private VapourCloud _cloud;
|
||||
private MeshRenderer _renderer;
|
||||
private MaterialPropertyBlock _block;
|
||||
private float _authoredDepth;
|
||||
|
||||
public void Bind(Zone zone, VapourCloud cloud)
|
||||
{
|
||||
_zone = zone;
|
||||
_cloud = cloud;
|
||||
_renderer = GetComponent<MeshRenderer>();
|
||||
_block = new MaterialPropertyBlock();
|
||||
_authoredDepth = _renderer.sharedMaterial.GetFloat(Depth);
|
||||
Place();
|
||||
}
|
||||
|
||||
private void Update() => Place();
|
||||
|
||||
private void Place()
|
||||
{
|
||||
var p = DrawAhead.Position(_cloud.Body, ActionGameManager.Clock.Lead);
|
||||
transform.position = new Vector3(p.x, PatchHeight, p.y);
|
||||
transform.localScale = Vector3.one * (2f * _cloud.Radius);
|
||||
|
||||
// The sim's own opacity, already saturated to 0..1 (VapourCloud.OpacityAt); the presenter adds no rule of its own.
|
||||
_renderer.GetPropertyBlock(_block);
|
||||
_block.SetFloat(Depth, _authoredDepth * _cloud.OpacityAt(_zone.Time));
|
||||
_renderer.SetPropertyBlock(_block);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Zone Display/VapourCloudInstance.cs.meta
Normal file
2
Assets/Scripts/Zone Display/VapourCloudInstance.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a792b8f456004d04997a26557b338d1c
|
||||
|
|
@ -45,6 +45,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
public GridObject GearPickup;
|
||||
public GridObject WeaponPickup;
|
||||
public MineInstance MinePrefab;
|
||||
public VapourCloudInstance CloudPrefab;
|
||||
public Material[] MapGravityMaterials;
|
||||
|
||||
[Header("Tour")] public bool Tour;
|
||||
|
|
@ -95,6 +96,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
public Dictionary<Wormhole, (GameObject gravity, CompassIcon icon)> WormholeInstances = new Dictionary<Wormhole, (GameObject, CompassIcon)>();
|
||||
private List<ItemPickup> _loot = new List<ItemPickup>();
|
||||
private Dictionary<Mine, MineInstance> _mines = new Dictionary<Mine, MineInstance>();
|
||||
private Dictionary<VapourCloud, VapourCloudInstance> _clouds = new Dictionary<VapourCloud, VapourCloudInstance>();
|
||||
|
||||
public Zone Zone { get; private set; }
|
||||
public ItemManager ItemManager { get; set; }
|
||||
|
|
@ -234,6 +236,15 @@ public class ZoneRenderer : MonoBehaviour
|
|||
instance.Blast();
|
||||
}));
|
||||
|
||||
// Every vapour cloud, whoever vented it, is drawn through this one subscription. A cloud leaves Zone.Clouds
|
||||
// when its opacity has reached nothing, so a removal destroys its fog bank with nothing left to show.
|
||||
foreach (var cloud in zone.Clouds) LoadCloud(zone, cloud);
|
||||
_zoneSubscriptions.Add(zone.Clouds.ObserveAdd().Subscribe(e => LoadCloud(zone, e.Value)));
|
||||
_zoneSubscriptions.Add(zone.Clouds.ObserveRemove().Subscribe(e =>
|
||||
{
|
||||
if (_clouds.Remove(e.Value, out var instance)) Destroy(instance.gameObject);
|
||||
}));
|
||||
|
||||
if (zone.GalaxyZone != null)
|
||||
{
|
||||
foreach (var adjacentZone in zone.GalaxyZone.AdjacentZones)
|
||||
|
|
@ -263,6 +274,13 @@ public class ZoneRenderer : MonoBehaviour
|
|||
_mines.Add(mine, instance);
|
||||
}
|
||||
|
||||
private void LoadCloud(Zone zone, VapourCloud cloud)
|
||||
{
|
||||
var instance = Instantiate(CloudPrefab);
|
||||
instance.Bind(zone, cloud);
|
||||
_clouds.Add(cloud, instance);
|
||||
}
|
||||
|
||||
public void AddWormhole(Wormhole wormhole)
|
||||
{
|
||||
var instance = Instantiate(WormholePrefab);
|
||||
|
|
@ -290,6 +308,10 @@ public class ZoneRenderer : MonoBehaviour
|
|||
if (instance) Destroy(instance.gameObject);
|
||||
_mines.Clear();
|
||||
|
||||
foreach (var instance in _clouds.Values)
|
||||
if (instance) Destroy(instance.gameObject);
|
||||
_clouds.Clear();
|
||||
|
||||
foreach(var gridObject in _loot)
|
||||
if(gridObject) Destroy(gridObject.gameObject);
|
||||
_loot.Clear();
|
||||
|
|
|
|||
Loading…
Reference in a new issue