summaryrefslogtreecommitdiffstats
path: root/Hex.gd
blob: 57a1a191bf584214b87c3d04b23665ce7b165310 (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
#warning-ignore-all:unused_argument
extends Tile

class_name Hex, "res://godot/Tile.png"

var type : int = -1
var roads : int = 0

func _ready() -> void:
	type = -1

func inspect() -> String:
	var s : String = 'plain'
	if type == 0: s = 'city'
	elif type == 1: s = 'wood'
	elif type == 2: s = 'mountain'
	elif type == 3: s = 'impracticable'
	return "%s e:%d h:%d c:%d r:%d\n -> [%d;%d]\n -> (%d;%d)" % [s, elevation(), height(), cost(), roads, coords.x, coords.y, position.x, position.y]

func has_road(o : int) -> bool:
	return (o & roads) > 0

func change() -> void:
	type = (type + 2) % 5 - 1
	for i in range(4):
		enable_overlay(i + 2, i == type)

func cost() -> int:
	if type == -1: return 1
	elif type == 3: return -1
	return type + 1

func height() -> int:
	if type == 0: return 2
	elif type == 1: return 1
	elif type == 2: return 0
	return 0

func elevation() -> int:
	if type == 2: return 2
	return 0

func block_los(from : Tile, to : Tile, d : float, dt : float) -> bool:
	var h : int = height() + elevation()
	if h == 0: return false
	var e : int = from.elevation()
	if e > h:
		if to.elevation() > h: return false
		return (h * dt / (e - h)) >= (d - dt)
	h -= e
	return ((h * d / dt) >= to.elevation() - e)

func show_los(b) -> void:
	if b: enable_overlay((1 if blocked else 0), true)
	else:
		enable_overlay(0, false)
		enable_overlay(1, false)

func show_move(b) -> void:
	if 6 < get_child_count():
		enable_overlay(6, b)