Directional unit factories (unfinished)

This commit is contained in:
Anuken
2020-05-23 10:39:44 -04:00
parent f250008db3
commit 39b0051b73
19 changed files with 2008 additions and 2164 deletions

View File

@@ -41,7 +41,7 @@ public class LoadRegionProcessor extends BaseProcessor{
//get # of array dimensions //get # of array dimensions
int dims = count(field.mirror().toString(), "[]"); int dims = count(field.mirror().toString(), "[]");
boolean doFallback = !an.fallback().equals("error"); boolean doFallback = !an.fallback().equals("error");
String fallbackString = doFallback ? ", " + parse(an.value()).replace("content.name", '"' + an.fallback() + '"') : ""; String fallbackString = doFallback ? ", " + parse(an.fallback()) : "";
//not an array //not an array
if(dims == 0){ if(dims == 0){

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 641 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 416 B

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 657 B

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 520 B

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 723 B

After

Width:  |  Height:  |  Size: 717 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 738 KiB

After

Width:  |  Height:  |  Size: 735 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 KiB

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 837 KiB

After

Width:  |  Height:  |  Size: 818 KiB

View File

@@ -8,11 +8,13 @@ import arc.scene.style.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.*; import mindustry.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
@@ -20,6 +22,7 @@ import mindustry.type.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.world.*; import mindustry.world.*;
import mindustry.world.blocks.*; import mindustry.world.blocks.*;
import mindustry.world.blocks.payloads.*;
import mindustry.world.consumers.*; import mindustry.world.consumers.*;
import mindustry.world.meta.*; import mindustry.world.meta.*;
@@ -27,7 +30,8 @@ import static mindustry.Vars.*;
public class UnitFactory extends Block{ public class UnitFactory extends Block{
public float launchVelocity = 5f; public float launchVelocity = 5f;
public @Load("@-top") TextureRegion topRegion; public @Load(value = "@-top", fallback = "factory-top") TextureRegion topRegion;
public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion;
public int[] capacities; public int[] capacities;
public UnitPlan[] plans = new UnitPlan[0]; public UnitPlan[] plans = new UnitPlan[0];
@@ -37,10 +41,12 @@ public class UnitFactory extends Block{
update = true; update = true;
hasPower = true; hasPower = true;
hasItems = true; hasItems = true;
solid = false; solid = true;
flags = EnumSet.of(BlockFlag.producer, BlockFlag.unitModifier); flags = EnumSet.of(BlockFlag.producer, BlockFlag.unitModifier);
unitCapModifier = 4; unitCapModifier = 4;
configurable = true; configurable = true;
outputsPayload = true;
rotate = true;
config(Integer.class, (tile, i) -> { config(Integer.class, (tile, i) -> {
((UnitFactoryEntity)tile).currentPlan = i < 0 || i >= plans.length ? -1 : i; ((UnitFactoryEntity)tile).currentPlan = i < 0 || i >= plans.length ? -1 : i;
@@ -92,14 +98,18 @@ public class UnitFactory extends Block{
super.setStats(); super.setStats();
stats.remove(BlockStat.itemCapacity); stats.remove(BlockStat.itemCapacity);
//TODO
//stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds);
} }
@Override @Override
public TextureRegion[] generateIcons(){ public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top")}; return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-out"), Core.atlas.find(name + "-top")};
}
@Override
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * req.animScale * Draw.scl, region.getHeight() * req.animScale * Draw.scl);
Draw.rect(outRegion, req.drawx(), req.drawy(), outRegion.getWidth() * req.animScale * Draw.scl, outRegion.getHeight() * req.animScale * Draw.scl, req.rotation * 90);
Draw.rect(topRegion, req.drawx(), req.drawy(), outRegion.getWidth() * req.animScale * Draw.scl, outRegion.getHeight() * req.animScale * Draw.scl);
} }
public static class UnitPlan{ public static class UnitPlan{
@@ -119,6 +129,7 @@ public class UnitFactory extends Block{
public class UnitFactoryEntity extends TileEntity{ public class UnitFactoryEntity extends TileEntity{
public int currentPlan = -1; public int currentPlan = -1;
public float progress, time, speedScl; public float progress, time, speedScl;
public @Nullable Payload payload;
public float fraction(){ public float fraction(){
return currentPlan == -1 ? 0 : progress / plans[currentPlan].time; return currentPlan == -1 ? 0 : progress / plans[currentPlan].time;
@@ -173,7 +184,8 @@ public class UnitFactory extends Block{
@Override @Override
public void draw(){ public void draw(){
super.draw(); Draw.rect(region, x, y);
Draw.rect(outRegion, x, y, rotation() * 90);
if(currentPlan != -1){ if(currentPlan != -1){
UnitPlan plan = plans[currentPlan]; UnitPlan plan = plans[currentPlan];
@@ -200,6 +212,10 @@ public class UnitFactory extends Block{
}); });
} }
if(payload != null){
payload.draw(x, y, rotation() * 90);
}
Draw.z(Layer.blockOver); Draw.z(Layer.blockOver);
Draw.rect(topRegion, x, y); Draw.rect(topRegion, x, y);
} }
@@ -218,14 +234,17 @@ public class UnitFactory extends Block{
speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f); speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f);
} }
if(currentPlan != -1){ if(payload != null){
}
if(currentPlan != -1 && payload != null){
UnitPlan plan = plans[currentPlan]; UnitPlan plan = plans[currentPlan];
if(progress >= plan.time/* && !Units.anyEntities(tile, !plan.unit.flying)*/ && Units.canCreate(team)){ if(progress >= plan.time && Units.canCreate(team)){
progress = 0f; progress = 0f;
Call.onUnitFactorySpawn(tile); this.payload = new UnitPayload(plan.unit.create(team));
useContent(plan.unit);
consume(); consume();
} }