Allowing multiple planets to have the same tech tree (#11017)

* Lists all planets having the same TechTree associated with them.

As of right now, this problem arizes only with modded games. If you add planets in a specific order (e.g. StarA, PlanetA, PlanetB) and attach same tech tree to all of them - only items from the first planet (StarA) will be used and accounted for.

You can see this if you try to attach Serpulo's TechTree to Planets.sun - no resources from Serpulo will be visible and usable in Serpulo's TechTree in ResearchWindow (or anywhere for that matter).

* Removed spaces

* Added braces, if anyone will need to expand the code later (ig)
This commit is contained in:
DarkJune
2025-07-16 22:10:53 +03:00
committed by GitHub
parent cc02c15844
commit dcc8625bab

View File

@@ -46,6 +46,7 @@ public class ResearchDialog extends BaseDialog{
public ItemSeq items; public ItemSeq items;
private final Seq<Planet> rootPlanets = new Seq<>(false, 4);
private boolean showTechSelect; private boolean showTechSelect;
private boolean needsRebuild; private boolean needsRebuild;
@@ -214,21 +215,30 @@ public class ResearchDialog extends BaseDialog{
ObjectMap<Sector, ItemSeq> cache = new ObjectMap<>(); ObjectMap<Sector, ItemSeq> cache = new ObjectMap<>();
{ {
//first, find a planet associated with the current tech tree //first, find a planets associated with the current tech tree
Planet rootPlanet = lastNode.planet != null ? lastNode.planet : content.planets().find(p -> p.techTree == lastNode); rootPlanets.clear();
for(var planet : content.planets()){
if(planet.techTree == lastNode){
rootPlanets.add(planet);
}
}
//if there is no root, fall back to serpulo //if there is no root, fall back to serpulo
if(rootPlanet == null) rootPlanet = Planets.serpulo; if(rootPlanets.size == 0){
rootPlanets.add(Planets.serpulo);
}
//add global counts of each sector //add global counts of each sector
for(Sector sector : rootPlanet.sectors){ for(Planet planet : rootPlanets){
if(sector.hasBase()){ for(Sector sector : planet.sectors){
ItemSeq cached = sector.items(); if(sector.hasBase()){
cache.put(sector, cached); ItemSeq cached = sector.items();
cached.each((item, amount) -> { cache.put(sector, cached);
values[item.id] += Math.max(amount, 0); cached.each((item, amount) -> {
total += Math.max(amount, 0); values[item.id] += Math.max(amount, 0);
}); total += Math.max(amount, 0);
});
}
} }
} }
} }