This commit is contained in:
Anuken 2024-07-07 20:17:14 -04:00
parent d8dc9c7c98
commit 07738cbac6

View File

@ -47,17 +47,7 @@ public class Logic implements ApplicationListener{
Events.on(BlockBuildEndEvent.class, event -> {
if(!event.breaking){
TeamData data = event.team.data();
Iterator<BlockPlan> it = data.plans.iterator();
var bounds = event.tile.block().bounds(event.tile.x, event.tile.y, Tmp.r1);
while(it.hasNext()){
BlockPlan b = it.next();
Block block = content.block(b.block);
if(bounds.overlaps(block.bounds(b.x, b.y, Tmp.r2))){
b.removed = true;
it.remove();
}
}
checkOverlappingPlans(event.team, event.tile);
if(event.team == state.rules.defaultTeam){
state.stats.placedBlockCount.increment(event.tile.block());
@ -65,6 +55,12 @@ public class Logic implements ApplicationListener{
}
});
Events.on(PayloadDropEvent.class, e -> {
if(e.build != null){
checkOverlappingPlans(e.build.team, e.build.tile);
}
});
//when loading a 'damaged' sector, propagate the damage
Events.on(SaveLoadEvent.class, e -> {
if(state.isCampaign()){
@ -211,6 +207,20 @@ public class Logic implements ApplicationListener{
});
}
private void checkOverlappingPlans(Team team, Tile tile){
TeamData data = team.data();
Iterator<BlockPlan> it = data.plans.iterator();
var bounds = tile.block().bounds(tile.x, tile.y, Tmp.r1);
while(it.hasNext()){
BlockPlan b = it.next();
Block block = content.block(b.block);
if(bounds.overlaps(block.bounds(b.x, b.y, Tmp.r2))){
b.removed = true;
it.remove();
}
}
}
/** Adds starting items, resets wave time, and sets state to playing. */
public void play(){
state.set(State.playing);