Randoloot/scripts/planets/planet_profiles.gd

70 lines
3.6 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends RefCounted
# These visually inspected families contain land, oceans and atmospheric clouds.
const EARTHLIKE_FAMILIES := ["Terrestrial", "Lush", "Tropical"]
const MATERIALS := ["silicon", "copper", "nickel", "tungsten", "mercury"]
const MATERIAL_NAMES := {"silicon": "Krzem", "copper": "Miedź", "nickel": "Nikiel", "tungsten": "Wolfram", "mercury": "Rtęć"}
static func is_earthlike(texture: Texture2D) -> bool:
if texture == null:
return false
for family in EARTHLIKE_FAMILIES:
if texture.resource_path.contains("/Solid/%s/" % family):
return true
return false
static func earthlike_textures() -> Array[Texture2D]:
var found: Array[Texture2D] = []
for texture in preload("res://scripts/levels/celestial_texture_catalog.gd").PLANET_TEXTURES:
if is_earthlike(texture):
found.append(texture)
return found
static func generate(system_seed: int, index: int, name: String) -> Dictionary:
var rng := RandomNumberGenerator.new()
rng.seed = system_seed ^ (index * 0x504c414e) ^ 0x42494f4d
var easy := rng.randf() < 0.7
var oxygen := rng.randi_range(81, 100) if easy else rng.randi_range(0, 80)
var temperature := rng.randi_range(-10, 40) if easy else rng.randi_range(-50, 100)
var flora := 0 if easy else rng.randi_range(5, 50)
var o := maxf(0.0, 80.0 - oxygen) / 80.0
var t := maxf(0.0, maxf(-10.0 - temperature, temperature - 40.0)) / 60.0
var f := float(flora) / 50.0
var difficulty := clampf((o + t + f) / 3.0, 0, 1)
return {"id": "%d:planet:%d" % [system_seed, index], "name": name, "oxygen": oxygen, "temperature": temperature, "flora": flora, "easy": easy, "difficulty": difficulty, "landing_damage": roundi(lerpf(5.0, 20.0, difficulty)), "seed": rng.randi(), "index": index}
static func success_chance(profile: Dictionary, captain: Resource, stage: int) -> float:
var gear := preload("res://scripts/planets/captain_equipment.gd")
var penalties := [
maxf(0, 80.0 - float(profile.oxygen)) / 80.0,
maxf(0, maxf(-10.0 - float(profile.temperature), float(profile.temperature) - 40.0)) / 60.0,
float(profile.flora) / 50.0]
var environment := 0.0
var equipment_bonus := 0.0
for index in 3:
var rank: int = gear.level(captain, gear.KINDS[index])
var protection := minf(0.8, maxf(0, rank - 1) * 0.06)
environment += penalties[index] * (1.0 - protection) / 3.0
equipment_bonus += maxf(0, rank - 1) * 0.004
var base: float = [0.90, 0.60, 0.35][clampi(stage, 0, 2)]
return clampf(base - environment * 0.35 + minf(0.12, equipment_bonus), 0.08, 0.98)
static func biome_name(profile: Dictionary) -> String:
if bool(profile.easy):
return "Łagodna biosfera"
if int(profile.temperature) < -10:
return "Zimna biosfera"
if int(profile.temperature) > 40:
return "Gorąca biosfera"
return "Dzika biosfera"
static func scan_description(profile: Dictionary, captain: Resource) -> String:
var oxygen := int(profile.oxygen)
var temperature := int(profile.temperature)
var flora := int(profile.flora)
var breathing := "dogodne oddychanie" if oxygen > 80 else "system oddychania poprawia szanse"
var climate := "łagodny klimat" if temperature >= -10 and temperature <= 40 else "skafander ogranicza ryzyko"
var biology := "brak zagrożeń biologicznych" if flora == 0 else "broń ręczna ogranicza zagrożenia"
return "%s · %s\nTLEN %d%% — %s\nTEMPERATURA %d°C — %s\nFLORA %d/50 — %s\nLądowanie: −%d HP · Lądownik: %d%%\nPierwszy etap POI: %d%% szans z obecnym sprzętem" % [
profile.name,biome_name(profile),oxygen,breathing,temperature,climate,flora,biology,
profile.landing_damage,ceili(captain.expedition.lander_hp),roundi(success_chance(profile,captain,0)*100)]