120 lines
3.4 KiB
GDScript
120 lines
3.4 KiB
GDScript
extends Node
|
|
#class_name Manager
|
|
|
|
# --- KONFIGURACJA ---
|
|
@export var SECTOR_COUNT: int = 10
|
|
@export var PLANETS_PER_SECTOR_RANGE: Vector2 = Vector2(1, 5)
|
|
|
|
# --- DANE ---
|
|
var sectors_data: Array = [] # Każdy element: {"name": str, "position": Vector2, "planets": Array, "star": Dictionary}
|
|
var current_sector: int = -1
|
|
|
|
# Nazwy sektorów i planet
|
|
var sector_names = [
|
|
"Aetherion", "Altaris", "Andur System", "Artemis Reach", "Astrion",
|
|
"Azura Prime", "Borealis Expanse", "Caldris Belt", "Canthar System", "Celion Verge",
|
|
"Corvax Sector", "Cygnera Rift", "Daedalus Reach", "Darnis Cluster", "Dravon Expanse"
|
|
]
|
|
|
|
var planet_names = [
|
|
"Arcturus","Betelgeuse","Canopus","Deneb","Elnath",
|
|
"Fomalhaut","Gacrux","Hadar","Izar","Jabbah",
|
|
"Kaus","Lesath","Menkent","Nunki","Okul",
|
|
"Pollux","Rigel","Sargas","Toliman","Unukalhai",
|
|
"Vega","Wezen","Xamidimura","Yildun","Zosma"
|
|
]
|
|
|
|
# --- START ---
|
|
func _ready():
|
|
randomize()
|
|
_initialize_sectors()
|
|
|
|
# --- LOSOWANIE UNIKALNEJ NAZWY SEKTORA ---
|
|
func get_unique_sector_name() -> String:
|
|
if sector_names.size() == 0:
|
|
return "Unknown Sector"
|
|
var index = randi() % sector_names.size()
|
|
var name = sector_names[index]
|
|
sector_names.remove_at(index)
|
|
return name
|
|
|
|
# --- INICJALIZACJA SEKTORÓW ---
|
|
func _initialize_sectors():
|
|
var screen_size = get_viewport().get_visible_rect().size
|
|
|
|
for i in range(SECTOR_COUNT):
|
|
if sectors_data.size() <= i:
|
|
sectors_data.resize(i + 1)
|
|
if sectors_data[i] == null:
|
|
# Losowa pozycja
|
|
var pos = Vector2(
|
|
randf_range(100, screen_size.x - 200),
|
|
randf_range(100, screen_size.y - 200)
|
|
)
|
|
|
|
# Unikalna nazwa
|
|
var name = get_unique_sector_name()
|
|
|
|
# Utwórz sektor
|
|
var scale = randf_range(0.03, 0.08)
|
|
|
|
sectors_data[i] = {
|
|
"name": name,
|
|
"position": pos,
|
|
"star_scale": scale,
|
|
"planets": [],
|
|
"star": {}
|
|
}
|
|
|
|
|
|
# Losowe planety
|
|
var planet_count = randi_range(PLANETS_PER_SECTOR_RANGE.x, PLANETS_PER_SECTOR_RANGE.y)
|
|
for j in range(planet_count):
|
|
var size = randi_range(1, 3)
|
|
var growth_rate = randf_range(0.1, 1.0)
|
|
var texture_planet = "res://assets/planets/p%d.png" % randi_range(1,18)
|
|
var planet = {
|
|
"name": planet_names[randi() % planet_names.size()],
|
|
"size": size,
|
|
"population": 0,
|
|
"max_population": get_max_population(size),
|
|
"resources": 0.0,
|
|
"mining_rate": randf_range(0.1, 1.0),
|
|
"growth_rate": growth_rate,
|
|
"is_colonized": false,
|
|
"angle": randf() * TAU,
|
|
"rotation_speed": randf_range(0.001, 0.02),
|
|
"texture_path": texture_planet
|
|
}
|
|
sectors_data[i]["planets"].append(planet)
|
|
|
|
# --- FUNKCJE POMOCNICZE ---
|
|
func get_max_population(size: int) -> int:
|
|
match size:
|
|
1: return 1000
|
|
2: return 5000
|
|
3: return 15000
|
|
4: return 30000
|
|
return 1000
|
|
|
|
func get_sector(index: int) -> Dictionary:
|
|
if index >= 0 and index < sectors_data.size():
|
|
return sectors_data[index]
|
|
return {}
|
|
|
|
func get_planets(index: int) -> Array:
|
|
var sector = get_sector(index)
|
|
if sector.has("planets"):
|
|
return sector["planets"]
|
|
return []
|
|
|
|
func register_planet(sector_index: int, planet_data: Dictionary):
|
|
if sectors_data.size() <= sector_index:
|
|
sectors_data.resize(sector_index + 1)
|
|
if sectors_data[sector_index] == null:
|
|
sectors_data[sector_index] = {"planets": [], "name":"Unknown", "position": Vector2.ZERO, "star":{}}
|
|
sectors_data[sector_index]["planets"].append(planet_data)
|
|
|
|
func get_mined_per_cycle(planet: Dictionary) -> float:
|
|
return planet["mining_rate"] * pow(planet["population"], 0.5) * 0.05
|