Guarantee a nearby gas giant

This commit is contained in:
Loïc Wisniewski 2026-08-14 12:07:50 +02:00
commit 31ebfa905e
2 changed files with 26 additions and 2 deletions

View file

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