Skip to content

Commit 334ae36

Browse files
author
=
committed
unit factory (not units factory)
1 parent 3b67275 commit 334ae36

File tree

6 files changed

+132
-11
lines changed

6 files changed

+132
-11
lines changed

assets/bundles/bundle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ block.sw-light.description = A shrapnel energy turret.
4141

4242
block.sw-submarine-factory.name = Submarine Factory
4343
block.sw-submarine-factory.description = A unit factory that makes submarines.
44+
block.sw-crafter-factory.name = Crafter Factory
45+
block.sw-crafter-factory.description = A unit factory that can only make units if it outnumbers them.
4446

4547
block.sw-core-scaffold.name = Core Scaffold
4648
block.sw-core-scaffold.description = A core slightly better than shard, the root of the Tech Tree.
@@ -71,6 +73,4 @@ stat.sw-heat-use = Heat used/Second
7173
stat.sw-heat-tresh = Heat Transfer Threshold
7274

7375
## vanilla doesn't have one
74-
ability.spawndeath = Spawns unit after death
75-
76-
planet.sw-orion.name = Orion
76+
ability.spawndeath = Spawns unit after death
963 Bytes
Loading
701 Bytes
Loading

src/sw/content/SWBlocks.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import sw.world.blocks.heat.HeatRadiator;
2727
import sw.world.blocks.production.MultiCrafter;
2828
import sw.world.blocks.production.StackCrafter;
29+
import sw.world.blocks.units.SingleUnitFactory;
2930
import sw.world.consumers.ConsumeHeat;
3031
import sw.world.recipes.GenericRecipe;
3132

3233
import static mindustry.type.ItemStack.with;
34+
import static mindustry.world.blocks.units.UnitFactory.*;
3335

3436
public class SWBlocks {
3537
public static Block
@@ -51,6 +53,7 @@ public class SWBlocks {
5153
bolt, light, /*thunder,*/
5254

5355
subFactory,
56+
crafterFactory,
5457

5558
coreScaffold;
5659

@@ -131,14 +134,15 @@ public static void load() {
131134
requirements(Category.crafting, with(Items.titanium, 120, Items.silicon, 50, Items.graphite, 75, SWItems.nickel, 150));
132135
size = 3;
133136
health = 200;
134-
craftTime = 10f;
137+
craftTime = 30f;
138+
stacks = 6;
135139
consumeItem(Items.coal, 1);
136140
consumeLiquid(SWLiquids.steam, 0.02f);
137141
drawer = new DrawMulti(new DrawDefault(), new DrawBlurSpin("-rotator", 1f) {{
138142
rotateSpeed = 0.2f;
139143
blurThresh = 1.1f;
140144
}});
141-
outputItems = with(Items.graphite, 1);
145+
outputItems = with(Items.graphite, 8);
142146
}};
143147
rebuilder = new MultiCrafter("rebuilder") {{
144148
requirements(Category.crafting, with(
@@ -256,6 +260,19 @@ public static void load() {
256260
consumePower(1.5f);
257261
plans.add(new UnitPlan(SWUnitTypes.recluse, 60f * 50f, with(Items.silicon, 15, Items.metaglass, 25, SWItems.compound, 20)));
258262
}};
263+
crafterFactory = new SingleUnitFactory("crafter-factory") {{
264+
requirements(Category.units, with(
265+
SWItems.compound, 130,
266+
Items.titanium, 120,
267+
Items.silicon, 150
268+
));
269+
size = 2;
270+
health = 160;
271+
consumePower(2f);
272+
itemCapacity = 40;
273+
unitPlan = new UnitPlan(SWUnitTypes.bakler, 60f * 30f, with(Items.silicon, 20, Items.titanium, 15, SWItems.compound, 10));
274+
consumeItems(unitPlan.requirements);
275+
}};
259276

260277
// storage
261278
coreScaffold = new CoreBlock("core-scaffold") {{

src/sw/type/SWUnitType.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ public SWUnitType(String name) {
3232
@Override
3333
public void setStats() {
3434
super.setStats();
35-
stats.add(Stat.input, t -> {
36-
for (ItemStack stack : recipe.consumeItems) t.add(new ItemImage(stack));
37-
});
38-
stats.add(Stat.output, t -> {
39-
for (ItemStack stack : recipe.outputItems) t.add(new ItemImage(stack));
40-
});
35+
if (recipe != null) {
36+
stats.add(Stat.input, t -> {
37+
for (ItemStack stack : recipe.consumeItems) t.add(new ItemImage(stack)).pad(3f);
38+
});
39+
stats.add(Stat.output, t -> {
40+
for (ItemStack stack : recipe.outputItems) t.add(new ItemImage(stack)).pad(3f);
41+
});
42+
}
4143
}
4244

4345
@Override
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package sw.world.blocks.units;
2+
3+
import arc.Core;
4+
import arc.Events;
5+
import arc.graphics.g2d.Draw;
6+
import arc.graphics.g2d.TextureRegion;
7+
import arc.math.Mathf;
8+
import arc.struct.Seq;
9+
import arc.util.io.Reads;
10+
import arc.util.io.Writes;
11+
import mindustry.Vars;
12+
import mindustry.content.UnitTypes;
13+
import mindustry.game.EventType.UnitCreateEvent;
14+
import mindustry.gen.Building;
15+
import mindustry.gen.Unit;
16+
import mindustry.graphics.Drawf;
17+
import mindustry.graphics.Layer;
18+
import mindustry.type.ItemStack;
19+
import mindustry.ui.ItemImage;
20+
import mindustry.world.Block;
21+
import mindustry.world.blocks.units.UnitFactory.UnitPlan;
22+
import mindustry.world.meta.Stat;
23+
24+
public class SingleUnitFactory extends Block {
25+
public TextureRegion topRegion;
26+
public UnitPlan unitPlan = new UnitPlan(UnitTypes.flare, 60f, ItemStack.empty);
27+
public int unitCapacity = 1;
28+
29+
public SingleUnitFactory(String name) {
30+
super(name);
31+
destructible = update = sync = true;
32+
}
33+
34+
@Override
35+
public void setStats() {
36+
super.setStats();
37+
stats.add(Stat.input, t -> {for (ItemStack stack : unitPlan.requirements) t.add(new ItemImage(stack)).pad(3f);});
38+
stats.add(Stat.output, t -> t.image(unitPlan.unit.fullIcon).size(32f).pad(5));
39+
}
40+
41+
@Override
42+
public void load() {
43+
super.load();
44+
topRegion = Core.atlas.find(name + "-top");
45+
}
46+
47+
@Override
48+
public TextureRegion[] icons() {
49+
return new TextureRegion[]{region, topRegion};
50+
}
51+
52+
public class SingleUnitFactoryBuild extends Building {
53+
public float progress, totalProgress, warmup;
54+
public boolean canCreate() {
55+
Seq<Building> otherFactories = team.data().getBuildings(block);
56+
return unitPlan.unit.useUnitCap ? team.data().countType(unitPlan.unit) < team.data().unitCap : team.data().countType(unitPlan.unit) < otherFactories.size * unitCapacity;
57+
}
58+
59+
@Override
60+
public void updateTile() {
61+
if (efficiency > 0 && canCreate()) {
62+
progress += getProgressIncrease(unitPlan.time) * warmup * Vars.state.rules.unitBuildSpeedMultiplier;
63+
totalProgress += edelta() * Vars.state.rules.unitBuildSpeedMultiplier;
64+
warmup = Mathf.approachDelta(warmup, 1, 0.014f * Vars.state.rules.unitBuildSpeedMultiplier);
65+
66+
if (progress >= 1f) {
67+
progress %= 1f;
68+
69+
Unit unit = unitPlan.unit.spawn(team, this);
70+
Events.fire(new UnitCreateEvent(unit, this));
71+
}
72+
} else {
73+
warmup = Mathf.approachDelta(warmup, 0, 0.014f);
74+
progress = Mathf.approachDelta(warmup, 0, 0.014f);
75+
}
76+
}
77+
78+
@Override
79+
public void draw() {
80+
super.draw();
81+
Draw.draw(Layer.blockOver, () -> Drawf.construct(this, unitPlan.unit, 0, progress, warmup * Vars.state.rules.unitBuildSpeedMultiplier, totalProgress));
82+
Draw.z(Layer.blockOver + 0.01f);
83+
Draw.rect(topRegion, x, y, 0);
84+
}
85+
86+
@Override
87+
public void write(Writes write) {
88+
super.write(write);
89+
write.f(progress);
90+
write.f(totalProgress);
91+
write.f(warmup);
92+
}
93+
94+
@Override
95+
public void read(Reads read, byte revision) {
96+
super.read(read, revision);
97+
progress = read.f();
98+
totalProgress = read.f();
99+
warmup = read.f();
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)