Duplicate ID check, hasItems cleanup, web host message, projector start
This commit is contained in:
@@ -78,13 +78,11 @@ public class PowerBlocks extends BlockList implements ContentList {
|
||||
|
||||
battery = new PowerGenerator("battery") {{
|
||||
powerCapacity = 320f;
|
||||
hasItems = false;
|
||||
}};
|
||||
|
||||
batteryLarge = new PowerGenerator("batterylarge") {{
|
||||
size = 3;
|
||||
powerCapacity = 2000f;
|
||||
hasItems = false;
|
||||
}};
|
||||
|
||||
powernode = new PowerDistributor("powernode") {{
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.units.*;
|
||||
|
||||
public class UnitBlocks extends BlockList implements ContentList {
|
||||
public static Block resupplyPoint, repairPoint, droneFactory, dropPoint, reconstructor;
|
||||
public static Block resupplyPoint, repairPoint, droneFactory, dropPoint, reconstructor, overdriveProjector, shieldProjector;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
@@ -39,5 +39,13 @@ public class UnitBlocks extends BlockList implements ContentList {
|
||||
reconstructor = new Reconstructor("reconstructor") {{
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
overdriveProjector = new OverdriveProjector("overdriveprojector") {{
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
shieldProjector = new ShieldProjector("shieldprojector") {{
|
||||
size = 2;
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class NetServer extends Module{
|
||||
private final static float serverSyncTime = 4, kickDuration = 30 * 1000;
|
||||
private final static boolean preventDuplicatNames = false;
|
||||
private final static Vector2 vector = new Vector2();
|
||||
/**If a play goes away of their server-side coordinates by this distance, they get teleported back.*/
|
||||
private final static float correctDist = 16f;
|
||||
@@ -94,12 +93,19 @@ public class NetServer extends Module{
|
||||
return;
|
||||
}
|
||||
|
||||
if(preventDuplicatNames) {
|
||||
boolean preventDuplicates = headless;
|
||||
|
||||
if(preventDuplicates) {
|
||||
for (Player player : playerGroup.all()) {
|
||||
if (player.name.equalsIgnoreCase(packet.name)) {
|
||||
kick(id, KickReason.nameInUse);
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.uuid.equals(packet.uuid)) {
|
||||
kick(id, KickReason.idInUse);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -216,6 +216,27 @@ public class Units {
|
||||
});
|
||||
}
|
||||
|
||||
/**Iterates over all units in a circle around this position.*/
|
||||
public static void getNearby(Team team, float x, float y, float radius, Consumer<Unit> cons){
|
||||
rect.setSize(radius * 2).setCenter(x, y);
|
||||
|
||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
EntityPhysics.getNearby(group, rect, entity -> {
|
||||
if(entity.distanceTo(x, y) <= radius) {
|
||||
cons.accept((Unit) entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//now check all players
|
||||
EntityPhysics.getNearby(playerGroup, rect, player -> {
|
||||
if(((Unit)player).team == team && player.distanceTo(x, y) <= radius){
|
||||
cons.accept((Unit)player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**Iterates over all units in a rectangle.*/
|
||||
public static void getNearby(Rectangle rect, Consumer<Unit> cons){
|
||||
|
||||
|
||||
@@ -63,11 +63,14 @@ public class PausedDialog extends FloatingDialog{
|
||||
|
||||
content().row();
|
||||
|
||||
if(!gwt) {
|
||||
content().addButton("$text.hostserver", () -> {
|
||||
content().addButton("$text.hostserver", () -> {
|
||||
if(!gwt){
|
||||
ui.host.show();
|
||||
}).disabled(b -> Net.active());
|
||||
}
|
||||
}else{
|
||||
ui.showInfo("$text.host.web");
|
||||
}
|
||||
}).disabled(b -> Net.active());
|
||||
|
||||
|
||||
content().row();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
public abstract class BaseBlock {
|
||||
public boolean hasItems = true;
|
||||
public boolean hasItems;
|
||||
public boolean hasLiquids;
|
||||
public boolean hasPower;
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ public class LiquidBlock extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
hasLiquids = true;
|
||||
hasItems = false;
|
||||
group = BlockGroup.liquids;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ public class Wall extends Block{
|
||||
solid = true;
|
||||
destructible = true;
|
||||
group = BlockGroup.walls;
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ public class ShieldBlock extends PowerBlock{
|
||||
public ShieldBlock(String name) {
|
||||
super(name);
|
||||
powerCapacity = 80f;
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,7 +72,6 @@ public abstract class Turret extends Block{
|
||||
solid = true;
|
||||
layer = Layer.turret;
|
||||
group = BlockGroup.turrets;
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ public class BufferedItemBridge extends ExtendingItemBridge {
|
||||
public BufferedItemBridge(String name) {
|
||||
super(name);
|
||||
hasPower = false;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,7 @@ public class ExtendingItemBridge extends ItemBridge {
|
||||
|
||||
public ExtendingItemBridge(String name) {
|
||||
super(name);
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,6 +47,7 @@ public class ItemBridge extends Block {
|
||||
expanded = true;
|
||||
itemCapacity = 30;
|
||||
configurable = true;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,6 @@ public class Junction extends Block{
|
||||
solid = true;
|
||||
instantTransfer = true;
|
||||
group = BlockGroup.transportation;
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,7 @@ public class OverflowGate extends Splitter {
|
||||
|
||||
public OverflowGate(String name) {
|
||||
super(name);
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ public class Router extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
itemCapacity = 20;
|
||||
hasItems = true;
|
||||
group = BlockGroup.transportation;
|
||||
autoSleep = true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ public class Splitter extends Block{
|
||||
solid = true;
|
||||
instantTransfer = true;
|
||||
destructible = true;
|
||||
hasItems = false;
|
||||
group = BlockGroup.transportation;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ public class TunnelConduit extends LiquidBlock {
|
||||
rotate = true;
|
||||
solid = true;
|
||||
health = 70;
|
||||
hasItems = true;
|
||||
instantTransfer = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.distribution;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.NumberUtils;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
|
||||
public class TunnelConveyor extends Block{
|
||||
protected int maxdist = 3;
|
||||
protected float speed = 53; //frames taken to go through this tunnel
|
||||
protected int capacity = 32;
|
||||
|
||||
protected TunnelConveyor(String name) {
|
||||
super(name);
|
||||
rotate = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
health = 70;
|
||||
instantTransfer = true;
|
||||
bars.add(new io.anuke.mindustry.world.meta.BlockBar(BarType.inventory, true, tile -> (float)tile.<TunnelEntity>entity().index/capacity));
|
||||
group = BlockGroup.transportation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
TunnelEntity entity = tile.entity();
|
||||
|
||||
if(entity.index >= entity.buffer.length) return;
|
||||
|
||||
entity.buffer[entity.index ++] = Bits.packLong(NumberUtils.floatToIntBits(Timers.time()), item.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
TunnelEntity entity = tile.entity();
|
||||
|
||||
if(entity.index > 0){
|
||||
long l = entity.buffer[0];
|
||||
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
|
||||
|
||||
if(Timers.time() >= time + speed || Timers.time() < time){
|
||||
|
||||
Item item = Item.getByID(Bits.getRightInt(l));
|
||||
|
||||
Tile tunnel = getDestTunnel(tile, item);
|
||||
if(tunnel == null) return;
|
||||
Tile target = tunnel.getNearby(tunnel.getRotation());
|
||||
if(target == null) return;
|
||||
|
||||
if(!target.block().acceptItem(item, target, tunnel)) return;
|
||||
|
||||
target.block().handleItem(item, target, tunnel);
|
||||
System.arraycopy(entity.buffer, 1, entity.buffer, 0, entity.index - 1);
|
||||
entity.index --;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source) {
|
||||
TunnelEntity entity = tile.entity();
|
||||
int rot = source.relativeTo(tile.x, tile.y);
|
||||
return rot == (tile.getRotation() + 2) % 4 && entity.index < entity.buffer.length - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new TunnelEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<Object> getDebugInfo(Tile tile){
|
||||
TunnelEntity entity = tile.entity();
|
||||
Array<Object> arr = super.getDebugInfo(tile);
|
||||
for(int i = 0; i < 4; i ++){
|
||||
arr.add("nearby." + i);
|
||||
arr.add(tile.getNearby(i));
|
||||
}
|
||||
|
||||
arr.add("buffer");
|
||||
arr.add(entity.index);
|
||||
|
||||
for(int i = 0; i < entity.index; i++){
|
||||
long l = entity.items.items[i];
|
||||
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
|
||||
Item item = Item.getByID(Bits.getRightInt(l));
|
||||
Tile dest = getDestTunnel(tile, item);
|
||||
arr.add(" buffer.item");
|
||||
arr.add(time + " | " + item.name + " | " + ( dest == null ? "no dest" : dest.block() + ":" + dest.floor()));
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
Tile getDestTunnel(Tile tile, Item item){
|
||||
Tile dest = tile;
|
||||
int rel = (tile.getRotation() + 2)%4;
|
||||
for(int i = 0; i < maxdist; i ++){
|
||||
if(dest == null) return null;
|
||||
dest = dest.getNearby(rel);
|
||||
if(dest != null && dest.block() instanceof TunnelConveyor && dest.getRotation() == rel
|
||||
&& dest.getNearby(rel) != null
|
||||
&& dest.getNearby(rel).block().acceptItem(item, dest.getNearby(rel), dest)){
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class TunnelEntity extends TileEntity {
|
||||
long[] buffer = new long[capacity];
|
||||
int index;
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@ public class WarpGate extends PowerBlock{
|
||||
size = 3;
|
||||
itemCapacity = 100;
|
||||
hasLiquids = true;
|
||||
hasItems = true;
|
||||
liquidCapacity = 100f;
|
||||
configurable = true;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class BurnerGenerator extends PowerGenerator {
|
||||
public BurnerGenerator(String name) {
|
||||
super(name);
|
||||
itemCapacity = 20;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ public class DecayGenerator extends BurnerGenerator {
|
||||
|
||||
public DecayGenerator(String name) {
|
||||
super(name);
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ public class LiquidBurnerGenerator extends PowerGenerator {
|
||||
super(name);
|
||||
liquidCapacity = 30f;
|
||||
hasLiquids = true;
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,6 @@ public class LiquidHeatGenerator extends LiquidBurnerGenerator {
|
||||
|
||||
public LiquidHeatGenerator(String name) {
|
||||
super(name);
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,6 @@ public class PowerDistributor extends PowerBlock{
|
||||
super(name);
|
||||
expanded = true;
|
||||
layer = Layer.power;
|
||||
hasItems = false;
|
||||
powerCapacity = 5f;
|
||||
configurable = true;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@ package io.anuke.mindustry.world.blocks.power;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class SolarGenerator extends io.anuke.mindustry.world.blocks.power.PowerGenerator {
|
||||
public class SolarGenerator extends PowerGenerator {
|
||||
/**power generated per frame*/
|
||||
protected float generation = 0.005f;
|
||||
|
||||
public SolarGenerator(String name){
|
||||
super(name);
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,6 +65,7 @@ public class Drill extends Block{
|
||||
group = BlockGroup.drills;
|
||||
hasLiquids = true;
|
||||
liquidCapacity = 5f;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ public class Fracker extends SolidPump {
|
||||
|
||||
public Fracker(String name) {
|
||||
super(name);
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.io.IOException;
|
||||
public class GenericCrafter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
/**Can be null. If you use this, make sure to set hasInvetory to true!*/
|
||||
/**Can be null. If you use this, make sure to set hasItems to true!*/
|
||||
protected ItemStack inputItem;
|
||||
/**Can be null. If you use this, make sure to set hasLiquids to true!*/
|
||||
protected Liquid inputLiquid;
|
||||
|
||||
@@ -23,7 +23,6 @@ public class Incinerator extends Block {
|
||||
public Incinerator(String name) {
|
||||
super(name);
|
||||
hasPower = true;
|
||||
hasItems = false;
|
||||
hasLiquids = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
|
||||
@@ -36,6 +36,7 @@ public class MechFactory extends Block{
|
||||
public MechFactory(String name){
|
||||
super(name);
|
||||
solid = true;
|
||||
hasItems = true;
|
||||
destructible = true;
|
||||
configurable = true;
|
||||
update = true;
|
||||
|
||||
@@ -28,6 +28,7 @@ public class PowerCrafter extends Block{
|
||||
solid = true;
|
||||
update = true;
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,6 +46,7 @@ public class PowerSmelter extends PowerBlock {
|
||||
|
||||
public PowerSmelter(String name) {
|
||||
super(name);
|
||||
hasItems = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ public class Pulverizer extends GenericCrafter {
|
||||
|
||||
public Pulverizer(String name) {
|
||||
super(name);
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,6 +36,7 @@ public class Smelter extends Block{
|
||||
public Smelter(String name) {
|
||||
super(name);
|
||||
update = true;
|
||||
hasItems = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ public abstract class StorageBlock extends Block {
|
||||
|
||||
public StorageBlock(String name){
|
||||
super(name);
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
/**Removes an item and returns it. If item is not null, it should return the item.
|
||||
|
||||
@@ -15,6 +15,7 @@ public class Unloader extends Block {
|
||||
solid = true;
|
||||
health = 70;
|
||||
group = BlockGroup.transportation;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.anuke.mindustry.world.blocks.units;
|
||||
|
||||
public class OverdriveProjector extends Projector {
|
||||
|
||||
public OverdriveProjector(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.anuke.mindustry.world.blocks.units;
|
||||
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public abstract class Projector extends Block {
|
||||
protected final int timerApply = timers++;
|
||||
protected final float applyTime = 4f;
|
||||
|
||||
protected float powerUse = 0.01f;
|
||||
protected float range = 40f;
|
||||
|
||||
protected StatusEffect status;
|
||||
protected float intensity;
|
||||
|
||||
public Projector(String name) {
|
||||
super(name);
|
||||
hasPower = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile) {
|
||||
if(Timers.get(timerApply, applyTime)) {
|
||||
Units.getNearby(tile.getTeam(), tile.drawx(), tile.drawy(), range, unit -> {
|
||||
unit.applyEffect(status, intensity);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,6 @@ public class RepairPoint extends Block{
|
||||
flags = EnumSet.of(BlockFlag.repair);
|
||||
layer = Layer.turret;
|
||||
layer2 = Layer.laser;
|
||||
hasItems = false;
|
||||
hasPower = true;
|
||||
powerCapacity = 20f;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.anuke.mindustry.world.blocks.units;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
public class ShieldProjector extends Projector {
|
||||
|
||||
public ShieldProjector(String name) {
|
||||
super(name);
|
||||
hasPower = true;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.units;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.fx.BlockFx;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
@@ -14,9 +13,9 @@ import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.BarType;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.meta.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.modules.InventoryModule;
|
||||
import io.anuke.mindustry.world.meta.BlockBar;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -29,8 +28,6 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnitFactory extends Block {
|
||||
private final Rectangle rect = new Rectangle();
|
||||
|
||||
protected UnitType type;
|
||||
protected ItemStack[] requirements;
|
||||
protected float produceTime = 1000f;
|
||||
@@ -43,6 +40,7 @@ public class UnitFactory extends Block {
|
||||
super(name);
|
||||
update = true;
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
solidifes = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user