Planet progress
This commit is contained in:
@@ -4,11 +4,16 @@ import arc.graphics.*;
|
|||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.noise.*;
|
import arc.util.noise.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
|
import mindustry.game.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.graphics.g3d.*;
|
import mindustry.graphics.g3d.*;
|
||||||
import mindustry.graphics.g3d.PlanetGrid.*;
|
import mindustry.graphics.g3d.PlanetGrid.*;
|
||||||
|
import mindustry.maps.generators.*;
|
||||||
import mindustry.maps.planet.*;
|
import mindustry.maps.planet.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class Planets implements ContentList{
|
public class Planets implements ContentList{
|
||||||
public static Planet
|
public static Planet
|
||||||
@@ -51,14 +56,35 @@ public class Planets implements ContentList{
|
|||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
new Planet("gier-" + i, erekir, 0.1f){{
|
new Planet("gier-" + i, erekir, 0.1f){{
|
||||||
hasAtmosphere = false;
|
hasAtmosphere = false;
|
||||||
|
//for testing only!
|
||||||
alwaysUnlocked = true;
|
alwaysUnlocked = true;
|
||||||
|
updateLighting = false;
|
||||||
sectors.add(new Sector(this, Ptile.empty));
|
sectors.add(new Sector(this, Ptile.empty));
|
||||||
camRadius = 0.43f;
|
camRadius = 0.43f;
|
||||||
|
orbitOffset = 0f;
|
||||||
|
|
||||||
//new SectorPreset(name + "-sector", this, 0){{
|
//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(){
|
meshLoader = () -> new HexMesh(this, new HexMesher(){
|
||||||
Simplex sim = new Simplex(id);
|
Simplex sim = new Simplex(id);
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class Universe{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state.hasSector()){
|
if(state.hasSector() && state.getSector().planet.updateLighting){
|
||||||
//update sector light
|
//update sector light
|
||||||
float light = state.getSector().getLight();
|
float light = state.getSector().getLight();
|
||||||
float alpha = Mathf.clamp(Mathf.map(light, 0f, 0.8f, 0.3f, 1f));
|
float alpha = Mathf.clamp(Mathf.map(light, 0f, 0.8f, 0.3f, 1f));
|
||||||
|
|||||||
43
core/src/mindustry/maps/generators/BlankPlanetGenerator.java
Normal file
43
core/src/mindustry/maps/generators/BlankPlanetGenerator.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -124,6 +124,11 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe
|
|||||||
return 3200;
|
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){
|
public void generate(Tiles tiles, Sector sec){
|
||||||
this.tiles = tiles;
|
this.tiles = tiles;
|
||||||
this.sector = sec;
|
this.sector = sec;
|
||||||
|
|||||||
@@ -45,12 +45,16 @@ public class Planet extends UnlockableContent{
|
|||||||
public float orbitTime;
|
public float orbitTime;
|
||||||
/** Time for the planet to perform a full revolution, in seconds. One day. */
|
/** Time for the planet to perform a full revolution, in seconds. One day. */
|
||||||
public float rotateTime = 24f * 60f;
|
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. */
|
/** Approx. radius of one sector. */
|
||||||
public float sectorApproxRadius;
|
public float sectorApproxRadius;
|
||||||
/** Whether this planet is tidally locked relative to its parent - see https://en.wikipedia.org/wiki/Tidal_locking */
|
/** Whether this planet is tidally locked relative to its parent - see https://en.wikipedia.org/wiki/Tidal_locking */
|
||||||
public boolean tidalLock = false;
|
public boolean tidalLock = false;
|
||||||
/** Whether or not this planet is listed in the planet access UI. **/
|
/** Whether or not this planet is listed in the planet access UI. **/
|
||||||
public boolean accessible = true;
|
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. */
|
/** The default starting sector displayed to the map dialog. */
|
||||||
public int startSector = 0;
|
public int startSector = 0;
|
||||||
/** Whether the bloom render effect is enabled. */
|
/** Whether the bloom render effect is enabled. */
|
||||||
@@ -79,6 +83,7 @@ public class Planet extends UnlockableContent{
|
|||||||
|
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
this.orbitOffset = Mathf.randomSeed(id, 360);
|
||||||
|
|
||||||
//total radius is initially just the radius
|
//total radius is initially just the radius
|
||||||
totalRadius = radius;
|
totalRadius = radius;
|
||||||
@@ -153,9 +158,7 @@ public class Planet extends UnlockableContent{
|
|||||||
|
|
||||||
/** Calculates orbital rotation based on universe time.*/
|
/** Calculates orbital rotation based on universe time.*/
|
||||||
public float getOrbitAngle(){
|
public float getOrbitAngle(){
|
||||||
//applies random offset to prevent planets from starting out in a line
|
return (orbitOffset + universe.secondsf() / (orbitTime / 360f)) % 360f;
|
||||||
float offset = Mathf.randomSeed(id, 360);
|
|
||||||
return (offset + universe.secondsf() / (orbitTime / 360f)) % 360f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Calulates rotation on own axis based on universe time.*/
|
/** Calulates rotation on own axis based on universe time.*/
|
||||||
|
|||||||
@@ -153,9 +153,7 @@ public class Sector{
|
|||||||
|
|
||||||
/** @return the sector size, in tiles */
|
/** @return the sector size, in tiles */
|
||||||
public int getSize(){
|
public int getSize(){
|
||||||
if(planet.generator == null) return 1;
|
return planet.generator == null ? 1 : planet.generator.getSectorSize(this);
|
||||||
int res = (int)(rect.radius * planet.generator.getSizeScl());
|
|
||||||
return res % 2 == 0 ? res : res + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeItems(ItemSeq items){
|
public void removeItems(ItemSeq items){
|
||||||
|
|||||||
@@ -307,6 +307,10 @@ public class UnitType extends UnlockableContent{
|
|||||||
immunities.add(StatusEffects.wet);
|
immunities.add(StatusEffects.wet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(flying){
|
||||||
|
envEnabled |= Env.space;
|
||||||
|
}
|
||||||
|
|
||||||
if(lightRadius == -1){
|
if(lightRadius == -1){
|
||||||
lightRadius = Math.max(60f, hitSize * 2.3f);
|
lightRadius = Math.max(60f, hitSize * 2.3f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -599,9 +599,16 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
|||||||
if(planets.planet.hasGrid()){
|
if(planets.planet.hasGrid()){
|
||||||
hovered = planets.planet.getSector(planets.cam.getMouseRay(), PlanetRenderer.outlineRad);
|
hovered = planets.planet.getSector(planets.cam.getMouseRay(), PlanetRenderer.outlineRad);
|
||||||
}else if(planets.planet.isLandable()){
|
}else if(planets.planet.isLandable()){
|
||||||
|
boolean wasNull = selected == null;
|
||||||
//always have the first sector selected.
|
//always have the first sector selected.
|
||||||
//TODO better support for multiple sectors in gridless planets?
|
//TODO better support for multiple sectors in gridless planets?
|
||||||
hovered = selected = planets.planet.sectors.first();
|
hovered = selected = planets.planet.sectors.first();
|
||||||
|
|
||||||
|
//autoshow
|
||||||
|
if(wasNull){
|
||||||
|
Log.info("was null, updating selected");
|
||||||
|
updateSelected();
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
hovered = selected = null;
|
hovered = selected = null;
|
||||||
}
|
}
|
||||||
@@ -858,13 +865,17 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
|||||||
if(launching){
|
if(launching){
|
||||||
stable.color.sub(0, 0, 0, 0.05f * Time.delta);
|
stable.color.sub(0, 0, 0, 0.05f * Time.delta);
|
||||||
}else{
|
}else{
|
||||||
//fade out UI when not facing selected sector
|
if(!planets.planet.hasGrid()){
|
||||||
Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -planets.planet.getRotation()).scl(-1f).nor();
|
stable.color.a = 1f;
|
||||||
float dot = planets.cam.direction.dot(Tmp.v31);
|
}else{
|
||||||
stable.color.a = Math.max(dot, 0f)*2f;
|
//fade out UI when not facing selected sector
|
||||||
if(dot*2f <= -0.1f){
|
Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -planets.planet.getRotation()).scl(-1f).nor();
|
||||||
selected = null;
|
float dot = planets.cam.direction.dot(Tmp.v31);
|
||||||
updateSelected();
|
stable.color.a = Math.max(dot, 0f)*2f;
|
||||||
|
if(dot*2f <= -0.1f){
|
||||||
|
selected = null;
|
||||||
|
updateSelected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user