Added basic multi-unit factories
This commit is contained in:
@@ -4,7 +4,6 @@ import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ctype.*;
|
||||
@@ -76,8 +75,7 @@ public class Blocks implements ContentList{
|
||||
duo, scatter, scorch, hail, arc, wave, lancer, swarmer, salvo, fuse, ripple, cyclone, spectre, meltdown,
|
||||
|
||||
//units
|
||||
commandCenter, draugFactory, spiritFactory, phantomFactory, wraithFactory, ghoulFactory, revenantFactory, daggerFactory, crawlerFactory, titanFactory,
|
||||
fortressFactory, repairPoint
|
||||
groundFactory, repairPoint
|
||||
|
||||
//upgrades
|
||||
//dartPad, alphaPad, deltaPad, tauPad, omegaPad, javelinPad, tridentPad, glaivePad;
|
||||
@@ -1655,6 +1653,19 @@ public class Blocks implements ContentList{
|
||||
//endregion
|
||||
//region units
|
||||
|
||||
//for testing only.
|
||||
groundFactory = new UnitFactory("ground-factory"){{
|
||||
requirements(Category.units, ItemStack.with(Items.copper, 30, Items.lead, 70));
|
||||
plans = new UnitPlan[]{
|
||||
new UnitPlan(UnitTypes.dagger, 60f, ItemStack.with(Items.silicon, 10)),
|
||||
new UnitPlan(UnitTypes.wraith, 60f, ItemStack.with(Items.silicon, 10)),
|
||||
};
|
||||
size = 3;
|
||||
consumes.power(1.2f);
|
||||
consumes.items(new ItemStack(Items.silicon, 10));
|
||||
}};
|
||||
|
||||
/*
|
||||
draugFactory = new UnitFactory("draug-factory"){{
|
||||
requirements(Category.units, ItemStack.with(Items.copper, 30, Items.lead, 70));
|
||||
unitType = UnitTypes.draug;
|
||||
@@ -1750,7 +1761,7 @@ public class Blocks implements ContentList{
|
||||
size = 3;
|
||||
consumes.power(1.4f);
|
||||
consumes.items(new ItemStack(Items.silicon, 20), new ItemStack(Items.graphite, 10));
|
||||
}};
|
||||
}};*/
|
||||
|
||||
repairPoint = new RepairPoint("repair-point"){{
|
||||
requirements(Category.units, ItemStack.with(Items.lead, 15, Items.copper, 15, Items.silicon, 15));
|
||||
@@ -1869,6 +1880,7 @@ public class Blocks implements ContentList{
|
||||
|
||||
//looked up by name, no ref needed
|
||||
new LegacyMechPad("legacy-mech-pad");
|
||||
new LegacyUnitFactory("legacy-unit-factory");
|
||||
|
||||
//endregion
|
||||
}
|
||||
|
||||
@@ -276,6 +276,7 @@ public class TechTree implements ContentList{
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
node(draugFactory, () -> {
|
||||
node(spiritFactory, () -> {
|
||||
node(phantomFactory);
|
||||
|
||||
@@ -91,8 +91,8 @@ public class Zones implements ContentList{
|
||||
resources = with(copper, scrap, lead, coal, sand, titanium);
|
||||
requirements = with(
|
||||
new ZoneWave(desertWastes, 60),
|
||||
new Unlock(Blocks.daggerFactory),
|
||||
new Unlock(Blocks.draugFactory),
|
||||
//new Unlock(Blocks.daggerFactory),
|
||||
//new Unlock(Blocks.draugFactory),
|
||||
new Unlock(Blocks.door),
|
||||
new Unlock(Blocks.waterExtractor)
|
||||
);
|
||||
@@ -157,8 +157,8 @@ public class Zones implements ContentList{
|
||||
configureObjective = new Launched(this);
|
||||
requirements = with(
|
||||
new ZoneWave(stainedMountains, 15),
|
||||
new Unlock(Blocks.daggerFactory),
|
||||
new Unlock(Blocks.crawlerFactory),
|
||||
//new Unlock(Blocks.daggerFactory),
|
||||
//new Unlock(Blocks.crawlerFactory),
|
||||
new Unlock(Blocks.door),
|
||||
new Unlock(Blocks.siliconSmelter)
|
||||
);
|
||||
@@ -175,9 +175,9 @@ public class Zones implements ContentList{
|
||||
new ZoneWave(craters, 40),
|
||||
new Launched(fungalPass),
|
||||
new Unlock(Blocks.cultivator),
|
||||
new Unlock(Blocks.sporePress),
|
||||
new Unlock(Blocks.titanFactory),
|
||||
new Unlock(Blocks.wraithFactory)
|
||||
new Unlock(Blocks.sporePress)
|
||||
//new Unlock(Blocks.titanFactory),
|
||||
//new Unlock(Blocks.wraithFactory)
|
||||
);
|
||||
}};
|
||||
|
||||
|
||||
@@ -21,7 +21,18 @@ public abstract class SaveFileReader{
|
||||
"alpha-mech-pad", "legacy-mech-pad",
|
||||
"tau-mech-pad", "legacy-mech-pad",
|
||||
"omega-mech-pad", "legacy-mech-pad",
|
||||
"delta-mech-pad", "legacy-mech-pad"
|
||||
"delta-mech-pad", "legacy-mech-pad",
|
||||
|
||||
"draug-factory", "legacy-unit-factory",
|
||||
"spirit-factory", "legacy-unit-factory",
|
||||
"phantom-factory", "legacy-unit-factory",
|
||||
"wraith-factory", "legacy-unit-factory",
|
||||
"ghoul-factory", "legacy-unit-factory",
|
||||
"revenant-factory", "legacy-unit-factory",
|
||||
"dagger-factory", "legacy-unit-factory",
|
||||
"crawler-factory", "legacy-unit-factory",
|
||||
"titan-factory", "legacy-unit-factory",
|
||||
"fortress-factory", "legacy-unit-factory"
|
||||
);
|
||||
|
||||
protected void region(String name, DataInput stream, CounterInputStream counter, IORunner<DataInput> cons) throws IOException{
|
||||
|
||||
@@ -573,7 +573,7 @@ public class Tile implements Position, QuadTreeObject{
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return floor.name + ":" + block.name + ":" + overlay + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) + ":" + team();
|
||||
return floor.name + ":" + block.name + ":" + overlay + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass().getSimpleName())) + ":" + team();
|
||||
}
|
||||
|
||||
//remote utility methods
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package mindustry.world.blocks.legacy;
|
||||
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class LegacyUnitFactory extends Block{
|
||||
|
||||
public LegacyUnitFactory(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
solid = false;
|
||||
}
|
||||
|
||||
public class LegacyUnitFactoryEntity extends TileEntity{
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
//build time
|
||||
read.f();
|
||||
|
||||
if(revision == 0){
|
||||
//spawn count
|
||||
read.i();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package mindustry.world.blocks.units;
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
@@ -15,18 +16,19 @@ import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.net;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitFactory extends Block{
|
||||
public UnitType unitType;
|
||||
public float produceTime = 1000f;
|
||||
public float launchVelocity = 0f;
|
||||
public TextureRegion topRegion;
|
||||
public int[] capacities;
|
||||
|
||||
public UnitPlan[] plans = new UnitPlan[0];
|
||||
|
||||
public UnitFactory(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
@@ -34,27 +36,15 @@ public class UnitFactory extends Block{
|
||||
hasItems = true;
|
||||
solid = false;
|
||||
flags = EnumSet.of(BlockFlag.producer);
|
||||
configurable = true;
|
||||
|
||||
config(Integer.class, (tile, i) -> ((UnitFactoryEntity)tile).currentPlan = i < 0 || i >= plans.length ? -1 : i);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onUnitFactorySpawn(Tile tile){
|
||||
if(!(tile.entity instanceof UnitFactoryEntity) || !(tile.block() instanceof UnitFactory)) return;
|
||||
|
||||
UnitFactory factory = (UnitFactory)tile.block();
|
||||
UnitFactoryEntity entity = tile.ent();
|
||||
|
||||
entity.buildTime = 0f;
|
||||
|
||||
Effects.shake(2f, 3f, entity);
|
||||
Fx.producesmoke.at(entity);
|
||||
|
||||
if(!net.client()){
|
||||
Unitc unit = factory.unitType.create(entity.team());
|
||||
unit.set(entity.x() + Mathf.range(4), entity.y() + Mathf.range(4));
|
||||
unit.add();
|
||||
unit.vel().y = factory.launchVelocity;
|
||||
Events.fire(new UnitCreateEvent(unit));
|
||||
}
|
||||
if(!(tile.entity instanceof UnitFactoryEntity)) return;
|
||||
tile.<UnitFactoryEntity>ent().spawned();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,7 +70,7 @@ public class UnitFactory extends Block{
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, () -> ((UnitFactoryEntity)entity).buildTime / produceTime));
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, ((UnitFactoryEntity)entity)::fraction));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +83,8 @@ public class UnitFactory extends Block{
|
||||
super.setStats();
|
||||
|
||||
stats.remove(BlockStat.itemCapacity);
|
||||
stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds);
|
||||
//TODO
|
||||
//stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,59 +92,113 @@ public class UnitFactory extends Block{
|
||||
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top")};
|
||||
}
|
||||
|
||||
public static class UnitPlan{
|
||||
public UnitType unit;
|
||||
public ItemStack[] requirements;
|
||||
public float time;
|
||||
|
||||
public UnitPlan(UnitType unit, float time, ItemStack[] requirements){
|
||||
this.unit = unit;
|
||||
this.time = time;
|
||||
this.requirements = requirements;
|
||||
}
|
||||
|
||||
UnitPlan(){}
|
||||
}
|
||||
|
||||
public class UnitFactoryEntity extends TileEntity{
|
||||
float buildTime;
|
||||
float time;
|
||||
float speedScl;
|
||||
//int spawned;
|
||||
public int currentPlan = -1;
|
||||
|
||||
public float progress, time, speedScl;
|
||||
|
||||
public float fraction(){
|
||||
return currentPlan == -1 ? 0 : progress / plans[currentPlan].time;
|
||||
}
|
||||
|
||||
public void spawned(){
|
||||
progress = 0f;
|
||||
|
||||
Effects.shake(2f, 3f, this);
|
||||
Fx.producesmoke.at(this);
|
||||
|
||||
if(!net.client() && currentPlan != -1){
|
||||
UnitPlan plan = plans[currentPlan];
|
||||
Unitc unit = plan.unit.create(team);
|
||||
unit.set(x + Mathf.range(4), y + Mathf.range(4));
|
||||
unit.add();
|
||||
unit.vel().y = launchVelocity;
|
||||
Events.fire(new UnitCreateEvent(unit));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Table table){
|
||||
Array<UnitType> units = Array.with(plans).map(u -> u.unit);
|
||||
|
||||
ItemSelection.buildTable(table, units, () -> currentPlan == -1 ? null : plans[currentPlan].unit, unit -> tile.configure(units.indexOf(unit)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object config(){
|
||||
return currentPlan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
TextureRegion region = unitType.icon(Cicon.full);
|
||||
super.draw();
|
||||
|
||||
Draw.rect(name, x, y);
|
||||
if(currentPlan != -1){
|
||||
UnitPlan plan = plans[currentPlan];
|
||||
|
||||
Shaders.build.region = region;
|
||||
Shaders.build.progress = buildTime / produceTime;
|
||||
Shaders.build.color.set(Pal.accent);
|
||||
Shaders.build.color.a = speedScl;
|
||||
Shaders.build.time = -time / 20f;
|
||||
TextureRegion region = plan.unit.icon(Cicon.full);
|
||||
|
||||
Draw.shader(Shaders.build);
|
||||
Draw.rect(region, x, y);
|
||||
Draw.shader();
|
||||
Shaders.build.region = region;
|
||||
Shaders.build.progress = progress / plan.time;
|
||||
Shaders.build.color.set(Pal.accent);
|
||||
Shaders.build.color.a = speedScl;
|
||||
Shaders.build.time = -time / 20f;
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
Draw.alpha(speedScl);
|
||||
Draw.shader(Shaders.build);
|
||||
Draw.rect(region, x, y);
|
||||
Draw.shader();
|
||||
|
||||
Lines.lineAngleCenter(
|
||||
x + Mathf.sin(time, 20f, Vars.tilesize / 2f * size - 2f),
|
||||
y,
|
||||
90,
|
||||
size * Vars.tilesize - 4f);
|
||||
Draw.color(Pal.accent);
|
||||
Draw.alpha(speedScl);
|
||||
|
||||
Draw.reset();
|
||||
Lines.lineAngleCenter(x + Mathf.sin(time, 20f, Vars.tilesize / 2f * size - 2f), y, 90, size * Vars.tilesize - 4f);
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
Draw.rect(topRegion, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(currentPlan < 0 || currentPlan >= plans.length){
|
||||
currentPlan = -1;
|
||||
}
|
||||
|
||||
if(consValid() || tile.isEnemyCheat()){
|
||||
time += delta() * speedScl * Vars.state.rules.unitBuildSpeedMultiplier * efficiency();
|
||||
buildTime += delta() * efficiency() * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
if((consValid() || tile.isEnemyCheat()) && currentPlan != -1){
|
||||
time += delta() * efficiency() * speedScl * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
progress += delta() * efficiency() * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
speedScl = Mathf.lerpDelta(speedScl, 1f, 0.05f);
|
||||
}else{
|
||||
speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f);
|
||||
}
|
||||
|
||||
if(buildTime >= produceTime){
|
||||
buildTime = 0f;
|
||||
if(currentPlan != -1){
|
||||
UnitPlan plan = plans[currentPlan];
|
||||
|
||||
Call.onUnitFactorySpawn(tile);
|
||||
useContent(unitType);
|
||||
consume();
|
||||
if(progress >= plan.time){
|
||||
progress = 0f;
|
||||
|
||||
Call.onUnitFactorySpawn(tile);
|
||||
useContent(plan.unit);
|
||||
consume();
|
||||
}
|
||||
}else{
|
||||
progress = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,18 +215,13 @@ public class UnitFactory extends Block{
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(buildTime);
|
||||
write.f(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
buildTime = read.f();
|
||||
|
||||
if(revision == 0){
|
||||
//spawn count
|
||||
read.i();
|
||||
}
|
||||
progress = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user