diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-11 00:07:56 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-11 00:07:56 +0200 |
commit | 7fca7e65985deb24d51041d30fb8ea6ed2bd8571 (patch) | |
tree | 1c0b918d97b9122a9e1b091654bc5b441609e7c0 | |
parent | 35b1995824bbc3e35ed2488e4034cc6b47c2bc76 (diff) | |
download | godot-hexgrid-7fca7e65985deb24d51041d30fb8ea6ed2bd8571.zip godot-hexgrid-7fca7e65985deb24d51041d30fb8ea6ed2bd8571.tar.gz |
properly implement road march
-rw-r--r-- | Hex.gd | 16 | ||||
-rw-r--r-- | Map.gd | 14 | ||||
-rw-r--r-- | Piece.gd | 2 | ||||
-rw-r--r-- | Tile.gd | 2 | ||||
-rw-r--r-- | Unit.gd | 9 | ||||
-rw-r--r-- | assets/block.png | bin | 0 -> 5029 bytes | |||
-rw-r--r-- | assets/map-v.png | bin | 28405 -> 73999 bytes |
7 files changed, 30 insertions, 13 deletions
@@ -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) @@ -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 @@ -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") @@ -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: @@ -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 Binary files differnew file mode 100644 index 0000000..7704d65 --- /dev/null +++ b/assets/block.png diff --git a/assets/map-v.png b/assets/map-v.png Binary files differindex fd97059..3960ffc 100644 --- a/assets/map-v.png +++ b/assets/map-v.png |