1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-20 04:47:54 +03:00

PvP defeated team cleanup

This commit is contained in:
Anuken 2021-07-17 08:52:24 -04:00
parent 0980495a28
commit 6973ed7d55
6 changed files with 41 additions and 20 deletions

View File

@ -996,6 +996,7 @@ rules.wavetimer = Wave Timer
rules.waves = Waves
rules.attack = Attack Mode
rules.buildai = AI Building
rules.cleanupdeadteams = Clean Up Defeated Team Buildings (PvP)
rules.corecapture = Capture Core On Destruction
rules.polygoncoreprotection = Polygonal Core Protection
rules.enemyCheat = Infinite AI (Red Team) Resources

View File

@ -129,25 +129,7 @@ public class Logic implements ApplicationListener{
Events.on(SectorCaptureEvent.class, e -> {
if(!net.client() && e.sector == state.getSector() && e.sector.isBeingPlayed()){
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;
Call.setTeam(b, Team.derelict);
Time.run(Mathf.random(0f, 60f * 6f), () -> {
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);
}
});
state.rules.waveTeam.data().destroyToDerelict();
}
});
@ -163,6 +145,12 @@ 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();
}
}));
}
/** Adds starting items, resets wave time, and sets state to playing. */

View File

@ -70,6 +70,8 @@ public class Rules{
public float enemyCoreBuildRadius = 400f;
/** If true, no-build zones are calculated based on the closest core. */
public boolean polygonCoreProtection = false;
/** If true, dead teams in PvP automatically have their blocks & units converted to derelict upon death. */
public boolean cleanupDeadTeams = true;
/** Radius around enemy wave drop zones.*/
public float dropZoneRadius = 300f;
/** Time between waves in ticks. */

View File

@ -1,6 +1,7 @@
package mindustry.game;
import arc.func.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.Queue;
import arc.struct.*;
@ -260,6 +261,34 @@ public class Teams{
this.ai = new BaseAI(this);
}
/** Destroys this team's presence on the map, killing part of its buildings and converting everything to 'derelict'. */
public void destroyToDerelict(){
//grab all buildings from quadtree.
var builds = new Seq<Building>();
if(buildings != null){
buildings.getObjects(builds);
}
//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);
}
}
//kill all units randomly
units.each(u -> Time.run(Mathf.random(0f, 60f * 5f), () -> {
//ensure unit hasn't switched teams for whatever reason
if(u.team == team){
u.kill();
}
}));
}
@Nullable
public Seq<Unit> unitCache(UnitType type){
if(unitsByType == null || unitsByType.length <= type.id || unitsByType[type.id] == null) return null;

View File

@ -142,6 +142,7 @@ public class CustomRulesDialog extends BaseDialog{
check("@rules.reactorexplosions", b -> rules.reactorExplosions = b, () -> rules.reactorExplosions);
check("@rules.schematic", b -> rules.schematicsAllowed = b, () -> rules.schematicsAllowed);
check("@rules.coreincinerates", b -> rules.coreIncinerates = b, () -> rules.coreIncinerates);
check("@rules.cleanupdeadteams", b -> rules.cleanupDeadTeams = b, () -> rules.cleanupDeadTeams, () -> rules.pvp);
number("@rules.buildcostmultiplier", false, f -> rules.buildCostMultiplier = f, () -> rules.buildCostMultiplier, () -> !rules.infiniteResources);
number("@rules.buildspeedmultiplier", f -> rules.buildSpeedMultiplier = f, () -> rules.buildSpeedMultiplier, 0.001f, 50f);
number("@rules.deconstructrefundmultiplier", false, f -> rules.deconstructRefundMultiplier = f, () -> rules.deconstructRefundMultiplier, () -> !rules.infiniteResources);

View File

@ -10,4 +10,4 @@ kapt.include.compile.classpath=false
kotlin.stdlib.default.dependency=false
#needed for android compilation
android.useAndroidX=true
archash=735ab5cb989b89d6978892788e3e0ad089131926
archash=3fe3fc594d041fa0a7e096e50ce1a032ffe3dae0