diff --git a/core/src/mindustry/ai/BlockIndexer.java b/core/src/mindustry/ai/BlockIndexer.java index 8ede0315f1..683d04cc78 100644 --- a/core/src/mindustry/ai/BlockIndexer.java +++ b/core/src/mindustry/ai/BlockIndexer.java @@ -56,18 +56,7 @@ public class BlockIndexer{ public BlockIndexer(){ Events.on(TileChangeEvent.class, event -> { - if(typeMap.get(event.tile.pos()) != null){ - TileIndex index = typeMap.get(event.tile.pos()); - for(BlockFlag flag : index.flags){ - getFlagged(index.team)[flag.ordinal()].remove(event.tile); - } - - if(index.flags.contains(BlockFlag.unitModifier)){ - updateCap(index.team); - } - } - process(event.tile); - updateQuadrant(event.tile); + updateIndices(event.tile); }); Events.on(WorldLoadEvent.class, event -> { @@ -111,6 +100,21 @@ public class BlockIndexer{ }); } + public void updateIndices(Tile tile){ + if(typeMap.get(tile.pos()) != null){ + TileIndex index = typeMap.get(tile.pos()); + for(BlockFlag flag : index.flags){ + getFlagged(index.team)[flag.ordinal()].remove(tile); + } + + if(index.flags.contains(BlockFlag.unitModifier)){ + updateCap(index.team); + } + } + process(tile); + updateQuadrant(tile); + } + private TileArray[] getFlagged(Team team){ return flagMap[team.id]; } diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 4a5d7175af..82d9cb8574 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -121,6 +121,30 @@ public class Logic implements ApplicationListener{ } }); + Events.on(SectorCaptureEvent.class, e -> { + if(!net.client()){ + for(Tile tile : world.tiles){ + //convert all blocks to neutral, randomly killing them + if(tile.isCenter() && tile.build != null && tile.build.team == state.rules.waveTeam){ + Building b = tile.build; + Time.run(Mathf.random(0f, 60f * 6f), () -> { + Call.setTeam(b, Team.derelict); + if(Mathf.chance(0.25)){ + b.kill(); + } + }); + } + } + + //kill all units + Groups.unit.each(u -> { + if(u.team == state.rules.waveTeam){ + Time.run(Mathf.random(0f, 60f * 5f), u::kill); + } + }); + } + }); + } /** Adds starting items, resets wave time, and sets state to playing. */ diff --git a/core/src/mindustry/entities/units/AIController.java b/core/src/mindustry/entities/units/AIController.java index 1707df15f5..c572aa368f 100644 --- a/core/src/mindustry/entities/units/AIController.java +++ b/core/src/mindustry/entities/units/AIController.java @@ -15,9 +15,7 @@ import static mindustry.Vars.*; public class AIController implements UnitController{ protected static final Vec2 vec = new Vec2(); - protected static final int timerTarget = 0; - protected static final int timerTarget2 = 1; - protected static final int timerTarget3 = 2; + protected static final int timerTarget = 0, timerTarget2 = 1, timerTarget3 = 2; protected Unit unit; protected Interval timer = new Interval(4); diff --git a/core/src/mindustry/type/Sector.java b/core/src/mindustry/type/Sector.java index 918a2f3a7a..6240ac2ffa 100644 --- a/core/src/mindustry/type/Sector.java +++ b/core/src/mindustry/type/Sector.java @@ -103,7 +103,7 @@ public class Sector{ /** @return whether the enemy has a generated base here. */ public boolean hasEnemyBase(){ - return generateEnemyBase && (save == null || info.waves); + return generateEnemyBase && (save == null || info.attack); } public boolean isBeingPlayed(){ diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index 02c482187b..e8a27b7c05 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -602,6 +602,14 @@ public class Tile implements Position, QuadTreeObject, Displayable{ tile.setBlock(block, team, rotation); } + @Remote(called = Loc.server) + public static void setTeam(Building build, Team team){ + if(build != null){ + build.team = team; + indexer.updateIndices(build.tile); + } + } + @Remote(called = Loc.server, unreliable = true) public static void tileDamage(Building build, float health){ if(build == null) return;