From 31ebb1d1569142e0ebf71b56959a954eb9dfdc6b Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 10 Jun 2021 20:46:10 -0400 Subject: [PATCH] Planet progress --- core/src/mindustry/content/Planets.java | 26 +++++++++++ core/src/mindustry/game/Universe.java | 2 +- .../maps/generators/BlankPlanetGenerator.java | 43 +++++++++++++++++++ .../maps/generators/PlanetGenerator.java | 5 +++ core/src/mindustry/type/Planet.java | 9 ++-- core/src/mindustry/type/Sector.java | 4 +- core/src/mindustry/type/UnitType.java | 4 ++ .../mindustry/ui/dialogs/PlanetDialog.java | 25 ++++++++--- 8 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 core/src/mindustry/maps/generators/BlankPlanetGenerator.java diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index 524c1c1980..80e2003819 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -4,11 +4,16 @@ import arc.graphics.*; import arc.math.geom.*; import arc.util.noise.*; import mindustry.ctype.*; +import mindustry.game.*; import mindustry.graphics.*; import mindustry.graphics.g3d.*; import mindustry.graphics.g3d.PlanetGrid.*; +import mindustry.maps.generators.*; import mindustry.maps.planet.*; import mindustry.type.*; +import mindustry.world.meta.*; + +import static mindustry.Vars.*; public class Planets implements ContentList{ public static Planet @@ -51,14 +56,35 @@ public class Planets implements ContentList{ for(int i = 0; i < 4; i++){ new Planet("gier-" + i, erekir, 0.1f){{ hasAtmosphere = false; + //for testing only! alwaysUnlocked = true; + updateLighting = false; sectors.add(new Sector(this, Ptile.empty)); camRadius = 0.43f; + orbitOffset = 0f; //new SectorPreset(name + "-sector", this, 0){{ //}}; + generator = new BlankPlanetGenerator(){ + @Override + public void generate(){ + pass((x, y) -> { + floor = Blocks.space; + }); + + Schematics.placeLaunchLoadout(width/2, height/2); + + state.rules.environment = Env.space; + } + + @Override + public int getSectorSize(Sector sector){ + return 300; + } + }; + meshLoader = () -> new HexMesh(this, new HexMesher(){ Simplex sim = new Simplex(id); @Override diff --git a/core/src/mindustry/game/Universe.java b/core/src/mindustry/game/Universe.java index a9215f70d0..6a90d892fe 100644 --- a/core/src/mindustry/game/Universe.java +++ b/core/src/mindustry/game/Universe.java @@ -82,7 +82,7 @@ public class Universe{ } } - if(state.hasSector()){ + if(state.hasSector() && state.getSector().planet.updateLighting){ //update sector light float light = state.getSector().getLight(); float alpha = Mathf.clamp(Mathf.map(light, 0f, 0.8f, 0.3f, 1f)); diff --git a/core/src/mindustry/maps/generators/BlankPlanetGenerator.java b/core/src/mindustry/maps/generators/BlankPlanetGenerator.java new file mode 100644 index 0000000000..6e46fa95d0 --- /dev/null +++ b/core/src/mindustry/maps/generators/BlankPlanetGenerator.java @@ -0,0 +1,43 @@ +package mindustry.maps.generators; + +import arc.graphics.*; +import arc.math.geom.*; +import mindustry.game.*; +import mindustry.type.*; +import mindustry.world.*; + +/** A planet generator that provides no weather, height, color or bases. Override generate().*/ +public class BlankPlanetGenerator extends PlanetGenerator{ + + @Override + public float getHeight(Vec3 position){ + return 0; + } + + @Override + public Color getColor(Vec3 position){ + return Color.white; + } + + @Override + public void generateSector(Sector sector){ + + } + + @Override + public void addWeather(Sector sector, Rules rules){ + + } + + @Override + public void generate(Tiles tiles, Sector sec){ + this.tiles = tiles; + this.sector = sec; + this.rand.setSeed(sec.id); + + tiles.fill(); + + generate(tiles); + } + +} diff --git a/core/src/mindustry/maps/generators/PlanetGenerator.java b/core/src/mindustry/maps/generators/PlanetGenerator.java index 830be018fb..521e5aa08e 100644 --- a/core/src/mindustry/maps/generators/PlanetGenerator.java +++ b/core/src/mindustry/maps/generators/PlanetGenerator.java @@ -124,6 +124,11 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe return 3200; } + public int getSectorSize(Sector sector){ + int res = (int)(sector.rect.radius * getSizeScl()); + return res % 2 == 0 ? res : res + 1; + } + public void generate(Tiles tiles, Sector sec){ this.tiles = tiles; this.sector = sec; diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index 37ec2caa50..c044198113 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -45,12 +45,16 @@ public class Planet extends UnlockableContent{ public float orbitTime; /** Time for the planet to perform a full revolution, in seconds. One day. */ public float rotateTime = 24f * 60f; + /** Random orbit angle offset to prevent planets from starting out in a line. */ + public float orbitOffset; /** Approx. radius of one sector. */ public float sectorApproxRadius; /** Whether this planet is tidally locked relative to its parent - see https://en.wikipedia.org/wiki/Tidal_locking */ public boolean tidalLock = false; /** Whether or not this planet is listed in the planet access UI. **/ public boolean accessible = true; + /** If true, a day/night cycle is simulated. */ + public boolean updateLighting = true; /** The default starting sector displayed to the map dialog. */ public int startSector = 0; /** Whether the bloom render effect is enabled. */ @@ -79,6 +83,7 @@ public class Planet extends UnlockableContent{ this.radius = radius; this.parent = parent; + this.orbitOffset = Mathf.randomSeed(id, 360); //total radius is initially just the radius totalRadius = radius; @@ -153,9 +158,7 @@ public class Planet extends UnlockableContent{ /** Calculates orbital rotation based on universe time.*/ public float getOrbitAngle(){ - //applies random offset to prevent planets from starting out in a line - float offset = Mathf.randomSeed(id, 360); - return (offset + universe.secondsf() / (orbitTime / 360f)) % 360f; + return (orbitOffset + universe.secondsf() / (orbitTime / 360f)) % 360f; } /** Calulates rotation on own axis based on universe time.*/ diff --git a/core/src/mindustry/type/Sector.java b/core/src/mindustry/type/Sector.java index a7cc5851c7..344d33dffc 100644 --- a/core/src/mindustry/type/Sector.java +++ b/core/src/mindustry/type/Sector.java @@ -153,9 +153,7 @@ public class Sector{ /** @return the sector size, in tiles */ public int getSize(){ - if(planet.generator == null) return 1; - int res = (int)(rect.radius * planet.generator.getSizeScl()); - return res % 2 == 0 ? res : res + 1; + return planet.generator == null ? 1 : planet.generator.getSectorSize(this); } public void removeItems(ItemSeq items){ diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 0bc82be792..f1f0585ff1 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -307,6 +307,10 @@ public class UnitType extends UnlockableContent{ immunities.add(StatusEffects.wet); } + if(flying){ + envEnabled |= Env.space; + } + if(lightRadius == -1){ lightRadius = Math.max(60f, hitSize * 2.3f); } diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index 06e142f233..0229a4d7a4 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -599,9 +599,16 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ if(planets.planet.hasGrid()){ hovered = planets.planet.getSector(planets.cam.getMouseRay(), PlanetRenderer.outlineRad); }else if(planets.planet.isLandable()){ + boolean wasNull = selected == null; //always have the first sector selected. //TODO better support for multiple sectors in gridless planets? hovered = selected = planets.planet.sectors.first(); + + //autoshow + if(wasNull){ + Log.info("was null, updating selected"); + updateSelected(); + } }else{ hovered = selected = null; } @@ -858,13 +865,17 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ if(launching){ stable.color.sub(0, 0, 0, 0.05f * Time.delta); }else{ - //fade out UI when not facing selected sector - Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -planets.planet.getRotation()).scl(-1f).nor(); - float dot = planets.cam.direction.dot(Tmp.v31); - stable.color.a = Math.max(dot, 0f)*2f; - if(dot*2f <= -0.1f){ - selected = null; - updateSelected(); + if(!planets.planet.hasGrid()){ + stable.color.a = 1f; + }else{ + //fade out UI when not facing selected sector + Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -planets.planet.getRotation()).scl(-1f).nor(); + float dot = planets.cam.direction.dot(Tmp.v31); + stable.color.a = Math.max(dot, 0f)*2f; + if(dot*2f <= -0.1f){ + selected = null; + updateSelected(); + } } } }