From a7ca632c09300db7a6eabf31daa17f675b449814 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 16 Jun 2020 16:04:25 -0400 Subject: [PATCH] AI in custom game attack mode --- core/src/mindustry/ai/BaseAI.java | 18 ++++++++++++++++-- core/src/mindustry/content/UnitTypes.java | 6 +++++- core/src/mindustry/game/Gamemode.java | 4 ++++ gradle.properties | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/ai/BaseAI.java b/core/src/mindustry/ai/BaseAI.java index b99610ba76..06e7720651 100644 --- a/core/src/mindustry/ai/BaseAI.java +++ b/core/src/mindustry/ai/BaseAI.java @@ -10,10 +10,12 @@ import mindustry.content.*; import mindustry.game.*; import mindustry.game.Schematic.*; import mindustry.game.Teams.*; +import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; import mindustry.world.blocks.defense.*; import mindustry.world.blocks.production.*; +import mindustry.world.blocks.storage.*; import static mindustry.Vars.*; @@ -23,6 +25,7 @@ public class BaseAI{ private static final float step = 5; private static final int attempts = 5; private static final float emptyChance = 0.01f; + private final static int timerStep = 0, timerSpawn = 1; private static int correct = 0, incorrect = 0; @@ -30,16 +33,27 @@ public class BaseAI{ private boolean triedWalls; TeamData data; - Interval timer = new Interval(); + Interval timer = new Interval(4); public BaseAI(TeamData data){ this.data = data; } public void update(){ + if(timer.get(timerSpawn, 60) && data.hasCore()){ + CoreBlock block = (CoreBlock)data.core().block; + + //create AI core unit + if(!Groups.unit.contains(u -> u.team() == data.team && u.type() == block.unitType)){ + Unitc unit = block.unitType.create(data.team); + unit.set(data.core()); + unit.add(); + Fx.spawn.at(unit); + } + } //only schedule when there's something to build. - if(data.blocks.isEmpty() && timer.get(step)){ + if(data.blocks.isEmpty() && timer.get(timerStep, step)){ if(!triedWalls){ tryWalls(); triedWalls = true; diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index ada48ba6a5..b0cdd121f4 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -487,6 +487,10 @@ public class UnitTypes implements ContentList{ }}; alpha = new UnitType("alpha"){{ + //TODO maybe these should be changed + defaultController = BuilderAI::new; + isCounted = false; + flying = true; mineSpeed = 2f; buildSpeed = 0.5f; @@ -513,7 +517,7 @@ public class UnitTypes implements ContentList{ lifetime = 60f; shootEffect = Fx.shootSmall; smokeEffect = Fx.shootSmallSmoke; - tileDamageMultiplier = 0.15f; + tileDamageMultiplier = 0.1f; }}; }}); }}; diff --git a/core/src/mindustry/game/Gamemode.java b/core/src/mindustry/game/Gamemode.java index 55bd7e0249..9de5e71052 100644 --- a/core/src/mindustry/game/Gamemode.java +++ b/core/src/mindustry/game/Gamemode.java @@ -21,6 +21,10 @@ public enum Gamemode{ rules.attackMode = true; rules.waves = true; rules.waveTimer = true; + + rules.waveSpacing /= 2f; + rules.teams.get(rules.waveTeam).ai = true; + rules.teams.get(rules.waveTeam).infiniteResources = true; }, map -> map.teams.contains(state.rules.waveTeam.id)), pvp(rules -> { rules.pvp = true; diff --git a/gradle.properties b/gradle.properties index 2d87c6ca4c..14972e4621 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=662afc44313c42b637f9cfd9d21da7f280b27d65 +archash=30796daec8eba235f9cde3723537431df4e4f6f5