Optimization; fixed #9
This commit is contained in:
@@ -20,8 +20,8 @@ public class Vars{
|
||||
public static final float placerange = 66;
|
||||
//respawn time in frames
|
||||
public static final float respawnduration = 60*4;
|
||||
//time between waves in frames
|
||||
public static final float wavespace = 40*60*(android ? 1 : 1);
|
||||
//time between waves in frames (on normal mode)
|
||||
public static final float wavespace = 50*60*(android ? 1 : 1);
|
||||
//waves can last no longer than 6 minutes, otherwise the next one spawns
|
||||
public static final float maxwavespace = 60*60*6;
|
||||
//how far away from spawn points the player can't place blocks
|
||||
|
||||
@@ -2,12 +2,13 @@ package io.anuke.mindustry.core;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.badlogic.gdx.Application.ApplicationType;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.input.GestureDetector;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
@@ -41,11 +42,11 @@ public class Control extends Module{
|
||||
boolean hiscore = false;
|
||||
|
||||
final Array<Weapon> weapons = new Array<>();
|
||||
final ObjectMap<Item, Integer> items = new ObjectMap<>();
|
||||
final int[] items = new int[Item.values().length];
|
||||
|
||||
final EntityGroup<Enemy> enemyGroup = Entities.addGroup(Enemy.class);
|
||||
final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||
final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
|
||||
public final EntityGroup<Enemy> enemyGroup = Entities.addGroup(Enemy.class);
|
||||
public final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||
public final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
|
||||
|
||||
Array<EnemySpawn> spawns = new Array<>();
|
||||
int wave = 1;
|
||||
@@ -163,9 +164,7 @@ public class Control extends Module{
|
||||
wavetime = waveSpacing()*2;
|
||||
|
||||
if(mode == GameMode.sandbox){
|
||||
for(Item type : Item.values()){
|
||||
items.put(type, 999999999);
|
||||
}
|
||||
Arrays.fill(items, 999999999);
|
||||
}
|
||||
|
||||
ui.updateItems();
|
||||
@@ -347,22 +346,21 @@ public class Control extends Module{
|
||||
}
|
||||
|
||||
public void clearItems(){
|
||||
items.clear();
|
||||
Arrays.fill(items, 0);
|
||||
|
||||
items.put(Item.stone, 40);
|
||||
addItem(Item.stone, 40);
|
||||
|
||||
if(debug){
|
||||
for(Item item : Item.values())
|
||||
items.put(item, 2000000);
|
||||
Arrays.fill(items, 2000000);
|
||||
}
|
||||
}
|
||||
|
||||
public int getAmount(Item item){
|
||||
return items.get(item, 0);
|
||||
return items[item.ordinal()];
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
items.put(item, items.get(item, 0)+amount);
|
||||
items[item.ordinal()] += amount;
|
||||
shouldUpdateItems = true;
|
||||
}
|
||||
|
||||
@@ -374,21 +372,20 @@ public class Control extends Module{
|
||||
}
|
||||
|
||||
public boolean hasItem(ItemStack req){
|
||||
return items.get(req.item, 0) >= req.amount;
|
||||
return items[req.item.ordinal()] >= req.amount;
|
||||
}
|
||||
|
||||
public void removeItem(ItemStack req){
|
||||
items.put(req.item, items.get(req.item, 0)-req.amount);
|
||||
items[req.item.ordinal()] -= req.amount;
|
||||
shouldUpdateItems = true;
|
||||
}
|
||||
|
||||
public void removeItems(ItemStack... reqs){
|
||||
for(ItemStack req : reqs)
|
||||
items.put(req.item, items.get(req.item, 0)-req.amount);
|
||||
shouldUpdateItems = true;
|
||||
removeItem(req);
|
||||
}
|
||||
|
||||
public ObjectMap<Item, Integer> getItems(){
|
||||
public int[] getItems(){
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.input.AndroidInput;
|
||||
import io.anuke.mindustry.input.Input;
|
||||
import io.anuke.mindustry.input.PlaceMode;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.SpawnPoint;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
@@ -161,7 +162,8 @@ public class Renderer extends RendererModule{
|
||||
Graphics.surface();
|
||||
|
||||
Profiler.begin("blockDraw");
|
||||
renderTiles();
|
||||
drawFloor();
|
||||
drawBlocks(false);
|
||||
Profiler.end("blockDraw");
|
||||
|
||||
Profiler.begin("entityDraw");
|
||||
@@ -174,6 +176,8 @@ public class Renderer extends RendererModule{
|
||||
Entities.draw(control.bulletGroup);
|
||||
|
||||
Profiler.end("entityDraw");
|
||||
|
||||
drawBlocks(true);
|
||||
|
||||
drawShield();
|
||||
|
||||
@@ -250,7 +254,7 @@ public class Renderer extends RendererModule{
|
||||
shieldHits.addAll(x, y, 0f);
|
||||
}
|
||||
|
||||
void renderTiles(){
|
||||
void drawFloor(){
|
||||
int chunksx = world.width() / chunksize, chunksy = world.height() / chunksize;
|
||||
|
||||
//render the entire map
|
||||
@@ -281,6 +285,27 @@ public class Renderer extends RendererModule{
|
||||
if(Vars.showPaths && Vars.debug){
|
||||
drawPaths();
|
||||
}
|
||||
|
||||
if(Vars.debug && Vars.debugChunks){
|
||||
Draw.color(Color.YELLOW);
|
||||
Draw.thick(1f);
|
||||
for(int x = -crangex; x <= crangex; x++){
|
||||
for(int y = -crangey; y <= crangey; y++){
|
||||
int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x;
|
||||
int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y;
|
||||
|
||||
if(!Mathf.inBounds(worldx, worldy, cache))
|
||||
continue;
|
||||
Draw.linerect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize);
|
||||
}
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void drawBlocks(boolean top){
|
||||
int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1;
|
||||
int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1;
|
||||
|
||||
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2) + 2;
|
||||
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2) + 2;
|
||||
@@ -288,16 +313,25 @@ public class Renderer extends RendererModule{
|
||||
boolean noshadows = Settings.getBool("noshadows");
|
||||
|
||||
boolean drawTiles = Settings.getBool("drawblocks");
|
||||
|
||||
if(!drawTiles) return;
|
||||
|
||||
Layer[] layers = Layer.values();
|
||||
|
||||
int start = top ? 4 : (noshadows ? 1 : 0);
|
||||
int end = top ? 4 + layers.length-1 : 4;
|
||||
|
||||
//0 = shadows
|
||||
//1 = cache blocks
|
||||
//2 = normal blocks
|
||||
//3 = over blocks
|
||||
for(int l = (noshadows ? 1 : 0); l < (drawTiles ? 4 : 0); l++){
|
||||
//3+ = layers
|
||||
for(int l = start; l < end; l++){
|
||||
if(l == 0){
|
||||
Graphics.surface("shadow");
|
||||
}
|
||||
|
||||
Layer layer = l >= 3 ? layers[l - 3] : null;
|
||||
|
||||
boolean expand = l >= 2;
|
||||
int expandr = (expand ? 4 : 0);
|
||||
|
||||
@@ -322,8 +356,12 @@ public class Renderer extends RendererModule{
|
||||
!expanded || tile.block().expanded){
|
||||
if(l == 2){
|
||||
tile.block().draw(tile);
|
||||
}else if(l == 3){
|
||||
tile.block().drawOver(tile);
|
||||
}else{
|
||||
if(tile.block().layer == layer)
|
||||
tile.block().drawLayer(tile);
|
||||
|
||||
if(tile.block().layer2 == layer)
|
||||
tile.block().drawLayer2(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,22 +375,6 @@ public class Renderer extends RendererModule{
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
if(Vars.debug && Vars.debugChunks){
|
||||
Draw.color(Color.YELLOW);
|
||||
Draw.thick(1f);
|
||||
for(int x = -crangex; x <= crangex; x++){
|
||||
for(int y = -crangey; y <= crangey; y++){
|
||||
int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x;
|
||||
int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y;
|
||||
|
||||
if(!Mathf.inBounds(worldx, worldy, cache))
|
||||
continue;
|
||||
Draw.linerect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize);
|
||||
}
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void drawCache(int layer, int crangex, int crangey){
|
||||
@@ -525,7 +547,7 @@ public class Renderer extends RendererModule{
|
||||
if(target.entity != null)
|
||||
drawHealth(target.entity.x + offset.x, target.entity.y - 3f - target.block().height / 2f * Vars.tilesize + offset.y, target.entity.health, target.entity.maxhealth);
|
||||
|
||||
target.block().drawPixelOverlay(target);
|
||||
target.block().drawSelect(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@ import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.*;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
@@ -24,7 +22,7 @@ import io.anuke.ucore.noise.Simplex;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class EditorControl extends Module{
|
||||
private ObjectMap<Block, Integer> colors = new ObjectMap<>();
|
||||
private ObjectIntMap<Block> colors = new ObjectIntMap<>();
|
||||
Pixmap pixmap;
|
||||
Texture texture;
|
||||
Simplex sim = new Simplex();
|
||||
@@ -56,8 +54,9 @@ public class EditorControl extends Module{
|
||||
};
|
||||
|
||||
public EditorControl() {
|
||||
|
||||
for(int key : Generator.colors.keys()){
|
||||
IntMap.Keys keys = Generator.colors.keys();
|
||||
|
||||
for(int key = keys.next(); keys.hasNext; key = keys.next()){
|
||||
colors.put(Generator.colors.get(key), key);
|
||||
}
|
||||
loadMap(map);
|
||||
@@ -119,7 +118,7 @@ public class EditorControl extends Module{
|
||||
|
||||
Block block = noise > 0.6 ? Blocks.stoneblock : Blocks.stone;
|
||||
|
||||
pixmap.drawPixel(x, y, colors.get(block));
|
||||
pixmap.drawPixel(x, y, colors.get(block, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,7 +253,7 @@ public class EditorControl extends Module{
|
||||
}
|
||||
}
|
||||
|
||||
pixmap.drawPixel(x, y, colors.get(block));
|
||||
pixmap.drawPixel(x, y, colors.get(block, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.entities.*;
|
||||
import io.anuke.ucore.entities.BulletEntity;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Bullet extends BulletEntity{
|
||||
@@ -76,7 +78,7 @@ public class Bullet extends BulletEntity{
|
||||
|
||||
@Override
|
||||
public Bullet add(){
|
||||
return super.add(Entities.getGroup(Bullet.class));
|
||||
return super.add(Vars.control.bulletGroup);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
@@ -16,14 +14,13 @@ import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
import io.anuke.mindustry.world.blocks.types.Wall;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
|
||||
public class TileEntity extends Entity{
|
||||
public Tile tile;
|
||||
public ObjectIntMap<Item> items = new ObjectIntMap<>();
|
||||
public int[] items = new int[Item.values().length];
|
||||
public Timer timer;
|
||||
public int maxhealth, health;
|
||||
public boolean dead = false;
|
||||
@@ -99,34 +96,34 @@ public class TileEntity extends Entity{
|
||||
|
||||
public int totalItems(){
|
||||
int sum = 0;
|
||||
for(Item item : Item.values()){
|
||||
sum += items.get(item, 0);
|
||||
for(int i = 0; i < items.length; i ++){
|
||||
sum += items[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public int getItem(Item item){
|
||||
return items.get(item, 0);
|
||||
return items[item.ordinal()];
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item){
|
||||
return items.get(item, 0) > 0;
|
||||
return getItem(item) > 0;
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item, int amount){
|
||||
return items.get(item, 0) >= amount;
|
||||
return getItem(item) >= amount;
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
items.put(item, items.get(item, 0) + amount);
|
||||
items[item.ordinal()] += amount;
|
||||
}
|
||||
|
||||
public void removeItem(Item item, int amount){
|
||||
items.put(item, items.get(item, 0) - amount);
|
||||
items[item.ordinal()] -= amount;;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity add(){
|
||||
return add(Entities.getGroup(TileEntity.class));
|
||||
return add(Vars.control.tileGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DamageArea{
|
||||
public static void damage(boolean enemies, float x, float y, float radius, int damage){
|
||||
|
||||
if(enemies){
|
||||
Entities.getNearby(Entities.getGroup(Enemy.class), x, y, radius*2, entity->{
|
||||
Entities.getNearby(Vars.control.enemyGroup, x, y, radius*2, entity->{
|
||||
if(entity instanceof Enemy){
|
||||
Enemy enemy = (Enemy)entity;
|
||||
if(enemy.distanceTo(x, y) > radius){
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.entities.effect;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
|
||||
import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.ShieldBlock;
|
||||
@@ -55,7 +55,7 @@ public class Shield extends Entity{
|
||||
|
||||
ShieldBlock block = (ShieldBlock)tile.block();
|
||||
|
||||
Entities.getNearby(Entities.getGroup(Bullet.class), x, y, block.shieldRadius * 2*uptime + 10, entity->{
|
||||
Entities.getNearby(Vars.control.bulletGroup, x, y, block.shieldRadius * 2*uptime + 10, entity->{
|
||||
BulletEntity bullet = (BulletEntity)entity;
|
||||
if((bullet.owner instanceof Enemy || hitPlayers)){
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -41,7 +42,7 @@ public class TeslaOrb extends Entity{
|
||||
break;
|
||||
}
|
||||
|
||||
Array<SolidEntity> enemies = Entities.getNearby(Entities.getGroup(Enemy.class), curx, cury, range*2f);
|
||||
Array<SolidEntity> enemies = Entities.getNearby(Vars.control.enemyGroup, curx, cury, range*2f);
|
||||
|
||||
for(SolidEntity entity : enemies){
|
||||
if(entity.distanceTo(curx, cury) < range && !hit.contains((Enemy)entity)){
|
||||
|
||||
@@ -82,7 +82,7 @@ public class Enemy extends DestructibleEntity{
|
||||
float attractRange = avoidRange + 7f;
|
||||
float avoidSpeed = this.speed/2.7f;
|
||||
|
||||
Entities.getNearby(Entities.getGroup(Enemy.class), x, y, range, other -> {
|
||||
Entities.getNearby(Vars.control.enemyGroup, x, y, range, other -> {
|
||||
Enemy enemy = (Enemy)other;
|
||||
float dst = other.distanceTo(this);
|
||||
if(other == this)
|
||||
@@ -268,6 +268,6 @@ public class Enemy extends DestructibleEntity{
|
||||
|
||||
@Override
|
||||
public <T extends Entity> T add(){
|
||||
return (T) add(Entities.getGroup(Enemy.class));
|
||||
return (T) add(Vars.control.enemyGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.entities.enemies;
|
||||
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.effect.Shaders;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
@@ -31,7 +32,7 @@ public class HealerEnemy extends Enemy{
|
||||
@Override
|
||||
void updateTargeting(boolean nearCore){
|
||||
if(Timers.get(this, "target", 15)){
|
||||
target = Entities.getClosest(Entities.getGroup(Enemy.class),
|
||||
target = Entities.getClosest(Vars.control.enemyGroup,
|
||||
x, y, range, e -> e instanceof Enemy && e != this && ((Enemy)e).healthfrac() < 1f);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import static io.anuke.mindustry.Vars.android;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
@@ -201,18 +202,29 @@ public class SaveIO{
|
||||
|
||||
//--INVENTORY--
|
||||
|
||||
stream.writeByte(Vars.control.getItems().size); //amount of items
|
||||
int l = Vars.control.getItems().length;
|
||||
int itemsize = 0;
|
||||
|
||||
for(Item item : Vars.control.getItems().keys()){
|
||||
stream.writeByte(item.ordinal()); //item ID
|
||||
stream.writeInt(Vars.control.getAmount(item)); //item amount
|
||||
for(int i = 0; i < l; i ++){
|
||||
if(Vars.control.getItems()[i] > 0){
|
||||
itemsize ++;
|
||||
}
|
||||
}
|
||||
|
||||
stream.writeByte(itemsize); //amount of items
|
||||
|
||||
for(int i = 0; i < l; i ++){
|
||||
if(Vars.control.getItems()[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(Vars.control.getItems()[i]); //item amount
|
||||
}
|
||||
}
|
||||
|
||||
//--ENEMIES--
|
||||
|
||||
int totalEnemies = 0;
|
||||
|
||||
for(Enemy entity : Entities.get(Enemy.class)){
|
||||
for(Enemy entity : Vars.control.enemyGroup.all()){
|
||||
if(idEnemies.containsKey(entity.getClass())){
|
||||
totalEnemies ++;
|
||||
}
|
||||
@@ -220,7 +232,7 @@ public class SaveIO{
|
||||
|
||||
stream.writeInt(totalEnemies); //enemy amount
|
||||
|
||||
for(Enemy enemy : Entities.get(Enemy.class)){
|
||||
for(Enemy enemy : Vars.control.enemyGroup.all()){
|
||||
if(idEnemies.containsKey(enemy.getClass())){
|
||||
stream.writeByte(idEnemies.get(enemy.getClass())); //type
|
||||
stream.writeByte(enemy.spawn); //lane
|
||||
@@ -265,11 +277,17 @@ public class SaveIO{
|
||||
if(tile.entity != null){
|
||||
stream.writeByte(tile.getRotation()); //rotation
|
||||
stream.writeInt(tile.entity.health); //health
|
||||
stream.writeByte(tile.entity.items.size); //amount of items
|
||||
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(Item item : tile.entity.items.keys()){
|
||||
stream.writeByte(item.ordinal()); //item ID
|
||||
stream.writeInt(tile.entity.items.get(item, 0)); //item amount
|
||||
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);
|
||||
@@ -331,12 +349,12 @@ public class SaveIO{
|
||||
|
||||
int totalItems = stream.readByte();
|
||||
|
||||
Vars.control.getItems().clear();
|
||||
Arrays.fill(Vars.control.getItems(), 0);
|
||||
|
||||
for(int i = 0; i < totalItems; i ++){
|
||||
Item item = itemEnums[stream.readByte()];
|
||||
int amount = stream.readInt();
|
||||
Vars.control.getItems().put(item, amount);
|
||||
Vars.control.getItems()[item.ordinal()] = amount;
|
||||
}
|
||||
|
||||
Vars.ui.updateItems();
|
||||
@@ -364,7 +382,7 @@ public class SaveIO{
|
||||
enemy.x = x;
|
||||
enemy.y = y;
|
||||
enemy.tier = tier;
|
||||
enemy.add(Entities.getGroup(Enemy.class));
|
||||
enemy.add(Vars.control.enemyGroup);
|
||||
enemiesToUpdate.add(enemy);
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
@@ -420,7 +438,7 @@ public class SaveIO{
|
||||
for(int j = 0; j < items; j ++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
tile.entity.items.put(itemEnums[itemid], itemamount);
|
||||
tile.entity.items[itemid] = itemamount;
|
||||
}
|
||||
|
||||
tile.entity.read(stream);
|
||||
|
||||
@@ -4,20 +4,16 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.GameMode;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.function.StringSupplier;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.builders.imagebutton;
|
||||
@@ -34,7 +30,6 @@ import io.anuke.ucore.util.Profiler;
|
||||
public class HudFragment implements Fragment{
|
||||
private Table itemtable, respawntable;
|
||||
private Cell<Table> itemcell;
|
||||
private Array<Item> tempItems = new Array<>();
|
||||
|
||||
public void build(){
|
||||
//menu at top left
|
||||
@@ -142,9 +137,9 @@ public class HudFragment implements Fragment{
|
||||
new table(){{
|
||||
abottom();
|
||||
aleft();
|
||||
new label((StringSupplier)()->"[purple]tiles: " + Entities.getGroup(TileEntity.class).amount()).left();
|
||||
new label((StringSupplier)()->"[purple]tiles: " + Vars.control.tileGroup.amount()).left();
|
||||
row();
|
||||
new label((StringSupplier)()->"[purple]enemies: " + Entities.getGroup(Enemy.class).amount()).left();
|
||||
new label((StringSupplier)()->"[purple]enemies: " + Vars.control.enemyGroup.amount()).left();
|
||||
row();
|
||||
new label((StringSupplier)()->"[orange]noclip: " + Vars.noclip).left();
|
||||
row();
|
||||
@@ -216,19 +211,15 @@ public class HudFragment implements Fragment{
|
||||
return;
|
||||
}
|
||||
|
||||
tempItems.clear();
|
||||
for(Item item : control.getItems().keys()){
|
||||
tempItems.add(item);
|
||||
}
|
||||
tempItems.sort();
|
||||
Item[] items = Item.values();
|
||||
|
||||
for(Item stack : tempItems){
|
||||
int amount = control.getAmount(stack);
|
||||
for(int i = 0; i < control.getItems().length; i ++){
|
||||
int amount = control.getItems()[i];
|
||||
String formatted = Mindustry.formatter.format(amount);
|
||||
if(amount > 99999999){
|
||||
formatted = "inf";
|
||||
}
|
||||
Image image = new Image(Draw.region("icon-" + stack.name()));
|
||||
Image image = new Image(Draw.region("icon-" + items[i]));
|
||||
Label label = new Label(formatted);
|
||||
label.setFontScale(fontscale*1.5f);
|
||||
itemtable.add(image).size(8*3).units(Unit.dp);
|
||||
|
||||
@@ -71,6 +71,10 @@ public class Block{
|
||||
public boolean expanded = false;
|
||||
/**Max of timers used.*/
|
||||
public int timers = 0;
|
||||
/**Layer to draw extra stuff on.*/
|
||||
public Layer layer = Layer.overlay;
|
||||
/**Extra layer to draw extra extra stuff on.*/
|
||||
public Layer layer2 = Layer.overlay;
|
||||
|
||||
public Block(String name) {
|
||||
blocks.add(this);
|
||||
@@ -81,8 +85,10 @@ public class Block{
|
||||
this.id = lastid++;
|
||||
}
|
||||
|
||||
public void drawOver(Tile tile){}
|
||||
public void drawPixelOverlay(Tile tile){}
|
||||
|
||||
public void drawLayer(Tile tile){}
|
||||
public void drawLayer2(Tile tile){}
|
||||
public void drawSelect(Tile tile){}
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){}
|
||||
public void postInit(){}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.world;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.TargetEnemy;
|
||||
@@ -19,7 +19,7 @@ public class Generator{
|
||||
static final int spawn = Color.rgba8888(Color.RED);
|
||||
static final int start = Color.rgba8888(Color.GREEN);
|
||||
|
||||
public static ObjectMap<Integer, Block> colors = map(
|
||||
public static IntMap<Block> colors = map(
|
||||
Hue.rgb(80, 150, 90), Blocks.grass,
|
||||
Hue.rgb(90, 180, 100), Blocks.grassblock,
|
||||
Hue.rgb(80, 110, 180), Blocks.water,
|
||||
@@ -130,9 +130,9 @@ public class Generator{
|
||||
}
|
||||
}
|
||||
|
||||
private static ObjectMap<Integer, Block> map(Object...objects){
|
||||
private static IntMap<Block> map(Object...objects){
|
||||
|
||||
ObjectMap<Integer, Block> out = new ObjectMap<>();
|
||||
IntMap<Block> out = new IntMap<>();
|
||||
|
||||
for(int i = 0; i < objects.length; i += 2){
|
||||
out.put(Hue.rgb((Color)objects[i]), (Block)objects[i+1]);
|
||||
|
||||
12
core/src/io/anuke/mindustry/world/Layer.java
Normal file
12
core/src/io/anuke/mindustry/world/Layer.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package io.anuke.mindustry.world;
|
||||
|
||||
public enum Layer{
|
||||
/**First overlay. Stuff like conveyor items.*/
|
||||
overlay,
|
||||
/**"High" blocks, like turrets.*/
|
||||
turret,
|
||||
/**Power lasers.*/
|
||||
power,
|
||||
/**Extra lasers, like healing turrets.*/
|
||||
laser;
|
||||
}
|
||||
@@ -131,7 +131,11 @@ public class Tile{
|
||||
}
|
||||
|
||||
public void setDump(byte dump){
|
||||
data = Bits.packShort(getRotation(), dump);
|
||||
data = Bits.packShort(getRotation(), Bits.packByte(dump, getExtra()));
|
||||
}
|
||||
|
||||
public void setExtra(byte extra){
|
||||
data = Bits.packShort(getRotation(), Bits.packByte(getDump(), extra));
|
||||
}
|
||||
|
||||
public byte getRotation(){
|
||||
@@ -139,7 +143,11 @@ public class Tile{
|
||||
}
|
||||
|
||||
public byte getDump(){
|
||||
return Bits.getRightByte(data);
|
||||
return Bits.getLeftByte(Bits.getRightByte(data));
|
||||
}
|
||||
|
||||
public byte getExtra(){
|
||||
return Bits.getRightByte(Bits.getRightByte(data));
|
||||
}
|
||||
|
||||
public boolean passable(){
|
||||
|
||||
@@ -12,7 +12,6 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.ai.Pathfind;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Recipe;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
@@ -276,7 +275,7 @@ public class World extends Module{
|
||||
Vector2 offset = type.getPlaceOffset();
|
||||
Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize);
|
||||
|
||||
for(SolidEntity e : Entities.getNearby(Entities.getGroup(Enemy.class), x * tilesize, y * tilesize, tilesize * 2f)){
|
||||
for(SolidEntity e : Entities.getNearby(control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
||||
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
||||
|
||||
if(Tmp.r2.overlaps(rect)){
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class PowerBlock extends Block implements PowerAcceptor{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
public void drawSelect(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
float fract = (float)entity.power / powerCapacity;
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
@@ -78,7 +77,7 @@ public class Door extends Wall implements Configurable{
|
||||
Vector2 offset = type.getPlaceOffset();
|
||||
Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize);
|
||||
|
||||
for(SolidEntity e : Entities.getNearby(Entities.getGroup(Enemy.class), x * tilesize, y * tilesize, tilesize * 2f)){
|
||||
for(SolidEntity e : Entities.getNearby(Vars.control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
||||
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
||||
|
||||
if(Tmp.r2.overlaps(rect)){
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.math.MathUtils;
|
||||
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -23,6 +24,7 @@ public class LaserTurret extends PowerTurret{
|
||||
public LaserTurret(String name) {
|
||||
super(name);
|
||||
shootsound = null;
|
||||
layer2 = Layer.laser;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,15 +39,16 @@ public class LaserTurret extends PowerTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){
|
||||
public void drawLayer2(Tile tile){
|
||||
TurretEntity entity = tile.entity();
|
||||
|
||||
if(entity.target != null &&
|
||||
Angles.angleDist(entity.rotation, Angles.angle(tile.worldx(), tile.worldy(), entity.target.x, entity.target.y)) <= cone){
|
||||
Angles.translation(entity.rotation, 4f);
|
||||
|
||||
float x = tile.worldx(), y = tile.worldy();
|
||||
float x = tile.worldx() + Angles.x(), y = tile.worldy() + Angles.y();
|
||||
float x2 = entity.target.x, y2 = entity.target.y;
|
||||
|
||||
|
||||
float lighten = (MathUtils.sin(Timers.time()/1.2f) + 1f) / 10f;
|
||||
|
||||
Draw.color(Tmp.c1.set(beamColor).mul(1f + lighten, 1f + lighten, 1f + lighten, 1f));
|
||||
@@ -63,7 +66,5 @@ public class LaserTurret extends PowerTurret{
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
|
||||
super.drawOver(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class PowerTurret extends Turret implements PowerAcceptor{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
public void drawSelect(Tile tile){
|
||||
Vector2 offset = getPlaceOffset();
|
||||
|
||||
Draw.color("green");
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -18,6 +19,7 @@ public class RepairTurret extends PowerTurret{
|
||||
public RepairTurret(String name) {
|
||||
super(name);
|
||||
powerUsed = 0.1f;
|
||||
layer2 = Layer.laser;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +68,7 @@ public class RepairTurret extends PowerTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
public void drawSelect(Tile tile){
|
||||
Draw.color("green");
|
||||
Draw.dashCircle(tile.worldx(), tile.worldy(), range);
|
||||
Draw.reset();
|
||||
@@ -75,13 +77,14 @@ public class RepairTurret extends PowerTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){
|
||||
public void drawLayer2(Tile tile){
|
||||
PowerTurretEntity entity = tile.entity();
|
||||
|
||||
if(entity.power >= powerUsed && entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){
|
||||
Tile targetTile = entity.blockTarget.tile;
|
||||
Vector2 offset = targetTile.block().getPlaceOffset();
|
||||
float x = tile.worldx(), y = tile.worldy();
|
||||
Angles.translation(entity.rotation, 4f);
|
||||
float x = tile.worldx() + Angles.x(), y = tile.worldy() + Angles.y();
|
||||
float x2 = entity.blockTarget.x + offset.x, y2 = entity.blockTarget.y + offset.y;
|
||||
|
||||
Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));
|
||||
@@ -97,7 +100,5 @@ public class RepairTurret extends PowerTurret{
|
||||
Draw.rect("circle", x2, y2, 5f, 5f);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
Draw.rect(name(), tile.worldx(), tile.worldy(), entity.rotation - 90);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -52,6 +53,7 @@ public class Turret extends Block{
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
layer = Layer.turret;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +92,7 @@ public class Turret extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){
|
||||
public void drawLayer(Tile tile){
|
||||
TurretEntity entity = tile.entity();
|
||||
Vector2 offset = getPlaceOffset();
|
||||
|
||||
@@ -102,7 +104,7 @@ public class Turret extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
public void drawSelect(Tile tile){
|
||||
Vector2 offset = getPlaceOffset();
|
||||
|
||||
Draw.color("green");
|
||||
@@ -145,7 +147,7 @@ public class Turret extends Block{
|
||||
if(hasAmmo(tile) || (Vars.debug && Vars.infiniteAmmo)){
|
||||
|
||||
if(entity.timer.get(timerTarget, targetInterval)){
|
||||
entity.target = (Enemy)Entities.getClosest(Entities.getGroup(Enemy.class),
|
||||
entity.target = (Enemy)Entities.getClosest(Vars.control.enemyGroup,
|
||||
tile.worldx(), tile.worldy(), range, e-> e instanceof Enemy && !((Enemy)e).isDead());
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.badlogic.gdx.utils.IntArray;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -30,6 +31,7 @@ public class Conveyor extends Block{
|
||||
super(name);
|
||||
rotate = true;
|
||||
update = true;
|
||||
layer = Layer.overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,12 +47,18 @@ public class Conveyor extends Block{
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
ConveyorEntity entity = tile.entity();
|
||||
|
||||
byte rotation = tile.getRotation();
|
||||
|
||||
Draw.rect(name() +
|
||||
(Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed && acceptItem(Item.stone, tile, null) ? "" : "move"), tile.worldx(), tile.worldy(), rotation * 90);
|
||||
(Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed && acceptItem(Item.stone, tile, null) ? "" : "move"),
|
||||
tile.worldx(), tile.worldy(), rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLayer(Tile tile){
|
||||
ConveyorEntity entity = tile.entity();
|
||||
|
||||
byte rotation = tile.getRotation();
|
||||
|
||||
for(int i = 0; i < entity.convey.size; i ++){
|
||||
ItemPos pos = pos1.set(entity.convey.get(i));
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
@@ -9,8 +7,6 @@ import io.anuke.ucore.core.Draw;
|
||||
|
||||
public class LiquidRouter extends LiquidBlock{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
private ObjectMap<Tile, Byte> lastmap = new ObjectMap<>();
|
||||
|
||||
public LiquidRouter(String name) {
|
||||
super(name);
|
||||
@@ -23,7 +19,7 @@ public class LiquidRouter extends LiquidBlock{
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerDump, 2) && entity.liquidAmount > 0){
|
||||
if(lastmap.get(tile, (byte)-1) != tile.getRotation()){
|
||||
if(tile.getExtra() != tile.getRotation()){
|
||||
tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]);
|
||||
}
|
||||
|
||||
@@ -34,7 +30,7 @@ public class LiquidRouter extends LiquidBlock{
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
super.handleLiquid(tile, source, liquid, amount);
|
||||
lastmap.put(tile, (byte)tile.relativeTo(source.x, source.y));
|
||||
tile.setExtra((byte)tile.relativeTo(source.x, source.y));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,8 +23,8 @@ public class PowerBooster extends Generator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
super.drawPixelOverlay(tile);
|
||||
public void drawSelect(Tile tile){
|
||||
super.drawSelect(tile);
|
||||
|
||||
Draw.color("yellow");
|
||||
Draw.dashCircle(tile.worldx(), tile.worldy(), powerRange * Vars.tilesize);
|
||||
@@ -51,8 +51,7 @@ public class PowerBooster extends Generator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){
|
||||
}
|
||||
public void drawLayer(Tile tile){}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
@@ -13,7 +12,6 @@ import io.anuke.ucore.util.Mathf;
|
||||
public class Router extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
private ObjectMap<Tile, Byte> lastmap = new ObjectMap<>();
|
||||
int capacity = 20;
|
||||
|
||||
public Router(String name) {
|
||||
@@ -36,7 +34,7 @@ public class Router extends Block{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
if(tile.entity.timer.get(timerDump, 2) && tile.entity.totalItems() > 0){
|
||||
if(lastmap.get(tile, (byte)-1) != tile.getRotation()
|
||||
if(tile.getExtra() != tile.getRotation()
|
||||
|| Mathf.chance(0.3)){ //sometimes dump backwards at a 1/4 chance... this somehow works?
|
||||
tryDump(tile, tile.getRotation(), null);
|
||||
}
|
||||
@@ -48,7 +46,7 @@ public class Router extends Block{
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
super.handleItem(item, tile, source);
|
||||
lastmap.put(tile, (byte)tile.relativeTo(source.x, source.y));
|
||||
tile.setExtra((byte)tile.relativeTo(source.x, source.y));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,7 +56,7 @@ public class Router extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
public void drawSelect(Tile tile){
|
||||
|
||||
float fract = (float)tile.entity.totalItems()/capacity;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -27,6 +28,7 @@ public class Drill extends Block{
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
layer = Layer.overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,7 +43,7 @@ public class Drill extends Block{
|
||||
TileEntity entity = tile.entity;
|
||||
|
||||
if((tile.floor() == resource || (resource.drops.equals(tile.floor().drops)))
|
||||
&& entity.timer.get(timerDrill, 60 * time) && tile.entity.totalItems() < capacity){
|
||||
&& entity.timer.get(timerDrill, 60 * time) && tile.entity.getItem(result) < capacity){
|
||||
offloadNear(tile, result);
|
||||
Effects.effect(drillEffect, tile.worldx(), tile.worldy());
|
||||
}
|
||||
@@ -52,7 +54,7 @@ public class Drill extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){
|
||||
public void drawLayer(Tile tile){
|
||||
if(tile.floor() != resource && resource != null && !(resource.drops.equals(tile.floor().drops))){
|
||||
Draw.colorl(0.85f + Mathf.absin(Timers.time(), 6f, 0.15f));
|
||||
Draw.rect("cross", tile.worldx(), tile.worldy());
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.effect.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;
|
||||
@@ -32,6 +33,7 @@ public class Generator extends PowerBlock{
|
||||
public Generator(String name){
|
||||
super(name);
|
||||
expanded = true;
|
||||
layer = Layer.power;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,8 +51,8 @@ public class Generator extends PowerBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
super.drawPixelOverlay(tile);
|
||||
public void drawSelect(Tile tile){
|
||||
super.drawSelect(tile);
|
||||
|
||||
if(drawRangeOverlay){
|
||||
int rotation = tile.getRotation();
|
||||
@@ -124,7 +126,7 @@ public class Generator extends PowerBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){
|
||||
public void drawLayer(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
for(int i = 0; i < laserDirections; i++){
|
||||
|
||||
@@ -54,18 +54,18 @@ public class ItemPowerGenerator extends Generator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
super.drawPixelOverlay(tile);
|
||||
public void drawSelect(Tile tile){
|
||||
super.drawSelect(tile);
|
||||
|
||||
TileEntity entity = tile.entity;
|
||||
|
||||
//TODO maybe don't draw it due to clutter
|
||||
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 10, (float)entity.totalItems() / itemCapacity);
|
||||
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 10, (float)entity.getItem(generateItem) / itemCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return item == generateItem && tile.entity.totalItems() < itemCapacity;
|
||||
return item == generateItem && tile.entity.getItem(generateItem) < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,10 +81,10 @@ public class LiquidCrafter extends LiquidBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
public void drawSelect(Tile tile){
|
||||
if(input == null) return;
|
||||
|
||||
float fract = (float)tile.entity.items.get(input, 0) / itemCapacity;
|
||||
float fract = (float)tile.entity.getItem(input) / itemCapacity;
|
||||
|
||||
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 6, fract);
|
||||
}
|
||||
@@ -97,7 +97,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.items.get(item, 0) < itemCapacity;
|
||||
return input != null && item == input && entity.getItem(input) < itemCapacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ public class LiquidItemPowerGenerator extends LiquidPowerGenerator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
super.drawPixelOverlay(tile);
|
||||
public void drawSelect(Tile tile){
|
||||
super.drawSelect(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);
|
||||
offset.y + height*Vars.tilesize/2f, (float)entity.getItem(generateItem) / itemCapacity);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class LiquidItemPowerGenerator extends LiquidPowerGenerator{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return item == generateItem && tile.entity.totalItems() < itemCapacity;
|
||||
return item == generateItem && tile.entity.getItem(generateItem) < itemCapacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -136,8 +136,8 @@ public class NuclearReactor extends LiquidItemPowerGenerator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
super.drawPixelOverlay(tile);
|
||||
public void drawSelect(Tile tile){
|
||||
super.drawSelect(tile);
|
||||
|
||||
NuclearReactorEntity entity = tile.entity();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ 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.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
@@ -21,6 +22,7 @@ public class Pump extends LiquidBlock{
|
||||
super(name);
|
||||
rotate = false;
|
||||
solid = true;
|
||||
layer = Layer.overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,7 +51,7 @@ public class Pump extends LiquidBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){
|
||||
public void drawLayer(Tile tile){
|
||||
if(tile.floor().liquidDrop == null){
|
||||
Draw.colorl(0.85f + Mathf.absin(Timers.time(), 6f, 0.15f));
|
||||
Draw.rect("cross", tile.worldx(), tile.worldy());
|
||||
|
||||
Reference in New Issue
Block a user