More experimental changes / Better RTS AI

This commit is contained in:
Anuken 2022-04-11 00:35:24 -04:00
parent 0d66c7dec7
commit 9f95dc6e47
4 changed files with 27 additions and 4 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 909 B

After

Width:  |  Height:  |  Size: 914 B

View File

@ -13,6 +13,7 @@ import mindustry.game.EventType.*;
import mindustry.game.Teams.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.defense.turrets.Turret.*;
@ -170,7 +171,8 @@ public class RtsAI{
});
//defend when close, or this is the only squad defending
if(best instanceof CoreBuild || (units.size >= minSquadSize && (noDefenders || best.within(ax, ay, 400f)))){
//TODO will always rush to defense no matter what
if(best instanceof CoreBuild || (/*(units.size >= minSquadSize || best.within(ax, ay, 300f)) && */(noDefenders || best.within(ax, ay, 400f)))){
defend = best;
if(debug){
@ -183,8 +185,10 @@ public class RtsAI{
Vec2 defendPos = null;
Teamc defendTarget = null;
if(defend != null){
float checkRange = 260f;
//TODO could be made faster by storing bullet shooter
Unit aggressor = Units.closestEnemy(data.team, defend.x, defend.y, 250f, u -> true);
Unit aggressor = Units.closestEnemy(data.team, defend.x, defend.y, checkRange, u -> true);
if(aggressor != null){
defendTarget = aggressor;
}else if(false){ //TODO currently ignored, no use defending against nothing
@ -193,6 +197,24 @@ public class RtsAI{
if(closest != null){
defendPos = new Vec2(closest.worldx(), closest.worldy());
}
}else{
float mindst = Float.MAX_VALUE;
Building build = null;
//find closest turret to attack.
for(var turret : Vars.indexer.getEnemy(data.team, BlockFlag.turret)){
if(turret.within(defend, ((Ranged)turret).range())){
float dst = turret.dst2(defend);
if(dst < mindst){
mindst = dst;
build = turret;
}
}
}
if(build != null){
defendTarget = build;
}
}
}

View File

@ -68,7 +68,7 @@ public class Planets{
updateLighting = false;
ruleSetter = r -> {
r.placeRangeCheck = true;
r.placeRangeCheck = false; //TODO true or false?
r.attributes.set(Attribute.heat, 0.8f);
r.showSpawns = true;
r.fog = true;

View File

@ -175,7 +175,8 @@ public class OverlayRenderer{
Draw.color();
}else{
state.teams.eachEnemyCore(player.team(), core -> {
if(core.wasVisible && Core.camera.bounds(Tmp.r1).overlaps(Tmp.r2.setCentered(core.x, core.y, state.rules.enemyCoreBuildRadius * 2f))){
//it must be clear that there is a core here.
if(/*core.wasVisible && */Core.camera.bounds(Tmp.r1).overlaps(Tmp.r2.setCentered(core.x, core.y, state.rules.enemyCoreBuildRadius * 2f))){
Draw.color(Color.darkGray);
Lines.circle(core.x, core.y - 2, state.rules.enemyCoreBuildRadius);
Draw.color(Pal.accent, core.team.color, 0.5f + Mathf.absin(Time.time, 10f, 0.5f));