Shield breaker block

This commit is contained in:
Anuken
2022-04-21 14:34:01 -04:00
parent bfdf07d0eb
commit 09221f952a
6 changed files with 47 additions and 3 deletions

View File

@@ -114,7 +114,8 @@ public class BlockIndexer{
}
//no longer part of the building list
data.buildings.remove(tile.build);
data.buildings.remove(build);
data.buildingTypes.get(build.block, () -> new Seq<>(false)).remove(build);
//update the unit cap when building is removed
data.unitCap -= tile.block().unitCapModifier;
@@ -449,6 +450,7 @@ public class BlockIndexer{
//record in list of buildings
data.buildings.add(tile.build);
data.buildingTypes.get(tile.block(), () -> new Seq<>(false)).add(tile.build);
//update the unit cap when new tile is registered
data.unitCap += tile.block().unitCapModifier;

View File

@@ -91,6 +91,7 @@ public class Blocks{
//campaign only
shieldProjector,
largeShieldProjector,
shieldBreaker,
//transport
conveyor, titaniumConveyor, plastaniumConveyor, armoredConveyor, distributor, junction, itemBridge, phaseConveyor, sorter, invertedSorter, router,
@@ -1781,6 +1782,14 @@ public class Blocks{
consumePower(5f);
}};
shieldBreaker = new BaseShield("shield-breaker"){{
requirements(Category.effect, BuildVisibility.editorOnly, with());
size = 5;
consumeItem(Items.tungsten, 100);
}};
//endregion
//region distribution

View File

@@ -10,6 +10,7 @@ import mindustry.*;
import mindustry.ai.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.payloads.*;
import mindustry.world.blocks.storage.CoreBlock.*;
@@ -260,6 +261,8 @@ public class Teams{
public int unitCount;
/** Counts for each type of unit. Do not access directly. */
public @Nullable int[] typeCounts;
/** Cached buildings by type. */
public ObjectMap<Block, Seq<Building>> buildingTypes = new ObjectMap<>();
/** Units of this team. Updated each frame. */
public Seq<Unit> units = new Seq<>(false);
/** Same as units, but players. */
@@ -273,6 +276,10 @@ public class Teams{
this.team = team;
}
public Seq<Building> getBuildings(Block block){
return buildingTypes.get(block, () -> new Seq<>(false));
}
/** Destroys this team's presence on the map, killing part of its buildings and converting everything to 'derelict'. */
public void destroyToDerelict(){

View File

@@ -1,9 +1,16 @@
package mindustry.world.blocks.defense;
import arc.math.*;
import arc.util.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.world.*;
public class ShieldBreaker extends Block{
public @Nullable Block toDestroy;
public Effect effect = Fx.shockwave, breakEffect = Fx.reactorExplosion, selfKillEffect = Fx.massiveExplosion;
public ShieldBreaker(String name){
super(name);
@@ -11,11 +18,30 @@ public class ShieldBreaker extends Block{
solid = update = true;
}
@Override
public boolean canBreak(Tile tile){
return false;
}
public class ShieldBreakerBuild extends Building{
@Override
public void updateTile(){
if(Mathf.equal(efficiency, 1f)){
if(toDestroy != null){
effect.at(this);
for(var other : Vars.state.teams.active){
if(team != other.team){
other.getBuildings(toDestroy).copy().each(b -> {
breakEffect.at(b);
b.kill();
});
}
}
selfKillEffect.at(this);
kill();
}
}
}
}
}