Experimental: block loader/unloaders
BIN
core/assets-raw/sprites/blocks/distribution/block-loader.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
core/assets-raw/sprites/blocks/distribution/block-unloader.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
@@ -233,3 +233,4 @@
|
|||||||
63511=naval-factory|block-naval-factory-medium
|
63511=naval-factory|block-naval-factory-medium
|
||||||
63510=air-factory|block-air-factory-medium
|
63510=air-factory|block-air-factory-medium
|
||||||
63509=basic-reconstructor|block-basic-reconstructor-medium
|
63509=basic-reconstructor|block-basic-reconstructor-medium
|
||||||
|
63508=block-loader|block-block-loader-medium
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 717 B After Width: | Height: | Size: 720 B |
|
Before Width: | Height: | Size: 818 KiB After Width: | Height: | Size: 820 KiB |
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 122 KiB |
|
Before Width: | Height: | Size: 243 KiB After Width: | Height: | Size: 244 KiB |
|
Before Width: | Height: | Size: 859 KiB After Width: | Height: | Size: 867 KiB |
@@ -24,6 +24,7 @@ import mindustry.maps.*;
|
|||||||
import mindustry.mod.*;
|
import mindustry.mod.*;
|
||||||
import mindustry.net.Net;
|
import mindustry.net.Net;
|
||||||
import mindustry.net.*;
|
import mindustry.net.*;
|
||||||
|
import mindustry.world.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
@@ -84,6 +85,8 @@ public class Vars implements Loadable{
|
|||||||
public static final float turnDuration = 5 * Time.toMinutes;
|
public static final float turnDuration = 5 * Time.toMinutes;
|
||||||
/** min armor fraction damage; e.g. 0.05 = at least 5% damage */
|
/** min armor fraction damage; e.g. 0.05 = at least 5% damage */
|
||||||
public static final float minArmorDamage = 0.05f;
|
public static final float minArmorDamage = 0.05f;
|
||||||
|
/** tile used in certain situations, instead of null */
|
||||||
|
public static Tile emptyTile;
|
||||||
/** for map generator dialog */
|
/** for map generator dialog */
|
||||||
public static boolean updateEditorOnChange = false;
|
public static boolean updateEditorOnChange = false;
|
||||||
/** size of tiles in units */
|
/** size of tiles in units */
|
||||||
@@ -231,6 +234,7 @@ public class Vars implements Loadable{
|
|||||||
schematicDirectory = dataDirectory.child("schematics/");
|
schematicDirectory = dataDirectory.child("schematics/");
|
||||||
bebuildDirectory = dataDirectory.child("be_builds/");
|
bebuildDirectory = dataDirectory.child("be_builds/");
|
||||||
emptyMap = new Map(new StringMap());
|
emptyMap = new Map(new StringMap());
|
||||||
|
emptyTile = null;
|
||||||
|
|
||||||
if(tree == null) tree = new FileTree();
|
if(tree == null) tree = new FileTree();
|
||||||
if(mods == null) mods = new Mods();
|
if(mods == null) mods = new Mods();
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class Blocks implements ContentList{
|
|||||||
|
|
||||||
//misc experimental
|
//misc experimental
|
||||||
|
|
||||||
blockForge, blockLauncher;
|
blockForge, blockLauncher, blockLoader, blockUnloader;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
@@ -1789,6 +1789,20 @@ public class Blocks implements ContentList{
|
|||||||
consumes.power(2f);
|
consumes.power(2f);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
blockLoader = new BlockLoader("block-loader"){{
|
||||||
|
requirements(Category.production, BuildVisibility.debugOnly, ItemStack.with(Items.thorium, 100));
|
||||||
|
hasPower = true;
|
||||||
|
consumes.power(2f);
|
||||||
|
size = 3;
|
||||||
|
}};
|
||||||
|
|
||||||
|
blockUnloader = new BlockUnloader("block-unloader"){{
|
||||||
|
requirements(Category.production, BuildVisibility.debugOnly, ItemStack.with(Items.thorium, 100));
|
||||||
|
hasPower = true;
|
||||||
|
consumes.power(2f);
|
||||||
|
size = 3;
|
||||||
|
}};
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package mindustry.editor;
|
package mindustry.editor;
|
||||||
|
|
||||||
|
import arc.func.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.editor.DrawOperation.*;
|
import mindustry.editor.DrawOperation.*;
|
||||||
@@ -108,9 +109,9 @@ public class EditorTile extends Tile{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void changeEntity(Team team){
|
protected void changeEntity(Team team, Prov<Tilec> entityprov){
|
||||||
if(state.isGame()){
|
if(state.isGame()){
|
||||||
super.changeEntity(team);
|
super.changeEntity(team, entityprov);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ public class EditorTile extends Tile{
|
|||||||
Block block = block();
|
Block block = block();
|
||||||
|
|
||||||
if(block.hasEntity()){
|
if(block.hasEntity()){
|
||||||
entity = block.newEntity().init(this, team, false);
|
entity = entityprov.get().init(this, team, false);
|
||||||
entity.cons(new ConsumeModule(entity));
|
entity.cons(new ConsumeModule(entity));
|
||||||
if(block.hasItems) entity.items(new ItemModule());
|
if(block.hasItems) entity.items(new ItemModule());
|
||||||
if(block.hasLiquids) entity.liquids(new LiquidModule());
|
if(block.hasLiquids) entity.liquids(new LiquidModule());
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class MapGenerateDialog extends FloatingDialog{
|
|||||||
private CachedTile ctile = new CachedTile(){
|
private CachedTile ctile = new CachedTile(){
|
||||||
//nothing.
|
//nothing.
|
||||||
@Override
|
@Override
|
||||||
protected void changeEntity(Team team){
|
protected void changeEntity(Team team, Prov<Tilec> entityprov){
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import arc.util.*;
|
|||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.audio.SoundLoop;
|
import mindustry.audio.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
@@ -64,14 +64,32 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
|
|
||||||
private transient boolean sleeping;
|
private transient boolean sleeping;
|
||||||
private transient float sleepTime;
|
private transient float sleepTime;
|
||||||
|
private transient boolean initialized;
|
||||||
|
|
||||||
/** Sets this tile entity data to this and adds it if necessary. */
|
/** Sets this tile entity data to this and adds it if necessary. */
|
||||||
public Tilec init(Tile tile, Team team, boolean shouldAdd){
|
public Tilec init(Tile tile, Team team, boolean shouldAdd){
|
||||||
|
if(!initialized){
|
||||||
|
create(tile.block(), team);
|
||||||
|
}
|
||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
this.block = tile.block();
|
|
||||||
this.team = team;
|
|
||||||
|
|
||||||
set(tile.drawx(), tile.drawy());
|
set(tile.drawx(), tile.drawy());
|
||||||
|
|
||||||
|
if(shouldAdd){
|
||||||
|
add();
|
||||||
|
}
|
||||||
|
|
||||||
|
created();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets up all the necessary variables, but does not add this entity anywhere. */
|
||||||
|
public Tilec create(Block block, Team team){
|
||||||
|
this.tile = emptyTile;
|
||||||
|
this.block = block;
|
||||||
|
this.team = team;
|
||||||
|
|
||||||
if(block.activeSound != Sounds.none){
|
if(block.activeSound != Sounds.none){
|
||||||
sound = new SoundLoop(block.activeSound, block.activeSoundVolume);
|
sound = new SoundLoop(block.activeSound, block.activeSoundVolume);
|
||||||
}
|
}
|
||||||
@@ -80,11 +98,15 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
maxHealth(block.health);
|
maxHealth(block.health);
|
||||||
timer(new Interval(block.timers));
|
timer(new Interval(block.timers));
|
||||||
|
|
||||||
if(shouldAdd){
|
cons = new ConsumeModule(this);
|
||||||
add();
|
if(block.hasItems) items = new ItemModule();
|
||||||
|
if(block.hasLiquids) liquids = new LiquidModule();
|
||||||
|
if(block.hasPower){
|
||||||
|
power = new PowerModule();
|
||||||
|
power.graph.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
created();
|
initialized = true;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -382,7 +404,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
* @return whether the payload was moved successfully
|
* @return whether the payload was moved successfully
|
||||||
*/
|
*/
|
||||||
public boolean dumpPayload(@NonNull Payload todump){
|
public boolean dumpPayload(@NonNull Payload todump){
|
||||||
int dump = rotation();
|
int dump = tile.data;
|
||||||
|
|
||||||
if(proximity.size == 0) return false;
|
if(proximity.size == 0) return false;
|
||||||
|
|
||||||
@@ -418,7 +440,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void dumpLiquid(Liquid liquid){
|
public void dumpLiquid(Liquid liquid){
|
||||||
int dump = rotation() / block.dumpIncrement;
|
int dump = tile.data;
|
||||||
|
|
||||||
for(int i = 0; i < proximity.size; i++){
|
for(int i = 0; i < proximity.size; i++){
|
||||||
incrementDump(proximity.size);
|
incrementDump(proximity.size);
|
||||||
@@ -513,7 +535,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
*/
|
*/
|
||||||
public void offload(Item item){
|
public void offload(Item item){
|
||||||
Array<Tilec> proximity = proximity();
|
Array<Tilec> proximity = proximity();
|
||||||
int dump = rotation() / block.dumpIncrement;
|
int dump = tile.data;
|
||||||
useContent(item);
|
useContent(item);
|
||||||
|
|
||||||
for(int i = 0; i < proximity.size; i++){
|
for(int i = 0; i < proximity.size; i++){
|
||||||
@@ -533,7 +555,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
*/
|
*/
|
||||||
public boolean put(Item item){
|
public boolean put(Item item){
|
||||||
Array<Tilec> proximity = proximity();
|
Array<Tilec> proximity = proximity();
|
||||||
int dump = rotation() / block.dumpIncrement;
|
int dump = tile.data;
|
||||||
useContent(item);
|
useContent(item);
|
||||||
|
|
||||||
for(int i = 0; i < proximity.size; i++){
|
for(int i = 0; i < proximity.size; i++){
|
||||||
@@ -561,7 +583,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
if(!block.hasItems || items.total() == 0 || (todump != null && !items.has(todump))) return false;
|
if(!block.hasItems || items.total() == 0 || (todump != null && !items.has(todump))) return false;
|
||||||
|
|
||||||
Array<Tilec> proximity = proximity();
|
Array<Tilec> proximity = proximity();
|
||||||
int dump = rotation() / block.dumpIncrement;
|
int dump = tile.data;
|
||||||
|
|
||||||
if(proximity.size == 0) return false;
|
if(proximity.size == 0) return false;
|
||||||
|
|
||||||
@@ -596,7 +618,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void incrementDump(int prox){
|
public void incrementDump(int prox){
|
||||||
rotation((byte)((rotation() + block.dumpIncrement) % (prox * block.dumpIncrement)));
|
tile.data = (byte)((tile.data + 1) % prox);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used for dumping items. */
|
/** Used for dumping items. */
|
||||||
|
|||||||
@@ -765,7 +765,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tilec tile = world.entWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y);
|
Tilec tile = world.entWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y);
|
||||||
if(tile instanceof ControlBlock){
|
if(tile instanceof ControlBlock && tile.team() == player.team()){
|
||||||
return ((ControlBlock)tile).unit();
|
return ((ControlBlock)tile).unit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ public class Block extends UnlockableContent{
|
|||||||
public int itemCapacity = 10;
|
public int itemCapacity = 10;
|
||||||
public float liquidCapacity = 10f;
|
public float liquidCapacity = 10f;
|
||||||
public float liquidPressure = 1f;
|
public float liquidPressure = 1f;
|
||||||
public int dumpIncrement = 1;
|
|
||||||
|
|
||||||
public final BlockStats stats = new BlockStats();
|
public final BlockStats stats = new BlockStats();
|
||||||
public final BlockBars bars = new BlockBars();
|
public final BlockBars bars = new BlockBars();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package mindustry.world;
|
package mindustry.world;
|
||||||
|
|
||||||
|
import arc.func.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.world.modules.*;
|
import mindustry.world.modules.*;
|
||||||
@@ -20,13 +21,13 @@ public class CachedTile extends Tile{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void changeEntity(Team team){
|
protected void changeEntity(Team team, Prov<Tilec> entityprov){
|
||||||
entity = null;
|
entity = null;
|
||||||
|
|
||||||
Block block = block();
|
Block block = block();
|
||||||
|
|
||||||
if(block.hasEntity()){
|
if(block.hasEntity()){
|
||||||
Tilec n = block.newEntity();
|
Tilec n = entityprov.get();
|
||||||
n.cons(new ConsumeModule(entity));
|
n.cons(new ConsumeModule(entity));
|
||||||
n.tile(this);
|
n.tile(this);
|
||||||
n.block(block);
|
n.block(block);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import mindustry.game.*;
|
|||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.blocks.environment.*;
|
import mindustry.world.blocks.environment.*;
|
||||||
import mindustry.world.modules.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -24,10 +23,12 @@ public class Tile implements Position, QuadTreeObject{
|
|||||||
/** Tile entity, usually null. */
|
/** Tile entity, usually null. */
|
||||||
public @Nullable Tilec entity;
|
public @Nullable Tilec entity;
|
||||||
public short x, y;
|
public short x, y;
|
||||||
|
/** Extra data. Used for dumping. */
|
||||||
|
public byte data;
|
||||||
protected @NonNull Block block;
|
protected @NonNull Block block;
|
||||||
protected @NonNull Floor floor;
|
protected @NonNull Floor floor;
|
||||||
protected @NonNull Floor overlay;
|
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 byte rotation;
|
||||||
protected boolean changing = false;
|
protected boolean changing = false;
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ public class Tile implements Position, QuadTreeObject{
|
|||||||
this.block = wall;
|
this.block = wall;
|
||||||
|
|
||||||
//update entity and create it if needed
|
//update entity and create it if needed
|
||||||
changeEntity(Team.derelict);
|
changeEntity(Team.derelict, wall::newEntity);
|
||||||
changed();
|
changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,12 +165,16 @@ public class Tile implements Position, QuadTreeObject{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBlock(@NonNull Block type, Team team, int rotation){
|
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;
|
changing = true;
|
||||||
|
|
||||||
this.block = type;
|
this.block = type;
|
||||||
this.rotation = rotation == 0 ? 0 : (byte)Mathf.mod(rotation, 4);
|
this.rotation = rotation == 0 ? 0 : (byte)Mathf.mod(rotation, 4);
|
||||||
preChanged();
|
preChanged();
|
||||||
changeEntity(team);
|
changeEntity(team, entityprov);
|
||||||
|
|
||||||
if(entity != null){
|
if(entity != null){
|
||||||
entity.team(team);
|
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){
|
if(entity != null){
|
||||||
int size = entity.block().size;
|
int size = entity.block().size;
|
||||||
entity.remove();
|
entity.remove();
|
||||||
@@ -546,14 +551,7 @@ public class Tile implements Position, QuadTreeObject{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(block.hasEntity()){
|
if(block.hasEntity()){
|
||||||
entity = block.newEntity().init(this, team, block.update);
|
entity = entityprov.get().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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import arc.math.*;
|
|||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
@@ -193,6 +194,24 @@ public class PayloadConveyor extends Block{
|
|||||||
this.animation = 0;
|
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){
|
boolean blends(int direction){
|
||||||
if(direction == rotation()){
|
if(direction == rotation()){
|
||||||
return !blocked || next != null;
|
return !blocked || next != null;
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ public class StackConveyor extends Block implements Autotiler{
|
|||||||
idleSound = Sounds.conveyor;
|
idleSound = Sounds.conveyor;
|
||||||
idleSoundVolume = 0.004f;
|
idleSoundVolume = 0.004f;
|
||||||
unloadable = false;
|
unloadable = false;
|
||||||
dumpIncrement = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import arc.math.*;
|
|||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
|
import mindustry.entities.units.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
@@ -14,9 +17,12 @@ 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.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 float buildSpeed = 0.4f;
|
||||||
|
public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion;
|
||||||
|
|
||||||
public BlockForge(String name){
|
public BlockForge(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -27,8 +33,19 @@ public class BlockForge extends Block{
|
|||||||
hasItems = true;
|
hasItems = true;
|
||||||
configurable = true;
|
configurable = true;
|
||||||
hasPower = true;
|
hasPower = true;
|
||||||
|
rotate = true;
|
||||||
|
|
||||||
config(Block.class, (tile, block) -> ((BlockForgeEntity)tile).recipe = block);
|
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
|
@Override
|
||||||
@@ -38,8 +55,13 @@ public class BlockForge extends Block{
|
|||||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, () -> ((BlockForgeEntity)entity).progress));
|
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, () -> ((BlockForgeEntity)entity).progress));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BlockForgeEntity extends TileEntity{
|
@Override
|
||||||
public @Nullable Payload payload;
|
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 @Nullable Block recipe;
|
||||||
public float progress, time, heat;
|
public float progress, time, heat;
|
||||||
|
|
||||||
@@ -57,16 +79,21 @@ public class BlockForge extends Block{
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptPayload(Tilec source, Payload payload){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTile(){
|
public void updateTile(){
|
||||||
boolean produce = recipe != null && consValid() && payload == null && items.has(recipe.requirements);
|
boolean produce = recipe != null && consValid() && payload == null;
|
||||||
|
|
||||||
if(produce){
|
if(produce){
|
||||||
progress += buildSpeed * edelta();
|
progress += buildSpeed * edelta();
|
||||||
|
|
||||||
if(progress >= recipe.buildCost){
|
if(progress >= recipe.buildCost){
|
||||||
items.remove(recipe.requirements);
|
consume();
|
||||||
payload = new BlockPayload(recipe);
|
payload = new BlockPayload(recipe, team);
|
||||||
progress = 0f;
|
progress = 0f;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@@ -76,14 +103,12 @@ public class BlockForge extends Block{
|
|||||||
heat = Mathf.lerpDelta(heat, Mathf.num(produce), 0.3f);
|
heat = Mathf.lerpDelta(heat, Mathf.num(produce), 0.3f);
|
||||||
time += heat * delta();
|
time += heat * delta();
|
||||||
|
|
||||||
if(payload != null && dumpPayload(payload)){
|
moveOutPayload();
|
||||||
payload = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildConfiguration(Table table){
|
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);
|
ItemSelection.buildTable(table, blocks, () -> recipe, block -> recipe = block);
|
||||||
}
|
}
|
||||||
@@ -95,11 +120,8 @@ public class BlockForge extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(){
|
public void draw(){
|
||||||
super.draw();
|
Draw.rect(region, x, y);
|
||||||
|
Draw.rect(outRegion, x, y, rotdeg());
|
||||||
if(payload != null){
|
|
||||||
payload.draw(x, y, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(recipe != null){
|
if(recipe != null){
|
||||||
Draw.draw(Layer.blockOver, () -> {
|
Draw.draw(Layer.blockOver, () -> {
|
||||||
@@ -123,6 +145,8 @@ public class BlockForge extends Block{
|
|||||||
Draw.reset();
|
Draw.reset();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class BlockLauncher extends PayloadAcceptor{
|
|||||||
positions.clear();
|
positions.clear();
|
||||||
|
|
||||||
Geometry.circle(tileX(), tileY(), world.width(), world.height(), (int)(range / tilesize), (cx, cy) -> {
|
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));
|
positions.add(Point2.pack(cx, cy));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -57,7 +57,7 @@ public class BlockLauncher extends PayloadAcceptor{
|
|||||||
if(positions.isEmpty()) return;
|
if(positions.isEmpty()) return;
|
||||||
|
|
||||||
int pick = positions.random();
|
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);
|
Fx.blockTransfer.at(x, y, 0, launch);
|
||||||
Time.run(Fx.blockTransfer.lifetime, () -> {
|
Time.run(Fx.blockTransfer.lifetime, () -> {
|
||||||
float ex = launch.x * tilesize + launch.block.offset(), ey = launch.y * tilesize + launch.block.offset();
|
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
@@ -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;
|
package mindustry.world.blocks.payloads;
|
||||||
|
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
|
import arc.util.io.*;
|
||||||
|
import mindustry.game.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
@@ -8,15 +11,40 @@ import mindustry.world.*;
|
|||||||
import static mindustry.Vars.tilesize;
|
import static mindustry.Vars.tilesize;
|
||||||
|
|
||||||
public class BlockPayload implements Payload{
|
public class BlockPayload implements Payload{
|
||||||
public Block block;
|
public Tilec entity;
|
||||||
|
|
||||||
public BlockPayload(Block block){
|
public BlockPayload(Block block, Team team){
|
||||||
this.block = block;
|
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
|
@Override
|
||||||
public void draw(float x, float y, float rotation){
|
public void draw(float x, float y, float rotation){
|
||||||
Drawf.shadow(x, y, block.size * tilesize * 2f);
|
Drawf.shadow(x, y, entity.block().size * tilesize * 2f);
|
||||||
Draw.rect(block.icon(Cicon.full), x, y, 0);
|
Draw.rect(entity.block().icon(Cicon.full), x, y, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,58 @@
|
|||||||
package mindustry.world.blocks.payloads;
|
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{
|
public interface Payload{
|
||||||
|
int payloadUnit = 0, payloadBlock = 1;
|
||||||
|
|
||||||
/** draws this payload at a position. */
|
/** draws this payload at a position. */
|
||||||
void draw(float x, float y, float rotation);
|
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. */
|
/** @return whether this payload was dumped. */
|
||||||
default boolean dump(float x, float y, float rotation){
|
default boolean dump(float x, float y, float rotation){
|
||||||
return false;
|
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;
|
package mindustry.world.blocks.payloads;
|
||||||
|
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
@@ -13,6 +14,18 @@ public class UnitPayload implements Payload{
|
|||||||
this.unit = unit;
|
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
|
@Override
|
||||||
public boolean dump(float x, float y, float rotation){
|
public boolean dump(float x, float y, float rotation){
|
||||||
//no client dumping
|
//no client dumping
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import arc.graphics.g2d.*;
|
|||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
@@ -51,12 +52,40 @@ public class PayloadAcceptor extends Block{
|
|||||||
public boolean moveInPayload(){
|
public boolean moveInPayload(){
|
||||||
if(payload == null) return false;
|
if(payload == null) return false;
|
||||||
|
|
||||||
|
payload.set(x + payVector.x, y + payVector.y);
|
||||||
payRotation = Mathf.slerpDelta(payRotation, rotate ? rotdeg() : 90f, 0.3f);
|
payRotation = Mathf.slerpDelta(payRotation, rotate ? rotdeg() : 90f, 0.3f);
|
||||||
payVector.approachDelta(Vec2.ZERO, payloadSpeed);
|
payVector.approachDelta(Vec2.ZERO, payloadSpeed);
|
||||||
|
|
||||||
return hasArrived();
|
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(){
|
public boolean hasArrived(){
|
||||||
return payVector.isZero(0.01f);
|
return payVector.isZero(0.01f);
|
||||||
}
|
}
|
||||||
@@ -67,5 +96,24 @@ public class PayloadAcceptor extends Block{
|
|||||||
payload.draw(x + payVector.x, y + payVector.y, payRotation);
|
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){
|
if(payload != null){
|
||||||
//check if offloading
|
//check if offloading
|
||||||
if(payload.unit.type().upgrade == null || payload.unit.type().tier != tier){
|
if(payload.unit.type().upgrade == null || payload.unit.type().tier != tier){
|
||||||
outputPayload();
|
moveOutPayload();
|
||||||
}else{ //update progress
|
}else{ //update progress
|
||||||
if(moveInPayload()){
|
if(moveInPayload()){
|
||||||
if(consValid()){
|
if(consValid()){
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class UnitBlock extends PayloadAcceptor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class UnitBlockEntity extends PayloadAcceptorEntity<UnitPayload>{
|
public class UnitBlockEntity extends PayloadAcceptorEntity<UnitPayload>{
|
||||||
public float progress, payloadPos, time, speedScl;
|
public float progress, time, speedScl;
|
||||||
|
|
||||||
public void spawned(){
|
public void spawned(){
|
||||||
progress = 0f;
|
progress = 0f;
|
||||||
@@ -51,29 +51,11 @@ public class UnitBlock extends PayloadAcceptor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload = null;
|
payload = null;
|
||||||
payloadPos = 0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outputPayload(){
|
@Override
|
||||||
if(payload == null) return;
|
public void dumpPayload(){
|
||||||
|
Call.onUnitBlockSpawn(tile);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ public class UnitFactory extends UnitBlock{
|
|||||||
speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f);
|
speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
outputPayload();
|
moveOutPayload();
|
||||||
|
|
||||||
if(currentPlan != -1 && payload == null){
|
if(currentPlan != -1 && payload == null){
|
||||||
UnitPlan plan = plans[currentPlan];
|
UnitPlan plan = plans[currentPlan];
|
||||||
@@ -196,7 +196,6 @@ public class UnitFactory extends UnitBlock{
|
|||||||
if(progress >= plan.time && Units.canCreate(team)){
|
if(progress >= plan.time && Units.canCreate(team)){
|
||||||
progress = 0f;
|
progress = 0f;
|
||||||
|
|
||||||
payloadPos = 0f;
|
|
||||||
payload = new UnitPayload(plan.unit.create(team));
|
payload = new UnitPayload(plan.unit.create(team));
|
||||||
payVector.setZero();
|
payVector.setZero();
|
||||||
consume();
|
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.*/
|
/** @return a specific item's flow rate in items/s; any value < 0 means not ready.*/
|
||||||
public float getFlowRate(Item item){
|
public float getFlowRate(Item item){
|
||||||
if(flow == null) return -1f;
|
if(flow == null) return -1f;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=ca7245cbd7cd13b4343da2f2b105d4fc44058df2
|
archash=67ba53c2135dc53ad9c1e87843029a776a96cc26
|
||||||
|
|||||||
@@ -88,11 +88,7 @@ public class PowerTestFixture{
|
|||||||
|
|
||||||
// Simulate the "changed" method. Calling it through reflections would require half the game to be initialized.
|
// Simulate the "changed" method. Calling it through reflections would require half the game to be initialized.
|
||||||
tile.entity = block.newEntity().init(tile, Team.sharded, false);
|
tile.entity = block.newEntity().init(tile, Team.sharded, false);
|
||||||
tile.entity.cons(new ConsumeModule(tile.entity));
|
|
||||||
if(block.hasItems) tile.entity.items(new ItemModule());
|
|
||||||
if(block.hasLiquids) tile.entity.liquids(new LiquidModule());
|
|
||||||
if(block.hasPower){
|
if(block.hasPower){
|
||||||
tile.entity.power(new PowerModule());
|
|
||||||
tile.entity.power().graph = new PowerGraph(){
|
tile.entity.power().graph = new PowerGraph(){
|
||||||
//assume there's always something consuming power
|
//assume there's always something consuming power
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -242,36 +242,40 @@ public class Generators{
|
|||||||
ImagePacker.generate("unit-icons", () -> {
|
ImagePacker.generate("unit-icons", () -> {
|
||||||
content.units().each(type -> {
|
content.units().each(type -> {
|
||||||
type.load();
|
type.load();
|
||||||
|
try{
|
||||||
|
|
||||||
Image image = ImagePacker.get(type.region);
|
Image image = ImagePacker.get(type.region);
|
||||||
|
|
||||||
if(type.constructor.get() instanceof Legsc){
|
if(type.constructor.get() instanceof Legsc){
|
||||||
image.drawCenter(type.baseRegion);
|
image.drawCenter(type.baseRegion);
|
||||||
image.drawCenter(type.legRegion);
|
image.drawCenter(type.legRegion);
|
||||||
image.drawCenter(type.legRegion, true, false);
|
image.drawCenter(type.legRegion, true, false);
|
||||||
}
|
|
||||||
image.draw(type.region);
|
|
||||||
|
|
||||||
Image baseCell = ImagePacker.get(type.cellRegion);
|
|
||||||
Image cell = new Image(type.cellRegion.getWidth(), type.cellRegion.getHeight());
|
|
||||||
cell.each((x, y) -> cell.draw(x, y, baseCell.getColor(x, y).mul(Color.valueOf("ffa665"))));
|
|
||||||
|
|
||||||
image.draw(cell, image.width/2 - cell.width/2, image.height/2 - cell.height/2);
|
|
||||||
|
|
||||||
for(Weapon weapon : type.weapons){
|
|
||||||
weapon.load();
|
|
||||||
|
|
||||||
for(int i : (weapon.mirror ? Mathf.signs : Mathf.one)){
|
|
||||||
i *= Mathf.sign(weapon.flipped);
|
|
||||||
|
|
||||||
image.draw(weapon.region,
|
|
||||||
(int)(i * weapon.x / Draw.scl + image.width / 2 - weapon.region.getWidth() / 2),
|
|
||||||
(int)(-weapon.y / Draw.scl + image.height / 2f - weapon.region.getHeight() / 2f),
|
|
||||||
i > 0, false);
|
|
||||||
}
|
}
|
||||||
}
|
image.draw(type.region);
|
||||||
|
|
||||||
image.save("unit-" + type.name + "-full");
|
Image baseCell = ImagePacker.get(type.cellRegion);
|
||||||
|
Image cell = new Image(type.cellRegion.getWidth(), type.cellRegion.getHeight());
|
||||||
|
cell.each((x, y) -> cell.draw(x, y, baseCell.getColor(x, y).mul(Color.valueOf("ffa665"))));
|
||||||
|
|
||||||
|
image.draw(cell, image.width / 2 - cell.width / 2, image.height / 2 - cell.height / 2);
|
||||||
|
|
||||||
|
for(Weapon weapon : type.weapons){
|
||||||
|
weapon.load();
|
||||||
|
|
||||||
|
for(int i : (weapon.mirror ? Mathf.signs : Mathf.one)){
|
||||||
|
i *= Mathf.sign(weapon.flipped);
|
||||||
|
|
||||||
|
image.draw(weapon.region,
|
||||||
|
(int)(i * weapon.x / Draw.scl + image.width / 2 - weapon.region.getWidth() / 2),
|
||||||
|
(int)(-weapon.y / Draw.scl + image.height / 2f - weapon.region.getHeight() / 2f),
|
||||||
|
i > 0, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
image.save("unit-" + type.name + "-full");
|
||||||
|
}catch(IllegalArgumentException ignored){
|
||||||
|
//skip
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||