109 lines
3.9 KiB
GDScript
109 lines
3.9 KiB
GDScript
extends Node
|
|
|
|
const CAPTAIN_PROGRESS := preload("res://scripts/captain/captain_progress.gd")
|
|
var captain: CaptainProgress = CAPTAIN_PROGRESS.new()
|
|
|
|
var selected_ship_path: String = ""
|
|
var restart_inventory: Dictionary = {}
|
|
var system_level: int = 1
|
|
var system_seed: int = 0
|
|
var active_distant_map: Dictionary = {}
|
|
var distant_home: Dictionary = {}
|
|
var return_to_freighter := false
|
|
var highest_system := 1
|
|
var system_seeds: Dictionary = {}
|
|
var cleared_systems: Dictionary = {}
|
|
var _production_signal_time := 0.0
|
|
var explored_pois: Dictionary = {}
|
|
var asteroid_retry_seeds: Dictionary = {}
|
|
var exploration_wreck_bonuses: Dictionary = {}
|
|
var hud_panel_state: Dictionary = {}
|
|
|
|
func depart_distant(map_id: String) -> bool:
|
|
if not active_distant_map.is_empty() or not captain.expedition.distant_maps.has(map_id): return false
|
|
var map: Dictionary = captain.expedition.distant_maps[map_id]
|
|
var cost: int = preload("res://scripts/planets/distant_expeditions.gd").fuel_cost(map)
|
|
if captain.expedition.deuter < cost: return false
|
|
distant_home = {"level":system_level,"seed":system_seed}
|
|
active_distant_map = map.duplicate(true)
|
|
captain.expedition.deuter -= cost
|
|
system_level = int(map.level)
|
|
system_seed = int(map.seed)
|
|
captain.expedition.emit_changed()
|
|
return true
|
|
|
|
func restore_distant_home() -> void:
|
|
if distant_home.is_empty(): return
|
|
system_level = int(distant_home.level)
|
|
system_seed = int(distant_home.seed)
|
|
active_distant_map.clear()
|
|
distant_home.clear()
|
|
|
|
func create_system_seed() -> int:
|
|
var rng := RandomNumberGenerator.new()
|
|
rng.randomize()
|
|
return maxi(1, rng.randi())
|
|
|
|
func reset_current_system_exploration() -> void:
|
|
# Keep the system and rewards, but regenerate asteroid placement and minerals.
|
|
var previous: int = asteroid_retry_seeds.get(system_seed, system_seed)
|
|
var next_seed := create_system_seed()
|
|
while next_seed == previous:
|
|
next_seed = create_system_seed()
|
|
asteroid_retry_seeds[system_seed] = next_seed
|
|
var prefix := "%d:" % system_seed
|
|
for id in explored_pois.keys():
|
|
if str(id).begins_with(prefix):
|
|
explored_pois.erase(id)
|
|
|
|
func start_new_run() -> void:
|
|
captain = CAPTAIN_PROGRESS.new()
|
|
system_level = 1
|
|
highest_system = 1
|
|
active_distant_map.clear()
|
|
distant_home.clear()
|
|
return_to_freighter = false
|
|
system_seeds.clear()
|
|
cleared_systems.clear()
|
|
_production_signal_time = 0
|
|
system_seed = create_system_seed()
|
|
restart_inventory.clear()
|
|
explored_pois.clear()
|
|
asteroid_retry_seeds.clear()
|
|
exploration_wreck_bonuses.clear()
|
|
hud_panel_state.clear()
|
|
|
|
func _ready() -> void:
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
|
var game_window := get_tree().root
|
|
game_window.content_scale_size = Vector2i(1280, 720)
|
|
game_window.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
|
|
game_window.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND
|
|
|
|
func remember_system() -> void:
|
|
highest_system = maxi(highest_system, system_level)
|
|
system_seeds[system_level] = system_seed
|
|
|
|
func can_visit_system(level: int) -> bool:
|
|
return level >= 1 and level <= highest_system and level <= 120
|
|
|
|
func seed_for_system(level: int) -> int:
|
|
if not system_seeds.has(level): system_seeds[level] = create_system_seed()
|
|
return int(system_seeds[level])
|
|
|
|
func _process(delta: float) -> void:
|
|
advance_play_time(delta, get_tree().current_scene)
|
|
|
|
func advance_play_time(delta: float, scene: Node) -> void:
|
|
if scene == null or not scene.has_node("PlayerShip"): return
|
|
if bool(scene.get_node("PlayerShip").get("_is_destroyed")): return
|
|
var expedition := scene.get_node_or_null("PlanetExpeditions")
|
|
var location_open := expedition != null and is_instance_valid(expedition.screen)
|
|
if get_tree().paused and not location_open: return
|
|
var network := preload("res://scripts/planets/mining_network.gd")
|
|
if network.advance(captain.expedition, delta) <= 0: return
|
|
_production_signal_time += delta
|
|
if _production_signal_time >= 1.0:
|
|
_production_signal_time = fmod(_production_signal_time, 1.0)
|
|
captain.expedition.emit_changed()
|