first commit
This commit is contained in:
88
scripts/station.gd
Normal file
88
scripts/station.gd
Normal file
@@ -0,0 +1,88 @@
|
||||
extends Node3D
|
||||
## Bahnhof: Bahnsteig, Gebaeude, Warteplaetze, Warenlager.
|
||||
|
||||
const Mat = preload("res://scripts/mat.gd")
|
||||
const Deco = preload("res://scripts/deco.gd")
|
||||
const Cargo = preload("res://scripts/cargo.gd")
|
||||
|
||||
const PLATFORM_LEN := 44.0
|
||||
const PLATFORM_H := 0.95
|
||||
|
||||
var station_name := ""
|
||||
var progress := 0.0
|
||||
var side := 1.0
|
||||
var produces := -1
|
||||
var accepts: Array[int] = []
|
||||
var stock := 0.0
|
||||
var max_stock := 30.0
|
||||
var rate := 0.55
|
||||
var waiting_spots: Array[Vector3] = [] ## Weltpositionen auf dem Bahnsteig
|
||||
var waiting: Array = [] ## wartende Passagiere
|
||||
|
||||
func setup(nm: String, prog: float, prod: int, acc: Array[int]) -> void:
|
||||
station_name = nm
|
||||
progress = prog
|
||||
produces = prod
|
||||
accepts = acc
|
||||
|
||||
func tick(delta: float) -> void:
|
||||
if produces >= 0:
|
||||
stock = minf(stock + rate * delta, max_stock)
|
||||
|
||||
func _box(parent: Node3D, center: Vector3, size: Vector3, color: Color) -> MeshInstance3D:
|
||||
var m := MeshInstance3D.new()
|
||||
m.mesh = Deco.box(size)
|
||||
m.material_override = Mat.flat(color)
|
||||
m.position = center
|
||||
parent.add_child(m)
|
||||
return m
|
||||
|
||||
func build_visuals(track_xf: Transform3D, s: float, wall: Color, roof: Color, chimney: bool) -> void:
|
||||
transform = track_xf
|
||||
side = s
|
||||
var edge := s * 2.4
|
||||
|
||||
# Bahnsteig
|
||||
_box(self, Vector3(edge + s * 1.6, PLATFORM_H * 0.5, 0),
|
||||
Vector3(3.2, PLATFORM_H, PLATFORM_LEN), Color("cfc3a8"))
|
||||
_box(self, Vector3(edge + s * 0.06, PLATFORM_H - 0.04, 0),
|
||||
Vector3(0.35, 0.1, PLATFORM_LEN), Color("e8e0cc"))
|
||||
|
||||
# Vordach
|
||||
for i in 3:
|
||||
var z := -PLATFORM_LEN * 0.22 + i * PLATFORM_LEN * 0.22
|
||||
_box(self, Vector3(edge + s * 4.1, PLATFORM_H + 1.75, z),
|
||||
Vector3(0.24, 3.5, 0.24), Color("6b5a45"))
|
||||
_box(self, Vector3(edge + s * 3.0, PLATFORM_H + 3.6, 0),
|
||||
Vector3(3.4, 0.22, PLATFORM_LEN * 0.5), roof)
|
||||
|
||||
# Empfangsgebaeude
|
||||
var h := Deco.house(wall, roof, 11.0, 8.0, 4.6, chimney)
|
||||
h.position = Vector3(edge + s * 11.5, 0.0, -PLATFORM_LEN * 0.18)
|
||||
h.rotate_y(PI * 0.5 * -s)
|
||||
add_child(h)
|
||||
|
||||
# Baenke
|
||||
for i in 3:
|
||||
var z := -PLATFORM_LEN * 0.25 + i * PLATFORM_LEN * 0.25
|
||||
_box(self, Vector3(edge + s * 2.5, PLATFORM_H + 0.28, z),
|
||||
Vector3(0.55, 0.12, 1.6), Color("8a6b4a"))
|
||||
_box(self, Vector3(edge + s * 2.75, PLATFORM_H + 0.6, z),
|
||||
Vector3(0.1, 0.55, 1.6), Color("8a6b4a"))
|
||||
|
||||
# Namensschild
|
||||
var label := Label3D.new()
|
||||
label.text = station_name
|
||||
label.font_size = 64
|
||||
label.pixel_size = 0.014
|
||||
label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
||||
label.outline_size = 18
|
||||
label.outline_modulate = Color(0, 0, 0, 0.7)
|
||||
label.position = Vector3(edge + s * 3.0, PLATFORM_H + 4.9, 0)
|
||||
add_child(label)
|
||||
|
||||
# Warteplaetze auf dem Bahnsteig
|
||||
for i in 10:
|
||||
var lz := -PLATFORM_LEN * 0.34 + i * PLATFORM_LEN * 0.075
|
||||
var lx := edge + s * (1.1 + (0.9 if i % 2 == 0 else 0.0))
|
||||
waiting_spots.append(to_global(Vector3(lx, PLATFORM_H, lz)))
|
||||
Reference in New Issue
Block a user