Unit cargo transport system
This commit is contained in:
@@ -3,6 +3,7 @@ package mindustry.world.blocks.distribution;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
@@ -127,6 +128,20 @@ public class StackConveyor extends Block implements Autotiler{
|
||||
}
|
||||
}
|
||||
|
||||
//draw inputs
|
||||
if(state == stateLoad){
|
||||
for(int i = 0; i < 4; i++){
|
||||
if((blendprox & (1 << i)) != 0 && i != 0){
|
||||
int dir = rotation - i;
|
||||
Draw.rect(sliced(regions[0], SliceMode.bottom), x + Geometry.d4x(dir) * tilesize*0.75f, y + Geometry.d4y(dir) * tilesize*0.75f, (float)(dir*90));
|
||||
}
|
||||
}
|
||||
}else if(state == stateUnload){ //front unload
|
||||
if((blendprox & (1)) != 0){
|
||||
Draw.rect(sliced(regions[0], SliceMode.top), x + Geometry.d4x(rotation) * tilesize*0.75f, y + Geometry.d4y(rotation) * tilesize*0.75f, rotation * 90f);
|
||||
}
|
||||
}
|
||||
|
||||
Draw.z(Layer.block - 0.1f);
|
||||
|
||||
Tile from = world.tile(link);
|
||||
|
||||
@@ -525,12 +525,16 @@ public class LogicBlock extends Block{
|
||||
write.b(compressed);
|
||||
|
||||
//write only the non-constant variables
|
||||
int count = Structs.count(executor.vars, v -> !v.constant || v == executor.vars[LExecutor.varUnit]);
|
||||
int count = Structs.count(executor.vars, v -> (!v.constant || v == executor.vars[LExecutor.varUnit]) && !(v.isobj && v.objval == null));
|
||||
|
||||
write.i(count);
|
||||
for(int i = 0; i < executor.vars.length; i++){
|
||||
Var v = executor.vars[i];
|
||||
|
||||
//null is the default variable value, so waste no time serializing that
|
||||
if(v.isobj && v.objval == null) continue;
|
||||
|
||||
//skip constants
|
||||
if(v.constant && i != LExecutor.varUnit) continue;
|
||||
|
||||
//write the name and the object value
|
||||
|
||||
@@ -113,6 +113,12 @@ public class Pump extends LiquidBlock{
|
||||
draw.drawBase(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLight(){
|
||||
super.drawLight();
|
||||
draw.drawLights(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pickedUp(){
|
||||
amount = 0f;
|
||||
|
||||
@@ -396,6 +396,9 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public void drawSelect(){
|
||||
//do not draw a pointless single outline when there's no storage
|
||||
if(team.cores().size <= 1 && !proximity.contains(storage -> storage.items == items)) return;
|
||||
|
||||
Lines.stroke(1f, Pal.accent);
|
||||
Cons<Building> outline = b -> {
|
||||
for(int i = 0; i < 4; i++){
|
||||
|
||||
146
core/src/mindustry/world/blocks/units/UnitCargoLoader.java
Normal file
146
core/src/mindustry/world/blocks/units/UnitCargoLoader.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class UnitCargoLoader extends Block{
|
||||
public UnitType unitType = UnitTypes.manifold;
|
||||
public float buildTime = 60f * 8f;
|
||||
|
||||
public float polyStroke = 1.8f, polyRadius = 8f;
|
||||
public int polySides = 6;
|
||||
public float polyRotateSpeed = 1f;
|
||||
public Color polyColor = Pal.accent;
|
||||
|
||||
public UnitCargoLoader(String name){
|
||||
super(name);
|
||||
|
||||
solid = true;
|
||||
update = true;
|
||||
hasItems = true;
|
||||
itemCapacity = 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
bars.add("units", (UnitTransportSourceBuild e) ->
|
||||
new Bar(
|
||||
() ->
|
||||
Core.bundle.format("bar.unitcap",
|
||||
Fonts.getUnicodeStr(unitType.name),
|
||||
e.team.data().countType(unitType),
|
||||
Units.getStringCap(e.team)
|
||||
),
|
||||
() -> Pal.power,
|
||||
() -> (float)e.team.data().countType(unitType) / Units.getCap(e.team)
|
||||
));
|
||||
}
|
||||
|
||||
public class UnitTransportSourceBuild extends Building{
|
||||
//needs to be "unboxed" after reading, since units are read after buildings.
|
||||
public int readUnitId = -1;
|
||||
public float buildProgress, totalProgress;
|
||||
public float warmup, readyness;
|
||||
public @Nullable Unit unit;
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
//unit was lost/destroyed
|
||||
if(unit != null && (unit.dead || !unit.isAdded())){
|
||||
unit = null;
|
||||
}
|
||||
|
||||
if(readUnitId != -1){
|
||||
unit = Groups.unit.getByID(readUnitId);
|
||||
readUnitId = -1;
|
||||
}
|
||||
|
||||
warmup = Mathf.approachDelta(warmup, efficiency(), 1f / 60f);
|
||||
readyness = Mathf.approachDelta(readyness, unit != null ? 1f : 0f, 1f / 60f);
|
||||
|
||||
if(unit == null && Units.canCreate(team, unitType)){
|
||||
buildProgress += edelta() / buildTime;
|
||||
totalProgress += edelta();
|
||||
|
||||
if(buildProgress >= 1f){
|
||||
unit = unitType.create(team);
|
||||
if(unit instanceof BuildingTetherc bt){
|
||||
bt.building(this);
|
||||
}
|
||||
unit.set(x, y);
|
||||
unit.rotation = 90f;
|
||||
unit.add();
|
||||
|
||||
Fx.spawn.at(unit);
|
||||
|
||||
buildProgress = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Building source, Item item){
|
||||
return items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldConsume(){
|
||||
return unit == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect(block.region, x, y);
|
||||
if(unit == null){
|
||||
Draw.draw(Layer.blockOver, () -> {
|
||||
//TODO make sure it looks proper
|
||||
Drawf.construct(this, unitType.fullIcon, 0f, buildProgress, warmup, totalProgress);
|
||||
});
|
||||
}else{
|
||||
Draw.z(Layer.bullet - 0.01f);
|
||||
Draw.color(polyColor);
|
||||
Lines.stroke(polyStroke * readyness);
|
||||
Lines.poly(x, y, polySides, polyRadius, Time.time * polyRotateSpeed);
|
||||
Draw.reset();
|
||||
Draw.z(Layer.block);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float totalProgress(){
|
||||
return totalProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float progress(){
|
||||
return buildProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
|
||||
write.i(unit == null ? -1 : unit.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
|
||||
readUnitId = read.i();
|
||||
}
|
||||
}
|
||||
}
|
||||
109
core/src/mindustry/world/blocks/units/UnitCargoUnloadPoint.java
Normal file
109
core/src/mindustry/world/blocks/units/UnitCargoUnloadPoint.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitCargoUnloadPoint extends Block{
|
||||
/** If a block is full for this amount of time, it will not be flown to anymore. */
|
||||
public float staleTimeDuration = 60f * 6f;
|
||||
|
||||
public @Load("@-top") TextureRegion topRegion;
|
||||
|
||||
public UnitCargoUnloadPoint(String name){
|
||||
super(name);
|
||||
update = solid = true;
|
||||
hasItems = true;
|
||||
configurable = true;
|
||||
saveConfig = true;
|
||||
flags = EnumSet.of(BlockFlag.unitCargoUnloadPoint);
|
||||
|
||||
config(Item.class, (UnitCargoUnloadPointBuild build, Item item) -> build.item = item);
|
||||
configClear((UnitCargoUnloadPointBuild build) -> build.item = null);
|
||||
}
|
||||
|
||||
public class UnitCargoUnloadPointBuild extends Building{
|
||||
public Item item;
|
||||
public float staleTimer;
|
||||
public boolean stale;
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
if(item != null){
|
||||
Draw.color(item.color);
|
||||
Draw.rect(topRegion, x, y);
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
super.updateTile();
|
||||
|
||||
if(items.total() < itemCapacity){
|
||||
staleTimer = 0f;
|
||||
stale = false;
|
||||
}
|
||||
|
||||
if(dumpAccumulate()){
|
||||
staleTimer = 0f;
|
||||
stale = false;
|
||||
}else if(items.total() >= itemCapacity && (staleTimer += Time.delta) >= staleTimeDuration){
|
||||
stale = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Teamc source){
|
||||
return Math.min(itemCapacity - items.total(), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Table table){
|
||||
ItemSelection.buildTable(UnitCargoUnloadPoint.this, table, content.items(), () -> item, this::configure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onConfigureTileTapped(Building other){
|
||||
if(this == other){
|
||||
deselect();
|
||||
configure(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object config(){
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.s(item == null ? -1 : item.id);
|
||||
write.bool(stale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
item = Vars.content.item(read.s());
|
||||
stale = read.bool();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,9 @@ public enum BlockFlag{
|
||||
/** Blocks that extinguishes fires. */
|
||||
extinguisher,
|
||||
/** Just a launch pad. */
|
||||
launchPad;
|
||||
launchPad,
|
||||
/** Destination for unit cargo. */
|
||||
unitCargoUnloadPoint;
|
||||
|
||||
public final static BlockFlag[] all = values();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user