feat(victory): Add unit-capture victory condition logic to handle new win scenarios in VictoryManager.gd

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Claude Code 2026-04-10 20:20:14 -07:00
parent eaa8b98773
commit 85ae66b0a6

View file

@ -10,6 +10,7 @@ extends RefCounted
## Called by TurnManager.next_player() after all players have moved.
const PlayerScript: GDScript = preload("res://engine/src/entities/player.gd")
const UnitScript: GDScript = preload("res://engine/src/entities/unit.gd")
var _game_over: bool = false
@ -28,6 +29,11 @@ func check_all(_game_map: RefCounted) -> void:
## Domination: the last player with at least one city wins.
##
## A player without cities is still considered alive while they hold any
## founder unit, since they can still settle. This prevents the check from
## firing on the very first turn that one side founds before the other has
## had a chance — a "haven't finished setting up" state, not a real victory.
func _check_domination() -> int:
var alive_players: Array[int] = []
for player: Variant in GameState.players:
@ -35,12 +41,22 @@ func _check_domination() -> int:
continue
if player.cities.size() > 0:
alive_players.append(player.index)
continue
if _has_living_founder(player):
alive_players.append(player.index)
if alive_players.size() == 1:
return alive_players[0]
return -1
func _has_living_founder(player: RefCounted) -> bool:
for unit: Variant in player.units:
if unit is UnitScript and unit.is_alive() and unit.can_found_city:
return true
return false
## Calculate a simple score for a player (used by victory/defeat screens).
## Points: 1 per population, 5 per city, 3 per tech, 2 per unit alive.
func calculate_score(player: RefCounted, _game_map: RefCounted) -> int: