From 9f95dc6e47e1668f694d4e9b7efef65581ba85a0 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 11 Apr 2022 00:35:24 -0400 Subject: [PATCH] More experimental changes / Better RTS AI --- .../sprites/blocks/logic/canvas.png | Bin 909 -> 914 bytes core/src/mindustry/ai/RtsAI.java | 26 ++++++++++++++++-- core/src/mindustry/content/Planets.java | 2 +- .../mindustry/graphics/OverlayRenderer.java | 3 +- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/core/assets-raw/sprites/blocks/logic/canvas.png b/core/assets-raw/sprites/blocks/logic/canvas.png index 6ccc8badba26283e90f196495d1b61834aa14c4d..b6fddec7033522abc2be5f34ac25192b210a977c 100644 GIT binary patch delta 891 zcmV->1BCpI2a*SnB!5{+L_t(|0qvVhYZFlzhEEMyC|FBlsl`=Mqsc-AFDR*C-3VR~ z#8nr9BE^j&{sHF?=vL8WKJ&clXICl$rSECh}Lf1z7t)!dfiERJ$f{HG;%(*41WwKzh9Q;w)*)CrBW$c zSuLu*zFy^mkITL4#O^rtrPxnBo6&)<_T5CD|2UZVcoqtW%GD^2>#CCyIu#zY05&=$ zf!44Y?fB*eBLGCg#QS$@ZtipD^6Eof?VDLp^V6-Ddz1CdpTo{__(+AQhIIm9=v+;A z2V}Tl;&+!iTYqfrm7e_SYVC*7-909=+w+-!S-fY1U$7ckv8i~*Y+2iO(DAQ)zWFb$f)V>=V3 z!7vSmY0&gwdzOR3(_@v0Q&z#Q;QK7VN>t%ywGwf@E`Jj8B7pFq1+XC!@*qIMgAo8o zh!6Z-GV-wtJRV-ZJhe^$+!!jFC2QXVJlwga29Ng>)6gJ*3ar$!Zts%-!UOqi5(NMf zp1u9T=C&v5-(xZ~EdYEGaIq8w@O^3;TENf2sy+@7>U2^b7}*Pe>F%c<@C4tHMdgInW^BO@EEYH9iRdB#fL) zSr6cEDZVd>E$^@C(O)nvfbihE0P=AV#1sfxfPaJsDhR%H0g!wmL7xt@Ly!vKvj9MX zJ{0DTkS75U1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tsAI.java b/core/src/mindustry/ai/RtsAI.java index 15d779af7a..f8464b6924 100644 --- a/core/src/mindustry/ai/RtsAI.java +++ b/core/src/mindustry/ai/RtsAI.java @@ -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; + } } } diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index baa1847752..af7d055650 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -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; diff --git a/core/src/mindustry/graphics/OverlayRenderer.java b/core/src/mindustry/graphics/OverlayRenderer.java index bd2c16c503..05f597edba 100644 --- a/core/src/mindustry/graphics/OverlayRenderer.java +++ b/core/src/mindustry/graphics/OverlayRenderer.java @@ -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));