Add multi-cell reach triggers
This commit is contained in:
@@ -239,6 +239,50 @@ if (Has-Prop $campaign "chapters") {
|
||||
}
|
||||
}
|
||||
|
||||
function Check-Unit-Reaches-Cells($Source, [string]$Context, [int]$Width, [int]$Height, $Rows) {
|
||||
$hasPos = Has-Prop $Source "pos"
|
||||
$hasCells = Has-Prop $Source "cells"
|
||||
if ($hasPos -and $hasCells) {
|
||||
Fail "$Context must use either pos or cells, not both."
|
||||
}
|
||||
if (-not $hasPos -and -not $hasCells) {
|
||||
Fail "$Context is missing pos or cells."
|
||||
}
|
||||
|
||||
$cellEntries = @()
|
||||
if ($hasPos) {
|
||||
$cellEntries += ,$Source.pos
|
||||
} else {
|
||||
if (-not ($Source.cells -is [System.Array])) {
|
||||
Fail "$Context cells must be an array."
|
||||
}
|
||||
$cellEntries = @($Source.cells)
|
||||
if ($cellEntries.Count -le 0) {
|
||||
Fail "$Context cells must not be empty."
|
||||
}
|
||||
}
|
||||
|
||||
$seenCells = New-Object System.Collections.Generic.HashSet[string]
|
||||
foreach ($entry in $cellEntries) {
|
||||
$cell = Resolve-Cell $entry $Context
|
||||
$x = [int]$cell.X
|
||||
$y = [int]$cell.Y
|
||||
if ($Width -ge 0 -and $Height -ge 0 -and ($x -lt 0 -or $y -lt 0 -or $x -ge $Width -or $y -ge $Height)) {
|
||||
Fail "$Context is outside map at [$x,$y]."
|
||||
}
|
||||
if ($null -ne $Rows) {
|
||||
$terrainKey = Terrain-At $Rows $x $y
|
||||
if ([int]$terrain.$terrainKey.move_cost.foot -ge 99 -and [int]$terrain.$terrainKey.move_cost.mounted -ge 99 -and [int]$terrain.$terrainKey.move_cost.archer -ge 99) {
|
||||
Fail "$Context targets impassable terrain at [$x,$y]."
|
||||
}
|
||||
}
|
||||
$key = "$x,$y"
|
||||
if (-not $seenCells.Add($key)) {
|
||||
Fail "$Context has duplicate cell [$x,$y]."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Check-Condition($Condition, [string]$ScenarioId, $EventIds, [int]$Width = -1, [int]$Height = -1, $Rows = $null, $KnownUnitIds = $null) {
|
||||
if ($Condition -is [System.Array]) {
|
||||
foreach ($entry in $Condition) {
|
||||
@@ -279,21 +323,7 @@ function Check-Condition($Condition, [string]$ScenarioId, $EventIds, [int]$Width
|
||||
}
|
||||
}
|
||||
if ($type -eq "unit_reaches_tile") {
|
||||
if (-not (Has-Prop $Condition "pos")) {
|
||||
Fail "Scenario $ScenarioId unit_reaches_tile condition is missing pos."
|
||||
}
|
||||
$cell = Resolve-Cell $Condition.pos "Scenario $ScenarioId unit_reaches_tile condition"
|
||||
$x = [int]$cell.X
|
||||
$y = [int]$cell.Y
|
||||
if ($Width -ge 0 -and $Height -ge 0 -and ($x -lt 0 -or $y -lt 0 -or $x -ge $Width -or $y -ge $Height)) {
|
||||
Fail "Scenario $ScenarioId unit_reaches_tile condition is outside map at [$x,$y]."
|
||||
}
|
||||
if ($null -ne $Rows) {
|
||||
$terrainKey = Terrain-At $Rows $x $y
|
||||
if ([int]$terrain.$terrainKey.move_cost.foot -ge 99 -and [int]$terrain.$terrainKey.move_cost.mounted -ge 99 -and [int]$terrain.$terrainKey.move_cost.archer -ge 99) {
|
||||
Fail "Scenario $ScenarioId unit_reaches_tile condition targets impassable terrain at [$x,$y]."
|
||||
}
|
||||
}
|
||||
Check-Unit-Reaches-Cells $Condition "Scenario $ScenarioId unit_reaches_tile condition" $Width $Height $Rows
|
||||
$unitIdsValue = $null
|
||||
if (Has-Prop $Condition "unit_ids") {
|
||||
$unitIdsValue = $Condition.unit_ids
|
||||
@@ -336,19 +366,7 @@ function Check-Condition($Condition, [string]$ScenarioId, $EventIds, [int]$Width
|
||||
}
|
||||
|
||||
function Check-Unit-Reaches-Event-When($When, [string]$ScenarioId, [int]$Width, [int]$Height, $Rows, $KnownUnitIds) {
|
||||
if (-not (Has-Prop $When "pos")) {
|
||||
Fail "Scenario $ScenarioId unit_reaches_tile event is missing pos."
|
||||
}
|
||||
$cell = Resolve-Cell $When.pos "Scenario $ScenarioId unit_reaches_tile event"
|
||||
$x = [int]$cell.X
|
||||
$y = [int]$cell.Y
|
||||
if ($x -lt 0 -or $y -lt 0 -or $x -ge $Width -or $y -ge $Height) {
|
||||
Fail "Scenario $ScenarioId unit_reaches_tile event is outside map at [$x,$y]."
|
||||
}
|
||||
$terrainKey = Terrain-At $Rows $x $y
|
||||
if ([int]$terrain.$terrainKey.move_cost.foot -ge 99 -and [int]$terrain.$terrainKey.move_cost.mounted -ge 99 -and [int]$terrain.$terrainKey.move_cost.archer -ge 99) {
|
||||
Fail "Scenario $ScenarioId unit_reaches_tile event targets impassable terrain at [$x,$y]."
|
||||
}
|
||||
Check-Unit-Reaches-Cells $When "Scenario $ScenarioId unit_reaches_tile event" $Width $Height $Rows
|
||||
|
||||
$unitIdsValue = $null
|
||||
if (Has-Prop $When "unit_ids") {
|
||||
|
||||
Reference in New Issue
Block a user