Better payload framework
This commit is contained in:
@@ -26,6 +26,7 @@ import mindustry.type.*;
|
|||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.environment.*;
|
import mindustry.world.blocks.environment.*;
|
||||||
|
import mindustry.world.blocks.payloads.*;
|
||||||
import mindustry.world.blocks.power.*;
|
import mindustry.world.blocks.power.*;
|
||||||
import mindustry.world.consumers.*;
|
import mindustry.world.consumers.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
@@ -315,6 +316,40 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
noSleep();
|
noSleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean acceptPayload(Tilec source, Payload payload){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handlePayload(Tilec source, Payload payload){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries dumping a payload.
|
||||||
|
* @param todump payload to dump.
|
||||||
|
* @return whether the payload was moved successfully
|
||||||
|
*/
|
||||||
|
public boolean dumpPayload(@NonNull Payload todump){
|
||||||
|
Array<Tilec> proximity = proximity();
|
||||||
|
int dump = rotation();
|
||||||
|
|
||||||
|
if(proximity.size == 0) return false;
|
||||||
|
|
||||||
|
for(int i = 0; i < proximity.size; i++){
|
||||||
|
Tilec other = proximity.get((i + dump) % proximity.size);
|
||||||
|
|
||||||
|
if(other.team() == team() && other.acceptPayload(this, todump)){
|
||||||
|
other.handlePayload(this, todump);
|
||||||
|
incrementDump(proximity.size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
incrementDump(proximity.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void handleItem(Tilec source, Item item){
|
public void handleItem(Tilec source, Item item){
|
||||||
items.add(item, 1);
|
items.add(item, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class Block extends UnlockableContent{
|
|||||||
public boolean outputsLiquid = false;
|
public boolean outputsLiquid = false;
|
||||||
public boolean consumesPower = true;
|
public boolean consumesPower = true;
|
||||||
public boolean outputsPower = false;
|
public boolean outputsPower = false;
|
||||||
|
public boolean outputsPayload = false;
|
||||||
|
|
||||||
public int itemCapacity = 10;
|
public int itemCapacity = 10;
|
||||||
public float liquidCapacity = 10f;
|
public float liquidCapacity = 10f;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import mindustry.content.*;
|
|||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.ui.*;
|
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
import mindustry.world.blocks.payloads.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ public class MassConveyor extends Block{
|
|||||||
size = 3;
|
size = 3;
|
||||||
rotate = true;
|
rotate = true;
|
||||||
update = true;
|
update = true;
|
||||||
|
outputsPayload = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,10 +40,10 @@ public class MassConveyor extends Block{
|
|||||||
edgeRegion = Core.atlas.find(name + "-edge");
|
edgeRegion = Core.atlas.find(name + "-edge");
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MassConveyorEntity extends TileEntity implements MassAcceptor{
|
public class MassConveyorEntity extends TileEntity{
|
||||||
public @Nullable Payload item;
|
public @Nullable Payload item;
|
||||||
public float progress, itemRotation, animation;
|
public float progress, itemRotation, animation;
|
||||||
public @Nullable MassAcceptor next;
|
public @Nullable Tilec next;
|
||||||
public boolean blocked;
|
public boolean blocked;
|
||||||
public int step = -1, stepAccepted = -1;
|
public int step = -1, stepAccepted = -1;
|
||||||
|
|
||||||
@@ -52,9 +53,9 @@ public class MassConveyor extends Block{
|
|||||||
|
|
||||||
Tilec accept = nearby(Geometry.d4[rotation()].x * size, Geometry.d4[rotation()].y * size);
|
Tilec accept = nearby(Geometry.d4[rotation()].x * size, Geometry.d4[rotation()].y * size);
|
||||||
//next block must be aligned and of the same size
|
//next block must be aligned and of the same size
|
||||||
if(accept instanceof MassAcceptor && accept.block().size == size &&
|
if(accept.block().size == size &&
|
||||||
tileX() + Geometry.d4[rotation()].x * size == accept.tileX() && tileY() + Geometry.d4[rotation()].y * size == accept.tileY()){
|
tileX() + Geometry.d4[rotation()].x * size == accept.tileX() && tileY() + Geometry.d4[rotation()].y * size == accept.tileY()){
|
||||||
next = (MassAcceptor)accept;
|
next = accept;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ntrns = 1 + size/2;
|
int ntrns = 1 + size/2;
|
||||||
@@ -73,6 +74,7 @@ public class MassConveyor extends Block{
|
|||||||
animation = 0f;
|
animation = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO nondeterministic input priority
|
||||||
int curStep = curStep();
|
int curStep = curStep();
|
||||||
if(curStep > step){
|
if(curStep > step){
|
||||||
boolean valid = step != -1;
|
boolean valid = step != -1;
|
||||||
@@ -83,21 +85,21 @@ public class MassConveyor extends Block{
|
|||||||
//trigger update forward
|
//trigger update forward
|
||||||
next.updateTile();
|
next.updateTile();
|
||||||
|
|
||||||
if(next.acceptMass(item, this)){
|
if(next.acceptPayload(this, item)){
|
||||||
//move forward.
|
//move forward.
|
||||||
next.handleMass(item, this);
|
next.handlePayload(this, item);
|
||||||
item = null;
|
item = null;
|
||||||
}
|
}
|
||||||
}else if(!blocked){
|
}else if(!blocked){
|
||||||
//dump item forward
|
//dump item forward
|
||||||
float trnext = size * tilesize / 2f, cx = Geometry.d4[rotation()].x, cy = Geometry.d4[rotation()].y, rot = rotation() * 90;
|
float trnext = size * tilesize / 2f, cx = Geometry.d4[rotation()].x, cy = Geometry.d4[rotation()].y, rot = rotation() * 90;
|
||||||
|
|
||||||
item.dump(x + cx * trnext, y + cy * trnext, rotation() * 90);
|
if(item.dump(x + cx * trnext, y + cy * trnext, rotation() * 90)){
|
||||||
item = null;
|
item = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -172,13 +174,13 @@ public class MassConveyor extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptMass(Payload item, Tilec source){
|
public boolean acceptPayload(Tilec source, Payload payload){
|
||||||
return this.item == null;
|
return this.item == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMass(Payload item, Tilec source){
|
public void handlePayload(Tilec source, Payload payload){
|
||||||
this.item = item;
|
this.item = payload;
|
||||||
this.stepAccepted = curStep();
|
this.stepAccepted = curStep();
|
||||||
this.itemRotation = source.rotation() * 90;
|
this.itemRotation = source.rotation() * 90;
|
||||||
this.animation = 0;
|
this.animation = 0;
|
||||||
@@ -189,8 +191,9 @@ public class MassConveyor extends Block{
|
|||||||
return !blocked || next != null;
|
return !blocked || next != null;
|
||||||
}else{
|
}else{
|
||||||
Tilec accept = nearby(Geometry.d4[direction].x * size, Geometry.d4[direction].y * size);
|
Tilec accept = nearby(Geometry.d4[direction].x * size, Geometry.d4[direction].y * size);
|
||||||
return accept instanceof MassAcceptor && accept.block().size == size &&
|
return accept.block().size == size && accept.block().outputsPayload &&
|
||||||
accept.tileX() + Geometry.d4[accept.rotation()].x * size == tileX() && accept.tileY() + Geometry.d4[accept.rotation()].y * size == tileY();
|
//block must either be facing this one, or not be rotating
|
||||||
|
((accept.tileX() + Geometry.d4[accept.rotation()].x * size == tileX() && accept.tileY() + Geometry.d4[accept.rotation()].y * size == tileY()) || !accept.block().rotate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +222,7 @@ public class MassConveyor extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
int curStep(){
|
int curStep(){
|
||||||
return (int)(Time.time() / moveTime);
|
return (int)((Time.time()) / moveTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
float fract(){
|
float fract(){
|
||||||
@@ -227,36 +230,4 @@ public class MassConveyor extends Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface MassAcceptor extends Tilec{
|
|
||||||
boolean acceptMass(Payload item, Tilec source);
|
|
||||||
void handleMass(Payload item, Tilec source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Payload{
|
|
||||||
void draw(float x, float y, float rotation);
|
|
||||||
void dump(float x, float y, float rotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class UnitPayload implements Payload{
|
|
||||||
public Unitc unit;
|
|
||||||
|
|
||||||
public UnitPayload(Unitc unit){
|
|
||||||
this.unit = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dump(float x, float y, float rotation){
|
|
||||||
unit.set(x, y);
|
|
||||||
unit.rotation(rotation);
|
|
||||||
unit.add();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(float x, float y, float rotation){
|
|
||||||
Drawf.shadow(x, y, 24);
|
|
||||||
Draw.rect("pneumatic-drill", x, y, rotation);
|
|
||||||
Drawf.shadow(x, y, 20);
|
|
||||||
Draw.rect(unit.type().icon(Cicon.full), x, y, rotation - 90);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package mindustry.world.blocks.payloads;
|
||||||
|
|
||||||
|
public interface Payload{
|
||||||
|
|
||||||
|
/** draws this payload at a position. */
|
||||||
|
void draw(float x, float y, float rotation);
|
||||||
|
|
||||||
|
/** @return whether this payload was dumped. */
|
||||||
|
default boolean dump(float x, float y, float rotation){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package mindustry.world.blocks.payloads;
|
||||||
|
|
||||||
|
import arc.graphics.g2d.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
|
import mindustry.graphics.*;
|
||||||
|
import mindustry.ui.*;
|
||||||
|
|
||||||
|
public class UnitPayload implements Payload{
|
||||||
|
public Unitc unit;
|
||||||
|
|
||||||
|
public UnitPayload(Unitc unit){
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dump(float x, float y, float rotation){
|
||||||
|
unit.set(x, y);
|
||||||
|
unit.rotation(rotation);
|
||||||
|
unit.add();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(float x, float y, float rotation){
|
||||||
|
Drawf.shadow(x, y, 24);
|
||||||
|
Draw.rect("pneumatic-drill", x, y, rotation);
|
||||||
|
Drawf.shadow(x, y, 20);
|
||||||
|
Draw.rect(unit.type().icon(Cicon.full), x, y, rotation - 90);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user