Add multi-cell reach triggers

This commit is contained in:
2026-06-18 14:29:04 +09:00
parent 4f5e949d84
commit 0c0a49ad57
10 changed files with 173 additions and 54 deletions

View File

@@ -3240,11 +3240,11 @@ func _append_target_officers_progress_line(
func _append_destination_progress_line(result: Array[String], condition: Dictionary, pending := false) -> void:
var target := _condition_cell(condition.get("pos", []))
if not is_inside(target):
var targets := _condition_cells(condition)
if targets.is_empty():
return
var status := "reached" if _unit_reaches_tile(condition) else "not reached"
_append_progress_line(result, "Destination %s: %s" % [_format_cell(target), status], pending)
_append_progress_line(result, "Destination %s: %s" % [_format_cells(targets), status], pending)
func _append_turn_limit_progress_line(result: Array[String]) -> void:
@@ -3272,11 +3272,11 @@ func _append_after_event_progress_line(result: Array[String], event_id: String)
func _append_event_destination_progress_line(result: Array[String], when: Dictionary) -> void:
var target := _condition_cell(when.get("pos", []))
if not is_inside(target):
var targets := _condition_cells(when)
if targets.is_empty():
return
var status := "reached" if _unit_reaches_tile(when) else "not reached"
_append_progress_line(result, "Reach %s: %s" % [_format_cell(target), status])
_append_progress_line(result, "Reach %s: %s" % [_format_cells(targets), status])
func _append_turn_condition_progress_line(result: Array[String], condition: Dictionary, mode: String, pending := false) -> void:
@@ -3435,8 +3435,8 @@ func _is_turn_reached(condition: Dictionary) -> bool:
func _unit_reaches_tile(condition: Dictionary) -> bool:
var target := _condition_cell(condition.get("pos", []))
if not is_inside(target):
var targets := _condition_cells(condition)
if targets.is_empty():
return false
var team := str(condition.get("team", ""))
var unit_ids = condition.get("unit_ids", [])
@@ -3450,7 +3450,7 @@ func _unit_reaches_tile(condition: Dictionary) -> bool:
continue
if not _unit_matches_condition_ids(unit, unit_ids, officer_ids):
continue
if unit.get("pos", Vector2i(-9999, -9999)) == target:
if targets.has(unit.get("pos", Vector2i(-9999, -9999))):
return true
return false
@@ -3481,6 +3481,20 @@ func _condition_cell(pos_value) -> Vector2i:
return Vector2i(int(pos_value[0]), int(pos_value[1]))
func _condition_cells(source: Dictionary) -> Array[Vector2i]:
var result: Array[Vector2i] = []
if source.has("cells") and typeof(source["cells"]) == TYPE_ARRAY:
for pos_value in source["cells"]:
var cell := _condition_cell(pos_value)
if is_inside(cell) and not result.has(cell):
result.append(cell)
elif source.has("pos"):
var cell := _condition_cell(source.get("pos", []))
if is_inside(cell):
result.append(cell)
return result
func _condition_gate_open(condition: Dictionary) -> bool:
var after_event := str(condition.get("after_event", ""))
if after_event.is_empty():
@@ -3514,9 +3528,9 @@ func _collect_objective_cells(condition_group, result: Array[Vector2i]) -> void:
if condition_type != "unit_reaches_tile":
return
var cell := _condition_cell(condition_group.get("pos", []))
if is_inside(cell) and not result.has(cell):
result.append(cell)
for cell in _condition_cells(condition_group):
if not result.has(cell):
result.append(cell)
func _find_turn_limit(condition_group) -> int:
@@ -3608,10 +3622,10 @@ func _run_events(trigger_type: String, team := "", turn := -1, trigger_unit: Dic
func _unit_reaches_event_tile(unit: Dictionary, when: Dictionary) -> bool:
if unit.is_empty() or not unit.get("deployed", true) or not unit.get("alive", false):
return false
var target := _condition_cell(when.get("pos", []))
if not is_inside(target):
var targets := _condition_cells(when)
if targets.is_empty():
return false
if unit.get("pos", Vector2i(-9999, -9999)) != target:
if not targets.has(unit.get("pos", Vector2i(-9999, -9999))):
return false
return _unit_matches_condition_ids(unit, when.get("unit_ids", []), when.get("officer_ids", []))
@@ -3900,6 +3914,17 @@ func _format_cell(cell: Vector2i) -> String:
return "(%d, %d)" % [cell.x + 1, cell.y + 1]
func _format_cells(cells: Array[Vector2i]) -> String:
if cells.is_empty():
return ""
if cells.size() == 1:
return _format_cell(cells[0])
var labels := []
for cell in cells:
labels.append(_format_cell(cell))
return _join_strings(labels, ", ")
func _join_strings(values: Array, delimiter: String) -> String:
var text := ""
for value in values: