Facility: on screen an ore rig works the rocks, off screen its recipes run by span
A rig whose run list is all raw ore works the zone's first whole rock (belt Site, then index) through Zone.Wear and FireControl.Extract, the player's own mining, at Production.OreRate (Facility.Work); the unit's FacilityRun is left alone and a cycle begun off screen resumes when the zone is. RegionClock calls Facility.Span, always Production.Advance, so off screen the same rig starts its recipes by the deposit pick. Any other list, a skimmer's included, runs Advance in both. Dice for the ore a rig's wear pays: SimulationDice.RigStream. ExtractionTests pins the pick, the per-unit weight, the gate, Barren, Cycles in a pack, the zone's deposits, the on-screen wear, the agreement of both rates, the full-bay stop, the skimmer's spans against steps, OreRate against what Advance averages, and the batch. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b4e25c5821
commit
6004fbc8d8
4 changed files with 585 additions and 6 deletions
|
|
@ -1,4 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
|
@ -19,10 +22,18 @@ public class FacilityData : BehaviorData
|
|||
}
|
||||
|
||||
// The installed facility (ruling demand-consumed-inputs-processed-by-facilities). It ticks once per zone step, from EquippedItem.Update
|
||||
// while the item is active, on screen; off screen RegionClock.AdvanceInstalled calls Execute with the span the zone missed. Its recipes are the run list of its design, fixed for a run because the catalog is.
|
||||
// while the item is active, on screen; off screen RegionClock.AdvanceInstalled calls Span with the span the zone missed. Its recipes are
|
||||
// the run list of its design, fixed for a run because the catalog is.
|
||||
//
|
||||
// Two paths, by where the zone is (ruling auto-mining-is-off-screen-only). Off screen every facility advances by Production.Advance:
|
||||
// an ore rig's raw recipes start by the deposit pick. On screen a run list of nothing but raw ore works the zone's rocks instead (Work),
|
||||
// through Zone.Wear and FireControl.Extract, the player's own mining, at Production.OreRate, the rate Advance's pick averages to; the
|
||||
// player sees the rocks break, and the unit's FacilityRun is left as the off-screen path last wrote it. Any other list, a skimmer's
|
||||
// included (ruling skimmers-run-their-recipe-on-screen-for-now), runs Advance in both.
|
||||
public class Facility : Behavior
|
||||
{
|
||||
private IReadOnlyList<RecipeData> _runList;
|
||||
private bool _mines;
|
||||
private EntityHold _hold;
|
||||
|
||||
// Why the facility advanced no further this step: derived by Advance every step, never stored on the unit.
|
||||
|
|
@ -37,23 +48,76 @@ public class Facility : Behavior
|
|||
|
||||
public Facility(FacilityData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_runList = Production.RunList(ItemManager.ItemData, Item.EquippableItem.Data.Key);
|
||||
SetRunList();
|
||||
}
|
||||
|
||||
// The run list as the catalog holds it, and whether it is all raw ore: the lists that work rocks on screen.
|
||||
private void SetRunList()
|
||||
{
|
||||
_runList = Production.RunList(ItemManager.ItemData, Item.EquippableItem.Data.Key);
|
||||
_mines = _runList.Count > 0 && _runList.All(recipe => Recipes.IsRaw(ItemManager.ItemData, recipe)
|
||||
&& ItemManager.ItemData.Get(recipe.Output) is SimpleCommodityData output && FieldKinds.IsOre(ItemManager.ItemData, output));
|
||||
}
|
||||
|
||||
// The on-screen step: one zone step.
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
if (_mines) Work(dt);
|
||||
else Advance(dt);
|
||||
return true;
|
||||
}
|
||||
|
||||
// The off-screen step: the span the zone missed, always the recipe rule.
|
||||
public void Span(double seconds) => Advance(seconds);
|
||||
|
||||
// The rock an ore rig works, in sim time dt: the first whole rock in belt Site then index order (the order Deposits reads the
|
||||
// belts in) takes the damage that owes OreRate x dt units (what FireControl.Extract pays for the damage it absorbs), and Extract pays
|
||||
// the station by dice of its own stream. Barren with no whole rock or no ore the ground holds; Room, with nothing worn, when no bay
|
||||
// has a cell for any of its ores. A cycle begun off screen resumes when the zone is off screen again.
|
||||
private void Work(double dt)
|
||||
{
|
||||
_hold ??= new EntityHold(Entity);
|
||||
var catalog = ItemManager.ItemData;
|
||||
var zone = Entity.Zone;
|
||||
var rate = Production.OreRate(catalog, _runList, _hold);
|
||||
if (zone == null || !(rate > 0)) { Stall = Stall.Barren; return; }
|
||||
|
||||
var rock = default(ChunkId);
|
||||
var found = false;
|
||||
foreach (var belt in zone.AsteroidBelts.OrderBy(entry => entry.Value.Data.SiteOr(entry.Key), StringComparer.Ordinal))
|
||||
{
|
||||
for (var index = 0; index < belt.Value.Data.Asteroids.Length && !found; index++)
|
||||
if (zone.ChunkExists(rock = new ChunkId(belt.Key, index))) found = true;
|
||||
if (found) break;
|
||||
}
|
||||
if (!found) { Stall = Stall.Barren; return; }
|
||||
|
||||
var room = _runList.Any(recipe => _hold.Deposit(recipe.Output.Key) > 0f && Entity.CargoBays.Any(bay =>
|
||||
bay.TryFindSpace(new SimpleCommodity { Data = new CultRecordRef<ItemData>(recipe.Output.Key), Quantity = 1 })));
|
||||
if (!room) { Stall = Stall.Room; return; }
|
||||
|
||||
var settings = zone.Settings;
|
||||
var size = ((AsteroidBeltData) zone.Planets[rock.Field]).Asteroids[rock.Index].Size;
|
||||
var damage = (float) (rate * dt / settings.AsteroidYield.Evaluate(size) * settings.AsteroidHitpoints.Evaluate(size));
|
||||
var place = Entity.Equipment.IndexOf(Item);
|
||||
var ordinal = SimulationDice.Mix(unchecked((uint) (long) Math.Floor(zone.ExactTime * 1000))) ^ (uint) place;
|
||||
FireControl.Extract(zone, rock, zone.Wear(rock, damage), Entity, SimulationDice.For(zone.DropSeed, SimulationDice.RigStream, ordinal));
|
||||
Stall = Stall.None;
|
||||
}
|
||||
|
||||
private void Advance(double seconds)
|
||||
{
|
||||
_hold ??= new EntityHold(Entity);
|
||||
var idle = Item.EquippableItem.Run == null || Item.EquippableItem.Run.Progress <= 0;
|
||||
if (idle && Stall == Stall.Inputs && _hold.Revision == _failedAt) return true;
|
||||
if (idle && Stall == Stall.Inputs && _hold.Revision == _failedAt) return;
|
||||
Attempts++;
|
||||
// A running cycle whose recipe left the catalog or stopped running here is dropped by Advance: the list it was built from is
|
||||
// stale, so it is rebuilt from the catalog before that step.
|
||||
if (!idle && Production.Live(ItemManager.ItemData, Item.EquippableItem.Run.Recipe) == null)
|
||||
_runList = Production.RunList(ItemManager.ItemData, Item.EquippableItem.Data.Key);
|
||||
var (run, stall) = Production.Advance(ItemManager.ItemData, _runList, Item.EquippableItem.Run, dt, _hold);
|
||||
SetRunList();
|
||||
var (run, stall) = Production.Advance(ItemManager.ItemData, _runList, Item.EquippableItem.Run, seconds, _hold);
|
||||
Item.EquippableItem.Run = run;
|
||||
Stall = stall;
|
||||
if (idle && stall == Stall.Inputs) _failedAt = _hold.Revision;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue