Upgradeable cores

This commit is contained in:
Anuken
2020-06-27 19:16:39 -04:00
parent 313cadb763
commit 80332e37d5
63 changed files with 365 additions and 290 deletions

View File

@@ -59,13 +59,13 @@ public class BuildBlock extends Block{
@Remote(called = Loc.server)
public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team, boolean skipConfig){
if(tile == null) return;
float healthf = tile.entity.healthf();
float healthf = tile.build.healthf();
tile.setBlock(block, team, rotation);
tile.entity.health(block.health * healthf);
tile.build.health(block.health * healthf);
//last builder was this local client player, call placed()
if(!headless && builderID == player.unit().id()){
if(!skipConfig){
tile.entity.playerPlaced();
tile.build.playerPlaced();
}
}
Fx.placeBlock.at(tile.drawx(), tile.drawy(), block.size);
@@ -97,7 +97,7 @@ public class BuildBlock extends Block{
public static void constructed(Tile tile, Block block, int builderID, byte rotation, Team team, boolean skipConfig){
Call.onConstructFinish(tile, block, builderID, rotation, team, skipConfig);
tile.entity.placed();
tile.build.placed();
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, false));
if(shouldPlay()) Sounds.place.at(tile, calcPitch(true));

View File

@@ -39,7 +39,7 @@ public class Wall extends Block{
@Override
public boolean canReplace(Block other){
return super.canReplace(other) && health > other.health;
return super.canReplace(other) && health > other.health && size == other.size;
}
public class WallEntity extends Building{

View File

@@ -101,7 +101,7 @@ public class LaserTurret extends PowerTurret{
@Override
protected void bullet(BulletType type, float angle){
bullet = type.create(tile.entity, team, x + tr.x, y + tr.y, angle);
bullet = type.create(tile.build, team, x + tr.x, y + tr.y, angle);
bulletLife = shootDuration;
}

View File

@@ -93,7 +93,7 @@ public class LiquidTurret extends Turret{
shootSound.at(tile);
if(shootShake > 0){
Effects.shake(shootShake, shootShake, tile.entity);
Effects.shake(shootShake, shootShake, tile.build);
}
recoil = recoilAmount;

View File

@@ -112,7 +112,7 @@ public class ItemBridge extends Block{
return false;
}
return (other.block() == tile.block() || (!(tile.block() instanceof ItemBridge) && other.block() == this)) && (other.team() == tile.team() || tile.block() != this) && (!checkDouble || other.<ItemBridgeEntity>ent().link != tile.pos());
return (other.block() == tile.block() || (!(tile.block() instanceof ItemBridge) && other.block() == this)) && (other.team() == tile.team() || tile.block() != this) && (!checkDouble || other.<ItemBridgeEntity>bc().link != tile.pos());
}
public Tile findLink(int x, int y){
@@ -134,7 +134,7 @@ public class ItemBridge extends Block{
public void playerPlaced(){
Tile link = findLink(tile.x, tile.y);
if(linkValid(tile, link)){
link.entity.configure(tile.pos());
link.build.configure(tile.pos());
}
lastPlaced = tile.pos();
@@ -154,7 +154,7 @@ public class ItemBridge extends Block{
private void drawInput(Tile other){
if(!linkValid(tile, other, false)) return;
boolean linked = other.pos() == link;
if(!linked && !(other.<ItemBridgeEntity>ent().link == tile.pos())) return;
if(!linked && !(other.<ItemBridgeEntity>bc().link == tile.pos())) return;
Tmp.v2.trns(tile.angleTo(other), 2f);
float tx = tile.drawx(), ty = tile.drawy();
@@ -227,7 +227,7 @@ public class ItemBridge extends Block{
while(it.hasNext){
int i = it.next();
Tile other = world.tile(i);
if(!linkValid(tile, other, false) || other.<ItemBridgeEntity>ent().link != tile.pos()){
if(!linkValid(tile, other, false) || other.<ItemBridgeEntity>bc().link != tile.pos()){
it.remove();
}
}
@@ -245,7 +245,7 @@ public class ItemBridge extends Block{
dump();
uptime = 0f;
}else{
((ItemBridgeEntity)other.entity).incoming.add(tile.pos());
((ItemBridgeEntity)other.build).incoming.add(tile.pos());
if(consValid() && Mathf.zero(1f - efficiency())){
uptime = Mathf.lerpDelta(uptime, 1f, 0.04f);
@@ -253,7 +253,7 @@ public class ItemBridge extends Block{
uptime = Mathf.lerpDelta(uptime, 0f, 0.02f);
}
updateTransport(other.entity);
updateTransport(other.build);
}
}

View File

@@ -290,7 +290,7 @@ public class MassDriver extends Block{
protected boolean shooterValid(Tile other){
if(other == null) return true;
if(!(other.block() instanceof MassDriver)) return false;
MassDriverEntity entity = other.ent();
MassDriverEntity entity = other.bc();
return entity.link == tile.pos() && tile.dst(other) <= range;
}

View File

@@ -44,7 +44,7 @@ public class Sorter extends Block{
@Override
public int minimapColor(Tile tile){
return tile.<SorterEntity>ent().sortItem == null ? 0 : tile.<SorterEntity>ent().sortItem.color.rgba();
return tile.<SorterEntity>bc().sortItem == null ? 0 : tile.<SorterEntity>bc().sortItem.color.rgba();
}
public class SorterEntity extends Building{

View File

@@ -52,8 +52,8 @@ public class StackConveyor extends Block implements Autotiler{
@Override
public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
if(tile.entity instanceof StackConveyorEntity){
int state = ((StackConveyorEntity)tile.entity).state;
if(tile.build instanceof StackConveyorEntity){
int state = ((StackConveyorEntity)tile.build).state;
if(state == stateLoad){ //standard conveyor mode
return otherblock.outputsItems() && lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock);
}else if(state == stateUnload){ //router mode

View File

@@ -178,8 +178,8 @@ public class PowerNode extends PowerBlock{
tempTileEnts.clear();
graphs.clear();
if(tile.entity != null && tile.entity.power != null){
graphs.add(tile.entity.power.graph);
if(tile.build != null && tile.build.power != null){
graphs.add(tile.build.power.graph);
}
Geometry.circle(tile.x, tile.y, (int)(laserRange + 2), (x, y) -> {

View File

@@ -10,6 +10,7 @@ import arc.util.ArcAnnotate.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.game.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -52,7 +53,7 @@ public class CoreBlock extends StorageBlock{
public static void onPlayerSpawn(Tile tile, Player player){
if(player == null || tile == null) return;
CoreEntity entity = tile.ent();
CoreEntity entity = tile.bc();
CoreBlock block = (CoreBlock)tile.block();
Fx.spawn.at(entity);
@@ -91,6 +92,27 @@ public class CoreBlock extends StorageBlock{
return false;
}
@Override
public boolean canReplace(Block other){
//coreblocks can upgrade smaller cores
return super.canReplace(other) || (other instanceof CoreBlock && size > other.size);
}
@Override
public boolean canPlaceOn(Tile tile, Team team){
return canReplace(tile.block());
}
@Override
public void placeBegan(Tile tile, Block previous){
//finish placement immediately when a block is replaced.
if(previous instanceof CoreBlock){
tile.setBlock(this, tile.team());
Fx.placeBlock.at(tile, tile.block().size);
Fx.upgradeCore.at(tile, tile.block().size);
}
}
public class CoreEntity extends Building implements ControlBlock{
public int storageCapacity;
//note that this unit is never actually used for control; the possession handler makes the player respawn when this unit is controlled

View File

@@ -82,7 +82,7 @@ public class Unloader extends Block{
@Override
public void buildConfiguration(Table table){
ItemSelection.buildTable(table, content.items(), () -> tile.<UnloaderEntity>ent().sortItem, item -> configure(item));
ItemSelection.buildTable(table, content.items(), () -> tile.<UnloaderEntity>bc().sortItem, item -> configure(item));
}
@Override

View File

@@ -26,8 +26,8 @@ public class UnitBlock extends PayloadAcceptor{
@Remote(called = Loc.server)
public static void onUnitBlockSpawn(Tile tile){
if(!(tile.entity instanceof UnitBlockEntity)) return;
tile.<UnitBlockEntity>ent().spawned();
if(!(tile.build instanceof UnitBlockEntity)) return;
tile.<UnitBlockEntity>bc().spawned();
}
public class UnitBlockEntity extends PayloadAcceptorEntity<UnitPayload>{