60 lines
1.5 KiB
GDScript
60 lines
1.5 KiB
GDScript
# Manager.gd
|
|
extends Node
|
|
|
|
# Globalna lista wszystkich planet (słowniki)
|
|
var planets_data: Array = []
|
|
|
|
# Czas do aktualizacji
|
|
var update_timer := 0.0
|
|
const UPDATE_INTERVAL := 5.0 # co 5 sekund
|
|
|
|
func _ready():
|
|
print("[Manager] Initialized global manager")
|
|
|
|
func _process(delta):
|
|
update_timer += delta
|
|
if update_timer >= UPDATE_INTERVAL:
|
|
update_timer = 0
|
|
_update_planets()
|
|
|
|
# --- Tworzenie planety globalnie ---
|
|
func register_planet(planet_name: String, size: int, mining_rate: float):
|
|
var planet = {
|
|
"name": planet_name,
|
|
"size": size,
|
|
"population": 0,
|
|
"max_population": get_max_population(size),
|
|
"resources": 0.0,
|
|
"mining_rate": mining_rate,
|
|
"is_colonized": false
|
|
}
|
|
planets_data.append(planet)
|
|
return planet
|
|
|
|
# --- Symulacja wzrostu i wydobycia ---
|
|
func _update_planets():
|
|
for planet in planets_data:
|
|
if planet["is_colonized"]:
|
|
var growth = int(planet["population"] / 10) # +10%
|
|
planet["population"] = min(planet["population"] + growth, planet["max_population"])
|
|
planet["resources"] += get_mined_per_cycle(planet)
|
|
print("[Manager] Updated planets")
|
|
|
|
func get_mined_per_cycle(planet: Dictionary) -> float:
|
|
return planet["mining_rate"] * pow(planet["population"], 0.5) * 0.05
|
|
|
|
func get_max_population(size: int) -> int:
|
|
match size:
|
|
1: return 1000
|
|
2: return 5000
|
|
3: return 15000
|
|
4: return 30000
|
|
return 1000
|
|
|
|
# --- Funkcje pomocnicze ---
|
|
func get_planet_by_name(name: String) -> Dictionary:
|
|
for planet in planets_data:
|
|
if planet["name"] == name:
|
|
return planet
|
|
return {}
|