Added basic multi-unit factories

This commit is contained in:
Anuken
2020-04-13 16:56:33 -04:00
parent d860977144
commit 2af12a632a
17 changed files with 2209 additions and 2587 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -222,3 +222,5 @@
63522=alpha-mech-pad|block-alpha-mech-pad-medium 63522=alpha-mech-pad|block-alpha-mech-pad-medium
63521=cliff|block-cliff-medium 63521=cliff|block-cliff-medium
63520=legacy-mech-pad|block-legacy-mech-pad-medium 63520=legacy-mech-pad|block-legacy-mech-pad-medium
63519=ground-factory|block-ground-factory-medium
63518=legacy-unit-factory|block-legacy-unit-factory-medium

Binary file not shown.

Before

Width:  |  Height:  |  Size: 736 B

After

Width:  |  Height:  |  Size: 705 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 768 KiB

After

Width:  |  Height:  |  Size: 752 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 KiB

After

Width:  |  Height:  |  Size: 813 KiB

View File

@@ -4,7 +4,6 @@ import arc.*;
import arc.graphics.*; import arc.graphics.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.*; import mindustry.*;
import mindustry.ctype.*; 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, duo, scatter, scorch, hail, arc, wave, lancer, swarmer, salvo, fuse, ripple, cyclone, spectre, meltdown,
//units //units
commandCenter, draugFactory, spiritFactory, phantomFactory, wraithFactory, ghoulFactory, revenantFactory, daggerFactory, crawlerFactory, titanFactory, groundFactory, repairPoint
fortressFactory, repairPoint
//upgrades //upgrades
//dartPad, alphaPad, deltaPad, tauPad, omegaPad, javelinPad, tridentPad, glaivePad; //dartPad, alphaPad, deltaPad, tauPad, omegaPad, javelinPad, tridentPad, glaivePad;
@@ -1655,6 +1653,19 @@ public class Blocks implements ContentList{
//endregion //endregion
//region units //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"){{ draugFactory = new UnitFactory("draug-factory"){{
requirements(Category.units, ItemStack.with(Items.copper, 30, Items.lead, 70)); requirements(Category.units, ItemStack.with(Items.copper, 30, Items.lead, 70));
unitType = UnitTypes.draug; unitType = UnitTypes.draug;
@@ -1750,7 +1761,7 @@ public class Blocks implements ContentList{
size = 3; size = 3;
consumes.power(1.4f); consumes.power(1.4f);
consumes.items(new ItemStack(Items.silicon, 20), new ItemStack(Items.graphite, 10)); consumes.items(new ItemStack(Items.silicon, 20), new ItemStack(Items.graphite, 10));
}}; }};*/
repairPoint = new RepairPoint("repair-point"){{ repairPoint = new RepairPoint("repair-point"){{
requirements(Category.units, ItemStack.with(Items.lead, 15, Items.copper, 15, Items.silicon, 15)); 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 //looked up by name, no ref needed
new LegacyMechPad("legacy-mech-pad"); new LegacyMechPad("legacy-mech-pad");
new LegacyUnitFactory("legacy-unit-factory");
//endregion //endregion
} }

View File

@@ -276,6 +276,7 @@ public class TechTree implements ContentList{
}); });
}); });
/*
node(draugFactory, () -> { node(draugFactory, () -> {
node(spiritFactory, () -> { node(spiritFactory, () -> {
node(phantomFactory); node(phantomFactory);

View File

@@ -91,8 +91,8 @@ public class Zones implements ContentList{
resources = with(copper, scrap, lead, coal, sand, titanium); resources = with(copper, scrap, lead, coal, sand, titanium);
requirements = with( requirements = with(
new ZoneWave(desertWastes, 60), new ZoneWave(desertWastes, 60),
new Unlock(Blocks.daggerFactory), //new Unlock(Blocks.daggerFactory),
new Unlock(Blocks.draugFactory), //new Unlock(Blocks.draugFactory),
new Unlock(Blocks.door), new Unlock(Blocks.door),
new Unlock(Blocks.waterExtractor) new Unlock(Blocks.waterExtractor)
); );
@@ -157,8 +157,8 @@ public class Zones implements ContentList{
configureObjective = new Launched(this); configureObjective = new Launched(this);
requirements = with( requirements = with(
new ZoneWave(stainedMountains, 15), new ZoneWave(stainedMountains, 15),
new Unlock(Blocks.daggerFactory), //new Unlock(Blocks.daggerFactory),
new Unlock(Blocks.crawlerFactory), //new Unlock(Blocks.crawlerFactory),
new Unlock(Blocks.door), new Unlock(Blocks.door),
new Unlock(Blocks.siliconSmelter) new Unlock(Blocks.siliconSmelter)
); );
@@ -175,9 +175,9 @@ public class Zones implements ContentList{
new ZoneWave(craters, 40), new ZoneWave(craters, 40),
new Launched(fungalPass), new Launched(fungalPass),
new Unlock(Blocks.cultivator), new Unlock(Blocks.cultivator),
new Unlock(Blocks.sporePress), new Unlock(Blocks.sporePress)
new Unlock(Blocks.titanFactory), //new Unlock(Blocks.titanFactory),
new Unlock(Blocks.wraithFactory) //new Unlock(Blocks.wraithFactory)
); );
}}; }};

View File

@@ -21,7 +21,18 @@ public abstract class SaveFileReader{
"alpha-mech-pad", "legacy-mech-pad", "alpha-mech-pad", "legacy-mech-pad",
"tau-mech-pad", "legacy-mech-pad", "tau-mech-pad", "legacy-mech-pad",
"omega-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{ protected void region(String name, DataInput stream, CounterInputStream counter, IORunner<DataInput> cons) throws IOException{

View File

@@ -573,7 +573,7 @@ public class Tile implements Position, QuadTreeObject{
@Override @Override
public String toString(){ 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 //remote utility methods

View File

@@ -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();
}
}
}
}

View File

@@ -3,6 +3,7 @@ package mindustry.world.blocks.units;
import arc.*; import arc.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.scene.ui.layout.*;
import arc.struct.*; import arc.struct.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.*; import mindustry.*;
@@ -15,18 +16,19 @@ import mindustry.graphics.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.world.*; import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.consumers.*; import mindustry.world.consumers.*;
import mindustry.world.meta.*; import mindustry.world.meta.*;
import static mindustry.Vars.net; import static mindustry.Vars.*;
public class UnitFactory extends Block{ public class UnitFactory extends Block{
public UnitType unitType;
public float produceTime = 1000f;
public float launchVelocity = 0f; public float launchVelocity = 0f;
public TextureRegion topRegion; public TextureRegion topRegion;
public int[] capacities; public int[] capacities;
public UnitPlan[] plans = new UnitPlan[0];
public UnitFactory(String name){ public UnitFactory(String name){
super(name); super(name);
update = true; update = true;
@@ -34,27 +36,15 @@ public class UnitFactory extends Block{
hasItems = true; hasItems = true;
solid = false; solid = false;
flags = EnumSet.of(BlockFlag.producer); 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) @Remote(called = Loc.server)
public static void onUnitFactorySpawn(Tile tile){ public static void onUnitFactorySpawn(Tile tile){
if(!(tile.entity instanceof UnitFactoryEntity) || !(tile.block() instanceof UnitFactory)) return; if(!(tile.entity instanceof UnitFactoryEntity)) return;
tile.<UnitFactoryEntity>ent().spawned();
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));
}
} }
@Override @Override
@@ -80,7 +70,7 @@ public class UnitFactory extends Block{
@Override @Override
public void setBars(){ public void setBars(){
super.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 @Override
@@ -93,7 +83,8 @@ public class UnitFactory extends Block{
super.setStats(); super.setStats();
stats.remove(BlockStat.itemCapacity); stats.remove(BlockStat.itemCapacity);
stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds); //TODO
//stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds);
} }
@Override @Override
@@ -101,59 +92,113 @@ public class UnitFactory extends Block{
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top")}; 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{ public class UnitFactoryEntity extends TileEntity{
float buildTime; public int currentPlan = -1;
float time;
float speedScl; public float progress, time, speedScl;
//int spawned;
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 @Override
public void draw(){ 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; TextureRegion region = plan.unit.icon(Cicon.full);
Shaders.build.progress = buildTime / produceTime;
Shaders.build.color.set(Pal.accent);
Shaders.build.color.a = speedScl;
Shaders.build.time = -time / 20f;
Draw.shader(Shaders.build); Shaders.build.region = region;
Draw.rect(region, x, y); Shaders.build.progress = progress / plan.time;
Draw.shader(); Shaders.build.color.set(Pal.accent);
Shaders.build.color.a = speedScl;
Shaders.build.time = -time / 20f;
Draw.color(Pal.accent); Draw.shader(Shaders.build);
Draw.alpha(speedScl); Draw.rect(region, x, y);
Draw.shader();
Lines.lineAngleCenter( Draw.color(Pal.accent);
x + Mathf.sin(time, 20f, Vars.tilesize / 2f * size - 2f), Draw.alpha(speedScl);
y,
90,
size * Vars.tilesize - 4f);
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); Draw.rect(topRegion, x, y);
} }
@Override @Override
public void updateTile(){ public void updateTile(){
if(currentPlan < 0 || currentPlan >= plans.length){
currentPlan = -1;
}
if(consValid() || tile.isEnemyCheat()){ if((consValid() || tile.isEnemyCheat()) && currentPlan != -1){
time += delta() * speedScl * Vars.state.rules.unitBuildSpeedMultiplier * efficiency(); time += delta() * efficiency() * speedScl * Vars.state.rules.unitBuildSpeedMultiplier;
buildTime += delta() * efficiency() * Vars.state.rules.unitBuildSpeedMultiplier; progress += delta() * efficiency() * Vars.state.rules.unitBuildSpeedMultiplier;
speedScl = Mathf.lerpDelta(speedScl, 1f, 0.05f); speedScl = Mathf.lerpDelta(speedScl, 1f, 0.05f);
}else{ }else{
speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f); speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f);
} }
if(buildTime >= produceTime){ if(currentPlan != -1){
buildTime = 0f; UnitPlan plan = plans[currentPlan];
Call.onUnitFactorySpawn(tile); if(progress >= plan.time){
useContent(unitType); progress = 0f;
consume();
Call.onUnitFactorySpawn(tile);
useContent(plan.unit);
consume();
}
}else{
progress = 0f;
} }
} }
@@ -170,18 +215,13 @@ public class UnitFactory extends Block{
@Override @Override
public void write(Writes write){ public void write(Writes write){
super.write(write); super.write(write);
write.f(buildTime); write.f(progress);
} }
@Override @Override
public void read(Reads read, byte revision){ public void read(Reads read, byte revision){
super.read(read, revision); super.read(read, revision);
buildTime = read.f(); progress = read.f();
if(revision == 0){
//spawn count
read.i();
}
} }
} }
} }

View File

@@ -112,9 +112,10 @@ public class SStats implements SteamUserStatsCallback{
chainRouters.complete(); chainRouters.complete();
} }
if(e.tile.block() == Blocks.daggerFactory){ //TODO implement
buildDaggerFactory.complete(); //if(e.tile.block() == Blocks.daggerFactory){
} // buildDaggerFactory.complete();
//}
if(e.tile.block() == Blocks.meltdown || e.tile.block() == Blocks.spectre){ if(e.tile.block() == Blocks.meltdown || e.tile.block() == Blocks.spectre){
if(e.tile.block() == Blocks.meltdown && !Core.settings.getBool("meltdownp", false)){ if(e.tile.block() == Blocks.meltdown && !Core.settings.getBool("meltdownp", false)){