summaryrefslogtreecommitdiff
path: root/scripts/HexSpace.gd
blob: 614039aef6a6e289cf50dfaaa660c1fbdd81b1a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
tool
extends StaticBody

enum { PLAIN, HILLS, MOUNTAINS, AIRPORT }
enum { Y, X }

# general cell variables
var x : int = -1
var y : int = -1 
var cell_type : int = PLAIN
var orientation : int = 0 # 0 - 5 

# airport variables
var airport_number : int
var airport_color : Color
var airport_id : int
var airport_name : String
var runway_count : int
var airport_closed : bool = false

# cell offsets that describe valid approaches based on runways and surroundings
# used to choose a takeoff position
enum rotations { EAST, NORTHEAST, NORTHWEST, WEST, SOUTHWEST, SOUTHEAST }
const bearings = [ [0,1] , [-1, 0], [-1, -1], [0, -1], [1, 0], [1, 1] ]

var valid_departure_bearings = []
var valid_arrival_bearings = []



func _ready():
	pass

func reset():
	$Hills.visible = false
	$Mountain.visible = false
	$Airport.visible = false
	$Airport/EasyRunway.visible = true # reset runways
	$Airport/MediumRunway.visible = true
	$Airport/AirportName.visible = false
	$Airport/AirportIcon.visible = false
	orientation = 0
	self.rotation.y = 0
	cell_type = PLAIN
	x = -1
	y = -1
	airport_closed = false

	
func set_up(settings):
	x = settings["pos"][X] ; y = settings["pos"][Y]
	cell_type = settings["cell_type"]
	
	valid_departure_bearings.clear()
	valid_arrival_bearings.clear()
	
	
	if "orientation" in settings: # bearing according to E, NE, etc. 
		orientation = settings["orientation"]
		self.global_rotation.y = orientation * deg2rad(60)
	
	if cell_type == HILLS:
		$Hills.visible = true
	elif cell_type == MOUNTAINS:
		$Mountain.visible = true
	elif cell_type == AIRPORT:
		$Airport.visible = true
		
		if settings["use_names"]:
			airport_name = settings["airport_name"]
			$Airport/AirportName.text = airport_name
			$Airport/AirportName.visible = true
		else:
			airport_number = settings["airport_number"]
			airport_color = Color(settings["airport_color"])
			$Airport/AirportIcon.visible = true
			$Airport/AirportIcon.texture = load("res://textures/airport_indicator_%d.png" % airport_number)
			$Airport/AirportIcon.modulate = airport_color
		
		valid_departure_bearings = settings["valid_approach_offsets"]
		airport_id = settings["airport_id"]
		
		for departure_bearing in valid_departure_bearings:
			var bearing_i = bearings.find(departure_bearing)
			bearing_i = (bearing_i + 3) % 6 # opposite bearing
			valid_arrival_bearings.push_back(bearings[bearing_i])
		
		runway_count = int(clamp(settings["runway_count"], 1, 3))
		if runway_count < 3:
			$Airport/EasyRunway.visible = false
		if runway_count == 1:
			$Airport/MediumRunway.visible = false