Optimized conveyors and all timer blocks, edited laser FX
This commit is contained in:
@@ -8,6 +8,7 @@ import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.graphics.*;
|
||||
import com.badlogic.gdx.graphics.profiling.GLProfiler;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
@@ -47,8 +48,14 @@ public class Renderer extends RendererModule{
|
||||
public Renderer() {
|
||||
Core.cameraScale = baseCameraScale;
|
||||
Effects.setEffectProvider((name, color, x, y, rotation) -> {
|
||||
if(Settings.getBool("effects"))
|
||||
new EffectEntity(name, color, rotation).set(x, y).add();
|
||||
if(Settings.getBool("effects")){
|
||||
Rectangle view = Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight)
|
||||
.setCenter(camera.position.x, camera.position.y);
|
||||
Rectangle pos = Tmp.r2.setSize(name.size).setCenter(x, y);
|
||||
if(view.overlaps(pos)){
|
||||
new EffectEntity(name, color, rotation).set(x, y).add();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
@@ -19,10 +19,12 @@ 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 ObjectMap<Item, Integer> items = new ObjectMap<>();
|
||||
public ObjectIntMap<Item> items = new ObjectIntMap<>();
|
||||
public Timer timer;
|
||||
public int maxhealth, health;
|
||||
public boolean dead = false;
|
||||
public boolean added;
|
||||
@@ -37,8 +39,10 @@ public class TileEntity extends Entity{
|
||||
maxhealth = tile.block().health;
|
||||
health = maxhealth;
|
||||
|
||||
timer = new Timer(tile.block().timers);
|
||||
|
||||
if(added){
|
||||
add(Entities.getGroup(TileEntity.class));
|
||||
add();
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -79,12 +83,12 @@ public class TileEntity extends Entity{
|
||||
}
|
||||
|
||||
public boolean collide(Bullet other){
|
||||
return other.owner instanceof Enemy; //TODO
|
||||
return other.owner instanceof Enemy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(health != 0 && !(tile.block() instanceof Wall) &&
|
||||
if(health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
|
||||
Mathf.chance(0.009f*Timers.delta()*(1f-(float)health/maxhealth))){
|
||||
|
||||
Effects.effect(Fx.smoke, x+Mathf.range(4), y+Mathf.range(4));
|
||||
@@ -120,4 +124,9 @@ public class TileEntity extends Entity{
|
||||
public void removeItem(Item item, int amount){
|
||||
items.put(item, items.get(item, 0) - amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity add(){
|
||||
return add(Entities.getGroup(TileEntity.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class WaveCreator{
|
||||
after = 12;
|
||||
amount = 3;
|
||||
spacing = 5;
|
||||
scaling = 2;
|
||||
scaling = 3;
|
||||
}},
|
||||
|
||||
new EnemySpawn(EmpEnemy.class){{
|
||||
@@ -107,7 +107,7 @@ public class WaveCreator{
|
||||
new EnemySpawn(HealerEnemy.class){{
|
||||
after = 16;
|
||||
spacing = 5;
|
||||
scaling = 1;
|
||||
scaling = 2;
|
||||
amount = 2;
|
||||
}},
|
||||
//end boss wave
|
||||
@@ -117,14 +117,14 @@ public class WaveCreator{
|
||||
after = 16 + 5;
|
||||
amount = 1;
|
||||
spacing = 5;
|
||||
scaling = 1;
|
||||
scaling = 2;
|
||||
}},
|
||||
|
||||
new EnemySpawn(EmpEnemy.class){{
|
||||
after = 16 + 5;
|
||||
amount = 1;
|
||||
spacing = 5;
|
||||
scaling = 1;
|
||||
scaling = 2;
|
||||
}}
|
||||
//end enchanced boss wave
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class Fx{
|
||||
|
||||
public static final Effect
|
||||
|
||||
generatorexplosion = new Effect(28, e -> {
|
||||
generatorexplosion = new Effect(28, 40f, e -> {
|
||||
Angles.randLenVectors(e.id, 16, 10f + e.ifract()*8f, (x, y)->{
|
||||
float size = e.fract()*12f + 1f;
|
||||
Draw.color(Color.WHITE, lightOrange, e.ifract());
|
||||
@@ -44,7 +44,7 @@ public class Fx{
|
||||
});
|
||||
}),
|
||||
|
||||
nuclearcloud = new Effect(90, e -> {
|
||||
nuclearcloud = new Effect(90, 200f, e -> {
|
||||
Angles.randLenVectors(e.id, 10, e.powfract()*90f, (x, y)->{
|
||||
float size = e.fract()*14f;
|
||||
Draw.color(Color.LIME, Color.GRAY, e.ifract());
|
||||
@@ -106,14 +106,14 @@ public class Fx{
|
||||
Draw.reset();
|
||||
}),
|
||||
|
||||
shockwave = new Effect(10f, e -> {
|
||||
shockwave = new Effect(10f, 80f, e -> {
|
||||
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
|
||||
Draw.thick(e.fract()*2f + 0.2f);
|
||||
Draw.circle(e.x, e.y, e.ifract()*28f);
|
||||
Draw.reset();
|
||||
}),
|
||||
|
||||
nuclearShockwave = new Effect(10f, e -> {
|
||||
nuclearShockwave = new Effect(10f, 200f, e -> {
|
||||
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
|
||||
Draw.thick(e.fract()*3f + 0.2f);
|
||||
Draw.polygon(40, e.x, e.y, e.ifract()*140f);
|
||||
@@ -366,7 +366,7 @@ public class Fx{
|
||||
Draw.reset();
|
||||
}),
|
||||
|
||||
titanExplosion = new Effect(11, e -> {
|
||||
titanExplosion = new Effect(11, 48f, e -> {
|
||||
Draw.thickness(2f*e.fract()+0.5f);
|
||||
Draw.color(Color.WHITE, Color.DARK_GRAY, e.powfract());
|
||||
Draw.circle(e.x, e.y, 5f + e.powfract() * 8f);
|
||||
|
||||
@@ -11,15 +11,15 @@ import io.anuke.mindustry.entities.effect.Shaders;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.*;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
import io.anuke.ucore.util.*;
|
||||
|
||||
public class Enemy extends DestructibleEntity{
|
||||
public final static Color[] tierColors = { Color.valueOf("ffe451"), Color.valueOf("f48e20"), Color.valueOf("ff6757"), Color.valueOf("ff2d86") };
|
||||
public final static int maxtier = 4;
|
||||
public final static float maxIdle = 60*1.5f;
|
||||
|
||||
|
||||
protected int timeid;
|
||||
protected Timer timer = new Timer(5);
|
||||
protected float speed = 0.4f;
|
||||
protected float reload = 32;
|
||||
protected float range = 60;
|
||||
@@ -37,7 +37,7 @@ public class Enemy extends DestructibleEntity{
|
||||
protected boolean stopNearCore = true;
|
||||
protected float mass = 1f;
|
||||
|
||||
public float idletime = 0f;
|
||||
public float idletime = 0f;
|
||||
public int spawn;
|
||||
public int node = -1;
|
||||
public Tile[] path;
|
||||
@@ -45,6 +45,9 @@ public class Enemy extends DestructibleEntity{
|
||||
public float xvelocity, yvelocity;
|
||||
public Entity target;
|
||||
public int tier = 1;
|
||||
|
||||
protected final int timerTarget = timeid ++;
|
||||
protected final int timerReload = timeid ++;
|
||||
|
||||
public Enemy() {
|
||||
hitbox.setSize(5f);
|
||||
@@ -110,7 +113,7 @@ public class Enemy extends DestructibleEntity{
|
||||
target = null;
|
||||
}
|
||||
|
||||
if(Timers.get(this, "target", 15) && !nearCore){
|
||||
if(timer.get(timerTarget, 15) && !nearCore){
|
||||
target = Vars.world.findTileTarget(x, y, null, range, false);
|
||||
|
||||
//no tile found
|
||||
@@ -127,7 +130,7 @@ public class Enemy extends DestructibleEntity{
|
||||
}
|
||||
|
||||
void updateShooting(){
|
||||
if(Timers.get(this, "reload", reload * Vars.multiplier)){
|
||||
if(timer.get(timerReload, reload * Vars.multiplier)){
|
||||
shoot(bullet);
|
||||
if(shootsound != null) Effects.sound(shootsound, this);
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ public class SaveIO{
|
||||
|
||||
for(Item item : tile.entity.items.keys()){
|
||||
stream.writeByte(item.ordinal()); //item ID
|
||||
stream.writeInt(tile.entity.items.get(item)); //item amount
|
||||
stream.writeInt(tile.entity.items.get(item, 0)); //item amount
|
||||
}
|
||||
|
||||
tile.entity.write(stream);
|
||||
|
||||
@@ -37,7 +37,7 @@ public class SaveDialog extends LoadDialog{
|
||||
}
|
||||
|
||||
void save(int slot){
|
||||
Vars.ui.showLoading("[orange]Saving...");
|
||||
Vars.ui.showLoading("[accent]Saving...");
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
hide();
|
||||
|
||||
@@ -10,6 +10,7 @@ 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;
|
||||
@@ -141,6 +142,8 @@ public class HudFragment implements Fragment{
|
||||
new table(){{
|
||||
abottom();
|
||||
aleft();
|
||||
new label((StringSupplier)()->"[purple]tiles: " + Entities.getGroup(TileEntity.class).amount()).left();
|
||||
row();
|
||||
new label((StringSupplier)()->"[purple]enemies: " + Entities.getGroup(Enemy.class).amount()).left();
|
||||
row();
|
||||
new label((StringSupplier)()->"[orange]noclip: " + Vars.noclip).left();
|
||||
|
||||
@@ -69,6 +69,8 @@ public class Block{
|
||||
public String fullDescription;
|
||||
/**Whether to draw this block in the expanded draw range.*/
|
||||
public boolean expanded = false;
|
||||
/**Max of timers used.*/
|
||||
public int timers = 0;
|
||||
|
||||
public Block(String name) {
|
||||
blocks.add(this);
|
||||
@@ -201,7 +203,6 @@ public class Block{
|
||||
Tile other = tile.getNearby()[tile.getRotation()];
|
||||
if(other != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
//other.entity.addCovey(item, ch == 1 ? 0.5f : ch ==2 ? 1f : 0f);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -2,17 +2,20 @@ 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 io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.TargetEnemy;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.graphics.Hue;
|
||||
import io.anuke.ucore.noise.Noise;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Generator{
|
||||
public static boolean debugBlockspam = false;
|
||||
|
||||
static final int spawn = Color.rgba8888(Color.RED);
|
||||
static final int start = Color.rgba8888(Color.GREEN);
|
||||
|
||||
@@ -117,9 +120,9 @@ public class Generator{
|
||||
}
|
||||
|
||||
//preformance debugging
|
||||
//if(Vector2.dst(pixmap.getWidth()/2, pixmap.getHeight()/2, x, y) < 30){
|
||||
// block = Mathf.choose(ProductionBlocks.stonedrill, DistributionBlocks.conveyor);
|
||||
//}
|
||||
if(debugBlockspam && Vector2.dst(0, 0, x, y) < 260){
|
||||
block = Mathf.choose(ProductionBlocks.omnidrill, DistributionBlocks.conveyor, DistributionBlocks.router, WeaponBlocks.turret);
|
||||
}
|
||||
|
||||
tiles[x][y].setBlock(block, 0);
|
||||
tiles[x][y].setFloor(floor);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
@@ -8,7 +9,6 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.production.*;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class ProductionBlocks{
|
||||
public static final Block
|
||||
@@ -192,6 +192,9 @@ public class ProductionBlocks{
|
||||
|
||||
omnidrill = new Drill("omnidrill"){
|
||||
{
|
||||
drillEffect = Fx.sparkbig;
|
||||
resource = null;
|
||||
result = null;
|
||||
time = 3;
|
||||
formalName = "omnidrill";
|
||||
description = "Mines 1 of any resource every "+time+" seconds.";
|
||||
@@ -200,13 +203,14 @@ public class ProductionBlocks{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
TileEntity entity = tile.entity;
|
||||
|
||||
if(tile.floor().drops != null && Timers.get(tile, "drill", 60 * time)){
|
||||
if(tile.floor().drops != null && entity.timer.get(timerDrill, 60 * time)){
|
||||
offloadNear(tile, tile.floor().drops.item);
|
||||
Effects.effect(Fx.sparkbig, tile.worldx(), tile.worldy());
|
||||
Effects.effect(drillEffect, tile.worldx(), tile.worldy());
|
||||
}
|
||||
|
||||
if(Timers.get(tile, "dump", 30)){
|
||||
if(entity.timer.get(timerDump, 30)){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,11 @@ import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class LiquidBlock extends Block implements LiquidAcceptor{
|
||||
protected final int timerFlow = timers++;
|
||||
|
||||
protected float liquidCapacity = 10f;
|
||||
protected float flowfactor = 4.9f;
|
||||
|
||||
@@ -56,7 +57,7 @@ public class LiquidBlock extends Block implements LiquidAcceptor{
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquidAmount > 0.01f && Timers.get(entity, "flow", 3)){
|
||||
if(entity.liquidAmount > 0.01f && entity.timer.get(timerFlow, 3)){
|
||||
tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class RepairTurret extends PowerTurret{
|
||||
entity.blockTarget = null;
|
||||
}
|
||||
|
||||
if(Timers.get(entity, "blocktarget", targetInterval)){
|
||||
if(entity.timer.get(timerTarget, targetInterval)){
|
||||
entity.blockTarget = Vars.world.findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RepairTurret extends PowerTurret{
|
||||
float target = entity.angleTo(entity.blockTarget);
|
||||
entity.rotation = Mathf.slerp(entity.rotation, target, 0.16f*Timers.delta());
|
||||
|
||||
if(Timers.get(tile, "reload", reload) && Angles.angleDist(target, entity.rotation) < shootCone){
|
||||
if(entity.timer.get(timerReload, reload) && Angles.angleDist(target, entity.rotation) < shootCone){
|
||||
entity.blockTarget.health++;
|
||||
|
||||
if(entity.blockTarget.health > entity.blockTarget.health)
|
||||
|
||||
@@ -30,6 +30,9 @@ public class Turret extends Block{
|
||||
static final int targetInterval = 15;
|
||||
static boolean drawDebug = false;
|
||||
|
||||
protected final int timerTarget = timers++;
|
||||
protected final int timerReload = timers++;
|
||||
|
||||
protected float range = 50f;
|
||||
protected float reload = 10f;
|
||||
protected float inaccuracy = 0f;
|
||||
@@ -141,11 +144,9 @@ public class Turret extends Block{
|
||||
|
||||
if(hasAmmo(tile) || (Vars.debug && Vars.infiniteAmmo)){
|
||||
|
||||
if(Timers.get(entity, "target", targetInterval)){
|
||||
if(entity.timer.get(timerTarget, targetInterval)){
|
||||
entity.target = (Enemy)Entities.getClosest(Entities.getGroup(Enemy.class),
|
||||
tile.worldx(), tile.worldy(), range, e->
|
||||
e instanceof Enemy && !((Enemy)e).isDead()
|
||||
);
|
||||
tile.worldx(), tile.worldy(), range, e-> e instanceof Enemy && !((Enemy)e).isDead());
|
||||
}
|
||||
|
||||
if(entity.target != null){
|
||||
@@ -157,7 +158,7 @@ public class Turret extends Block{
|
||||
rotatespeed*Timers.delta());
|
||||
|
||||
float reload = Vars.multiplier*this.reload;
|
||||
if(Angles.angleDist(entity.rotation, targetRot) < shootCone && Timers.get(tile, "reload", reload)){
|
||||
if(Angles.angleDist(entity.rotation, targetRot) < shootCone && entity.timer.get(timerReload, reload)){
|
||||
if(shootsound != null) Effects.sound(shootsound, entity);
|
||||
shoot(tile);
|
||||
consumeAmmo(tile);
|
||||
|
||||
@@ -5,8 +5,10 @@ import static io.anuke.mindustry.Vars.tilesize;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
|
||||
@@ -76,22 +78,14 @@ public class Conveyor extends Block{
|
||||
int value = entity.convey.get(i);
|
||||
ItemPos pos = pos1.set(value);
|
||||
|
||||
boolean canmove = true;
|
||||
|
||||
for(int j = 0; j < entity.convey.size; j ++){
|
||||
ItemPos other = pos2.set(entity.convey.get(j));
|
||||
|
||||
if(other.y > pos.y && other.y - pos.y < 0.14 * Timers.delta()){
|
||||
canmove = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean canmove = i == entity.convey.size - 1 ||
|
||||
!(pos2.set(entity.convey.get(i + 1)).y - pos.y < 0.135 * Timers.delta());
|
||||
|
||||
if(canmove){
|
||||
pos.y += Math.max(speed * Timers.delta(), 1f/252f); //TODO fix precision issues?
|
||||
pos.x = MathUtils.lerp(pos.x, 0, 0.06f * Timers.delta());
|
||||
pos.x = Mathf.lerpDelta(pos.x, 0, 0.06f);
|
||||
}else{
|
||||
pos.x = MathUtils.lerp(pos.x, pos.seed/128f/3f, 0.1f * Timers.delta());
|
||||
pos.x = Mathf.lerpDelta(pos.x, pos.seed/128f/3f, 0.1f);
|
||||
}
|
||||
|
||||
pos.y = Mathf.clamp(pos.y);
|
||||
@@ -135,7 +129,21 @@ public class Conveyor extends Block{
|
||||
float y = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0;
|
||||
|
||||
ConveyorEntity entity = tile.entity();
|
||||
entity.convey.add(ItemPos.packItem(item, y*0.9f, pos, (byte)Mathf.random(255)));
|
||||
int result = ItemPos.packItem(item, y*0.9f, pos, (byte)Mathf.random(255));
|
||||
boolean inserted = false;
|
||||
|
||||
for(int i = 0; i < entity.convey.size; i ++){
|
||||
if(compareItems(result, entity.convey.get(i)) < 0){
|
||||
entity.convey.insert(i, result);
|
||||
inserted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//this item must be greater than anything there...
|
||||
if(!inserted){
|
||||
entity.convey.add(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,9 +175,41 @@ public class Conveyor extends Block{
|
||||
for(int i = 0; i < amount; i ++){
|
||||
convey.add(stream.readInt());
|
||||
}
|
||||
|
||||
sort(convey.items, convey.size);
|
||||
}
|
||||
}
|
||||
|
||||
private static void sort(int[] elements, int length){
|
||||
List<Integer> wrapper = new AbstractList<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer get(int index) {
|
||||
return elements[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer set(int index, Integer element) {
|
||||
int v = elements[index];
|
||||
elements[index] = element;
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
Collections.sort(wrapper, Conveyor::compareItems);
|
||||
}
|
||||
|
||||
private static int compareItems(int a, int b){
|
||||
pos1.set(a);
|
||||
pos2.set(b);
|
||||
return Float.compare(pos1.y, pos2.y);
|
||||
}
|
||||
|
||||
//Container class. Do not instantiate.
|
||||
static class ItemPos{
|
||||
Item item;
|
||||
|
||||
@@ -6,9 +6,10 @@ import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class LiquidRouter extends LiquidBlock{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
private ObjectMap<Tile, Byte> lastmap = new ObjectMap<>();
|
||||
|
||||
public LiquidRouter(String name) {
|
||||
@@ -21,7 +22,7 @@ public class LiquidRouter extends LiquidBlock{
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(Timers.get(tile, "dump", 2) && entity.liquidAmount > 0){
|
||||
if(entity.timer.get(timerDump, 2) && entity.liquidAmount > 0){
|
||||
if(lastmap.get(tile, (byte)-1) != tile.getRotation()){
|
||||
tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]);
|
||||
}
|
||||
|
||||
@@ -8,28 +8,29 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
import io.anuke.mindustry.world.blocks.types.production.Generator;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class PowerBooster extends Generator{
|
||||
public int powerRange = 4;
|
||||
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 drawPixelOverlay(Tile tile){
|
||||
super.drawPixelOverlay(tile);
|
||||
|
||||
|
||||
Draw.color("yellow");
|
||||
Draw.dashCircle(tile.worldx(), tile.worldy(), powerRange * Vars.tilesize);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
Draw.color("purple");
|
||||
@@ -37,69 +38,70 @@ public class PowerBooster extends Generator{
|
||||
Draw.dashCircle(x * Vars.tilesize, y * Vars.tilesize, powerRange * Vars.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 drawOver(Tile tile){}
|
||||
|
||||
public void drawOver(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){
|
||||
if(!Timers.get(tile, "generate", powerTime)){
|
||||
return;
|
||||
}
|
||||
protected void distributePower(Tile tile){
|
||||
PowerEntity p = tile.entity();
|
||||
|
||||
if(!p.timer.get(timerGenerate, powerTime)){
|
||||
return;
|
||||
}
|
||||
|
||||
PowerEntity p = tile.entity();
|
||||
int acceptors = 0;
|
||||
float flow = 0f;
|
||||
|
||||
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++){
|
||||
|
||||
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(x == 0 && y == 0){
|
||||
continue;
|
||||
}
|
||||
if(Vector2.dst(x, y, 0, 0) < powerRange){
|
||||
Tile dest = Vars.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();
|
||||
|
||||
if(Vector2.dst(x, y, 0, 0) < powerRange){
|
||||
Tile dest = Vars.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 transmission = Math.min(flow, p.power);
|
||||
|
||||
float amount = block.addPower(dest, transmission);
|
||||
p.power -= amount;
|
||||
}else{
|
||||
acceptors++;
|
||||
}
|
||||
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);
|
||||
}
|
||||
//TODO better distribution scheme
|
||||
if(i == 0 && acceptors > 0){
|
||||
flow = Mathf.clamp(p.power / acceptors, 0f, powerSpeed / acceptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
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;
|
||||
|
||||
@@ -34,7 +35,7 @@ public class Router extends Block{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
if(Timers.get(tile, "dump", 2) && tile.entity.totalItems() > 0){
|
||||
if(tile.entity.timer.get(timerDump, 2) && tile.entity.totalItems() > 0){
|
||||
if(lastmap.get(tile, (byte)-1) != tile.getRotation()
|
||||
|| Mathf.chance(0.3)){ //sometimes dump backwards at a 1/4 chance... this somehow works?
|
||||
tryDump(tile, tile.getRotation(), null);
|
||||
|
||||
@@ -9,9 +9,10 @@ import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class Crafter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Item[] requirements;
|
||||
protected Item result;
|
||||
|
||||
@@ -31,7 +32,7 @@ public class Crafter extends Block{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
|
||||
if(Timers.get(tile, "dump", 20) && tile.entity.hasItem(result)){
|
||||
if(tile.entity.timer.get(timerDump, 20) && tile.entity.hasItem(result)){
|
||||
tryDump(tile, -1, result);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,20 +2,26 @@ package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
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.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Drill extends Block{
|
||||
protected final int timerDrill = timers++;
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Block resource;
|
||||
protected Item result;
|
||||
protected int time = 5;
|
||||
protected int capacity = 5;
|
||||
protected Effect drillEffect = Fx.spark;
|
||||
|
||||
public Drill(String name) {
|
||||
super(name);
|
||||
@@ -32,13 +38,15 @@ public class Drill extends Block{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
TileEntity entity = tile.entity;
|
||||
|
||||
if((tile.floor() == resource || (resource.drops.equals(tile.floor().drops))) && Timers.get(tile, "drill", 60 * time) && tile.entity.totalItems() < capacity){
|
||||
if((tile.floor() == resource || (resource.drops.equals(tile.floor().drops)))
|
||||
&& entity.timer.get(timerDrill, 60 * time) && tile.entity.totalItems() < capacity){
|
||||
offloadNear(tile, result);
|
||||
Effects.effect(Fx.spark, tile.worldx(), tile.worldy());
|
||||
Effects.effect(drillEffect, tile.worldx(), tile.worldy());
|
||||
}
|
||||
|
||||
if(Timers.get(tile, "dump", 30)){
|
||||
if(entity.timer.get(timerDump, 30)){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,9 +184,19 @@ public class Generator extends PowerBlock{
|
||||
}
|
||||
|
||||
float r = interfering ? 0.8f : 0f;
|
||||
|
||||
Draw.laser("laser", "laserend", tile.worldx() + Angles.x(), tile.worldy() + Angles.y(), target.worldx() - Tmp.v1.x + Mathf.range(r), target.worldy() - Tmp.v1.y + Mathf.range(r), 0.7f + Mathf.sin(Timers.time(), 2f, 0.1f * 0));
|
||||
|
||||
|
||||
int relative = tile.relativeTo(target.x, target.y);
|
||||
|
||||
if(relative == -1){
|
||||
Draw.laser("laser", "laserend", tile.worldx() + Angles.x(), tile.worldy() + Angles.y(),
|
||||
target.worldx() - Tmp.v1.x + Mathf.range(r),
|
||||
target.worldy() - Tmp.v1.y + Mathf.range(r), 0.7f);
|
||||
}else{
|
||||
Draw.rect("laserfull",
|
||||
tile.worldx() + Geometry.getD4Points()[relative].x * width * Vars.tilesize / 2f,
|
||||
tile.worldy() + Geometry.getD4Points()[relative].y * width * Vars.tilesize / 2f);
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@ import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
public class LiquidCrafter extends LiquidBlock{
|
||||
protected final int timerDump = timers++;
|
||||
protected final int timerPurify = timers++;
|
||||
|
||||
/**Can be null.*/
|
||||
public Item input = null;
|
||||
public int inputAmount = 5;
|
||||
@@ -63,7 +65,7 @@ public class LiquidCrafter extends LiquidBlock{
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(Timers.get(tile, "purify", purifyTime) && entity.liquidAmount >= liquidAmount &&
|
||||
if(entity.timer.get(timerPurify, purifyTime) && entity.liquidAmount >= liquidAmount &&
|
||||
(input == null || entity.hasItem(input, inputAmount))){
|
||||
|
||||
if(input != null)
|
||||
@@ -73,7 +75,7 @@ public class LiquidCrafter extends LiquidBlock{
|
||||
Effects.effect(craftEffect, tile.worldx(), tile.worldy());
|
||||
}
|
||||
|
||||
if(Timers.get(tile.hashCode(), "dump", 30)){
|
||||
if(entity.timer.get(timerDump, 30)){
|
||||
tryDump(tile, -1, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
public class NuclearReactor extends LiquidItemPowerGenerator{
|
||||
protected final int timerFuel = timers++;
|
||||
|
||||
protected Color coolColor = new Color(1, 1, 1, 0f);
|
||||
protected Color hotColor = Color.valueOf("ff9575a3");
|
||||
protected int fuelUseTime = 120; //time to consume 1 fuel
|
||||
@@ -53,7 +55,7 @@ public class NuclearReactor extends LiquidItemPowerGenerator{
|
||||
if(fuel > 0){
|
||||
entity.heat += fullness * heating;
|
||||
entity.power += powerMultiplier * fullness;
|
||||
if(Timers.get(tile, "fuelRemove", fuelUseTime)){
|
||||
if(entity.timer.get(timerFuel, fuelUseTime)){
|
||||
entity.removeItem(generateItem, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
public class Pump extends LiquidBlock{
|
||||
protected final int timerPump = timers++;
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected float pumpAmount = 2f;
|
||||
protected float pumpTime = 8f;
|
||||
|
||||
@@ -59,12 +62,12 @@ public class Pump extends LiquidBlock{
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(tile.floor().liquidDrop != null &&
|
||||
Timers.get(tile, "pump", pumpTime) && entity.liquidAmount < liquidCapacity){
|
||||
entity.timer.get(timerPump, pumpTime) && entity.liquidAmount < liquidCapacity){
|
||||
entity.liquid = tile.floor().liquidDrop;
|
||||
entity.liquidAmount += Math.min(pumpAmount, this.liquidCapacity - entity.liquidAmount);
|
||||
}
|
||||
|
||||
if(Timers.get(tile, "dump", 1)){
|
||||
if(entity.timer.get(timerDump, pumpTime)){
|
||||
tryDumpLiquid(tile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user