New power system implemented

This commit is contained in:
Anuken
2018-03-23 22:39:42 -04:00
parent 7d2fd514be
commit 7b3d60215b
18 changed files with 128 additions and 37 deletions

View File

@@ -25,7 +25,7 @@ allprojects {
appName = 'Mindustry' appName = 'Mindustry'
gdxVersion = '1.9.8' gdxVersion = '1.9.8'
aiVersion = '1.8.1' aiVersion = '1.8.1'
uCoreVersion = '5e6c99a' uCoreVersion = '64d13cc'
getVersionString = { getVersionString = {
String buildVersion = getBuildVersion() String buildVersion = getBuildVersion()

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

View File

@@ -1,7 +1,7 @@
#Autogenerated file. Do not modify. #Autogenerated file. Do not modify.
#Fri Mar 23 20:15:39 EDT 2018 #Fri Mar 23 22:35:52 EDT 2018
version=release version=release
androidBuildCode=621 androidBuildCode=623
name=Mindustry name=Mindustry
code=3.4 code=3.4
build=custom build build=custom build

View File

@@ -109,12 +109,6 @@ public class Control extends Module{
DefaultKeybinds.load(); DefaultKeybinds.load();
for(int i = 0; i < saveSlots; i ++){
Settings.defaults("save-" + i + "-autosave", !gwt);
Settings.defaults("save-" + i + "-name", "untitled");
Settings.defaults("save-" + i + "-data", "empty");
}
Settings.defaultList( Settings.defaultList(
"ip", "localhost", "ip", "localhost",
"port", port+"", "port", port+"",
@@ -172,7 +166,7 @@ public class Control extends Module{
Events.on(WaveEvent.class, () -> { Events.on(WaveEvent.class, () -> {
Sounds.play("spawn"); Sounds.play("spawn");
int last = Settings.getInt("hiscore" + world.getMap().name); int last = Settings.getInt("hiscore" + world.getMap().name, 0);
if(state.wave > last && !state.mode.infiniteResources && !state.mode.disableWaveTimer){ if(state.wave > last && !state.mode.infiniteResources && !state.mode.disableWaveTimer){
Settings.putInt("hiscore" + world.getMap().name, state.wave); Settings.putInt("hiscore" + world.getMap().name, state.wave);

View File

@@ -96,7 +96,7 @@ public class DesktopInput extends InputHandler{
} }
Tile cursor = world.tile(tilex(), tiley()); Tile cursor = world.tile(tilex(), tiley());
Tile target = cursor == null ? null : cursor.isLinked() ? cursor.getLinked() : cursor; Tile target = cursor == null ? null : cursor.target();
boolean showCursor = false; boolean showCursor = false;
if(recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown("block_info") if(recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown("block_info")
@@ -111,10 +111,11 @@ public class DesktopInput extends InputHandler{
if(target != null && Inputs.keyTap("select") && !ui.hasMouse()){ if(target != null && Inputs.keyTap("select") && !ui.hasMouse()){
if(target.block().isConfigurable(target)){ if(target.block().isConfigurable(target)){
if((!ui.configfrag.isShown() if((!ui.configfrag.isShown()
|| ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), target))) || ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor)))
ui.configfrag.showConfig(target); ui.configfrag.showConfig(target);
}else if(!ui.configfrag.hasConfigMouse()){ }else if(!ui.configfrag.hasConfigMouse()){
ui.configfrag.hideConfig(); if(ui.configfrag.isShown() && ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor))
ui.configfrag.hideConfig();
} }
target.block().tapped(target); target.block().tapped(target);

View File

@@ -44,7 +44,7 @@ public class SaveIO{
public static void loadFromSlot(int slot){ public static void loadFromSlot(int slot){
if(gwt){ if(gwt){
String string = Settings.getString("save-"+slot+"-data"); String string = Settings.getString("save-"+slot+"-data", "");
ByteArrayInputStream stream = new ByteArrayInputStream(Base64Coder.decode(string)); ByteArrayInputStream stream = new ByteArrayInputStream(Base64Coder.decode(string));
load(stream); load(stream);
}else{ }else{
@@ -54,7 +54,7 @@ public class SaveIO{
public static DataInputStream getSlotStream(int slot){ public static DataInputStream getSlotStream(int slot){
if(gwt){ if(gwt){
String string = Settings.getString("save-"+slot+"-data"); String string = Settings.getString("save-"+slot+"-data", "");
byte[] bytes = Base64Coder.decode(string); byte[] bytes = Base64Coder.decode(string);
return new DataInputStream(new ByteArrayInputStream(bytes)); return new DataInputStream(new ByteArrayInputStream(bytes));
}else{ }else{

View File

@@ -11,6 +11,7 @@ import io.anuke.ucore.core.Timers;
import java.io.IOException; import java.io.IOException;
import static io.anuke.mindustry.Vars.gwt;
import static io.anuke.mindustry.Vars.saveSlots; import static io.anuke.mindustry.Vars.saveSlots;
import static io.anuke.mindustry.Vars.state; import static io.anuke.mindustry.Vars.state;
@@ -127,7 +128,7 @@ public class Saves {
} }
public String getName(){ public String getName(){
return Settings.getString("save-"+index+"-name"); return Settings.getString("save-"+index+"-name", "untittled");
} }
public void setName(String name){ public void setName(String name){
@@ -148,7 +149,7 @@ public class Saves {
} }
public boolean isAutosave(){ public boolean isAutosave(){
return Settings.getBool("save-"+index+"-autosave"); return Settings.getBool("save-"+index+"-autosave", !gwt);
} }
public void setAutosave(boolean save){ public void setAutosave(boolean save){

View File

@@ -36,7 +36,7 @@ public abstract class BaseBlock {
} }
public boolean acceptPower(Tile tile, Tile source, float amount){ public boolean acceptPower(Tile tile, Tile source, float amount){
return amount + tile.entity.power.amount <= powerCapacity; return true;
} }
public float addPower(Tile tile, float amount){ public float addPower(Tile tile, float amount){

View File

@@ -1,9 +1,9 @@
package io.anuke.mindustry.world.blocks; package io.anuke.mindustry.world.blocks;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.mindustry.world.blocks.types.distribution.*; import io.anuke.mindustry.world.blocks.types.distribution.*;
import io.anuke.mindustry.world.blocks.types.generation.PowerDistributor; import io.anuke.mindustry.world.blocks.types.generation.PowerDistributor;
import io.anuke.mindustry.world.blocks.types.generation.PowerGenerator;
import io.anuke.mindustry.world.blocks.types.storage.SortedUnloader; import io.anuke.mindustry.world.blocks.types.storage.SortedUnloader;
import io.anuke.mindustry.world.blocks.types.storage.Unloader; import io.anuke.mindustry.world.blocks.types.storage.Unloader;
import io.anuke.mindustry.world.blocks.types.storage.Vault; import io.anuke.mindustry.world.blocks.types.storage.Vault;
@@ -78,10 +78,10 @@ public class DistributionBlocks{
}}, }},
powernode = new PowerDistributor("powernode"){{ powernode = new PowerDistributor("powernode"){{
}}, }},
battery = new PowerBlock("battery"){{ battery = new PowerGenerator("battery"){{
powerCapacity = 320f; powerCapacity = 320f;
}}, }},
batteryLarge = new PowerBlock("batterylarge"){{ batteryLarge = new PowerGenerator("batterylarge"){{
size = 3; size = 3;
powerCapacity = 2000f; powerCapacity = 2000f;
}}, }},

View File

@@ -47,7 +47,6 @@ public class NuclearReactor extends LiquidPowerGenerator{
liquidCapacity = 50; liquidCapacity = 50;
explosionEffect = Fx.nuclearShockwave; explosionEffect = Fx.nuclearShockwave;
powerCapacity = 80f; powerCapacity = 80f;
powerSpeed = 0.5f;
} }
@Override @Override

View File

@@ -46,13 +46,17 @@ public class PowerDistributor extends PowerBlock{
expanded = true; expanded = true;
layer = Layer.power; layer = Layer.power;
hasInventory = false; hasInventory = false;
powerCapacity = 1f;
} }
@Override
public void setBars(){}
@Override @Override
public void placed(Tile tile) { public void placed(Tile tile) {
Tile before = world.tile(lastPlaced); Tile before = world.tile(lastPlaced);
if(linkValid(tile, before)){ if(linkValid(tile, before) && before.block() instanceof PowerDistributor){
tile.<DistributorEntity>entity().links.add(before.packedPosition()); link(tile, before);
} }
lastPlaced = tile.packedPosition(); lastPlaced = tile.packedPosition();
@@ -78,13 +82,13 @@ public class PowerDistributor extends PowerBlock{
@Override @Override
public boolean onConfigureTileTapped(Tile tile, Tile other){ public boolean onConfigureTileTapped(Tile tile, Tile other){
DistributorEntity entity = tile.entity(); other = other.target();
if(linkValid(tile, other)){ if(linkValid(tile, other)){
if(entity.links.contains(other.packedPosition())){ if(linked(tile, other)){
entity.links.removeValue(other.packedPosition()); unlink(tile, other);
}else{ }else{
entity.links.add(other.packedPosition()); link(tile, other);
} }
return false; return false;
} }
@@ -105,11 +109,12 @@ public class PowerDistributor extends PowerBlock{
@Override @Override
public void drawConfigure(Tile tile){ public void drawConfigure(Tile tile){
Draw.color("accent"); Draw.color("accent");
Lines.stroke(1f); Lines.stroke(1f);
Lines.square(tile.drawx(), tile.drawy(), Lines.square(tile.drawx(), tile.drawy(),
tile.block().size * tilesize / 2f + 1f); tile.block().size * tilesize / 2f + 1f + Mathf.absin(Timers.time(), 4f, 1f));
Lines.stroke(1f); Lines.stroke(1f);
@@ -120,9 +125,17 @@ public class PowerDistributor extends PowerBlock{
for(int x = tile.x - laserRange; x <= tile.x + laserRange; x ++){ for(int x = tile.x - laserRange; x <= tile.x + laserRange; x ++){
for(int y = tile.y - laserRange; y <= tile.y + laserRange; y ++){ for(int y = tile.y - laserRange; y <= tile.y + laserRange; y ++){
Tile link = world.tile(x, y); Tile link = world.tile(x, y);
if(link != null) link = link.target();
if(link != tile && linkValid(tile, link)){ if(link != tile && linkValid(tile, link)){
if(linked(tile, link)){
Draw.color("place");
}else{
Draw.color(Color.SCARLET);
}
Lines.square(link.drawx(), link.drawy(), Lines.square(link.drawx(), link.drawy(),
link.block().size * tilesize / 2f + 1f); link.block().size * tilesize / 2f + 1f + Mathf.absin(Timers.time(), 4f, 1f));
} }
} }
} }
@@ -165,13 +178,67 @@ public class PowerDistributor extends PowerBlock{
protected void distributeLaserPower(Tile tile){ protected void distributeLaserPower(Tile tile){
DistributorEntity entity = tile.entity(); DistributorEntity entity = tile.entity();
//TODO implement //validate everything first.
for(int i = 0; i < entity.links.size; i ++){
Tile target = world.tile(entity.links.get(i));
if(!linkValid(tile, target)) {
entity.links.removeIndex(i);
i --;
}
}
float result = Math.min(entity.power.amount / entity.links.size, powerSpeed * Timers.delta());
for(int i = 0; i < entity.links.size; i ++){
Tile target = world.tile(entity.links.get(i));
float transmit = Math.min(result * Timers.delta(), entity.power.amount);
if(target.block().acceptPower(target, tile, transmit)){
entity.power.amount -= target.block().addPower(target, transmit);
}
}
}
protected void link(Tile tile, Tile other){
DistributorEntity entity = tile.entity();
if(!entity.links.contains(other.packedPosition())){
entity.links.add(other.packedPosition());
}
if(other.block() instanceof PowerDistributor){
DistributorEntity oe = other.entity();
if(!oe.links.contains(tile.packedPosition())){
oe.links.add(tile.packedPosition());
}
}
}
protected void unlink(Tile tile, Tile other){
DistributorEntity entity = tile.entity();
entity.links.removeValue(other.packedPosition());
if(other.block() instanceof PowerDistributor){
DistributorEntity oe = other.entity();
oe.links.removeValue(tile.packedPosition());
}
}
protected boolean linked(Tile tile, Tile other){
return tile.<DistributorEntity>entity().links.contains(other.packedPosition());
} }
protected boolean linkValid(Tile tile, Tile link){ protected boolean linkValid(Tile tile, Tile link){
return tile != link && link != null && link.block() instanceof PowerDistributor && if(!(tile != link && link != null && link.block().hasPower)) return false;
Vector2.dst(tile.worldx(), tile.worldy(), link.worldx(), link.worldy()) < Math.max(laserRange * tilesize,
((PowerDistributor)link.block()).laserRange * tilesize); if(link.block() instanceof PowerDistributor){
return Vector2.dst(tile.worldx(), tile.worldy(), link.worldx(), link.worldy()) <= Math.max(laserRange * tilesize,
((PowerDistributor)link.block()).laserRange * tilesize) - tilesize/2f;
}else{
return Vector2.dst(tile.worldx(), tile.worldy(), link.worldx(), link.worldy()) <= laserRange * tilesize - tilesize/2f;
}
} }
protected void drawLaser(Tile tile, Tile target){ protected void drawLaser(Tile tile, Tile target){
@@ -182,7 +249,7 @@ public class PowerDistributor extends PowerBlock{
float angle2 = angle1 + 180f; float angle2 = angle1 + 180f;
t1.trns(angle1, tile.block().size * tilesize/2f + 1f); t1.trns(angle1, tile.block().size * tilesize/2f + 1f);
t2.trns(angle2,tile.block().size * tilesize/2f + 1f); t2.trns(angle2, target.block().size * tilesize/2f + 1f);
Shapes.laser("laser", "laser-end", x1 + t1.x, y1 + t1.y, Shapes.laser("laser", "laser-end", x1 + t1.x, y1 + t1.y,
x2 + t2.x, y2 + t2.y, thicknessScl); x2 + t2.x, y2 + t2.y, thicknessScl);

View File

@@ -1,7 +1,9 @@
package io.anuke.mindustry.world.blocks.types.generation; package io.anuke.mindustry.world.blocks.types.generation;
import com.badlogic.gdx.math.GridPoint2;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.world.Edges;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerBlock; import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects;
@@ -9,14 +11,41 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
public class PowerGenerator extends PowerBlock { public class PowerGenerator extends PowerBlock {
protected float powerSpeed = 1f;
public PowerGenerator(String name) { public PowerGenerator(String name) {
super(name); super(name);
} }
protected void distributePower(Tile tile){ protected void distributePower(Tile tile){
//TODO! TileEntity entity = tile.entity;
int sources = 0;
for(GridPoint2 point : Edges.getEdges(size)){
Tile target = tile.getNearby(point);
if(target != null && target.block().hasPower) sources ++;
}
if(sources == 0) return;
float result = entity.power.amount / sources;
for(GridPoint2 point : Edges.getEdges(size)){
Tile target = tile.getNearby(point);
if(target == null) continue;
target = target.target();
if(target.block().hasPower){
float transmit = Math.min(result * Timers.delta(), entity.power.amount);
if(target.block().acceptPower(target, tile, transmit)){
entity.power.amount -= target.block().addPower(target, transmit);
}
}
}
}
@Override
public void update(Tile tile) {
distributePower(tile);
} }
@Override @Override