Skip to content

Commit

Permalink
feat: Add dependencies from asteroid destruction.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleStan committed Nov 16, 2024
1 parent 7388368 commit 5b60234
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
15 changes: 10 additions & 5 deletions Yafc.Model/Data/DataClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ public float Power(Quality quality)
public Item[] itemsToPlace { get; internal set; } = null!; // null-forgiving: This is initialized in CalculateMaps.
internal Location[] spawnLocations { get; set; } = null!; // null-forgiving: This is initialized in CalculateMaps.
internal List<Ammo> captureAmmo { get; } = [];
internal List<Entity> sourceEntities { get; set; } = null!;
internal string? autoplaceControl { get; set; }
public int size { get; internal set; }
internal override FactorioObjectSortOrder sortingOrder => FactorioObjectSortOrder.Entities;
Expand All @@ -536,17 +537,21 @@ public float Power(Quality quality)
internal Lazy<Entity?>? getSpoilResult;

public sealed override DependencyNode GetDependencies() {
// Asteroid chunks require locations OR bigger-asteroid
List<DependencyList> collector = [];
if (energy != null) {
collector.Add(new(energy.fuels, DependencyList.Flags.Fuel));
}
if (spawnLocations.Length != 0) {
collector.Add(new(spawnLocations, DependencyList.Flags.Location));
}

if (captureAmmo.Count == 0) {
if (spawnLocations.Length != 0) {
collector.Add(new(spawnLocations, DependencyList.Flags.Location));
}
if (sourceEntities.Count > 0) {
// Asteroid chunks require locations OR bigger-asteroid
collector.Add(new(sourceEntities, DependencyList.Flags.Source));
return DependencyNode.RequireAny(collector);
}

if (captureAmmo.Count == 0) {
if (!mapGenerated) {
collector.Add(new(itemsToPlace, DependencyList.Flags.ItemToPlace));
}
Expand Down
4 changes: 4 additions & 0 deletions Yafc.Parser/Data/FactorioDataDeserializer_Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal partial class FactorioDataDeserializer {
private readonly DataBucket<Recipe, Module> recipeModules = new DataBucket<Recipe, Module>();
private readonly Dictionary<Item, List<string>> placeResults = [];
private readonly Dictionary<Item, string> plantResults = [];
private readonly DataBucket<string, Entity> asteroids = new();
private readonly List<Module> allModules = [];
private readonly HashSet<Item> sciencePacks = [];
private readonly Dictionary<string, List<Fluid>> fluidVariants = [];
Expand Down Expand Up @@ -411,6 +412,7 @@ private void CalculateMaps(bool netProduction) {
entityPlacers.Seal();
entityLocations.Seal();
autoplaceControlLocations.Seal();
asteroids.Seal();

// step 2 - fill maps

Expand Down Expand Up @@ -457,6 +459,8 @@ private void CalculateMaps(bool netProduction) {
if (entity.spawnLocations.Length > 0) {
entity.mapGenerated = true;
}

entity.sourceEntities = asteroids.GetArray(entity.name).ToList();
break;
case Location location:
location.technologyUnlock = locationUnlockers.GetArray(location);
Expand Down
13 changes: 13 additions & 0 deletions Yafc.Parser/Data/FactorioDataDeserializer_Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ private void DeserializeEntity(LuaTable table, ErrorCollector errorCollector) {
break;
case "assembling-machine":
goto case "furnace";
case "asteroid":
Entity asteroid = GetObject<Entity>(name);
if (table.Get("dying_trigger_effect", out LuaTable? death)) {
death.ReadObjectOrArray(trigger => {
switch (trigger.Get<string>("type")) {
case "create-entity" when trigger.Get("entity_name", out string? result):
case "create-asteroid-chunk" when trigger.Get("asteroid_name", out result):
asteroids.Add(result, asteroid);
break;
}
});
}
break;
case "asteroid-collector":
EntityCrafter collector = GetObject<Entity, EntityCrafter>(name);
_ = table.Get("arm_energy_usage", out usesPower);
Expand Down
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Version:
Date:
Features:
- Add dependency information for tree and resource spawns, fluid pumping, and some asteroid mining.
- Add dependency information for tree and resource spawns, fluid pumping, and asteroid mining.
- (SA) Locations (except nauvis) are now part of the default milestone list.
- Milestone overlays can be displayed on inaccessible objects.
Internal changes:
Expand Down

0 comments on commit 5b60234

Please sign in to comment.