From c8b11c44475f818d1b5e2b79b1f4f6524d293d55 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 13 Feb 2022 20:54:25 -0500 Subject: [PATCH] Fixed erekir unit requirements --- core/src/mindustry/content/Planets.java | 4 ++++ core/src/mindustry/core/Logic.java | 2 ++ core/src/mindustry/core/World.java | 1 + core/src/mindustry/game/Rules.java | 2 ++ core/src/mindustry/graphics/Drawf.java | 4 ++++ core/src/mindustry/input/DesktopInput.java | 14 ++++++++++++++ .../maps/planet/ErekirPlanetGenerator.java | 1 + core/src/mindustry/type/Planet.java | 3 +++ core/src/mindustry/world/Block.java | 2 ++ core/src/mindustry/world/Build.java | 10 +++++++++- .../world/blocks/defense/turrets/BaseTurret.java | 1 + 11 files changed, 43 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index 6cbdcf77bc..c3c2f7c25c 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -61,6 +61,10 @@ public class Planets{ lightSrcTo = 0.5f; lightDstFrom = 0.2f; hiddenItems.addAll(Items.serpuloItems).removeAll(Items.erekirItems); + ruleSetter = r -> { + r.unitCommand = true; + r.placeRangeCheck = true; + }; unlockedOnLand.add(Blocks.coreBastion); }}; diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 0ee8638afc..ec9d81c375 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -89,6 +89,8 @@ public class Logic implements ApplicationListener{ } } + state.getSector().planet.ruleSetter.get(state.rules); + //reset values info.damage = 0f; info.wavesPassed = 0; diff --git a/core/src/mindustry/core/World.java b/core/src/mindustry/core/World.java index 5a56472ba6..1ca1bcd1d3 100644 --- a/core/src/mindustry/core/World.java +++ b/core/src/mindustry/core/World.java @@ -311,6 +311,7 @@ public class World{ state.rules.environment = sector.planet.defaultEnv; state.rules.hiddenBuildItems.clear(); state.rules.hiddenBuildItems.addAll(sector.planet.hiddenItems); + sector.planet.ruleSetter.get(state.rules); sector.info.resources = content.toSeq(); sector.info.resources.sort(Structs.comps(Structs.comparing(Content::getContentType), Structs.comparingInt(c -> c.id))); sector.saveInfo(); diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index 960757da3c..6e5e73422d 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -77,6 +77,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, blocks cannot be placed near blocks that are near the enemy team.*/ + public boolean placeRangeCheck = 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.*/ diff --git a/core/src/mindustry/graphics/Drawf.java b/core/src/mindustry/graphics/Drawf.java index 499992dec0..3bb9a345aa 100644 --- a/core/src/mindustry/graphics/Drawf.java +++ b/core/src/mindustry/graphics/Drawf.java @@ -118,6 +118,10 @@ public class Drawf{ Draw.z(pz); } + public static void dashLineDst(Color color, float x, float y, float x2, float y2){ + dashLine(color, x, y, x2, y2, (int)(Mathf.dst(x, y, x2, y2) / tilesize * 2)); + } + public static void dashLine(Color color, float x, float y, float x2, float y2){ dashLine(color, x, y, x2, y2, (int)(Math.max(Math.abs(x - x2), Math.abs(y - y2)) / tilesize * 2)); } diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 08f9d60dba..2c5942a30a 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -230,6 +230,20 @@ public class DesktopInput extends InputHandler{ brequest.config = null; Draw.reset(); } + + if(!valid && state.rules.placeRangeCheck){ + var blocker = Build.getEnemyOverlap(block, player.team(), cursorX, cursorY); + if(blocker != null){ + Drawf.selected(blocker, blocker.team.color); + Tmp.v1.set(cursorX, cursorY).scl(tilesize).add(block.offset, block.offset).sub(blocker).scl(-1f).nor(); + Drawf.dashLineDst(Pal.remove, + cursorX * tilesize + block.offset + Tmp.v1.x * block.size * tilesize/2f, + cursorY * tilesize + block.offset + Tmp.v1.y * block.size * tilesize/2f, + blocker.x + Tmp.v1.x * -blocker.block.size * tilesize/2f, + blocker.y + Tmp.v1.y * -blocker.block.size * tilesize/2f + ); + } + } } } diff --git a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java index 76d188ac1f..cf65b029b3 100644 --- a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java @@ -445,6 +445,7 @@ public class ErekirPlanetGenerator extends PlanetGenerator{ state.rules.attributes.set(Attribute.heat, 0.8f); state.rules.environment = sector.planet.defaultEnv; state.rules.unitCommand = true; + state.rules.placeRangeCheck = true; //TODO remove slag and arkycite around core. Schematics.placeLaunchLoadout(spawnX, spawnY); diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index bcaa41442c..5e5839017d 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -11,6 +11,7 @@ import arc.util.*; import arc.util.noise.*; import mindustry.content.TechTree.*; import mindustry.ctype.*; +import mindustry.game.*; import mindustry.graphics.*; import mindustry.graphics.g3d.*; import mindustry.graphics.g3d.PlanetGrid.*; @@ -92,6 +93,8 @@ public class Planet extends UnlockableContent{ public boolean allowSectorInvasion = false; /** If true, builder AI is turned on for all sectors on this planet by default. */ public boolean defaultAI = false; + /** Sets up rules on game load for any sector on this planet. */ + public Cons ruleSetter = r -> {}; /** Parent body that this planet orbits around. If null, this planet is considered to be in the middle of the solar system.*/ public @Nullable Planet parent; /** The root parent of the whole solar system this planet is in. */ diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 0418c3b97c..c9b96d4698 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -159,6 +159,8 @@ public class Block extends UnlockableContent implements Senseable{ public boolean expanded = false; /** Clipping size of this block. Should be as large as the block will draw. */ public float clipSize = -1f; + /** When placeRangeCheck is enabled, this is the range checked for enemy blocks. */ + public float placeOverlapRange = 30f; /** Max of timers used. */ public int timers = 0; /** Cache layer. Only used for 'cached' rendering. */ diff --git a/core/src/mindustry/world/Build.java b/core/src/mindustry/world/Build.java index 88482114f5..ed5c514689 100644 --- a/core/src/mindustry/world/Build.java +++ b/core/src/mindustry/world/Build.java @@ -94,7 +94,7 @@ public class Build{ Block previous = tile.block(); Block sub = ConstructBlock.get(result.size); - Seq prevBuild = new Seq<>(9); + var prevBuild = new Seq(9); result.beforePlaceBegan(tile, previous); tmp.clear(); @@ -201,9 +201,17 @@ public class Build{ } } + if(state.rules.placeRangeCheck && getEnemyOverlap(type, team, x, y) != null){ + return false; + } + return true; } + public static @Nullable Building getEnemyOverlap(Block block, Team team, int x, int y){ + return indexer.findEnemyTile(team, x * tilesize + block.size, y * tilesize + block.size, block.placeOverlapRange + 4f, p -> true); + } + public static boolean contactsGround(int x, int y, Block block){ if(block.isMultiblock()){ for(Point2 point : Edges.getEdges(block.size)){ diff --git a/core/src/mindustry/world/blocks/defense/turrets/BaseTurret.java b/core/src/mindustry/world/blocks/defense/turrets/BaseTurret.java index da83bd4ae6..a4bffba45b 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/BaseTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/BaseTurret.java @@ -45,6 +45,7 @@ public class BaseTurret extends Block{ consumes.add(coolantOverride != null ? new ConsumeLiquid(coolantOverride, coolantUsage) : new ConsumeCoolant(coolantUsage)).update(false).boost(); } + placeOverlapRange = Math.max(placeOverlapRange, range); super.init(); }