Merge branch 'master' of https://github.com/Anuken/Mindustry into refactor-paths

 Conflicts:
	core/src/mindustry/ai/types/GroundAI.java
This commit is contained in:
Anuken
2020-09-03 09:18:06 -04:00
186 changed files with 10171 additions and 8983 deletions
+2
View File
@@ -56,6 +56,8 @@ public class Block extends UnlockableContent{
public final BlockBars bars = new BlockBars();
public final Consumers consumes = new Consumers();
/** whether to display flow rate */
public boolean displayFlow = true;
/** whether this block is visible in the editor */
public boolean inEditor = true;
/** the last configuration value applied to this block. */
+10 -1
View File
@@ -148,7 +148,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{
}
public Team team(){
return build == null ? Team.derelict : build.team();
return build == null ? Team.derelict : build.team;
}
public void setTeam(Team team){
@@ -180,6 +180,10 @@ public class Tile implements Position, QuadTreeObject, Displayable{
public void setBlock(@NonNull Block type, Team team, int rotation, Prov<Building> entityprov){
changing = true;
if(type.isStatic() || this.block.isStatic()){
recache();
}
this.block = type;
preChanged();
changeEntity(team, entityprov, (byte)Mathf.mod(rotation, 4));
@@ -286,6 +290,11 @@ public class Tile implements Position, QuadTreeObject, Displayable{
Call.removeTile(this);
}
/** set()-s this tile, except it's synced across the network */
public void setNet(Block block){
Call.setTile(this, block, Team.derelict, 0);
}
/** set()-s this tile, except it's synced across the network */
public void setNet(Block block, Team team, int rotation){
Call.setTile(this, block, team, rotation);
+1 -1
View File
@@ -72,7 +72,7 @@ public class Tiles implements Iterable<Tile>{
return get(Point2.x(pos), Point2.y(pos));
}
public void each(Cons<Tile> cons){
public void eachTile(Cons<Tile> cons){
for(Tile tile : array){
cons.get(tile);
}
@@ -147,7 +147,7 @@ public interface Autotiler{
default boolean blends(Tile tile, int rotation, int direction){
Building other = tile.getNearbyEntity(Mathf.mod(rotation - direction, 4));
return other != null && other.team() == tile.team() && blends(tile, rotation, other.tileX(), other.tileY(), other.rotation, other.block());
return other != null && other.team == tile.team() && blends(tile, rotation, other.tileX(), other.tileY(), other.rotation, other.block());
}
default boolean blendsArmored(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
@@ -61,9 +61,9 @@ public class BuildBlock extends Block{
if(tile == null) return;
float healthf = tile.build == null ? 1f : tile.build.healthf();
tile.setBlock(block, team, rotation);
tile.build.health = block.health * healthf;
if(tile.build != null) tile.build.health = block.health * healthf;
//last builder was this local client player, call placed()
if(!headless && builderID == player.unit().id()){
if(tile.build != null && !headless && builderID == player.unit().id()){
if(!skipConfig){
tile.build.playerPlaced();
}
@@ -43,7 +43,7 @@ public class ShockMine extends Block{
@Override
public void unitOn(Unit unit){
if(unit.team() != team && timer(timerDamage, cooldown)){
if(enabled && unit.team != team && timer(timerDamage, cooldown)){
for(int i = 0; i < tendrils; i++){
Lightning.create(team, Pal.lancerLaser, damage, x, y, Mathf.random(360f), length);
}
@@ -91,7 +91,7 @@ public class Wall extends Block{
//create lightning if necessary
if(lightningChance > 0){
if(Mathf.chance(lightningChance)){
Lightning.create(team(), Pal.surge, lightningDamage, x, y, bullet.rotation() + 180f, lightningLength);
Lightning.create(team, Pal.surge, lightningDamage, x, y, bullet.rotation() + 180f, lightningLength);
}
}
@@ -138,13 +138,18 @@ public class ItemTurret extends Turret{
return ammoTypes.get(item) != null && totalAmmo + ammoTypes.get(item).ammoMultiplier <= maxAmmo;
}
@Override
public byte version(){
return 2;
}
@Override
public void write(Writes write){
super.write(write);
write.b(ammo.size);
for(AmmoEntry entry : ammo){
ItemEntry i = (ItemEntry)entry;
write.b(i.item.id);
write.s(i.item.id);
write.s(i.amount);
}
}
@@ -152,12 +157,16 @@ public class ItemTurret extends Turret{
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
byte amount = read.b();
int amount = read.ub();
for(int i = 0; i < amount; i++){
Item item = Vars.content.item(read.b());
Item item = Vars.content.item(revision < 2 ? read.ub() : read.s());
short a = read.s();
totalAmmo += a;
ammo.add(new ItemEntry(item, a));
//only add ammo if this is a valid ammo type
if(ammoTypes.containsKey(item)){
ammo.add(new ItemEntry(item, a));
}
}
}
}
@@ -65,7 +65,7 @@ public class LaserTurret extends PowerTurret{
bullet = null;
}
}else if(reload > 0){
Liquid liquid = liquids().current();
Liquid liquid = liquids.current();
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
float used = (cheating() ? maxUsed * Time.delta : Math.min(liquids.get(liquid), maxUsed * Time.delta)) * liquid.heatCapacity * coolantMultiplier;
@@ -436,7 +436,7 @@ public abstract class Turret extends Block{
public void read(Reads read, byte revision){
super.read(read, revision);
if(revision == 1){
if(revision >= 1){
reload = read.f();
rotation = read.f();
}
@@ -163,7 +163,7 @@ public class Conveyor extends Block implements Autotiler{
if(front() != null && front() != null){
next = front();
nextc = next instanceof ConveyorBuild && next.team() == team ? (ConveyorBuild)next : null;
nextc = next instanceof ConveyorBuild && next.team == team ? (ConveyorBuild)next : null;
aligned = nextc != null && rotation == next.rotation;
}
}
@@ -178,7 +178,7 @@ public class Conveyor extends Block implements Autotiler{
float mspeed = speed * tilesize * 55f;
float centerSpeed = 0.1f;
float centerDstScl = 3f;
float tx = Geometry.d4x[rotation], ty = Geometry.d4y[rotation];
float tx = Geometry.d4x(rotation), ty = Geometry.d4y(rotation);
float centerx = 0f, centery = 0f;
@@ -42,6 +42,7 @@ public class ItemBridge extends Block{
unloadable = false;
group = BlockGroup.transportation;
canOverdrive = false;
noUpdateDisabled = true;
//point2 config is relative
config(Point2.class, (ItemBridgeBuild tile, Point2 i) -> tile.link = Point2.pack(i.x + tile.tileX(), i.y + tile.tileY()));
@@ -341,7 +342,7 @@ public class ItemBridge extends Block{
@Override
public boolean acceptLiquid(Building source, Liquid liquid, float amount){
if(team != source.team() || !hasLiquids) return false;
if(team != source.team || !hasLiquids) return false;
Tile other = world.tile(link);
@@ -19,6 +19,7 @@ public class Junction extends Block{
solid = true;
group = BlockGroup.transportation;
unloadable = false;
noUpdateDisabled = true;
}
@Override
@@ -49,7 +50,7 @@ public class Junction extends Block{
Building dest = nearby(i);
//skip blocks that don't want the item, keep waiting until they do
if(dest == null || !dest.acceptItem(this, item) || dest.team() != team){
if(dest == null || !dest.acceptItem(this, item) || dest.team != team){
continue;
}
@@ -73,7 +74,7 @@ public class Junction extends Block{
if(relative == -1 || !buffer.accepts(relative)) return false;
Building to = nearby(relative);
return to != null && to.team() == team;
return to != null && to.team == team;
}
@Override
@@ -223,7 +223,7 @@ public class MassDriver extends Block{
if(link == other.pos()){
configure(-1);
return false;
}else if(other.block() instanceof MassDriver && other.dst(tile) <= range && other.team() == team){
}else if(other.block() instanceof MassDriver && other.dst(tile) <= range && other.team == team){
configure(other.pos());
return false;
}
@@ -254,7 +254,7 @@ public class MassDriver extends Block{
float angle = tile.angleTo(target);
Bullets.driverBolt.create(this, team(),
Bullets.driverBolt.create(this, team,
x + Angles.trnsx(angle, translation), y + Angles.trnsy(angle, translation),
angle, -1f, bulletSpeed, bulletLifetime, data);
@@ -76,7 +76,7 @@ public class OverflowGate extends Block{
@Override
public boolean acceptItem(Building source, Item item){
return team == source.team() && lastItem == null && items.total() == 0;
return team == source.team && lastItem == null && items.total() == 0;
}
@Override
@@ -91,16 +91,17 @@ public class OverflowGate extends Block{
int from = relativeToEdge(src);
if(from == -1) return null;
Building to = nearby((from + 2) % 4);
boolean canForward = to != null && to.acceptItem(this, item) && to.team() == team && !(to.block() instanceof OverflowGate);
boolean canForward = to != null && to.acceptItem(this, item) && to.team == team && !(to.block() instanceof OverflowGate);
boolean inv = invert == enabled;
if(!canForward || invert){
if(!canForward || inv){
Building a = nearby(Mathf.mod(from - 1, 4));
Building b = nearby(Mathf.mod(from + 1, 4));
boolean ac = a != null && a.acceptItem(this, item) && !(a.block() instanceof OverflowGate) && a.team == team;
boolean bc = b != null && b.acceptItem(this, item) && !(b.block() instanceof OverflowGate) && b.team == team;
if(!ac && !bc){
return invert && canForward ? to : null;
return inv && canForward ? to : null;
}
if(ac && !bc){
@@ -17,7 +17,7 @@ import mindustry.world.blocks.production.*;
import static mindustry.Vars.*;
public class PayloadConveyor extends Block{
public float moveTime = 70f;
public float moveTime = 60f;
public @Load("@-top") TextureRegion topRegion;
public @Load("@-edge") TextureRegion edgeRegion;
public Interp interp = Interp.pow5;
@@ -29,6 +29,7 @@ public class PayloadConveyor extends Block{
rotate = true;
update = true;
outputsPayload = true;
noUpdateDisabled = true;
}
@Override
@@ -85,7 +86,7 @@ public class PayloadConveyor extends Block{
int ntrns = 1 + size/2;
Tile next = tile.getNearby(Geometry.d4(rotation).x * ntrns, Geometry.d4(rotation).y * ntrns);
blocked = (next != null && next.solid()) || (this.next != null && (this.next.rotation + 2)%4 == rotation);
blocked = (next != null && next.solid() && !next.block().outputsPayload) || (this.next != null && (this.next.rotation + 2)%4 == rotation);
}
@Override
@@ -95,7 +96,9 @@ public class PayloadConveyor extends Block{
@Override
public void updateTile(){
progress = Time.time() % moveTime;
if(!enabled) return;
progress = time() % moveTime;
updatePayload();
@@ -184,6 +187,10 @@ public class PayloadConveyor extends Block{
}
}
public float time(){
return Time.time();
}
@Override
public boolean acceptPayload(Building source, Payload payload){
//accepting payloads from units isn't supported
@@ -273,7 +280,7 @@ public class PayloadConveyor extends Block{
}
public int curStep(){
return (int)((Time.time()) / moveTime);
return (int)((time()) / moveTime);
}
public float fract(){
@@ -35,7 +35,7 @@ public class Router extends Block{
time += 1f / speed * delta();
Building target = getTileTarget(lastItem, lastInput, false);
if(target != null && (time >= 1f || !(target.block() instanceof Router))){
if(target != null && (time >= 1f || !(target.block() instanceof Router || target.block().instantTransfer))){
getTileTarget(lastItem, lastInput, true);
target.handleItem(this, lastItem);
items.remove(lastItem, 1);
@@ -51,7 +51,7 @@ public class Router extends Block{
@Override
public boolean acceptItem(Building source, Item item){
return team == source.team() && lastItem == null && items.total() == 0;
return team == source.team && lastItem == null && items.total() == 0;
}
@Override
@@ -76,7 +76,7 @@ public class Router extends Block{
for(int i = 0; i < proximity.size; i++){
Building other = proximity.get((i + counter) % proximity.size);
if(set) rotation = ((byte)((rotation + 1) % proximity.size));
if(other.tile() == from && from.block() == Blocks.overflowGate) continue;
if(other.tile == from && from.block() == Blocks.overflowGate) continue;
if(other.acceptItem(this, item)){
return other;
}
@@ -76,7 +76,7 @@ public class Sorter extends Block{
public boolean acceptItem(Building source, Item item){
Building to = getTileTarget(item, source, false);
return to != null && to.acceptItem(this, item) && to.team() == team;
return to != null && to.acceptItem(this, item) && to.team == team;
}
@Override
@@ -1,20 +0,0 @@
package mindustry.world.blocks.legacy;
import arc.util.io.*;
import mindustry.gen.*;
public class LegacyCommandCenter extends LegacyBlock{
public LegacyCommandCenter(String name){
super(name);
update = true;
}
public class LegacyCommandCenterBuild extends Building{
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
read.b();
}
}
}
@@ -26,7 +26,7 @@ public class ArmoredConduit extends Conduit{
// draw the cap when a conduit would normally leak
Building next = front();
if(next != null && next.team() == team && next.block().hasLiquids) return;
if(next != null && next.team == team && next.block().hasLiquids) return;
Draw.rect(capRegion, x, y, rotdeg());
}
@@ -35,6 +35,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
solid = false;
floating = true;
conveyorPlacement = true;
noUpdateDisabled = true;
}
@Override
@@ -36,6 +36,8 @@ public class LiquidJunction extends LiquidBlock{
@Override
public Building getLiquidDestination(Building source, Liquid liquid){
if(!enabled) return this;
int dir = source.relativeTo(tile.x, tile.y);
dir = (dir + 4) % 4;
Building next = nearby(dir);
@@ -7,6 +7,8 @@ public class LiquidRouter extends LiquidBlock{
public LiquidRouter(String name){
super(name);
noUpdateDisabled = true;
}
public class LiquidRouterEntity extends LiquidBuild{
@@ -17,6 +17,7 @@ import mindustry.logic.LExecutor.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.BuildBlock.*;
import mindustry.world.meta.*;
import java.io.*;
import java.util.zip.*;
@@ -24,7 +25,7 @@ import java.util.zip.*;
import static mindustry.Vars.*;
public class LogicBlock extends Block{
public static final int maxInstructions = 2000;
public static final int maxInstructions = 1500;
public int maxInstructionScale = 5;
public int instructionsPerTick = 1;
@@ -35,6 +36,7 @@ public class LogicBlock extends Block{
update = true;
solid = true;
configurable = true;
sync = true;
config(byte[].class, (LogicBuild build, byte[] data) -> build.readCompressed(data, true));
@@ -113,6 +115,14 @@ public class LogicBlock extends Block{
}
}
@Override
public void setStats(){
super.setStats();
stats.add(BlockStat.linkRange, range / 8, StatUnit.blocks);
stats.add(BlockStat.instructions, instructionsPerTick * 60, StatUnit.perSecond);
}
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.circles(x*tilesize + offset, y*tilesize + offset, range);
@@ -198,7 +208,6 @@ public class LogicBlock extends Block{
stream.readInt();
}
}else{
for(int i = 0; i < total; i++){
String name = stream.readUTF();
short x = stream.readShort(), y = stream.readShort();
@@ -281,6 +290,7 @@ public class LogicBlock extends Block{
}
asm.putConst("@links", executor.links.length);
asm.putConst("@ipt", instructionsPerTick);
//store any older variables
for(Var var : executor.vars){
@@ -298,6 +308,8 @@ public class LogicBlock extends Block{
}
asm.putConst("@this", this);
asm.putConst("@thisx", x);
asm.putConst("@thisy", y);
executor.load(asm);
}catch(Exception e){
@@ -320,7 +332,9 @@ public class LogicBlock extends Block{
//check for previously invalid links to add after configuration
boolean changed = false;
for(LogicLink l : links){
for(int i = 0; i < links.size; i++){
LogicLink l = links.get(i);
if(!l.active) continue;
boolean valid = validLink(world.build(l.x, l.y));
@@ -328,10 +342,18 @@ public class LogicBlock extends Block{
changed = true;
l.valid = valid;
if(valid){
Building lbuild = world.build(l.x, l.y);
//this prevents conflicts
l.name = "";
//finds a new matching name after toggling
l.name = findLinkName(world.build(l.x, l.y).block);
l.name = findLinkName(lbuild.block);
//remove redundant links
links.removeAll(o -> world.build(o.x, o.y) == lbuild && o != l);
//break to prevent concurrent modification
break;
}
}
}
@@ -340,15 +362,17 @@ public class LogicBlock extends Block{
updateCode();
}
accumulator += edelta() * instructionsPerTick;
if(enabled){
accumulator += edelta() * instructionsPerTick * (consValid() ? 1 : 0);
if(accumulator > maxInstructionScale * instructionsPerTick) accumulator = maxInstructionScale * instructionsPerTick;
if(accumulator > maxInstructionScale * instructionsPerTick) accumulator = maxInstructionScale * instructionsPerTick;
for(int i = 0; i < (int)accumulator; i++){
if(executor.initialized()){
executor.runOnce();
for(int i = 0; i < (int)accumulator; i++){
if(executor.initialized()){
executor.runOnce();
}
accumulator --;
}
accumulator --;
}
}
@@ -9,6 +9,7 @@ import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.world.*;
public class LogicDisplay extends Block{
@@ -37,7 +38,7 @@ public class LogicDisplay extends Block{
public FrameBuffer buffer;
public float color = Color.whiteFloatBits;
public float stroke = 1f;
public LongQueue commands = new LongQueue();
public LongQueue commands = new LongQueue(LExecutor.maxDisplayBuffer);
@Override
public void draw(){
@@ -11,7 +11,6 @@ import arc.util.*;
import arc.util.io.*;
import arc.util.pooling.*;
import mindustry.gen.*;
import mindustry.net.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import mindustry.world.*;
@@ -30,8 +29,8 @@ public class MessageBlock extends Block{
destructible = true;
config(String.class, (MessageBuild tile, String text) -> {
if(net.server() && text.length() > maxTextLength){
throw new ValidateException(player, "Player has gone above text limit.");
if(text.length() > maxTextLength){
return; //no.
}
tile.message.ensureCapacity(text.length());
@@ -30,7 +30,7 @@ public class BlockPayload implements Payload{
}
public void place(Tile tile, int rotation){
tile.setBlock(entity.block(), entity.team(), rotation, () -> entity);
tile.setBlock(entity.block(), entity.team, rotation, () -> entity);
entity.dropped();
}
@@ -21,6 +21,7 @@ public class PowerDiode extends Block{
solid = true;
insulated = true;
group = BlockGroup.power;
noUpdateDisabled = true;
}
@Override
@@ -53,7 +54,7 @@ public class PowerDiode extends Block{
public void updateTile(){
super.updateTile();
if(front() == null || back() == null || !back().block().hasPower || !front().block().hasPower || back().team() != front().team()) return;
if(front() == null || back() == null || !back().block().hasPower || !front().block().hasPower || back().team != front().team) return;
PowerGraph backGraph = back().power.graph;
PowerGraph frontGraph = front().power.graph;
@@ -68,7 +68,7 @@ public class PowerNode extends PowerBlock{
power.links.add(other.pos());
}
if(other.team() == entity.team()){
if(other.team == entity.team){
if(!other.power.links.contains(entity.pos())){
other.power.links.add(entity.pos());
@@ -184,7 +184,7 @@ public class PowerNode extends PowerBlock{
protected void getPotentialLinks(Tile tile, Cons<Building> others){
Boolf<Building> valid = other -> other != null && other.tile() != tile && other.power != null &&
((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) &&
overlaps(tile.x * tilesize + offset, tile.y * tilesize + offset, other.tile(), laserRange * tilesize) && other.team() == player.team()
overlaps(tile.x * tilesize + offset, tile.y * tilesize + offset, other.tile(), laserRange * tilesize) && other.team == player.team()
&& !other.proximity().contains(e -> e.tile() == tile) && !graphs.contains(other.power.graph);
tempTileEnts.clear();
@@ -235,7 +235,7 @@ public class PowerNode extends PowerBlock{
}
public boolean linkValid(Building tile, Building link, boolean checkMaxNodes){
if(tile == link || link == null || !link.block().hasPower || tile.team() != link.team()) return false;
if(tile == link || link == null || !link.block().hasPower || tile.team != link.team) return false;
if(overlaps(tile, link, laserRange * tilesize) || (link.block() instanceof PowerNode && overlaps(link, tile, ((PowerNode)link.block()).laserRange * tilesize))){
if(checkMaxNodes && link.block() instanceof PowerNode){
@@ -24,12 +24,12 @@ public class SolarGenerator extends PowerGenerator{
public class SolarGeneratorBuild extends GeneratorBuild{
@Override
public void updateTile(){
productionEfficiency =
productionEfficiency = enabled ?
Mathf.maxZero(Attribute.light.env() +
(state.rules.solarPowerMultiplier < 0 ?
(state.rules.lighting ? 1f - state.rules.ambientLight.a : 1f) :
state.rules.solarPowerMultiplier
));
)) : 0f;
}
}
}
@@ -49,10 +49,10 @@ public class AttributeSmelter extends GenericSmelter{
}
@Override
public void placed(){
super.placed();
public void onProximityUpdate(){
super.onProximityUpdate();
attrsum = sumAttribute(attribute, tile.x, tile.y);
}
}
}
}
@@ -23,6 +23,7 @@ public class ItemSource extends Block{
group = BlockGroup.transportation;
configurable = true;
saveConfig = true;
noUpdateDisabled = true;
config(Item.class, (ItemSourceBuild tile, Item item) -> tile.outputItem = item);
configClear((ItemSourceBuild tile) -> tile.outputItem = null);
@@ -51,11 +52,13 @@ public class ItemSource extends Block{
public void draw(){
super.draw();
if(outputItem == null) return;
Draw.color(outputItem.color);
Draw.rect("center", x, y);
Draw.color();
if(outputItem == null){
Draw.rect("cross", x, y);
}else{
Draw.color(outputItem.color);
Draw.rect("center", x, y);
Draw.color();
}
}
@Override
@@ -17,7 +17,7 @@ public class ItemVoid extends Block{
@Override
public boolean acceptItem(Building source, Item item){
return true;
return enabled;
}
}
}
@@ -24,6 +24,8 @@ public class LiquidSource extends Block{
configurable = true;
outputsLiquid = true;
saveConfig = true;
noUpdateDisabled = true;
displayFlow = false;
config(Liquid.class, (LiquidSourceBuild tile, Liquid l) -> tile.source = l);
configClear((LiquidSourceBuild tile) -> tile.source = null);
@@ -58,7 +60,9 @@ public class LiquidSource extends Block{
public void draw(){
super.draw();
if(source != null){
if(source == null){
Draw.rect("cross", x, y);
}else{
Draw.color(source.color);
Draw.rect("center", x, y);
Draw.color();
@@ -86,16 +90,21 @@ public class LiquidSource extends Block{
return source;
}
@Override
public byte version(){
return 1;
}
@Override
public void write(Writes write){
super.write(write);
write.b(source == null ? -1 : source.id);
write.s(source == null ? -1 : source.id);
}
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
byte id = read.b();
int id = revision == 1 ? read.s() : read.b();
source = id == -1 ? null : content.liquid(id);
}
}
@@ -22,7 +22,7 @@ public class LiquidVoid extends Block{
public class LiquidVoidBuild extends Building{
@Override
public boolean acceptLiquid(Building source, Liquid liquid, float amount){
return true;
return enabled;
}
@Override
@@ -14,7 +14,7 @@ public class PowerSource extends PowerNode{
public class PowerSourceBuild extends PowerNodeBuild{
@Override
public float getPowerProduction(){
return 10000f;
return enabled ? 10000f : 0f;
}
}
@@ -143,7 +143,7 @@ public class CoreBlock extends StorageBlock{
if(!canPlaceOn(world.tile(x, y), player.team())){
drawPlaceText(Core.bundle.get((player.team().core() != null && player.team().core().items.has(requirements) && !state.rules.infiniteResources) ?
drawPlaceText(Core.bundle.get((player.team().core() != null && player.team().core().items.has(requirements)) || state.rules.infiniteResources ?
"bar.corereq" :
"bar.noresources"
), x, y, valid);
@@ -107,16 +107,21 @@ public class Unloader extends Block{
return sortItem;
}
@Override
public byte version(){
return 1;
}
@Override
public void write(Writes write){
super.write(write);
write.b(sortItem == null ? -1 : sortItem.id);
write.s(sortItem == null ? -1 : sortItem.id);
}
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
byte id = read.b();
int id = revision == 1 ? read.s() : read.b();
sortItem = id == -1 ? null : content.items().get(id);
}
}
@@ -0,0 +1,98 @@
package mindustry.world.blocks.units;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.scene.style.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.meta.*;
public class CommandCenter extends Block{
public TextureRegionDrawable[] commandRegions = new TextureRegionDrawable[UnitCommand.all.length];
public Color topColor = Pal.command, bottomColor = Color.valueOf("5e5e5e");
public Effect effect = Fx.commandSend;
public CommandCenter(String name){
super(name);
flags = EnumSet.of(BlockFlag.rally);
destructible = true;
solid = true;
configurable = true;
config(UnitCommand.class, (CommandBuild build, UnitCommand command) -> {
build.team.data().command = command;
effect.at(build);
});
}
@Override
public void load(){
super.load();
if(Vars.ui != null){
for(UnitCommand cmd : UnitCommand.all){
commandRegions[cmd.ordinal()] = Vars.ui.getIcon("command" + Strings.capitalize(cmd.name()), "cancel");
}
}
}
public class CommandBuild extends Building{
@Override
public Object config(){
return team.data().command;
}
@Override
public void draw(){
super.draw();
float size = 6f;
Draw.color(bottomColor);
Draw.rect(commandRegions[team.data().command.ordinal()].getRegion(), tile.drawx(), tile.drawy() - 1, size, size);
Draw.color(topColor);
Draw.rect(commandRegions[team.data().command.ordinal()].getRegion(), tile.drawx(), tile.drawy(), size, size);
Draw.color();
}
@Override
public void buildConfiguration(Table table){
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Table buttons = new Table();
for(UnitCommand cmd : UnitCommand.all){
buttons.button(commandRegions[cmd.ordinal()], Styles.clearToggleTransi, () -> {
if(team.data().command != cmd) configure(cmd);
}).size(44).group(group).update(b -> b.setChecked(team.data().command == cmd));
}
table.add(buttons);
table.row();
table.label(() -> team.data().command.localized()).style(Styles.outlineLabel).center().growX().get().setAlignment(Align.center);
}
@Override
public void write(Writes write){
super.write(write);
write.b(team.data().command.ordinal());
}
@Override
public void read(Reads read, byte version){
super.read(read, version);
team.data().command = UnitCommand.all[read.b()];
}
}
}
@@ -223,7 +223,7 @@ public class UnitFactory extends UnitBlock{
if(currentPlan != -1 && !Units.canCreate(team, plans[currentPlan].unit)){
return false;
}
return enabled;
return enabled && payload == null;
}
@Override
+1 -1
View File
@@ -10,7 +10,7 @@ public enum BlockFlag{
turret,
/** Repair point. */
repair,
/** Rally point. TODO remove*/
/** Rally point. */
rally,
/** Any block that boosts unit capacity. */
unitModifier;
@@ -32,6 +32,8 @@ public enum BlockStat{
drillTier(StatCategory.crafting),
drillSpeed(StatCategory.crafting),
maxUnits(StatCategory.crafting),
linkRange(StatCategory.crafting),
instructions(StatCategory.crafting),
speedIncrease(StatCategory.shooting),
repairTime(StatCategory.shooting),
@@ -5,5 +5,12 @@ import arc.util.io.*;
/** A class that represents compartmentalized tile entity state. */
public abstract class BlockModule{
public abstract void write(Writes write);
public abstract void read(Reads read);
public void read(Reads read, boolean legacy){
read(read);
}
public void read(Reads read){
read(read, false);
}
}
@@ -276,30 +276,30 @@ public class ItemModule extends BlockModule{
@Override
public void write(Writes write){
byte amount = 0;
int amount = 0;
for(int item : items){
if(item > 0) amount++;
}
write.b(amount); //amount of items
write.s(amount); //amount of items
for(int i = 0; i < items.length; i++){
if(items[i] > 0){
write.b(i); //item ID
write.s(i); //item ID
write.i(items[i]); //item amount
}
}
}
@Override
public void read(Reads read){
public void read(Reads read, boolean legacy){
//just in case, reset items
Arrays.fill(items, 0);
byte count = read.b();
int count = legacy ? read.ub() : read.s();
total = 0;
for(int j = 0; j < count; j++){
int itemid = read.b();
int itemid = legacy ? read.ub() : read.s();
int itemamount = read.i();
items[content.item(itemid).id] = itemamount;
total += itemamount;
@@ -20,6 +20,7 @@ public class LiquidModule extends BlockModule{
private Liquid current = content.liquid(0);
private float smoothLiquid;
private boolean hadFlow;
private @Nullable WindowedMean flow;
private float lastAdded, currentFlowRate;
@@ -29,6 +30,8 @@ public class LiquidModule extends BlockModule{
if(flowTimer.get(1, pollScl)){
if(flow == null) flow = new WindowedMean(windowSize);
if(lastAdded > 0.0001f) hadFlow = true;
flow.add(lastAdded);
lastAdded = 0;
if(currentFlowRate < 0 || flowTimer.get(updateInterval)){
@@ -38,6 +41,7 @@ public class LiquidModule extends BlockModule{
}else{
currentFlowRate = -1f;
flow = null;
hadFlow = false;
}
}
@@ -46,6 +50,10 @@ public class LiquidModule extends BlockModule{
return currentFlowRate * 60;
}
public boolean hadFlow(){
return hadFlow;
}
public float smoothAmount(){
return smoothLiquid;
}
@@ -114,29 +122,29 @@ public class LiquidModule extends BlockModule{
@Override
public void write(Writes write){
byte amount = 0;
int amount = 0;
for(float liquid : liquids){
if(liquid > 0) amount++;
}
write.b(amount); //amount of liquids
write.s(amount); //amount of liquids
for(int i = 0; i < liquids.length; i++){
if(liquids[i] > 0){
write.b(i); //liquid ID
write.f(liquids[i]); //item amount
write.s(i); //liquid ID
write.f(liquids[i]); //liquid amount
}
}
}
@Override
public void read(Reads read){
public void read(Reads read, boolean legacy){
Arrays.fill(liquids, 0);
total = 0f;
byte count = read.b();
int count = legacy ? read.ub() : read.s();
for(int j = 0; j < count; j++){
int liquidid = read.b();
int liquidid = legacy ? read.ub() : read.s();
float amount = read.f();
liquids[liquidid] = amount;
if(amount > 0){