Skip to content
This repository was archived by the owner on Jan 17, 2026. It is now read-only.

Commit fb9cabe

Browse files
committed
WOWZERS
1 parent 9f02d3e commit fb9cabe

File tree

3 files changed

+122
-16
lines changed

3 files changed

+122
-16
lines changed

src/biotech/content/AndoriTechTree.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class AndoriTechTree {
1313
public static void load(){
1414
BioPlanets.andori.techTree = bioNodeRoot("Andori", BioBlocks.coreSight, () -> {
15-
bioNode(BioBlocks.magnesiumConveyor, Seq.with(new Objectives.Produce(BioItems.magnesium)), () -> {
15+
bioNode(BioBlocks.magnesiumConveyor, Seq.with(new Objectives.Produce(BioItems.magnesium)), 2, () -> {
1616
bioNode(BioBlocks.unitDocker, Seq.with(new Objectives.Research(BioBlocks.boneCrusher)), () -> {
1717
bioNode(BioBlocks.unitDischarger);
1818
});
@@ -22,7 +22,7 @@ public static void load(){
2222
});
2323

2424
bioNode(BioBlocks.descentManufacturer, Seq.with(new Objectives.Research(BioBlocks.boneCrusher)), () -> {
25-
bioNode(BioUnits.strider, () -> {});
25+
bioNode(BioUnits.strider, null, 2, () -> {});
2626
bioNode(BioUnits.scout, Seq.with(new Objectives.SectorComplete(BioSectorPresets.crus)), () -> {});
2727
bioNode(BioBlocks.osylithReformer, Seq.with(new Objectives.SectorComplete(BioSectorPresets.femur)), () -> {
2828
bioNode(BioUnits.nomad, Seq.with(new Objectives.SectorComplete(BioSectorPresets.femur)), () -> {
@@ -35,7 +35,7 @@ public static void load(){
3535
});
3636
});
3737

38-
bioNode(BioBlocks.bioDrill, () -> {
38+
bioNode(BioBlocks.bioDrill, null, 2, () -> {
3939
bioNode(BioBlocks.magnesiumBurner, Seq.with(new Objectives.SectorComplete(BioSectorPresets.femur)), () -> {
4040
bioNode(BioBlocks.drillUpgrader);
4141
});

src/biotech/content/BioTechTree.java

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package biotech.content;
22

3+
import arc.Core;
4+
import arc.func.Cons;
5+
import arc.scene.style.Drawable;
6+
import arc.scene.style.TextureRegionDrawable;
7+
import arc.struct.ObjectFloatMap;
8+
import arc.struct.ObjectSet;
39
import arc.struct.Seq;
10+
import arc.util.Nullable;
411
import mindustry.content.TechTree;
12+
import mindustry.ctype.Content;
513
import mindustry.ctype.UnlockableContent;
614
import mindustry.game.Objectives;
715
import mindustry.type.ItemStack;
16+
import mindustry.type.Planet;
817

918
public class BioTechTree extends TechTree {
1019

@@ -13,8 +22,8 @@ public class BioTechTree extends TechTree {
1322
public static Seq<BioTechNode> all = new Seq<>();
1423
public static Seq<BioTechNode> roots = new Seq<>();
1524

16-
public static TechNode bioNodeRoot(String name, UnlockableContent content, Runnable children){
17-
return nodeRoot(name, content, false, children);
25+
public static BioTechNode bioNodeRoot(String name, UnlockableContent content, Runnable children){
26+
return bioNodeRoot(name, content, false, children);
1827
}
1928

2029
public static BioTechNode bioNodeRoot(String name, UnlockableContent content, boolean requireUnlock, Runnable children){
@@ -60,12 +69,108 @@ public static BioTechNode bioNode(UnlockableContent block){
6069
}
6170

6271
public static class BioTechNode extends TechNode {
63-
int importance;
64-
public final Seq<BioTechNode> children = new Seq<>();
65-
66-
public BioTechNode(TechNode parent, UnlockableContent content, ItemStack[] requirements, int importance) {
67-
super(parent, content, requirements);
72+
public int importance;
73+
public final Seq<BioTechNode> bioChildren = new Seq<>();
74+
public @Nullable BioTechNode bioParent;
75+
76+
public BioTechNode(BioTechNode bioParent, UnlockableContent content, ItemStack[] requirements, int importance) {
77+
super(bioParent, content, requirements);
78+
79+
if(bioParent != null){
80+
bioParent.bioChildren.add(this);
81+
planet = bioParent.planet;
82+
researchCostMultipliers = bioParent.researchCostMultipliers;
83+
}else if(researchCostMultipliers == null){
84+
researchCostMultipliers = new ObjectFloatMap<>();
85+
}
86+
87+
this.bioParent = bioParent;
6888
this.importance = importance;
89+
this.content = content;
90+
this.depth = bioParent == null ? 0 : bioParent.depth + 1;
91+
92+
if(researchCostMultipliers.size > 0){
93+
requirements = ItemStack.copy(requirements);
94+
for(ItemStack requirement : requirements){
95+
requirement.amount = (int)(requirement.amount * researchCostMultipliers.get(requirement.item, 1));
96+
}
97+
}
98+
99+
setupRequirements(requirements);
100+
101+
var used = new ObjectSet<Content>();
102+
103+
//add dependencies as objectives.
104+
content.getDependencies(d -> {
105+
if(used.add(d)){
106+
objectives.add(new Objectives.Research(d));
107+
}
108+
});
109+
110+
content.techNode = this;
111+
content.techNodes.add(this);
112+
all.add(this);
113+
}
114+
115+
/** Recursively iterates through everything that is a child of this node. Includes itself. */
116+
public void bioEach(Cons<BioTechNode> consumer){
117+
consumer.get(this);
118+
for(var child : bioChildren){
119+
child.bioEach(consumer);
120+
}
121+
}
122+
123+
/** Adds the specified database tab to all the content in this tree. */
124+
public void addDatabaseTab(UnlockableContent tab){
125+
bioEach(node -> node.content.databaseTabs.add(tab));
126+
}
127+
128+
/** Adds the specified planet to the shownPlanets of all the content in this tree. */
129+
public void addPlanet(Planet planet){
130+
bioEach(node -> node.content.shownPlanets.add(planet));
131+
}
132+
133+
public Drawable icon(){
134+
return icon == null ? new TextureRegionDrawable(content.uiIcon) : icon;
135+
}
136+
137+
public String localizedName(){
138+
return Core.bundle.get("techtree." + name, name);
139+
}
140+
141+
public void setupRequirements(ItemStack[] requirements){
142+
this.requirements = requirements;
143+
this.finishedRequirements = new ItemStack[requirements.length];
144+
145+
//load up the requirements that have been finished if settings are available
146+
for(int i = 0; i < requirements.length; i++){
147+
finishedRequirements[i] = new ItemStack(requirements[i].item, Core.settings == null ? 0 : Core.settings.getInt("req-" + content.name + "-" + requirements[i].item.name));
148+
}
149+
}
150+
151+
/** Resets finished requirements and saves. */
152+
public void reset(){
153+
for(ItemStack stack : finishedRequirements){
154+
stack.amount = 0;
155+
}
156+
save();
157+
}
158+
159+
/** Removes this node from the tech tree. */
160+
public void remove(){
161+
all.remove(this);
162+
if(bioParent != null){
163+
bioParent.bioChildren.remove(this);
164+
}
165+
}
166+
167+
/** Flushes research progress to settings. */
168+
public void save(){
169+
170+
//save finished requirements by item type
171+
for(ItemStack stack : finishedRequirements){
172+
Core.settings.put("req-" + content.name + "-" + stack.item.name, stack.amount);
173+
}
69174
}
70175
}
71-
}
176+
}

src/biotech/ui/BioResearchDialog.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class BioResearchDialog extends BaseDialog {
4242

4343
public final float nodeSize = Scl.scl(60f);
4444
public ObjectSet<TechTreeNode> nodes = new ObjectSet<>();
45-
public TechTreeNode root = new TechTreeNode(BioTechTree.roots.first(), null, 2);
45+
public TechTreeNode root = new TechTreeNode(BioTechTree.roots.first(), null, 3);
4646
public BioTechTree.BioTechNode lastNode = root.node;
4747
public Rect bounds = new Rect();
4848
public ItemsDisplay itemDisplay;
@@ -280,7 +280,7 @@ public void add(Item item, int amount) {
280280
public void switchTree(BioTechTree.BioTechNode node) {
281281
if (lastNode == node || node == null) return;
282282
nodes.clear();
283-
root = new TechTreeNode(node, null, 2);
283+
root = new TechTreeNode(node, null, 3);
284284
lastNode = node;
285285
view.rebuildAll();
286286

@@ -444,9 +444,10 @@ public TechTreeNode(BioTechTree.BioTechNode node, TechTreeNode parent, int impor
444444
this.importance = importance;
445445
this.width = this.height = nodeSize;
446446
nodes.add(this);
447-
children = new TechTreeNode[node.children.size];
447+
Log.info("added");
448+
children = new TechTreeNode[node.bioChildren.size];
448449
for (int i = 0; i < children.length; i++) {
449-
children[i] = new TechTreeNode(node.children.get(i), this, children[i].importance);
450+
children[i] = new TechTreeNode(node.bioChildren.get(i), this, node.bioChildren.get(i).importance);
450451
}
451452
}
452453
}
@@ -512,7 +513,7 @@ protected void updateRelative(float percentDelta) {
512513
});
513514
button.touchable(() -> !node.visible ? Touchable.disabled : Touchable.enabled);
514515
button.userObject = node.node;
515-
button.setSize(nodeSize * node.importance);
516+
button.setSize(nodeSize * node.importance + 10);
516517
button.resizeImage(32f * node.importance);
517518
button.getImage().setScaling(Scaling.fit);
518519
button.update(() -> {

0 commit comments

Comments
 (0)