Animate ship crafter deliveries
This commit is contained in:
parent
fc68c4e8cf
commit
798deb48a1
5 changed files with 140 additions and 4 deletions
33
GameState.gd
33
GameState.gd
|
|
@ -308,6 +308,11 @@ var next_building_id: int = 1
|
|||
# Production is simulated here, in the autoload, the same way extractor
|
||||
# haulers are, so a build finishes whether or not the player is in space.
|
||||
var stored_vessels: Array = []
|
||||
# Finished crafter orders travel to the mothership before appearing in its
|
||||
# hangar. State is authoritative here so delivery continues off-screen.
|
||||
# {"type", "from", "to", "progress"}
|
||||
var vessel_deliveries: Array = []
|
||||
const VESSEL_DELIVERY_SPEED: float = 950.0
|
||||
|
||||
signal order_completed(building_id: int, type: String)
|
||||
|
||||
|
|
@ -695,9 +700,15 @@ func _advance_production(delta: float) -> void:
|
|||
# hub and wait for work (#19).
|
||||
_station_transporter(b.position)
|
||||
else:
|
||||
# Everything else is delivered to the mothership and waits there
|
||||
# until the player crews it (#23).
|
||||
stored_vessels.append(product)
|
||||
# A finished hull launches from the crafter and physically flies to
|
||||
# the mothership hangar. With no mothership there is nowhere to fly,
|
||||
# so preserve the old safe fallback of holding it immediately.
|
||||
var mothership: Variant = get_mothership_position()
|
||||
if mothership == null:
|
||||
stored_vessels.append(product)
|
||||
else:
|
||||
vessel_deliveries.append({"type": product, "from": b.position,
|
||||
"to": mothership, "progress": 0.0})
|
||||
order_completed.emit(int(b.id), product)
|
||||
|
||||
|
||||
|
|
@ -818,6 +829,7 @@ func _process(delta: float) -> void:
|
|||
# Runs in the autoload, so mining and transport continue while the player
|
||||
# is on a planet's surface or nowhere near either.
|
||||
_advance_production(delta)
|
||||
_advance_vessel_deliveries(delta)
|
||||
for e in extractors:
|
||||
e.mining_progress = float(e.get("mining_progress", 0.0)) + delta * EXTRACTOR_RATE
|
||||
var whole: int = int(floor(float(e.mining_progress)))
|
||||
|
|
@ -827,6 +839,21 @@ func _process(delta: float) -> void:
|
|||
_advance_transporters(delta)
|
||||
|
||||
|
||||
func vessel_delivery_position(delivery: Dictionary) -> Vector2:
|
||||
return (delivery.from as Vector2).lerp(delivery.to as Vector2,
|
||||
clampf(float(delivery.progress), 0.0, 1.0))
|
||||
|
||||
|
||||
func _advance_vessel_deliveries(delta: float) -> void:
|
||||
for i in range(vessel_deliveries.size() - 1, -1, -1):
|
||||
var delivery: Dictionary = vessel_deliveries[i]
|
||||
var distance: float = (delivery.from as Vector2).distance_to(delivery.to as Vector2)
|
||||
delivery.progress = float(delivery.progress) + delta / maxf(distance / VESSEL_DELIVERY_SPEED, 0.001)
|
||||
if float(delivery.progress) >= 1.0:
|
||||
stored_vessels.append(String(delivery.type))
|
||||
vessel_deliveries.remove_at(i)
|
||||
|
||||
|
||||
# --- transporters (#19) ---------------------------------------------------
|
||||
|
||||
# Vessels stationed at a transport hub that fetch ore from the mothership and
|
||||
|
|
|
|||
Loading…
Reference in a new issue