RTS core capture derelict-ize

This commit is contained in:
Anuken
2022-03-02 14:08:28 -05:00
parent 76c972acfb
commit 895815b9db
3 changed files with 35 additions and 7 deletions

View File

@@ -152,6 +152,14 @@ public class Logic implements ApplicationListener{
}
});
Events.on(BlockDestroyEvent.class, e -> {
//TODO maybe make it a separate rule?
//makes cores go derelict in RTS mode, helps clean things up
if(e.tile.build instanceof CoreBuild core && core.team.isAI() && core.team.rules().rtsAi){
core.team.data().makeDerelict(core.x, core.y, state.rules.enemyCoreBuildRadius);
}
});
//send out items to each client
Events.on(TurnEvent.class, e -> {
if(net.server() && state.isCampaign()){
@@ -167,7 +175,9 @@ public class Logic implements ApplicationListener{
//listen to core changes; if all cores have been destroyed, set to derelict.
Events.on(CoreChangeEvent.class, e -> Core.app.post(() -> {
if(state.rules.cleanupDeadTeams && state.rules.pvp && !e.core.isAdded() && e.core.team != Team.derelict && e.core.team.cores().isEmpty()){
e.core.team.data().destroyToDerelict();
Core.app.post(() -> {
e.core.team.data().destroyToDerelict();
});
}
}));
}

View File

@@ -272,12 +272,7 @@ public class Teams{
//convert all team tiles to neutral, randomly killing them
for(var b : builds){
//TODO this may cause a lot of packet spam, optimize?
Call.setTeam(b, Team.derelict);
if(Mathf.chance(0.25)){
Time.run(Mathf.random(0f, 60f * 6f), b::kill);
}
scheduleDerelict(b);
}
//kill all units randomly
@@ -289,6 +284,29 @@ public class Teams{
}));
}
/** Make all buildings within this range derelict / explode. */
public void makeDerelict(float x, float y, float range){
var builds = new Seq<Building>();
if(buildings != null){
buildings.intersect(x - range, y - range, range * 2f, range * 2f, builds);
}
for(var build : builds){
if(build.within(x, y, range)){
scheduleDerelict(build);
}
}
}
private void scheduleDerelict(Building build){
//TODO this may cause a lot of packet spam, optimize?
Call.setTeam(build, Team.derelict);
if(Mathf.chance(0.25)){
Time.run(Mathf.random(0f, 60f * 6f), build::kill);
}
}
@Nullable
public Seq<Unit> unitCache(UnitType type){
if(unitsByType == null || unitsByType.length <= type.id || unitsByType[type.id] == null) return null;