Planet progress

This commit is contained in:
Anuken
2021-06-10 20:46:10 -04:00
parent f99b8e35bd
commit 31ebb1d156
8 changed files with 104 additions and 14 deletions

View File

@@ -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

View File

@@ -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));

View 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);
}
}

View File

@@ -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;

View File

@@ -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.*/

View File

@@ -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){

View File

@@ -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);
}

View File

@@ -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();
}
}
}
}