Completely borked liquid/power/inventory system
This commit is contained in:
@@ -16,7 +16,6 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.NetworkIO;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.mindustry.world.Placement;
|
||||
@@ -253,39 +252,6 @@ public class NetClient extends Module {
|
||||
|
||||
Net.handleClient(FriendlyFireChangePacket.class, packet -> state.friendlyFire = packet.enabled);
|
||||
|
||||
Net.handleClient(ItemTransferPacket.class, packet -> {
|
||||
Runnable r = () -> {
|
||||
Tile tile = world.tile(packet.position);
|
||||
if (tile == null || tile.entity == null) return;
|
||||
Tile next = tile.getNearby(packet.rotation);
|
||||
tile.entity.items[packet.itemid] --;
|
||||
next.block().handleItem(Item.getByID(packet.itemid), next, tile);
|
||||
};
|
||||
|
||||
threads.run(r);
|
||||
});
|
||||
|
||||
Net.handleClient(ItemSetPacket.class, packet -> {
|
||||
Runnable r = () -> {
|
||||
Tile tile = world.tile(packet.position);
|
||||
if (tile == null || tile.entity == null) return;
|
||||
tile.entity.items[packet.itemid] = packet.amount;
|
||||
};
|
||||
|
||||
threads.run(r);
|
||||
});
|
||||
|
||||
Net.handleClient(ItemOffloadPacket.class, packet -> {
|
||||
Runnable r = () -> {
|
||||
Tile tile = world.tile(packet.position);
|
||||
if (tile == null || tile.entity == null) return;
|
||||
Tile next = tile.getNearby(tile.getRotation());
|
||||
next.block().handleItem(Item.getByID(packet.itemid), next, tile);
|
||||
};
|
||||
|
||||
threads.run(r);
|
||||
});
|
||||
|
||||
Net.handleClient(NetErrorPacket.class, packet -> {
|
||||
ui.showError(packet.message);
|
||||
disconnectQuietly();
|
||||
|
||||
@@ -3,10 +3,12 @@ package io.anuke.mindustry.entities;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Wall;
|
||||
import io.anuke.mindustry.world.blocks.types.modules.InventoryModule;
|
||||
import io.anuke.mindustry.world.blocks.types.modules.LiquidModule;
|
||||
import io.anuke.mindustry.world.blocks.types.modules.PowerModule;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
@@ -22,11 +24,14 @@ import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class TileEntity extends Entity{
|
||||
public Tile tile;
|
||||
public int[] items = new int[Item.getAllItems().size];
|
||||
public Timer timer;
|
||||
public float health;
|
||||
public boolean dead = false;
|
||||
public boolean added;
|
||||
|
||||
public PowerModule power;
|
||||
public InventoryModule inventory;
|
||||
public LiquidModule liquid;
|
||||
|
||||
/**Sets this tile entity data to this tile, and adds it if necessary.*/
|
||||
public TileEntity init(Tile tile, boolean added){
|
||||
@@ -53,10 +58,6 @@ public class TileEntity extends Entity{
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
|
||||
}
|
||||
|
||||
public void readNetwork(DataInputStream stream, float elapsed) throws IOException{
|
||||
read(stream);
|
||||
}
|
||||
|
||||
public void onDeath(){
|
||||
onDeath(false);
|
||||
@@ -118,34 +119,6 @@ public class TileEntity extends Entity{
|
||||
}
|
||||
}
|
||||
|
||||
public int totalItems(){
|
||||
int sum = 0;
|
||||
for(int i = 0; i < items.length; i ++){
|
||||
sum += items[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public int getItem(Item item){
|
||||
return items[item.id];
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item){
|
||||
return getItem(item) > 0;
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item, int amount){
|
||||
return getItem(item) >= amount;
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
items[item.id] += amount;
|
||||
}
|
||||
|
||||
public void removeItem(Item item, int amount){
|
||||
items[item.id] -= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity add(){
|
||||
return add(tileGroup);
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.entities.TimedEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@@ -54,9 +53,8 @@ public class EMP extends TimedEntity{
|
||||
Tile tile = array.get(i);
|
||||
targets.add(tile);
|
||||
|
||||
if(tile != null && tile.block() instanceof PowerAcceptor){
|
||||
PowerAcceptor p = (PowerAcceptor)tile.block();
|
||||
p.setPower(tile, 0f);
|
||||
if(tile != null && tile.block().hasPower){
|
||||
tile.entity.power.amount = 0f;
|
||||
tile.entity.damage((int)(damage*2f)); //extra damage
|
||||
}
|
||||
|
||||
|
||||
@@ -4,25 +4,17 @@ import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import io.anuke.mindustry.io.versions.Save12;
|
||||
import io.anuke.mindustry.io.versions.Save13;
|
||||
import io.anuke.mindustry.io.versions.Save14;
|
||||
import io.anuke.mindustry.io.versions.Save15;
|
||||
import io.anuke.mindustry.io.versions.Save16;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.gwt;
|
||||
import static io.anuke.mindustry.Vars.logic;
|
||||
import static io.anuke.mindustry.Vars.saveDirectory;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class SaveIO{
|
||||
public static final IntMap<SaveFileVersion> versions = new IntMap<>();
|
||||
public static final Array<SaveFileVersion> versionArray = Array.with(
|
||||
new Save12(),
|
||||
new Save13(),
|
||||
new Save14(),
|
||||
new Save15()
|
||||
new Save16()
|
||||
);
|
||||
|
||||
static{
|
||||
|
||||
@@ -1,287 +0,0 @@
|
||||
package io.anuke.mindustry.io.versions;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.entities.enemies.EnemyType;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.io.BlockLoader;
|
||||
import io.anuke.mindustry.io.SaveFileVersion;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Save12 extends SaveFileVersion {
|
||||
|
||||
public Save12(){
|
||||
super(12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException {
|
||||
/*long loadTime = */stream.readLong();
|
||||
|
||||
//general state
|
||||
byte mode = stream.readByte();
|
||||
byte mapid = stream.readByte();
|
||||
|
||||
int wave = stream.readInt();
|
||||
float wavetime = stream.readFloat();
|
||||
|
||||
float playerx = stream.readFloat();
|
||||
float playery = stream.readFloat();
|
||||
|
||||
int playerhealth = stream.readInt();
|
||||
|
||||
Vars.player.x = playerx;
|
||||
Vars.player.y = playery;
|
||||
Vars.player.health = playerhealth;
|
||||
state.mode = GameMode.values()[mode];
|
||||
Core.camera.position.set(playerx, playery, 0);
|
||||
|
||||
//weapons
|
||||
|
||||
control.upgrades().getWeapons().clear();
|
||||
control.upgrades().getWeapons().add(Weapon.blaster);
|
||||
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
|
||||
|
||||
int weapons = stream.readByte();
|
||||
|
||||
for(int i = 0; i < weapons; i ++){
|
||||
control.upgrades().addWeapon((Weapon)Upgrade.getByID(stream.readByte()));
|
||||
}
|
||||
|
||||
ui.hudfrag.updateWeapons();
|
||||
|
||||
//inventory
|
||||
|
||||
int totalItems = stream.readByte();
|
||||
|
||||
Arrays.fill(state.inventory.getItems(), 0);
|
||||
|
||||
for(int i = 0; i < totalItems; i ++){
|
||||
Item item = Item.getByID(stream.readByte());
|
||||
int amount = stream.readInt();
|
||||
state.inventory.getItems()[item.id] = amount;
|
||||
}
|
||||
|
||||
ui.hudfrag.updateItems();
|
||||
|
||||
//enemies
|
||||
|
||||
Entities.clear();
|
||||
|
||||
int enemies = stream.readInt();
|
||||
|
||||
Array<Enemy> enemiesToUpdate = new Array<>();
|
||||
|
||||
for(int i = 0; i < enemies; i ++){
|
||||
byte type = stream.readByte();
|
||||
int lane = stream.readByte();
|
||||
float x = stream.readFloat();
|
||||
float y = stream.readFloat();
|
||||
byte tier = stream.readByte();
|
||||
int health = stream.readInt();
|
||||
|
||||
try{
|
||||
Enemy enemy = new Enemy(EnemyType.getByID(type));
|
||||
enemy.lane = lane;
|
||||
enemy.health = health;
|
||||
enemy.x = x;
|
||||
enemy.y = y;
|
||||
enemy.tier = tier;
|
||||
enemy.add(enemyGroup);
|
||||
enemiesToUpdate.add(enemy);
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
state.enemies = enemies;
|
||||
state.wave = wave;
|
||||
state.wavetime = wavetime;
|
||||
|
||||
if(!android)
|
||||
Vars.player.add();
|
||||
|
||||
//map
|
||||
|
||||
int seed = stream.readInt();
|
||||
int tiles = stream.readInt();
|
||||
|
||||
world.loadMap(world.maps().getMap(mapid), seed);
|
||||
renderer.clearTiles();
|
||||
|
||||
for(Enemy enemy : enemiesToUpdate){
|
||||
enemy.node = -2;
|
||||
}
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
//remove breakables like rocks
|
||||
if(tile.breakable()){
|
||||
world.tile(x, y).setBlock(Blocks.air);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < tiles; i ++){
|
||||
int pos = stream.readInt();
|
||||
byte link = stream.readByte();
|
||||
boolean hasEntity = stream.readBoolean();
|
||||
int blockid = stream.readInt();
|
||||
|
||||
Tile tile = world.tile(pos % world.width(), pos / world.width());
|
||||
tile.setBlock(BlockLoader.getByOldID(blockid));
|
||||
tile.link = link;
|
||||
|
||||
if(hasEntity){
|
||||
byte rotation = stream.readByte();
|
||||
int health = stream.readInt();
|
||||
int items = stream.readByte();
|
||||
|
||||
tile.entity.health = health;
|
||||
tile.setRotation(rotation);
|
||||
|
||||
for(int j = 0; j < items; j ++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
tile.entity.items[itemid] = itemamount;
|
||||
}
|
||||
|
||||
tile.entity.read(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
|
||||
//--META--
|
||||
stream.writeInt(version); //version id
|
||||
stream.writeLong(TimeUtils.millis()); //last saved
|
||||
|
||||
//--GENERAL STATE--
|
||||
stream.writeByte(state.mode.ordinal()); //gamemode
|
||||
stream.writeByte(world.getMap().id); //map ID
|
||||
|
||||
stream.writeInt(state.wave); //wave
|
||||
stream.writeFloat(state.wavetime); //wave countdown
|
||||
|
||||
stream.writeFloat(Vars.player.x); //player x/y
|
||||
stream.writeFloat(Vars.player.y);
|
||||
|
||||
stream.writeInt(Vars.player.health); //player health
|
||||
|
||||
stream.writeByte(control.upgrades().getWeapons().size - 1); //amount of weapons
|
||||
|
||||
//start at 1, because the first weapon is always the starter - ignore that
|
||||
for(int i = 1; i < control.upgrades().getWeapons().size; i ++){
|
||||
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
|
||||
}
|
||||
|
||||
//--INVENTORY--
|
||||
|
||||
int l = state.inventory.getItems().length;
|
||||
int itemsize = 0;
|
||||
|
||||
for(int i = 0; i < l; i ++){
|
||||
if(state.inventory.getItems()[i] > 0){
|
||||
itemsize ++;
|
||||
}
|
||||
}
|
||||
|
||||
stream.writeByte(itemsize); //amount of items
|
||||
|
||||
for(int i = 0; i < l; i ++){
|
||||
if(state.inventory.getItems()[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(state.inventory.getItems()[i]); //item amount
|
||||
}
|
||||
}
|
||||
|
||||
//--ENEMIES--
|
||||
|
||||
EntityContainer<Enemy> enemies = enemyGroup.all();
|
||||
|
||||
stream.writeInt(enemies.size()); //enemy amount
|
||||
|
||||
for(int i = 0; i < enemies.size(); i ++){
|
||||
Enemy enemy = enemies.get(i);
|
||||
stream.writeByte(enemy.type.id); //type
|
||||
stream.writeByte(enemy.lane); //lane
|
||||
stream.writeFloat(enemy.x); //x
|
||||
stream.writeFloat(enemy.y); //y
|
||||
stream.writeByte(enemy.tier); //tier
|
||||
stream.writeInt(enemy.health); //health
|
||||
}
|
||||
|
||||
//--MAP DATA--
|
||||
|
||||
//seed
|
||||
stream.writeInt(world.getSeed());
|
||||
|
||||
int totalblocks = 0;
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile.breakable()){
|
||||
totalblocks ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//tile amount
|
||||
stream.writeInt(totalblocks);
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile.breakable()){
|
||||
|
||||
stream.writeInt(x + y*world.width()); //tile pos
|
||||
stream.writeByte(tile.link);
|
||||
stream.writeBoolean(tile.entity != null); //whether it has a tile entity
|
||||
stream.writeInt(tile.block().id); //block ID
|
||||
|
||||
if(tile.entity != null){
|
||||
stream.writeByte(tile.getRotation()); //rotation
|
||||
stream.writeInt((int)tile.entity.health); //health
|
||||
int amount = 0;
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
if(tile.entity.items[i] > 0) amount ++;
|
||||
}
|
||||
stream.writeByte(amount); //amount of items
|
||||
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
if(tile.entity.items[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(tile.entity.items[i]); //item amount
|
||||
}
|
||||
}
|
||||
|
||||
tile.entity.write(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
package io.anuke.mindustry.io.versions;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.entities.enemies.EnemyType;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.io.BlockLoader;
|
||||
import io.anuke.mindustry.io.SaveFileVersion;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.WorldGenerator;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.types.BlockPart;
|
||||
import io.anuke.mindustry.world.blocks.types.Rock;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Save13 extends SaveFileVersion {
|
||||
|
||||
public Save13(){
|
||||
super(13);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException {
|
||||
/*long loadTime = */stream.readLong();
|
||||
|
||||
//general state
|
||||
byte mode = stream.readByte();
|
||||
byte mapid = stream.readByte();
|
||||
|
||||
int wave = stream.readInt();
|
||||
float wavetime = stream.readFloat();
|
||||
|
||||
float playerx = stream.readFloat();
|
||||
float playery = stream.readFloat();
|
||||
|
||||
int playerhealth = stream.readInt();
|
||||
|
||||
Vars.player.x = playerx;
|
||||
Vars.player.y = playery;
|
||||
Vars.player.health = playerhealth;
|
||||
state.mode = GameMode.values()[mode];
|
||||
Core.camera.position.set(playerx, playery, 0);
|
||||
|
||||
//weapons
|
||||
|
||||
control.upgrades().getWeapons().clear();
|
||||
control.upgrades().getWeapons().add(Weapon.blaster);
|
||||
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
|
||||
|
||||
int weapons = stream.readByte();
|
||||
|
||||
for(int i = 0; i < weapons; i ++){
|
||||
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
|
||||
}
|
||||
|
||||
ui.hudfrag.updateWeapons();
|
||||
|
||||
//inventory
|
||||
|
||||
int totalItems = stream.readByte();
|
||||
|
||||
Arrays.fill(state.inventory.getItems(), 0);
|
||||
|
||||
for(int i = 0; i < totalItems; i ++){
|
||||
Item item = Item.getByID(stream.readByte());
|
||||
int amount = stream.readInt();
|
||||
state.inventory.getItems()[item.id] = amount;
|
||||
}
|
||||
|
||||
ui.hudfrag.updateItems();
|
||||
|
||||
//enemies
|
||||
|
||||
Entities.clear();
|
||||
|
||||
int enemies = stream.readInt();
|
||||
|
||||
Array<Enemy> enemiesToUpdate = new Array<>();
|
||||
|
||||
for(int i = 0; i < enemies; i ++){
|
||||
byte type = stream.readByte();
|
||||
int lane = stream.readByte();
|
||||
float x = stream.readFloat();
|
||||
float y = stream.readFloat();
|
||||
byte tier = stream.readByte();
|
||||
int health = stream.readShort();
|
||||
|
||||
try{
|
||||
Enemy enemy = new Enemy(EnemyType.getByID(type));
|
||||
enemy.lane = lane;
|
||||
enemy.health = health;
|
||||
enemy.x = x;
|
||||
enemy.y = y;
|
||||
enemy.tier = tier;
|
||||
enemy.add(enemyGroup);
|
||||
enemiesToUpdate.add(enemy);
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
state.enemies = enemies;
|
||||
state.wave = wave;
|
||||
state.wavetime = wavetime;
|
||||
|
||||
if(!android)
|
||||
Vars.player.add();
|
||||
|
||||
//map
|
||||
|
||||
int seed = stream.readInt();
|
||||
|
||||
world.loadMap(world.maps().getMap(mapid), seed);
|
||||
renderer.clearTiles();
|
||||
|
||||
for(Enemy enemy : enemiesToUpdate){
|
||||
enemy.node = -2;
|
||||
}
|
||||
|
||||
int rocks = stream.readInt();
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
//remove breakables like rocks
|
||||
if(tile.breakable()){
|
||||
world.tile(x, y).setBlock(Blocks.air);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < rocks; i ++){
|
||||
int pos = stream.readInt();
|
||||
Tile tile = world.tile(pos % world.width(), pos / world.width());
|
||||
Block result = WorldGenerator.rocks.get(tile.floor());
|
||||
if(result != null) tile.setBlock(result);
|
||||
}
|
||||
|
||||
int tiles = stream.readInt();
|
||||
|
||||
for(int i = 0; i < tiles; i ++){
|
||||
int pos = stream.readInt();
|
||||
int blockid = stream.readInt();
|
||||
|
||||
Tile tile = world.tile(pos % world.width(), pos / world.width());
|
||||
tile.setBlock(BlockLoader.getByOldID(blockid));
|
||||
|
||||
if(blockid == Blocks.blockpart.id){
|
||||
tile.link = stream.readByte();
|
||||
}
|
||||
|
||||
if(tile.entity != null){
|
||||
byte rotation = stream.readByte();
|
||||
short health = stream.readShort();
|
||||
int items = stream.readByte();
|
||||
|
||||
tile.entity.health = health;
|
||||
tile.setRotation(rotation);
|
||||
|
||||
for(int j = 0; j < items; j ++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
tile.entity.items[itemid] = itemamount;
|
||||
}
|
||||
|
||||
tile.entity.read(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
//--META--
|
||||
stream.writeInt(version); //version id
|
||||
stream.writeLong(TimeUtils.millis()); //last saved
|
||||
|
||||
//--GENERAL STATE--
|
||||
stream.writeByte(state.mode.ordinal()); //gamemode
|
||||
stream.writeByte(world.getMap().id); //map ID
|
||||
|
||||
stream.writeInt(state.wave); //wave
|
||||
stream.writeFloat(state.wavetime); //wave countdown
|
||||
|
||||
stream.writeFloat(Vars.player.x); //player x/y
|
||||
stream.writeFloat(Vars.player.y);
|
||||
|
||||
stream.writeInt(Vars.player.health); //player health
|
||||
|
||||
stream.writeByte(control.upgrades().getWeapons().size - 1); //amount of weapons
|
||||
|
||||
//start at 1, because the first weapon is always the starter - ignore that
|
||||
for(int i = 1; i < control.upgrades().getWeapons().size; i ++){
|
||||
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
|
||||
}
|
||||
|
||||
//--INVENTORY--
|
||||
|
||||
int l = state.inventory.getItems().length;
|
||||
int itemsize = 0;
|
||||
|
||||
for(int i = 0; i < l; i ++){
|
||||
if(state.inventory.getItems()[i] > 0){
|
||||
itemsize ++;
|
||||
}
|
||||
}
|
||||
|
||||
stream.writeByte(itemsize); //amount of items
|
||||
|
||||
for(int i = 0; i < l; i ++){
|
||||
if(state.inventory.getItems()[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(state.inventory.getItems()[i]); //item amount
|
||||
}
|
||||
}
|
||||
|
||||
//--ENEMIES--
|
||||
EntityContainer<Enemy> enemies = enemyGroup.all();
|
||||
|
||||
stream.writeInt(enemies.size()); //enemy amount
|
||||
|
||||
for(int i = 0; i < enemies.size(); i ++){
|
||||
Enemy enemy = enemies.get(i);
|
||||
stream.writeByte(enemy.type.id); //type
|
||||
stream.writeByte(enemy.lane); //lane
|
||||
stream.writeFloat(enemy.x); //x
|
||||
stream.writeFloat(enemy.y); //y
|
||||
stream.writeByte(enemy.tier); //tier
|
||||
stream.writeShort(enemy.health); //health
|
||||
}
|
||||
|
||||
//--MAP DATA--
|
||||
|
||||
//seed
|
||||
stream.writeInt(world.getSeed());
|
||||
|
||||
int totalblocks = 0;
|
||||
int totalrocks = 0;
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile.breakable()){
|
||||
if(tile.block() instanceof Rock){
|
||||
totalrocks ++;
|
||||
}else{
|
||||
totalblocks ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//amount of rocks
|
||||
stream.writeInt(totalrocks);
|
||||
|
||||
//write all rocks
|
||||
for(int x = 0; x < world.width(); x ++) {
|
||||
for (int y = 0; y < world.height(); y++) {
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if (tile.block() instanceof Rock) {
|
||||
stream.writeInt(tile.packedPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//write all blocks
|
||||
stream.writeInt(totalblocks);
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile.breakable() && !(tile.block() instanceof Rock)){
|
||||
|
||||
stream.writeInt(x + y*world.width()); //tile pos
|
||||
stream.writeInt(tile.block().id); //block ID
|
||||
|
||||
if(tile.block() instanceof BlockPart) stream.writeByte(tile.link);
|
||||
|
||||
if(tile.entity != null){
|
||||
stream.writeByte(tile.getRotation()); //rotation
|
||||
stream.writeShort((short)tile.entity.health); //health
|
||||
byte amount = 0;
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
if(tile.entity.items[i] > 0) amount ++;
|
||||
}
|
||||
stream.writeByte(amount); //amount of items
|
||||
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
if(tile.entity.items[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(tile.entity.items[i]); //item amount
|
||||
}
|
||||
}
|
||||
|
||||
tile.entity.write(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,345 +0,0 @@
|
||||
package io.anuke.mindustry.io.versions;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.entities.enemies.EnemyType;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.io.SaveFileVersion;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.WorldGenerator;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.types.BlockPart;
|
||||
import io.anuke.mindustry.world.blocks.types.Rock;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Save14 extends SaveFileVersion{
|
||||
|
||||
public Save14(){
|
||||
super(14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException {
|
||||
/*long loadTime = */
|
||||
stream.readLong();
|
||||
|
||||
//general state
|
||||
byte mode = stream.readByte();
|
||||
byte mapid = stream.readByte();
|
||||
|
||||
int wave = stream.readInt();
|
||||
float wavetime = stream.readFloat();
|
||||
|
||||
//block header
|
||||
|
||||
int blocksize = stream.readInt();
|
||||
|
||||
IntMap<Block> map = new IntMap<>();
|
||||
|
||||
for(int i = 0; i < blocksize; i ++){
|
||||
String name = readString(stream);
|
||||
int id = stream.readShort();
|
||||
|
||||
map.put(id, Block.getByName(name));
|
||||
}
|
||||
|
||||
float playerx = stream.readFloat();
|
||||
float playery = stream.readFloat();
|
||||
|
||||
int playerhealth = stream.readInt();
|
||||
|
||||
Vars.player.x = playerx;
|
||||
Vars.player.y = playery;
|
||||
Vars.player.health = playerhealth;
|
||||
state.mode = GameMode.values()[mode];
|
||||
Core.camera.position.set(playerx, playery, 0);
|
||||
|
||||
//weapons
|
||||
|
||||
control.upgrades().getWeapons().clear();
|
||||
control.upgrades().getWeapons().add(Weapon.blaster);
|
||||
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
|
||||
|
||||
int weapons = stream.readByte();
|
||||
|
||||
for(int i = 0; i < weapons; i ++){
|
||||
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
|
||||
}
|
||||
|
||||
ui.hudfrag.updateWeapons();
|
||||
|
||||
//inventory
|
||||
|
||||
int totalItems = stream.readByte();
|
||||
|
||||
Arrays.fill(state.inventory.getItems(), 0);
|
||||
|
||||
for(int i = 0; i < totalItems; i ++){
|
||||
Item item = Item.getByID(stream.readByte());
|
||||
int amount = stream.readInt();
|
||||
state.inventory.getItems()[item.id] = amount;
|
||||
}
|
||||
|
||||
ui.hudfrag.updateItems();
|
||||
|
||||
//enemies
|
||||
|
||||
Entities.clear();
|
||||
|
||||
int enemies = stream.readInt();
|
||||
|
||||
Array<Enemy> enemiesToUpdate = new Array<>();
|
||||
|
||||
for(int i = 0; i < enemies; i ++){
|
||||
byte type = stream.readByte();
|
||||
int lane = stream.readByte();
|
||||
float x = stream.readFloat();
|
||||
float y = stream.readFloat();
|
||||
byte tier = stream.readByte();
|
||||
int health = stream.readShort();
|
||||
|
||||
try{
|
||||
Enemy enemy = new Enemy(EnemyType.getByID(type));
|
||||
enemy.lane = lane;
|
||||
enemy.health = health;
|
||||
enemy.x = x;
|
||||
enemy.y = y;
|
||||
enemy.tier = tier;
|
||||
enemy.add(enemyGroup);
|
||||
enemiesToUpdate.add(enemy);
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
state.enemies = enemies;
|
||||
state.wave = wave;
|
||||
state.wavetime = wavetime;
|
||||
|
||||
if(!android)
|
||||
Vars.player.add();
|
||||
|
||||
//map
|
||||
|
||||
int seed = stream.readInt();
|
||||
|
||||
world.loadMap(world.maps().getMap(mapid), seed);
|
||||
renderer.clearTiles();
|
||||
|
||||
for(Enemy enemy : enemiesToUpdate){
|
||||
enemy.node = -2;
|
||||
}
|
||||
|
||||
int rocks = stream.readInt();
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
//remove breakables like rocks
|
||||
if(tile.breakable()){
|
||||
world.tile(x, y).setBlock(Blocks.air);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < rocks; i ++){
|
||||
int pos = stream.readInt();
|
||||
Tile tile = world.tile(pos % world.width(), pos / world.width());
|
||||
if(tile == null) continue;
|
||||
Block result = WorldGenerator.rocks.get(tile.floor());
|
||||
if(result != null) tile.setBlock(result);
|
||||
}
|
||||
|
||||
int tiles = stream.readInt();
|
||||
|
||||
for(int i = 0; i < tiles; i ++){
|
||||
int pos = stream.readInt();
|
||||
int blockid = stream.readInt();
|
||||
|
||||
Tile tile = world.tile(pos % world.width(), pos / world.width());
|
||||
tile.setBlock(map.get(blockid));
|
||||
|
||||
if(blockid == Blocks.blockpart.id){
|
||||
tile.link = stream.readByte();
|
||||
}
|
||||
|
||||
if(tile.entity != null){
|
||||
byte rotation = stream.readByte();
|
||||
short health = stream.readShort();
|
||||
int items = stream.readByte();
|
||||
|
||||
tile.entity.health = health;
|
||||
tile.setRotation(rotation);
|
||||
|
||||
for(int j = 0; j < items; j ++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
tile.entity.items[itemid] = itemamount;
|
||||
}
|
||||
|
||||
tile.entity.read(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
//--META--
|
||||
stream.writeInt(version); //version id
|
||||
stream.writeLong(TimeUtils.millis()); //last saved
|
||||
|
||||
//--GENERAL STATE--
|
||||
stream.writeByte(state.mode.ordinal()); //gamemode
|
||||
stream.writeByte(world.getMap().id); //map ID
|
||||
|
||||
stream.writeInt(state.wave); //wave
|
||||
stream.writeFloat(state.wavetime); //wave countdown
|
||||
|
||||
//--BLOCK HEADER--
|
||||
|
||||
stream.writeInt(Block.getAllBlocks().size);
|
||||
|
||||
for(int i = 0; i < Block.getAllBlocks().size; i ++){
|
||||
Block block = Block.getAllBlocks().get(i);
|
||||
writeString(stream, block.name);
|
||||
stream.writeShort(block.id);
|
||||
}
|
||||
|
||||
stream.writeFloat(Vars.player.x); //player x/y
|
||||
stream.writeFloat(Vars.player.y);
|
||||
|
||||
stream.writeInt(Vars.player.health); //player health
|
||||
|
||||
stream.writeByte(control.upgrades().getWeapons().size - 1); //amount of weapons
|
||||
|
||||
//start at 1, because the first weapon is always the starter - ignore that
|
||||
for(int i = 1; i < control.upgrades().getWeapons().size; i ++){
|
||||
stream.writeByte(control.upgrades().getWeapons().get(i).id); //weapon ordinal
|
||||
}
|
||||
|
||||
//--INVENTORY--
|
||||
|
||||
int l = state.inventory.getItems().length;
|
||||
int itemsize = 0;
|
||||
|
||||
for(int i = 0; i < l; i ++){
|
||||
if(state.inventory.getItems()[i] > 0){
|
||||
itemsize ++;
|
||||
}
|
||||
}
|
||||
|
||||
stream.writeByte(itemsize); //amount of items
|
||||
|
||||
for(int i = 0; i < l; i ++){
|
||||
if(state.inventory.getItems()[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(state.inventory.getItems()[i]); //item amount
|
||||
}
|
||||
}
|
||||
|
||||
//--ENEMIES--
|
||||
|
||||
EntityContainer<Enemy> enemies = enemyGroup.all();
|
||||
|
||||
stream.writeInt(enemies.size()); //enemy amount
|
||||
|
||||
for(int i = 0; i < enemies.size(); i ++){
|
||||
Enemy enemy = enemies.get(i);
|
||||
stream.writeByte(enemy.type.id); //type
|
||||
stream.writeByte(enemy.lane); //lane
|
||||
stream.writeFloat(enemy.x); //x
|
||||
stream.writeFloat(enemy.y); //y
|
||||
stream.writeByte(enemy.tier); //tier
|
||||
stream.writeShort(enemy.health); //health
|
||||
}
|
||||
|
||||
//--MAP DATA--
|
||||
|
||||
//seed
|
||||
stream.writeInt(world.getSeed());
|
||||
|
||||
int totalblocks = 0;
|
||||
int totalrocks = 0;
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile.breakable()){
|
||||
if(tile.block() instanceof Rock){
|
||||
totalrocks ++;
|
||||
}else{
|
||||
totalblocks ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//amount of rocks
|
||||
stream.writeInt(totalrocks);
|
||||
|
||||
//write all rocks
|
||||
for(int x = 0; x < world.width(); x ++) {
|
||||
for (int y = 0; y < world.height(); y++) {
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if (tile.block() instanceof Rock) {
|
||||
stream.writeInt(tile.packedPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//write all blocks
|
||||
stream.writeInt(totalblocks);
|
||||
|
||||
for(int x = 0; x < world.width(); x ++){
|
||||
for(int y = 0; y < world.height(); y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile.breakable() && !(tile.block() instanceof Rock)){
|
||||
|
||||
stream.writeInt(x + y*world.width()); //tile pos
|
||||
stream.writeInt(tile.block().id); //block ID
|
||||
|
||||
if(tile.block() instanceof BlockPart) stream.writeByte(tile.link);
|
||||
|
||||
if(tile.entity != null){
|
||||
stream.writeByte(tile.getRotation()); //rotation
|
||||
stream.writeShort((short)tile.entity.health); //health
|
||||
byte amount = 0;
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
if(tile.entity.items[i] > 0) amount ++;
|
||||
}
|
||||
stream.writeByte(amount); //amount of items
|
||||
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
if(tile.entity.items[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(tile.entity.items[i]); //item amount
|
||||
}
|
||||
}
|
||||
|
||||
tile.entity.write(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,10 @@ import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Save15 extends SaveFileVersion {
|
||||
public class Save16 extends SaveFileVersion {
|
||||
|
||||
public Save15(){
|
||||
super(15);
|
||||
public Save16(){
|
||||
super(16);
|
||||
}
|
||||
|
||||
public SaveMeta getData(DataInputStream stream) throws IOException{
|
||||
@@ -205,11 +205,9 @@ public class Save15 extends SaveFileVersion {
|
||||
tile.entity.health = health;
|
||||
tile.setRotation(rotation);
|
||||
|
||||
for(int j = 0; j < items; j ++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
tile.entity.items[itemid] = itemamount;
|
||||
}
|
||||
if(tile.entity.inventory != null) tile.entity.inventory.read(stream);
|
||||
if(tile.entity.power != null) tile.entity.power.read(stream);
|
||||
if(tile.entity.liquid != null) tile.entity.liquid.read(stream);
|
||||
|
||||
tile.entity.read(stream);
|
||||
}
|
||||
@@ -348,18 +346,10 @@ public class Save15 extends SaveFileVersion {
|
||||
if(tile.entity != null){
|
||||
stream.writeByte(tile.getRotation()); //rotation
|
||||
stream.writeShort((short)tile.entity.health); //health
|
||||
byte amount = 0;
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
if(tile.entity.items[i] > 0) amount ++;
|
||||
}
|
||||
stream.writeByte(amount); //amount of items
|
||||
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
if(tile.entity.items[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(tile.entity.items[i]); //item amount
|
||||
}
|
||||
}
|
||||
if(tile.entity.inventory != null) tile.entity.inventory.write(stream);
|
||||
if(tile.entity.power != null) tile.entity.power.write(stream);
|
||||
if(tile.entity.liquid != null) tile.entity.liquid.write(stream);
|
||||
|
||||
tile.entity.write(stream);
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -128,29 +127,6 @@ public class NetEvents {
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleTransfer(Tile tile, byte rotation, Item item){
|
||||
ItemTransferPacket packet = new ItemTransferPacket();
|
||||
packet.position = tile.packedPosition();
|
||||
packet.rotation = rotation;
|
||||
packet.itemid = (byte)item.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handleItemSet(Tile tile, Item item, byte amount){
|
||||
ItemSetPacket packet = new ItemSetPacket();
|
||||
packet.position = tile.packedPosition();
|
||||
packet.itemid = (byte)item.id;
|
||||
packet.amount = amount;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handleOffload(Tile tile, Item item){
|
||||
ItemOffloadPacket packet = new ItemOffloadPacket();
|
||||
packet.position = tile.packedPosition();
|
||||
packet.itemid = (byte)item.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handleAdminSet(Player player, boolean admin){
|
||||
PlayerAdminPacket packet = new PlayerAdminPacket();
|
||||
packet.admin = admin;
|
||||
|
||||
@@ -191,10 +191,9 @@ public class NetworkIO {
|
||||
stream.writeByte(tile.getExtra());
|
||||
stream.writeShort((short)tile.entity.health); //health
|
||||
|
||||
//items
|
||||
for(int i = 0; i < tile.entity.items.length; i ++){
|
||||
stream.writeInt(tile.entity.items[i]);
|
||||
}
|
||||
if(tile.entity.inventory != null) tile.entity.inventory.write(stream);
|
||||
if(tile.entity.power != null) tile.entity.power.write(stream);
|
||||
if(tile.entity.liquid != null) tile.entity.liquid.write(stream);
|
||||
|
||||
//timer data
|
||||
|
||||
@@ -326,9 +325,9 @@ public class NetworkIO {
|
||||
|
||||
tile.entity.health = health;
|
||||
|
||||
for(int j = 0; j < tile.entity.items.length; j ++){
|
||||
tile.entity.items[j] = stream.readInt();
|
||||
}
|
||||
if(tile.entity.inventory != null) tile.entity.inventory.read(stream);
|
||||
if(tile.entity.power != null) tile.entity.power.read(stream);
|
||||
if(tile.entity.liquid != null) tile.entity.liquid.read(stream);
|
||||
|
||||
byte timers = stream.readByte();
|
||||
for(int time = 0; time < timers; time ++){
|
||||
|
||||
@@ -504,62 +504,6 @@ public class Packets {
|
||||
public void read(ByteBuffer buffer) { }
|
||||
}
|
||||
|
||||
public static class ItemTransferPacket implements Packet, UnimportantPacket{
|
||||
public int position;
|
||||
public byte rotation;
|
||||
public byte itemid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt((rotation) | (position << 2));
|
||||
buffer.put(itemid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
int i = buffer.getInt();
|
||||
rotation = (byte)(i & 0x3);
|
||||
position = i >> 2;
|
||||
itemid = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemSetPacket implements Packet, UnimportantPacket{
|
||||
public int position;
|
||||
public byte itemid, amount;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(position);
|
||||
buffer.put(itemid);
|
||||
buffer.put(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
position = buffer.getInt();
|
||||
itemid = buffer.get();
|
||||
amount = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemOffloadPacket implements Packet{
|
||||
public int position;
|
||||
public byte itemid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(position);
|
||||
buffer.put(itemid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
position = buffer.getInt();
|
||||
itemid = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetErrorPacket implements Packet{
|
||||
public String message;
|
||||
|
||||
|
||||
@@ -38,9 +38,6 @@ public class Registrator {
|
||||
CustomMapPacket.class,
|
||||
MapAckPacket.class,
|
||||
EntitySpawnPacket.class,
|
||||
ItemTransferPacket.class,
|
||||
ItemSetPacket.class,
|
||||
ItemOffloadPacket.class,
|
||||
NetErrorPacket.class,
|
||||
PlayerAdminPacket.class,
|
||||
AdministerRequestPacket.class,
|
||||
|
||||
@@ -10,6 +10,7 @@ public class Liquid {
|
||||
|
||||
public static final Liquid
|
||||
|
||||
none = new Liquid("none", Color.CLEAR),
|
||||
water = new Liquid("water", Color.ROYAL),
|
||||
plasma = new Liquid("plasma", Color.CORAL){
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.mindustry.resource.*;
|
||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.BlockStats;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Hue;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
@@ -29,7 +30,6 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class BlocksFragment implements Fragment{
|
||||
private Table desctable, itemtable, blocks, weapons;
|
||||
private Stack stack = new Stack();
|
||||
private Array<String> statlist = new Array<>();
|
||||
private boolean shown = true;
|
||||
private Recipe hoveredDescriptionRecipe;
|
||||
|
||||
@@ -293,8 +293,12 @@ public class BlocksFragment implements Fragment{
|
||||
}
|
||||
|
||||
public void showBlockInfo(Block block){
|
||||
statlist.clear();
|
||||
block.getStats(statlist);
|
||||
Array<String> statlist = new Array<String>();
|
||||
BlockStats stats = block.stats;
|
||||
|
||||
for(String s : stats.getMap().orderedKeys()){
|
||||
statlist.add(Bundles.get("text.blocks." + s) + ": []" + stats.getMap().get(s));
|
||||
}
|
||||
|
||||
Label desclabel = new Label(block.fullDescription);
|
||||
desclabel.setWrap(true);
|
||||
@@ -324,12 +328,6 @@ public class BlocksFragment implements Fragment{
|
||||
}
|
||||
|
||||
for(String s : statlist){
|
||||
if(s.contains(":")) {
|
||||
String color = s.substring(0, s.indexOf("]")+1);
|
||||
String first = s.substring(color.length(), s.indexOf(":")).replace("/", "").replace(" ", "").toLowerCase();
|
||||
String last = s.substring(s.indexOf(":"), s.length());
|
||||
s = color + Bundles.get("text.blocks." + first) + last;
|
||||
}
|
||||
table.add(s).left();
|
||||
table.row();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
@@ -12,9 +11,10 @@ import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.blocks.BaseBlock;
|
||||
import io.anuke.mindustry.world.blocks.types.BlockStats;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@@ -22,9 +22,10 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class Block{
|
||||
public class Block extends BaseBlock {
|
||||
private static int lastid;
|
||||
private static Array<Block> blocks = new Array<>();
|
||||
private static ObjectMap<String, Block> map = new ObjectMap<>();
|
||||
@@ -93,6 +94,8 @@ public class Block{
|
||||
/**whether this block has instant transfer checking. used for calculations to prevent infinite loops.*/
|
||||
public boolean instantTransfer = false;
|
||||
|
||||
public BlockStats stats = new BlockStats();
|
||||
|
||||
public Block(String name) {
|
||||
this.name = name;
|
||||
this.formalName = Bundles.get("block." + name + ".name", name);
|
||||
@@ -116,7 +119,11 @@ public class Block{
|
||||
public void drawSelect(Tile tile){}
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){}
|
||||
public void placed(Tile tile){}
|
||||
public void init(){}
|
||||
/**Called after all blocks are created.*/
|
||||
public void init(){
|
||||
setStats();
|
||||
setBars();
|
||||
}
|
||||
|
||||
public void tapped(Tile tile){}
|
||||
public void buildTable(Tile tile, Table table) {}
|
||||
@@ -130,9 +137,20 @@ public class Block{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void getStats(Array<String> list){
|
||||
list.add("[gray]size: " + size);
|
||||
list.add("[healthstats]health: " + health);
|
||||
public void setStats(){
|
||||
stats.add("size", size);
|
||||
stats.add("health", health);
|
||||
|
||||
if(hasPower) stats.add("powercapacity", powerCapacity);
|
||||
if(hasLiquids) stats.add("liquidcapacity", liquidCapacity);
|
||||
if(hasInventory) stats.add("capacity", itemCapacity);
|
||||
}
|
||||
|
||||
//TODO make this easier to config.
|
||||
public void setBars(){
|
||||
if(hasPower) bars.add(new BlockBar(Color.YELLOW, true, tile -> tile.entity.power.amount / powerCapacity));
|
||||
if(hasLiquids) bars.add(new BlockBar(Color.ROYAL, true, tile -> tile.entity.liquid.amount / liquidCapacity));
|
||||
if(hasInventory) bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.inventory.totalItems() / itemCapacity));
|
||||
}
|
||||
|
||||
public String name(){
|
||||
@@ -150,16 +168,6 @@ public class Block{
|
||||
public int handleDamage(Tile tile, int amount){
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
if(tile.entity == null) return;
|
||||
|
||||
tile.entity.addItem(item, 1);
|
||||
}
|
||||
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return false;
|
||||
}
|
||||
|
||||
public void update(Tile tile){}
|
||||
|
||||
@@ -185,82 +193,6 @@ public class Block{
|
||||
public TileEntity getEntity(){
|
||||
return new TileEntity();
|
||||
}
|
||||
|
||||
public boolean syncEntity(){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to put this item into a nearby container, if there are no available
|
||||
* containers, it gets added to the block's inventory.*/
|
||||
public void offloadNear(Tile tile, Item item){
|
||||
GridPoint2[] nearby = Edges.getEdges(size);
|
||||
|
||||
for(int j = 0; j < nearby.length; j ++){
|
||||
Tile other = tile.getNearby(nearby[j]);
|
||||
Tile in = tile.getNearby(Edges.getInsideEdges(size)[j]);
|
||||
if(other != null && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
handleItem(item, tile, tile);
|
||||
}
|
||||
|
||||
/**Try dumping any item near the tile.*/
|
||||
protected boolean tryDump(Tile tile){
|
||||
return tryDump(tile, null);
|
||||
}
|
||||
|
||||
/**Try dumping a specific item near the tile.*/
|
||||
protected boolean tryDump(Tile tile, Item todump){
|
||||
GridPoint2[] nearby = Edges.getEdges(size);
|
||||
byte i = (byte)(tile.getDump() % nearby.length);
|
||||
|
||||
for(int j = 0; j < nearby.length; j ++){
|
||||
Tile other;
|
||||
Tile in;
|
||||
|
||||
for(Item item : Item.getAllItems()){
|
||||
other = tile.getNearby(nearby[i]);
|
||||
in = tile.getNearby(Edges.getInsideEdges(size)[i]);
|
||||
|
||||
if(todump != null && item != todump) continue;
|
||||
|
||||
if(tile.entity.hasItem(item) && other != null && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
tile.entity.removeItem(item, 1);
|
||||
i = (byte)((i + 1) % nearby.length);
|
||||
tile.setDump(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
i = (byte)((i + 1) % nearby.length);
|
||||
tile.setDump(i);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**Used for dumping items.*/
|
||||
public boolean canDump(Tile tile, Tile to, Item item){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try offloading an item to a nearby container in its facing direction. Returns true if success.
|
||||
*/
|
||||
protected boolean offloadDir(Tile tile, Item item){
|
||||
Tile other = tile.getNearby(tile.getRotation());
|
||||
if(other != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void draw(Tile tile){
|
||||
//note: multiblocks do not support rotation
|
||||
@@ -318,7 +250,7 @@ public class Block{
|
||||
"entity.x", tile.entity.x,
|
||||
"entity.y", tile.entity.y,
|
||||
"entity.id", tile.entity.id,
|
||||
"entity.items.total", tile.entity.totalItems()
|
||||
"entity.items.total", tile.entity.inventory.totalItems()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
149
core/src/io/anuke/mindustry/world/blocks/BaseBlock.java
Normal file
149
core/src/io/anuke/mindustry/world/blocks/BaseBlock.java
Normal file
@@ -0,0 +1,149 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Edges;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public abstract class BaseBlock {
|
||||
public boolean hasLiquids;
|
||||
public boolean hasInventory;
|
||||
public boolean hasPower;
|
||||
|
||||
public int itemCapacity;
|
||||
public float liquidCapacity;
|
||||
public float liquidFlowFactor = 4.9f;
|
||||
public float powerCapacity;
|
||||
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
tile.entity.inventory.addItem(item, 1);
|
||||
}
|
||||
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return tile.entity.liquid.amount + amount < liquidCapacity
|
||||
&& (tile.entity.liquid.liquid == liquid || tile.entity.liquid.amount <= 0.01f);
|
||||
}
|
||||
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
tile.entity.liquid.liquid = liquid;
|
||||
tile.entity.liquid.amount += amount;
|
||||
}
|
||||
|
||||
public boolean acceptPower(Tile tile, Tile source, float amount){
|
||||
return amount + tile.entity.power.amount <= powerCapacity;
|
||||
}
|
||||
|
||||
public float addPower(Tile tile, float amount){
|
||||
float canAccept = Math.min(powerCapacity - tile.entity.power.amount, amount);
|
||||
|
||||
tile.entity.power.amount += canAccept;
|
||||
|
||||
return canAccept;
|
||||
}
|
||||
|
||||
public void tryDumpLiquid(Tile tile){
|
||||
if(tile.entity.liquid.amount > 0.01f){
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.getDump()));
|
||||
tile.setDump((byte) Mathf.mod(tile.getDump() + 1, 4));
|
||||
}
|
||||
}
|
||||
|
||||
public void tryMoveLiquid(Tile tile, Tile next){
|
||||
|
||||
if(next != null && next.block().hasLiquids && tile.entity.liquid.amount > 0.01f){
|
||||
|
||||
float flow = Math.min(next.block().liquidCapacity - next.entity.liquid.amount - 0.001f,
|
||||
Math.min(tile.entity.liquid.amount/liquidFlowFactor * Math.max(Timers.delta(), 1f), tile.entity.liquid.amount));
|
||||
|
||||
if(flow <= 0f || tile.entity.liquid.amount < flow) return;
|
||||
|
||||
if(next.block().acceptLiquid(next, tile, tile.entity.liquid.liquid, flow)){
|
||||
next.block().handleLiquid(next, tile, tile.entity.liquid.liquid, flow);
|
||||
tile.entity.liquid.amount -= flow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to put this item into a nearby container, if there are no available
|
||||
* containers, it gets added to the block's inventory.*/
|
||||
public void offloadNear(Tile tile, Item item){
|
||||
int size = tile.block().size;
|
||||
|
||||
GridPoint2[] nearby = Edges.getEdges(size);
|
||||
|
||||
for(int j = 0; j < nearby.length; j ++){
|
||||
Tile other = tile.getNearby(nearby[j]);
|
||||
Tile in = tile.getNearby(Edges.getInsideEdges(size)[j]);
|
||||
if(other != null && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
handleItem(item, tile, tile);
|
||||
}
|
||||
|
||||
/**Try dumping any item near the tile.*/
|
||||
public boolean tryDump(Tile tile){
|
||||
return tryDump(tile, null);
|
||||
}
|
||||
|
||||
/**Try dumping a specific item near the tile.*/
|
||||
public boolean tryDump(Tile tile, Item todump){
|
||||
int size = tile.block().size;
|
||||
|
||||
GridPoint2[] nearby = Edges.getEdges(size);
|
||||
byte i = (byte)(tile.getDump() % nearby.length);
|
||||
|
||||
for(int j = 0; j < nearby.length; j ++){
|
||||
Tile other;
|
||||
Tile in;
|
||||
|
||||
for(Item item : Item.getAllItems()){
|
||||
other = tile.getNearby(nearby[i]);
|
||||
in = tile.getNearby(Edges.getInsideEdges(size)[i]);
|
||||
|
||||
if(todump != null && item != todump) continue;
|
||||
|
||||
if(tile.entity.inventory.hasItem(item) && other != null && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
tile.entity.inventory.removeItem(item, 1);
|
||||
i = (byte)((i + 1) % nearby.length);
|
||||
tile.setDump(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
i = (byte)((i + 1) % nearby.length);
|
||||
tile.setDump(i);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**Used for dumping items.*/
|
||||
public boolean canDump(Tile tile, Tile to, Item item){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try offloading an item to a nearby container in its facing direction. Returns true if success.
|
||||
*/
|
||||
public boolean offloadDir(Tile tile, Item item){
|
||||
Tile other = tile.getNearby(tile.getRotation());
|
||||
if(other != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -20,15 +20,10 @@ public class DebugBlocks {
|
||||
laserDirections = 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
super.update(tile);
|
||||
tile.<GeneratorEntity>entity().power = powerCapacity;
|
||||
tile.entity.power.amount = powerCapacity;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class DistributionBlocks{
|
||||
|
||||
pulseconduit = new Conduit("pulseconduit"){{
|
||||
liquidCapacity = 16f;
|
||||
flowfactor = 4.9f;
|
||||
liquidFlowFactor = 4.9f;
|
||||
health = 65;
|
||||
}},
|
||||
|
||||
@@ -42,7 +42,7 @@ public class DistributionBlocks{
|
||||
|
||||
multiplexer = new Router("multiplexer"){{
|
||||
size = 2;
|
||||
capacity = 80;
|
||||
itemCapacity = 80;
|
||||
}},
|
||||
|
||||
vault = new Vault("vault"){{
|
||||
@@ -63,9 +63,6 @@ public class DistributionBlocks{
|
||||
}},
|
||||
liquidjunction = new LiquidJunction("liquidjunction"){{
|
||||
|
||||
}},
|
||||
powerbooster = new PowerBooster("powerbooster"){{
|
||||
powerRange = 4;
|
||||
}},
|
||||
powerlaser = new PowerLaser("powerlaser"){{
|
||||
}},
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class BlockModule {
|
||||
public abstract void write(DataOutputStream stream) throws IOException;
|
||||
public abstract void read(DataInputStream stream) throws IOException;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
/**Used for multiblocks. Each block that is not the center of the multiblock is a blockpart.
|
||||
* Think of these as delegates to the actual block; all events are passed to the target block.
|
||||
* They are made to share all properties from the linked tile/block.*/
|
||||
public class BlockPart extends Block implements PowerAcceptor, LiquidAcceptor{
|
||||
public class BlockPart extends Block{
|
||||
|
||||
public BlockPart() {
|
||||
super("blockpart");
|
||||
@@ -40,56 +40,35 @@ public class BlockPart extends Block implements PowerAcceptor, LiquidAcceptor{
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
Block block = linked(tile);
|
||||
return block instanceof LiquidAcceptor
|
||||
&& ((LiquidAcceptor)block).acceptLiquid(tile.getLinked(), source, liquid, amount);
|
||||
return block.hasLiquids
|
||||
&& block.acceptLiquid(tile.getLinked(), source, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
Block block = linked(tile);
|
||||
((LiquidAcceptor)block).handleLiquid(tile.getLinked(), source, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLiquid(Tile tile){
|
||||
Block block = linked(tile);
|
||||
return block instanceof LiquidAcceptor ? ((LiquidAcceptor)block).getLiquid(tile.getLinked()) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLiquidCapacity(Tile tile){
|
||||
Block block = linked(tile);
|
||||
return block instanceof LiquidAcceptor ? ((LiquidAcceptor)block).getLiquidCapacity(tile.getLinked()) : 0;
|
||||
block.handleLiquid(tile.getLinked(), source, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float addPower(Tile tile, float amount){
|
||||
Block block = linked(tile);
|
||||
if(block instanceof PowerAcceptor){
|
||||
return ((PowerAcceptor)block).addPower(tile.getLinked(), amount);
|
||||
if(block.hasPower){
|
||||
return block.addPower(tile.getLinked(), amount);
|
||||
}else{
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
public boolean acceptPower(Tile tile, Tile from, float amount){
|
||||
Block block = linked(tile);
|
||||
if(block instanceof PowerAcceptor){
|
||||
return ((PowerAcceptor)block).acceptsPower(tile.getLinked());
|
||||
if(block.hasPower){
|
||||
return block.acceptPower(tile.getLinked(), from, amount);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPower(Tile tile, float power){
|
||||
Block block = linked(tile);
|
||||
|
||||
if(block instanceof PowerAcceptor){
|
||||
((PowerAcceptor)block).setPower(tile.getLinked(), power);
|
||||
}
|
||||
}
|
||||
|
||||
private Block linked(Tile tile){
|
||||
return tile.getLinked().block();
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
public class BlockStats {
|
||||
private OrderedMap<String, Object> map = new OrderedMap<>();
|
||||
|
||||
public void add(String label, Object value){
|
||||
if(!Bundles.has("text.blocks." + label)) throw new RuntimeException("No bundle entry for description label \"" + label + "\"!");
|
||||
if(map.containsKey(label)) throw new RuntimeException("Duplicate label entry: \"" +label + "\"");
|
||||
map.put(label, value);
|
||||
}
|
||||
|
||||
public void remove(String label){
|
||||
Object o = map.remove(label) != null;
|
||||
if(o == null) throw new RuntimeException("No label entry found with name \"" + label + "\"!");
|
||||
}
|
||||
|
||||
public OrderedMap<String, Object> getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
public interface LiquidAcceptor{
|
||||
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount);
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount);
|
||||
public float getLiquid(Tile tile);
|
||||
public float getLiquidCapacity(Tile tile);
|
||||
}
|
||||
@@ -1,136 +1,39 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.mindustry.world.blocks.types.modules.LiquidModule;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LiquidBlock extends Block implements LiquidAcceptor{
|
||||
public class LiquidBlock extends Block{
|
||||
protected final int timerFlow = timers++;
|
||||
|
||||
protected float liquidCapacity = 10f;
|
||||
protected float flowfactor = 4.9f;
|
||||
|
||||
public LiquidBlock(String name) {
|
||||
super(name);
|
||||
rotate = true;
|
||||
update = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[liquidinfo]Liquid Capacity: " + liquidCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
LiquidModule mod = tile.entity.liquid;
|
||||
|
||||
Draw.rect(name() + "bottom", tile.worldx(), tile.worldy(), tile.getRotation() * 90);
|
||||
|
||||
if(entity.liquid != null && entity.liquidAmount > 0.01f){
|
||||
Draw.color(entity.liquid.color);
|
||||
Draw.alpha(entity.liquidAmount / liquidCapacity);
|
||||
if(mod.amount > 0.01f){
|
||||
Draw.color(mod.liquid.color);
|
||||
Draw.alpha(mod.amount / liquidCapacity);
|
||||
Draw.rect("conduitliquid", tile.worldx(), tile.worldy(), tile.getRotation() * 90);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
Draw.rect(name() + "top", tile.worldx(), tile.worldy(), tile.getRotation() * 90);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity(){
|
||||
return new LiquidEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquidAmount > 0.01f && entity.timer.get(timerFlow, 1)){
|
||||
if(tile.entity.liquid.amount > 0.01f && tile.entity.timer.get(timerFlow, 1)){
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()));
|
||||
}
|
||||
}
|
||||
|
||||
public void tryDumpLiquid(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquidAmount > 0.01f){
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.getDump()));
|
||||
tile.setDump((byte)Mathf.mod(tile.getDump() + 1, 4));
|
||||
}
|
||||
}
|
||||
|
||||
public void tryMoveLiquid(Tile tile, Tile next){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
Liquid liquid = entity.liquid;
|
||||
|
||||
if(next != null && next.block() instanceof LiquidAcceptor && entity.liquidAmount > 0.01f){
|
||||
LiquidAcceptor other = (LiquidAcceptor)next.block();
|
||||
|
||||
float flow = Math.min(other.getLiquidCapacity(next) - other.getLiquid(next) - 0.001f,
|
||||
Math.min(entity.liquidAmount/flowfactor * Math.max(Timers.delta(), 1f), entity.liquidAmount));
|
||||
|
||||
if(flow <= 0f || entity.liquidAmount < flow) return;
|
||||
|
||||
if(other.acceptLiquid(next, tile, liquid, flow)){
|
||||
other.handleLiquid(next, tile, liquid, flow);
|
||||
entity.liquidAmount -= flow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
return entity.liquidAmount + amount < liquidCapacity && (entity.liquid == liquid || entity.liquidAmount <= 0.01f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
LiquidEntity entity = tile.entity();
|
||||
entity.liquid = liquid;
|
||||
entity.liquidAmount += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLiquid(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
return entity.liquidAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLiquidCapacity(Tile tile){
|
||||
return liquidCapacity;
|
||||
}
|
||||
|
||||
public static class LiquidEntity extends TileEntity{
|
||||
public Liquid liquid;
|
||||
public float liquidAmount;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
stream.writeByte(liquid == null ? -1 : liquid.id);
|
||||
stream.writeByte((byte)(liquidAmount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
byte id = stream.readByte();
|
||||
liquid = id == -1 ? null : Liquid.getByID(id);
|
||||
liquidAmount = stream.readByte();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
public interface PowerAcceptor{
|
||||
/**Attempts to add some power to this block; returns the amount of power <i>not</i> accepted.
|
||||
* To add no power, you would return amount.*/
|
||||
public float addPower(Tile tile, float amount);
|
||||
|
||||
/**Whether this block accepts power at all.*/
|
||||
public boolean acceptsPower(Tile tile);
|
||||
|
||||
/**Sets the power on this block. This can be negative!*/
|
||||
public void setPower(Tile tile, float power);
|
||||
}
|
||||
@@ -1,17 +1,9 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class PowerBlock extends Block implements PowerAcceptor{
|
||||
public abstract class PowerBlock extends Block{
|
||||
public float powerCapacity = 10f;
|
||||
public float voltage = 0.001f;
|
||||
|
||||
@@ -19,41 +11,6 @@ public abstract class PowerBlock extends Block implements PowerAcceptor{
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
|
||||
bars.add(new BlockBar(Color.YELLOW, true, tile -> tile.<PowerEntity>entity().power / powerCapacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Power Capacity: " + powerCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
return entity.power + 0.001f <= powerCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float addPower(Tile tile, float amount){
|
||||
if(amount < voltage){
|
||||
return amount;
|
||||
}
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
float canAccept = Math.min(powerCapacity - entity.power, amount);
|
||||
|
||||
entity.power += canAccept;
|
||||
|
||||
return canAccept;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPower(Tile tile, float power){
|
||||
PowerEntity entity = tile.entity();
|
||||
entity.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,17 +19,6 @@ public abstract class PowerBlock extends Block implements PowerAcceptor{
|
||||
}
|
||||
|
||||
public static class PowerEntity extends TileEntity{
|
||||
public float power;
|
||||
public float time; //generator time. this is a bit of a hack
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
stream.writeFloat(power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
power = stream.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidAcceptor;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class LiquidTurret extends Turret implements LiquidAcceptor{
|
||||
public abstract class LiquidTurret extends Turret{
|
||||
public Liquid ammoLiquid = Liquid.water;
|
||||
public float liquidCapacity = 60f;
|
||||
public float liquidPerShot = 1f;
|
||||
@@ -20,62 +14,20 @@ public abstract class LiquidTurret extends Turret implements LiquidAcceptor{
|
||||
|
||||
@Override
|
||||
public boolean hasAmmo(Tile tile){
|
||||
LiquidTurretEntity entity = tile.entity();
|
||||
return entity.liquidAmount > liquidPerShot;
|
||||
TurretEntity entity = tile.entity();
|
||||
return entity.liquid.amount > liquidPerShot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumeAmmo(Tile tile){
|
||||
LiquidTurretEntity entity = tile.entity();
|
||||
entity.liquidAmount -= liquidPerShot;
|
||||
TurretEntity entity = tile.entity();
|
||||
entity.liquid.amount -= liquidPerShot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
LiquidTurretEntity entity = tile.entity();
|
||||
return ammoLiquid == liquid && entity.liquidAmount + amount < liquidCapacity && (entity.liquid == liquid || entity.liquidAmount <= 0.01f);
|
||||
return ammoLiquid == liquid && super.acceptLiquid(tile, source, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
LiquidTurretEntity entity = tile.entity();
|
||||
entity.liquid = liquid;
|
||||
entity.liquidAmount += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLiquid(Tile tile){
|
||||
LiquidTurretEntity entity = tile.entity();
|
||||
return entity.liquidAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLiquidCapacity(Tile tile){
|
||||
return liquidCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new LiquidTurretEntity();
|
||||
}
|
||||
|
||||
static class LiquidTurretEntity extends TurretEntity{
|
||||
public Liquid liquid;
|
||||
public float liquidAmount;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
super.write(stream);
|
||||
stream.writeByte(liquid == null ? -1 : liquid.id);
|
||||
stream.writeByte((byte)(liquidAmount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
super.read(stream);
|
||||
byte id = stream.readByte();
|
||||
liquid = id == -1 ? null : Liquid.getByID(id);
|
||||
liquidAmount = stream.readByte();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,25 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class PowerTurret extends Turret implements PowerAcceptor{
|
||||
public float powerCapacity = 20f;
|
||||
public abstract class PowerTurret extends Turret{
|
||||
public float powerUsed = 0.5f;
|
||||
|
||||
public PowerTurret(String name) {
|
||||
super(name);
|
||||
ammo = null;
|
||||
|
||||
bars.set(1, new BlockBar(Color.YELLOW, true, tile -> tile.<PowerTurretEntity>entity().power / powerCapacity));
|
||||
hasPower = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Power Capacity: " + (int)powerCapacity);
|
||||
list.add("[powerinfo]Power/shot: " + Strings.toFixed(powerUsed, 1));
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("powershot", Strings.toFixed(powerUsed, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,61 +31,16 @@ public abstract class PowerTurret extends Turret implements PowerAcceptor{
|
||||
|
||||
@Override
|
||||
public boolean hasAmmo(Tile tile){
|
||||
PowerTurretEntity entity = tile.entity();
|
||||
return entity.power >= powerUsed;
|
||||
return tile.entity.power.amount >= powerUsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumeAmmo(Tile tile){
|
||||
PowerTurretEntity entity = tile.entity();
|
||||
entity.power -= powerUsed;
|
||||
tile.entity.power.amount -= powerUsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
PowerTurretEntity entity = tile.entity();
|
||||
|
||||
return entity.power + 0.001f <= powerCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float addPower(Tile tile, float amount){
|
||||
PowerTurretEntity entity = tile.entity();
|
||||
|
||||
float canAccept = Math.min(powerCapacity - entity.power, amount);
|
||||
|
||||
entity.power += canAccept;
|
||||
|
||||
return canAccept;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPower(Tile tile, float power){
|
||||
PowerTurretEntity entity = tile.entity();
|
||||
entity.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity(){
|
||||
return new PowerTurretEntity();
|
||||
}
|
||||
|
||||
public static class PowerTurretEntity extends TurretEntity{
|
||||
public float power;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
stream.writeFloat(power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
power = stream.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.types.defense;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -26,19 +25,18 @@ public class RepairTurret extends PowerTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
list.add("[health]health: " + health);
|
||||
list.add("[powerinfo]Power Capacity: " + (int)powerCapacity);
|
||||
list.add("[powerinfo]Power/shot: " + Strings.toFixed(powerUsed, 1));
|
||||
list.add("[turretinfo]Range: " + (int)range);
|
||||
list.add("[turretinfo]Repairs/Second: " + Strings.toFixed(60f/reload * repairFrac * 100, 1) + "%");
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
//TODO remove extra crap
|
||||
stats.add("repairssecond", Strings.toFixed(60f/reload * repairFrac * 100, 1) + "%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
PowerTurretEntity entity = tile.entity();
|
||||
|
||||
if(entity.power < powerUsed){
|
||||
TurretEntity entity = tile.entity();
|
||||
|
||||
if(entity.power.amount < powerUsed){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,7 +64,7 @@ public class RepairTurret extends PowerTurret{
|
||||
if(entity.blockTarget.health > maxhealth)
|
||||
entity.blockTarget.health = maxhealth;
|
||||
|
||||
entity.power -= powerUsed;
|
||||
entity.power.amount -= powerUsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,10 +78,10 @@ public class RepairTurret extends PowerTurret{
|
||||
|
||||
@Override
|
||||
public void drawLayer2(Tile tile){
|
||||
PowerTurretEntity entity = tile.entity();
|
||||
TurretEntity entity = tile.entity();
|
||||
TileEntity target = entity.blockTarget;
|
||||
|
||||
if(entity.power >= powerUsed && target != null && Angles.angleDist(entity.angleTo(target), entity.rotation) < 10){
|
||||
if(entity.power.amount >= powerUsed && target != null && Angles.angleDist(entity.angleTo(target), entity.rotation) < 10){
|
||||
Tile targetTile = target.tile;
|
||||
float len = 4f;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Shield;
|
||||
@@ -30,11 +29,11 @@ public class ShieldBlock extends PowerBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Power/second: " + Strings.toFixed(powerDrain*60, 2));
|
||||
list.add("[powerinfo]Power Drain/damage: " + Strings.toFixed(powerPerDamage, 2));
|
||||
list.add("[powerinfo]Shield Radius: " + (int)shieldRadius);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("powersecond", Strings.toFixed(powerDrain*60, 2));
|
||||
stats.add("powerdraindamage", Strings.toFixed(powerPerDamage, 2));
|
||||
stats.add("shieldradius", (int)shieldRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,19 +46,19 @@ public class ShieldBlock extends PowerBlock{
|
||||
entity.shield.add();
|
||||
}
|
||||
|
||||
if(entity.power > powerPerDamage){
|
||||
if(entity.power.amount > powerPerDamage){
|
||||
if(!entity.shield.active){
|
||||
entity.shield.add();
|
||||
}
|
||||
|
||||
entity.power -= powerDrain * Timers.delta();
|
||||
entity.power.amount -= powerDrain * Timers.delta();
|
||||
}else{
|
||||
if(entity.shield.active && !(Vars.infiniteAmmo && Vars.debug)){
|
||||
entity.shield.removeDelay();
|
||||
}
|
||||
}
|
||||
|
||||
entity.shield.radius = Mathf.lerp(entity.shield.radius, Math.min(entity.power / powerCapacity * radiusScale, maxRadius), Timers.delta() * 0.05f);
|
||||
entity.shield.radius = Mathf.lerp(entity.shield.radius, Math.min(entity.power.amount / powerCapacity * radiusScale, maxRadius), Timers.delta() * 0.05f);
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +70,7 @@ public class ShieldBlock extends PowerBlock{
|
||||
public void handleBullet(Tile tile, BulletEntity bullet){
|
||||
ShieldEntity entity = tile.entity();
|
||||
|
||||
if(entity.power < bullet.getDamage() * powerPerDamage){
|
||||
if(entity.power.amount < bullet.getDamage() * powerPerDamage){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,7 +78,7 @@ public class ShieldBlock extends PowerBlock{
|
||||
Effects.effect(bullet.damage > 5 ? Fx.shieldhit : Fx.laserhit, bullet);
|
||||
if(!headless) renderer.addShieldHit(bullet.x, bullet.y);
|
||||
|
||||
entity.power -= bullet.getDamage() * powerPerDamage;
|
||||
entity.power.amount -= bullet.getDamage() * powerPerDamage;
|
||||
}
|
||||
|
||||
static class ShieldEntity extends PowerEntity{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerBlock;
|
||||
@@ -11,6 +9,7 @@ import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class ShieldedWallBlock extends PowerBlock{
|
||||
static final float hitTime = 18f;
|
||||
@@ -29,13 +28,13 @@ public class ShieldedWallBlock extends PowerBlock{
|
||||
float drain = amount * powerPerDamage;
|
||||
ShieldedWallEntity entity = tile.entity();
|
||||
|
||||
if(entity.power > drain){
|
||||
entity.power -= drain;
|
||||
if(entity.power.amount > drain){
|
||||
entity.power.amount -= drain;
|
||||
entity.hit = hitTime;
|
||||
return 0;
|
||||
}else if(entity.power > 0){
|
||||
int reduction = (int)(entity.power / powerPerDamage);
|
||||
entity.power = 0;
|
||||
}else if(entity.power.amount > 0){
|
||||
int reduction = (int)(entity.power.amount / powerPerDamage);
|
||||
entity.power.amount = 0;
|
||||
|
||||
return amount - reduction;
|
||||
}
|
||||
@@ -44,9 +43,9 @@ public class ShieldedWallBlock extends PowerBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Power Drain/damage: " + Strings.toFixed(powerPerDamage, 2));
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("powerdraindamage", Strings.toFixed(powerPerDamage, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,7 +54,7 @@ public class ShieldedWallBlock extends PowerBlock{
|
||||
|
||||
ShieldedWallEntity entity = tile.entity();
|
||||
|
||||
if(entity.power > powerPerDamage){
|
||||
if(entity.power.amount > powerPerDamage){
|
||||
renderer.addShield(() -> Draw.rect("blank", tile.worldx(), tile.worldy(), tilesize, tilesize));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
@@ -65,16 +64,16 @@ public class Turret extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
if(ammo != null) list.add("[turretinfo]Ammo: " + ammo);
|
||||
if(ammo != null) list.add("[turretinfo]Ammo Capacity: " + maxammo);
|
||||
if(ammo != null) list.add("[turretinfo]Ammo/Item: " + ammoMultiplier);
|
||||
list.add("[turretinfo]Range: " + (int)range);
|
||||
list.add("[turretinfo]Inaccuracy: " + (int)inaccuracy);
|
||||
list.add("[turretinfo]Damage/Shot: " + bullet.damage);
|
||||
list.add("[turretinfo]Shots/Second: " + Strings.toFixed(60f/reload, 1));
|
||||
list.add("[turretinfo]Shots: " + shots);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
if(ammo != null) stats.add("ammo", ammo);
|
||||
if(ammo != null) stats.add("ammocapacity", maxammo);
|
||||
if(ammo != null) stats.add("ammoitem", ammoMultiplier);
|
||||
stats.add("range", (int)range);
|
||||
stats.add("inaccuracy", (int)inaccuracy);
|
||||
stats.add("damageshot", bullet.damage);
|
||||
stats.add("shotssecond", Strings.toFixed(60f/reload, 1));
|
||||
stats.add("shots", shots);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,9 +124,9 @@ public class Turret extends Block{
|
||||
public void update(Tile tile){
|
||||
TurretEntity entity = tile.entity();
|
||||
|
||||
if(ammo != null && entity.hasItem(ammo)){
|
||||
if(ammo != null && entity.inventory.hasItem(ammo)){
|
||||
entity.ammo += ammoMultiplier;
|
||||
entity.removeItem(ammo, 1);
|
||||
entity.inventory.removeItem(ammo, 1);
|
||||
}
|
||||
|
||||
if(entity.target != null && entity.target.isDead())
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.LongArray;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
@@ -42,9 +41,9 @@ public class Conveyor extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[iteminfo]Item Speed/second: " + Strings.toFixed(speed * 60, 1));
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("itemspeedsecond", Strings.toFixed(speed * 60, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,11 +176,6 @@ public class Conveyor extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncEntity(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conveyor data format:
|
||||
* [0] item ordinal
|
||||
|
||||
@@ -10,14 +10,13 @@ public class LiquidRouter extends Conduit{
|
||||
super(name);
|
||||
rotate = false;
|
||||
solid = true;
|
||||
flowfactor = 2f;
|
||||
liquidFlowFactor = 2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquidAmount > 0){
|
||||
if(tile.entity.liquid.amount > 0){
|
||||
if(tile.getExtra() != tile.getRotation()){
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()));
|
||||
}
|
||||
@@ -29,18 +28,15 @@ public class LiquidRouter extends Conduit{
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
super.handleLiquid(tile, source, liquid, amount);
|
||||
tile.setExtra((byte)tile.relativeTo(source.x, source.y));
|
||||
tile.setExtra(tile.relativeTo(source.x, source.y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
Draw.rect(name(), tile.worldx(), tile.worldy());
|
||||
|
||||
if(entity.liquid == null) return;
|
||||
|
||||
Draw.color(entity.liquid.color);
|
||||
Draw.alpha(entity.liquidAmount / liquidCapacity);
|
||||
Draw.color(tile.entity.liquid.liquid.color);
|
||||
Draw.alpha(tile.entity.liquid.amount / liquidCapacity);
|
||||
Draw.rect("blank", tile.worldx(), tile.worldy(), 2, 2);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
import io.anuke.mindustry.world.blocks.types.generation.Generator;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class PowerBooster extends Generator{
|
||||
protected final int timerGenerate = timers++;
|
||||
|
||||
public int powerRange = 4;
|
||||
|
||||
public PowerBooster(String name) {
|
||||
super(name);
|
||||
explosive = false;
|
||||
hasLasers = false;
|
||||
powerSpeed = 0.4f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSelect(Tile tile){
|
||||
super.drawSelect(tile);
|
||||
|
||||
Draw.color(Color.YELLOW);
|
||||
Lines.dashCircle(tile.worldx(), tile.worldy(), powerRange * tilesize);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
Draw.color(Color.PURPLE);
|
||||
Lines.stroke(1f);
|
||||
Lines.dashCircle(x * tilesize, y * tilesize, powerRange * tilesize);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Power Range: " + powerRange + " tiles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
distributePower(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLayer(Tile tile){}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
return entity.power + 0.001f <= powerCapacity;
|
||||
}
|
||||
|
||||
//TODO better distribution
|
||||
protected void distributePower(Tile tile){
|
||||
PowerEntity p = tile.entity();
|
||||
|
||||
if(!p.timer.get(timerGenerate, powerTime)){
|
||||
return;
|
||||
}
|
||||
|
||||
int acceptors = 0;
|
||||
float flow = 0f;
|
||||
|
||||
for(int i = 0; i < 2; i++){
|
||||
for(int x = -powerRange; x <= powerRange; x++){
|
||||
for(int y = -powerRange; y <= powerRange; y++){
|
||||
|
||||
if(x == 0 && y == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(Vector2.dst(x, y, 0, 0) < powerRange){
|
||||
Tile dest = world.tile(tile.x + x, tile.y + y);
|
||||
if(dest != null && dest.block() instanceof PowerAcceptor && ((PowerAcceptor) dest.block()).acceptsPower(dest)){
|
||||
if(i == 1){
|
||||
PowerAcceptor block = (PowerAcceptor) dest.block();
|
||||
|
||||
float transmission = Math.min(flow, p.power);
|
||||
|
||||
float amount = block.addPower(dest, transmission);
|
||||
p.power -= amount;
|
||||
}else{
|
||||
acceptors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO better distribution scheme
|
||||
if(i == 0 && acceptors > 0){
|
||||
flow = Mathf.clamp(p.power / acceptors, 0f, powerSpeed / acceptors * Timers.delta());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,9 @@ public class PowerLaser extends Generator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
public boolean acceptPower(Tile tile, Tile from, float amount){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
return entity.power + 0.001f <= powerCapacity;
|
||||
return entity.power.amount <= powerCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class Router extends Block{
|
||||
protected int capacity = 20;
|
||||
|
||||
public Router(String name) {
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.totalItems()/capacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[iteminfo]Capacity: " + capacity);
|
||||
itemCapacity = 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,7 +24,7 @@ public class Router extends Block{
|
||||
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
|
||||
|
||||
for(int i = 0; i < iterations; i ++) {
|
||||
if (tile.entity.totalItems() > 0) {
|
||||
if (tile.entity.inventory.totalItems() > 0) {
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
@@ -48,8 +38,8 @@ public class Router extends Block{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
int items = tile.entity.totalItems();
|
||||
return items < capacity;
|
||||
int items = tile.entity.inventory.totalItems();
|
||||
return items < itemCapacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ public class Teleporter extends PowerBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Power/item: " + Strings.toFixed(powerPerItem, 1));
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("poweritem", Strings.toFixed(powerPerItem, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +90,7 @@ public class Teleporter extends PowerBlock{
|
||||
|
||||
teleporters[entity.color].add(tile);
|
||||
|
||||
if(entity.totalItems() > 0){
|
||||
if(entity.inventory.totalItems() > 0){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
@@ -139,17 +139,17 @@ public class Teleporter extends PowerBlock{
|
||||
if(links.size > 0){
|
||||
if(!syncBlockState || Net.server() || !Net.active()){
|
||||
Tile target = links.random();
|
||||
target.entity.addItem(item, 1);
|
||||
target.entity.inventory.addItem(item, 1);
|
||||
}
|
||||
}
|
||||
|
||||
entity.power -= powerPerItem;
|
||||
entity.power.amount -= powerPerItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
PowerEntity entity = tile.entity();
|
||||
return !(source.block() instanceof Teleporter) && entity.power >= powerPerItem && findLinks(tile).size > 0;
|
||||
return !(source.block() instanceof Teleporter) && entity.power.amount >= powerPerItem && findLinks(tile).size > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -168,7 +168,7 @@ public class Teleporter extends PowerBlock{
|
||||
if(other.block() instanceof Teleporter){
|
||||
if(other.<TeleporterEntity>entity().color != entity.color){
|
||||
removal.add(other);
|
||||
}else if(other.entity.totalItems() == 0){
|
||||
}else if(other.entity.inventory.totalItems() == 0){
|
||||
returns.add(other);
|
||||
}
|
||||
}else{
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidAcceptor;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
|
||||
public class TunnelConduit extends Conduit {
|
||||
@@ -27,11 +26,9 @@ public class TunnelConduit extends Conduit {
|
||||
Tile tunnel = getDestTunnel(tile);
|
||||
if (tunnel == null) return;
|
||||
Tile to = tunnel.getNearby(tunnel.getRotation());
|
||||
if (to == null || !(to.block() instanceof LiquidAcceptor)) return;
|
||||
if (to == null || !(to.block().hasLiquids)) return;
|
||||
|
||||
LiquidAcceptor a = (LiquidAcceptor) to.block();
|
||||
|
||||
if (a.acceptLiquid(tile, source, liquid, amount)) a.handleLiquid(to, tunnel, liquid, amount);
|
||||
if (to.block().acceptLiquid(tile, source, liquid, amount)) to.block().handleLiquid(to, tunnel, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,8 +39,8 @@ public class TunnelConduit extends Conduit {
|
||||
|
||||
if (tunnel != null) {
|
||||
Tile to = tunnel.getNearby(tunnel.getRotation());
|
||||
return to != null && (to.block() instanceof LiquidAcceptor) &&
|
||||
((LiquidAcceptor) to.block()).acceptLiquid(to, tunnel, liquid, amount);
|
||||
return to != null && (to.block().hasLiquids) &&
|
||||
(to.block()).acceptLiquid(to, tunnel, liquid, amount);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class TunnelConveyor extends Block{
|
||||
arr.add(entity.index);
|
||||
|
||||
for(int i = 0; i < entity.index; i++){
|
||||
long l = entity.items[i];
|
||||
long l = entity.inventory.items[i];
|
||||
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
|
||||
Item item = Item.getByID(Bits.getRightInt(l));
|
||||
Tile dest = getDestTunnel(tile, item);
|
||||
|
||||
@@ -3,13 +3,11 @@ package io.anuke.mindustry.world.blocks.types.generation;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerBlock;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
@@ -18,7 +16,10 @@ import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Hue;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.graphics.Shapes;
|
||||
import io.anuke.ucore.util.*;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -43,16 +44,17 @@ public class Generator extends PowerBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(hasLasers){
|
||||
list.add("[powerinfo]Laser tile range: " + laserRange);
|
||||
list.add("[powerinfo]Max power transfer/second: " + Strings.toFixed(powerSpeed * 60, 2));
|
||||
stats.add("lasertilerange", laserRange);
|
||||
stats.add("maxpowertransfersecond", Strings.toFixed(powerSpeed * 60, 2));
|
||||
}
|
||||
|
||||
//TODO fix this
|
||||
if(explosive){
|
||||
list.add("[orange]" + Bundles.get("text.blocks.explosive"));
|
||||
stats.add("explosive", "!!! //TODO");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +140,7 @@ public class Generator extends PowerBlock{
|
||||
GeneratorEntity entity = tile.entity();
|
||||
|
||||
for(int i = 0; i < laserDirections; i++){
|
||||
if(entity.power > powerSpeed){
|
||||
if(entity.power.amount > powerSpeed){
|
||||
entity.laserThickness = Mathf.lerpDelta(entity.laserThickness, 1f, 0.05f);
|
||||
}else{
|
||||
entity.laserThickness = Mathf.lerpDelta(entity.laserThickness, 0.2f, 0.05f);
|
||||
@@ -150,7 +152,7 @@ public class Generator extends PowerBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
public boolean acceptPower(Tile tile, Tile source, float amount){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -173,11 +175,10 @@ public class Generator extends PowerBlock{
|
||||
if(target == null || isInterfering(target, rot))
|
||||
continue;
|
||||
|
||||
PowerAcceptor p = (PowerAcceptor) target.block();
|
||||
float transmit = Math.min(powerSpeed * Timers.delta(), entity.power);
|
||||
if(p.acceptsPower(target)){
|
||||
float accepted = p.addPower(target, transmit);
|
||||
entity.power -= accepted;
|
||||
float transmit = Math.min(powerSpeed * Timers.delta(), entity.power.amount);
|
||||
if(target.block().acceptPower(target, tile, transmit)){
|
||||
float accepted = target.block().addPower(target, transmit);
|
||||
entity.power.amount -= accepted;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -253,9 +254,9 @@ public class Generator extends PowerBlock{
|
||||
for(int i = 1; i < laserRange; i++){
|
||||
Tile other = world.tile(tile.x + i * point.x, tile.y + i * point.y);
|
||||
|
||||
if(other != null && other.block() instanceof PowerAcceptor){
|
||||
if(other != null && other.block().hasPower){
|
||||
Tile linked = other.getLinked();
|
||||
if(linked == null || linked.block() instanceof PowerAcceptor){
|
||||
if(linked == null || linked.block().hasPower){
|
||||
return other;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.generation;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
@@ -25,16 +24,15 @@ public class ItemPowerGenerator extends Generator{
|
||||
super(name);
|
||||
outputOnly = true;
|
||||
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.getItem(generateItem) / itemCapacity));
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.inventory.getItem(generateItem) / itemCapacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Item Capacity: " + itemCapacity);
|
||||
list.add("[powerinfo]Power Generation/second: " + Strings.toFixed(powerOutput*60f, 2));
|
||||
list.add("[powerinfo]Generation Seconds/item: " + Strings.toFixed(itemDuration/60f, 2));
|
||||
list.add("[powerinfo]Input: " + generateItem);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("powergenerationsecond", Strings.toFixed(powerOutput*60f, 2));
|
||||
stats.add("generationsecondsitem", Strings.toFixed(itemDuration/60f, 2));
|
||||
stats.add("input", generateItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,7 +43,7 @@ public class ItemPowerGenerator extends Generator{
|
||||
|
||||
if(entity.time > 0){
|
||||
Draw.color(heatColor);
|
||||
float alpha = (entity.hasItem(generateItem) ? 1f : Mathf.clamp(entity.time));
|
||||
float alpha = (entity.inventory.hasItem(generateItem) ? 1f : Mathf.clamp(entity.time));
|
||||
alpha = alpha * 0.7f + Mathf.absin(Timers.time(), 12f, 0.3f) * alpha;
|
||||
Draw.alpha(alpha);
|
||||
Draw.rect(name + "-top", tile.worldx(), tile.worldy());
|
||||
@@ -55,25 +53,25 @@ public class ItemPowerGenerator extends Generator{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return item == generateItem && tile.entity.getItem(generateItem) < itemCapacity;
|
||||
return item == generateItem && tile.entity.inventory.getItem(generateItem) < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
float maxPower = Math.min(powerCapacity - entity.power, powerOutput * Timers.delta());
|
||||
float maxPower = Math.min(powerCapacity - entity.power.amount, powerOutput * Timers.delta());
|
||||
float mfract = maxPower/(powerOutput);
|
||||
|
||||
if(entity.time > 0f){
|
||||
entity.time -= 1f/itemDuration*mfract;
|
||||
entity.power += maxPower;
|
||||
entity.power.amount += maxPower;
|
||||
entity.time = Mathf.clamp(entity.time);
|
||||
}
|
||||
|
||||
if(entity.time <= 0f && entity.hasItem(generateItem)){
|
||||
if(entity.time <= 0f && entity.inventory.hasItem(generateItem)){
|
||||
Effects.effect(generateEffect, tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f));
|
||||
entity.removeItem(generateItem, 1);
|
||||
entity.inventory.removeItem(generateItem, 1);
|
||||
entity.time = 1f;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package io.anuke.mindustry.world.blocks.types.generation;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidAcceptor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -13,43 +11,39 @@ import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
||||
public class LiquidPowerGenerator extends Generator{
|
||||
public int generateTime = 15;
|
||||
public Liquid generateLiquid;
|
||||
public float powerPerLiquid = 0.13f;
|
||||
/**Maximum liquid used per frame.*/
|
||||
public float maxLiquidGenerate = 0.4f;
|
||||
public float liquidCapacity = 30f;
|
||||
public Effect generateEffect = Fx.generatespark;
|
||||
|
||||
public LiquidPowerGenerator(String name) {
|
||||
super(name);
|
||||
outputOnly = true;
|
||||
liquidCapacity = 30f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[liquidinfo]Liquid Capacity: " + (int)liquidCapacity);
|
||||
list.add("[liquidinfo]Power/Liquid: " + Strings.toFixed(powerPerLiquid, 2) + " power/liquid");
|
||||
list.add("[liquidinfo]Max liquid/second: " + Strings.toFixed(maxLiquidGenerate*60f, 2) + " liquid/s");
|
||||
list.add("[liquidinfo]Input: " + generateLiquid);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("liquidcapacity", (int)liquidCapacity);
|
||||
stats.add("powerliquid", Strings.toFixed(powerPerLiquid, 2) + " power/liquid");
|
||||
stats.add("maxliquidsecond", Strings.toFixed(maxLiquidGenerate*60f, 2) + " liquid/s");
|
||||
stats.add("input", generateLiquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
TileEntity entity = tile.entity();
|
||||
|
||||
LiquidPowerEntity entity = tile.entity();
|
||||
if(entity.liquid.liquid == null) return;
|
||||
|
||||
if(entity.liquid == null) return;
|
||||
|
||||
Draw.color(entity.liquid.color);
|
||||
Draw.alpha(entity.liquidAmount / liquidCapacity);
|
||||
Draw.color(entity.liquid.liquid.color);
|
||||
Draw.alpha(entity.liquid.amount / liquidCapacity);
|
||||
drawLiquidCenter(tile);
|
||||
Draw.color();
|
||||
}
|
||||
@@ -60,14 +54,14 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
LiquidPowerEntity entity = tile.entity();
|
||||
TileEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquidAmount > 0){
|
||||
float used = Math.min(entity.liquidAmount, maxLiquidGenerate * Timers.delta());
|
||||
used = Math.min(used, (powerCapacity - entity.power)/powerPerLiquid);
|
||||
if(entity.liquid.amount > 0){
|
||||
float used = Math.min(entity.liquid.amount, maxLiquidGenerate * Timers.delta());
|
||||
used = Math.min(used, (powerCapacity - entity.power.amount)/powerPerLiquid);
|
||||
|
||||
entity.liquidAmount -= used;
|
||||
entity.power += used * powerPerLiquid;
|
||||
entity.liquid.amount -= used;
|
||||
entity.power.amount += used * powerPerLiquid;
|
||||
|
||||
if(used > 0.001f && Mathf.chance(0.05 * Timers.delta())){
|
||||
|
||||
@@ -79,54 +73,8 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity(){
|
||||
return new LiquidPowerEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
LiquidPowerEntity entity = tile.entity();
|
||||
|
||||
return liquid == generateLiquid && entity.liquidAmount + amount < liquidCapacity && (entity.liquid == liquid || entity.liquidAmount <= 0.01f);
|
||||
return liquid == generateLiquid && super.acceptLiquid(tile, source, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
LiquidPowerEntity entity = tile.entity();
|
||||
entity.liquid = liquid;
|
||||
entity.liquidAmount += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLiquid(Tile tile){
|
||||
LiquidPowerEntity entity = tile.entity();
|
||||
return entity.liquidAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLiquidCapacity(Tile tile){
|
||||
return liquidCapacity;
|
||||
}
|
||||
|
||||
public static class LiquidPowerEntity extends GeneratorEntity{
|
||||
public Liquid liquid;
|
||||
public float liquidAmount;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(liquid == null ? -1 : liquid.id);
|
||||
stream.writeByte((byte)(liquidAmount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
super.read(stream);
|
||||
byte id = stream.readByte();
|
||||
liquid = id == -1 ? null : Liquid.getByID(id);
|
||||
liquidAmount = stream.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.generation;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
@@ -28,7 +27,6 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
protected final Translator tr = new Translator();
|
||||
|
||||
protected Item generateItem;
|
||||
protected int itemCapacity = 30;
|
||||
protected Color coolColor = new Color(1, 1, 1, 0f);
|
||||
protected Color hotColor = Color.valueOf("ff9575a3");
|
||||
protected int fuelUseTime = 130; //time to consume 1 fuel
|
||||
@@ -51,39 +49,40 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
powerCapacity = 80f;
|
||||
powerSpeed = 0.5f;
|
||||
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.getItem(generateItem) / itemCapacity));
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.inventory.getItem(generateItem) / itemCapacity));
|
||||
bars.add(new BlockBar(Color.ORANGE, true, tile -> tile.<NuclearReactorEntity>entity().heat));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[powerinfo]Input Item: " + generateItem);
|
||||
list.add("[powerinfo]Max Power Generation/second: " + Strings.toFixed(powerMultiplier*60f, 2));
|
||||
list.removeValue(list.select(s -> s.contains("Power/Liquid")).iterator().next(), true);
|
||||
list.removeValue(list.select(s -> s.contains("Max liquid/second:")).iterator().next(), true);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("inputitem", generateItem);
|
||||
stats.add("maxpowergenerationsecond", Strings.toFixed(powerMultiplier*60f, 2));
|
||||
|
||||
stats.remove("powerliquid");
|
||||
stats.remove("maxliquidsecond");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
NuclearReactorEntity entity = tile.entity();
|
||||
|
||||
int fuel = entity.getItem(generateItem);
|
||||
int fuel = entity.inventory.getItem(generateItem);
|
||||
float fullness = (float)fuel / itemCapacity;
|
||||
|
||||
if(fuel > 0){
|
||||
entity.heat += fullness * heating * Math.min(Timers.delta(), 4f);
|
||||
entity.power += powerMultiplier * fullness * Timers.delta();
|
||||
entity.power = Mathf.clamp(entity.power, 0f, powerCapacity);
|
||||
entity.power.amount += powerMultiplier * fullness * Timers.delta();
|
||||
entity.power.amount = Mathf.clamp(entity.power.amount, 0f, powerCapacity);
|
||||
if(entity.timer.get(timerFuel, fuelUseTime)){
|
||||
entity.removeItem(generateItem, 1);
|
||||
entity.inventory.removeItem(generateItem, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if(entity.liquidAmount > 0){
|
||||
float maxCool = Math.min(entity.liquidAmount * coolantPower, entity.heat);
|
||||
if(entity.liquid.amount > 0){
|
||||
float maxCool = Math.min(entity.liquid.amount * coolantPower, entity.heat);
|
||||
entity.heat -= maxCool; //TODO steam when cooling large amounts?
|
||||
entity.liquidAmount -= maxCool / coolantPower;
|
||||
entity.liquid.amount -= maxCool / coolantPower;
|
||||
}
|
||||
|
||||
if(entity.heat > smokeThreshold){
|
||||
@@ -114,7 +113,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
|
||||
NuclearReactorEntity entity = tile.entity();
|
||||
|
||||
int fuel = entity.getItem(generateItem);
|
||||
int fuel = entity.inventory.getItem(generateItem);
|
||||
|
||||
if(fuel < 5 && entity.heat < 0.5f) return;
|
||||
|
||||
@@ -131,7 +130,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
Effects.shake(6f, 16f, tile.worldx(), tile.worldy());
|
||||
Effects.effect(explosionEffect, tile.worldx(), tile.worldy());
|
||||
for(int i = 0; i < 6; i ++){
|
||||
Timers.run(Mathf.random(40), ()->{
|
||||
Timers.run(Mathf.random(40), () -> {
|
||||
Effects.effect(Fx.nuclearcloud, tile.worldx(), tile.worldy());
|
||||
});
|
||||
}
|
||||
@@ -156,7 +155,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return item == generateItem && tile.entity.getItem(generateItem) < itemCapacity;
|
||||
return item == generateItem && tile.entity.inventory.getItem(generateItem) < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,7 +183,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
return new NuclearReactorEntity();
|
||||
}
|
||||
|
||||
public static class NuclearReactorEntity extends LiquidPowerEntity{
|
||||
public static class NuclearReactorEntity extends PowerEntity{
|
||||
public float heat;
|
||||
public float flash;
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package io.anuke.mindustry.world.blocks.types.modules;
|
||||
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.blocks.types.BlockModule;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class InventoryModule extends BlockModule{
|
||||
public int[] items = new int[Item.getAllItems().size];
|
||||
|
||||
public int totalItems(){
|
||||
int sum = 0;
|
||||
for(int i = 0; i < items.length; i ++){
|
||||
sum += items[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public int getItem(Item item){
|
||||
return items[item.id];
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item){
|
||||
return getItem(item) > 0;
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item, int amount){
|
||||
return getItem(item) >= amount;
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
items[item.id] += amount;
|
||||
}
|
||||
|
||||
public void removeItem(Item item, int amount){
|
||||
items[item.id] -= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
byte amount = 0;
|
||||
for(int i = 0; i < items.length; i ++){
|
||||
if(items[i] > 0) amount ++;
|
||||
}
|
||||
|
||||
stream.writeByte(amount); //amount of items
|
||||
|
||||
for(int i = 0; i < items.length; i ++){
|
||||
if(items[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(items[i]); //item amount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException {
|
||||
byte count = stream.readByte();
|
||||
|
||||
for(int j = 0; j < count; j ++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
items[itemid] = itemamount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package io.anuke.mindustry.world.blocks.types.modules;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.blocks.types.BlockModule;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LiquidModule extends BlockModule {
|
||||
public float amount;
|
||||
public Liquid liquid = Liquid.none;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
stream.writeByte(liquid.id);
|
||||
stream.writeByte((byte)(amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
byte id = stream.readByte();
|
||||
liquid = Liquid.getByID(id);
|
||||
amount = stream.readByte();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.anuke.mindustry.world.blocks.types.modules;
|
||||
|
||||
import io.anuke.mindustry.world.blocks.types.BlockModule;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PowerModule extends BlockModule{
|
||||
public float amount;
|
||||
public float capacity = 10f;
|
||||
public float voltage = 0.0001f;
|
||||
|
||||
public boolean acceptsPower(){
|
||||
return amount + 0.001f <= capacity;
|
||||
}
|
||||
|
||||
public float addPower(float add){
|
||||
if(add < voltage){
|
||||
return add;
|
||||
}
|
||||
|
||||
float canAccept = Math.min(capacity - amount, add);
|
||||
|
||||
amount += canAccept;
|
||||
|
||||
return canAccept;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
stream.writeFloat(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
amount = stream.readFloat();
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ public class Drill extends Block{
|
||||
protected Block resource;
|
||||
protected Item result;
|
||||
protected float time = 5;
|
||||
protected int capacity = 5;
|
||||
protected Effect drillEffect = Fx.spark;
|
||||
|
||||
public Drill(String name) {
|
||||
@@ -30,13 +29,13 @@ public class Drill extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
layer = Layer.overlay;
|
||||
itemCapacity = 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[iteminfo]Capacity: " + capacity);
|
||||
list.add("[iteminfo]Seconds/item: " + time);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("secondsitem", time);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,7 +54,7 @@ public class Drill extends Block{
|
||||
if(isValid(tile)) mines = 1;
|
||||
}
|
||||
|
||||
if(mines > 0 && entity.timer.get(timerDrill, 60 * time) && tile.entity.getItem(result) < capacity){
|
||||
if(mines > 0 && entity.timer.get(timerDrill, 60 * time) && tile.entity.inventory.getItem(result) < itemCapacity){
|
||||
for(int i = 0; i < mines; i ++) offloadNear(tile, result);
|
||||
Effects.effect(drillEffect, tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
@@ -36,47 +35,44 @@ public class LiquidCrafter extends LiquidBlock{
|
||||
health = 60;
|
||||
liquidCapacity = 21f;
|
||||
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> input == null ? -1f : (float)tile.entity.getItem(input) / itemCapacity));
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> input == null ? -1f : (float)tile.entity.inventory.getItem(input) / itemCapacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[liquidinfo]Max items/second: " + Strings.toFixed(60f/purifyTime, 1));
|
||||
list.add("[liquidinfo]Input liquid: " + inputLiquid + " x " + (int)liquidAmount);
|
||||
if(input != null) list.add("[iteminfo]Item Capacity: " + itemCapacity);
|
||||
if(input != null) list.add("[iteminfo]Input item: " + input + " x " + inputAmount);
|
||||
list.add("[iteminfo]Output: " + output);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("maxitemssecond", Strings.toFixed(60f/purifyTime, 1));
|
||||
stats.add("inputliquid", inputLiquid + " x " + (int)liquidAmount);
|
||||
if(input != null) stats.add("itemcapacity", itemCapacity);
|
||||
if(input != null) stats.add("inputitem", input + " x " + inputAmount);
|
||||
stats.add("output", output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
Draw.rect(name(), tile.drawx(), tile.drawy());
|
||||
|
||||
if(entity.liquid == null) return;
|
||||
if(tile.entity.liquid.liquid == null) return;
|
||||
|
||||
Draw.color(entity.liquid.color);
|
||||
Draw.alpha(entity.liquidAmount / liquidCapacity);
|
||||
Draw.color(tile.entity.liquid.liquid.color);
|
||||
Draw.alpha(tile.entity.liquid.amount / liquidCapacity);
|
||||
Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerPurify, purifyTime) && entity.liquidAmount >= liquidAmount &&
|
||||
(input == null || entity.hasItem(input, inputAmount))){
|
||||
if(tile.entity.timer.get(timerPurify, purifyTime) && tile.entity.liquid.amount >= liquidAmount &&
|
||||
(input == null || tile.entity.inventory.hasItem(input, inputAmount))){
|
||||
|
||||
if(input != null)
|
||||
entity.removeItem(input, inputAmount);
|
||||
entity.liquidAmount -= liquidAmount;
|
||||
tile.entity.inventory.removeItem(input, inputAmount);
|
||||
tile.entity.liquid.amount -= liquidAmount;
|
||||
offloadNear(tile, output);
|
||||
Effects.effect(craftEffect, tile.worldx(), tile.worldy());
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDump, 15)){
|
||||
if(tile.entity.timer.get(timerDump, 15)){
|
||||
tryDump(tile, output);
|
||||
}
|
||||
}
|
||||
@@ -89,7 +85,7 @@ public class LiquidCrafter extends LiquidBlock{
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
TileEntity entity = tile.entity();
|
||||
return input != null && item == input && entity.getItem(input) < itemCapacity;
|
||||
return input != null && item == input && entity.inventory.getItem(input) < itemCapacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerBlock.PowerEntity;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class PowerDrill extends Drill implements PowerAcceptor {
|
||||
public float powerCapacity = 10f;
|
||||
public class PowerDrill extends Drill{
|
||||
/**power use per frame.*/
|
||||
public float powerUse = 0.08f;
|
||||
|
||||
@@ -21,7 +16,7 @@ public class PowerDrill extends Drill implements PowerAcceptor {
|
||||
public PowerDrill(String name){
|
||||
super(name);
|
||||
|
||||
bars.add(new BlockBar(Color.YELLOW, true, tile -> tile.<PowerEntity>entity().power / powerCapacity));
|
||||
hasPower = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,8 +27,8 @@ public class PowerDrill extends Drill implements PowerAcceptor {
|
||||
|
||||
float used = Math.min(powerUse * Timers.delta(), powerCapacity-0.1f);
|
||||
|
||||
if(entity.power >= used){
|
||||
entity.power -= used;
|
||||
if(entity.power.amount >= used){
|
||||
entity.power.amount -= used;
|
||||
}
|
||||
|
||||
for(Tile other : tile.getLinkedTiles(tempTiles)){
|
||||
@@ -42,8 +37,8 @@ public class PowerDrill extends Drill implements PowerAcceptor {
|
||||
}
|
||||
}
|
||||
|
||||
if(toAdd.size > 0 && entity.power > powerUse && entity.timer.get(timerDrill, 60 * time)
|
||||
&& tile.entity.totalItems() < capacity){
|
||||
if(toAdd.size > 0 && entity.power.amount > powerUse && entity.timer.get(timerDrill, 60 * time)
|
||||
&& tile.entity.inventory.totalItems() < itemCapacity){
|
||||
for(ItemStack stack : toAdd) offloadNear(tile, stack.item);
|
||||
Effects.effect(drillEffect, tile.drawx(), tile.drawy());
|
||||
}
|
||||
@@ -53,35 +48,6 @@ public class PowerDrill extends Drill implements PowerAcceptor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
return entity.power + 0.001f <= powerCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float addPower(Tile tile, float amount){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
float canAccept = Math.min(powerCapacity - entity.power, amount);
|
||||
|
||||
entity.power += canAccept;
|
||||
|
||||
return canAccept;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPower(Tile tile, float power){
|
||||
PowerEntity entity = tile.entity();
|
||||
entity.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new PowerEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValid(Tile tile){
|
||||
return tile.floor().drops != null;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
@@ -45,35 +44,35 @@ public class PowerSmelter extends PowerBlock {
|
||||
@Override
|
||||
public void init(){
|
||||
for(ItemStack item : inputs){
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.getItem(item.item)/capacity));
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.inventory.getItem(item.item)/capacity));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[craftinfo]Input: " + Arrays.toString(inputs));
|
||||
list.add("[craftinfo]Power drain/second: " + Strings.toFixed(powerDrain*60f, 2));
|
||||
list.add("[craftinfo]Output: " + result);
|
||||
list.add("[craftinfo]Fuel Duration: " + Strings.toFixed(burnDuration/60f, 1));
|
||||
list.add("[craftinfo]Max output/second: " + Strings.toFixed(60f/craftTime, 1));
|
||||
list.add("[craftinfo]Input Capacity: " + capacity);
|
||||
list.add("[craftinfo]Output Capacity: " + capacity);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("input", Arrays.toString(inputs));
|
||||
stats.add("powerdrainsecond", Strings.toFixed(powerDrain*60f, 2));
|
||||
stats.add("output", result);
|
||||
stats.add("fuelduration", Strings.toFixed(burnDuration/60f, 1));
|
||||
stats.add("maxoutputsecond", Strings.toFixed(60f/craftTime, 1));
|
||||
stats.add("inputcapacity", capacity);
|
||||
stats.add("outputcapacity", capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
PowerSmelterEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerDump, 5) && entity.hasItem(result)){
|
||||
if(entity.timer.get(timerDump, 5) && entity.inventory.hasItem(result)){
|
||||
tryDump(tile, result);
|
||||
}
|
||||
|
||||
float used = powerDrain * Timers.delta();
|
||||
|
||||
//heat it up if there's enough power
|
||||
if(entity.power > used){
|
||||
entity.power -= used;
|
||||
if(entity.power.amount > used){
|
||||
entity.power.amount -= used;
|
||||
entity.heat += 1f /heatUpTime;
|
||||
if(Mathf.chance(Timers.delta() * burnEffectChance)) Effects.effect(burnEffect, entity.x + Mathf.range(2f), entity.y + Mathf.range(2f));
|
||||
}else{
|
||||
@@ -84,19 +83,19 @@ public class PowerSmelter extends PowerBlock {
|
||||
|
||||
//make sure it has all the items
|
||||
for(ItemStack item : inputs){
|
||||
if(!entity.hasItem(item.item, item.amount)){
|
||||
if(!entity.inventory.hasItem(item.item, item.amount)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(entity.getItem(result) >= capacity //output full
|
||||
if(entity.inventory.getItem(result) >= capacity //output full
|
||||
|| entity.heat <= minHeat //not burning
|
||||
|| !entity.timer.get(timerCraft, craftTime)){ //not yet time
|
||||
return;
|
||||
}
|
||||
|
||||
for(ItemStack item : inputs){
|
||||
entity.removeItem(item.item, item.amount);
|
||||
entity.inventory.removeItem(item.item, item.amount);
|
||||
}
|
||||
|
||||
offloadNear(tile, result);
|
||||
@@ -114,7 +113,7 @@ public class PowerSmelter extends PowerBlock {
|
||||
}
|
||||
}
|
||||
|
||||
return (isInput && tile.entity.getItem(item) < capacity);
|
||||
return (isInput && tile.entity.inventory.getItem(item) < capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
@@ -23,7 +21,7 @@ public class Pump extends LiquidBlock{
|
||||
rotate = false;
|
||||
solid = true;
|
||||
layer = Layer.overlay;
|
||||
flowfactor = 3f;
|
||||
liquidFlowFactor = 3f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,9 +30,9 @@ public class Pump extends LiquidBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[liquidinfo]Liquid/second: " + Strings.toFixed(60f*pumpAmount, 1));
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("liquidsecond", Strings.toFixed(60f*pumpAmount, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,12 +44,8 @@ public class Pump extends LiquidBlock{
|
||||
public void draw(Tile tile){
|
||||
Draw.rect(name(), tile.worldx(), tile.worldy());
|
||||
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquid == null) return;
|
||||
|
||||
Draw.color(entity.liquid.color);
|
||||
Draw.alpha(entity.liquidAmount / liquidCapacity);
|
||||
Draw.color(tile.entity.liquid.liquid.color);
|
||||
Draw.alpha(tile.entity.liquid.amount / liquidCapacity);
|
||||
Draw.rect("blank", tile.worldx(), tile.worldy(), 2, 2);
|
||||
Draw.color();
|
||||
}
|
||||
@@ -70,15 +64,14 @@ public class Pump extends LiquidBlock{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(tile.floor().liquidDrop != null){
|
||||
float maxPump = Math.min(liquidCapacity - entity.liquidAmount, pumpAmount * Timers.delta());
|
||||
entity.liquid = tile.floor().liquidDrop;
|
||||
entity.liquidAmount += maxPump;
|
||||
float maxPump = Math.min(liquidCapacity - tile.entity.liquid.amount, pumpAmount * Timers.delta());
|
||||
tile.entity.liquid.liquid = tile.floor().liquidDrop;
|
||||
tile.entity.liquid.amount += maxPump;
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDump, 1)){
|
||||
if(tile.entity.timer.get(timerDump, 1)){
|
||||
tryDumpLiquid(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
@@ -40,33 +39,33 @@ public class Smelter extends Block{
|
||||
@Override
|
||||
public void init(){
|
||||
for(Item item : inputs){
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.getItem(item)/capacity));
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.inventory.getItem(item)/capacity));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[craftinfo]Input: " + Arrays.toString(inputs));
|
||||
list.add("[craftinfo]Fuel: " + fuel);
|
||||
list.add("[craftinfo]Output: " + result);
|
||||
list.add("[craftinfo]Fuel Duration: " + Strings.toFixed(burnDuration/60f, 1));
|
||||
list.add("[craftinfo]Max output/second: " + Strings.toFixed(60f/craftTime, 1));
|
||||
list.add("[craftinfo]Input Capacity: " + capacity);
|
||||
list.add("[craftinfo]Output Capacity: " + capacity);
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add("input", Arrays.toString(inputs));
|
||||
stats.add("fuel", fuel);
|
||||
stats.add("output", result);
|
||||
stats.add("fuelduration", Strings.toFixed(burnDuration/60f, 1));
|
||||
stats.add("maxoutputsecond", Strings.toFixed(60f/craftTime, 1));
|
||||
stats.add("input capacity", capacity);
|
||||
stats.add("outputcapacity", capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
CrafterEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerDump, 5) && entity.hasItem(result)){
|
||||
if(entity.timer.get(timerDump, 5) && entity.inventory.hasItem(result)){
|
||||
tryDump(tile, result);
|
||||
}
|
||||
|
||||
//add fuel
|
||||
if(entity.getItem(fuel) > 0 && entity.burnTime <= 0f){
|
||||
entity.removeItem(fuel, 1);
|
||||
if(entity.inventory.getItem(fuel) > 0 && entity.burnTime <= 0f){
|
||||
entity.inventory.removeItem(fuel, 1);
|
||||
entity.burnTime += burnDuration;
|
||||
Effects.effect(burnEffect, entity.x + Mathf.range(2f), entity.y + Mathf.range(2f));
|
||||
}
|
||||
@@ -78,19 +77,19 @@ public class Smelter extends Block{
|
||||
|
||||
//make sure it has all the items
|
||||
for(Item item : inputs){
|
||||
if(!entity.hasItem(item)){
|
||||
if(!entity.inventory.hasItem(item)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(entity.getItem(result) >= capacity //output full
|
||||
if(entity.inventory.getItem(result) >= capacity //output full
|
||||
|| entity.burnTime <= 0 //not burning
|
||||
|| !entity.timer.get(timerCraft, craftTime)){ //not yet time
|
||||
return;
|
||||
}
|
||||
|
||||
for(Item item : inputs){
|
||||
entity.removeItem(item, 1);
|
||||
entity.inventory.removeItem(item, 1);
|
||||
}
|
||||
|
||||
offloadNear(tile, result);
|
||||
@@ -108,7 +107,7 @@ public class Smelter extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
return (isInput && tile.entity.getItem(item) < capacity) || (item == fuel && tile.entity.getItem(fuel) < capacity);
|
||||
return (isInput && tile.entity.inventory.getItem(item) < capacity) || (item == fuel && tile.entity.inventory.getItem(fuel) < capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,6 +31,6 @@ public class CoreBlock extends StorageBlock {
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return item.material && tile.entity.getItem(item) < capacity;
|
||||
return item.material && tile.entity.inventory.getItem(item) < capacity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ public abstract class StorageBlock extends Block {
|
||||
/**Removes any one item and returns it. Returns null if no items are there.*/
|
||||
public Item removeItem(Tile tile){
|
||||
TileEntity entity = tile.entity;
|
||||
for(int i = 0; i < entity.items.length; i ++){
|
||||
if(entity.items[i] > 0){
|
||||
entity.items[i] --;
|
||||
for(int i = 0; i < entity.inventory.items.length; i ++){
|
||||
if(entity.inventory.items[i] > 0){
|
||||
entity.inventory.items[i] --;
|
||||
return Item.getByID(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,16 @@ public class Unloader extends Block {
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
if(tile.entity.totalItems() == 0 && tile.entity.timer.get(timerUnload, 5)){
|
||||
if(tile.entity.inventory.totalItems() == 0 && tile.entity.timer.get(timerUnload, 5)){
|
||||
tile.allNearby(other -> {
|
||||
if(tile.entity.totalItems() == 0 && other.block() instanceof StorageBlock &&
|
||||
other.entity.totalItems() > 0){
|
||||
if(other.block() instanceof StorageBlock && tile.entity.inventory.totalItems() == 0 &&
|
||||
other.entity.inventory.totalItems() > 0){
|
||||
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(tile.entity.totalItems() > 0){
|
||||
if(tile.entity.inventory.totalItems() > 0){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.storage;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -14,13 +13,7 @@ public class Vault extends StorageBlock {
|
||||
super(name);
|
||||
solid = true;
|
||||
update = true;
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.totalItems()/capacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[iteminfo]Capacity: " + capacity);
|
||||
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.inventory.totalItems()/capacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,7 +21,7 @@ public class Vault extends StorageBlock {
|
||||
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
|
||||
|
||||
for(int i = 0; i < iterations; i ++) {
|
||||
if (tile.entity.totalItems() > 0) {
|
||||
if (tile.entity.inventory.totalItems() > 0) {
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +35,7 @@ public class Vault extends StorageBlock {
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source) {
|
||||
return tile.entity.totalItems() < capacity;
|
||||
return tile.entity.inventory.totalItems() < capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user