Merge branch '6.0' of https://github.com/Anuken/Mindustry into object-config
# Conflicts: # core/src/mindustry/entities/traits/BuilderTrait.java # core/src/mindustry/entities/type/TileEntity.java # core/src/mindustry/game/EventType.java # core/src/mindustry/game/Schematics.java # core/src/mindustry/input/InputHandler.java # core/src/mindustry/io/TypeIO.java # core/src/mindustry/world/Block.java # core/src/mindustry/world/blocks/distribution/Sorter.java
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
package mindustry.world;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.Graphics.*;
|
||||
import arc.Graphics.Cursor.*;
|
||||
import arc.audio.*;
|
||||
import arc.struct.EnumSet;
|
||||
import arc.struct.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
@@ -14,15 +11,15 @@ import arc.graphics.g2d.TextureAtlas.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.EnumSet;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.pooling.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.ctype.ContentType;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.effect.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.MultiPacker.*;
|
||||
@@ -103,7 +100,9 @@ public class Block extends BlockStorage{
|
||||
* The color of this block when displayed on the minimap or map preview.
|
||||
* Do not set manually! This is overriden when loading for most blocks.
|
||||
*/
|
||||
public Color color = new Color(0, 0, 0, 1);
|
||||
public Color mapColor = new Color(0, 0, 0, 1);
|
||||
/** Whether this block has a minimap color. */
|
||||
public boolean hasColor = false;
|
||||
/** Whether units target this block. */
|
||||
public boolean targetable = true;
|
||||
/** Whether the overdrive core has any effect on this block. */
|
||||
@@ -143,7 +142,7 @@ public class Block extends BlockStorage{
|
||||
|
||||
protected TextureRegion[] cacheRegions = {};
|
||||
protected Array<String> cacheRegionStrings = new Array<>();
|
||||
protected Prov<TileEntity> entityType = TileEntity::new;
|
||||
protected Prov<Tilec> entityType = TileEntity::create;
|
||||
protected ObjectMap<Class<?>, ConfigHandler> configurations = new ObjectMap<>();
|
||||
|
||||
protected Array<Tile> tempTiles = new Array<>();
|
||||
@@ -163,6 +162,10 @@ public class Block extends BlockStorage{
|
||||
this.solid = false;
|
||||
}
|
||||
|
||||
public boolean isAir(){
|
||||
return id == 0;
|
||||
}
|
||||
|
||||
public boolean canBreak(Tile tile){
|
||||
return true;
|
||||
}
|
||||
@@ -176,7 +179,7 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
public void onProximityRemoved(Tile tile){
|
||||
if(tile.entity.power != null){
|
||||
if(tile.entity.power() != null){
|
||||
tile.block().powerGraphRemoved(tile);
|
||||
}
|
||||
}
|
||||
@@ -186,49 +189,49 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
protected void updatePowerGraph(Tile tile){
|
||||
TileEntity entity = tile.ent();
|
||||
Tilec entity = tile.ent();
|
||||
|
||||
for(Tile other : getPowerConnections(tile, tempTiles)){
|
||||
if(other.entity.power != null){
|
||||
other.entity.power.graph.add(entity.power.graph);
|
||||
if(other.entity.power() != null){
|
||||
other.entity.power().graph.add(entity.power().graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void powerGraphRemoved(Tile tile){
|
||||
if(tile.entity == null || tile.entity.power == null){
|
||||
if(tile.entity == null || tile.entity.power() == null){
|
||||
return;
|
||||
}
|
||||
|
||||
tile.entity.power.graph.remove(tile);
|
||||
for(int i = 0; i < tile.entity.power.links.size; i++){
|
||||
Tile other = world.tile(tile.entity.power.links.get(i));
|
||||
if(other != null && other.entity != null && other.entity.power != null){
|
||||
other.entity.power.links.removeValue(tile.pos());
|
||||
tile.entity.power().graph.remove(tile);
|
||||
for(int i = 0; i < tile.entity.power().links.size; i++){
|
||||
Tile other = world.tile(tile.entity.power().links.get(i));
|
||||
if(other != null && other.entity != null && other.entity.power() != null){
|
||||
other.entity.power().links.removeValue(tile.pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Array<Tile> getPowerConnections(Tile tile, Array<Tile> out){
|
||||
out.clear();
|
||||
if(tile == null || tile.entity == null || tile.entity.power == null) return out;
|
||||
if(tile == null || tile.entity == null || tile.entity.power() == null) return out;
|
||||
|
||||
for(Tile other : tile.entity.proximity()){
|
||||
if(other != null && other.entity != null && other.entity.power != null
|
||||
if(other != null && other.entity != null && other.entity.power() != null
|
||||
&& !(consumesPower && other.block().consumesPower && !outputsPower && !other.block().outputsPower)
|
||||
&& !tile.entity.power.links.contains(other.pos())){
|
||||
&& !tile.entity.power().links.contains(other.pos())){
|
||||
out.add(other);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < tile.entity.power.links.size; i++){
|
||||
Tile link = world.tile(tile.entity.power.links.get(i));
|
||||
if(link != null && link.entity != null && link.entity.power != null) out.add(link);
|
||||
for(int i = 0; i < tile.entity.power().links.size; i++){
|
||||
Tile link = world.tile(tile.entity.power().links.get(i));
|
||||
if(link != null && link.entity != null && link.entity.power() != null) out.add(link);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
protected float getProgressIncrease(TileEntity entity, float baseTime){
|
||||
protected float getProgressIncrease(Tilec entity, float baseTime){
|
||||
return 1f / baseTime * entity.delta() * entity.efficiency();
|
||||
}
|
||||
|
||||
@@ -300,8 +303,8 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
public void drawLight(Tile tile){
|
||||
if(tile.entity != null && hasLiquids && drawLiquidLight && tile.entity.liquids.current().lightColor.a > 0.001f){
|
||||
drawLiquidLight(tile, tile.entity.liquids.current(), tile.entity.liquids.smoothAmount());
|
||||
if(tile.entity != null && hasLiquids && drawLiquidLight && tile.entity.liquids().current().lightColor.a > 0.001f){
|
||||
drawLiquidLight(tile, tile.entity.liquids().current(), tile.entity.liquids().smoothAmount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +320,7 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
public void drawTeam(Tile tile){
|
||||
Draw.color(tile.getTeam().color);
|
||||
Draw.color(tile.team().color);
|
||||
Draw.rect("block-border", tile.drawx() - size * tilesize / 2f + 4, tile.drawy() - size * tilesize / 2f + 4);
|
||||
Draw.color();
|
||||
}
|
||||
@@ -339,14 +342,14 @@ public class Block extends BlockStorage{
|
||||
Geometry.circle(tile.x, tile.y, range, (x, y) -> {
|
||||
Tile other = world.ltile(x, y);
|
||||
if(other != null && other.block instanceof PowerNode && ((PowerNode)other.block).linkValid(other, tile) && !PowerNode.insulated(other, tile) && !other.entity.proximity().contains(tile) &&
|
||||
!(outputsPower && tile.entity.proximity().contains(p -> p.entity != null && p.entity.power != null && p.entity.power.graph == other.entity.power.graph))){
|
||||
!(outputsPower && tile.entity.proximity().contains(p -> p.entity != null && p.entity.power() != null && p.entity.power().graph == other.entity.power().graph))){
|
||||
tempTiles.add(other);
|
||||
}
|
||||
});
|
||||
tempTiles.sort(Structs.comparingFloat(t -> t.dst2(tile)));
|
||||
if(!tempTiles.isEmpty()){
|
||||
Tile toLink = tempTiles.first();
|
||||
if(!toLink.entity.power.links.contains(tile.pos())){
|
||||
if(!toLink.entity.power().links.contains(tile.pos())){
|
||||
toLink.configureAny(tile.pos());
|
||||
}
|
||||
}
|
||||
@@ -357,11 +360,11 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
/** Called every frame a unit is on this tile. */
|
||||
public void unitOn(Tile tile, Unit unit){
|
||||
public void unitOn(Tile tile, Unitc unit){
|
||||
}
|
||||
|
||||
/** Called when a unit that spawned at this tile is removed. */
|
||||
public void unitRemoved(Tile tile, Unit unit){
|
||||
public void unitRemoved(Tile tile, Unitc unit){
|
||||
}
|
||||
|
||||
/** Returns whether ot not this block can be place on the specified tile. */
|
||||
@@ -372,7 +375,7 @@ public class Block extends BlockStorage{
|
||||
/** Call when some content is produced. This unlocks the content if it is applicable. */
|
||||
public void useContent(Tile tile, UnlockableContent content){
|
||||
//only unlocks content in zones
|
||||
if(!headless && tile.getTeam() == player.getTeam() && world.isZone()){
|
||||
if(!headless && tile.team() == player.team() && state.isCampaign()){
|
||||
logic.handleContent(content);
|
||||
}
|
||||
}
|
||||
@@ -467,12 +470,12 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
/** Called when the block is tapped. This is equivalent to being configured with null. */
|
||||
public void tapped(Tile tile, Player player){
|
||||
public void tapped(Tile tile, Playerc player){
|
||||
|
||||
}
|
||||
|
||||
/** Called when arbitrary configuration is applied to a tile. */
|
||||
public void configured(Tile tile, @Nullable Player player, @Nullable Object value){
|
||||
public void configured(Tile tile, @Nullable Playerc player, @Nullable Object value){
|
||||
if(value == null){
|
||||
tapped(tile, player);
|
||||
}else if(configurations.containsKey(value.getClass())){
|
||||
@@ -511,12 +514,12 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
/** Returns whether this config menu should show when the specified player taps it. */
|
||||
public boolean shouldShowConfigure(Tile tile, Player player){
|
||||
public boolean shouldShowConfigure(Tile tile, Playerc player){
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Whether this configuration should be hidden now. Called every frame the config is open. */
|
||||
public boolean shouldHideConfigure(Tile tile, Player player){
|
||||
public boolean shouldHideConfigure(Tile tile, Playerc player){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -550,15 +553,15 @@ public class Block extends BlockStorage{
|
||||
bars.add("health", entity -> new Bar("blocks.health", Pal.health, entity::healthf).blink(Color.white));
|
||||
|
||||
if(hasLiquids){
|
||||
Func<TileEntity, Liquid> current;
|
||||
Func<Tilec, Liquid> current;
|
||||
if(consumes.has(ConsumeType.liquid) && consumes.get(ConsumeType.liquid) instanceof ConsumeLiquid){
|
||||
Liquid liquid = consumes.<ConsumeLiquid>get(ConsumeType.liquid).liquid;
|
||||
current = entity -> liquid;
|
||||
}else{
|
||||
current = entity -> entity.liquids.current();
|
||||
current = entity -> entity.liquids().current();
|
||||
}
|
||||
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName,
|
||||
() -> current.get(entity).barColor(), () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
|
||||
bars.add("liquid", entity -> new Bar(() -> entity.liquids().get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName,
|
||||
() -> current.get(entity).barColor(), () -> entity.liquids().get(current.get(entity)) / liquidCapacity));
|
||||
}
|
||||
|
||||
if(hasPower && consumes.hasPower()){
|
||||
@@ -566,12 +569,12 @@ public class Block extends BlockStorage{
|
||||
boolean buffered = cons.buffered;
|
||||
float capacity = cons.capacity;
|
||||
|
||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.status * capacity) ? "<ERROR>" : (int)(entity.power.status * capacity)) :
|
||||
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.status));
|
||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power().status * capacity) ? "<ERROR>" : (int)(entity.power().status * capacity)) :
|
||||
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.power().graph.getPowerProduced() + entity.power().graph.getBatteryStored() > 0f ? 1f : entity.power().status));
|
||||
}
|
||||
|
||||
if(hasItems && configurable){
|
||||
bars.add("items", entity -> new Bar(() -> Core.bundle.format("bar.items", entity.items.total()), () -> Pal.items, () -> (float)entity.items.total() / itemCapacity));
|
||||
bars.add("items", entity -> new Bar(() -> Core.bundle.format("bar.items", entity.items().total()), () -> Pal.items, () -> (float)entity.items().total() / itemCapacity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,7 +599,7 @@ public class Block extends BlockStorage{
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void handleBulletHit(TileEntity entity, Bullet bullet){
|
||||
public void handleBulletHit(Tilec entity, Bulletc bullet){
|
||||
entity.damage(bullet.damage());
|
||||
}
|
||||
|
||||
@@ -616,31 +619,31 @@ public class Block extends BlockStorage{
|
||||
|
||||
if(hasItems){
|
||||
for(Item item : content.items()){
|
||||
int amount = tile.entity.items.get(item);
|
||||
int amount = tile.entity.items().get(item);
|
||||
explosiveness += item.explosiveness * amount;
|
||||
flammability += item.flammability * amount;
|
||||
}
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
flammability += tile.entity.liquids.sum((liquid, amount) -> liquid.explosiveness * amount / 2f);
|
||||
explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 2f);
|
||||
flammability += tile.entity.liquids().sum((liquid, amount) -> liquid.explosiveness * amount / 2f);
|
||||
explosiveness += tile.entity.liquids().sum((liquid, amount) -> liquid.flammability * amount / 2f);
|
||||
}
|
||||
|
||||
if(consumes.hasPower() && consumes.getPower().buffered){
|
||||
power += tile.entity.power.status * consumes.getPower().capacity;
|
||||
power += tile.entity.power().status * consumes.getPower().capacity;
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
|
||||
tile.entity.liquids.each((liquid, amount) -> {
|
||||
tile.entity.liquids().each((liquid, amount) -> {
|
||||
float splash = Mathf.clamp(amount / 4f, 0f, 10f);
|
||||
|
||||
for(int i = 0; i < Mathf.clamp(amount / 5, 0, 30); i++){
|
||||
Time.run(i / 2f, () -> {
|
||||
Tile other = world.tile(tile.x + Mathf.range(size / 2), tile.y + Mathf.range(size / 2));
|
||||
if(other != null){
|
||||
Puddle.deposit(other, liquid, splash);
|
||||
Puddles.deposit(other, liquid, splash);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -649,7 +652,7 @@ public class Block extends BlockStorage{
|
||||
|
||||
Damage.dynamicExplosion(x, y, flammability, explosiveness * 3.5f, power, tilesize * size / 2f, Pal.darkFlame);
|
||||
if(!tile.floor().solid && !tile.floor().isLiquid){
|
||||
RubbleDecal.create(tile.drawx(), tile.drawy(), size);
|
||||
Effects.rubble(tile.drawx(), tile.drawy(), size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,10 +667,10 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
return 0;
|
||||
}else{
|
||||
float result = tile.entity.items.sum((item, amount) -> item.flammability * amount);
|
||||
float result = tile.entity.items().sum((item, amount) -> item.flammability * amount);
|
||||
|
||||
if(hasLiquids){
|
||||
result += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 3f);
|
||||
result += tile.entity.liquids().sum((liquid, amount) -> liquid.flammability * amount / 3f);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -683,7 +686,7 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
public void display(Tile tile, Table table){
|
||||
TileEntity entity = tile.entity;
|
||||
Tilec entity = tile.entity;
|
||||
|
||||
if(entity != null){
|
||||
table.table(bars -> {
|
||||
@@ -709,7 +712,7 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
public void displayBars(Tile tile, Table table){
|
||||
for(Func<TileEntity, Bar> bar : bars.list()){
|
||||
for(Func<Tilec, Bar> bar : bars.list()){
|
||||
table.add(bar.get(tile.entity)).growX();
|
||||
table.row();
|
||||
}
|
||||
@@ -769,7 +772,7 @@ public class Block extends BlockStorage{
|
||||
|
||||
if(!synthetic()){
|
||||
PixmapRegion image = Core.atlas.getPixmap((AtlasRegion)icon(Cicon.full));
|
||||
color.set(image.getPixel(image.width/2, image.height/2));
|
||||
mapColor.set(image.getPixel(image.width/2, image.height/2));
|
||||
}
|
||||
|
||||
getGeneratedIcons();
|
||||
@@ -864,7 +867,7 @@ public class Block extends BlockStorage{
|
||||
return destructible || update;
|
||||
}
|
||||
|
||||
public final TileEntity newEntity(){
|
||||
public final Tilec newEntity(){
|
||||
return entityType.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
package mindustry.world;
|
||||
|
||||
import arc.struct.Array;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.Vars;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.entities.Effects;
|
||||
import mindustry.entities.effect.Puddle;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.entities.type.Unit;
|
||||
import mindustry.ctype.UnlockableContent;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.type.Liquid;
|
||||
import mindustry.world.consumers.Consumers;
|
||||
import mindustry.world.meta.BlockBars;
|
||||
import mindustry.world.meta.BlockStats;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public abstract class BlockStorage extends UnlockableContent{
|
||||
public boolean hasItems;
|
||||
@@ -51,9 +47,9 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
}
|
||||
|
||||
/** Returns the amount of items this block can accept. */
|
||||
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
||||
if(acceptItem(item, tile, tile) && hasItems && (source == null || source.getTeam() == tile.getTeam())){
|
||||
return Math.min(getMaximumAccepted(tile, item) - tile.entity.items.get(item), amount);
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
if(acceptItem(item, tile, tile) && hasItems && (source == null || source.team() == tile.team())){
|
||||
return Math.min(getMaximumAccepted(tile, item) - tile.entity.items().get(item), amount);
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
@@ -65,17 +61,17 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
|
||||
/** Remove a stack from this inventory, and return the amount removed. */
|
||||
public int removeStack(Tile tile, Item item, int amount){
|
||||
if(tile.entity == null || tile.entity.items == null) return 0;
|
||||
amount = Math.min(amount, tile.entity.items.get(item));
|
||||
if(tile.entity == null || tile.entity.items() == null) return 0;
|
||||
amount = Math.min(amount, tile.entity.items().get(item));
|
||||
tile.entity.noSleep();
|
||||
tile.entity.items.remove(item, amount);
|
||||
tile.entity.items().remove(item, amount);
|
||||
return amount;
|
||||
}
|
||||
|
||||
/** Handle a stack input. */
|
||||
public void handleStack(Item item, int amount, Tile tile, Unit source){
|
||||
public void handleStack(Item item, int amount, Tile tile, Teamc source){
|
||||
tile.entity.noSleep();
|
||||
tile.entity.items.add(item, amount);
|
||||
tile.entity.items().add(item, amount);
|
||||
}
|
||||
|
||||
public boolean outputsItems(){
|
||||
@@ -92,19 +88,19 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
}
|
||||
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
tile.entity.items.add(item, 1);
|
||||
tile.entity.items().add(item, 1);
|
||||
}
|
||||
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return consumes.itemFilters.get(item.id) && tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
return consumes.itemFilters.get(item.id) && tile.entity.items().get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return hasLiquids && tile.entity.liquids.get(liquid) + amount < liquidCapacity && consumes.liquidfilters.get(liquid.id);
|
||||
return hasLiquids && tile.entity.liquids().get(liquid) + amount < liquidCapacity && consumes.liquidfilters.get(liquid.id);
|
||||
}
|
||||
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
tile.entity.liquids.add(liquid, amount);
|
||||
tile.entity.liquids().add(liquid, amount);
|
||||
}
|
||||
|
||||
public void tryDumpLiquid(Tile tile, Liquid liquid){
|
||||
@@ -118,9 +114,9 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
|
||||
other = other.block().getLiquidDestination(other, in, liquid);
|
||||
|
||||
if(other != null && other.getTeam() == tile.getTeam() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid) && other.entity.liquids != null){
|
||||
float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity;
|
||||
float fract = tile.entity.liquids.get(liquid) / liquidCapacity;
|
||||
if(other != null && other.team() == tile.team() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid) && other.entity.liquids() != null){
|
||||
float ofract = other.entity.liquids().get(liquid) / other.block().liquidCapacity;
|
||||
float fract = tile.entity.liquids().get(liquid) / liquidCapacity;
|
||||
|
||||
if(ofract < fract) tryMoveLiquid(tile, in, other, (fract - ofract) * liquidCapacity / 2f, liquid);
|
||||
}
|
||||
@@ -133,11 +129,11 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
}
|
||||
|
||||
public void tryMoveLiquid(Tile tile, Tile tileSource, Tile next, float amount, Liquid liquid){
|
||||
float flow = Math.min(next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f, amount);
|
||||
float flow = Math.min(next.block().liquidCapacity - next.entity.liquids().get(liquid) - 0.001f, amount);
|
||||
|
||||
if(next.block().acceptLiquid(next, tileSource, liquid, flow)){
|
||||
next.block().handleLiquid(next, tileSource, liquid, flow);
|
||||
tile.entity.liquids.remove(liquid, flow);
|
||||
tile.entity.liquids().remove(liquid, flow);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,38 +147,38 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
next = next.link();
|
||||
next = next.block().getLiquidDestination(next, tile, liquid);
|
||||
|
||||
if(next.getTeam() == tile.getTeam() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
|
||||
if(next.team() == tile.team() && next.block().hasLiquids && tile.entity.liquids().get(liquid) > 0f){
|
||||
|
||||
if(next.block().acceptLiquid(next, tile, liquid, 0f)){
|
||||
float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity;
|
||||
float fract = tile.entity.liquids.get(liquid) / liquidCapacity * liquidPressure;
|
||||
float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.liquids.get(liquid));
|
||||
flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f);
|
||||
float ofract = next.entity.liquids().get(liquid) / next.block().liquidCapacity;
|
||||
float fract = tile.entity.liquids().get(liquid) / liquidCapacity * liquidPressure;
|
||||
float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.liquids().get(liquid));
|
||||
flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids().get(liquid) - 0.001f);
|
||||
|
||||
if(flow > 0f && ofract <= fract && next.block().acceptLiquid(next, tile, liquid, flow)){
|
||||
next.block().handleLiquid(next, tile, liquid, flow);
|
||||
tile.entity.liquids.remove(liquid, flow);
|
||||
tile.entity.liquids().remove(liquid, flow);
|
||||
return flow;
|
||||
}else if(ofract > 0.1f && fract > 0.1f){
|
||||
Liquid other = next.entity.liquids.current();
|
||||
Liquid other = next.entity.liquids().current();
|
||||
if((other.flammability > 0.3f && liquid.temperature > 0.7f) || (liquid.flammability > 0.3f && other.temperature > 0.7f)){
|
||||
tile.entity.damage(1 * Time.delta());
|
||||
next.entity.damage(1 * Time.delta());
|
||||
if(Mathf.chance(0.1 * Time.delta())){
|
||||
Effects.effect(Fx.fire, (tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f);
|
||||
Fx.fire.at((tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f);
|
||||
}
|
||||
}else if((liquid.temperature > 0.7f && other.temperature < 0.55f) || (other.temperature > 0.7f && liquid.temperature < 0.55f)){
|
||||
tile.entity.liquids.remove(liquid, Math.min(tile.entity.liquids.get(liquid), 0.7f * Time.delta()));
|
||||
tile.entity.liquids().remove(liquid, Math.min(tile.entity.liquids().get(liquid), 0.7f * Time.delta()));
|
||||
if(Mathf.chance(0.2f * Time.delta())){
|
||||
Effects.effect(Fx.steam, (tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f);
|
||||
Fx.steam.at((tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(leakResistance != 100f && !next.block().solid && !next.block().hasLiquids){
|
||||
float leakAmount = tile.entity.liquids.get(liquid) / leakResistance;
|
||||
Puddle.deposit(next, tile, liquid, leakAmount);
|
||||
tile.entity.liquids.remove(liquid, leakAmount);
|
||||
float leakAmount = tile.entity.liquids().get(liquid) / leakResistance;
|
||||
Puddles.deposit(next, tile, liquid, leakAmount);
|
||||
tile.entity.liquids().remove(liquid, leakAmount);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -203,7 +199,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
incrementDump(tile, proximity.size);
|
||||
Tile other = proximity.get((i + dump) % proximity.size);
|
||||
Tile in = Edges.getFacingEdge(tile, other);
|
||||
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
if(other.team() == tile.team() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
return;
|
||||
}
|
||||
@@ -222,8 +218,8 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
* @param todump Item to dump. Can be null to dump anything.
|
||||
*/
|
||||
public boolean tryDump(Tile tile, Item todump){
|
||||
TileEntity entity = tile.entity;
|
||||
if(entity == null || !hasItems || tile.entity.items.total() == 0 || (todump != null && !entity.items.has(todump)))
|
||||
Tilec entity = tile.entity;
|
||||
if(entity == null || !hasItems || tile.entity.items().total() == 0 || (todump != null && !entity.items().has(todump)))
|
||||
return false;
|
||||
|
||||
Array<Tile> proximity = entity.proximity();
|
||||
@@ -240,18 +236,18 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
for(int ii = 0; ii < Vars.content.items().size; ii++){
|
||||
Item item = Vars.content.item(ii);
|
||||
|
||||
if(other.getTeam() == tile.getTeam() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
if(other.team() == tile.team() && entity.items().has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
tile.entity.items.remove(item, 1);
|
||||
tile.entity.items().remove(item, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
||||
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||
if(other.team() == tile.team() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||
other.block().handleItem(todump, other, in);
|
||||
tile.entity.items.remove(todump, 1);
|
||||
tile.entity.items().remove(todump, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
return true;
|
||||
}
|
||||
@@ -274,9 +270,8 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
|
||||
/** Try offloading an item to a nearby container in its facing direction. Returns true if success. */
|
||||
public boolean offloadDir(Tile tile, Item item){
|
||||
Tile other = tile.getNearby(tile.rotation());
|
||||
if(other != null) other = other.link();
|
||||
if(other != null && other.getTeam() == tile.getTeam() && other.block().acceptItem(item, other, tile)){
|
||||
Tile other = tile.front();
|
||||
if(other != null && other.team() == tile.team() && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Build{
|
||||
|
||||
tile.set(sub, team, rotation);
|
||||
tile.<BuildEntity>ent().setDeconstruct(previous);
|
||||
tile.entity.health = tile.entity.maxHealth() * prevPercent;
|
||||
tile.entity.health(tile.entity.maxHealth() * prevPercent);
|
||||
|
||||
Core.app.post(() -> Events.fire(new BlockBuildBeginEvent(tile, team, true)));
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class Build{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(state.teams.eachEnemyCore(team, core -> Mathf.dst(x * tilesize + type.offset(), y * tilesize + type.offset(), core.x, core.y) < state.rules.enemyCoreBuildRadius + type.size * tilesize / 2f)){
|
||||
if(state.teams.eachEnemyCore(team, core -> Mathf.dst(x * tilesize + type.offset(), y * tilesize + type.offset(), core.x(), core.y()) < state.rules.enemyCoreBuildRadius + type.size * tilesize / 2f)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,11 @@ public class Build{
|
||||
|
||||
if(tile == null) return false;
|
||||
|
||||
//ca check
|
||||
if(world.getDarkness(x, y) >= 3){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(type.isMultiblock()){
|
||||
if(type.canReplace(tile.block()) && tile.block().size == type.size && type.canPlaceOn(tile) && tile.interactable(team)){
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package mindustry.world;
|
||||
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.game.Team;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class CachedTile extends Tile{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Team getTeam(){
|
||||
public Team team(){
|
||||
return Team.get(getTeamID());
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ public class CachedTile extends Tile{
|
||||
Block block = block();
|
||||
|
||||
if(block.hasEntity()){
|
||||
TileEntity n = block.newEntity();
|
||||
n.cons = new ConsumeModule(entity);
|
||||
n.tile = this;
|
||||
n.block = block;
|
||||
if(block.hasItems) n.items = new ItemModule();
|
||||
if(block.hasLiquids) n.liquids = new LiquidModule();
|
||||
if(block.hasPower) n.power = new PowerModule();
|
||||
Tilec n = block.newEntity();
|
||||
n.cons(new ConsumeModule(entity));
|
||||
n.tile(this);
|
||||
n.block(block);
|
||||
if(block.hasItems) n.items(new ItemModule());
|
||||
if(block.hasLiquids) n.liquids(new LiquidModule());
|
||||
if(block.hasPower) n.power(new PowerModule());
|
||||
entity = n;
|
||||
}
|
||||
}
|
||||
|
||||
24
core/src/mindustry/world/ColorMapper.java
Normal file
24
core/src/mindustry/world/ColorMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package mindustry.world;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
|
||||
public class ColorMapper{
|
||||
private static final IntMap<Block> color2block = new IntMap<>();
|
||||
|
||||
public static Block get(int color){
|
||||
return color2block.get(color, Blocks.air);
|
||||
}
|
||||
|
||||
public static void load(){
|
||||
color2block.clear();
|
||||
|
||||
for(Block block : Vars.content.blocks()){
|
||||
color2block.put(block.mapColor.rgba(), block);
|
||||
}
|
||||
|
||||
color2block.put(Color.rgba8888(0, 0, 0, 1), Blocks.air);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package mindustry.world;
|
||||
|
||||
import mindustry.annotations.Annotations.Struct;
|
||||
import arc.util.Time;
|
||||
import mindustry.gen.BufferItem;
|
||||
import mindustry.type.Item;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -46,22 +47,22 @@ public class DirectionalItemBuffer{
|
||||
indexes[buffer] --;
|
||||
}
|
||||
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
public void write(Writes write){
|
||||
for(int i = 0; i < 4; i++){
|
||||
stream.writeByte(indexes[i]);
|
||||
stream.writeByte(buffers[i].length);
|
||||
write.b(indexes[i]);
|
||||
write.b(buffers[i].length);
|
||||
for(long l : buffers[i]){
|
||||
stream.writeLong(l);
|
||||
write.l(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void read(DataInput stream) throws IOException{
|
||||
public void read(Reads read){
|
||||
for(int i = 0; i < 4; i++){
|
||||
indexes[i] = stream.readByte();
|
||||
byte length = stream.readByte();
|
||||
indexes[i] = read.b();
|
||||
byte length = read.b();
|
||||
for(int j = 0; j < length; j++){
|
||||
long value = stream.readLong();
|
||||
long value = read.l();
|
||||
if(j < buffers[i].length){
|
||||
buffers[i][j] = value;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package mindustry.world;
|
||||
|
||||
import arc.util.*;
|
||||
import mindustry.type.Item;
|
||||
|
||||
import java.io.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
@@ -60,19 +59,19 @@ public class ItemBuffer{
|
||||
index--;
|
||||
}
|
||||
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeByte((byte)index);
|
||||
stream.writeByte((byte)buffer.length);
|
||||
public void write(Writes write){
|
||||
write.b((byte)index);
|
||||
write.b((byte)buffer.length);
|
||||
for(long l : buffer){
|
||||
stream.writeLong(l);
|
||||
write.l(l);
|
||||
}
|
||||
}
|
||||
|
||||
public void read(DataInput stream) throws IOException{
|
||||
index = stream.readByte();
|
||||
byte length = stream.readByte();
|
||||
public void read(Reads read){
|
||||
index = read.b();
|
||||
byte length = read.b();
|
||||
for(int i = 0; i < length; i++){
|
||||
long l = stream.readLong();
|
||||
long l = read.l();
|
||||
if(i < buffer.length){
|
||||
buffer[i] = l;
|
||||
}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package mindustry.world;
|
||||
|
||||
import arc.struct.IntMap;
|
||||
import arc.graphics.Color;
|
||||
import mindustry.content.Blocks;
|
||||
import mindustry.ctype.ContentList;
|
||||
import mindustry.world.blocks.Floor;
|
||||
|
||||
public class LegacyColorMapper implements ContentList{
|
||||
private static IntMap<LegacyBlock> blockMap = new IntMap<>();
|
||||
private static LegacyBlock defaultValue;
|
||||
|
||||
public static LegacyBlock get(int color){
|
||||
return blockMap.get(color, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
defaultValue = new LegacyBlock(Blocks.stone, Blocks.air);
|
||||
|
||||
map("ff0000", Blocks.stone, Blocks.air, Blocks.spawn);
|
||||
map("00ff00", Blocks.stone);
|
||||
map("323232", Blocks.stone);
|
||||
map("646464", Blocks.stone, Blocks.rocks);
|
||||
map("50965a", Blocks.grass);
|
||||
map("5ab464", Blocks.grass, Blocks.pine);
|
||||
map("506eb4", Blocks.water);
|
||||
map("465a96", Blocks.deepwater);
|
||||
map("252525", Blocks.ignarock);
|
||||
map("575757", Blocks.ignarock, Blocks.duneRocks);
|
||||
map("988a67", Blocks.sand);
|
||||
map("e5d8bb", Blocks.sand, Blocks.duneRocks);
|
||||
map("c2d1d2", Blocks.snow);
|
||||
map("c4e3e7", Blocks.ice);
|
||||
map("f7feff", Blocks.snow, Blocks.snowrocks);
|
||||
map("6e501e", Blocks.holostone);
|
||||
map("ed5334", Blocks.magmarock);
|
||||
map("292929", Blocks.tar);
|
||||
map("c3a490", Blocks.stone, Blocks.air, Blocks.oreCopper);
|
||||
map("161616", Blocks.stone, Blocks.air, Blocks.oreCoal);
|
||||
map("6277bc", Blocks.stone, Blocks.air, Blocks.oreTitanium);
|
||||
map("83bc58", Blocks.stone, Blocks.air, Blocks.oreThorium);
|
||||
}
|
||||
|
||||
private void map(String color, Block block, Block wall, Block ore){
|
||||
blockMap.put(Color.rgba8888(Color.valueOf(color)), new LegacyBlock(block, wall, ore));
|
||||
}
|
||||
|
||||
private void map(String color, Block block, Block wall){
|
||||
blockMap.put(Color.rgba8888(Color.valueOf(color)), new LegacyBlock(block, wall));
|
||||
}
|
||||
|
||||
private void map(String color, Block block){
|
||||
blockMap.put(Color.rgba8888(Color.valueOf(color)), new LegacyBlock(block, Blocks.air));
|
||||
}
|
||||
|
||||
public static class LegacyBlock{
|
||||
public final Floor floor;
|
||||
public final Block wall;
|
||||
public final Block ore;
|
||||
|
||||
public LegacyBlock(Block floor, Block wall){
|
||||
this(floor, wall, Blocks.air);
|
||||
}
|
||||
|
||||
public LegacyBlock(Block floor, Block wall, Block ore){
|
||||
this.floor = (Floor)floor;
|
||||
this.wall = wall;
|
||||
this.ore = ore;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.traits.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
@@ -17,15 +15,15 @@ import mindustry.world.modules.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Tile implements Position, TargetTrait{
|
||||
public class Tile implements Position{
|
||||
/** Tile traversal cost. */
|
||||
public byte cost = 1;
|
||||
/** Tile entity, usually null. */
|
||||
public TileEntity entity;
|
||||
public Tilec entity;
|
||||
public short x, y;
|
||||
protected Block block;
|
||||
protected Floor floor;
|
||||
protected Floor overlay;
|
||||
protected @NonNull Block block;
|
||||
protected @NonNull Floor floor;
|
||||
protected @NonNull Floor overlay;
|
||||
/** Rotation, 0-3. Also used to store offload location, in which case it can be any number.*/
|
||||
protected byte rotation;
|
||||
/** Team ordinal. */
|
||||
@@ -37,17 +35,21 @@ public class Tile implements Position, TargetTrait{
|
||||
block = floor = overlay = (Floor)Blocks.air;
|
||||
}
|
||||
|
||||
public Tile(int x, int y, int floor, int overlay, int wall){
|
||||
public Tile(int x, int y, Block floor, Block overlay, Block wall){
|
||||
this.x = (short)x;
|
||||
this.y = (short)y;
|
||||
this.floor = (Floor)content.block(floor);
|
||||
this.overlay = (Floor)content.block(overlay);
|
||||
this.block = content.block(wall);
|
||||
this.floor = (Floor)floor;
|
||||
this.overlay = (Floor)overlay;
|
||||
this.block = wall;
|
||||
|
||||
//update entity and create it if needed
|
||||
changed();
|
||||
}
|
||||
|
||||
public Tile(int x, int y, int floor, int overlay, int wall){
|
||||
this(x, y, content.block(floor), content.block(overlay), content.block(wall));
|
||||
}
|
||||
|
||||
/** Returns this tile's position as a {@link Pos}. */
|
||||
public int pos(){
|
||||
return Pos.get(x, y);
|
||||
@@ -121,7 +123,7 @@ public class Tile implements Position, TargetTrait{
|
||||
}
|
||||
|
||||
public boolean isDarkened(){
|
||||
return block().solid && !block().synthetic() && block().fillsTile;
|
||||
return block.solid && !block.synthetic() && block.fillsTile;
|
||||
}
|
||||
|
||||
public @NonNull Floor floor(){
|
||||
@@ -141,8 +143,7 @@ public class Tile implements Position, TargetTrait{
|
||||
return (T)block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Team getTeam(){
|
||||
public Team team(){
|
||||
return Team.get(link().team);
|
||||
}
|
||||
|
||||
@@ -174,10 +175,13 @@ public class Tile implements Position, TargetTrait{
|
||||
changed();
|
||||
}
|
||||
|
||||
/**This resets the overlay!*/
|
||||
/** This resets the overlay! */
|
||||
public void setFloor(@NonNull Floor type){
|
||||
this.floor = type;
|
||||
this.overlay = (Floor)Blocks.air;
|
||||
|
||||
recache();
|
||||
block.onProximityUpdate(this);
|
||||
}
|
||||
|
||||
/** Sets the floor, preserving overlay.*/
|
||||
@@ -187,6 +191,19 @@ public class Tile implements Position, TargetTrait{
|
||||
setOverlay(overlay);
|
||||
}
|
||||
|
||||
public void recache(){
|
||||
if(!headless && !world.isGenerating()){
|
||||
renderer.blocks.floor.recacheTile(this);
|
||||
renderer.minimap.update(this);
|
||||
for(int i = 0; i < 8; i++){
|
||||
Tile other = world.tile(x + Geometry.d8[i].x, y + Geometry.d8[i].y);
|
||||
if(other != null){
|
||||
renderer.blocks.floor.recacheTile(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
link().getLinkedTiles(other -> other.setBlock(Blocks.air));
|
||||
}
|
||||
@@ -226,6 +243,16 @@ public class Tile implements Position, TargetTrait{
|
||||
Call.setTile(this, block, team, rotation);
|
||||
}
|
||||
|
||||
/** set()-s this tile, except it's synced across the network */
|
||||
public void setFloorNet(Block floor, Block overlay){
|
||||
Call.setFloor(this, floor, overlay);
|
||||
}
|
||||
|
||||
/** set()-s this tile, except it's synced across the network */
|
||||
public void setFloorNet(Block floor){
|
||||
setFloorNet(floor, Blocks.air);
|
||||
}
|
||||
|
||||
public byte rotation(){
|
||||
return rotation;
|
||||
}
|
||||
@@ -280,7 +307,7 @@ public class Tile implements Position, TargetTrait{
|
||||
}
|
||||
|
||||
public boolean isEnemyCheat(){
|
||||
return getTeam() == state.rules.waveTeam && state.rules.enemyCheat;
|
||||
return team() == state.rules.waveTeam && state.rules.enemyCheat;
|
||||
}
|
||||
|
||||
public boolean isLinked(){
|
||||
@@ -384,7 +411,7 @@ public class Tile implements Position, TargetTrait{
|
||||
}
|
||||
|
||||
public boolean interactable(Team team){
|
||||
return state.teams.canInteract(team, getTeam());
|
||||
return state.teams.canInteract(team, team());
|
||||
}
|
||||
|
||||
public @Nullable Item drop(){
|
||||
@@ -440,10 +467,14 @@ public class Tile implements Position, TargetTrait{
|
||||
}
|
||||
|
||||
protected void preChanged(){
|
||||
block().removed(this);
|
||||
block.removed(this);
|
||||
if(entity != null){
|
||||
entity.removeFromProximity();
|
||||
}
|
||||
//recache when static blocks get changed
|
||||
if(block.isStatic()){
|
||||
recache();
|
||||
}
|
||||
team = 0;
|
||||
}
|
||||
|
||||
@@ -457,12 +488,12 @@ public class Tile implements Position, TargetTrait{
|
||||
|
||||
if(block.hasEntity()){
|
||||
entity = block.newEntity().init(this, block.update);
|
||||
entity.cons = new ConsumeModule(entity);
|
||||
if(block.hasItems) entity.items = new ItemModule();
|
||||
if(block.hasLiquids) entity.liquids = new LiquidModule();
|
||||
entity.cons(new ConsumeModule(entity));
|
||||
if(block.hasItems) entity.items(new ItemModule());
|
||||
if(block.hasLiquids) entity.liquids(new LiquidModule());
|
||||
if(block.hasPower){
|
||||
entity.power = new PowerModule();
|
||||
entity.power.graph.add(this);
|
||||
entity.power(new PowerModule());
|
||||
entity.power().graph.add(this);
|
||||
}
|
||||
|
||||
if(!world.isGenerating()){
|
||||
@@ -481,16 +512,11 @@ public class Tile implements Position, TargetTrait{
|
||||
updateOcclusion();
|
||||
|
||||
world.notifyChanged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDead(){
|
||||
return entity == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2 velocity(){
|
||||
return Vec2.ZERO;
|
||||
//recache when static block is added
|
||||
if(block.isStatic()){
|
||||
recache();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -498,28 +524,24 @@ public class Tile implements Position, TargetTrait{
|
||||
return drawx();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setX(float x){
|
||||
throw new IllegalArgumentException("Tile position cannot change.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getY(){
|
||||
return drawy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setY(float y){
|
||||
throw new IllegalArgumentException("Tile position cannot change.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return floor.name + ":" + block.name + ":" + overlay + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) + ":" + getTeam();
|
||||
return floor.name + ":" + block.name + ":" + overlay + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) + ":" + team();
|
||||
}
|
||||
|
||||
//remote utility methods
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void setFloor(Tile tile, Block floor, Block overlay){
|
||||
tile.setFloor(floor.asFloor());
|
||||
tile.setOverlay(overlay);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void removeTile(Tile tile){
|
||||
tile.remove();
|
||||
@@ -529,4 +551,21 @@ public class Tile implements Position, TargetTrait{
|
||||
public static void setTile(Tile tile, Block block, Team team, int rotation){
|
||||
tile.set(block, team, rotation);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, unreliable = true)
|
||||
public static void onTileDamage(Tile tile, float health){
|
||||
if(tile.entity != null){
|
||||
tile.entity.health(health);
|
||||
|
||||
if(tile.entity.damaged()){
|
||||
indexer.notifyTileDamaged(tile.entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onTileDestroyed(Tile tile){
|
||||
if(tile.entity == null) return;
|
||||
tile.entity.killed();
|
||||
}
|
||||
}
|
||||
|
||||
4
core/src/mindustry/world/TileData.java
Normal file
4
core/src/mindustry/world/TileData.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package mindustry.world;
|
||||
|
||||
public class TileData{
|
||||
}
|
||||
19
core/src/mindustry/world/TileGen.java
Normal file
19
core/src/mindustry/world/TileGen.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package mindustry.world;
|
||||
|
||||
import mindustry.content.*;
|
||||
|
||||
public class TileGen{
|
||||
public Block floor;
|
||||
public Block block ;
|
||||
public Block overlay;
|
||||
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
floor = Blocks.stone;
|
||||
block = Blocks.air;
|
||||
overlay = Blocks.air;
|
||||
}
|
||||
}
|
||||
86
core/src/mindustry/world/Tiles.java
Normal file
86
core/src/mindustry/world/Tiles.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package mindustry.world;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** A tile container. */
|
||||
public class Tiles implements Iterable<Tile>{
|
||||
public final int width, height;
|
||||
|
||||
private final Tile[] array;
|
||||
private final TileIterator iterator = new TileIterator();
|
||||
|
||||
public Tiles(int width, int height){
|
||||
this.array = new Tile[width * height];
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void each(Intc2 cons){
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int y = 0; y < height; y++){
|
||||
cons.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** fills this tile set with empty air tiles. */
|
||||
public void fill(){
|
||||
for(int i = 0; i < array.length; i++){
|
||||
array[i] = new Tile(i % width, i / width);
|
||||
}
|
||||
}
|
||||
|
||||
/** set a tile at a position; does not range-check. use with caution. */
|
||||
public void set(int x, int y, Tile tile){
|
||||
array[y*width + x] = tile;
|
||||
}
|
||||
|
||||
/** @return whether these coordinates are in bounds */
|
||||
public boolean in(int x, int y){
|
||||
return x >= 0 && x < width && y >= 0 && y < height;
|
||||
}
|
||||
|
||||
/** @return a tile at coordinates, or null if out of bounds */
|
||||
public @Nullable Tile get(int x, int y){
|
||||
return (x < 0 || x >= width || y < 0 || y >= height) ? null : array[y*width + x];
|
||||
}
|
||||
|
||||
/** @return a tile at coordinates; throws an exception if out of bounds */
|
||||
public @NonNull Tile getn(int x, int y){
|
||||
if(x < 0 || x >= width || y < 0 || y >= height) throw new IllegalArgumentException(x + ", " + y + " out of bounds: width=" + width + ", height=" + height);
|
||||
return array[y*width + x];
|
||||
}
|
||||
|
||||
/** @return a tile at an iteration index [0, width * height] */
|
||||
public @NonNull Tile geti(int idx){
|
||||
return array[idx];
|
||||
}
|
||||
|
||||
/** @return a tile at an int position (not equivalent to geti) */
|
||||
public @Nullable Tile getp(int pos){
|
||||
return get(Pos.x(pos), Pos.y(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Tile> iterator(){
|
||||
iterator.index = 0;
|
||||
return iterator;
|
||||
}
|
||||
|
||||
private class TileIterator implements Iterator<Tile>{
|
||||
int index = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext(){
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tile next(){
|
||||
return array[index++];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -84,7 +84,7 @@ public interface Autotiler{
|
||||
default boolean blends(Tile tile, int rotation, int direction){
|
||||
Tile other = tile.getNearby(Mathf.mod(rotation - direction, 4));
|
||||
if(other != null) other = other.link();
|
||||
return other != null && blends(tile, rotation, other.x, other.y, other.rotation(), other.block());
|
||||
return other != null && other.team() == tile.team() && blends(tile, rotation, other.x, other.y, other.rotation(), other.block());
|
||||
}
|
||||
|
||||
default boolean blendsArmored(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.Graphics.*;
|
||||
import arc.Graphics.Cursor.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.effect.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -22,8 +21,6 @@ import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class BuildBlock extends Block{
|
||||
@@ -55,10 +52,10 @@ public class BuildBlock extends Block{
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onDeconstructFinish(Tile tile, Block block, int builderID){
|
||||
Team team = tile.getTeam();
|
||||
Effects.effect(Fx.breakBlock, tile.drawx(), tile.drawy(), block.size);
|
||||
Team team = tile.team();
|
||||
Fx.breakBlock.at(tile.drawx(), tile.drawy(), block.size);
|
||||
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, true));
|
||||
tile.remove();
|
||||
Events.fire(new BlockBuildEndEvent(tile, playerGroup.getByID(builderID), team, true));
|
||||
if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false));
|
||||
}
|
||||
|
||||
@@ -68,15 +65,15 @@ public class BuildBlock extends Block{
|
||||
float healthf = tile.entity == null ? 1f : tile.entity.healthf();
|
||||
tile.set(block, team, rotation);
|
||||
if(tile.entity != null){
|
||||
tile.entity.health = block.health * healthf;
|
||||
tile.entity.health(block.health * healthf);
|
||||
}
|
||||
//last builder was this local client player, call placed()
|
||||
if(!headless && builderID == player.id){
|
||||
if(!headless && builderID == player.id()){
|
||||
if(!skipConfig){
|
||||
tile.block().playerPlaced(tile);
|
||||
}
|
||||
}
|
||||
Effects.effect(Fx.placeBlock, tile.drawx(), tile.drawy(), block.size);
|
||||
Fx.placeBlock.at(tile.drawx(), tile.drawy(), block.size);
|
||||
}
|
||||
|
||||
static boolean shouldPlay(){
|
||||
@@ -107,7 +104,7 @@ public class BuildBlock extends Block{
|
||||
Call.onConstructFinish(tile, block, builderID, rotation, team, skipConfig);
|
||||
tile.block().placed(tile);
|
||||
|
||||
Events.fire(new BlockBuildEndEvent(tile, playerGroup.getByID(builderID), team, false));
|
||||
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, false));
|
||||
if(shouldPlay()) Sounds.place.at(tile, calcPitch(true));
|
||||
}
|
||||
|
||||
@@ -140,25 +137,24 @@ public class BuildBlock extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tapped(Tile tile, Player player){
|
||||
public void tapped(Tile tile, Playerc player){
|
||||
BuildEntity entity = tile.ent();
|
||||
|
||||
//if the target is constructible, begin constructing
|
||||
if(entity.cblock != null){
|
||||
if(player.buildWasAutoPaused && !player.isBuilding){
|
||||
player.isBuilding = true;
|
||||
if(!headless && entity.cblock != null){
|
||||
if(control.input.buildWasAutoPaused && !control.input.isBuilding && player.isBuilder()){
|
||||
control.input.isBuilding = true;
|
||||
}
|
||||
//player.clearBuilding();
|
||||
player.addBuildRequest(new BuildRequest(tile.x, tile.y, tile.rotation(), entity.cblock), false);
|
||||
player.builder().addBuild(new BuildRequest(tile.x, tile.y, tile.rotation(), entity.cblock), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyed(Tile tile){
|
||||
Effects.effect(Fx.blockExplosionSmoke, tile);
|
||||
Fx.blockExplosionSmoke.at(tile);
|
||||
|
||||
if(!tile.floor().solid && !tile.floor().isLiquid){
|
||||
RubbleDecal.create(tile.drawx(), tile.drawy(), size);
|
||||
Effects.rubble(tile.drawx(), tile.drawy(), size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +214,7 @@ public class BuildBlock extends Block{
|
||||
private float[] accumulator;
|
||||
private float[] totalAccumulator;
|
||||
|
||||
public boolean construct(Unit builder, @Nullable TileEntity core, float amount, boolean configured){
|
||||
public boolean construct(Unitc builder, @Nullable Tilec core, float amount, boolean configured){
|
||||
if(cblock == null){
|
||||
kill();
|
||||
return false;
|
||||
@@ -228,7 +224,7 @@ public class BuildBlock extends Block{
|
||||
setConstruct(previous, cblock);
|
||||
}
|
||||
|
||||
float maxProgress = core == null ? amount : checkRequired(core.items, amount, false);
|
||||
float maxProgress = core == null ? amount : checkRequired(core.items(), amount, false);
|
||||
|
||||
for(int i = 0; i < cblock.requirements.length; i++){
|
||||
int reqamount = Math.round(state.rules.buildCostMultiplier * cblock.requirements[i].amount);
|
||||
@@ -236,22 +232,19 @@ public class BuildBlock extends Block{
|
||||
totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount);
|
||||
}
|
||||
|
||||
maxProgress = core == null ? maxProgress : checkRequired(core.items, maxProgress, true);
|
||||
maxProgress = core == null ? maxProgress : checkRequired(core.items(), maxProgress, true);
|
||||
|
||||
progress = Mathf.clamp(progress + maxProgress);
|
||||
|
||||
if(builder instanceof Player){
|
||||
builderID = builder.getID();
|
||||
}
|
||||
builderID = builder.id();
|
||||
|
||||
if(progress >= 1f || state.rules.infiniteResources){
|
||||
constructed(tile, cblock, builderID, tile.rotation(), builder.getTeam(), configured);
|
||||
constructed(tile, cblock, builderID, tile.rotation(), builder.team(), configured);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void deconstruct(Unit builder, @Nullable TileEntity core, float amount){
|
||||
public void deconstruct(Unitc builder, @Nullable Tilec core, float amount){
|
||||
float deconstructMultiplier = 0.5f;
|
||||
|
||||
if(cblock != null){
|
||||
@@ -272,8 +265,8 @@ public class BuildBlock extends Block{
|
||||
|
||||
if(clampedAmount > 0 && accumulated > 0){ //if it's positive, add it to the core
|
||||
if(core != null){
|
||||
int accepting = core.tile.block().acceptStack(requirements[i].item, accumulated, core.tile, builder);
|
||||
core.tile.block().handleStack(requirements[i].item, accepting, core.tile, builder);
|
||||
int accepting = core.tile().block().acceptStack(requirements[i].item, accumulated, core.tile(), builder);
|
||||
core.tile().block().handleStack(requirements[i].item, accepting, core.tile(), builder);
|
||||
accumulator[i] -= accepting;
|
||||
}else{
|
||||
accumulator[i] -= accumulated;
|
||||
@@ -284,9 +277,7 @@ public class BuildBlock extends Block{
|
||||
|
||||
progress = Mathf.clamp(progress - amount);
|
||||
|
||||
if(builder instanceof Player){
|
||||
builderID = builder.getID();
|
||||
}
|
||||
builderID = builder.id();
|
||||
|
||||
if(progress <= 0 || state.rules.infiniteResources){
|
||||
Call.onDeconstructFinish(tile, this.cblock == null ? previous : this.cblock, builderID);
|
||||
@@ -351,37 +342,37 @@ public class BuildBlock extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(progress);
|
||||
stream.writeShort(previous == null ? -1 : previous.id);
|
||||
stream.writeShort(cblock == null ? -1 : cblock.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(progress);
|
||||
write.s(previous == null ? -1 : previous.id);
|
||||
write.s(cblock == null ? -1 : cblock.id);
|
||||
|
||||
if(accumulator == null){
|
||||
stream.writeByte(-1);
|
||||
write.b(-1);
|
||||
}else{
|
||||
stream.writeByte(accumulator.length);
|
||||
write.b(accumulator.length);
|
||||
for(int i = 0; i < accumulator.length; i++){
|
||||
stream.writeFloat(accumulator[i]);
|
||||
stream.writeFloat(totalAccumulator[i]);
|
||||
write.f(accumulator[i]);
|
||||
write.f(totalAccumulator[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
progress = stream.readFloat();
|
||||
short pid = stream.readShort();
|
||||
short rid = stream.readShort();
|
||||
byte acsize = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
progress = read.f();
|
||||
short pid = read.s();
|
||||
short rid = read.s();
|
||||
byte acsize = read.b();
|
||||
|
||||
if(acsize != -1){
|
||||
accumulator = new float[acsize];
|
||||
totalAccumulator = new float[acsize];
|
||||
for(int i = 0; i < acsize; i++){
|
||||
accumulator[i] = stream.readFloat();
|
||||
totalAccumulator[i] = stream.readFloat();
|
||||
accumulator[i] = read.f();
|
||||
totalAccumulator[i] = read.f();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
36
core/src/mindustry/world/blocks/Cliff.java
Normal file
36
core/src/mindustry/world/blocks/Cliff.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.util.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class Cliff extends Block{
|
||||
|
||||
public Cliff(String name){
|
||||
super(name);
|
||||
breakable = alwaysReplace = false;
|
||||
solid = true;
|
||||
cacheLayer = CacheLayer.walls;
|
||||
fillsTile = false;
|
||||
hasShadow = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
int r = tile.rotation();
|
||||
for(int i = 0; i < 8; i++){
|
||||
if((r & (1 << i)) != 0){
|
||||
Draw.color(Tmp.c1.set(tile.floor().mapColor).mul(1.3f + (i >= 4 ? -0.4f : 0.3f)));
|
||||
Draw.rect(region, tile.worldx(), tile.worldy(), 11f, 11f, i * 45f);
|
||||
}
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minimapColor(Tile tile){
|
||||
return Tmp.c1.set(tile.floor().mapColor).mul(1.2f).rgba();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,22 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.graphics.g2d.TextureAtlas.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.Effects.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.MultiPacker.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Floor extends Block{
|
||||
/** number of different variant regions to use */
|
||||
@@ -35,13 +36,13 @@ public class Floor extends Block{
|
||||
/** Effect displayed when drowning on this floor. */
|
||||
public Effect drownUpdateEffect = Fx.bubble;
|
||||
/** Status effect applied when walking on. */
|
||||
public StatusEffect status = StatusEffects.none;
|
||||
public @NonNull StatusEffect status = StatusEffects.none;
|
||||
/** Intensity of applied status effect. */
|
||||
public float statusDuration = 60f;
|
||||
/** liquids that drop from this block, used for pumps */
|
||||
public Liquid liquidDrop = null;
|
||||
public @Nullable Liquid liquidDrop = null;
|
||||
/** item that drops from this block, used for drills */
|
||||
public Item itemDrop = null;
|
||||
public @Nullable Item itemDrop = null;
|
||||
/** whether this block can be drowned in */
|
||||
public boolean isLiquid;
|
||||
/** if true, this block cannot be mined by players. useful for annoying things like sand. */
|
||||
@@ -52,6 +53,14 @@ public class Floor extends Block{
|
||||
public Effect updateEffect = Fx.none;
|
||||
/** Array of affinities to certain things. */
|
||||
public Attributes attributes = new Attributes();
|
||||
/** Whether this ore generates in maps by default. */
|
||||
public boolean oreDefault = false;
|
||||
/** Ore generation params. */
|
||||
public float oreScale = 24f, oreThreshold = 0.828f;
|
||||
/** Wall variant of this block. May be Blocks.air if not found. */
|
||||
public Block wall = Blocks.air;
|
||||
/** Decoration block. Usually a rock. May be air. */
|
||||
public Block decoration = Blocks.air;
|
||||
|
||||
protected TextureRegion[][] edges;
|
||||
protected byte eq = 0;
|
||||
@@ -87,6 +96,24 @@ public class Floor extends Block{
|
||||
edgeRegion = Core.atlas.find("edge");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
if(wall == Blocks.air){
|
||||
wall = content.block(name + "Rocks");
|
||||
if(wall == null) wall = content.block(name + "rocks");
|
||||
if(wall == null) wall = content.block(name.replace("darksand", "dune") + "rocks");
|
||||
}
|
||||
|
||||
//keep default value if not found...
|
||||
if(wall == null) wall = Blocks.air;
|
||||
|
||||
if(decoration == Blocks.air){
|
||||
decoration = content.blocks().min(b -> b instanceof Rock && b.breakable ? mapColor.diff(b.mapColor) : Float.POSITIVE_INFINITY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createIcons(MultiPacker packer){
|
||||
super.createIcons(packer);
|
||||
@@ -192,7 +219,7 @@ public class Floor extends Block{
|
||||
for(int i = 0; i < 4; i++){
|
||||
Tile other = tile.getNearby(i);
|
||||
if(other != null && doEdge(other.floor(), sameLayer)){
|
||||
Color color = other.floor().color;
|
||||
Color color = other.floor().mapColor;
|
||||
Draw.color(color.r, color.g, color.b, 1f);
|
||||
Draw.rect(edgeRegion, tile.worldx(), tile.worldy(), i*90);
|
||||
}
|
||||
@@ -217,4 +244,4 @@ public class Floor extends Block{
|
||||
return block.edges()[x][2 - y];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import arc.struct.*;
|
||||
import arc.func.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class ItemSelection{
|
||||
private static float scrollPos = 0f;
|
||||
|
||||
public static void buildItemTable(Table table, Prov<Item> holder, Cons<Item> consumer){
|
||||
|
||||
Array<Item> items = content.items();
|
||||
public static <T extends UnlockableContent> void buildTable(Table table, Array<T> items, Prov<T> holder, Cons<T> consumer){
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
cont.defaults().size(38);
|
||||
cont.defaults().size(40);
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(Item item : items){
|
||||
if(!data.isUnlocked(item) && world.isZone()) continue;
|
||||
for(T item : items){
|
||||
if(!data.isUnlocked(item) && state.isCampaign()) continue;
|
||||
|
||||
ImageButton button = cont.addImageButton(Tex.whiteui, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).group(group).get();
|
||||
button.changed(() -> consumer.get(button.isChecked() ? item : null));
|
||||
@@ -38,6 +36,22 @@ public class ItemSelection{
|
||||
}
|
||||
}
|
||||
|
||||
table.add(cont);
|
||||
//add extra blank spaces so it looks nice
|
||||
if(i % 4 != 0){
|
||||
int remaining = 4 - (i % 4);
|
||||
for(int j = 0; j < remaining; j++){
|
||||
cont.addImage(Styles.black6);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollPane pane = new ScrollPane(cont, Styles.smallPane);
|
||||
pane.setScrollingDisabled(true, false);
|
||||
pane.setScrollYForce(scrollPos);
|
||||
pane.update(() -> {
|
||||
scrollPos = pane.getScrollY();
|
||||
});
|
||||
|
||||
pane.setOverscroll(false, false);
|
||||
table.add(pane).maxHeight(Scl.scl(40 * 5));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class LiquidBlock extends Block{
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
LiquidModule mod = tile.entity.liquids;
|
||||
LiquidModule mod = tile.entity.liquids();
|
||||
|
||||
int rotation = rotate ? tile.rotation() * 90 : 0;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class OreBlock extends OverlayFloor{
|
||||
this.localizedName = ore.localizedName;
|
||||
this.itemDrop = ore;
|
||||
this.variants = 3;
|
||||
this.color.set(ore.color);
|
||||
this.mapColor.set(ore.color);
|
||||
}
|
||||
|
||||
/** For mod use only!*/
|
||||
@@ -31,7 +31,7 @@ public class OreBlock extends OverlayFloor{
|
||||
public void setup(Item ore){
|
||||
this.localizedName = ore.localizedName;
|
||||
this.itemDrop = ore;
|
||||
this.color.set(ore.color);
|
||||
this.mapColor.set(ore.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@ package mindustry.world.blocks;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
@@ -12,7 +12,7 @@ import static mindustry.Vars.net;
|
||||
|
||||
public class RespawnBlock{
|
||||
|
||||
public static void drawRespawn(Tile tile, float heat, float progress, float time, Player player, Mech to){
|
||||
public static void drawRespawn(Tile tile, float heat, float progress, float time, Playerc player, UnitType to){
|
||||
progress = Mathf.clamp(progress);
|
||||
|
||||
Draw.color(Pal.darkMetal);
|
||||
@@ -67,7 +67,7 @@ public class RespawnBlock{
|
||||
Draw.reset();
|
||||
|
||||
if(net.active() && player != null){
|
||||
tile.block().drawPlaceText(player.name, tile.x, tile.y - (Math.max((tile.block().size-1)/2, 0)), true);
|
||||
tile.block().drawPlaceText(player.name(), tile.x, tile.y - (Math.max((tile.block().size-1)/2, 0)), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.type.Bullet;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
@@ -42,33 +41,36 @@ public class DeflectorWall extends Wall{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleBulletHit(TileEntity entity, Bullet bullet){
|
||||
public void handleBulletHit(Tilec entity, Bulletc bullet){
|
||||
super.handleBulletHit(entity, bullet);
|
||||
|
||||
//TODO fix and test
|
||||
//doesn't reflect powerful bullets
|
||||
if(bullet.damage() > maxDamageDeflect || bullet.isDeflected()) return;
|
||||
if(bullet.damage() > maxDamageDeflect) return;
|
||||
|
||||
float penX = Math.abs(entity.x - bullet.x), penY = Math.abs(entity.y - bullet.y);
|
||||
float penX = Math.abs(entity.getX() - bullet.x()), penY = Math.abs(entity.getY() - bullet.y());
|
||||
|
||||
bullet.hitbox(rect2);
|
||||
|
||||
Vec2 position = Geometry.raycastRect(bullet.x - bullet.velocity().x*Time.delta(), bullet.y - bullet.velocity().y*Time.delta(), bullet.x + bullet.velocity().x*Time.delta(), bullet.y + bullet.velocity().y*Time.delta(),
|
||||
rect.setSize(size * tilesize + rect2.width*2 + rect2.height*2).setCenter(entity.x, entity.y));
|
||||
Vec2 position = Geometry.raycastRect(bullet.x() - bullet.vel().x*Time.delta(), bullet.y() - bullet.vel().y*Time.delta(), bullet.x() + bullet.vel().x*Time.delta(), bullet.y() + bullet.vel().y*Time.delta(),
|
||||
rect.setSize(size * tilesize + rect2.width*2 + rect2.height*2).setCenter(entity.getX(), entity.getY()));
|
||||
|
||||
if(position != null){
|
||||
bullet.set(position.x, position.y);
|
||||
}
|
||||
|
||||
if(penX > penY){
|
||||
bullet.velocity().x *= -1;
|
||||
bullet.vel().x *= -1;
|
||||
}else{
|
||||
bullet.velocity().y *= -1;
|
||||
bullet.vel().y *= -1;
|
||||
}
|
||||
|
||||
//bullet.updateVelocity();
|
||||
bullet.resetOwner(entity, entity.getTeam());
|
||||
bullet.scaleTime(1f);
|
||||
bullet.deflect();
|
||||
bullet.owner(entity);
|
||||
bullet.team(entity.team());
|
||||
bullet.time(bullet.time() + 1f);
|
||||
//TODO deflect
|
||||
//bullet.deflect();
|
||||
|
||||
((DeflectorEntity)entity).hit = 1f;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.blocks.defense;
|
||||
|
||||
import arc.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.Graphics.*;
|
||||
import arc.Graphics.Cursor.*;
|
||||
@@ -8,8 +9,6 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Effects.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
@@ -35,7 +34,7 @@ public class Door extends Wall{
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onDoorToggle(Player player, Tile tile, boolean open){
|
||||
public static void onDoorToggle(Playerc player, Tile tile, boolean open){
|
||||
DoorEntity entity = tile.ent();
|
||||
if(entity != null){
|
||||
entity.open = open;
|
||||
@@ -43,9 +42,9 @@ public class Door extends Wall{
|
||||
|
||||
pathfinder.updateTile(tile);
|
||||
if(!entity.open){
|
||||
Effects.effect(door.openfx, tile.drawx(), tile.drawy());
|
||||
door.openfx.at(tile.drawx(), tile.drawy());
|
||||
}else{
|
||||
Effects.effect(door.closefx, tile.drawx(), tile.drawy());
|
||||
door.closefx.at(tile.drawx(), tile.drawy());
|
||||
}
|
||||
Sounds.door.at(tile);
|
||||
}
|
||||
@@ -80,10 +79,10 @@ public class Door extends Wall{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tapped(Tile tile, Player player){
|
||||
public void tapped(Tile tile, Playerc player){
|
||||
DoorEntity entity = tile.ent();
|
||||
|
||||
if((Units.anyEntities(tile) && entity.open) || !tile.entity.timer.get(timerToggle, 30f)){
|
||||
if((Units.anyEntities(tile) && entity.open) || !tile.entity.timer(timerToggle, 30f)){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -94,15 +93,15 @@ public class Door extends Wall{
|
||||
public boolean open = false;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeBoolean(open);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.bool(open);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
open = stream.readBoolean();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
open = read.bool();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,9 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.traits.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.type.BaseEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.consumers.*;
|
||||
@@ -19,7 +17,7 @@ import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class ForceProjector extends Block{
|
||||
public final int timerUse = timers++;
|
||||
@@ -37,12 +35,12 @@ public class ForceProjector extends Block{
|
||||
private static Tile paramTile;
|
||||
private static ForceProjector paramBlock;
|
||||
private static ForceEntity paramEntity;
|
||||
private static Cons<AbsorbTrait> shieldConsumer = trait -> {
|
||||
if(trait.canBeAbsorbed() && trait.getTeam() != paramTile.getTeam() && Intersector.isInsideHexagon(trait.getX(), trait.getY(), paramBlock.realRadius(paramEntity) * 2f, paramTile.drawx(), paramTile.drawy())){
|
||||
private static Cons<Shielderc> shieldConsumer = trait -> {
|
||||
if(trait.team() != paramTile.team() && Intersector.isInsideHexagon(trait.x(), trait.y(), paramBlock.realRadius(paramEntity) * 2f, paramTile.drawx(), paramTile.drawy())){
|
||||
trait.absorb();
|
||||
Effects.effect(Fx.absorb, trait);
|
||||
Fx.absorb.at(trait);
|
||||
paramEntity.hit = 1f;
|
||||
paramEntity.buildup += trait.getShieldDamage() * paramEntity.warmup;
|
||||
paramEntity.buildup += trait.damage() * paramEntity.warmup;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -92,22 +90,23 @@ public class ForceProjector extends Block{
|
||||
ForceEntity entity = tile.ent();
|
||||
|
||||
if(entity.shield == null){
|
||||
entity.shield = new ShieldEntity(tile);
|
||||
entity.shield.add();
|
||||
//TODO implement
|
||||
//entity.shield = new ShieldEntity(tile);
|
||||
//entity.shield.add();
|
||||
}
|
||||
|
||||
boolean phaseValid = consumes.get(ConsumeType.item).valid(tile.entity);
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(phaseValid), 0.1f);
|
||||
|
||||
if(phaseValid && !entity.broken && entity.timer.get(timerUse, phaseUseTime) && entity.efficiency() > 0){
|
||||
entity.cons.trigger();
|
||||
if(phaseValid && !entity.broken && entity.timer(timerUse, phaseUseTime) && entity.efficiency() > 0){
|
||||
entity.consume();
|
||||
}
|
||||
|
||||
entity.radscl = Mathf.lerpDelta(entity.radscl, entity.broken ? 0f : entity.warmup, 0.05f);
|
||||
|
||||
if(Mathf.chance(Time.delta() * entity.buildup / breakage * 0.1f)){
|
||||
Effects.effect(Fx.reactorsmoke, tile.drawx() + Mathf.range(tilesize / 2f), tile.drawy() + Mathf.range(tilesize / 2f));
|
||||
Fx.reactorsmoke.at(tile.drawx() + Mathf.range(tilesize / 2f), tile.drawy() + Mathf.range(tilesize / 2f));
|
||||
}
|
||||
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, entity.efficiency(), 0.1f);
|
||||
@@ -117,7 +116,7 @@ public class ForceProjector extends Block{
|
||||
ConsumeLiquidFilter cons = consumes.get(ConsumeType.liquid);
|
||||
if(cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
scale *= (cooldownLiquid * (1f + (entity.liquids.current().heatCapacity - 0.4f) * 0.9f));
|
||||
scale *= (cooldownLiquid * (1f + (entity.liquids().current().heatCapacity - 0.4f) * 0.9f));
|
||||
}
|
||||
|
||||
entity.buildup -= Time.delta() * scale;
|
||||
@@ -130,7 +129,7 @@ public class ForceProjector extends Block{
|
||||
if(entity.buildup >= breakage && !entity.broken){
|
||||
entity.broken = true;
|
||||
entity.buildup = breakage;
|
||||
Effects.effect(Fx.shieldBreak, tile.drawx(), tile.drawy(), radius);
|
||||
Fx.shieldBreak.at(tile.drawx(), tile.drawy(), radius);
|
||||
}
|
||||
|
||||
if(entity.hit > 0f){
|
||||
@@ -142,7 +141,7 @@ public class ForceProjector extends Block{
|
||||
paramTile = tile;
|
||||
paramEntity = entity;
|
||||
paramBlock = this;
|
||||
bulletGroup.intersect(tile.drawx() - realRadius, tile.drawy() - realRadius, realRadius*2f, realRadius * 2f, shieldConsumer);
|
||||
Groups.bullet.intersect(tile.drawx() - realRadius, tile.drawy() - realRadius, realRadius*2f, realRadius * 2f, shieldConsumer);
|
||||
}
|
||||
|
||||
float realRadius(ForceEntity entity){
|
||||
@@ -173,26 +172,34 @@ public class ForceProjector extends Block{
|
||||
float phaseHeat;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeBoolean(broken);
|
||||
stream.writeFloat(buildup);
|
||||
stream.writeFloat(radscl);
|
||||
stream.writeFloat(warmup);
|
||||
stream.writeFloat(phaseHeat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.bool(broken);
|
||||
write.f(buildup);
|
||||
write.f(radscl);
|
||||
write.f(warmup);
|
||||
write.f(phaseHeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
broken = stream.readBoolean();
|
||||
buildup = stream.readFloat();
|
||||
radscl = stream.readFloat();
|
||||
warmup = stream.readFloat();
|
||||
phaseHeat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
broken = read.bool();
|
||||
buildup = read.f();
|
||||
radscl = read.f();
|
||||
warmup = read.f();
|
||||
phaseHeat = read.f();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO fix
|
||||
class ShieldEntity{
|
||||
|
||||
}
|
||||
/*
|
||||
//@EntityDef({Drawc.class})
|
||||
//class ShieldDef{}
|
||||
|
||||
public class ShieldEntity extends BaseEntity implements DrawTrait{
|
||||
final ForceEntity entity;
|
||||
|
||||
@@ -247,5 +254,5 @@ public class ForceProjector extends Block{
|
||||
public EntityGroup targetGroup(){
|
||||
return shieldGroup;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package mindustry.world.blocks.defense;
|
||||
|
||||
import arc.Core;
|
||||
import arc.struct.IntSet;
|
||||
import arc.graphics.Color;
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.entities.Effects;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class MendProjector extends Block{
|
||||
@@ -65,37 +63,23 @@ public class MendProjector extends Block{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
MendEntity entity = tile.ent();
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f);
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.consValid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f);
|
||||
entity.charge += entity.heat * entity.delta();
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons().optionalValid()), 0.1f);
|
||||
|
||||
if(entity.cons.optionalValid() && entity.timer.get(timerUse, useTime) && entity.efficiency() > 0){
|
||||
entity.cons.trigger();
|
||||
if(entity.cons().optionalValid() && entity.timer(timerUse, useTime) && entity.efficiency() > 0){
|
||||
entity.consume();
|
||||
}
|
||||
|
||||
if(entity.charge >= reload){
|
||||
float realRange = range + entity.phaseHeat * phaseRangeBoost;
|
||||
entity.charge = 0f;
|
||||
|
||||
int tileRange = (int)(realRange / tilesize + 1);
|
||||
healed.clear();
|
||||
|
||||
for(int x = -tileRange + tile.x; x <= tileRange + tile.x; x++){
|
||||
for(int y = -tileRange + tile.y; y <= tileRange + tile.y; y++){
|
||||
if(!Mathf.within(x * tilesize, y * tilesize, tile.drawx(), tile.drawy(), realRange)) continue;
|
||||
|
||||
Tile other = world.ltile(x, y);
|
||||
|
||||
if(other == null) continue;
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null && other.entity.health < other.entity.maxHealth()){
|
||||
other.entity.healBy(other.entity.maxHealth() * (healPercent + entity.phaseHeat * phaseBoost) / 100f * entity.efficiency());
|
||||
Effects.effect(Fx.healBlockFull, Tmp.c1.set(baseColor).lerp(phaseColor, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
|
||||
healed.add(other.pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
indexer.eachBlock(entity, realRange, other -> other.entity.damaged(), other -> {
|
||||
other.entity.heal(other.entity.maxHealth() * (healPercent + entity.phaseHeat * phaseBoost) / 100f * entity.efficiency());
|
||||
Fx.healBlockFull.at(other.drawx(), other.drawy(), other.block().size, Tmp.c1.set(baseColor).lerp(phaseColor, entity.phaseHeat));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,9 +105,7 @@ public class MendProjector extends Block{
|
||||
|
||||
Draw.color(baseColor, phaseColor, entity.phaseHeat);
|
||||
Draw.alpha(entity.heat * Mathf.absin(Time.time(), 10f, 1f) * 0.5f);
|
||||
//Draw.blend(Blending.additive);
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy());
|
||||
//Draw.blend();
|
||||
|
||||
Draw.alpha(1f);
|
||||
Lines.stroke((2f * f + 0.2f) * entity.heat);
|
||||
@@ -143,17 +125,17 @@ public class MendProjector extends Block{
|
||||
float phaseHeat;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(heat);
|
||||
stream.writeFloat(phaseHeat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(heat);
|
||||
write.f(phaseHeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
heat = stream.readFloat();
|
||||
phaseHeat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
heat = read.f();
|
||||
phaseHeat = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package mindustry.world.blocks.defense;
|
||||
|
||||
import arc.Core;
|
||||
import arc.struct.IntSet;
|
||||
import arc.graphics.Color;
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.Mathf;
|
||||
import arc.util.Time;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class OverdriveProjector extends Block{
|
||||
@@ -75,13 +74,13 @@ public class OverdriveProjector extends Block{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
OverdriveEntity entity = tile.ent();
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() ? 1f : 0f, 0.08f);
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.consValid() ? 1f : 0f, 0.08f);
|
||||
entity.charge += entity.heat * Time.delta();
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons().optionalValid()), 0.1f);
|
||||
|
||||
if(entity.timer.get(timerUse, useTime) && entity.efficiency() > 0){
|
||||
entity.cons.trigger();
|
||||
if(entity.timer(timerUse, useTime) && entity.efficiency() > 0){
|
||||
entity.consume();
|
||||
}
|
||||
|
||||
if(entity.charge >= reload){
|
||||
@@ -89,27 +88,7 @@ public class OverdriveProjector extends Block{
|
||||
float realBoost = (speedBoost + entity.phaseHeat * speedBoostPhase) * entity.efficiency();
|
||||
|
||||
entity.charge = 0f;
|
||||
|
||||
int tileRange = (int)(realRange / tilesize + 1);
|
||||
healed.clear();
|
||||
|
||||
for(int x = -tileRange + tile.x; x <= tileRange + tile.x; x++){
|
||||
for(int y = -tileRange + tile.y; y <= tileRange + tile.y; y++){
|
||||
if(!Mathf.within(x * tilesize, y * tilesize, tile.drawx(), tile.drawy(), realRange)) continue;
|
||||
|
||||
Tile other = world.ltile(x, y);
|
||||
|
||||
if(other == null) continue;
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null){
|
||||
if(other.entity.timeScale <= realBoost){
|
||||
other.entity.timeScaleDuration = Math.max(other.entity.timeScaleDuration, reload + 1f);
|
||||
other.entity.timeScale = Math.max(other.entity.timeScale, realBoost);
|
||||
}
|
||||
healed.add(other.pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
indexer.eachBlock(entity, realRange, other -> other.entity.timeScale() < realBoost, other -> other.entity.applyBoost(realBoost, reload + 1f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,17 +123,17 @@ public class OverdriveProjector extends Block{
|
||||
float phaseHeat;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(heat);
|
||||
stream.writeFloat(phaseHeat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(heat);
|
||||
write.f(phaseHeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
heat = stream.readFloat();
|
||||
phaseHeat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
heat = read.f();
|
||||
phaseHeat = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package mindustry.world.blocks.defense;
|
||||
|
||||
import arc.graphics.g2d.Draw;
|
||||
import arc.graphics.g2d.Fill;
|
||||
import arc.math.Mathf;
|
||||
import mindustry.entities.effect.Lightning;
|
||||
import mindustry.entities.type.Unit;
|
||||
import mindustry.graphics.Layer;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.world.Block;
|
||||
import mindustry.world.Tile;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class ShockMine extends Block{
|
||||
public final int timerDamage = timers++;
|
||||
@@ -32,7 +29,7 @@ public class ShockMine extends Block{
|
||||
@Override
|
||||
public void drawLayer(Tile tile){
|
||||
super.draw(tile);
|
||||
Draw.color(tile.getTeam().color);
|
||||
Draw.color(tile.team().color);
|
||||
Draw.alpha(0.22f);
|
||||
Fill.rect(tile.drawx(), tile.drawy(), 2f, 2f);
|
||||
Draw.color();
|
||||
@@ -49,10 +46,10 @@ public class ShockMine extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitOn(Tile tile, Unit unit){
|
||||
if(unit.getTeam() != tile.getTeam() && tile.entity.timer.get(timerDamage, cooldown)){
|
||||
public void unitOn(Tile tile, Unitc unit){
|
||||
if(unit.team() != tile.team() && tile.entity.timer(timerDamage, cooldown)){
|
||||
for(int i = 0; i < tendrils; i++){
|
||||
Lightning.create(tile.getTeam(), Pal.lancerLaser, damage, tile.drawx(), tile.drawy(), Mathf.random(360f), length);
|
||||
Lightning.create(tile.team(), Pal.lancerLaser, damage, tile.drawx(), tile.drawy(), Mathf.random(360f), length);
|
||||
}
|
||||
tile.entity.damage(tileDamage);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package mindustry.world.blocks.defense;
|
||||
|
||||
import arc.math.Mathf;
|
||||
import mindustry.entities.type.Bullet;
|
||||
import mindustry.entities.effect.Lightning;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.graphics.Pal;
|
||||
import arc.math.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
|
||||
public class SurgeWall extends Wall{
|
||||
public float lightningChance = 0.05f;
|
||||
@@ -16,10 +15,10 @@ public class SurgeWall extends Wall{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleBulletHit(TileEntity entity, Bullet bullet){
|
||||
public void handleBulletHit(Tilec entity, Bulletc bullet){
|
||||
super.handleBulletHit(entity, bullet);
|
||||
if(Mathf.chance(lightningChance)){
|
||||
Lightning.create(entity.getTeam(), Pal.surge, lightningDamage, bullet.x, bullet.y, bullet.rot() + 180f, lightningLength);
|
||||
Lightning.create(entity.team(), Pal.surge, lightningDamage, bullet.x(), bullet.y(), bullet.rotation() + 180f, lightningLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package mindustry.world.blocks.defense.turrets;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Vec2;
|
||||
import mindustry.entities.Predict;
|
||||
import mindustry.entities.type.Bullet;
|
||||
import mindustry.entities.bullet.BulletType;
|
||||
import mindustry.world.Tile;
|
||||
|
||||
@@ -37,7 +36,7 @@ public class ArtilleryTurret extends ItemTurret{
|
||||
float maxTraveled = type.lifetime * type.speed;
|
||||
|
||||
for(int i = 0; i < shots; i++){
|
||||
Bullet.create(ammo, tile.entity, tile.getTeam(), tile.drawx() + tr.x, tile.drawy() + tr.y,
|
||||
ammo.create(tile.entity, tile.team(), tile.drawx() + tr.x, tile.drawy() + tr.y,
|
||||
entity.rotation + Mathf.range(inaccuracy + type.inaccuracy), 1f + Mathf.range(velocityInaccuracy), (dst / maxTraveled));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ public class ChargeTurret extends PowerTurret{
|
||||
useAmmo(tile);
|
||||
|
||||
tr.trns(entity.rotation, size * tilesize / 2);
|
||||
Effects.effect(chargeBeginEffect, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
chargeBeginEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
|
||||
for(int i = 0; i < chargeEffects; i++){
|
||||
Time.run(Mathf.random(chargeMaxDelay), () -> {
|
||||
if(!isTurret(tile)) return;
|
||||
tr.trns(entity.rotation, size * tilesize / 2);
|
||||
Effects.effect(chargeEffect, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
chargeEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Effects.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
@@ -37,7 +36,7 @@ public class CooledTurret extends Turret{
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
if(tile.entity.liquids.currentAmount() <= 0.001f){
|
||||
if(tile.entity.liquids().currentAmount() <= 0.001f){
|
||||
Events.fire(Trigger.turretCool);
|
||||
}
|
||||
|
||||
@@ -51,14 +50,14 @@ public class CooledTurret extends Turret{
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
TurretEntity entity = tile.ent();
|
||||
Liquid liquid = entity.liquids.current();
|
||||
Liquid liquid = entity.liquids().current();
|
||||
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity)) * baseReloadSpeed(tile);
|
||||
float used = Math.min(Math.min(entity.liquids().get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity)) * baseReloadSpeed(tile);
|
||||
entity.reload += used * liquid.heatCapacity * coolantMultiplier;
|
||||
entity.liquids.remove(liquid, used);
|
||||
entity.liquids().remove(liquid, used);
|
||||
|
||||
if(Mathf.chance(0.06 * used)){
|
||||
Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));
|
||||
coolEffect.at(tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@ package mindustry.world.blocks.defense.turrets;
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
@@ -46,14 +47,14 @@ public class ItemTurret extends CooledTurret{
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
content.items().each(i -> filter.get(i) && (!world.isZone() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)),
|
||||
content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)),
|
||||
() -> tile.entity != null && !((ItemTurretEntity)tile.entity).ammo.isEmpty() && ((ItemEntry)tile.<ItemTurretEntity>ent().ammo.peek()).item == item)));
|
||||
|
||||
table.add(image).size(8 * 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(TileEntity entity){
|
||||
public boolean valid(Tilec entity){
|
||||
//valid when there's any ammo in the turret
|
||||
return !((ItemTurretEntity)entity).ammo.isEmpty();
|
||||
}
|
||||
@@ -86,7 +87,7 @@ public class ItemTurret extends CooledTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
TurretEntity entity = tile.ent();
|
||||
|
||||
BulletType type = ammo.get(item);
|
||||
@@ -97,7 +98,7 @@ public class ItemTurret extends CooledTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleStack(Item item, int amount, Tile tile, Unit source){
|
||||
public void handleStack(Item item, int amount, Tile tile, Teamc source){
|
||||
for(int i = 0; i < amount; i++){
|
||||
handleItem(item, tile, null);
|
||||
}
|
||||
@@ -151,23 +152,23 @@ public class ItemTurret extends CooledTurret{
|
||||
|
||||
public class ItemTurretEntity extends TurretEntity{
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(ammo.size);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(ammo.size);
|
||||
for(AmmoEntry entry : ammo){
|
||||
ItemEntry i = (ItemEntry)entry;
|
||||
stream.writeByte(i.item.id);
|
||||
stream.writeShort(i.amount);
|
||||
write.b(i.item.id);
|
||||
write.s(i.amount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
byte amount = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
byte amount = read.b();
|
||||
for(int i = 0; i < amount; i++){
|
||||
Item item = Vars.content.item(stream.readByte());
|
||||
short a = stream.readShort();
|
||||
Item item = Vars.content.item(read.b());
|
||||
short a = read.s();
|
||||
totalAmmo += a;
|
||||
ammo.add(new ItemEntry(item, a));
|
||||
}
|
||||
|
||||
@@ -2,9 +2,8 @@ package mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.consumers.*;
|
||||
@@ -45,7 +44,7 @@ public class LaserTurret extends PowerTurret{
|
||||
|
||||
if(entity.bulletLife > 0 && entity.bullet != null){
|
||||
tr.trns(entity.rotation, size * tilesize / 2f, 0f);
|
||||
entity.bullet.rot(entity.rotation);
|
||||
entity.bullet.rotation(entity.rotation);
|
||||
entity.bullet.set(tile.drawx() + tr.x, tile.drawy() + tr.y);
|
||||
entity.bullet.time(0f);
|
||||
entity.heat = 1f;
|
||||
@@ -65,22 +64,22 @@ public class LaserTurret extends PowerTurret{
|
||||
return;
|
||||
}
|
||||
|
||||
if(entity.reload >= reload && (entity.cons.valid() || tile.isEnemyCheat())){
|
||||
if(entity.reload >= reload && (entity.consValid() || tile.isEnemyCheat())){
|
||||
BulletType type = peekAmmo(tile);
|
||||
|
||||
shoot(tile, type);
|
||||
|
||||
entity.reload = 0f;
|
||||
}else{
|
||||
Liquid liquid = entity.liquids.current();
|
||||
Liquid liquid = entity.liquids().current();
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
float used = baseReloadSpeed(tile) * (tile.isEnemyCheat() ? maxUsed : Math.min(entity.liquids.get(liquid), maxUsed * Time.delta())) * liquid.heatCapacity * coolantMultiplier;
|
||||
float used = baseReloadSpeed(tile) * (tile.isEnemyCheat() ? maxUsed : Math.min(entity.liquids().get(liquid), maxUsed * Time.delta())) * liquid.heatCapacity * coolantMultiplier;
|
||||
entity.reload += used;
|
||||
entity.liquids.remove(liquid, used);
|
||||
entity.liquids().remove(liquid, used);
|
||||
|
||||
if(Mathf.chance(0.06 * used)){
|
||||
Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));
|
||||
coolEffect.at(tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +95,7 @@ public class LaserTurret extends PowerTurret{
|
||||
protected void bullet(Tile tile, BulletType type, float angle){
|
||||
LaserTurretEntity entity = tile.ent();
|
||||
|
||||
entity.bullet = Bullet.create(type, tile.entity, tile.getTeam(), tile.drawx() + tr.x, tile.drawy() + tr.y, angle);
|
||||
entity.bullet = type.create(tile.entity, tile.team(), tile.drawx() + tr.x, tile.drawy() + tr.y, angle);
|
||||
entity.bulletLife = shootDuration;
|
||||
}
|
||||
|
||||
@@ -108,7 +107,7 @@ public class LaserTurret extends PowerTurret{
|
||||
}
|
||||
|
||||
class LaserTurretEntity extends TurretEntity{
|
||||
Bullet bullet;
|
||||
Bulletc bullet;
|
||||
float bulletLife;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import arc.graphics.g2d.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.entities.effect.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
@@ -38,8 +36,8 @@ public class LiquidTurret extends Turret{
|
||||
TurretEntity entity = tile.ent();
|
||||
|
||||
if(Core.atlas.isFound(reg(liquidRegion))){
|
||||
Draw.color(entity.liquids.current().color);
|
||||
Draw.alpha(entity.liquids.total() / liquidCapacity);
|
||||
Draw.color(entity.liquids().current().color);
|
||||
Draw.alpha(entity.liquids().total() / liquidCapacity);
|
||||
Draw.rect(reg(liquidRegion), tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
|
||||
Draw.color();
|
||||
}
|
||||
@@ -52,7 +50,7 @@ public class LiquidTurret extends Turret{
|
||||
stats.add(BlockStat.ammo, new AmmoListValue<>(ammo));
|
||||
consumes.add(new ConsumeLiquidFilter(i -> ammo.containsKey(i), 1f){
|
||||
@Override
|
||||
public boolean valid(TileEntity entity){
|
||||
public boolean valid(Tilec entity){
|
||||
return !((TurretEntity)entity).ammo.isEmpty();
|
||||
}
|
||||
|
||||
@@ -69,24 +67,15 @@ public class LiquidTurret extends Turret{
|
||||
return entity.target != null && hasAmmo(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean validateTarget(Tile tile){
|
||||
TurretEntity entity = tile.ent();
|
||||
if(entity.liquids.current().canExtinguish() && entity.target instanceof Tile){
|
||||
return Fire.has(((Tile)entity.target).x, ((Tile)entity.target).y);
|
||||
}
|
||||
return super.validateTarget(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void findTarget(Tile tile){
|
||||
TurretEntity entity = tile.ent();
|
||||
if(entity.liquids.current().canExtinguish()){
|
||||
if(entity.liquids().current().canExtinguish()){
|
||||
int tr = (int)(range / tilesize);
|
||||
for(int x = -tr; x <= tr; x++){
|
||||
for(int y = -tr; y <= tr; y++){
|
||||
if(Fire.has(x + tile.x, y + tile.y)){
|
||||
entity.target = world.tile(x + tile.x, y + tile.y);
|
||||
if(Fires.has(x + tile.x, y + tile.y)){
|
||||
entity.target = Fires.get(x + tile.x, y + tile.y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -102,9 +91,9 @@ public class LiquidTurret extends Turret{
|
||||
|
||||
TurretEntity entity = tile.ent();
|
||||
|
||||
Effects.effect(type.shootEffect, entity.liquids.current().color, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
Effects.effect(type.smokeEffect, entity.liquids.current().color, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
//shootSound.at(tile);
|
||||
type.shootEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.liquids().current().color);
|
||||
type.smokeEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.liquids().current().color);
|
||||
shootSound.at(tile);
|
||||
|
||||
if(shootShake > 0){
|
||||
Effects.shake(shootShake, shootShake, tile.entity);
|
||||
@@ -116,21 +105,21 @@ public class LiquidTurret extends Turret{
|
||||
@Override
|
||||
public BulletType useAmmo(Tile tile){
|
||||
TurretEntity entity = tile.ent();
|
||||
if(tile.isEnemyCheat()) return ammo.get(entity.liquids.current());
|
||||
BulletType type = ammo.get(entity.liquids.current());
|
||||
entity.liquids.remove(entity.liquids.current(), type.ammoMultiplier);
|
||||
if(tile.isEnemyCheat()) return ammo.get(entity.liquids().current());
|
||||
BulletType type = ammo.get(entity.liquids().current());
|
||||
entity.liquids().remove(entity.liquids().current(), type.ammoMultiplier);
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BulletType peekAmmo(Tile tile){
|
||||
return ammo.get(tile.entity.liquids.current());
|
||||
return ammo.get(tile.entity.liquids().current());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAmmo(Tile tile){
|
||||
TurretEntity entity = tile.ent();
|
||||
return ammo.get(entity.liquids.current()) != null && entity.liquids.total() >= ammo.get(entity.liquids.current()).ammoMultiplier;
|
||||
return ammo.get(entity.liquids().current()) != null && entity.liquids().total() >= ammo.get(entity.liquids().current()).ammoMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,7 +130,7 @@ public class LiquidTurret extends Turret{
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return ammo.get(liquid) != null
|
||||
&& (tile.entity.liquids.current() == liquid || (ammo.containsKey(tile.entity.liquids.current()) && tile.entity.liquids.get(tile.entity.liquids.current()) <= ammo.get(tile.entity.liquids.current()).ammoMultiplier + 0.001f));
|
||||
&& (tile.entity.liquids().current() == liquid || (ammo.containsKey(tile.entity.liquids().current()) && tile.entity.liquids().get(tile.entity.liquids().current()) <= ammo.get(tile.entity.liquids().current()).ammoMultiplier + 0.001f));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,6 +47,6 @@ public class PowerTurret extends CooledTurret{
|
||||
|
||||
@Override
|
||||
protected float baseReloadSpeed(Tile tile){
|
||||
return tile.isEnemyCheat() ? 1f : tile.entity.power.status;
|
||||
return tile.isEnemyCheat() ? 1f : tile.entity.power().status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
package mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import arc.Core;
|
||||
import arc.*;
|
||||
import arc.audio.*;
|
||||
import arc.struct.Array;
|
||||
import arc.struct.EnumSet;
|
||||
import arc.func.Cons2;
|
||||
import arc.graphics.Blending;
|
||||
import arc.graphics.Color;
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.Angles;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.util.Time;
|
||||
import mindustry.content.Fx;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Effects.Effect;
|
||||
import mindustry.entities.type.Bullet;
|
||||
import mindustry.entities.bullet.BulletType;
|
||||
import mindustry.entities.traits.TargetTrait;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.Block;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
@@ -133,7 +126,7 @@ public abstract class Turret extends Block{
|
||||
|
||||
@Override
|
||||
public void drawSelect(Tile tile){
|
||||
Drawf.dashCircle(tile.drawx(), tile.drawy(), range, tile.getTeam().color);
|
||||
Drawf.dashCircle(tile.drawx(), tile.drawy(), range, tile.team().color);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,7 +145,7 @@ public abstract class Turret extends Block{
|
||||
|
||||
if(hasAmmo(tile)){
|
||||
|
||||
if(entity.timer.get(timerTarget, targetInterval)){
|
||||
if(entity.timer(timerTarget, targetInterval)){
|
||||
findTarget(tile);
|
||||
}
|
||||
|
||||
@@ -186,16 +179,16 @@ public abstract class Turret extends Block{
|
||||
|
||||
protected boolean validateTarget(Tile tile){
|
||||
TurretEntity entity = tile.ent();
|
||||
return !Units.invalidateTarget(entity.target, tile.getTeam(), tile.drawx(), tile.drawy());
|
||||
return !Units.invalidateTarget(entity.target, tile.team(), tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
protected void findTarget(Tile tile){
|
||||
TurretEntity entity = tile.ent();
|
||||
|
||||
if(targetAir && !targetGround){
|
||||
entity.target = Units.closestEnemy(tile.getTeam(), tile.drawx(), tile.drawy(), range, e -> !e.isDead() && e.isFlying());
|
||||
entity.target = Units.closestEnemy(tile.team(), tile.drawx(), tile.drawy(), range, e -> !e.dead() && !e.isGrounded());
|
||||
}else{
|
||||
entity.target = Units.closestTarget(tile.getTeam(), tile.drawx(), tile.drawy(), range, e -> !e.isDead() && (!e.isFlying() || targetAir) && (e.isFlying() || targetGround));
|
||||
entity.target = Units.closestTarget(tile.team(), tile.drawx(), tile.drawy(), range, e -> !e.dead() && (e.isGrounded() || targetAir) && (!e.isGrounded() || targetGround));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +262,7 @@ public abstract class Turret extends Block{
|
||||
}
|
||||
|
||||
protected void bullet(Tile tile, BulletType type, float angle){
|
||||
Bullet.create(type, tile.entity, tile.getTeam(), tile.drawx() + tr.x, tile.drawy() + tr.y, angle);
|
||||
type.create(tile.entity, tile.team(), tile.drawx() + tr.x, tile.drawy() + tr.y, angle);
|
||||
}
|
||||
|
||||
protected void effects(Tile tile){
|
||||
@@ -278,8 +271,8 @@ public abstract class Turret extends Block{
|
||||
|
||||
TurretEntity entity = tile.ent();
|
||||
|
||||
Effects.effect(shootEffect, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
Effects.effect(smokeEffect, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
shootEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
smokeEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
shootSound.at(tile, Mathf.random(0.9f, 1.1f));
|
||||
|
||||
if(shootShake > 0){
|
||||
@@ -293,7 +286,7 @@ public abstract class Turret extends Block{
|
||||
if(!isTurret(tile)) return;
|
||||
TurretEntity entity = tile.ent();
|
||||
|
||||
Effects.effect(ammoUseEffect, tile.drawx() - Angles.trnsx(entity.rotation, ammoEjectBack),
|
||||
ammoUseEffect.at(tile.drawx() - Angles.trnsx(entity.rotation, ammoEjectBack),
|
||||
tile.drawy() - Angles.trnsy(entity.rotation, ammoEjectBack), entity.rotation);
|
||||
}
|
||||
|
||||
@@ -319,6 +312,27 @@ public abstract class Turret extends Block{
|
||||
public float recoil = 0f;
|
||||
public float heat;
|
||||
public int shots;
|
||||
public TargetTrait target;
|
||||
public Posc target;
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(reload);
|
||||
write.f(rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
if(revision == 1){
|
||||
reload = read.f();
|
||||
rotation = read.f();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
@@ -23,12 +24,12 @@ public class BufferedItemBridge extends ExtendingItemBridge{
|
||||
public void updateTransport(Tile tile, Tile other){
|
||||
BufferedItemBridgeEntity entity = tile.ent();
|
||||
|
||||
if(entity.buffer.accepts() && entity.items.total() > 0){
|
||||
entity.buffer.accept(entity.items.take());
|
||||
if(entity.buffer.accepts() && entity.items().total() > 0){
|
||||
entity.buffer.accept(entity.items().take());
|
||||
}
|
||||
|
||||
Item item = entity.buffer.poll();
|
||||
if(entity.timer.get(timerAccept, 4) && item != null && other.block().acceptItem(item, other, tile)){
|
||||
if(entity.timer(timerAccept, 4) && item != null && other.block().acceptItem(item, other, tile)){
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
|
||||
other.block().handleItem(item, other, tile);
|
||||
entity.buffer.remove();
|
||||
@@ -41,15 +42,15 @@ public class BufferedItemBridge extends ExtendingItemBridge{
|
||||
ItemBuffer buffer = new ItemBuffer(bufferCapacity, speed);
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
buffer.write(stream);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
buffer.write(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
buffer.read(stream);
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
buffer.read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
@@ -24,10 +25,8 @@ import static mindustry.Vars.*;
|
||||
|
||||
public class Conveyor extends Block implements Autotiler{
|
||||
private static final float itemSpace = 0.4f;
|
||||
private static final float minmove = 1f / (Short.MAX_VALUE - 2);
|
||||
private static ItemPos drawpos = new ItemPos();
|
||||
private static ItemPos pos1 = new ItemPos();
|
||||
private static ItemPos pos2 = new ItemPos();
|
||||
private static final int capacity = 4;
|
||||
|
||||
private final Vec2 tr1 = new Vec2();
|
||||
private final Vec2 tr2 = new Vec2();
|
||||
private TextureRegion[][] regions = new TextureRegion[7][4];
|
||||
@@ -51,12 +50,6 @@ public class Conveyor extends Block implements Autotiler{
|
||||
unloadable = false;
|
||||
}
|
||||
|
||||
private static int compareItems(long a, long b){
|
||||
pos1.set(a, ItemPos.packShorts);
|
||||
pos2.set(b, ItemPos.packShorts);
|
||||
return Float.compare(pos1.y, pos2.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
@@ -80,7 +73,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
ConveyorEntity entity = tile.ent();
|
||||
byte rotation = tile.rotation();
|
||||
|
||||
int frame = entity.clogHeat <= 0.5f ? (int)(((Time.time() * speed * 8f * entity.timeScale)) % 4) : 0;
|
||||
int frame = entity.clogHeat <= 0.5f ? (int)(((Time.time() * speed * 8f * entity.timeScale())) % 4) : 0;
|
||||
Draw.rect(regions[Mathf.clamp(entity.blendbits, 0, regions.length - 1)][Mathf.clamp(frame, 0, regions[0].length - 1)], tile.drawx(), tile.drawy(),
|
||||
tilesize * entity.blendsclx, tilesize * entity.blendscly, rotation * 90);
|
||||
}
|
||||
@@ -100,6 +93,12 @@ public class Conveyor extends Block implements Autotiler{
|
||||
entity.blendbits = bits[0];
|
||||
entity.blendsclx = bits[1];
|
||||
entity.blendscly = bits[2];
|
||||
|
||||
if(tile.front() != null && tile.front().entity != null){
|
||||
entity.next = tile.front().entity;
|
||||
entity.nextc = entity.next instanceof ConveyorEntity && entity.next.team() == tile.team() ? (ConveyorEntity)entity.next : null;
|
||||
entity.aligned = entity.nextc != null && tile.rotation() == entity.next.tile().rotation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,32 +123,22 @@ public class Conveyor extends Block implements Autotiler{
|
||||
|
||||
@Override
|
||||
public void drawLayer(Tile tile){
|
||||
ConveyorEntity entity = tile.ent();
|
||||
|
||||
ConveyorEntity e = tile.ent();
|
||||
byte rotation = tile.rotation();
|
||||
|
||||
try{
|
||||
for(int i = 0; i < e.len; i++){
|
||||
Item item = e.ids[i];
|
||||
tr1.trns(rotation * 90, tilesize, 0);
|
||||
tr2.trns(rotation * 90, -tilesize / 2f, e.xs[i] * tilesize / 2f);
|
||||
|
||||
for(int i = 0; i < entity.convey.size; i++){
|
||||
ItemPos pos = drawpos.set(entity.convey.get(i), ItemPos.drawShorts);
|
||||
|
||||
if(pos.item == null) continue;
|
||||
|
||||
tr1.trns(rotation * 90, tilesize, 0);
|
||||
tr2.trns(rotation * 90, -tilesize / 2f, pos.x * tilesize / 2f);
|
||||
|
||||
Draw.rect(pos.item.icon(Cicon.medium),
|
||||
(tile.x * tilesize + tr1.x * pos.y + tr2.x),
|
||||
(tile.y * tilesize + tr1.y * pos.y + tr2.y), itemSize, itemSize);
|
||||
}
|
||||
|
||||
}catch(IndexOutOfBoundsException e){
|
||||
Log.err(e);
|
||||
Draw.rect(item.icon(Cicon.medium),
|
||||
(tile.x * tilesize + tr1.x * e.ys[i] + tr2.x),
|
||||
(tile.y * tilesize + tr1.y * e.ys[i] + tr2.y), itemSize, itemSize);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitOn(Tile tile, Unit unit){
|
||||
public void unitOn(Tile tile, Unitc unit){
|
||||
ConveyorEntity entity = tile.ent();
|
||||
|
||||
if(entity.clogHeat > 0.5f){
|
||||
@@ -166,86 +155,63 @@ public class Conveyor extends Block implements Autotiler{
|
||||
float centerx = 0f, centery = 0f;
|
||||
|
||||
if(Math.abs(tx) > Math.abs(ty)){
|
||||
centery = Mathf.clamp((tile.worldy() - unit.y) / centerDstScl, -centerSpeed, centerSpeed);
|
||||
if(Math.abs(tile.worldy() - unit.y) < 1f) centery = 0f;
|
||||
centery = Mathf.clamp((tile.worldy() - unit.y()) / centerDstScl, -centerSpeed, centerSpeed);
|
||||
if(Math.abs(tile.worldy() - unit.y()) < 1f) centery = 0f;
|
||||
}else{
|
||||
centerx = Mathf.clamp((tile.worldx() - unit.x) / centerDstScl, -centerSpeed, centerSpeed);
|
||||
if(Math.abs(tile.worldx() - unit.x) < 1f) centerx = 0f;
|
||||
centerx = Mathf.clamp((tile.worldx() - unit.x()) / centerDstScl, -centerSpeed, centerSpeed);
|
||||
if(Math.abs(tile.worldx() - unit.x()) < 1f) centerx = 0f;
|
||||
}
|
||||
|
||||
if(entity.convey.size * itemSpace < 0.9f){
|
||||
unit.applyImpulse((tx * speed + centerx) * entity.delta(), (ty * speed + centery) * entity.delta());
|
||||
if(entity.len * itemSpace < 0.9f){
|
||||
unit.impulse((tx * speed + centerx) * entity.delta(), (ty * speed + centery) * entity.delta());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
ConveyorEntity entity = tile.ent();
|
||||
entity.minitem = 1f;
|
||||
Tile next = tile.getNearby(tile.rotation());
|
||||
if(next != null) next = next.link();
|
||||
ConveyorEntity e = tile.ent();
|
||||
e.minitem = 1f;
|
||||
e.mid = 0;
|
||||
|
||||
float nextMax = next != null && next.block() instanceof Conveyor && next.block().acceptItem(null, next, tile) ? 1f - Math.max(itemSpace - next.<ConveyorEntity>ent().minitem, 0) : 1f;
|
||||
int minremove = Integer.MAX_VALUE;
|
||||
//skip updates if possible
|
||||
if(e.len == 0){
|
||||
e.clogHeat = 0f;
|
||||
e.sleep();
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = entity.convey.size - 1; i >= 0; i--){
|
||||
long value = entity.convey.get(i);
|
||||
ItemPos pos = pos1.set(value, ItemPos.updateShorts);
|
||||
float nextMax = e.aligned ? 1f - Math.max(itemSpace - e.nextc.minitem, 0) : 1f;
|
||||
|
||||
//..this should never happen, but in case it does, remove it and stop here
|
||||
if(pos.item == null){
|
||||
entity.convey.removeValue(value);
|
||||
break;
|
||||
}
|
||||
for(int i = e.len - 1; i >= 0; i--){
|
||||
float nextpos = (i == e.len - 1 ? 100f : e.ys[i + 1]) - itemSpace;
|
||||
float maxmove = Mathf.clamp(nextpos - e.ys[i], 0, speed * e.delta());
|
||||
|
||||
float nextpos = (i == entity.convey.size - 1 ? 100f : pos2.set(entity.convey.get(i + 1), ItemPos.updateShorts).y) - itemSpace;
|
||||
float maxmove = Math.min(nextpos - pos.y, speed * entity.delta());
|
||||
e.ys[i] += maxmove;
|
||||
|
||||
if(maxmove > minmove){
|
||||
pos.y += maxmove;
|
||||
if(Mathf.equal(pos.x, 0, 0.1f)){
|
||||
pos.x = 0f;
|
||||
if(e.ys[i] > nextMax) e.ys[i] = nextMax;
|
||||
if(e.ys[i] > 0.5 && i > 0) e.mid = i - 1;
|
||||
e.xs[i] = Mathf.approachDelta(e.xs[i], 0, speed*2);
|
||||
|
||||
if(e.ys[i] >= 1f && offloadDir(tile, e.ids[i])){
|
||||
//align X position if passing forwards
|
||||
if(e.aligned){
|
||||
e.nextc.xs[e.nextc.lastInserted] = e.xs[i];
|
||||
}
|
||||
pos.x = Mathf.lerpDelta(pos.x, 0, 0.1f);
|
||||
}
|
||||
|
||||
pos.y = Mathf.clamp(pos.y, 0, nextMax);
|
||||
|
||||
if(pos.y >= 0.9999f && offloadDir(tile, pos.item)){
|
||||
if(next != null && next.block() instanceof Conveyor){
|
||||
ConveyorEntity othere = next.ent();
|
||||
|
||||
ItemPos ni = pos2.set(othere.convey.get(othere.lastInserted), ItemPos.updateShorts);
|
||||
|
||||
if(next.rotation() == tile.rotation()){
|
||||
ni.x = pos.x;
|
||||
}
|
||||
othere.convey.set(othere.lastInserted, ni.pack());
|
||||
}
|
||||
minremove = Math.min(i, minremove);
|
||||
tile.entity.items.remove(pos.item, 1);
|
||||
}else{
|
||||
value = pos.pack();
|
||||
|
||||
if(pos.y < entity.minitem)
|
||||
entity.minitem = pos.y;
|
||||
entity.convey.set(i, value);
|
||||
//remove last item
|
||||
e.items().remove(e.ids[i], e.len - i);
|
||||
e.len = Math.min(i, e.len);
|
||||
}else if(e.ys[i] < e.minitem){
|
||||
e.minitem = e.ys[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(entity.minitem < itemSpace){
|
||||
entity.clogHeat = Mathf.lerpDelta(entity.clogHeat, 1f, 0.02f);
|
||||
if(e.minitem < itemSpace + (e.blendbits == 1 ? 0.3f : 0f)){
|
||||
e.clogHeat = Mathf.lerpDelta(e.clogHeat, 1f, 0.02f);
|
||||
}else{
|
||||
entity.clogHeat = Mathf.lerpDelta(entity.clogHeat, 0f, 1f);
|
||||
e.clogHeat = 0f;
|
||||
}
|
||||
|
||||
if(entity.items.total() == 0){
|
||||
entity.sleep();
|
||||
}else{
|
||||
entity.noSleep();
|
||||
}
|
||||
|
||||
if(minremove != Integer.MAX_VALUE) entity.convey.truncate(minremove);
|
||||
e.noSleep();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -265,22 +231,22 @@ public class Conveyor extends Block implements Autotiler{
|
||||
|
||||
@Override
|
||||
public int removeStack(Tile tile, Item item, int amount){
|
||||
ConveyorEntity entity = tile.ent();
|
||||
entity.noSleep();
|
||||
ConveyorEntity e = tile.ent();
|
||||
e.noSleep();
|
||||
int removed = 0;
|
||||
|
||||
for(int j = 0; j < amount; j++){
|
||||
for(int i = 0; i < entity.convey.size; i++){
|
||||
long val = entity.convey.get(i);
|
||||
ItemPos pos = pos1.set(val, ItemPos.drawShorts);
|
||||
if(pos.item == item){
|
||||
entity.convey.removeValue(val);
|
||||
entity.items.remove(item, 1);
|
||||
removed++;
|
||||
for(int i = 0; i < e.len; i++){
|
||||
if(e.ids[i] == item){
|
||||
e.remove(i);
|
||||
removed ++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
e.items().remove(item, removed);
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
@@ -290,65 +256,74 @@ public class Conveyor extends Block implements Autotiler{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
ConveyorEntity entity = tile.ent();
|
||||
return Math.min((int)(entity.minitem / itemSpace), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleStack(Item item, int amount, Tile tile, Unit source){
|
||||
ConveyorEntity entity = tile.ent();
|
||||
public void handleStack(Item item, int amount, Tile tile, Teamc source){
|
||||
ConveyorEntity e = tile.ent();
|
||||
amount = Math.min(amount, itemCapacity - e.len);
|
||||
|
||||
for(int i = amount - 1; i >= 0; i--){
|
||||
long result = ItemPos.packItem(item, 0f, i * itemSpace);
|
||||
entity.convey.insert(0, result);
|
||||
entity.items.add(item, 1);
|
||||
e.add(0);
|
||||
e.xs[0] = 0;
|
||||
e.ys[0] = i * itemSpace;
|
||||
e.ids[0] = item;
|
||||
e.items().add(item, 1);
|
||||
}
|
||||
|
||||
entity.noSleep();
|
||||
e.noSleep();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
ConveyorEntity e = tile.ent();
|
||||
if(e.len >= capacity) return false;
|
||||
int direction = source == null ? 0 : Math.abs(source.relativeTo(tile.x, tile.y) - tile.rotation());
|
||||
float minitem = tile.<ConveyorEntity>ent().minitem;
|
||||
return (((direction == 0) && minitem > itemSpace) ||
|
||||
((direction % 2 == 1) && minitem > 0.52f)) && (source == null || !(source.block().rotate && (source.rotation() + 2) % 4 == tile.rotation()));
|
||||
return (((direction == 0) && e.minitem >= itemSpace) || ((direction % 2 == 1) && e.minitem > 0.7f)) && (source == null || !(source.block().rotate && (source.rotation() + 2) % 4 == tile.rotation()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
byte rotation = tile.rotation();
|
||||
ConveyorEntity e = tile.ent();
|
||||
if(e.len >= capacity) return;
|
||||
|
||||
int ch = Math.abs(source.relativeTo(tile.x, tile.y) - rotation);
|
||||
int ang = ((source.relativeTo(tile.x, tile.y) - rotation));
|
||||
byte r = tile.rotation();
|
||||
int ang = ((source.relativeTo(tile.x, tile.y) - r));
|
||||
float x = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0;
|
||||
|
||||
float pos = ch == 0 ? 0 : ch % 2 == 1 ? 0.5f : 1f;
|
||||
float y = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0;
|
||||
e.noSleep();
|
||||
e.items().add(item, 1);
|
||||
|
||||
ConveyorEntity entity = tile.ent();
|
||||
entity.noSleep();
|
||||
long result = ItemPos.packItem(item, y * 0.9f, pos);
|
||||
|
||||
tile.entity.items.add(item, 1);
|
||||
|
||||
for(int i = 0; i < entity.convey.size; i++){
|
||||
if(compareItems(result, entity.convey.get(i)) < 0){
|
||||
entity.convey.insert(i, result);
|
||||
entity.lastInserted = (byte)i;
|
||||
return;
|
||||
}
|
||||
if(Math.abs(source.relativeTo(tile.x, tile.y) - r) == 0){ //idx = 0
|
||||
e.add(0);
|
||||
e.xs[0] = x;
|
||||
e.ys[0] = 0;
|
||||
e.ids[0] = item;
|
||||
}else{ //idx = mid
|
||||
e.add(e.mid);
|
||||
e.xs[e.mid] = x;
|
||||
e.ys[e.mid] = 0.5f;
|
||||
e.ids[e.mid] = item;
|
||||
}
|
||||
|
||||
//this item must be greater than anything there...
|
||||
entity.convey.add(result);
|
||||
entity.lastInserted = (byte)(entity.convey.size - 1);
|
||||
}
|
||||
|
||||
public static class ConveyorEntity extends TileEntity{
|
||||
//parallel array data
|
||||
Item[] ids = new Item[capacity];
|
||||
float[] xs = new float[capacity];
|
||||
float[] ys = new float[capacity];
|
||||
//amount of items, always < capacity
|
||||
int len = 0;
|
||||
//next entity
|
||||
@Nullable Tilec next;
|
||||
@Nullable ConveyorEntity nextc;
|
||||
//whether the next conveyor's rotation == tile rotation
|
||||
boolean aligned;
|
||||
|
||||
LongArray convey = new LongArray();
|
||||
byte lastInserted;
|
||||
int lastInserted, mid;
|
||||
float minitem = 1;
|
||||
|
||||
int blendbits;
|
||||
@@ -356,96 +331,53 @@ public class Conveyor extends Block implements Autotiler{
|
||||
|
||||
float clogHeat = 0f;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(convey.size);
|
||||
final void add(int o){
|
||||
for(int i = Math.max(o + 1, len); i > o; i--){
|
||||
ids[i] = ids[i - 1];
|
||||
xs[i] = xs[i - 1];
|
||||
ys[i] = ys[i - 1];
|
||||
}
|
||||
|
||||
for(int i = 0; i < convey.size; i++){
|
||||
stream.writeInt(ItemPos.toInt(convey.get(i)));
|
||||
len++;
|
||||
}
|
||||
|
||||
final void remove(int o){
|
||||
for(int i = o; i < len - 1; i++){
|
||||
ids[i] = ids[i + 1];
|
||||
xs[i] = xs[i + 1];
|
||||
ys[i] = ys[i + 1];
|
||||
}
|
||||
|
||||
len--;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.i(len);
|
||||
|
||||
for(int i = 0; i < len; i++){
|
||||
write.i(Pack.intBytes((byte)ids[i].id, (byte)(xs[i] * 127), (byte)(ys[i] * 255 - 128), (byte)0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
convey.clear();
|
||||
int amount = stream.readInt();
|
||||
convey.ensureCapacity(Math.min(amount, 10));
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
int amount = read.i();
|
||||
len = Math.min(amount, capacity);
|
||||
|
||||
for(int i = 0; i < amount; i++){
|
||||
convey.add(ItemPos.toLong(stream.readInt()));
|
||||
int val = read.i();
|
||||
byte id = (byte)(val >> 24);
|
||||
float x = (float)((byte)(val >> 16)) / 127f;
|
||||
float y = ((float)((byte)(val >> 8)) + 128f) / 255f;
|
||||
if(i < capacity){
|
||||
ids[i] = content.item(id);
|
||||
xs[i] = x;
|
||||
ys[i] = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Container class. Do not instantiate.
|
||||
static class ItemPos{
|
||||
private static short[] writeShort = new short[4];
|
||||
private static byte[] writeByte = new byte[4];
|
||||
|
||||
private static short[] packShorts = new short[4];
|
||||
private static short[] drawShorts = new short[4];
|
||||
private static short[] updateShorts = new short[4];
|
||||
|
||||
Item item;
|
||||
float x, y;
|
||||
|
||||
private ItemPos(){
|
||||
}
|
||||
|
||||
static long packItem(Item item, float x, float y){
|
||||
short[] shorts = packShorts;
|
||||
shorts[0] = (short)item.id;
|
||||
shorts[1] = (short)(x * Short.MAX_VALUE);
|
||||
shorts[2] = (short)((y - 1f) * Short.MAX_VALUE);
|
||||
return Pack.longShorts(shorts);
|
||||
}
|
||||
|
||||
static int toInt(long value){
|
||||
short[] values = Pack.shorts(value, writeShort);
|
||||
|
||||
short itemid = values[0];
|
||||
float x = values[1] / (float)Short.MAX_VALUE;
|
||||
float y = ((float)values[2]) / Short.MAX_VALUE + 1f;
|
||||
|
||||
byte[] bytes = writeByte;
|
||||
bytes[0] = (byte)itemid;
|
||||
bytes[1] = (byte)(x * 127);
|
||||
bytes[2] = (byte)(y * 255 - 128);
|
||||
|
||||
return Pack.intBytes(bytes);
|
||||
}
|
||||
|
||||
static long toLong(int value){
|
||||
byte[] values = Pack.bytes(value, writeByte);
|
||||
|
||||
short itemid = content.item(values[0]).id;
|
||||
float x = values[1] / 127f;
|
||||
float y = ((int)values[2] + 128) / 255f;
|
||||
|
||||
short[] shorts = writeShort;
|
||||
shorts[0] = itemid;
|
||||
shorts[1] = (short)(x * Short.MAX_VALUE);
|
||||
shorts[2] = (short)((y - 1f) * Short.MAX_VALUE);
|
||||
return Pack.longShorts(shorts);
|
||||
}
|
||||
|
||||
ItemPos set(long lvalue, short[] values){
|
||||
Pack.shorts(lvalue, values);
|
||||
|
||||
if(values[0] >= content.items().size || values[0] < 0)
|
||||
item = null;
|
||||
else
|
||||
item = content.items().get(values[0]);
|
||||
|
||||
x = values[1] / (float)Short.MAX_VALUE;
|
||||
y = ((float)values[2]) / Short.MAX_VALUE + 1f;
|
||||
return this;
|
||||
}
|
||||
|
||||
long pack(){
|
||||
return packItem(item, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
@@ -45,7 +46,7 @@ public class ItemBridge extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
tile.<ItemBridgeEntity>ent().link = value;
|
||||
}
|
||||
|
||||
@@ -187,7 +188,7 @@ public class ItemBridge extends Block{
|
||||
}else{
|
||||
((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos());
|
||||
|
||||
if(entity.cons.valid() && Mathf.zero(1f - entity.efficiency())){
|
||||
if(entity.consValid() && Mathf.zero(1f - entity.efficiency())){
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
|
||||
}else{
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
|
||||
@@ -200,14 +201,14 @@ public class ItemBridge extends Block{
|
||||
public void updateTransport(Tile tile, Tile other){
|
||||
ItemBridgeEntity entity = tile.ent();
|
||||
|
||||
if(entity.uptime >= 0.5f && entity.timer.get(timerTransport, transportTime)){
|
||||
Item item = entity.items.take();
|
||||
if(entity.uptime >= 0.5f && entity.timer(timerTransport, transportTime)){
|
||||
Item item = entity.items().take();
|
||||
if(item != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
|
||||
}else{
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);
|
||||
if(item != null) entity.items.add(item, 1);
|
||||
if(item != null) entity.items().add(item, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,7 +256,7 @@ public class ItemBridge extends Block{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
if(tile.getTeam() != source.getTeam()) return false;
|
||||
if(tile.team() != source.team()) return false;
|
||||
|
||||
ItemBridgeEntity entity = tile.ent();
|
||||
Tile other = world.tile(entity.link);
|
||||
@@ -266,10 +267,10 @@ public class ItemBridge extends Block{
|
||||
|
||||
if(rel == rel2) return false;
|
||||
}else{
|
||||
return source.block() instanceof ItemBridge && source.<ItemBridgeEntity>ent().link == tile.pos() && tile.entity.items.total() < itemCapacity;
|
||||
return source.block() instanceof ItemBridge && source.<ItemBridgeEntity>ent().link == tile.pos() && tile.entity.items().total() < itemCapacity;
|
||||
}
|
||||
|
||||
return tile.entity.items.total() < itemCapacity;
|
||||
return tile.entity.items().total() < itemCapacity;
|
||||
}
|
||||
|
||||
|
||||
@@ -301,7 +302,7 @@ public class ItemBridge extends Block{
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
if(tile.getTeam() != source.getTeam() || !hasLiquids) return false;
|
||||
if(tile.team() != source.team() || !hasLiquids) return false;
|
||||
|
||||
ItemBridgeEntity entity = tile.ent();
|
||||
Tile other = world.tile(entity.link);
|
||||
@@ -315,7 +316,7 @@ public class ItemBridge extends Block{
|
||||
return false;
|
||||
}
|
||||
|
||||
return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f);
|
||||
return tile.entity.liquids().get(liquid) + amount < liquidCapacity && (tile.entity.liquids().current() == liquid || tile.entity.liquids().get(tile.entity.liquids().current()) < 0.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -375,27 +376,27 @@ public class ItemBridge extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(link);
|
||||
stream.writeFloat(uptime);
|
||||
stream.writeByte(incoming.size);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.i(link);
|
||||
write.f(uptime);
|
||||
write.b(incoming.size);
|
||||
|
||||
IntSetIterator it = incoming.iterator();
|
||||
|
||||
while(it.hasNext){
|
||||
stream.writeInt(it.next());
|
||||
write.i(it.next());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
link = stream.readInt();
|
||||
uptime = stream.readFloat();
|
||||
byte links = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
link = read.i();
|
||||
uptime = read.f();
|
||||
byte links = read.b();
|
||||
for(int i = 0; i < links; i++){
|
||||
incoming.add(stream.readInt());
|
||||
incoming.add(read.i());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.util.Time;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.entities.type.Unit;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.gen.BufferItem;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.world.Block;
|
||||
@@ -10,8 +10,6 @@ import mindustry.world.DirectionalItemBuffer;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.meta.BlockGroup;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
@@ -24,14 +22,13 @@ public class Junction extends Block{
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
instantTransfer = true;
|
||||
group = BlockGroup.transportation;
|
||||
unloadable = false;
|
||||
entityType = JunctionEntity::new;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -58,7 +55,7 @@ public class Junction extends Block{
|
||||
if(dest != null) dest = dest.link();
|
||||
|
||||
//skip blocks that don't want the item, keep waiting until they do
|
||||
if(dest == null || !dest.block().acceptItem(item, dest, tile) || dest.getTeam() != tile.getTeam()){
|
||||
if(dest == null || !dest.block().acceptItem(item, dest, tile) || dest.team() != tile.team()){
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -84,22 +81,22 @@ public class Junction extends Block{
|
||||
|
||||
if(entity == null || relative == -1 || !entity.buffer.accepts(relative)) return false;
|
||||
Tile to = tile.getNearby(relative);
|
||||
return to != null && to.link().entity != null && to.getTeam() == tile.getTeam();
|
||||
return to != null && to.link().entity != null && to.team() == tile.team();
|
||||
}
|
||||
|
||||
class JunctionEntity extends TileEntity{
|
||||
DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity, speed);
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
buffer.write(stream);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
buffer.write(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
buffer.read(stream);
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
buffer.read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import arc.struct.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.pooling.Pool.*;
|
||||
import arc.util.pooling.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Effects.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
@@ -46,7 +46,7 @@ public class MassDriver extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
tile.<MassDriverEntity>ent().link = value;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class MassDriver extends Block{
|
||||
//switch states
|
||||
if(entity.state == DriverState.idle){
|
||||
//start accepting when idle and there's space
|
||||
if(!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items.total() >= minDistribute)){
|
||||
if(!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items().total() >= minDistribute)){
|
||||
entity.state = DriverState.accepting;
|
||||
}else if(hasLink){ //switch to shooting if there's a valid link.
|
||||
entity.state = DriverState.shooting;
|
||||
@@ -94,13 +94,13 @@ public class MassDriver extends Block{
|
||||
}
|
||||
|
||||
//skip when there's no power
|
||||
if(!entity.cons.valid()){
|
||||
if(!entity.consValid()){
|
||||
return;
|
||||
}
|
||||
|
||||
if(entity.state == DriverState.accepting){
|
||||
//if there's nothing shooting at this, bail - OR, items full
|
||||
if(entity.currentShooter() == null || (itemCapacity - entity.items.total() < minDistribute)){
|
||||
if(entity.currentShooter() == null || (itemCapacity - entity.items().total() < minDistribute)){
|
||||
entity.state = DriverState.idle;
|
||||
return;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class MassDriver extends Block{
|
||||
entity.rotation = Mathf.slerpDelta(entity.rotation, tile.angleTo(entity.currentShooter()), rotateSpeed * entity.efficiency());
|
||||
}else if(entity.state == DriverState.shooting){
|
||||
//if there's nothing to shoot at OR someone wants to shoot at this thing, bail
|
||||
if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items.total() >= minDistribute))){
|
||||
if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items().total() >= minDistribute))){
|
||||
entity.state = DriverState.idle;
|
||||
return;
|
||||
}
|
||||
@@ -117,8 +117,8 @@ public class MassDriver extends Block{
|
||||
float targetRotation = tile.angleTo(link);
|
||||
|
||||
if(
|
||||
tile.entity.items.total() >= minDistribute && //must shoot minimum amount of items
|
||||
link.block().itemCapacity - link.entity.items.total() >= minDistribute //must have minimum amount of space
|
||||
tile.entity.items().total() >= minDistribute && //must shoot minimum amount of items
|
||||
link.block().itemCapacity - link.entity.items().total() >= minDistribute //must have minimum amount of space
|
||||
){
|
||||
MassDriverEntity other = link.ent();
|
||||
other.waitingShooters.add(tile);
|
||||
@@ -192,6 +192,11 @@ public class MassDriver extends Block{
|
||||
|
||||
MassDriverEntity entity = tile.ent();
|
||||
|
||||
for(Tile shooter : entity.waitingShooters){
|
||||
Drawf.circles(shooter.drawx(), shooter.drawy(), (tile.block().size / 2f + 1) * tilesize + sin - 2f, Pal.place);
|
||||
Drawf.arrow(shooter.drawx(), shooter.drawy(), tile.drawx(), tile.drawy(), size * tilesize + sin, 4f + sin, Pal.place);
|
||||
}
|
||||
|
||||
if(linkValid(tile)){
|
||||
Tile target = world.tile(entity.link);
|
||||
Drawf.circles(target.drawx(), target.drawy(), (target.block().size / 2f + 1) * tilesize + sin - 2f, Pal.place);
|
||||
@@ -210,7 +215,7 @@ public class MassDriver extends Block{
|
||||
if(entity.link == other.pos()){
|
||||
tile.configure(-1);
|
||||
return false;
|
||||
}else if(other.block() instanceof MassDriver && other.dst(tile) <= range && other.getTeam() == tile.getTeam()){
|
||||
}else if(other.block() instanceof MassDriver && other.dst(tile) <= range && other.team() == tile.team()){
|
||||
tile.configure(other.pos());
|
||||
return false;
|
||||
}
|
||||
@@ -221,7 +226,7 @@ public class MassDriver extends Block{
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
//mass drivers that ouput only cannot accept items
|
||||
return tile.entity.items.total() < itemCapacity && linkValid(tile);
|
||||
return tile.entity.items().total() < itemCapacity && linkValid(tile);
|
||||
}
|
||||
|
||||
protected void fire(Tile tile, Tile target){
|
||||
@@ -236,34 +241,34 @@ public class MassDriver extends Block{
|
||||
data.to = other;
|
||||
int totalUsed = 0;
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
int maxTransfer = Math.min(entity.items.get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed);
|
||||
int maxTransfer = Math.min(entity.items().get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed);
|
||||
data.items[i] = maxTransfer;
|
||||
totalUsed += maxTransfer;
|
||||
entity.items.remove(content.item(i), maxTransfer);
|
||||
entity.items().remove(content.item(i), maxTransfer);
|
||||
}
|
||||
|
||||
float angle = tile.angleTo(target);
|
||||
|
||||
Bullet.create(Bullets.driverBolt, entity, entity.getTeam(),
|
||||
Bullets.driverBolt.create(entity, entity.team(),
|
||||
tile.drawx() + Angles.trnsx(angle, translation), tile.drawy() + Angles.trnsy(angle, translation),
|
||||
angle, 1f, 1f, data);
|
||||
angle, -1f, 1f, 1f, data);
|
||||
|
||||
Effects.effect(shootEffect, tile.drawx() + Angles.trnsx(angle, translation),
|
||||
shootEffect.at(tile.drawx() + Angles.trnsx(angle, translation),
|
||||
tile.drawy() + Angles.trnsy(angle, translation), angle);
|
||||
|
||||
Effects.effect(smokeEffect, tile.drawx() + Angles.trnsx(angle, translation),
|
||||
smokeEffect.at(tile.drawx() + Angles.trnsx(angle, translation),
|
||||
tile.drawy() + Angles.trnsy(angle, translation), angle);
|
||||
|
||||
Effects.shake(shake, shake, entity);
|
||||
}
|
||||
|
||||
protected void handlePayload(MassDriverEntity entity, Bullet bullet, DriverBulletData data){
|
||||
int totalItems = entity.items.total();
|
||||
protected void handlePayload(MassDriverEntity entity, Bulletc bullet, DriverBulletData data){
|
||||
int totalItems = entity.items().total();
|
||||
|
||||
//add all the items possible
|
||||
for(int i = 0; i < data.items.length; i++){
|
||||
int maxAdd = Math.min(data.items[i], itemCapacity * 2 - totalItems);
|
||||
entity.items.add(content.item(i), maxAdd);
|
||||
entity.items().add(content.item(i), maxAdd);
|
||||
data.items[i] -= maxAdd;
|
||||
totalItems += maxAdd;
|
||||
|
||||
@@ -273,7 +278,7 @@ public class MassDriver extends Block{
|
||||
}
|
||||
|
||||
Effects.shake(shake, shake, entity);
|
||||
Effects.effect(recieveEffect, bullet);
|
||||
recieveEffect.at(bullet);
|
||||
|
||||
entity.reload = 1f;
|
||||
bullet.remove();
|
||||
@@ -293,7 +298,7 @@ public class MassDriver extends Block{
|
||||
if(entity == null || entity.link == -1) return false;
|
||||
Tile link = world.tile(entity.link);
|
||||
|
||||
return link != null && link.block() instanceof MassDriver && link.getTeam() == tile.getTeam() && tile.dst(link) <= range;
|
||||
return link != null && link.block() instanceof MassDriver && link.team() == tile.team() && tile.dst(link) <= range;
|
||||
}
|
||||
|
||||
public static class DriverBulletData implements Poolable{
|
||||
@@ -318,8 +323,8 @@ public class MassDriver extends Block{
|
||||
return waitingShooters.isEmpty() ? null : waitingShooters.first();
|
||||
}
|
||||
|
||||
public void handlePayload(Bullet bullet, DriverBulletData data){
|
||||
((MassDriver)block).handlePayload(this, bullet, data);
|
||||
public void handlePayload(Bulletc bullet, DriverBulletData data){
|
||||
((MassDriver)block()).handlePayload(this, bullet, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -328,19 +333,19 @@ public class MassDriver extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(link);
|
||||
stream.writeFloat(rotation);
|
||||
stream.writeByte((byte)state.ordinal());
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.i(link);
|
||||
write.f(rotation);
|
||||
write.b((byte)state.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
link = stream.readInt();
|
||||
rotation = stream.readFloat();
|
||||
state = DriverState.values()[stream.readByte()];
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
link = read.i();
|
||||
rotation = read.f();
|
||||
state = DriverState.values()[read.b()];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.math.Mathf;
|
||||
import arc.util.Time;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.type.Item;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.BlockGroup;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
import static mindustry.Vars.world;
|
||||
|
||||
public class OverflowGate extends Block{
|
||||
public float speed = 1f;
|
||||
public boolean invert = false;
|
||||
|
||||
public OverflowGate(String name){
|
||||
super(name);
|
||||
@@ -27,6 +29,11 @@ public class OverflowGate extends Block{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeStack(Tile tile, Item item, int amount){
|
||||
OverflowGateEntity entity = tile.ent();
|
||||
@@ -41,18 +48,23 @@ public class OverflowGate extends Block{
|
||||
public void update(Tile tile){
|
||||
OverflowGateEntity entity = tile.ent();
|
||||
|
||||
if(entity.lastItem == null && entity.items.total() > 0){
|
||||
entity.items.clear();
|
||||
if(entity.lastItem == null && entity.items().total() > 0){
|
||||
entity.items().clear();
|
||||
}
|
||||
|
||||
if(entity.lastItem != null){
|
||||
if(entity.lastInput == null){
|
||||
entity.lastItem = null;
|
||||
return;
|
||||
}
|
||||
|
||||
entity.time += 1f / speed * Time.delta();
|
||||
Tile target = getTileTarget(tile, entity.lastItem, entity.lastInput, false);
|
||||
|
||||
if(target != null && (entity.time >= 1f)){
|
||||
getTileTarget(tile, entity.lastItem, entity.lastInput, true);
|
||||
target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target));
|
||||
entity.items.remove(entity.lastItem, 1);
|
||||
entity.items().remove(entity.lastItem, 1);
|
||||
entity.lastItem = null;
|
||||
}
|
||||
}
|
||||
@@ -62,33 +74,36 @@ public class OverflowGate extends Block{
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
OverflowGateEntity entity = tile.ent();
|
||||
|
||||
return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.items.total() == 0;
|
||||
return tile.team() == source.team() && entity.lastItem == null && entity.items().total() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
OverflowGateEntity entity = tile.ent();
|
||||
entity.items.add(item, 1);
|
||||
entity.items().add(item, 1);
|
||||
entity.lastItem = item;
|
||||
entity.time = 0f;
|
||||
entity.lastInput = source;
|
||||
|
||||
update(tile);
|
||||
}
|
||||
|
||||
Tile getTileTarget(Tile tile, Item item, Tile src, boolean flip){
|
||||
public Tile getTileTarget(Tile tile, Item item, Tile src, boolean flip){
|
||||
int from = tile.relativeTo(src.x, src.y);
|
||||
if(from == -1) return null;
|
||||
Tile to = tile.getNearby((from + 2) % 4);
|
||||
if(to == null) return null;
|
||||
Tile edge = Edges.getFacingEdge(tile, to);
|
||||
boolean canForward = to.block().acceptItem(item, to, edge) && to.team() == tile.team() && !(to.block() instanceof OverflowGate);
|
||||
|
||||
if(!to.block().acceptItem(item, to, edge) || to.getTeam() != tile.getTeam() || (to.block() instanceof OverflowGate)){
|
||||
if(!canForward || invert){
|
||||
Tile a = tile.getNearby(Mathf.mod(from - 1, 4));
|
||||
Tile b = tile.getNearby(Mathf.mod(from + 1, 4));
|
||||
boolean ac = a != null && a.block().acceptItem(item, a, edge) && !(a.block() instanceof OverflowGate) && a.getTeam() == tile.getTeam();
|
||||
boolean bc = b != null && b.block().acceptItem(item, b, edge) && !(b.block() instanceof OverflowGate) && b.getTeam() == tile.getTeam();
|
||||
boolean ac = a != null && a.block().acceptItem(item, a, edge) && !(a.block() instanceof OverflowGate) && a.team() == tile.team();
|
||||
boolean bc = b != null && b.block().acceptItem(item, b, edge) && !(b.block() instanceof OverflowGate) && b.team() == tile.team();
|
||||
|
||||
if(!ac && !bc){
|
||||
return null;
|
||||
return invert && canForward ? to : null;
|
||||
}
|
||||
|
||||
if(ac && !bc){
|
||||
@@ -116,19 +131,22 @@ public class OverflowGate extends Block{
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
public void write(Writes write){
|
||||
write.i(lastInput == null ? Pos.invalid : lastInput.pos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
if(revision == 1){
|
||||
new DirectionalItemBuffer(25, 50f).read(stream);
|
||||
new DirectionalItemBuffer(25, 50f).read(read);
|
||||
}else if(revision == 3){
|
||||
lastInput = world.tile(read.i());
|
||||
lastItem = items.first();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package mindustry.world.blocks.distribution;
|
||||
import arc.struct.Array;
|
||||
import arc.util.Time;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.BlockGroup;
|
||||
@@ -26,8 +26,8 @@ public class Router extends Block{
|
||||
public void update(Tile tile){
|
||||
RouterEntity entity = tile.ent();
|
||||
|
||||
if(entity.lastItem == null && entity.items.total() > 0){
|
||||
entity.items.clear();
|
||||
if(entity.lastItem == null && entity.items().total() > 0){
|
||||
entity.items().clear();
|
||||
}
|
||||
|
||||
if(entity.lastItem != null){
|
||||
@@ -37,7 +37,7 @@ public class Router extends Block{
|
||||
if(target != null && (entity.time >= 1f || !(target.block() instanceof Router))){
|
||||
getTileTarget(tile, entity.lastItem, entity.lastInput, true);
|
||||
target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target));
|
||||
entity.items.remove(entity.lastItem, 1);
|
||||
entity.items().remove(entity.lastItem, 1);
|
||||
entity.lastItem = null;
|
||||
}
|
||||
}
|
||||
@@ -47,13 +47,13 @@ public class Router extends Block{
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
RouterEntity entity = tile.ent();
|
||||
|
||||
return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.items.total() == 0;
|
||||
return tile.team() == source.team() && entity.lastItem == null && entity.items().total() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
RouterEntity entity = tile.ent();
|
||||
entity.items.add(item, 1);
|
||||
entity.items().add(item, 1);
|
||||
entity.lastItem = item;
|
||||
entity.time = 0f;
|
||||
entity.lastInput = source;
|
||||
|
||||
@@ -3,10 +3,11 @@ package mindustry.world.blocks.distribution;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
@@ -14,7 +15,7 @@ import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Sorter extends Block{
|
||||
private static Item lastItem;
|
||||
@@ -44,6 +45,14 @@ public class Sorter extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
tile.<SorterEntity>ent().sortItem = content.item(value);
|
||||
if(!headless){
|
||||
renderer.minimap.update(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
drawRequestConfigCenter(req, (Item)req.config, "center");
|
||||
@@ -70,7 +79,7 @@ public class Sorter extends Block{
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
Tile to = getTileTarget(item, tile, source, false);
|
||||
|
||||
return to != null && to.block().acceptItem(item, to, tile) && to.getTeam() == tile.getTeam();
|
||||
return to != null && to.block().acceptItem(item, to, tile) && to.team() == tile.team();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,7 +90,8 @@ public class Sorter extends Block{
|
||||
}
|
||||
|
||||
boolean isSame(Tile tile, Tile other){
|
||||
return other != null && other.block() instanceof Sorter;
|
||||
//uncomment comment below to prevent sorter/gate chaining (hacky)
|
||||
return other != null && (other.block() instanceof Sorter/* || other.block() instanceof OverflowGate */);
|
||||
}
|
||||
|
||||
Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip){
|
||||
@@ -128,7 +138,7 @@ public class Sorter extends Block{
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
SorterEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.sortItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
@@ -153,17 +163,18 @@ public class Sorter extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeShort(sortItem == null ? -1 : sortItem.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.s(sortItem == null ? -1 : sortItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
sortItem = content.item(stream.readShort());
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
sortItem = content.item(read.s());
|
||||
|
||||
if(revision == 1){
|
||||
new DirectionalItemBuffer(20, 45f).read(stream);
|
||||
new DirectionalItemBuffer(20, 45f).read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ArmoredConduit extends Conduit{
|
||||
|
||||
// draw the cap when a conduit would normally leak
|
||||
Tile next = tile.front();
|
||||
if(next != null && next.getTeam() == tile.getTeam() && next.block().hasLiquids) return;
|
||||
if(next != null && next.team() == tile.team() && next.block().hasLiquids) return;
|
||||
|
||||
Draw.rect(capRegion, tile.drawx(), tile.drawy(), tile.rotation() * 90);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
@@ -96,7 +96,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
Draw.colorl(0.34f);
|
||||
Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
|
||||
|
||||
Draw.color(tile.entity.liquids.current().color);
|
||||
Draw.color(tile.entity.liquids().current().color);
|
||||
Draw.alpha(entity.smoothLiquid);
|
||||
Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
|
||||
Draw.color();
|
||||
@@ -107,10 +107,10 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
ConduitEntity entity = tile.ent();
|
||||
entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.liquids.currentAmount() / liquidCapacity, 0.05f);
|
||||
entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.liquids().currentAmount() / liquidCapacity, 0.05f);
|
||||
|
||||
if(tile.entity.liquids.total() > 0.001f && tile.entity.timer.get(timerFlow, 1)){
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.rotation()), leakResistance, tile.entity.liquids.current());
|
||||
if(tile.entity.liquids().total() > 0.001f && tile.entity.timer(timerFlow, 1)){
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.rotation()), leakResistance, tile.entity.liquids().current());
|
||||
entity.noSleep();
|
||||
}else{
|
||||
entity.sleep();
|
||||
@@ -125,7 +125,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
tile.entity.noSleep();
|
||||
return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f)
|
||||
return tile.entity.liquids().get(liquid) + amount < liquidCapacity && (tile.entity.liquids().current() == liquid || tile.entity.liquids().get(tile.entity.liquids().current()) < 0.2f)
|
||||
&& ((source.absoluteRelativeTo(tile.x, tile.y) + 2) % 4 != tile.rotation());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ public class LiquidBridge extends ItemBridge{
|
||||
|
||||
Tile other = world.tile(entity.link);
|
||||
if(!linkValid(tile, other)){
|
||||
tryDumpLiquid(tile, entity.liquids.current());
|
||||
tryDumpLiquid(tile, entity.liquids().current());
|
||||
}else{
|
||||
((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos());
|
||||
|
||||
if(entity.cons.valid()){
|
||||
if(entity.consValid()){
|
||||
float alpha = 0.04f;
|
||||
if(hasPower){
|
||||
alpha *= entity.efficiency(); // Exceed boot time unless power is at max.
|
||||
@@ -44,7 +44,7 @@ public class LiquidBridge extends ItemBridge{
|
||||
|
||||
if(entity.uptime >= 0.5f){
|
||||
|
||||
if(tryMoveLiquid(tile, other, false, entity.liquids.current()) > 0.1f){
|
||||
if(tryMoveLiquid(tile, other, false, entity.liquids().current()) > 0.1f){
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
|
||||
}else{
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);
|
||||
|
||||
@@ -28,19 +28,18 @@ public class LiquidExtendingBridge extends ExtendingItemBridge{
|
||||
|
||||
Tile other = world.tile(entity.link);
|
||||
if(!linkValid(tile, other)){
|
||||
tryDumpLiquid(tile, entity.liquids.current());
|
||||
tryDumpLiquid(tile, entity.liquids().current());
|
||||
}else{
|
||||
((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos());
|
||||
|
||||
if(entity.cons.valid()){
|
||||
if(entity.consValid()){
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
|
||||
}else{
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
|
||||
}
|
||||
|
||||
if(entity.uptime >= 0.5f){
|
||||
|
||||
if(tryMoveLiquid(tile, other, false, entity.liquids.current()) > 0.1f){
|
||||
if(tryMoveLiquid(tile, other, false, entity.liquids().current()) > 0.1f){
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
|
||||
}else{
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);
|
||||
|
||||
@@ -13,13 +13,13 @@ public class LiquidRouter extends LiquidBlock{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
|
||||
if(tile.entity.liquids.total() > 0.01f){
|
||||
tryDumpLiquid(tile, tile.entity.liquids.current());
|
||||
if(tile.entity.liquids().total() > 0.01f){
|
||||
tryDumpLiquid(tile, tile.entity.liquids().current());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f);
|
||||
return tile.entity.liquids().get(liquid) + amount < liquidCapacity && (tile.entity.liquids().current() == liquid || tile.entity.liquids().get(tile.entity.liquids().current()) < 0.2f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mindustry.world.blocks.logic;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.Input.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
@@ -9,17 +8,16 @@ import arc.math.geom.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.pooling.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.net.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class MessageBlock extends Block{
|
||||
@@ -35,7 +33,7 @@ public class MessageBlock extends Block{
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.both, forward = true)
|
||||
public static void setMessageBlockText(Player player, Tile tile, String text){
|
||||
public static void setMessageBlockText(Playerc player, Tile tile, String text){
|
||||
if(!Units.canInteract(player, tile)) return;
|
||||
if(net.server() && text.length() > maxTextLength){
|
||||
throw new ValidateException(player, "Player has gone above text limit.");
|
||||
@@ -98,7 +96,7 @@ public class MessageBlock extends Block{
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
MessageBlockEntity entity = tile.ent();
|
||||
|
||||
table.addImageButton(Icon.pencilSmall, () -> {
|
||||
table.addImageButton(Icon.pencil, () -> {
|
||||
if(mobile){
|
||||
Core.input.getTextInput(new TextInput(){{
|
||||
text = entity.message;
|
||||
@@ -151,15 +149,15 @@ public class MessageBlock extends Block{
|
||||
public String[] lines = {""};
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeUTF(message);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.str(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
message = stream.readUTF();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
message = read.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class Battery extends PowerDistributor{
|
||||
public int topRegion = reg("-top");
|
||||
|
||||
public Color emptyLightColor = Color.valueOf("f8c266");
|
||||
public Color fullLightColor = Color.valueOf("fb9567");
|
||||
|
||||
public Battery(String name){
|
||||
super(name);
|
||||
outputsPower = true;
|
||||
consumesPower = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
Draw.color(emptyLightColor, fullLightColor, tile.entity.power().status);
|
||||
Fill.square(tile.drawx(), tile.drawy(), tilesize * size / 2f - 1);
|
||||
Draw.color();
|
||||
|
||||
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import arc.func.Boolf;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.consumers.ConsumePower;
|
||||
|
||||
/** A power consumer that only activates sometimes. */
|
||||
public class ConditionalConsumePower extends ConsumePower{
|
||||
private final Boolf<TileEntity> consume;
|
||||
private final Boolf<Tilec> consume;
|
||||
|
||||
public ConditionalConsumePower(float usage, Boolf<TileEntity> consume){
|
||||
public ConditionalConsumePower(float usage, Boolf<Tilec> consume){
|
||||
super(usage, 0, false);
|
||||
this.consume = consume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float requestedPower(TileEntity entity){
|
||||
public float requestedPower(Tilec entity){
|
||||
return consume.get(entity) ? usage : 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
@@ -53,7 +54,7 @@ public class ImpactReactor extends PowerGenerator{
|
||||
|
||||
bars.add("poweroutput", entity -> new Bar(() ->
|
||||
Core.bundle.format("bar.poweroutput",
|
||||
Strings.fixed(Math.max(entity.block.getPowerProduction(entity.tile) - consumes.getPower().usage, 0) * 60 * entity.timeScale, 1)),
|
||||
Strings.fixed(Math.max(entity.block().getPowerProduction(entity.tile()) - consumes.getPower().usage, 0) * 60 * entity.timeScale(), 1)),
|
||||
() -> Pal.powerBar,
|
||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||
}
|
||||
@@ -71,7 +72,7 @@ public class ImpactReactor extends PowerGenerator{
|
||||
public void update(Tile tile){
|
||||
FusionReactorEntity entity = tile.ent();
|
||||
|
||||
if(entity.cons.valid() && entity.power.status >= 0.99f){
|
||||
if(entity.consValid() && entity.power().status >= 0.99f){
|
||||
boolean prevOut = getPowerProduction(tile) <= consumes.getPower().requestedPower(entity);
|
||||
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||
@@ -83,8 +84,8 @@ public class ImpactReactor extends PowerGenerator{
|
||||
Events.fire(Trigger.impactPower);
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerUse, itemDuration / entity.timeScale)){
|
||||
entity.cons.trigger();
|
||||
if(entity.timer(timerUse, itemDuration / entity.timeScale())){
|
||||
entity.consume();
|
||||
}
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
|
||||
@@ -138,9 +139,9 @@ public class ImpactReactor extends PowerGenerator{
|
||||
Sounds.explosionbig.at(tile);
|
||||
|
||||
Effects.shake(6f, 16f, tile.worldx(), tile.worldy());
|
||||
Effects.effect(Fx.impactShockwave, tile.worldx(), tile.worldy());
|
||||
Fx.impactShockwave.at(tile.worldx(), tile.worldy());
|
||||
for(int i = 0; i < 6; i++){
|
||||
Time.run(Mathf.random(80), () -> Effects.effect(Fx.impactcloud, tile.worldx(), tile.worldy()));
|
||||
Time.run(Mathf.random(80), () -> Fx.impactcloud.at(tile.worldx(), tile.worldy()));
|
||||
}
|
||||
|
||||
Damage.damage(tile.worldx(), tile.worldy(), explosionRadius * tilesize, explosionDamage * 4);
|
||||
@@ -149,14 +150,14 @@ public class ImpactReactor extends PowerGenerator{
|
||||
for(int i = 0; i < 20; i++){
|
||||
Time.run(Mathf.random(80), () -> {
|
||||
Tmp.v1.rnd(Mathf.random(40f));
|
||||
Effects.effect(Fx.explosion, Tmp.v1.x + tile.worldx(), Tmp.v1.y + tile.worldy());
|
||||
Fx.explosion.at(Tmp.v1.x + tile.worldx(), Tmp.v1.y + tile.worldy());
|
||||
});
|
||||
}
|
||||
|
||||
for(int i = 0; i < 70; i++){
|
||||
Time.run(Mathf.random(90), () -> {
|
||||
Tmp.v1.rnd(Mathf.random(120f));
|
||||
Effects.effect(Fx.impactsmoke, Tmp.v1.x + tile.worldx(), Tmp.v1.y + tile.worldy());
|
||||
Fx.impactsmoke.at(Tmp.v1.x + tile.worldx(), Tmp.v1.y + tile.worldy());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -165,15 +166,15 @@ public class ImpactReactor extends PowerGenerator{
|
||||
public float warmup;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(warmup);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(warmup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
warmup = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
warmup = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Effects.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.consumers.*;
|
||||
@@ -99,14 +98,14 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
//Power amount is delta'd by PowerGraph class already.
|
||||
float calculationDelta = entity.delta();
|
||||
|
||||
if(!entity.cons.valid()){
|
||||
if(!entity.consValid()){
|
||||
entity.productionEfficiency = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
Liquid liquid = null;
|
||||
for(Liquid other : content.liquids()){
|
||||
if(hasLiquids && entity.liquids.get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency){
|
||||
if(hasLiquids && entity.liquids().get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency){
|
||||
liquid = other;
|
||||
break;
|
||||
}
|
||||
@@ -115,35 +114,35 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.generateTime >= 0.001f ? 1f : 0f, 0.05f);
|
||||
|
||||
//liquid takes priority over solids
|
||||
if(hasLiquids && liquid != null && entity.liquids.get(liquid) >= 0.001f){
|
||||
if(hasLiquids && liquid != null && entity.liquids().get(liquid) >= 0.001f){
|
||||
float baseLiquidEfficiency = getLiquidEfficiency(liquid);
|
||||
float maximumPossible = maxLiquidGenerate * calculationDelta;
|
||||
float used = Math.min(entity.liquids.get(liquid) * calculationDelta, maximumPossible);
|
||||
float used = Math.min(entity.liquids().get(liquid) * calculationDelta, maximumPossible);
|
||||
|
||||
entity.liquids.remove(liquid, used * entity.power.graph.getUsageFraction());
|
||||
entity.liquids().remove(liquid, used * entity.power().graph.getUsageFraction());
|
||||
entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible;
|
||||
|
||||
if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){
|
||||
Effects.effect(generateEffect, tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f));
|
||||
generateEffect.at(tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f));
|
||||
}
|
||||
}else if(hasItems){
|
||||
// No liquids accepted or none supplied, try using items if accepted
|
||||
if(entity.generateTime <= 0f && entity.items.total() > 0){
|
||||
Effects.effect(generateEffect, tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f));
|
||||
Item item = entity.items.take();
|
||||
if(entity.generateTime <= 0f && entity.items().total() > 0){
|
||||
generateEffect.at(tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f));
|
||||
Item item = entity.items().take();
|
||||
entity.productionEfficiency = getItemEfficiency(item);
|
||||
entity.explosiveness = item.explosiveness;
|
||||
entity.generateTime = 1f;
|
||||
}
|
||||
|
||||
if(entity.generateTime > 0f){
|
||||
entity.generateTime -= Math.min(1f / itemDuration * entity.delta() * entity.power.graph.getUsageFraction(), entity.generateTime);
|
||||
entity.generateTime -= Math.min(1f / itemDuration * entity.delta() * entity.power().graph.getUsageFraction(), entity.generateTime);
|
||||
|
||||
if(randomlyExplode && state.rules.reactorExplosions && Mathf.chance(entity.delta() * 0.06 * Mathf.clamp(entity.explosiveness - 0.5f))){
|
||||
//this block is run last so that in the event of a block destruction, no code relies on the block type
|
||||
Core.app.post(() -> {
|
||||
entity.damage(Mathf.random(11f));
|
||||
Effects.effect(explodeEffect, tile.worldx() + Mathf.range(size * tilesize / 2f), tile.worldy() + Mathf.range(size * tilesize / 2f));
|
||||
explodeEffect.at(tile.worldx() + Mathf.range(size * tilesize / 2f), tile.worldy() + Mathf.range(size * tilesize / 2f));
|
||||
});
|
||||
}
|
||||
}else{
|
||||
@@ -166,8 +165,8 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
Draw.color(entity.liquids.current().color);
|
||||
Draw.alpha(entity.liquids.currentAmount() / liquidCapacity);
|
||||
Draw.color(entity.liquids().current().color);
|
||||
Draw.alpha(entity.liquids().currentAmount() / liquidCapacity);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.type.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
@@ -52,7 +52,7 @@ public class LightBlock extends Block{
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
LightEntity entity = tile.ent();
|
||||
|
||||
table.addImageButton(Icon.pencilSmall, () -> {
|
||||
table.addImageButton(Icon.pencil, () -> {
|
||||
ui.picker.show(Tmp.c1.set(entity.color).a(0.5f), false, res -> {
|
||||
entity.color = res.rgba();
|
||||
lastColor = entity.color;
|
||||
@@ -62,7 +62,7 @@ public class LightBlock extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
tile.<LightEntity>ent().color = value;
|
||||
}
|
||||
|
||||
@@ -81,15 +81,15 @@ public class LightBlock extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(color);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.i(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
color = stream.readInt();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
color = read.i();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
@@ -79,30 +80,30 @@ public class NuclearReactor extends PowerGenerator{
|
||||
ConsumeLiquid cliquid = consumes.get(ConsumeType.liquid);
|
||||
Item item = consumes.<ConsumeItems>get(ConsumeType.item).items[0].item;
|
||||
|
||||
int fuel = entity.items.get(item);
|
||||
int fuel = entity.items().get(item);
|
||||
float fullness = (float)fuel / itemCapacity;
|
||||
entity.productionEfficiency = fullness;
|
||||
|
||||
if(fuel > 0){
|
||||
entity.heat += fullness * heating * Math.min(entity.delta(), 4f);
|
||||
|
||||
if(entity.timer.get(timerFuel, itemDuration / entity.timeScale)){
|
||||
entity.cons.trigger();
|
||||
if(entity.timer(timerFuel, itemDuration / entity.timeScale())){
|
||||
entity.consume();
|
||||
}
|
||||
}
|
||||
|
||||
Liquid liquid = cliquid.liquid;
|
||||
|
||||
if(entity.heat > 0){
|
||||
float maxUsed = Math.min(entity.liquids.get(liquid), entity.heat / coolantPower);
|
||||
float maxUsed = Math.min(entity.liquids().get(liquid), entity.heat / coolantPower);
|
||||
entity.heat -= maxUsed * coolantPower;
|
||||
entity.liquids.remove(liquid, maxUsed);
|
||||
entity.liquids().remove(liquid, maxUsed);
|
||||
}
|
||||
|
||||
if(entity.heat > smokeThreshold){
|
||||
float smoke = 1.0f + (entity.heat - smokeThreshold) / (1f - smokeThreshold); //ranges from 1.0 to 2.0
|
||||
if(Mathf.chance(smoke / 20.0 * entity.delta())){
|
||||
Effects.effect(Fx.reactorsmoke, tile.worldx() + Mathf.range(size * tilesize / 2f),
|
||||
Fx.reactorsmoke.at(tile.worldx() + Mathf.range(size * tilesize / 2f),
|
||||
tile.worldy() + Mathf.random(size * tilesize / 2f));
|
||||
}
|
||||
}
|
||||
@@ -123,14 +124,14 @@ public class NuclearReactor extends PowerGenerator{
|
||||
|
||||
NuclearReactorEntity entity = tile.ent();
|
||||
|
||||
int fuel = entity.items.get(consumes.<ConsumeItems>get(ConsumeType.item).items[0].item);
|
||||
int fuel = entity.items().get(consumes.<ConsumeItems>get(ConsumeType.item).items[0].item);
|
||||
|
||||
if((fuel < 5 && entity.heat < 0.5f) || !state.rules.reactorExplosions) return;
|
||||
|
||||
Effects.shake(6f, 16f, tile.worldx(), tile.worldy());
|
||||
Effects.effect(Fx.nuclearShockwave, tile.worldx(), tile.worldy());
|
||||
Fx.nuclearShockwave.at(tile.worldx(), tile.worldy());
|
||||
for(int i = 0; i < 6; i++){
|
||||
Time.run(Mathf.random(40), () -> Effects.effect(Fx.nuclearcloud, tile.worldx(), tile.worldy()));
|
||||
Time.run(Mathf.random(40), () -> Fx.nuclearcloud.at(tile.worldx(), tile.worldy()));
|
||||
}
|
||||
|
||||
Damage.damage(tile.worldx(), tile.worldy(), explosionRadius * tilesize, explosionDamage * 4);
|
||||
@@ -138,14 +139,14 @@ public class NuclearReactor extends PowerGenerator{
|
||||
for(int i = 0; i < 20; i++){
|
||||
Time.run(Mathf.random(50), () -> {
|
||||
tr.rnd(Mathf.random(40f));
|
||||
Effects.effect(Fx.explosion, tr.x + tile.worldx(), tr.y + tile.worldy());
|
||||
Fx.explosion.at(tr.x + tile.worldx(), tr.y + tile.worldy());
|
||||
});
|
||||
}
|
||||
|
||||
for(int i = 0; i < 70; i++){
|
||||
Time.run(Mathf.random(80), () -> {
|
||||
tr.rnd(Mathf.random(120f));
|
||||
Effects.effect(Fx.nuclearsmoke, tr.x + tile.worldx(), tr.y + tile.worldy());
|
||||
Fx.nuclearsmoke.at(tr.x + tile.worldx(), tr.y + tile.worldy());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -166,8 +167,8 @@ public class NuclearReactor extends PowerGenerator{
|
||||
Draw.color(coolColor, hotColor, entity.heat);
|
||||
Fill.rect(tile.drawx(), tile.drawy(), size * tilesize, size * tilesize);
|
||||
|
||||
Draw.color(entity.liquids.current().color);
|
||||
Draw.alpha(entity.liquids.currentAmount() / liquidCapacity);
|
||||
Draw.color(entity.liquids().current().color);
|
||||
Draw.alpha(entity.liquids().currentAmount() / liquidCapacity);
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy());
|
||||
|
||||
if(entity.heat > flashThreshold){
|
||||
@@ -186,15 +187,15 @@ public class NuclearReactor extends PowerGenerator{
|
||||
public float flash;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(heat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(heat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
heat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
heat = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.world.blocks.power;
|
||||
|
||||
import arc.Core;
|
||||
import arc.math.Mathf;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.ui.Bar;
|
||||
import arc.util.Eachable;
|
||||
import mindustry.ui.Cicon;
|
||||
@@ -10,7 +11,6 @@ import mindustry.world.Block;
|
||||
import arc.graphics.g2d.Draw;
|
||||
import mindustry.graphics.Pal;
|
||||
import arc.graphics.g2d.TextureRegion;
|
||||
import mindustry.entities.traits.BuilderTrait;
|
||||
|
||||
public class PowerDiode extends Block{
|
||||
public TextureRegion arrow;
|
||||
@@ -27,10 +27,10 @@ public class PowerDiode extends Block{
|
||||
public void update(Tile tile){
|
||||
super.update(tile);
|
||||
|
||||
if(tile.front() == null || tile.back() == null || !tile.back().block().hasPower || !tile.front().block().hasPower || tile.back().getTeam() != tile.front().getTeam()) return;
|
||||
if(tile.front() == null || tile.back() == null || !tile.back().block().hasPower || !tile.front().block().hasPower || tile.back().team() != tile.front().team()) return;
|
||||
|
||||
PowerGraph backGraph = tile.back().entity.power.graph;
|
||||
PowerGraph frontGraph = tile.front().entity.power.graph;
|
||||
PowerGraph backGraph = tile.back().entity.power().graph;
|
||||
PowerGraph frontGraph = tile.front().entity.power().graph;
|
||||
if(backGraph == frontGraph) return;
|
||||
|
||||
// 0f - 1f of battery capacity in use
|
||||
@@ -51,15 +51,15 @@ public class PowerDiode extends Block{
|
||||
|
||||
// battery % of the graph on either side, defaults to zero
|
||||
public float bar(Tile tile){
|
||||
return (tile != null && tile.block().hasPower) ? tile.entity.power.graph.getBatteryStored() / tile.entity.power.graph.getTotalBatteryCapacity() : 0f;
|
||||
return (tile != null && tile.block().hasPower) ? tile.entity.power().graph.getBatteryStored() / tile.entity.power().graph.getTotalBatteryCapacity() : 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
bars.add("back", entity -> new Bar("bar.input", Pal.powerBar, () -> bar(entity.tile.back())));
|
||||
bars.add("front", entity -> new Bar("bar.output", Pal.powerBar, () -> bar(entity.tile.front())));
|
||||
bars.add("back", entity -> new Bar("bar.input", Pal.powerBar, () -> bar(entity.tile().back())));
|
||||
bars.add("front", entity -> new Bar("bar.output", Pal.powerBar, () -> bar(entity.tile().front())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +75,7 @@ public class PowerDiode extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestRegion(BuilderTrait.BuildRequest req, Eachable<BuilderTrait.BuildRequest> list) {
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list) {
|
||||
TextureRegion reg = icon(Cicon.full);
|
||||
Draw.rect(icon(Cicon.full), req.drawx(), req.drawy(),
|
||||
reg.getWidth() * req.animScale * Draw.scl,
|
||||
|
||||
@@ -3,7 +3,8 @@ package mindustry.world.blocks.power;
|
||||
import arc.Core;
|
||||
import arc.struct.EnumSet;
|
||||
import arc.util.Strings;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.ui.Bar;
|
||||
import mindustry.world.Tile;
|
||||
@@ -37,7 +38,7 @@ public class PowerGenerator extends PowerDistributor{
|
||||
if(hasPower && outputsPower && !consumes.hasPower()){
|
||||
bars.add("power", entity -> new Bar(() ->
|
||||
Core.bundle.format("bar.poweroutput",
|
||||
Strings.fixed(entity.block.getPowerProduction(entity.tile) * 60 * entity.timeScale, 1)),
|
||||
Strings.fixed(entity.block().getPowerProduction(entity.tile()) * 60 * entity.timeScale(), 1)),
|
||||
() -> Pal.powerBar,
|
||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||
}
|
||||
@@ -59,15 +60,15 @@ public class PowerGenerator extends PowerDistributor{
|
||||
public float productionEfficiency = 0.0f;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(productionEfficiency);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(productionEfficiency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
productionEfficiency = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
productionEfficiency = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class PowerGraph{
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
totalAccumulator += battery.entity.power.status * consumes.getPower().capacity;
|
||||
totalAccumulator += battery.entity.power().status * consumes.getPower().capacity;
|
||||
}
|
||||
}
|
||||
return totalAccumulator;
|
||||
@@ -99,7 +99,7 @@ public class PowerGraph{
|
||||
for(Tile battery : batteries){
|
||||
if(battery.block().consumes.hasPower()){
|
||||
ConsumePower power = battery.block().consumes.getPower();
|
||||
totalCapacity += (1f - battery.entity.power.status) * power.capacity;
|
||||
totalCapacity += (1f - battery.entity.power().status) * power.capacity;
|
||||
}
|
||||
}
|
||||
return totalCapacity;
|
||||
@@ -124,7 +124,7 @@ public class PowerGraph{
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
battery.entity.power.status *= (1f-consumedPowerPercentage);
|
||||
battery.entity.power().status *= (1f-consumedPowerPercentage);
|
||||
}
|
||||
}
|
||||
return used;
|
||||
@@ -141,7 +141,7 @@ public class PowerGraph{
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.capacity > 0f){
|
||||
battery.entity.power.status += (1f-battery.entity.power.status) * chargedPercent;
|
||||
battery.entity.power().status += (1f-battery.entity.power().status) * chargedPercent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,17 +159,17 @@ public class PowerGraph{
|
||||
if(!Mathf.zero(consumePower.capacity)){
|
||||
// Add an equal percentage of power to all buffers, based on the global power coverage in this graph
|
||||
float maximumRate = consumePower.requestedPower(consumer.entity) * coverage * consumer.entity.delta();
|
||||
consumer.entity.power.status = Mathf.clamp(consumer.entity.power.status + maximumRate / consumePower.capacity);
|
||||
consumer.entity.power().status = Mathf.clamp(consumer.entity.power().status + maximumRate / consumePower.capacity);
|
||||
}
|
||||
}else{
|
||||
//valid consumers get power as usual
|
||||
if(otherConsumersAreValid(consumer, consumePower)){
|
||||
consumer.entity.power.status = coverage;
|
||||
consumer.entity.power().status = coverage;
|
||||
}else{ //invalid consumers get an estimate, if they were to activate
|
||||
consumer.entity.power.status = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta()));
|
||||
consumer.entity.power().status = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta()));
|
||||
//just in case
|
||||
if(Float.isNaN(consumer.entity.power.status)){
|
||||
consumer.entity.power.status = 0f;
|
||||
if(Float.isNaN(consumer.entity.power().status)){
|
||||
consumer.entity.power().status = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ public class PowerGraph{
|
||||
}else if(!consumers.isEmpty() && consumers.first().isEnemyCheat()){
|
||||
//when cheating, just set status to 1
|
||||
for(Tile tile : consumers){
|
||||
tile.entity.power.status = 1f;
|
||||
tile.entity.power().status = 1f;
|
||||
}
|
||||
|
||||
lastPowerNeeded = lastPowerProduced = lastUsageFraction = 1f;
|
||||
@@ -230,8 +230,8 @@ public class PowerGraph{
|
||||
}
|
||||
|
||||
public void add(Tile tile){
|
||||
if(tile.entity == null || tile.entity.power == null) return;
|
||||
tile.entity.power.graph = this;
|
||||
if(tile.entity == null || tile.entity.power() == null) return;
|
||||
tile.entity.power().graph = this;
|
||||
all.add(tile);
|
||||
|
||||
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.getPower().buffered){
|
||||
@@ -277,7 +277,7 @@ public class PowerGraph{
|
||||
//go through all the connections of this tile
|
||||
for(Tile other : tile.block().getPowerConnections(tile, outArray1)){
|
||||
//a graph has already been assigned to this tile from a previous call, skip it
|
||||
if(other.entity.power.graph != this) continue;
|
||||
if(other.entity.power().graph != this) continue;
|
||||
|
||||
//create graph for this branch
|
||||
PowerGraph graph = new PowerGraph();
|
||||
@@ -296,7 +296,7 @@ public class PowerGraph{
|
||||
for(Tile next : child.block().getPowerConnections(child, outArray2)){
|
||||
//make sure it hasn't looped back, and that the new graph being assigned hasn't already been assigned
|
||||
//also skip closed tiles
|
||||
if(next != tile && next.entity.power.graph != graph && !closedSet.contains(next.pos())){
|
||||
if(next != tile && next.entity.power().graph != graph && !closedSet.contains(next.pos())){
|
||||
queue.addLast(next);
|
||||
closedSet.add(next.pos());
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
@@ -38,41 +38,41 @@ public class PowerNode extends PowerBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
TileEntity entity = tile.entity;
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
Tilec entity = tile.entity;
|
||||
Tile other = world.tile(value);
|
||||
boolean contains = entity.power.links.contains(value), valid = other != null && other.entity != null && other.entity.power != null;
|
||||
boolean contains = entity.power().links.contains(value), valid = other != null && other.entity != null && other.entity.power() != null;
|
||||
|
||||
if(contains){
|
||||
//unlink
|
||||
entity.power.links.removeValue(value);
|
||||
if(valid) other.entity.power.links.removeValue(tile.pos());
|
||||
entity.power().links.removeValue(value);
|
||||
if(valid) other.entity.power().links.removeValue(tile.pos());
|
||||
|
||||
PowerGraph newgraph = new PowerGraph();
|
||||
|
||||
//reflow from this point, covering all tiles on this side
|
||||
newgraph.reflow(tile);
|
||||
|
||||
if(valid && other.entity.power.graph != newgraph){
|
||||
if(valid && other.entity.power().graph != newgraph){
|
||||
//create new graph for other end
|
||||
PowerGraph og = new PowerGraph();
|
||||
//reflow from other end
|
||||
og.reflow(other);
|
||||
}
|
||||
}else if(linkValid(tile, other) && valid && entity.power.links.size < maxNodes){
|
||||
}else if(linkValid(tile, other) && valid && entity.power().links.size < maxNodes){
|
||||
|
||||
if(!entity.power.links.contains(other.pos())){
|
||||
entity.power.links.add(other.pos());
|
||||
if(!entity.power().links.contains(other.pos())){
|
||||
entity.power().links.add(other.pos());
|
||||
}
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID()){
|
||||
|
||||
if(!other.entity.power.links.contains(tile.pos())){
|
||||
other.entity.power.links.add(tile.pos());
|
||||
if(!other.entity.power().links.contains(tile.pos())){
|
||||
other.entity.power().links.add(tile.pos());
|
||||
}
|
||||
}
|
||||
|
||||
entity.power.graph.add(other.entity.power.graph);
|
||||
entity.power().graph.add(other.entity.power().graph);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,15 +89,15 @@ public class PowerNode extends PowerBlock{
|
||||
super.setBars();
|
||||
bars.add("power", entity -> new Bar(() ->
|
||||
Core.bundle.format("bar.powerbalance",
|
||||
((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.power.graph.getPowerBalance() * 60, 1))),
|
||||
((entity.power().graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.power().graph.getPowerBalance() * 60, 1))),
|
||||
() -> Pal.powerBar,
|
||||
() -> Mathf.clamp(entity.power.graph.getLastPowerProduced() / entity.power.graph.getLastPowerNeeded())));
|
||||
() -> Mathf.clamp(entity.power().graph.getLastPowerProduced() / entity.power().graph.getLastPowerNeeded())));
|
||||
|
||||
bars.add("batteries", entity -> new Bar(() ->
|
||||
Core.bundle.format("bar.powerstored",
|
||||
(ui.formatAmount((int)entity.power.graph.getBatteryStored())), ui.formatAmount((int)entity.power.graph.getTotalBatteryCapacity())),
|
||||
(ui.formatAmount((int)entity.power().graph.getBatteryStored())), ui.formatAmount((int)entity.power().graph.getTotalBatteryCapacity())),
|
||||
() -> Pal.powerBar,
|
||||
() -> Mathf.clamp(entity.power.graph.getBatteryStored() / entity.power.graph.getTotalBatteryCapacity())));
|
||||
() -> Mathf.clamp(entity.power().graph.getBatteryStored() / entity.power().graph.getTotalBatteryCapacity())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,7 +105,7 @@ public class PowerNode extends PowerBlock{
|
||||
if(net.client()) return;
|
||||
|
||||
Boolf<Tile> valid = other -> other != null && other != tile && ((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) && linkValid(tile, other)
|
||||
&& !other.entity.proximity().contains(tile) && other.entity.power.graph != tile.entity.power.graph;
|
||||
&& !other.entity.proximity().contains(tile) && other.entity.power().graph != tile.entity.power().graph;
|
||||
|
||||
tempTiles.clear();
|
||||
Geometry.circle(tile.x, tile.y, (int)(laserRange + 2), (x, y) -> {
|
||||
@@ -123,7 +123,7 @@ public class PowerNode extends PowerBlock{
|
||||
return Float.compare(a.dst2(tile), b.dst2(tile));
|
||||
});
|
||||
tempTiles.each(valid, other -> {
|
||||
if(!tile.entity.power.links.contains(other.pos())){
|
||||
if(!tile.entity.power().links.contains(other.pos())){
|
||||
tile.configureAny(other.pos());
|
||||
}
|
||||
});
|
||||
@@ -132,10 +132,10 @@ public class PowerNode extends PowerBlock{
|
||||
}
|
||||
|
||||
private void getPotentialLinks(Tile tile, Cons<Tile> others){
|
||||
Boolf<Tile> valid = other -> other != null && other != tile && other.entity != null && other.entity.power != null &&
|
||||
Boolf<Tile> valid = other -> other != null && other != tile && other.entity != null && other.entity.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, laserRange * tilesize) && other.getTeam() == player.getTeam()
|
||||
&& !other.entity.proximity().contains(tile) && !graphs.contains(other.entity.power.graph);
|
||||
overlaps(tile.x * tilesize + offset(), tile.y * tilesize + offset(), other, laserRange * tilesize) && other.team() == player.team()
|
||||
&& !other.entity.proximity().contains(tile) && !graphs.contains(other.entity.power().graph);
|
||||
|
||||
tempTiles.clear();
|
||||
graphs.clear();
|
||||
@@ -152,7 +152,7 @@ public class PowerNode extends PowerBlock{
|
||||
return Float.compare(a.dst2(tile), b.dst2(tile));
|
||||
});
|
||||
tempTiles.each(valid, t -> {
|
||||
graphs.add(t.entity.power.graph);
|
||||
graphs.add(t.entity.power().graph);
|
||||
others.get(t);
|
||||
});
|
||||
}
|
||||
@@ -167,12 +167,12 @@ public class PowerNode extends PowerBlock{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
tile.entity.power.graph.update();
|
||||
tile.entity.power().graph.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onConfigureTileTapped(Tile tile, Tile other){
|
||||
TileEntity entity = tile.ent();
|
||||
Tilec entity = tile.ent();
|
||||
other = other.link();
|
||||
|
||||
if(linkValid(tile, other)){
|
||||
@@ -181,13 +181,16 @@ public class PowerNode extends PowerBlock{
|
||||
}
|
||||
|
||||
if(tile == other){
|
||||
if(other.entity.power.links.size == 0){
|
||||
if(other.entity.power().links.size == 0){
|
||||
int[] total = {0};
|
||||
getPotentialLinks(tile, link -> {
|
||||
if(!insulated(tile, link)) tile.configure(link.pos());
|
||||
if(!insulated(tile, link) && total[0]++ < maxNodes){
|
||||
tile.configure(link.pos());
|
||||
}
|
||||
});
|
||||
}else{
|
||||
while(entity.power.links.size > 0){
|
||||
tile.configure(entity.power.links.get(0));
|
||||
while(entity.power().links.size > 0){
|
||||
tile.configure(entity.power().links.get(0));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -262,10 +265,10 @@ public class PowerNode extends PowerBlock{
|
||||
public void drawLayer(Tile tile){
|
||||
if(Core.settings.getInt("lasersopacity") == 0) return;
|
||||
|
||||
TileEntity entity = tile.ent();
|
||||
Tilec entity = tile.ent();
|
||||
|
||||
for(int i = 0; i < entity.power.links.size; i++){
|
||||
Tile link = world.tile(entity.power.links.get(i));
|
||||
for(int i = 0; i < entity.power().links.size; i++){
|
||||
Tile link = world.tile(entity.power().links.get(i));
|
||||
|
||||
if(!linkValid(tile, link)) continue;
|
||||
|
||||
@@ -278,7 +281,7 @@ public class PowerNode extends PowerBlock{
|
||||
}
|
||||
|
||||
protected boolean linked(Tile tile, Tile other){
|
||||
return tile.entity.power.links.contains(other.pos());
|
||||
return tile.entity.power().links.contains(other.pos());
|
||||
}
|
||||
|
||||
public boolean linkValid(Tile tile, Tile link){
|
||||
@@ -286,11 +289,11 @@ public class PowerNode extends PowerBlock{
|
||||
}
|
||||
|
||||
public boolean linkValid(Tile tile, Tile link, boolean checkMaxNodes){
|
||||
if(tile == link || link == null || link.entity == null || tile.entity == null || !link.block().hasPower || tile.getTeam() != link.getTeam()) return false;
|
||||
if(tile == link || link == null || link.entity == null || tile.entity == null || !link.block().hasPower || tile.team() != link.team()) return false;
|
||||
|
||||
if(overlaps(tile, link, laserRange * tilesize) || (link.block() instanceof PowerNode && overlaps(link, tile, link.<PowerNode>cblock().laserRange * tilesize))){
|
||||
if(checkMaxNodes && link.block() instanceof PowerNode){
|
||||
return link.entity.power.links.size < link.<PowerNode>cblock().maxNodes || link.entity.power.links.contains(tile.pos());
|
||||
return link.entity.power().links.size < link.<PowerNode>cblock().maxNodes || link.entity.power().links.contains(tile.pos());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -328,7 +331,7 @@ public class PowerNode extends PowerBlock{
|
||||
x2 += t2.x;
|
||||
y2 += t2.y;
|
||||
|
||||
float fract = 1f - tile.entity.power.graph.getSatisfaction();
|
||||
float fract = 1f - tile.entity.power().graph.getSatisfaction();
|
||||
|
||||
Draw.color(Color.white, Pal.powerLight, fract * 0.86f + Mathf.absin(3f, 0.1f));
|
||||
Draw.alpha(opacity);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SolarGenerator extends PowerGenerator{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
tile.<GeneratorEntity>ent().productionEfficiency = state.rules.lighting ? 1f - state.rules.ambientLight.a : 1f;
|
||||
tile.<GeneratorEntity>ent().productionEfficiency = state.rules.solarPowerMultiplier < 0 ? (state.rules.lighting ? 1f - state.rules.ambientLight.a : 1f) : state.rules.solarPowerMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,23 +13,31 @@ import static mindustry.Vars.renderer;
|
||||
|
||||
public class ThermalGenerator extends PowerGenerator{
|
||||
public Effect generateEffect = Fx.none;
|
||||
public Attribute attribute = Attribute.heat;
|
||||
|
||||
public ThermalGenerator(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.tiles, attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
GeneratorEntity entity = tile.ent();
|
||||
|
||||
if(entity.productionEfficiency > 0.1f && Mathf.chance(0.05 * entity.delta())){
|
||||
Effects.effect(generateEffect, tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f));
|
||||
generateEffect.at(tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", sumAttribute(Attribute.heat, x, y) * 100, 1), x, y, valid);
|
||||
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", sumAttribute(attribute, x, y) * 100, 1), x, y, valid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,7 +51,7 @@ public class ThermalGenerator extends PowerGenerator{
|
||||
super.onProximityAdded(tile);
|
||||
|
||||
GeneratorEntity entity = tile.ent();
|
||||
entity.productionEfficiency = sumAttribute(Attribute.heat, tile.x, tile.y);
|
||||
entity.productionEfficiency = sumAttribute(attribute, tile.x, tile.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,6 +64,6 @@ public class ThermalGenerator extends PowerGenerator{
|
||||
@Override
|
||||
public boolean canPlaceOn(Tile tile){
|
||||
//make sure there's heat at this location
|
||||
return tile.getLinkedTilesAs(this, tempTiles).sumf(other -> other.floor().attributes.get(Attribute.heat)) > 0.01f;
|
||||
return tile.getLinkedTilesAs(this, tempTiles).sumf(other -> other.floor().attributes.get(attribute)) > 0.01f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package mindustry.world.blocks.production;
|
||||
|
||||
import arc.Core;
|
||||
import arc.graphics.Color;
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.Rand;
|
||||
import arc.util.Time;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.ui.Bar;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.meta.Attribute;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Cultivator extends GenericCrafter{
|
||||
super.update(tile);
|
||||
|
||||
CultivatorEntity entity = tile.ent();
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, entity.cons.valid() ? 1f : 0f, 0.015f);
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, entity.consValid() ? 1f : 0f, 0.015f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +57,13 @@ public class Cultivator extends GenericCrafter{
|
||||
() -> ((CultivatorEntity)entity).warmup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.affinities, attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", (1 + sumAttribute(attribute, x, y)) * 100, 1), x, y, valid);
|
||||
@@ -104,7 +111,7 @@ public class Cultivator extends GenericCrafter{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getProgressIncrease(TileEntity entity, float baseTime){
|
||||
protected float getProgressIncrease(Tilec entity, float baseTime){
|
||||
CultivatorEntity c = (CultivatorEntity)entity;
|
||||
return super.getProgressIncrease(entity, baseTime) * (1f + c.boost);
|
||||
}
|
||||
@@ -114,15 +121,15 @@ public class Cultivator extends GenericCrafter{
|
||||
public float boost;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(warmup);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(warmup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
warmup = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
warmup = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Effects.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
@@ -77,7 +75,7 @@ public class Drill extends Block{
|
||||
bars.add("drillspeed", e -> {
|
||||
DrillEntity entity = (DrillEntity)e;
|
||||
|
||||
return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.timeScale, 2)), () -> Pal.ammo, () -> entity.warmup);
|
||||
return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.timeScale(), 2)), () -> Pal.ammo, () -> entity.warmup);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,7 +127,7 @@ public class Drill extends Block{
|
||||
|
||||
@Override
|
||||
public boolean shouldConsume(Tile tile){
|
||||
return tile.entity.items.total() < itemCapacity;
|
||||
return tile.entity.items().total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,28 +234,34 @@ public class Drill extends Block{
|
||||
returnCount = oreCount.get(itemArray.peek(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProximityUpdate(Tile tile){
|
||||
DrillEntity entity = tile.ent();
|
||||
|
||||
countOre(tile);
|
||||
entity.dominantItem = returnItem;
|
||||
entity.dominantItems = returnCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
DrillEntity entity = tile.ent();
|
||||
|
||||
if(entity.dominantItem == null){
|
||||
countOre(tile);
|
||||
if(returnItem == null) return;
|
||||
entity.dominantItem = returnItem;
|
||||
entity.dominantItems = returnCount;
|
||||
return;
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDump, dumpTime)){
|
||||
if(entity.timer(timerDump, dumpTime)){
|
||||
tryDump(tile, entity.dominantItem);
|
||||
}
|
||||
|
||||
entity.drillTime += entity.warmup * entity.delta();
|
||||
|
||||
if(entity.items.total() < itemCapacity && entity.dominantItems > 0 && entity.cons.valid()){
|
||||
if(entity.items().total() < itemCapacity && entity.dominantItems > 0 && entity.consValid()){
|
||||
|
||||
float speed = 1f;
|
||||
|
||||
if(entity.cons.optionalValid()){
|
||||
if(entity.cons().optionalValid()){
|
||||
speed = liquidBoostIntensity;
|
||||
}
|
||||
|
||||
@@ -269,14 +273,14 @@ public class Drill extends Block{
|
||||
* entity.dominantItems * speed * entity.warmup;
|
||||
|
||||
if(Mathf.chance(Time.delta() * updateEffectChance * entity.warmup))
|
||||
Effects.effect(updateEffect, entity.x + Mathf.range(size * 2f), entity.y + Mathf.range(size * 2f));
|
||||
updateEffect.at(entity.getX() + Mathf.range(size * 2f), entity.getY() + Mathf.range(size * 2f));
|
||||
}else{
|
||||
entity.lastDrillSpeed = 0f;
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, warmupSpeed);
|
||||
return;
|
||||
}
|
||||
|
||||
if(entity.dominantItems > 0 && entity.progress >= drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness && tile.entity.items.total() < itemCapacity){
|
||||
if(entity.dominantItems > 0 && entity.progress >= drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness && tile.entity.items().total() < itemCapacity){
|
||||
|
||||
offloadNear(tile, entity.dominantItem);
|
||||
|
||||
@@ -285,8 +289,7 @@ public class Drill extends Block{
|
||||
entity.index++;
|
||||
entity.progress = 0f;
|
||||
|
||||
Effects.effect(drillEffect, entity.dominantItem.color,
|
||||
entity.x + Mathf.range(size), entity.y + Mathf.range(size));
|
||||
drillEffect.at(entity.getX() + Mathf.range(size), entity.getY() + Mathf.range(size), entity.dominantItem.color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Fracker extends SolidPump{
|
||||
|
||||
@Override
|
||||
public boolean shouldConsume(Tile tile){
|
||||
return tile.entity.liquids.get(result) < liquidCapacity - 0.01f;
|
||||
return tile.entity.liquids().get(result) < liquidCapacity - 0.01f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,7 +55,7 @@ public class Fracker extends SolidPump{
|
||||
super.drawCracks(tile);
|
||||
|
||||
Draw.color(result.color);
|
||||
Draw.alpha(tile.entity.liquids.get(result) / liquidCapacity);
|
||||
Draw.alpha(tile.entity.liquids().get(result) / liquidCapacity);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
|
||||
Draw.color();
|
||||
|
||||
@@ -72,9 +72,9 @@ public class Fracker extends SolidPump{
|
||||
public void update(Tile tile){
|
||||
FrackerEntity entity = tile.ent();
|
||||
|
||||
if(entity.cons.valid()){
|
||||
if(entity.consValid()){
|
||||
if(entity.accumulator >= itemUseTime){
|
||||
entity.cons.trigger();
|
||||
entity.consume();
|
||||
entity.accumulator -= itemUseTime;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class Fracker extends SolidPump{
|
||||
|
||||
@Override
|
||||
public float typeLiquid(Tile tile){
|
||||
return tile.entity.liquids.get(result);
|
||||
return tile.entity.liquids().get(result);
|
||||
}
|
||||
|
||||
public static class FrackerEntity extends SolidPumpEntity{
|
||||
|
||||
@@ -4,10 +4,9 @@ import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Effects.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
@@ -61,7 +60,7 @@ public class GenericCrafter extends Block{
|
||||
|
||||
@Override
|
||||
public boolean shouldIdleSound(Tile tile){
|
||||
return tile.entity.cons.valid();
|
||||
return tile.entity.cons().valid();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,21 +87,21 @@ public class GenericCrafter extends Block{
|
||||
public void update(Tile tile){
|
||||
GenericCrafterEntity entity = tile.ent();
|
||||
|
||||
if(entity.cons.valid()){
|
||||
if(entity.consValid()){
|
||||
|
||||
entity.progress += getProgressIncrease(entity, craftTime);
|
||||
entity.totalProgress += entity.delta();
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
|
||||
if(Mathf.chance(Time.delta() * updateEffectChance)){
|
||||
Effects.effect(updateEffect, entity.x + Mathf.range(size * 4f), entity.y + Mathf.range(size * 4));
|
||||
updateEffect.at(entity.getX() + Mathf.range(size * 4f), entity.getY() + Mathf.range(size * 4));
|
||||
}
|
||||
}else{
|
||||
entity.warmup = Mathf.lerp(entity.warmup, 0f, 0.02f);
|
||||
}
|
||||
|
||||
if(entity.progress >= 1f){
|
||||
entity.cons.trigger();
|
||||
entity.consume();
|
||||
|
||||
if(outputItem != null){
|
||||
useContent(tile, outputItem.item);
|
||||
@@ -116,11 +115,11 @@ public class GenericCrafter extends Block{
|
||||
handleLiquid(tile, tile, outputLiquid.liquid, outputLiquid.amount);
|
||||
}
|
||||
|
||||
Effects.effect(craftEffect, tile.drawx(), tile.drawy());
|
||||
craftEffect.at(tile.drawx(), tile.drawy());
|
||||
entity.progress = 0f;
|
||||
}
|
||||
|
||||
if(outputItem != null && tile.entity.timer.get(timerDump, dumpTime)){
|
||||
if(outputItem != null && tile.entity.timer(timerDump, dumpTime)){
|
||||
tryDump(tile, outputItem.item);
|
||||
}
|
||||
|
||||
@@ -134,14 +133,12 @@ public class GenericCrafter extends Block{
|
||||
return outputItem != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldConsume(Tile tile){
|
||||
if(outputItem != null && tile.entity.items.get(outputItem.item) >= itemCapacity){
|
||||
if(outputItem != null && tile.entity.items().get(outputItem.item) >= itemCapacity){
|
||||
return false;
|
||||
}
|
||||
return outputLiquid == null || !(tile.entity.liquids.get(outputLiquid.liquid) >= liquidCapacity);
|
||||
return outputLiquid == null || !(tile.entity.liquids().get(outputLiquid.liquid) >= liquidCapacity - 0.001f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,17 +152,17 @@ public class GenericCrafter extends Block{
|
||||
public float warmup;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(progress);
|
||||
stream.writeFloat(warmup);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(progress);
|
||||
write.f(warmup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
progress = stream.readFloat();
|
||||
warmup = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
progress = read.f();
|
||||
warmup = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,8 @@ import arc.graphics.g2d.Fill;
|
||||
import arc.math.Mathf;
|
||||
import arc.util.Time;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.entities.Effects;
|
||||
import mindustry.entities.Effects.Effect;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.type.Liquid;
|
||||
import mindustry.world.Block;
|
||||
@@ -31,7 +30,7 @@ public class Incinerator extends Block{
|
||||
public void update(Tile tile){
|
||||
IncineratorEntity entity = tile.ent();
|
||||
|
||||
if(entity.cons.valid()){
|
||||
if(entity.consValid()){
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, 1f, 0.04f);
|
||||
}else{
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.02f);
|
||||
@@ -62,7 +61,7 @@ public class Incinerator extends Block{
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
if(Mathf.chance(0.3)){
|
||||
Effects.effect(effect, tile.drawx(), tile.drawy());
|
||||
effect.at(tile.drawx(), tile.drawy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ public class Incinerator extends Block{
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
if(Mathf.chance(0.02)){
|
||||
Effects.effect(effect, tile.drawx(), tile.drawy());
|
||||
effect.at(tile.drawx(), tile.drawy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class LiquidConverter extends GenericCrafter{
|
||||
@Override
|
||||
public void drawLight(Tile tile){
|
||||
if(hasLiquids && drawLiquidLight && outputLiquid.liquid.lightColor.a > 0.001f){
|
||||
drawLiquidLight(tile, outputLiquid.liquid, tile.entity.liquids.get(outputLiquid.liquid));
|
||||
drawLiquidLight(tile, outputLiquid.liquid, tile.entity.liquids().get(outputLiquid.liquid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,14 @@ public class LiquidConverter extends GenericCrafter{
|
||||
GenericCrafterEntity entity = tile.ent();
|
||||
ConsumeLiquidBase cl = consumes.get(ConsumeType.liquid);
|
||||
|
||||
if(tile.entity.cons.valid()){
|
||||
float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.liquids.get(outputLiquid.liquid)) * entity.efficiency();
|
||||
if(tile.entity.cons().valid()){
|
||||
float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.liquids().get(outputLiquid.liquid)) * entity.efficiency();
|
||||
|
||||
useContent(tile, outputLiquid.liquid);
|
||||
entity.progress += use / cl.amount / craftTime;
|
||||
entity.liquids.add(outputLiquid.liquid, use);
|
||||
entity.liquids().add(outputLiquid.liquid, use);
|
||||
if(entity.progress >= 1f){
|
||||
entity.cons.trigger();
|
||||
entity.consume();
|
||||
entity.progress = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public class Pump extends LiquidBlock{
|
||||
public void draw(Tile tile){
|
||||
Draw.rect(name, tile.drawx(), tile.drawy());
|
||||
|
||||
Draw.color(tile.entity.liquids.current().color);
|
||||
Draw.alpha(tile.entity.liquids.total() / liquidCapacity);
|
||||
Draw.color(tile.entity.liquids().current().color);
|
||||
Draw.alpha(tile.entity.liquids().total() / liquidCapacity);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
|
||||
Draw.color();
|
||||
}
|
||||
@@ -118,16 +118,16 @@ public class Pump extends LiquidBlock{
|
||||
liquidDrop = tile.floor().liquidDrop;
|
||||
}
|
||||
|
||||
if(tile.entity.cons.valid() && liquidDrop != null){
|
||||
float maxPump = Math.min(liquidCapacity - tile.entity.liquids.total(), tiles * pumpAmount * tile.entity.delta() / size / size) * tile.entity.efficiency();
|
||||
tile.entity.liquids.add(liquidDrop, maxPump);
|
||||
if(tile.entity.cons().valid() && liquidDrop != null){
|
||||
float maxPump = Math.min(liquidCapacity - tile.entity.liquids().total(), tiles * pumpAmount * tile.entity.delta() / size / size) * tile.entity.efficiency();
|
||||
tile.entity.liquids().add(liquidDrop, maxPump);
|
||||
}
|
||||
|
||||
if(tile.entity.liquids.currentAmount() > 0f && tile.entity.timer.get(timerContentCheck, 10)){
|
||||
useContent(tile, tile.entity.liquids.current());
|
||||
if(tile.entity.liquids().currentAmount() > 0f && tile.entity.timer(timerContentCheck, 10)){
|
||||
useContent(tile, tile.entity.liquids().current());
|
||||
}
|
||||
|
||||
tryDumpLiquid(tile, tile.entity.liquids.current());
|
||||
tryDumpLiquid(tile, tile.entity.liquids().current());
|
||||
}
|
||||
|
||||
protected boolean isValid(Tile tile){
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package mindustry.world.blocks.production;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
@@ -15,15 +15,11 @@ import mindustry.world.meta.values.*;
|
||||
* Extracts a random list of items from an input item and an input liquid.
|
||||
*/
|
||||
public class Separator extends Block{
|
||||
protected @NonNull ItemStack[] results;
|
||||
protected float craftTime;
|
||||
protected float spinnerRadius = 2.5f;
|
||||
protected float spinnerLength = 1f;
|
||||
protected float spinnerThickness = 1f;
|
||||
protected float spinnerSpeed = 2f;
|
||||
public @NonNull ItemStack[] results;
|
||||
public float craftTime;
|
||||
|
||||
protected Color color = Color.valueOf("858585");
|
||||
protected int liquidRegion;
|
||||
public int liquidRegion, spinnerRegion;
|
||||
public float spinnerSpeed = 3f;
|
||||
|
||||
public Separator(String name){
|
||||
super(name);
|
||||
@@ -33,6 +29,7 @@ public class Separator extends Block{
|
||||
hasLiquids = true;
|
||||
|
||||
liquidRegion = reg("-liquid");
|
||||
spinnerRegion = reg("-spinner");
|
||||
entityType = GenericCrafterEntity::new;
|
||||
}
|
||||
|
||||
@@ -57,7 +54,7 @@ public class Separator extends Block{
|
||||
|
||||
@Override
|
||||
public boolean shouldConsume(Tile tile){
|
||||
return tile.entity.items.total() < itemCapacity;
|
||||
return tile.entity.items().total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,14 +63,14 @@ public class Separator extends Block{
|
||||
|
||||
GenericCrafterEntity entity = tile.ent();
|
||||
|
||||
Draw.color(tile.entity.liquids.current().color);
|
||||
Draw.alpha(tile.entity.liquids.total() / liquidCapacity);
|
||||
Draw.color(tile.entity.liquids().current().color);
|
||||
Draw.alpha(tile.entity.liquids().total() / liquidCapacity);
|
||||
Draw.rect(reg(liquidRegion), tile.drawx(), tile.drawy());
|
||||
|
||||
Draw.color(color);
|
||||
Lines.stroke(spinnerThickness);
|
||||
Lines.spikes(tile.drawx(), tile.drawy(), spinnerRadius, spinnerLength, 3, entity.totalProgress * spinnerSpeed);
|
||||
Draw.reset();
|
||||
if(Core.atlas.isFound(reg(spinnerRegion))){
|
||||
Draw.rect(reg(spinnerRegion), tile.drawx(), tile.drawy(), entity.totalProgress * spinnerSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +79,7 @@ public class Separator extends Block{
|
||||
|
||||
entity.totalProgress += entity.warmup * entity.delta();
|
||||
|
||||
if(entity.cons.valid()){
|
||||
if(entity.consValid()){
|
||||
entity.progress += getProgressIncrease(entity, craftTime);
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
}else{
|
||||
@@ -107,14 +104,15 @@ public class Separator extends Block{
|
||||
count += stack.amount;
|
||||
}
|
||||
|
||||
entity.cons.trigger();
|
||||
entity.consume();
|
||||
|
||||
if(item != null && entity.items.get(item) < itemCapacity){
|
||||
if(item != null && entity.items().get(item) < itemCapacity){
|
||||
useContent(tile, item);
|
||||
offloadNear(tile, item);
|
||||
}
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDump, dumpTime)){
|
||||
if(entity.timer(timerDump, dumpTime)){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import arc.graphics.g2d.Draw;
|
||||
import arc.graphics.g2d.TextureRegion;
|
||||
import arc.math.Mathf;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.content.Liquids;
|
||||
import mindustry.entities.Effects;
|
||||
import mindustry.entities.Effects.Effect;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.type.Liquid;
|
||||
import mindustry.ui.Bar;
|
||||
@@ -26,7 +26,7 @@ public class SolidPump extends Pump{
|
||||
public float updateEffectChance = 0.02f;
|
||||
public float rotateSpeed = 1f;
|
||||
/** Attribute that is checked when calculating output. */
|
||||
public Attribute attribute;
|
||||
public @Nullable Attribute attribute;
|
||||
|
||||
public SolidPump(String name){
|
||||
super(name);
|
||||
@@ -64,6 +64,9 @@ public class SolidPump extends Pump{
|
||||
|
||||
stats.remove(BlockStat.output);
|
||||
stats.add(BlockStat.output, result, 60f * pumpAmount, true);
|
||||
if(attribute != null){
|
||||
stats.add(BlockStat.affinities, attribute);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,8 +74,8 @@ public class SolidPump extends Pump{
|
||||
SolidPumpEntity entity = tile.ent();
|
||||
|
||||
Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
Draw.color(tile.entity.liquids.current().color);
|
||||
Draw.alpha(tile.entity.liquids.total() / liquidCapacity);
|
||||
Draw.color(tile.entity.liquids().current().color);
|
||||
Draw.alpha(tile.entity.liquids().total() / liquidCapacity);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
|
||||
Draw.color();
|
||||
Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.pumpTime * rotateSpeed);
|
||||
@@ -102,13 +105,14 @@ public class SolidPump extends Pump{
|
||||
|
||||
fraction += entity.boost;
|
||||
|
||||
if(tile.entity.cons.valid() && typeLiquid(tile) < liquidCapacity - 0.001f){
|
||||
if(tile.entity.cons().valid() && typeLiquid(tile) < liquidCapacity - 0.001f){
|
||||
float maxPump = Math.min(liquidCapacity - typeLiquid(tile), pumpAmount * entity.delta() * fraction * entity.efficiency());
|
||||
tile.entity.liquids.add(result, maxPump);
|
||||
tile.entity.liquids().add(result, maxPump);
|
||||
entity.lastPump = maxPump;
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
if(tile.entity.timer(timerContentCheck, 10)) useContent(tile, result);
|
||||
if(Mathf.chance(entity.delta() * updateEffectChance))
|
||||
Effects.effect(updateEffect, entity.x + Mathf.range(size * 2f), entity.y + Mathf.range(size * 2f));
|
||||
updateEffect.at(entity.getX() + Mathf.range(size * 2f), entity.getY() + Mathf.range(size * 2f));
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f);
|
||||
entity.lastPump = 0f;
|
||||
@@ -149,7 +153,7 @@ public class SolidPump extends Pump{
|
||||
}
|
||||
|
||||
public float typeLiquid(Tile tile){
|
||||
return tile.entity.liquids.total();
|
||||
return tile.entity.liquids().total();
|
||||
}
|
||||
|
||||
public static class SolidPumpEntity extends TileEntity{
|
||||
|
||||
@@ -4,8 +4,9 @@ import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
@@ -29,7 +30,7 @@ public class ItemSource extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
tile.<ItemSourceEntity>ent().outputItem = content.item(value);
|
||||
}
|
||||
|
||||
@@ -73,15 +74,15 @@ public class ItemSource extends Block{
|
||||
ItemSourceEntity entity = tile.ent();
|
||||
if(entity.outputItem == null) return;
|
||||
|
||||
entity.items.set(entity.outputItem, 1);
|
||||
entity.items().set(entity.outputItem, 1);
|
||||
tryDump(tile, entity.outputItem);
|
||||
entity.items.set(entity.outputItem, 0);
|
||||
entity.items().set(entity.outputItem, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
ItemSourceEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.outputItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.outputItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
@@ -101,15 +102,15 @@ public class ItemSource extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeShort(outputItem == null ? -1 : outputItem.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.s(outputItem == null ? -1 : outputItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
outputItem = content.item(stream.readShort());
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
outputItem = content.item(read.s());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
package mindustry.world.blocks.sandbox;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class LiquidSource extends Block{
|
||||
public static Liquid lastLiquid;
|
||||
@@ -53,9 +49,9 @@ public class LiquidSource extends Block{
|
||||
LiquidSourceEntity entity = tile.ent();
|
||||
|
||||
if(entity.source == null){
|
||||
tile.entity.liquids.clear();
|
||||
tile.entity.liquids().clear();
|
||||
}else{
|
||||
tile.entity.liquids.add(entity.source, liquidCapacity);
|
||||
tile.entity.liquids().add(entity.source, liquidCapacity);
|
||||
tryDumpLiquid(tile, entity.source);
|
||||
}
|
||||
}
|
||||
@@ -82,33 +78,14 @@ public class LiquidSource extends Block{
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
LiquidSourceEntity entity = tile.ent();
|
||||
|
||||
Array<Liquid> items = content.liquids();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
|
||||
for(int i = 0; i < items.size; i++){
|
||||
final int f = i;
|
||||
ImageButton button = cont.addImageButton(Tex.clear, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).size(38).group(group).get();
|
||||
button.changed(() -> {
|
||||
tile.configure(button.isChecked() ? items.get(f).id : -1);
|
||||
control.input.frag.config.hideConfig();
|
||||
lastLiquid = items.get(f);
|
||||
});
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(items.get(i).icon(Cicon.medium));
|
||||
button.setChecked(entity.source == items.get(i));
|
||||
|
||||
if(i % 4 == 3){
|
||||
cont.row();
|
||||
}
|
||||
}
|
||||
|
||||
table.add(cont);
|
||||
ItemSelection.buildTable(table, content.liquids(), () -> entity.source, liquid -> {
|
||||
lastLiquid = liquid;
|
||||
tile.configure(liquid == null ? -1 : liquid.id);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
tile.<LiquidSourceEntity>ent().source = value == -1 ? null : content.liquid(value);
|
||||
}
|
||||
|
||||
@@ -121,15 +98,15 @@ public class LiquidSource extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(source == null ? -1 : source.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(source == null ? -1 : source.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
byte id = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
byte id = read.b();
|
||||
source = id == -1 ? null : content.liquid(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
package mindustry.world.blocks.storage;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.struct.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.traits.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class CoreBlock extends StorageBlock{
|
||||
public Mech mech = Mechs.starter;
|
||||
public UnitType mech = UnitTypes.starter;
|
||||
|
||||
public CoreBlock(String name){
|
||||
super(name);
|
||||
@@ -40,15 +36,16 @@ public class CoreBlock extends StorageBlock{
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onUnitRespawn(Tile tile, Player player){
|
||||
public static void onUnitRespawn(Tile tile, Playerc player){
|
||||
if(player == null || tile.entity == null) return;
|
||||
|
||||
CoreEntity entity = tile.ent();
|
||||
Effects.effect(Fx.spawn, entity);
|
||||
Fx.spawn.at(entity);
|
||||
entity.progress = 0;
|
||||
entity.spawnPlayer = player;
|
||||
entity.spawnPlayer.onRespawn(tile);
|
||||
entity.spawnPlayer.applyImpulse(0, 8f);
|
||||
//TODO fix
|
||||
//entity.spawnPlayer.onRespawn(tile);
|
||||
//entity.spawnPlayer.applyImpulse(0, 8f);
|
||||
entity.spawnPlayer = null;
|
||||
}
|
||||
|
||||
@@ -60,7 +57,7 @@ public class CoreBlock extends StorageBlock{
|
||||
new Bar(
|
||||
() -> Core.bundle.format("bar.capacity", ui.formatAmount(((CoreEntity)e).storageCapacity)),
|
||||
() -> Pal.items,
|
||||
() -> e.items.total() / (float)(((CoreEntity)e).storageCapacity * content.items().count(i -> i.type == ItemType.material))
|
||||
() -> e.items().total() / (float)(((CoreEntity)e).storageCapacity * content.items().count(i -> i.type == ItemType.material))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -71,7 +68,7 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
return tile.entity.items().get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,31 +81,31 @@ public class CoreBlock extends StorageBlock{
|
||||
public void onProximityUpdate(Tile tile){
|
||||
CoreEntity entity = tile.ent();
|
||||
|
||||
for(TileEntity other : state.teams.cores(tile.getTeam())){
|
||||
if(other.tile != tile){
|
||||
entity.items = other.items;
|
||||
for(Tilec other : state.teams.cores(tile.team())){
|
||||
if(other.tile() != tile){
|
||||
entity.items(other.items());
|
||||
}
|
||||
}
|
||||
state.teams.registerCore(entity);
|
||||
|
||||
entity.storageCapacity = itemCapacity + entity.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
|
||||
entity.proximity().each(this::isContainer, t -> {
|
||||
t.entity.items = entity.items;
|
||||
t.entity.items(entity.items());
|
||||
t.<StorageBlockEntity>ent().linkedCore = tile;
|
||||
});
|
||||
|
||||
for(TileEntity other : state.teams.cores(tile.getTeam())){
|
||||
if(other.tile == tile) continue;
|
||||
entity.storageCapacity += other.block.itemCapacity + entity.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
|
||||
for(Tilec other : state.teams.cores(tile.team())){
|
||||
if(other.tile() == tile) continue;
|
||||
entity.storageCapacity += other.block().itemCapacity + other.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
|
||||
}
|
||||
|
||||
if(!world.isGenerating()){
|
||||
for(Item item : content.items()){
|
||||
entity.items.set(item, Math.min(entity.items.get(item), entity.storageCapacity));
|
||||
entity.items().set(item, Math.min(entity.items().get(item), entity.storageCapacity));
|
||||
}
|
||||
}
|
||||
|
||||
for(CoreEntity other : state.teams.cores(tile.getTeam())){
|
||||
for(CoreEntity other : state.teams.cores(tile.team())){
|
||||
other.storageCapacity = entity.storageCapacity;
|
||||
}
|
||||
}
|
||||
@@ -123,10 +120,10 @@ public class CoreBlock extends StorageBlock{
|
||||
Draw.rect("block-select", t.drawx() + offset * p.x, t.drawy() + offset * p.y, i * 90);
|
||||
}
|
||||
};
|
||||
if(tile.entity.proximity().contains(e -> isContainer(e) && e.entity.items == tile.entity.items)){
|
||||
if(tile.entity.proximity().contains(e -> isContainer(e) && e.entity.items() == tile.entity.items())){
|
||||
outline.get(tile);
|
||||
}
|
||||
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, outline);
|
||||
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items() == tile.entity.items(), outline);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@@ -137,7 +134,7 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public float handleDamage(Tile tile, float amount){
|
||||
if(player != null && tile.getTeam() == player.getTeam()){
|
||||
if(player != null && tile.team() == player.team()){
|
||||
Events.fire(Trigger.teamCoreDamage);
|
||||
}
|
||||
return amount;
|
||||
@@ -151,27 +148,27 @@ public class CoreBlock extends StorageBlock{
|
||||
@Override
|
||||
public void removed(Tile tile){
|
||||
CoreEntity entity = tile.ent();
|
||||
int total = tile.entity.proximity().count(e -> e.entity != null && e.entity.items != null && e.entity.items == tile.entity.items);
|
||||
float fract = 1f / total / state.teams.cores(tile.getTeam()).size;
|
||||
int total = tile.entity.proximity().count(e -> e.entity != null && e.entity.items() != null && e.entity.items() == tile.entity.items());
|
||||
float fract = 1f / total / state.teams.cores(tile.team()).size;
|
||||
|
||||
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, t -> {
|
||||
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items() == tile.entity.items(), t -> {
|
||||
StorageBlockEntity ent = (StorageBlockEntity)t.entity;
|
||||
ent.linkedCore = null;
|
||||
ent.items = new ItemModule();
|
||||
ent.items(new ItemModule());
|
||||
for(Item item : content.items()){
|
||||
ent.items.set(item, (int)(fract * tile.entity.items.get(item)));
|
||||
ent.items().set(item, (int)(fract * tile.entity.items().get(item)));
|
||||
}
|
||||
});
|
||||
|
||||
state.teams.unregisterCore(entity);
|
||||
|
||||
int max = itemCapacity * state.teams.cores(tile.getTeam()).size;
|
||||
int max = itemCapacity * state.teams.cores(tile.team()).size;
|
||||
for(Item item : content.items()){
|
||||
tile.entity.items.set(item, Math.min(tile.entity.items.get(item), max));
|
||||
tile.entity.items().set(item, Math.min(tile.entity.items().get(item), max));
|
||||
}
|
||||
|
||||
for(CoreEntity other : state.teams.cores(tile.getTeam())){
|
||||
other.block.onProximityUpdate(other.tile);
|
||||
for(CoreEntity other : state.teams.cores(tile.team())){
|
||||
other.block().onProximityUpdate(other.tile());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +184,8 @@ public class CoreBlock extends StorageBlock{
|
||||
CoreEntity entity = tile.ent();
|
||||
|
||||
if(entity.heat > 0.001f){
|
||||
RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.spawnPlayer, mech);
|
||||
//TODO implement
|
||||
//RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.spawnPlayer, mech);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,8 +203,10 @@ public class CoreBlock extends StorageBlock{
|
||||
public void update(Tile tile){
|
||||
CoreEntity entity = tile.ent();
|
||||
|
||||
//TODO implement
|
||||
/*
|
||||
if(entity.spawnPlayer != null){
|
||||
if(!entity.spawnPlayer.isDead() || !entity.spawnPlayer.isAdded()){
|
||||
if(!entity.spawnPlayer.dead() || !entity.spawnPlayer.isAdded()){
|
||||
entity.spawnPlayer = null;
|
||||
return;
|
||||
}
|
||||
@@ -221,7 +221,7 @@ public class CoreBlock extends StorageBlock{
|
||||
}
|
||||
}else{
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.1f);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,26 +231,11 @@ public class CoreBlock extends StorageBlock{
|
||||
return entity.spawnPlayer != null;
|
||||
}
|
||||
|
||||
public class CoreEntity extends TileEntity implements SpawnerTrait{
|
||||
protected Player spawnPlayer;
|
||||
public class CoreEntity extends TileEntity{
|
||||
protected Playerc spawnPlayer;
|
||||
protected float progress;
|
||||
protected float time;
|
||||
protected float heat;
|
||||
protected int storageCapacity;
|
||||
|
||||
@Override
|
||||
public boolean hasUnit(Unit unit){
|
||||
return unit == spawnPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSpawning(Player player){
|
||||
if(!netServer.isWaitingForPlayers() && spawnPlayer == null){
|
||||
spawnPlayer = player;
|
||||
progress = 0f;
|
||||
player.mech = mech;
|
||||
player.beginRespawning(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import arc.math.Mathf;
|
||||
import arc.util.Time;
|
||||
import mindustry.Vars;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.entities.Effects;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.type.Item;
|
||||
@@ -17,8 +16,7 @@ import mindustry.world.Tile;
|
||||
import mindustry.world.meta.BlockStat;
|
||||
import mindustry.world.meta.StatUnit;
|
||||
|
||||
import static mindustry.Vars.data;
|
||||
import static mindustry.Vars.world;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class LaunchPad extends StorageBlock{
|
||||
public final int timerLaunch = timers++;
|
||||
@@ -41,14 +39,15 @@ public class LaunchPad extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return item.type == ItemType.material && tile.entity.items.total() < itemCapacity;
|
||||
return item.type == ItemType.material && tile.entity.items().total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
float progress = Mathf.clamp(Mathf.clamp((tile.entity.items.total() / (float)itemCapacity)) * ((tile.entity.timer.getTime(timerLaunch) / (launchTime / tile.entity.timeScale))));
|
||||
//TODO broken
|
||||
float progress = Mathf.clamp(Mathf.clamp((tile.entity.items().total() / (float)itemCapacity)) * ((tile.entity.timer().getTime(timerLaunch) / (launchTime / tile.entity.timeScale()))));
|
||||
float scale = size / 3f;
|
||||
|
||||
Lines.stroke(2f);
|
||||
@@ -57,7 +56,7 @@ public class LaunchPad extends StorageBlock{
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
|
||||
if(tile.entity.cons.valid()){
|
||||
if(tile.entity.cons().valid()){
|
||||
for(int i = 0; i < 3; i++){
|
||||
float f = (Time.time() / 200f + i * 0.5f) % 1f;
|
||||
|
||||
@@ -71,15 +70,15 @@ public class LaunchPad extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
TileEntity entity = tile.entity;
|
||||
Tilec entity = tile.entity;
|
||||
|
||||
if(world.isZone() && entity.cons.valid() && entity.items.total() >= itemCapacity && entity.timer.get(timerLaunch, launchTime / entity.timeScale)){
|
||||
if(state.isCampaign() && entity.consValid() && entity.items().total() >= itemCapacity && entity.timer(timerLaunch, launchTime / entity.timeScale())){
|
||||
for(Item item : Vars.content.items()){
|
||||
Events.fire(Trigger.itemLaunch);
|
||||
Effects.effect(Fx.padlaunch, tile);
|
||||
int used = Math.min(entity.items.get(item), itemCapacity);
|
||||
Fx.padlaunch.at(tile);
|
||||
int used = Math.min(entity.items().get(item), itemCapacity);
|
||||
data.addItem(item, used);
|
||||
entity.items.remove(item, used);
|
||||
entity.items().remove(item, used);
|
||||
Events.fire(new LaunchItemEvent(item, used));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mindustry.world.blocks.storage;
|
||||
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.world.Block;
|
||||
import mindustry.world.Tile;
|
||||
@@ -17,7 +17,7 @@ public abstract class StorageBlock extends Block{
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
StorageBlockEntity entity = tile.ent();
|
||||
return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(item, entity.linkedCore, source) : tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(item, entity.linkedCore, source) : tile.entity.items().get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,13 +43,13 @@ public abstract class StorageBlock extends Block{
|
||||
* Returns null if no items are there.
|
||||
*/
|
||||
public Item removeItem(Tile tile, Item item){
|
||||
TileEntity entity = tile.entity;
|
||||
Tilec entity = tile.entity;
|
||||
|
||||
if(item == null){
|
||||
return entity.items.take();
|
||||
return entity.items().take();
|
||||
}else{
|
||||
if(entity.items.has(item)){
|
||||
entity.items.remove(item, 1);
|
||||
if(entity.items().has(item)){
|
||||
entity.items().remove(item, 1);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@ public abstract class StorageBlock extends Block{
|
||||
* If the item is null, it should return whether it has ANY items.
|
||||
*/
|
||||
public boolean hasItem(Tile tile, Item item){
|
||||
TileEntity entity = tile.entity;
|
||||
Tilec entity = tile.entity;
|
||||
if(item == null){
|
||||
return entity.items.total() > 0;
|
||||
return entity.items().total() > 0;
|
||||
}else{
|
||||
return entity.items.has(item);
|
||||
return entity.items().has(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
@@ -54,8 +55,8 @@ public class Unloader extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
tile.entity.items.clear();
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
tile.entity.items().clear();
|
||||
tile.<UnloaderEntity>ent().sortItem = content.item(value);
|
||||
}
|
||||
|
||||
@@ -63,16 +64,16 @@ public class Unloader extends Block{
|
||||
public void update(Tile tile){
|
||||
UnloaderEntity entity = tile.ent();
|
||||
|
||||
if(tile.entity.timer.get(timerUnload, speed / entity.timeScale) && tile.entity.items.total() == 0){
|
||||
if(tile.entity.timer(timerUnload, speed / entity.timeScale()) && tile.entity.items().total() == 0){
|
||||
for(Tile other : tile.entity.proximity()){
|
||||
if(other.interactable(tile.getTeam()) && other.block().unloadable && other.block().hasItems && entity.items.total() == 0 &&
|
||||
((entity.sortItem == null && other.entity.items.total() > 0) || hasItem(other, entity.sortItem))){
|
||||
if(other.interactable(tile.team()) && other.block().unloadable && other.block().hasItems && entity.items().total() == 0 &&
|
||||
((entity.sortItem == null && other.entity.items().total() > 0) || hasItem(other, entity.sortItem))){
|
||||
offloadNear(tile, removeItem(other, entity.sortItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(entity.items.total() > 0){
|
||||
if(entity.items().total() > 0){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
@@ -82,13 +83,13 @@ public class Unloader extends Block{
|
||||
* Returns null if no items are there.
|
||||
*/
|
||||
private Item removeItem(Tile tile, Item item){
|
||||
TileEntity entity = tile.entity;
|
||||
Tilec entity = tile.entity;
|
||||
|
||||
if(item == null){
|
||||
return entity.items.take();
|
||||
return entity.items().take();
|
||||
}else{
|
||||
if(entity.items.has(item)){
|
||||
entity.items.remove(item, 1);
|
||||
if(entity.items().has(item)){
|
||||
entity.items().remove(item, 1);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -101,11 +102,11 @@ public class Unloader extends Block{
|
||||
* If the item is null, it should return whether it has ANY items.
|
||||
*/
|
||||
private boolean hasItem(Tile tile, Item item){
|
||||
TileEntity entity = tile.entity;
|
||||
Tilec entity = tile.entity;
|
||||
if(item == null){
|
||||
return entity.items.total() > 0;
|
||||
return entity.items().total() > 0;
|
||||
}else{
|
||||
return entity.items.has(item);
|
||||
return entity.items().has(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ public class Unloader extends Block{
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
UnloaderEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.sortItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
@@ -138,15 +139,15 @@ public class Unloader extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(sortItem == null ? -1 : sortItem.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(sortItem == null ? -1 : sortItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
byte id = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
byte id = read.b();
|
||||
sortItem = id == -1 ? null : content.items().get(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@ package mindustry.world.blocks.units;
|
||||
import arc.*;
|
||||
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.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Effects.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.graphics.*;
|
||||
@@ -20,10 +21,10 @@ import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.indexer;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class CommandCenter extends Block{
|
||||
protected TextureRegion[] commandRegions = new TextureRegion[UnitCommand.all.length];
|
||||
protected TextureRegionDrawable[] commandRegions = new TextureRegionDrawable[UnitCommand.all.length];
|
||||
protected Color topColor = Pal.command;
|
||||
protected Color bottomColor = Color.valueOf("5e5e5e");
|
||||
protected Effect effect = Fx.commandSend;
|
||||
@@ -41,7 +42,7 @@ public class CommandCenter extends Block{
|
||||
@Override
|
||||
public void placed(Tile tile){
|
||||
super.placed(tile);
|
||||
ObjectSet<Tile> set = indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter);
|
||||
ObjectSet<Tile> set = indexer.getAllied(tile.team(), BlockFlag.comandCenter);
|
||||
|
||||
if(set.size > 0){
|
||||
CommandCenterEntity entity = tile.ent();
|
||||
@@ -54,10 +55,10 @@ public class CommandCenter extends Block{
|
||||
public void removed(Tile tile){
|
||||
super.removed(tile);
|
||||
|
||||
ObjectSet<Tile> set = indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter);
|
||||
ObjectSet<Tile> set = indexer.getAllied(tile.team(), BlockFlag.comandCenter);
|
||||
|
||||
if(set.size == 1){
|
||||
Units.each(tile.getTeam(), u -> u.onCommand(UnitCommand.all[0]));
|
||||
Groups.unit.each(t -> t.team() == tile.team(), u -> u.controller().command(UnitCommand.all[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,8 +66,10 @@ public class CommandCenter extends Block{
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
for(UnitCommand cmd : UnitCommand.all){
|
||||
commandRegions[cmd.ordinal()] = Core.atlas.find("icon-command-" + cmd.name() + "-small");
|
||||
if(ui != null){
|
||||
for(UnitCommand cmd : UnitCommand.all){
|
||||
commandRegions[cmd.ordinal()] = ui.getIcon("command" + Strings.capitalize(cmd.name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,12 +78,12 @@ public class CommandCenter extends Block{
|
||||
CommandCenterEntity entity = tile.ent();
|
||||
super.draw(tile);
|
||||
|
||||
float size = IconSize.small.size/4f;
|
||||
float size = 6f;
|
||||
|
||||
Draw.color(bottomColor);
|
||||
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy() - 1, size, size);
|
||||
Draw.rect(commandRegions[entity.command.ordinal()].getRegion(), tile.drawx(), tile.drawy() - 1, size, size);
|
||||
Draw.color(topColor);
|
||||
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy(), size, size);
|
||||
Draw.rect(commandRegions[entity.command.ordinal()].getRegion(), tile.drawx(), tile.drawy(), size, size);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@@ -91,7 +94,7 @@ public class CommandCenter extends Block{
|
||||
Table buttons = new Table();
|
||||
|
||||
for(UnitCommand cmd : UnitCommand.all){
|
||||
buttons.addImageButton(Core.atlas.drawable("icon-command-" + cmd.name() + "-small"), Styles.clearToggleTransi, () -> tile.configure(cmd.ordinal()))
|
||||
buttons.addImageButton(commandRegions[cmd.ordinal()], Styles.clearToggleTransi, () -> tile.configure(cmd.ordinal()))
|
||||
.size(44).group(group).update(b -> b.setChecked(entity.command == cmd));
|
||||
}
|
||||
table.add(buttons);
|
||||
@@ -100,18 +103,18 @@ public class CommandCenter extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
public void configured(Tile tile, Playerc player, int value){
|
||||
UnitCommand command = UnitCommand.all[value];
|
||||
Effects.effect(((CommandCenter)tile.block()).effect, tile);
|
||||
((CommandCenter)tile.block()).effect.at(tile);
|
||||
|
||||
for(Tile center : indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter)){
|
||||
for(Tile center : indexer.getAllied(tile.team(), BlockFlag.comandCenter)){
|
||||
if(center.block() instanceof CommandCenter){
|
||||
CommandCenterEntity entity = center.ent();
|
||||
entity.command = command;
|
||||
}
|
||||
}
|
||||
|
||||
Units.each(tile.getTeam(), u -> u.onCommand(command));
|
||||
Groups.unit.each(t -> t.team() == tile.team(), u -> u.controller().command(command));
|
||||
Events.fire(new CommandIssueEvent(tile, command));
|
||||
}
|
||||
|
||||
@@ -124,15 +127,15 @@ public class CommandCenter extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(command.ordinal());
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(command.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte version) throws IOException{
|
||||
super.read(stream, version);
|
||||
command = UnitCommand.all[stream.readByte()];
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
command = UnitCommand.all[read.b()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,27 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.struct.EnumSet;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.traits.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
//TODO remove
|
||||
public class MechPad extends Block{
|
||||
public @NonNull Mech mech;
|
||||
public @NonNull UnitType mech;
|
||||
public float buildTime = 60 * 5;
|
||||
|
||||
public MechPad(String name){
|
||||
@@ -46,13 +42,13 @@ public class MechPad extends Block{
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.server)
|
||||
public static void onMechFactoryTap(Player player, Tile tile){
|
||||
public static void onMechFactoryTap(Playerc player, Tile tile){
|
||||
if(player == null || tile == null || !(tile.block() instanceof MechPad) || !checkValidTap(tile, player)) return;
|
||||
|
||||
MechFactoryEntity entity = tile.ent();
|
||||
|
||||
if(!entity.cons.valid()) return;
|
||||
player.beginRespawning(entity);
|
||||
if(!entity.consValid()) return;
|
||||
//player.beginRespawning(entity);
|
||||
entity.sameMech = false;
|
||||
}
|
||||
|
||||
@@ -62,27 +58,27 @@ public class MechPad extends Block{
|
||||
|
||||
MechFactoryEntity entity = tile.ent();
|
||||
|
||||
Effects.effect(Fx.spawn, entity);
|
||||
Fx.spawn.at(entity);
|
||||
|
||||
if(entity.player == null) return;
|
||||
Mech mech = ((MechPad)tile.block()).mech;
|
||||
boolean resetSpawner = !entity.sameMech && entity.player.mech == mech;
|
||||
entity.player.mech = !entity.sameMech && entity.player.mech == mech ? Mechs.starter : mech;
|
||||
//Mech mech = ((MechPad)tile.block()).mech;
|
||||
//boolean resetSpawner = !entity.sameMech && entity.player.mech == mech;
|
||||
//entity.player.mech = !entity.sameMech && entity.player.mech == mech ? UnitTypes.starter : mech;
|
||||
|
||||
Player player = entity.player;
|
||||
Playerc player = entity.player;
|
||||
|
||||
entity.progress = 0;
|
||||
entity.player.onRespawn(tile);
|
||||
if(resetSpawner) entity.player.lastSpawner = null;
|
||||
entity.player = null;
|
||||
//entity.progress = 0;
|
||||
//entity.player.onRespawn(tile);
|
||||
//if(resetSpawner) entity.player.lastSpawner = null;
|
||||
//entity.player = null;
|
||||
|
||||
Events.fire(new MechChangeEvent(player, player.mech));
|
||||
//Events.fire(new MechChangeEvent(player, player.mech));
|
||||
}
|
||||
|
||||
protected static boolean checkValidTap(Tile tile, Player player){
|
||||
protected static boolean checkValidTap(Tile tile, Playerc player){
|
||||
MechFactoryEntity entity = tile.ent();
|
||||
return !player.isDead() && tile.interactable(player.getTeam()) && Math.abs(player.x - tile.drawx()) <= tile.block().size * tilesize &&
|
||||
Math.abs(player.y - tile.drawy()) <= tile.block().size * tilesize && entity.cons.valid() && entity.player == null;
|
||||
return false;//!player.dead() && tile.interactable(player.team()) && Math.abs(player.x - tile.drawx()) <= tile.block().size * tilesize &&
|
||||
//Math.abs(player.y - tile.drawy()) <= tile.block().size * tilesize && entity.consValid() && entity.player == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,14 +92,15 @@ public class MechPad extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tapped(Tile tile, Player player){
|
||||
public void tapped(Tile tile, Playerc player){
|
||||
MechFactoryEntity entity = tile.ent();
|
||||
|
||||
if(checkValidTap(tile, player)){
|
||||
Call.onMechFactoryTap(player, tile);
|
||||
}else if(player.isLocal && mobile && !player.isDead() && entity.cons.valid() && entity.player == null){
|
||||
}else if(player.isLocal() && mobile && !player.dead() && entity.consValid() && entity.player == null){
|
||||
//deselect on double taps
|
||||
player.moveTarget = player.moveTarget == tile.entity ? null : tile.entity;
|
||||
//TODO remove
|
||||
//player.moveTarget = player.moveTarget == tile.entity ? null : tile.entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +109,8 @@ public class MechPad extends Block{
|
||||
MechFactoryEntity entity = tile.ent();
|
||||
|
||||
if(entity.player != null){
|
||||
RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.player, (!entity.sameMech && entity.player.mech == mech ? Mechs.starter : mech));
|
||||
//TODO remove
|
||||
//RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.player, (!entity.sameMech && entity.player.mech == mech ? UnitTypes.starter : mech));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,43 +133,27 @@ public class MechPad extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
public class MechFactoryEntity extends TileEntity implements SpawnerTrait{
|
||||
Player player;
|
||||
public class MechFactoryEntity extends TileEntity{
|
||||
Playerc player;
|
||||
boolean sameMech;
|
||||
float progress;
|
||||
float time;
|
||||
float heat;
|
||||
|
||||
@Override
|
||||
public boolean hasUnit(Unit unit){
|
||||
return unit == player;
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(progress);
|
||||
write.f(time);
|
||||
write.f(heat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSpawning(Player unit){
|
||||
if(player == null){
|
||||
progress = 0f;
|
||||
player = unit;
|
||||
sameMech = true;
|
||||
|
||||
player.beginRespawning(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(progress);
|
||||
stream.writeFloat(time);
|
||||
stream.writeFloat(heat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
progress = stream.readFloat();
|
||||
time = stream.readFloat();
|
||||
heat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
progress = read.f();
|
||||
time = read.f();
|
||||
heat = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.struct.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class RallyPoint extends Block{
|
||||
|
||||
public RallyPoint(String name){
|
||||
super(name);
|
||||
update = solid = true;
|
||||
flags = EnumSet.of(BlockFlag.rally);
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,7 @@ import arc.math.Mathf;
|
||||
import arc.math.geom.Rect;
|
||||
import arc.util.Time;
|
||||
import mindustry.entities.Units;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.entities.type.Unit;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.Block;
|
||||
import mindustry.world.Tile;
|
||||
@@ -96,7 +95,7 @@ public class RepairPoint extends Block{
|
||||
Draw.color(Color.valueOf("e8ffd7"));
|
||||
Drawf.laser(laser, laserEnd,
|
||||
tile.drawx() + Angles.trnsx(ang, len), tile.drawy() + Angles.trnsy(ang, len),
|
||||
entity.target.x, entity.target.y, entity.strength);
|
||||
entity.target.x(), entity.target.y(), entity.strength);
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
@@ -111,11 +110,10 @@ public class RepairPoint extends Block{
|
||||
RepairPointEntity entity = tile.ent();
|
||||
|
||||
boolean targetIsBeingRepaired = false;
|
||||
if(entity.target != null && (entity.target.isDead() || entity.target.dst(tile) > repairRadius || entity.target.health >= entity.target.maxHealth())){
|
||||
if(entity.target != null && (entity.target.dead() || entity.target.dst(tile) > repairRadius || entity.target.health() >= entity.target.maxHealth())){
|
||||
entity.target = null;
|
||||
}else if(entity.target != null && entity.cons.valid()){
|
||||
entity.target.health += repairSpeed * Time.delta() * entity.strength * entity.efficiency();
|
||||
entity.target.clampHealth();
|
||||
}else if(entity.target != null && entity.consValid()){
|
||||
entity.target.heal(repairSpeed * Time.delta() * entity.strength * entity.efficiency());
|
||||
entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f);
|
||||
targetIsBeingRepaired = true;
|
||||
}
|
||||
@@ -126,10 +124,9 @@ public class RepairPoint extends Block{
|
||||
entity.strength = Mathf.lerpDelta(entity.strength, 0f, 0.07f * Time.delta());
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerTarget, 20)){
|
||||
if(entity.timer(timerTarget, 20)){
|
||||
rect.setSize(repairRadius * 2).setCenter(tile.drawx(), tile.drawy());
|
||||
entity.target = Units.closest(tile.getTeam(), tile.drawx(), tile.drawy(), repairRadius,
|
||||
unit -> unit.health < unit.maxHealth());
|
||||
entity.target = Units.closest(tile.team(), tile.drawx(), tile.drawy(), repairRadius, Unitc::damaged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +138,7 @@ public class RepairPoint extends Block{
|
||||
}
|
||||
|
||||
public class RepairPointEntity extends TileEntity{
|
||||
public Unit target;
|
||||
public Unitc target;
|
||||
public float strength, rotation = 90;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.annotations.Annotations.Loc;
|
||||
import mindustry.annotations.Annotations.Remote;
|
||||
import arc.struct.EnumSet;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.Mathf;
|
||||
import mindustry.Vars;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.entities.Effects;
|
||||
import mindustry.entities.type.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.Call;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.graphics.Shaders;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.Bar;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.Block;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.consumers.ConsumeItems;
|
||||
import mindustry.world.consumers.ConsumeType;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
import static mindustry.Vars.net;
|
||||
|
||||
public class UnitFactory extends Block{
|
||||
public UnitType unitType;
|
||||
@@ -55,14 +51,13 @@ public class UnitFactory extends Block{
|
||||
entity.spawned = spawns;
|
||||
|
||||
Effects.shake(2f, 3f, entity);
|
||||
Effects.effect(Fx.producesmoke, tile.drawx(), tile.drawy());
|
||||
Fx.producesmoke.at(tile.drawx(), tile.drawy());
|
||||
|
||||
if(!net.client()){
|
||||
BaseUnit unit = factory.unitType.create(tile.getTeam());
|
||||
unit.setSpawner(tile);
|
||||
Unitc unit = factory.unitType.create(tile.team());
|
||||
unit.set(tile.drawx() + Mathf.range(4), tile.drawy() + Mathf.range(4));
|
||||
unit.add();
|
||||
unit.velocity().y = factory.launchVelocity;
|
||||
unit.vel().y = factory.launchVelocity;
|
||||
Events.fire(new UnitCreateEvent(unit));
|
||||
}
|
||||
}
|
||||
@@ -109,7 +104,7 @@ public class UnitFactory extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitRemoved(Tile tile, Unit unit){
|
||||
public void unitRemoved(Tile tile, Unitc unit){
|
||||
UnitFactoryEntity entity = tile.ent();
|
||||
entity.spawned--;
|
||||
entity.spawned = Math.max(entity.spawned, 0);
|
||||
@@ -159,7 +154,7 @@ public class UnitFactory extends Block{
|
||||
return;
|
||||
}
|
||||
|
||||
if(entity.cons.valid() || tile.isEnemyCheat()){
|
||||
if(entity.consValid() || tile.isEnemyCheat()){
|
||||
entity.time += entity.delta() * entity.speedScl * Vars.state.rules.unitBuildSpeedMultiplier * entity.efficiency();
|
||||
entity.buildTime += entity.delta() * entity.efficiency() * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f);
|
||||
@@ -173,7 +168,7 @@ public class UnitFactory extends Block{
|
||||
Call.onUnitFactorySpawn(tile, entity.spawned + 1);
|
||||
useContent(tile, unitType);
|
||||
|
||||
entity.cons.trigger();
|
||||
entity.consume();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,17 +190,17 @@ public class UnitFactory extends Block{
|
||||
int spawned;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(buildTime);
|
||||
stream.writeInt(spawned);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(buildTime);
|
||||
write.i(spawned);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
buildTime = stream.readFloat();
|
||||
spawned = stream.readInt();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
buildTime = read.f();
|
||||
spawned = read.i();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package mindustry.world.consumers;
|
||||
|
||||
import arc.struct.*;
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.meta.BlockStats;
|
||||
|
||||
@@ -62,15 +62,15 @@ public abstract class Consume{
|
||||
public abstract void build(Tile tile, Table table);
|
||||
|
||||
/** Called when a consumption is triggered manually. */
|
||||
public void trigger(TileEntity entity){
|
||||
public void trigger(Tilec entity){
|
||||
|
||||
}
|
||||
|
||||
public abstract String getIcon();
|
||||
|
||||
public abstract void update(TileEntity entity);
|
||||
public abstract void update(Tilec entity);
|
||||
|
||||
public abstract boolean valid(TileEntity entity);
|
||||
public abstract boolean valid(Tilec entity);
|
||||
|
||||
public abstract void display(BlockStats stats);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import arc.struct.*;
|
||||
import arc.func.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
@@ -35,7 +35,7 @@ public class ConsumeItemFilter extends Consume{
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
content.items().each(i -> filter.get(i) && (!world.isZone() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.items != null && tile.entity.items.has(item))));
|
||||
content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.items() != null && tile.entity.items().has(item))));
|
||||
|
||||
table.add(image).size(8 * 4);
|
||||
}
|
||||
@@ -46,26 +46,26 @@ public class ConsumeItemFilter extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TileEntity entity){
|
||||
public void update(Tilec entity){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(TileEntity entity){
|
||||
public void trigger(Tilec entity){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(entity.items != null && entity.items.has(item) && this.filter.get(item)){
|
||||
entity.items.remove(item, 1);
|
||||
if(entity.items() != null && entity.items().has(item) && this.filter.get(item)){
|
||||
entity.items().remove(item, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(TileEntity entity){
|
||||
public boolean valid(Tilec entity){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(entity.items != null && entity.items.has(item) && this.filter.get(item)){
|
||||
if(entity.items() != null && entity.items().has(item) && this.filter.get(item)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package mindustry.world.consumers;
|
||||
import arc.struct.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
@@ -38,7 +38,7 @@ public class ConsumeItems extends Consume{
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
for(ItemStack stack : items){
|
||||
table.add(new ReqImage(new ItemImage(stack.item.icon(Cicon.medium), stack.amount), () -> tile.entity != null && tile.entity.items != null && tile.entity.items.has(stack.item, stack.amount))).size(8 * 4).padRight(5);
|
||||
table.add(new ReqImage(new ItemImage(stack.item.icon(Cicon.medium), stack.amount), () -> tile.entity != null && tile.entity.items() != null && tile.entity.items().has(stack.item, stack.amount))).size(8 * 4).padRight(5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,20 +48,20 @@ public class ConsumeItems extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TileEntity entity){
|
||||
public void update(Tilec entity){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(TileEntity entity){
|
||||
public void trigger(Tilec entity){
|
||||
for(ItemStack stack : items){
|
||||
entity.items.remove(stack);
|
||||
entity.items().remove(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity.items != null && entity.items.has(items);
|
||||
public boolean valid(Tilec entity){
|
||||
return entity.items() != null && entity.items().has(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,7 @@ package mindustry.world.consumers;
|
||||
import arc.struct.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
@@ -38,13 +38,13 @@ public class ConsumeLiquid extends ConsumeLiquidBase{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TileEntity entity){
|
||||
entity.liquids.remove(liquid, Math.min(use(entity), entity.liquids.get(liquid)));
|
||||
public void update(Tilec entity){
|
||||
entity.liquids().remove(liquid, Math.min(use(entity), entity.liquids().get(liquid)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(entity);
|
||||
public boolean valid(Tilec entity){
|
||||
return entity != null && entity.liquids() != null && entity.liquids().get(liquid) >= use(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package mindustry.world.consumers;
|
||||
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
|
||||
public abstract class ConsumeLiquidBase extends Consume{
|
||||
/** amount used per frame */
|
||||
@@ -22,7 +22,7 @@ public abstract class ConsumeLiquidBase extends Consume{
|
||||
return ConsumeType.liquid;
|
||||
}
|
||||
|
||||
protected float use(TileEntity entity){
|
||||
return Math.min(amount * entity.delta(), entity.block.liquidCapacity);
|
||||
protected float use(Tilec entity){
|
||||
return Math.min(amount * entity.delta(), entity.block().liquidCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package mindustry.world.consumers;
|
||||
import arc.struct.*;
|
||||
import arc.func.Boolf;
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.Liquid;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.ui.MultiReqImage;
|
||||
@@ -32,7 +32,7 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{
|
||||
public void build(Tile tile, Table table){
|
||||
Array<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.get(l));
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
list.each(liquid -> image.add(new ReqImage(liquid.icon(Cicon.medium), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.entity))));
|
||||
list.each(liquid -> image.add(new ReqImage(liquid.icon(Cicon.medium), () -> tile.entity != null && tile.entity.liquids() != null && tile.entity.liquids().get(liquid) >= use(tile.entity))));
|
||||
|
||||
table.add(image).size(8 * 4);
|
||||
}
|
||||
@@ -43,13 +43,13 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TileEntity entity){
|
||||
entity.liquids.remove(entity.liquids.current(), use(entity));
|
||||
public void update(Tilec entity){
|
||||
entity.liquids().remove(entity.liquids().current(), use(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity != null && entity.liquids != null && filter.get(entity.liquids.current()) && entity.liquids.currentAmount() >= use(entity);
|
||||
public boolean valid(Tilec entity){
|
||||
return entity != null && entity.liquids() != null && filter.get(entity.liquids().current()) && entity.liquids().currentAmount() >= use(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@ package mindustry.world.consumers;
|
||||
|
||||
import arc.math.Mathf;
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
@@ -41,16 +41,16 @@ public class ConsumePower extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TileEntity entity){
|
||||
// Nothing to do since PowerGraph directly updates entity.power.status
|
||||
public void update(Tilec entity){
|
||||
// Nothing to do since PowerGraph directly updates entity.power().status
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(TileEntity entity){
|
||||
public boolean valid(Tilec entity){
|
||||
if(buffered){
|
||||
return true;
|
||||
}else{
|
||||
return entity.power.status > 0f;
|
||||
return entity.power().status > 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ public class ConsumePower extends Consume{
|
||||
* @param entity The entity which contains the power module.
|
||||
* @return The amount of power which is requested per tick.
|
||||
*/
|
||||
public float requestedPower(TileEntity entity){
|
||||
if(entity.tile.entity == null) return 0f;
|
||||
public float requestedPower(Tilec entity){
|
||||
if(entity.tile().entity == null) return 0f;
|
||||
if(buffered){
|
||||
return (1f-entity.power.status)*capacity;
|
||||
return (1f-entity.power().status)*capacity;
|
||||
}else{
|
||||
try{
|
||||
return usage * Mathf.num(entity.block.shouldConsume(entity.tile));
|
||||
return usage * Mathf.num(entity.block().shouldConsume(entity.tile()));
|
||||
}catch(Exception e){
|
||||
//HACK an error will only happen with a bar that is checking its requested power, and the entity is null/a different class
|
||||
return 0;
|
||||
|
||||
@@ -4,7 +4,7 @@ import arc.struct.*;
|
||||
import arc.func.Boolf;
|
||||
import arc.util.Structs;
|
||||
import mindustry.Vars;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.blocks.power.ConditionalConsumePower;
|
||||
import mindustry.world.meta.BlockStats;
|
||||
@@ -48,7 +48,7 @@ public class Consumers{
|
||||
}
|
||||
|
||||
/** Creates a consumer which only consumes power when the condition is met. */
|
||||
public ConsumePower powerCond(float usage, Boolf<TileEntity> cons){
|
||||
public ConsumePower powerCond(float usage, Boolf<Tilec> cons){
|
||||
return add(new ConditionalConsumePower(usage, cons));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ package mindustry.world.meta;
|
||||
|
||||
import arc.struct.OrderedMap;
|
||||
import arc.func.Func;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.ui.Bar;
|
||||
|
||||
public class BlockBars{
|
||||
private OrderedMap<String, Func<TileEntity, Bar>> bars = new OrderedMap<>();
|
||||
private OrderedMap<String, Func<Tilec, Bar>> bars = new OrderedMap<>();
|
||||
|
||||
public void add(String name, Func<TileEntity, Bar> sup){
|
||||
public void add(String name, Func<Tilec, Bar> sup){
|
||||
bars.put(name, sup);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class BlockBars{
|
||||
bars.remove(name);
|
||||
}
|
||||
|
||||
public Iterable<Func<TileEntity, Bar>> list(){
|
||||
public Iterable<Func<Tilec, Bar>> list(){
|
||||
return bars.values();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public enum BlockStat{
|
||||
powerConnections(StatCategory.power),
|
||||
basePowerGeneration(StatCategory.power),
|
||||
|
||||
tiles(StatCategory.crafting),
|
||||
input(StatCategory.crafting),
|
||||
output(StatCategory.crafting),
|
||||
productionTime(StatCategory.crafting),
|
||||
@@ -45,7 +46,8 @@ public enum BlockStat{
|
||||
ammo(StatCategory.shooting),
|
||||
|
||||
booster(StatCategory.optional),
|
||||
boostEffect(StatCategory.optional);
|
||||
boostEffect(StatCategory.optional),
|
||||
affinities(StatCategory.optional);
|
||||
|
||||
public final StatCategory category;
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.struct.Array;
|
||||
import arc.struct.ObjectMap.Entry;
|
||||
import arc.struct.OrderedMap;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.struct.ObjectMap.*;
|
||||
import mindustry.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
/** Hold and organizes a list of block stats. */
|
||||
@@ -36,6 +38,13 @@ public class BlockStats{
|
||||
add(stat, new LiquidValue(liquid, amount, perSecond));
|
||||
}
|
||||
|
||||
public void add(BlockStat stat, Attribute attr){
|
||||
for(Block block : Vars.content.blocks()){
|
||||
if(!block.isFloor() || Mathf.zero(block.asFloor().attributes.get(attr))) continue;
|
||||
add(stat, new FloorValue(block.asFloor()));
|
||||
}
|
||||
}
|
||||
|
||||
/** Adds a single string value with this stat. */
|
||||
public void add(BlockStat stat, String format, Object... args){
|
||||
add(stat, new StringValue(format, args));
|
||||
|
||||
@@ -8,7 +8,7 @@ public enum BuildVisibility{
|
||||
shown(() -> true),
|
||||
debugOnly(() -> false),
|
||||
sandboxOnly(() -> Vars.state.rules.infiniteResources),
|
||||
campaignOnly(() -> Vars.world.isZone()),
|
||||
campaignOnly(() -> Vars.state.isCampaign()),
|
||||
lightingOnly(() -> Vars.state.rules.lighting);
|
||||
|
||||
private final Boolp visible;
|
||||
|
||||
21
core/src/mindustry/world/meta/values/FloorValue.java
Normal file
21
core/src/mindustry/world/meta/values/FloorValue.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class FloorValue implements StatValue{
|
||||
private final Floor floor;
|
||||
|
||||
public FloorValue(Floor floor){
|
||||
this.floor = floor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
table.add(new Image(floor.icon(Cicon.small))).padRight(3);
|
||||
table.add(floor.localizedName).padRight(3);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import java.io.*;
|
||||
import arc.util.io.*;
|
||||
|
||||
/** A class that represents compartmentalized tile entity state. */
|
||||
public abstract class BlockModule{
|
||||
public abstract void write(DataOutput stream) throws IOException;
|
||||
|
||||
public abstract void read(DataInput stream) throws IOException;
|
||||
public abstract void write(Writes write);
|
||||
public abstract void read(Reads read);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.consumers.Consume;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ConsumeModule extends BlockModule{
|
||||
private boolean valid, optionalValid;
|
||||
private final TileEntity entity;
|
||||
private final Tilec entity;
|
||||
|
||||
public ConsumeModule(TileEntity entity){
|
||||
public ConsumeModule(Tilec entity){
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
//everything is valid here
|
||||
if(entity.tile.isEnemyCheat()){
|
||||
if(entity.tile().isEnemyCheat()){
|
||||
valid = optionalValid = true;
|
||||
return;
|
||||
}
|
||||
@@ -23,9 +22,9 @@ public class ConsumeModule extends BlockModule{
|
||||
boolean prevValid = valid();
|
||||
valid = true;
|
||||
optionalValid = true;
|
||||
boolean docons = entity.block.shouldConsume(entity.tile) && entity.block.productionValid(entity.tile);
|
||||
boolean docons = entity.block().shouldConsume(entity.tile()) && entity.block().productionValid(entity.tile());
|
||||
|
||||
for(Consume cons : entity.block.consumes.all()){
|
||||
for(Consume cons : entity.block().consumes.all()){
|
||||
if(cons.isOptional()) continue;
|
||||
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
@@ -35,7 +34,7 @@ public class ConsumeModule extends BlockModule{
|
||||
valid &= cons.valid(entity);
|
||||
}
|
||||
|
||||
for(Consume cons : entity.block.consumes.optionals()){
|
||||
for(Consume cons : entity.block().consumes.optionals()){
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
}
|
||||
@@ -45,13 +44,13 @@ public class ConsumeModule extends BlockModule{
|
||||
}
|
||||
|
||||
public void trigger(){
|
||||
for(Consume cons : entity.block.consumes.all()){
|
||||
for(Consume cons : entity.block().consumes.all()){
|
||||
cons.trigger(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean valid(){
|
||||
return valid && entity.block.shouldConsume(entity.tile);
|
||||
return valid && entity.block().shouldConsume(entity.tile());
|
||||
}
|
||||
|
||||
public boolean optionalValid(){
|
||||
@@ -59,12 +58,12 @@ public class ConsumeModule extends BlockModule{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeBoolean(valid);
|
||||
public void write(Writes write){
|
||||
write.bool(valid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
valid = stream.readBoolean();
|
||||
public void read(Reads read){
|
||||
valid = read.bool();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import arc.util.io.*;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.type.ItemStack;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
@@ -12,6 +12,9 @@ public class ItemModule extends BlockModule{
|
||||
private int[] items = new int[content.items().size];
|
||||
private int total;
|
||||
|
||||
// Make the take() loop persistent so it does not return the same item twice in a row unless there is nothing else to return.
|
||||
protected int takeRotation;
|
||||
|
||||
public void forEach(ItemConsumer cons){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
@@ -66,17 +69,29 @@ public class ItemModule extends BlockModule{
|
||||
return total;
|
||||
}
|
||||
|
||||
public Item take(){
|
||||
public Item first(){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
items[i]--;
|
||||
total--;
|
||||
return content.item(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Item take(){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
int index = (i + takeRotation);
|
||||
if(index >= items.length) index -= items.length;
|
||||
if(items[index] > 0){
|
||||
items[index] --;
|
||||
total --;
|
||||
takeRotation = index + 1;
|
||||
return content.item(index);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int get(Item item){
|
||||
return items[item.id];
|
||||
}
|
||||
@@ -115,32 +130,32 @@ public class ItemModule extends BlockModule{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
public void write(Writes write){
|
||||
byte amount = 0;
|
||||
for(int item : items){
|
||||
if(item > 0) amount++;
|
||||
}
|
||||
|
||||
stream.writeByte(amount); //amount of items
|
||||
write.b(amount); //amount of items
|
||||
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(items[i]); //item amount
|
||||
write.b(i); //item ID
|
||||
write.i(items[i]); //item amount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
public void read(Reads read){
|
||||
//just in case, reset items
|
||||
Arrays.fill(items, 0);
|
||||
byte count = stream.readByte();
|
||||
byte count = read.b();
|
||||
total = 0;
|
||||
|
||||
for(int j = 0; j < count; j++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
int itemid = read.b();
|
||||
int itemamount = read.i();
|
||||
items[content.item(itemid).id] = itemamount;
|
||||
total += itemamount;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.type.Liquid;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
@@ -83,30 +83,31 @@ public class LiquidModule extends BlockModule{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
public void write(Writes write){
|
||||
byte amount = 0;
|
||||
for(float liquid : liquids){
|
||||
if(liquid > 0) amount++;
|
||||
}
|
||||
|
||||
stream.writeByte(amount); //amount of liquids
|
||||
write.b(amount); //amount of liquids
|
||||
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
if(liquids[i] > 0){
|
||||
stream.writeByte(i); //liquid ID
|
||||
stream.writeFloat(liquids[i]); //item amount
|
||||
write.b(i); //liquid ID
|
||||
write.f(liquids[i]); //item amount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
public void read(Reads read){
|
||||
Arrays.fill(liquids, 0);
|
||||
byte count = stream.readByte();
|
||||
total = 0f;
|
||||
byte count = read.b();
|
||||
|
||||
for(int j = 0; j < count; j++){
|
||||
int liquidid = stream.readByte();
|
||||
float amount = stream.readFloat();
|
||||
int liquidid = read.b();
|
||||
float amount = read.f();
|
||||
liquids[liquidid] = amount;
|
||||
if(amount > 0){
|
||||
current = content.liquid(liquidid);
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import arc.struct.IntArray;
|
||||
import arc.util.io.*;
|
||||
import mindustry.world.blocks.power.PowerGraph;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PowerModule extends BlockModule{
|
||||
/**
|
||||
* In case of unbuffered consumers, this is the percentage (1.0f = 100%) of the demanded power which can be supplied.
|
||||
@@ -18,22 +15,22 @@ public class PowerModule extends BlockModule{
|
||||
public IntArray links = new IntArray();
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeShort(links.size);
|
||||
public void write(Writes write){
|
||||
write.s(links.size);
|
||||
for(int i = 0; i < links.size; i++){
|
||||
stream.writeInt(links.get(i));
|
||||
write.i(links.get(i));
|
||||
}
|
||||
stream.writeFloat(status);
|
||||
write.f(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
public void read(Reads read){
|
||||
links.clear();
|
||||
short amount = stream.readShort();
|
||||
short amount = read.s();
|
||||
for(int i = 0; i < amount; i++){
|
||||
links.add(stream.readInt());
|
||||
links.add(read.i());
|
||||
}
|
||||
status = stream.readFloat();
|
||||
status = read.f();
|
||||
if(Float.isNaN(status) || Float.isInfinite(status)) status = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user