Guarantee a nearby gas giant
This commit is contained in:
parent
8231e165ff
commit
31ebfa905e
2 changed files with 26 additions and 2 deletions
15
WorldGen.gd
15
WorldGen.gd
|
|
@ -15,6 +15,13 @@ const ASTEROID_FIELD_THRESHOLD: float = 0.15
|
|||
const PLANET_THRESHOLD: float = 0.33
|
||||
const GAS_GIANT_THRESHOLD: float = 0.55
|
||||
|
||||
# A predictable early gas source for play-testing. The origin chunk is
|
||||
# deterministically normal space. Its explicit in-chunk position puts it
|
||||
# roughly 1,080 world units from a fresh fleet: easy to reach, but not
|
||||
# sitting on the spawn.
|
||||
const NEARBY_GAS_GIANT_CHUNK: Vector2i = Vector2i.ZERO
|
||||
const NEARBY_GAS_GIANT_LOCAL_POS: Vector2 = Vector2(900.0, 600.0)
|
||||
|
||||
const PLANET_NAMES: Array = [
|
||||
"Kepler's Rest", "Ceres Minor", "Vesta's Shadow", "Ironhold",
|
||||
"Drift Anchor", "Stonefall", "Grey Watch", "Silent Quarry",
|
||||
|
|
@ -62,6 +69,8 @@ static func biome_at_chunk(chunk: Vector2i) -> int:
|
|||
|
||||
|
||||
static func has_planet_at_chunk(chunk: Vector2i) -> bool:
|
||||
if chunk == NEARBY_GAS_GIANT_CHUNK:
|
||||
return true
|
||||
var n: float = _get_planet_noise().get_noise_2d(float(chunk.x), float(chunk.y))
|
||||
return (biome_at_chunk(chunk) == Biome.ASTEROID_FIELD and n > PLANET_THRESHOLD) or (biome_at_chunk(chunk) == Biome.SPACE and n > GAS_GIANT_THRESHOLD)
|
||||
|
||||
|
|
@ -76,12 +85,14 @@ static func planet_data_at_chunk(chunk: Vector2i) -> Dictionary:
|
|||
# can never drift out of sync with each other.
|
||||
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
|
||||
rng.seed = hash(chunk)
|
||||
var local_pos: Vector2 = Vector2(rng.randf() * CHUNK_SIZE, rng.randf() * CHUNK_SIZE)
|
||||
var guaranteed_nearby_giant: bool = chunk == NEARBY_GAS_GIANT_CHUNK
|
||||
var local_pos: Vector2 = NEARBY_GAS_GIANT_LOCAL_POS if guaranteed_nearby_giant \
|
||||
else Vector2(rng.randf() * CHUNK_SIZE, rng.randf() * CHUNK_SIZE)
|
||||
var planet_name: String = PLANET_NAMES[rng.randi() % PLANET_NAMES.size()]
|
||||
var shape_seed: int = rng.randi()
|
||||
# A stable per-chunk roll makes gas giants persistent landmarks rather
|
||||
# than a different resource whenever the scene reloads.
|
||||
var gas_giant: bool = biome_at_chunk(chunk) == Biome.SPACE
|
||||
var gas_giant: bool = guaranteed_nearby_giant or biome_at_chunk(chunk) == Biome.SPACE
|
||||
if gas_giant:
|
||||
planet_name = GAS_GIANT_NAMES[rng.randi() % GAS_GIANT_NAMES.size()]
|
||||
return {"local_pos": local_pos, "name": planet_name, "shape_seed": shape_seed,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,19 @@ func _initialize() -> void:
|
|||
func _process(delta: float) -> bool:
|
||||
elapsed += delta
|
||||
if stage == 0:
|
||||
var nearby_chunk: Vector2i = WorldGen.NEARBY_GAS_GIANT_CHUNK
|
||||
var nearby_data: Dictionary = WorldGen.planet_data_at_chunk(nearby_chunk)
|
||||
var nearby_position: Vector2 = WorldGen.chunk_origin(nearby_chunk) + nearby_data.local_pos
|
||||
if not WorldGen.has_planet_at_chunk(nearby_chunk):
|
||||
return _fail("nearby gas giant chunk does not contain a planet")
|
||||
if WorldGen.biome_at_chunk(nearby_chunk) != WorldGen.Biome.SPACE:
|
||||
return _fail("nearby gas giant is not in the normal space biome")
|
||||
if String(nearby_data.get("planet_type", "")) != "gas_giant" \
|
||||
or String(nearby_data.get("resource_type", "")) != "gas":
|
||||
return _fail("nearby guaranteed planet is not a gas source")
|
||||
if nearby_position.length() > WorldGen.CHUNK_SIZE * 2.0:
|
||||
return _fail("nearby gas giant spawned too far away: %s" % nearby_position)
|
||||
|
||||
var found_giant: bool = false
|
||||
for x in range(-12, 13):
|
||||
for y in range(-12, 13):
|
||||
|
|
|
|||
Loading…
Reference in a new issue