Made nuclear reactor functional, better multiblock support
This commit is contained in:
@@ -67,6 +67,7 @@ import io.anuke.ucore.entities.Entity;
|
|||||||
* Amount of tiles (int)
|
* Amount of tiles (int)
|
||||||
* (tile list)
|
* (tile list)
|
||||||
* Tile position, as a single integer, in the format x+y*width
|
* Tile position, as a single integer, in the format x+y*width
|
||||||
|
* Tile link - byte
|
||||||
* Tile type (boolean)- whether the block has a tile entity attached
|
* Tile type (boolean)- whether the block has a tile entity attached
|
||||||
* Block ID - the block ID
|
* Block ID - the block ID
|
||||||
* (the following only applies to tile entity blocks)
|
* (the following only applies to tile entity blocks)
|
||||||
@@ -81,7 +82,7 @@ import io.anuke.ucore.entities.Entity;
|
|||||||
*/
|
*/
|
||||||
public class SaveIO{
|
public class SaveIO{
|
||||||
/**Save file version ID. Should be incremented every breaking release.*/
|
/**Save file version ID. Should be incremented every breaking release.*/
|
||||||
private static final int fileVersionID = 7;
|
private static final int fileVersionID = 8;
|
||||||
|
|
||||||
//TODO automatic registration of types?
|
//TODO automatic registration of types?
|
||||||
private static final Array<Class<? extends Enemy>> enemyIDs = Array.with(
|
private static final Array<Class<? extends Enemy>> enemyIDs = Array.with(
|
||||||
@@ -229,6 +230,7 @@ public class SaveIO{
|
|||||||
if(tile.breakable()){
|
if(tile.breakable()){
|
||||||
|
|
||||||
stream.writeInt(x + y*World.width()); //tile pos
|
stream.writeInt(x + y*World.width()); //tile pos
|
||||||
|
stream.writeByte(tile.link);
|
||||||
stream.writeBoolean(tile.entity != null); //whether it has a tile entity
|
stream.writeBoolean(tile.entity != null); //whether it has a tile entity
|
||||||
stream.writeInt(tile.block().id); //block ID
|
stream.writeInt(tile.block().id); //block ID
|
||||||
|
|
||||||
@@ -367,11 +369,13 @@ public class SaveIO{
|
|||||||
|
|
||||||
for(int i = 0; i < tiles; i ++){
|
for(int i = 0; i < tiles; i ++){
|
||||||
int pos = stream.readInt();
|
int pos = stream.readInt();
|
||||||
|
byte link = stream.readByte();
|
||||||
boolean hasEntity = stream.readBoolean();
|
boolean hasEntity = stream.readBoolean();
|
||||||
int blockid = stream.readInt();
|
int blockid = stream.readInt();
|
||||||
|
|
||||||
Tile tile = World.tile(pos % World.width(), pos / World.width());
|
Tile tile = World.tile(pos % World.width(), pos / World.width());
|
||||||
tile.setBlock(Block.getByID(blockid));
|
tile.setBlock(Block.getByID(blockid));
|
||||||
|
tile.link = link;
|
||||||
|
|
||||||
if(hasEntity){
|
if(hasEntity){
|
||||||
byte rotation = stream.readByte();
|
byte rotation = stream.readByte();
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class Generator{
|
|||||||
floor = Blocks.titanium;
|
floor = Blocks.titanium;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Noise.nnoise(x + 99999, y + 99999, 6, 1) > 0.254){
|
if(Noise.nnoise(x + 99999, y + 99999, 6, 1) > 0.256){
|
||||||
floor = Blocks.uranium;
|
floor = Blocks.uranium;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class Tile{
|
|||||||
private Block block = Blocks.air;
|
private Block block = Blocks.air;
|
||||||
/**The coordinates of the core tile this is linked to, in the form of two bytes packed into one.
|
/**The coordinates of the core tile this is linked to, in the form of two bytes packed into one.
|
||||||
* This is relative to the block it is linked to; negate coords to find the link.*/
|
* This is relative to the block it is linked to; negate coords to find the link.*/
|
||||||
private byte link = 0;
|
public byte link = 0;
|
||||||
public TileEntity entity;
|
public TileEntity entity;
|
||||||
public short x, y;
|
public short x, y;
|
||||||
public byte rotation, dump;
|
public byte rotation, dump;
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ public class ProductionBlocks{
|
|||||||
resource = Blocks.uranium;
|
resource = Blocks.uranium;
|
||||||
result = Item.uranium;
|
result = Item.uranium;
|
||||||
formalName = "uranium drill";
|
formalName = "uranium drill";
|
||||||
|
time = 7;
|
||||||
}},
|
}},
|
||||||
|
|
||||||
titaniumdrill = new Drill("titaniumdrill"){{
|
titaniumdrill = new Drill("titaniumdrill"){{
|
||||||
@@ -182,11 +183,15 @@ public class ProductionBlocks{
|
|||||||
powerCapacity = 40f;
|
powerCapacity = 40f;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nuclearReactor = new LiquidPowerGenerator("nuclearreactor"){
|
nuclearReactor = new LiquidItemPowerGenerator("nuclearreactor"){
|
||||||
{
|
{
|
||||||
width = 2;
|
width = 2;
|
||||||
height = 2;
|
height = 2;
|
||||||
generateLiquid = Liquid.water;
|
generateLiquid = Liquid.water;
|
||||||
|
generateItem = Item.uranium;
|
||||||
|
itemCapacity = 60;
|
||||||
|
itemInput = 6;
|
||||||
|
inputLiquid = 2f;
|
||||||
health = 340;
|
health = 340;
|
||||||
breaktime *= 2.2f;
|
breaktime *= 2.2f;
|
||||||
powerCapacity = 100f;
|
powerCapacity = 100f;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.anuke.mindustry.world.blocks.types;
|
package io.anuke.mindustry.world.blocks.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.resource.Liquid;
|
import io.anuke.mindustry.resource.Liquid;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
@@ -19,6 +20,16 @@ public class BlockPart extends Block implements PowerAcceptor, LiquidAcceptor{
|
|||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleItem(Tile tile, Item item, Tile source){
|
||||||
|
tile.getLinked().block().handleItem(tile.getLinked(), item, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||||
|
return dest.getLinked().block().acceptItem(item, dest.getLinked(), source);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||||
Block block = linked(tile);
|
Block block = linked(tile);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.DataOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.entities.Bullet;
|
import io.anuke.mindustry.entities.Bullet;
|
||||||
@@ -44,13 +45,16 @@ public class Turret extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Tile tile){
|
public void draw(Tile tile){
|
||||||
Draw.rect("block", tile.worldx(), tile.worldy());
|
Vector2 offset = getPlaceOffset();
|
||||||
|
Draw.rect("block", tile.worldx() + offset.x, tile.worldy() + offset.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawOver(Tile tile){
|
public void drawOver(Tile tile){
|
||||||
TurretEntity entity = tile.entity();
|
TurretEntity entity = tile.entity();
|
||||||
Draw.rect(name(), tile.worldx(), tile.worldy(), entity.rotation - 90);
|
Vector2 offset = getPlaceOffset();
|
||||||
|
|
||||||
|
Draw.rect(name(), tile.worldx() + offset.x, tile.worldy() + offset.y, entity.rotation - 90);
|
||||||
|
|
||||||
if(Vars.debug && drawDebug){
|
if(Vars.debug && drawDebug){
|
||||||
drawTargeting(tile);
|
drawTargeting(tile);
|
||||||
@@ -59,8 +63,10 @@ public class Turret extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawPixelOverlay(Tile tile){
|
public void drawPixelOverlay(Tile tile){
|
||||||
|
Vector2 offset = getPlaceOffset();
|
||||||
|
|
||||||
Draw.color("green");
|
Draw.color("green");
|
||||||
Draw.dashcircle(tile.worldx(), tile.worldy(), range);
|
Draw.dashcircle(tile.worldx() + offset.x, tile.worldy() + offset.y, range);
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|
||||||
TurretEntity entity = tile.entity();
|
TurretEntity entity = tile.entity();
|
||||||
@@ -69,7 +75,7 @@ public class Turret extends Block{
|
|||||||
if(fract > 0)
|
if(fract > 0)
|
||||||
fract = Mathf.clamp(fract, 0.24f, 1f);
|
fract = Mathf.clamp(fract, 0.24f, 1f);
|
||||||
|
|
||||||
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 6, fract);
|
Vars.renderer.drawBar(Color.GREEN, tile.worldx() + offset.x, tile.worldy() + 6 + offset.y, fract);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package io.anuke.mindustry.world.blocks.types.production;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
|
import io.anuke.mindustry.resource.Item;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.ucore.core.Effects;
|
||||||
|
import io.anuke.ucore.core.Timers;
|
||||||
|
|
||||||
|
public class LiquidItemPowerGenerator extends LiquidPowerGenerator{
|
||||||
|
public Item generateItem;
|
||||||
|
public int itemInput = 5;
|
||||||
|
public int itemCapacity = 30;
|
||||||
|
|
||||||
|
public LiquidItemPowerGenerator(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawPixelOverlay(Tile tile){
|
||||||
|
super.drawPixelOverlay(tile);
|
||||||
|
|
||||||
|
TileEntity entity = tile.entity();
|
||||||
|
|
||||||
|
Vector2 offset = getPlaceOffset();
|
||||||
|
|
||||||
|
Vars.renderer.drawBar(Color.GREEN, tile.worldx() + offset.x, tile.worldy() + 6 +
|
||||||
|
offset.y + height*Vars.tilesize/2f, (float)entity.totalItems() / itemCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Tile tile){
|
||||||
|
LiquidPowerEntity entity = tile.entity();
|
||||||
|
|
||||||
|
if(entity.liquidAmount >= inputLiquid && entity.hasItem(generateItem, itemInput)
|
||||||
|
&& Timers.get(tile, "consume", generateTime)){
|
||||||
|
entity.liquidAmount -= inputLiquid;
|
||||||
|
entity.power += generatePower;
|
||||||
|
|
||||||
|
Vector2 offset = getPlaceOffset();
|
||||||
|
Effects.effect(generateEffect, tile.worldx() + offset.x, tile.worldy() + offset.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Timers.get(tile, "generate", generateTime)){
|
||||||
|
distributePower(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||||
|
return item == generateItem && tile.entity.totalItems() < itemCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import io.anuke.mindustry.resource.Liquid;
|
|||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.types.LiquidAcceptor;
|
import io.anuke.mindustry.world.blocks.types.LiquidAcceptor;
|
||||||
import io.anuke.ucore.core.Draw;
|
import io.anuke.ucore.core.Draw;
|
||||||
|
import io.anuke.ucore.core.Effects;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
|
|
||||||
public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
||||||
@@ -19,8 +20,9 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
|||||||
/**Power to generate per generateInput.*/
|
/**Power to generate per generateInput.*/
|
||||||
public float generatePower = 1f;
|
public float generatePower = 1f;
|
||||||
/**How much liquid to consume to get one generatePower.*/
|
/**How much liquid to consume to get one generatePower.*/
|
||||||
public float generateInput = 1f;
|
public float inputLiquid = 1f;
|
||||||
public float liquidCapacity = 30f;
|
public float liquidCapacity = 30f;
|
||||||
|
public String generateEffect = "generate";
|
||||||
|
|
||||||
public LiquidPowerGenerator(String name) {
|
public LiquidPowerGenerator(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
@@ -46,12 +48,15 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
|||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
LiquidPowerEntity entity = tile.entity();
|
LiquidPowerEntity entity = tile.entity();
|
||||||
|
|
||||||
if(entity.liquidAmount >= generateInput && Timers.get(tile, "generate", generateTime)){
|
if(entity.liquidAmount >= inputLiquid && Timers.get(tile, "consume", generateTime)){
|
||||||
entity.liquidAmount -= generateInput;
|
entity.liquidAmount -= inputLiquid;
|
||||||
entity.power += generatePower;
|
entity.power += generatePower;
|
||||||
|
|
||||||
|
Vector2 offset = getPlaceOffset();
|
||||||
|
Effects.effect(generateEffect, tile.worldx() + offset.x, tile.worldy() + offset.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Timers.get(tile, "generate", generateTime)){
|
if(Timers.get(tile, "consume", generateTime)){
|
||||||
distributePower(tile);
|
distributePower(tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user