Experimental: block loader/unloaders
This commit is contained in:
@@ -50,7 +50,6 @@ public class Block extends UnlockableContent{
|
||||
public int itemCapacity = 10;
|
||||
public float liquidCapacity = 10f;
|
||||
public float liquidPressure = 1f;
|
||||
public int dumpIncrement = 1;
|
||||
|
||||
public final BlockStats stats = new BlockStats();
|
||||
public final BlockBars bars = new BlockBars();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mindustry.world;
|
||||
|
||||
import arc.func.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.modules.*;
|
||||
@@ -20,13 +21,13 @@ public class CachedTile extends Tile{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void changeEntity(Team team){
|
||||
protected void changeEntity(Team team, Prov<Tilec> entityprov){
|
||||
entity = null;
|
||||
|
||||
Block block = block();
|
||||
|
||||
if(block.hasEntity()){
|
||||
Tilec n = block.newEntity();
|
||||
Tilec n = entityprov.get();
|
||||
n.cons(new ConsumeModule(entity));
|
||||
n.tile(this);
|
||||
n.block(block);
|
||||
|
||||
@@ -12,7 +12,6 @@ import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.blocks.environment.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -24,10 +23,12 @@ public class Tile implements Position, QuadTreeObject{
|
||||
/** Tile entity, usually null. */
|
||||
public @Nullable Tilec entity;
|
||||
public short x, y;
|
||||
/** Extra data. Used for dumping. */
|
||||
public byte data;
|
||||
protected @NonNull Block block;
|
||||
protected @NonNull Floor floor;
|
||||
protected @NonNull Floor overlay;
|
||||
/** Rotation, 0-3. Also used to store offload location, in which case it can be any number.*/
|
||||
/** Rotation, 0-3. Not guaranteed to be in any specific range. */
|
||||
protected byte rotation;
|
||||
protected boolean changing = false;
|
||||
|
||||
@@ -45,7 +46,7 @@ public class Tile implements Position, QuadTreeObject{
|
||||
this.block = wall;
|
||||
|
||||
//update entity and create it if needed
|
||||
changeEntity(Team.derelict);
|
||||
changeEntity(Team.derelict, wall::newEntity);
|
||||
changed();
|
||||
}
|
||||
|
||||
@@ -164,12 +165,16 @@ public class Tile implements Position, QuadTreeObject{
|
||||
}
|
||||
|
||||
public void setBlock(@NonNull Block type, Team team, int rotation){
|
||||
setBlock(type, team, rotation, type::newEntity);
|
||||
}
|
||||
|
||||
public void setBlock(@NonNull Block type, Team team, int rotation, Prov<Tilec> entityprov){
|
||||
changing = true;
|
||||
|
||||
this.block = type;
|
||||
this.rotation = rotation == 0 ? 0 : (byte)Mathf.mod(rotation, 4);
|
||||
preChanged();
|
||||
changeEntity(team);
|
||||
changeEntity(team, entityprov);
|
||||
|
||||
if(entity != null){
|
||||
entity.team(team);
|
||||
@@ -523,7 +528,7 @@ public class Tile implements Position, QuadTreeObject{
|
||||
}
|
||||
}
|
||||
|
||||
protected void changeEntity(Team team){
|
||||
protected void changeEntity(Team team, Prov<Tilec> entityprov){
|
||||
if(entity != null){
|
||||
int size = entity.block().size;
|
||||
entity.remove();
|
||||
@@ -546,14 +551,7 @@ public class Tile implements Position, QuadTreeObject{
|
||||
}
|
||||
|
||||
if(block.hasEntity()){
|
||||
entity = block.newEntity().init(this, team, block.update);
|
||||
entity.cons(new ConsumeModule(entity));
|
||||
if(block.hasItems) entity.items(new ItemModule());
|
||||
if(block.hasLiquids) entity.liquids(new LiquidModule());
|
||||
if(block.hasPower){
|
||||
entity.power(new PowerModule());
|
||||
entity.power().graph.add(entity);
|
||||
}
|
||||
entity = entityprov.get().init(this, team, block.update);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.*;
|
||||
@@ -193,6 +194,24 @@ public class PayloadConveyor extends Block{
|
||||
this.animation = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
|
||||
write.f(progress);
|
||||
write.f(itemRotation);
|
||||
Payload.write(item, write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
|
||||
progress = read.f();
|
||||
itemRotation = read.f();
|
||||
item = Payload.read(read);
|
||||
}
|
||||
|
||||
boolean blends(int direction){
|
||||
if(direction == rotation()){
|
||||
return !blocked || next != null;
|
||||
|
||||
@@ -41,7 +41,6 @@ public class StackConveyor extends Block implements Autotiler{
|
||||
idleSound = Sounds.conveyor;
|
||||
idleSoundVolume = 0.004f;
|
||||
unloadable = false;
|
||||
dumpIncrement = 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,8 +5,11 @@ import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
@@ -14,9 +17,12 @@ import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
import mindustry.world.consumers.*;
|
||||
|
||||
public class BlockForge extends Block{
|
||||
public class BlockForge extends PayloadAcceptor{
|
||||
public float buildSpeed = 0.4f;
|
||||
public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion;
|
||||
|
||||
public BlockForge(String name){
|
||||
super(name);
|
||||
@@ -27,8 +33,19 @@ public class BlockForge extends Block{
|
||||
hasItems = true;
|
||||
configurable = true;
|
||||
hasPower = true;
|
||||
rotate = true;
|
||||
|
||||
config(Block.class, (tile, block) -> ((BlockForgeEntity)tile).recipe = block);
|
||||
|
||||
consumes.add(new ConsumeItemDynamic(e -> {
|
||||
BlockForgeEntity entity = (BlockForgeEntity)e;
|
||||
|
||||
if(entity.recipe != null){
|
||||
return entity.recipe.requirements;
|
||||
}
|
||||
|
||||
return ItemStack.empty;
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,8 +55,13 @@ public class BlockForge extends Block{
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, () -> ((BlockForgeEntity)entity).progress));
|
||||
}
|
||||
|
||||
public class BlockForgeEntity extends TileEntity{
|
||||
public @Nullable Payload payload;
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
Draw.rect(region, req.drawx(), req.drawy());
|
||||
Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90);
|
||||
}
|
||||
|
||||
public class BlockForgeEntity extends PayloadAcceptorEntity<BlockPayload>{
|
||||
public @Nullable Block recipe;
|
||||
public float progress, time, heat;
|
||||
|
||||
@@ -57,16 +79,21 @@ public class BlockForge extends Block{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Tilec source, Payload payload){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
boolean produce = recipe != null && consValid() && payload == null && items.has(recipe.requirements);
|
||||
boolean produce = recipe != null && consValid() && payload == null;
|
||||
|
||||
if(produce){
|
||||
progress += buildSpeed * edelta();
|
||||
|
||||
if(progress >= recipe.buildCost){
|
||||
items.remove(recipe.requirements);
|
||||
payload = new BlockPayload(recipe);
|
||||
consume();
|
||||
payload = new BlockPayload(recipe, team);
|
||||
progress = 0f;
|
||||
}
|
||||
}else{
|
||||
@@ -76,14 +103,12 @@ public class BlockForge extends Block{
|
||||
heat = Mathf.lerpDelta(heat, Mathf.num(produce), 0.3f);
|
||||
time += heat * delta();
|
||||
|
||||
if(payload != null && dumpPayload(payload)){
|
||||
payload = null;
|
||||
}
|
||||
moveOutPayload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Table table){
|
||||
Array<Block> blocks = Vars.content.blocks().select(b -> b.isVisible() && b.size <= 2 && b.requirements.length <= 3);
|
||||
Array<Block> blocks = Vars.content.blocks().select(b -> b.isVisible() && b.size <= 2);
|
||||
|
||||
ItemSelection.buildTable(table, blocks, () -> recipe, block -> recipe = block);
|
||||
}
|
||||
@@ -95,11 +120,8 @@ public class BlockForge extends Block{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
if(payload != null){
|
||||
payload.draw(x, y, 0);
|
||||
}
|
||||
Draw.rect(region, x, y);
|
||||
Draw.rect(outRegion, x, y, rotdeg());
|
||||
|
||||
if(recipe != null){
|
||||
Draw.draw(Layer.blockOver, () -> {
|
||||
@@ -123,6 +145,8 @@ public class BlockForge extends Block{
|
||||
Draw.reset();
|
||||
});
|
||||
}
|
||||
|
||||
drawPayload();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,7 +49,7 @@ public class BlockLauncher extends PayloadAcceptor{
|
||||
positions.clear();
|
||||
|
||||
Geometry.circle(tileX(), tileY(), world.width(), world.height(), (int)(range / tilesize), (cx, cy) -> {
|
||||
if(Build.validPlace(team, cx, cy, payload.block, 0)){
|
||||
if(Build.validPlace(team, cx, cy, payload.entity.block(), 0)){
|
||||
positions.add(Point2.pack(cx, cy));
|
||||
}
|
||||
});
|
||||
@@ -57,7 +57,7 @@ public class BlockLauncher extends PayloadAcceptor{
|
||||
if(positions.isEmpty()) return;
|
||||
|
||||
int pick = positions.random();
|
||||
LaunchedBlock launch = new LaunchedBlock(Point2.x(pick), Point2.y(pick), payload.block, team);
|
||||
LaunchedBlock launch = new LaunchedBlock(Point2.x(pick), Point2.y(pick), payload.entity.block(), team);
|
||||
Fx.blockTransfer.at(x, y, 0, launch);
|
||||
Time.run(Fx.blockTransfer.lifetime, () -> {
|
||||
float ex = launch.x * tilesize + launch.block.offset(), ey = launch.y * tilesize + launch.block.offset();
|
||||
|
||||
144
core/src/mindustry/world/blocks/experimental/BlockLoader.java
Normal file
144
core/src/mindustry/world/blocks/experimental/BlockLoader.java
Normal file
@@ -0,0 +1,144 @@
|
||||
package mindustry.world.blocks.experimental;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class BlockLoader extends PayloadAcceptor{
|
||||
public final int timerLoad = timers++;
|
||||
|
||||
public float loadTime = 2f;
|
||||
public int itemsLoaded = 5;
|
||||
public float liquidsLoaded = 5f;
|
||||
|
||||
public @Load(value = "@-top", fallback = "factory-top") TextureRegion topRegion;
|
||||
public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion;
|
||||
public @Load(value = "@-in", fallback = "factory-in") TextureRegion inRegion;
|
||||
|
||||
public BlockLoader(String name){
|
||||
super(name);
|
||||
|
||||
hasItems = true;
|
||||
itemCapacity = 25;
|
||||
//liquidCapacity = 25;
|
||||
update = true;
|
||||
outputsPayload = true;
|
||||
size = 3;
|
||||
rotate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputsItems(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, ((BlockLoaderEntity)entity)::fraction));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
Draw.rect(region, req.drawx(), req.drawy());
|
||||
Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90);
|
||||
Draw.rect(topRegion, req.drawx(), req.drawy());
|
||||
}
|
||||
|
||||
public class BlockLoaderEntity extends PayloadAcceptorEntity<BlockPayload>{
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Tilec source, Payload payload){
|
||||
return super.acceptPayload(source, payload) &&
|
||||
(payload instanceof BlockPayload) &&
|
||||
((((BlockPayload)payload).entity.block().hasItems && ((BlockPayload)payload).block().unloadable && ((BlockPayload)payload).block().itemCapacity >= 10)/* ||
|
||||
((BlockPayload)payload).entity.block().hasLiquids && ((BlockPayload)payload).block().liquidCapacity >= 10f)*/);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Tilec source, Item item){
|
||||
return items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect(region, x, y);
|
||||
|
||||
//draw input
|
||||
for(int i = 0; i < 4; i++){
|
||||
if(blends(this, i) && i != rotation()){
|
||||
Draw.rect(inRegion, x, y, i * 90);
|
||||
}
|
||||
}
|
||||
|
||||
Draw.rect(outRegion, x, y, rotdeg());
|
||||
|
||||
Draw.z(Layer.blockOver);
|
||||
payRotation = rotdeg();
|
||||
drawPayload();
|
||||
|
||||
Draw.z(Layer.blockOver + 0.1f);
|
||||
Draw.rect(topRegion, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(shouldExport()){
|
||||
moveOutPayload();
|
||||
}else if(moveInPayload()){
|
||||
|
||||
//load up items
|
||||
if(payload.block().hasItems && items.any()){
|
||||
if(timer(timerLoad, loadTime)){
|
||||
//load up items a set amount of times
|
||||
for(int j = 0; j < itemsLoaded && items.any(); j++){
|
||||
|
||||
for(int i = 0; i < items.length(); i++){
|
||||
if(items.get(i) > 0){
|
||||
Item item = content.item(i);
|
||||
if(payload.entity.acceptItem(payload.entity, item)){
|
||||
payload.entity.handleItem(payload.entity, item);
|
||||
items.remove(item, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//load up liquids (disabled)
|
||||
/*
|
||||
if(payload.block().hasLiquids && liquids.total() >= 0.001f){
|
||||
Liquid liq = liquids.current();
|
||||
float total = liquids.currentAmount();
|
||||
float flow = Math.min(Math.min(liquidsLoaded * delta(), payload.block().liquidCapacity - payload.entity.liquids().get(liq) - 0.0001f), total);
|
||||
if(payload.entity.acceptLiquid(payload.entity, liq, flow)){
|
||||
payload.entity.liquids().add(liq, flow);
|
||||
liquids.remove(liq, flow);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public float fraction(){
|
||||
return payload == null ? 0f : payload.entity.items().total() / (float)payload.entity.block().itemCapacity;
|
||||
}
|
||||
|
||||
public boolean shouldExport(){
|
||||
return payload != null &&
|
||||
((payload.block().hasLiquids && payload.entity.liquids().total() >= payload.block().liquidCapacity - 0.001f) ||
|
||||
(payload.block().hasItems && payload.entity.items().total() >= payload.block().itemCapacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package mindustry.world.blocks.experimental;
|
||||
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class BlockUnloader extends BlockLoader{
|
||||
|
||||
public BlockUnloader(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputsItems(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public class BlockUnloaderEntity extends BlockLoaderEntity{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Tilec source, Item item){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(shouldExport()){
|
||||
moveOutPayload();
|
||||
}else if(moveInPayload()){
|
||||
|
||||
//load up items
|
||||
if(payload.block().hasItems && !full()){
|
||||
if(timer(timerLoad, loadTime)){
|
||||
//load up items a set amount of times
|
||||
for(int j = 0; j < itemsLoaded && !full(); j++){
|
||||
for(int i = 0; i < items.length(); i++){
|
||||
if(payload.entity.items().get(i) > 0){
|
||||
Item item = content.item(i);
|
||||
payload.entity.items().remove(item, 1);
|
||||
items.add(item, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dump();
|
||||
}
|
||||
|
||||
public boolean full(){
|
||||
return items.total() >= itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float fraction(){
|
||||
return payload == null ? 0f : 1f - payload.entity.items().total() / (float)payload.entity.block().itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExport(){
|
||||
return payload != null && (payload.block().hasItems && payload.entity.items().empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package mindustry.world.blocks.payloads;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
@@ -8,15 +11,40 @@ import mindustry.world.*;
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class BlockPayload implements Payload{
|
||||
public Block block;
|
||||
public Tilec entity;
|
||||
|
||||
public BlockPayload(Block block){
|
||||
this.block = block;
|
||||
public BlockPayload(Block block, Team team){
|
||||
this.entity = block.newEntity().create(block, team);
|
||||
}
|
||||
|
||||
public Block block(){
|
||||
return entity.block();
|
||||
}
|
||||
|
||||
public void place(Tile tile){
|
||||
place(tile, 0);
|
||||
}
|
||||
|
||||
public void place(Tile tile, int rotation){
|
||||
tile.setBlock(entity.block(), entity.team(), rotation, () -> entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
write.b(payloadBlock);
|
||||
write.s(entity.block().id);
|
||||
write.b(entity.version());
|
||||
entity.writeAll(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(float x, float y){
|
||||
entity.set(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(float x, float y, float rotation){
|
||||
Drawf.shadow(x, y, block.size * tilesize * 2f);
|
||||
Draw.rect(block.icon(Cicon.full), x, y, 0);
|
||||
Drawf.shadow(x, y, entity.block().size * tilesize * 2f);
|
||||
Draw.rect(entity.block().icon(Cicon.full), x, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,58 @@
|
||||
package mindustry.world.blocks.payloads;
|
||||
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public interface Payload{
|
||||
int payloadUnit = 0, payloadBlock = 1;
|
||||
|
||||
/** draws this payload at a position. */
|
||||
void draw(float x, float y, float rotation);
|
||||
|
||||
/** writes the payload for saving. */
|
||||
void write(Writes write);
|
||||
|
||||
/** sets this payload's position on the map. */
|
||||
void set(float x, float y);
|
||||
|
||||
/** @return whether this payload was dumped. */
|
||||
default boolean dump(float x, float y, float rotation){
|
||||
return false;
|
||||
}
|
||||
|
||||
static void write(@Nullable Payload payload, Writes write){
|
||||
if(payload == null){
|
||||
write.bool(false);
|
||||
}else{
|
||||
write.bool(true);
|
||||
payload.write(write);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
static <T extends Payload> T read(Reads read){
|
||||
boolean exists = read.bool();
|
||||
if(!exists) return null;
|
||||
|
||||
byte type = read.b();
|
||||
if(type == payloadBlock){
|
||||
Block block = content.block(read.s());
|
||||
BlockPayload payload = new BlockPayload(block, Team.derelict);
|
||||
byte version = read.b();
|
||||
payload.entity.readAll(read, version);
|
||||
return (T)payload;
|
||||
}else if(type == payloadUnit){
|
||||
byte id = read.b();
|
||||
Unitc unit = (Unitc)EntityMapping.map(id).get();
|
||||
unit.read(read);
|
||||
return (T)new UnitPayload(unit);
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown payload type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.blocks.payloads;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
@@ -13,6 +14,18 @@ public class UnitPayload implements Payload{
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
write.b(payloadUnit);
|
||||
write.b(unit.classId());
|
||||
unit.write(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(float x, float y){
|
||||
unit.set(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dump(float x, float y, float rotation){
|
||||
//no client dumping
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
@@ -51,12 +52,40 @@ public class PayloadAcceptor extends Block{
|
||||
public boolean moveInPayload(){
|
||||
if(payload == null) return false;
|
||||
|
||||
payload.set(x + payVector.x, y + payVector.y);
|
||||
payRotation = Mathf.slerpDelta(payRotation, rotate ? rotdeg() : 90f, 0.3f);
|
||||
payVector.approachDelta(Vec2.ZERO, payloadSpeed);
|
||||
|
||||
return hasArrived();
|
||||
}
|
||||
|
||||
public void moveOutPayload(){
|
||||
if(payload == null) return;
|
||||
|
||||
payload.set(x + payVector.x, y + payVector.y);
|
||||
payVector.trns(rotdeg(), payVector.len() + edelta() * payloadSpeed);
|
||||
payRotation = rotdeg();
|
||||
|
||||
if(payVector.len() >= size * tilesize/2f){
|
||||
payVector.clamp(-size * tilesize / 2f, size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f);
|
||||
|
||||
Tile front = frontLarge();
|
||||
if(front != null && front.entity != null && front.block().outputsPayload){
|
||||
if(movePayload(payload)){
|
||||
payload = null;
|
||||
}
|
||||
}else if(front != null && !front.solid()){
|
||||
dumpPayload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dumpPayload(){
|
||||
if(payload.dump(x + payVector.x, y + payVector.y, payRotation)){
|
||||
payload = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasArrived(){
|
||||
return payVector.isZero(0.01f);
|
||||
}
|
||||
@@ -67,5 +96,24 @@ public class PayloadAcceptor extends Block{
|
||||
payload.draw(x + payVector.x, y + payVector.y, payRotation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
|
||||
write.f(payVector.x);
|
||||
write.f(payVector.y);
|
||||
write.f(payRotation);
|
||||
Payload.write(payload, write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
|
||||
payVector.set(read.f(), read.f());
|
||||
payRotation = read.f();
|
||||
payload = Payload.read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class Reconstructor extends UnitBlock{
|
||||
if(payload != null){
|
||||
//check if offloading
|
||||
if(payload.unit.type().upgrade == null || payload.unit.type().tier != tier){
|
||||
outputPayload();
|
||||
moveOutPayload();
|
||||
}else{ //update progress
|
||||
if(moveInPayload()){
|
||||
if(consValid()){
|
||||
|
||||
@@ -31,7 +31,7 @@ public class UnitBlock extends PayloadAcceptor{
|
||||
}
|
||||
|
||||
public class UnitBlockEntity extends PayloadAcceptorEntity<UnitPayload>{
|
||||
public float progress, payloadPos, time, speedScl;
|
||||
public float progress, time, speedScl;
|
||||
|
||||
public void spawned(){
|
||||
progress = 0f;
|
||||
@@ -51,29 +51,11 @@ public class UnitBlock extends PayloadAcceptor{
|
||||
}
|
||||
|
||||
payload = null;
|
||||
payloadPos = 0f;
|
||||
}
|
||||
|
||||
public void outputPayload(){
|
||||
if(payload == null) return;
|
||||
|
||||
payloadPos += edelta() * payloadSpeed;
|
||||
payVector.trns(rotdeg(), payloadPos);
|
||||
payRotation = rotdeg();
|
||||
|
||||
if(payloadPos >= size * tilesize/2f){
|
||||
payloadPos = size * tilesize/2f;
|
||||
|
||||
Tile front = frontLarge();
|
||||
if(front != null && front.entity != null && front.block().outputsPayload){
|
||||
if(movePayload(payload)){
|
||||
payload = null;
|
||||
}
|
||||
}else if(front != null && !front.solid()){
|
||||
//create unit if there's space
|
||||
Call.onUnitBlockSpawn(tile);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void dumpPayload(){
|
||||
Call.onUnitBlockSpawn(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ public class UnitFactory extends UnitBlock{
|
||||
speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f);
|
||||
}
|
||||
|
||||
outputPayload();
|
||||
moveOutPayload();
|
||||
|
||||
if(currentPlan != -1 && payload == null){
|
||||
UnitPlan plan = plans[currentPlan];
|
||||
@@ -196,7 +196,6 @@ public class UnitFactory extends UnitBlock{
|
||||
if(progress >= plan.time && Units.canCreate(team)){
|
||||
progress = 0f;
|
||||
|
||||
payloadPos = 0f;
|
||||
payload = new UnitPayload(plan.unit.create(team));
|
||||
payVector.setZero();
|
||||
consume();
|
||||
|
||||
@@ -66,6 +66,10 @@ public class ItemModule extends BlockModule{
|
||||
}
|
||||
}
|
||||
|
||||
public int length(){
|
||||
return items.length;
|
||||
}
|
||||
|
||||
/** @return a specific item's flow rate in items/s; any value < 0 means not ready.*/
|
||||
public float getFlowRate(Item item){
|
||||
if(flow == null) return -1f;
|
||||
|
||||
Reference in New Issue
Block a user