Unlinked global items of Serpulo and Erekir

This commit is contained in:
Anuken 2022-09-15 17:06:35 -04:00
parent e6213dd7b4
commit a0535395eb
4 changed files with 68 additions and 70 deletions

View File

@ -90,7 +90,7 @@ stats.destroyed = Buildings Destroyed
stats.deconstructed = Buildings Deconstructed
stats.playtime = Time Played
globalitems = [accent]Total Items
globalitems = [accent]Planet Items
map.delete = Are you sure you want to delete the map "[accent]{0}[]"?
level.highscore = High Score: [accent]{0}
level.select = Level Select

View File

@ -93,6 +93,8 @@ public class TechTree{
public Seq<Objective> objectives = new Seq<>();
/** Nodes that depend on this node. */
public final Seq<TechNode> children = new Seq<>();
/** Planet associated with this tech node. Null to auto-detect, or use Serpulo if no associated planet is found. */
public @Nullable Planet planet;
public TechNode(@Nullable TechNode parent, UnlockableContent content, ItemStack[] requirements){
if(parent != null){

View File

@ -278,21 +278,6 @@ public class Universe{
save();
}
/** This method is expensive to call; only do so sparingly. */
public ItemSeq getGlobalResources(){
ItemSeq count = new ItemSeq();
for(Planet planet : content.planets()){
for(Sector sector : planet.sectors){
if(sector.hasSave()){
count.add(sector.items());
}
}
}
return count;
}
public void updateNetSeconds(int value){
netSeconds = value;
}

View File

@ -116,60 +116,7 @@ public class ResearchDialog extends BaseDialog{
if(currPlanet != null && currPlanet.techTree != null){
switchTree(currPlanet.techTree);
}
items = new ItemSeq(){
//store sector item amounts for modifications
ObjectMap<Sector, ItemSeq> cache = new ObjectMap<>();
{
//add global counts of each sector
for(Planet planet : content.planets()){
for(Sector sector : planet.sectors){
if(sector.hasBase()){
ItemSeq cached = sector.items();
cache.put(sector, cached);
cached.each((item, amount) -> {
values[item.id] += Math.max(amount, 0);
total += Math.max(amount, 0);
});
}
}
}
}
//this is the only method that actually modifies the sequence itself.
@Override
public void add(Item item, int amount){
//only have custom removal logic for when the sequence gets items taken out of it (e.g. research)
if(amount < 0){
//remove items from each sector's storage, one by one
//negate amount since it's being *removed* - this makes it positive
amount = -amount;
//% that gets removed from each sector
double percentage = (double)amount / get(item);
int[] counter = {amount};
cache.each((sector, seq) -> {
if(counter[0] == 0) return;
//amount that will be removed
int toRemove = Math.min((int)Math.ceil(percentage * seq.get(item)), counter[0]);
//actually remove it from the sector
sector.removeItem(item, toRemove);
seq.remove(item, toRemove);
counter[0] -= toRemove;
});
//negate again to display correct number
amount = -amount;
}
super.add(item, amount);
}
};
rebuildItems();
checkNodes(root);
treeLayout();
@ -240,6 +187,68 @@ public class ResearchDialog extends BaseDialog{
});
}
public void rebuildItems(){
items = new ItemSeq(){
//store sector item amounts for modifications
ObjectMap<Sector, ItemSeq> cache = new ObjectMap<>();
{
//first, find a planet associated with the current tech tree
Planet rootPlanet = lastNode.planet != null ? lastNode.planet : content.planets().find(p -> p.techTree == lastNode);
//if there is no root, fall back to serpulo
if(rootPlanet == null) rootPlanet = Planets.serpulo;
//add global counts of each sector
for(Sector sector : rootPlanet.sectors){
if(sector.hasBase()){
ItemSeq cached = sector.items();
cache.put(sector, cached);
cached.each((item, amount) -> {
values[item.id] += Math.max(amount, 0);
total += Math.max(amount, 0);
});
}
}
}
//this is the only method that actually modifies the sequence itself.
@Override
public void add(Item item, int amount){
//only have custom removal logic for when the sequence gets items taken out of it (e.g. research)
if(amount < 0){
//remove items from each sector's storage, one by one
//negate amount since it's being *removed* - this makes it positive
amount = -amount;
//% that gets removed from each sector
double percentage = (double)amount / get(item);
int[] counter = {amount};
cache.each((sector, seq) -> {
if(counter[0] == 0) return;
//amount that will be removed
int toRemove = Math.min((int)Math.ceil(percentage * seq.get(item)), counter[0]);
//actually remove it from the sector
sector.removeItem(item, toRemove);
seq.remove(item, toRemove);
counter[0] -= toRemove;
});
//negate again to display correct number
amount = -amount;
}
super.add(item, amount);
}
};
itemDisplay.rebuild(items);
}
public @Nullable TechNode getPrefRoot(){
Planet currPlanet = ui.planet.isShown() ?
ui.planet.state.planet :
@ -253,6 +262,8 @@ public class ResearchDialog extends BaseDialog{
root = new TechTreeNode(node, null);
lastNode = node;
view.rebuildAll();
rebuildItems();
}
public void rebuildTree(TechNode node){