From 7fca7e65985deb24d51041d30fb8ea6ed2bd8571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 11 Jul 2020 00:07:56 +0200 Subject: properly implement road march --- Hex.gd | 16 +++++++++++----- Map.gd | 14 +++++++++++++- Piece.gd | 2 +- Tile.gd | 2 +- Unit.gd | 9 ++++----- assets/block.png | Bin 0 -> 5029 bytes assets/map-v.png | Bin 28405 -> 73999 bytes 7 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 assets/block.png diff --git a/Hex.gd b/Hex.gd index d53730e..57a1a19 100644 --- a/Hex.gd +++ b/Hex.gd @@ -4,6 +4,7 @@ extends Tile class_name Hex, "res://godot/Tile.png" var type : int = -1 +var roads : int = 0 func _ready() -> void: type = -1 @@ -13,15 +14,20 @@ func inspect() -> String: if type == 0: s = 'city' elif type == 1: s = 'wood' elif type == 2: s = 'mountain' - return "%s e:%d h:%d c:%d\n -> [%d;%d]\n -> (%d;%d)" % [s, elevation(), height(), cost(), coords.x, coords.y, position.x, position.y] + 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) % 4 - 1 - for i in range(3): + 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: @@ -51,5 +57,5 @@ func show_los(b) -> void: enable_overlay(1, false) func show_move(b) -> void: - if 5 < get_child_count(): - enable_overlay(5, b) + if 6 < get_child_count(): + enable_overlay(6, b) diff --git a/Map.gd b/Map.gd index b1859d0..1eda9e8 100644 --- a/Map.gd +++ b/Map.gd @@ -43,12 +43,24 @@ func reset() -> void: func get_tile(coords : Vector2, k : int) -> Tile: if hexes.has(k): return hexes[k] var hex : Hex = Hex.new() + hex.roads = get_road(k) hex.rotation_degrees = hex_rotation - hex.configure(board.center_of(coords), coords, [GREEN, BLACK, CITY, TREE, MOUNT, MOVE]) + hex.configure(board.center_of(coords), coords, [GREEN, BLACK, CITY, TREE, MOUNT, BLOCK, MOVE]) hexes[k] = hex $Hexes.add_child(hex) return hex +func get_road(k : int) -> int: + if not board.v: return 0 + var v : int = 0 + v += (HexBoard.Orientation.E if k in [19,20,21,23,24,42,43,44,45,46,47] else 0) + v += (HexBoard.Orientation.W if k in [19,20,21,22,24,25,43,44,45,46,47] else 0) + v += (HexBoard.Orientation.SE if k in [22,32,42,52,62] else 0) + v += (HexBoard.Orientation.NW if k in [32,42,52,62] else 0) + v += (HexBoard.Orientation.NE if k in [7,16,25,32] else 0) + v += (HexBoard.Orientation.SW if k in [7,16,23] else 0) + return v + func config(l : bool, m : bool) -> void: show_los = l show_move = m diff --git a/Piece.gd b/Piece.gd index 7564d0f..50baa43 100644 --- a/Piece.gd +++ b/Piece.gd @@ -13,7 +13,7 @@ func road_march_bonus() -> int: func move_cost(src : Tile, dst : Tile, a : int) -> int: print("Piece#move_cost() must be overriden in a subclass") - return 1 + return -1 # impracticable func at_least_one_tile() -> bool: print("Piece#at_least_one_tile() must be overriden in a subclass") diff --git a/Tile.gd b/Tile.gd index 03f10be..5127058 100644 --- a/Tile.gd +++ b/Tile.gd @@ -24,7 +24,7 @@ func configure(p : Vector2, c: Vector2, o :Array) -> void: visible = false func has_road(a) -> bool: - # FIXME + print("Tile#has_road() must be overriden in a subclass") return false func block_los(from : Tile, to : Tile, d : float, dt : float) -> bool: diff --git a/Unit.gd b/Unit.gd index 2de5ed6..cda26c8 100644 --- a/Unit.gd +++ b/Unit.gd @@ -4,11 +4,10 @@ extends Piece class_name Unit, "res://godot/Piece.png" func get_mp() -> int: - return 3 + return 2 func road_march_bonus() -> int: - return 3 + return 2 -func move_cost(src : Tile, dst : Tile, a : int) -> int: - print("from %d %d -> %d %d : %d" % [src.coords.x,src.coords.y,dst.coords.x,dst.coords.y,a]) - return dst.cost() +func move_cost(src : Tile, dst : Tile, o : int) -> int: + return (1 if (src.has_road(o) and dst.type != 3) else dst.cost()) diff --git a/assets/block.png b/assets/block.png new file mode 100644 index 0000000..7704d65 Binary files /dev/null and b/assets/block.png differ diff --git a/assets/map-v.png b/assets/map-v.png index fd97059..3960ffc 100644 Binary files a/assets/map-v.png and b/assets/map-v.png differ -- cgit v1.1-2-g2b99