summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2017-10-19 16:27:39 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2017-10-19 16:27:39 +0200 |
commit | ebb50d0c4063009dffcd3031ee2d6b82a28023bd (patch) | |
tree | ff9e7b8c661b49f2ce0b13ca674514a7164a410a /src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm | |
parent | 4ca4778bad6f586b38e41df9e571a9331e73b2f1 (diff) |
Partially fixes Navigator.
Still borked: click on a reachable tile, then click on another reachable
tile doesn't seem to properly change the path.
Diffstat (limited to 'src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm')
-rw-r--r-- | src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm b/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm index a8cac8e..9271a45 100644 --- a/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm +++ b/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm @@ -176,9 +176,9 @@ search result remaining dist atk_dist = ( (-1,-1), { - distance = (atk_dist + 1), + distance = 999999, path = [], - node_cost = 99, + node_cost = 999999, marker = Battlemap.Marker.CanAttack } ) @@ -219,65 +219,79 @@ search result remaining dist atk_dist = grid_to_range_indicators : ( (Battlemap.Location.Type -> Bool) -> + (Battlemap.Location.Type -> Int) -> Battlemap.Location.Type -> - Int -> (List Battlemap.Location.Type) -> (Dict.Dict Battlemap.Location.Ref Type) -> (Dict.Dict Battlemap.Location.Ref Type) ) -grid_to_range_indicators can_cross_fun location dist grid result = +grid_to_range_indicators can_cross_fun cost_fun location grid result = case (Util.List.pop grid) of Nothing -> result (Just (head, tail)) -> if (can_cross_fun head) then - -- TODO: test if the current char can cross that tile. - -- TODO: get tile cost. (grid_to_range_indicators (can_cross_fun) + (cost_fun) location - dist tail (Dict.insert (Battlemap.Location.get_ref head) { distance = ( - if ((location.x == head.x) && (location.y == head.y)) + if + ( + (location.x == head.x) + && (location.y == head.y) + ) then 0 else - (dist + 1) + 9999 ), path = [], - node_cost = 1, + node_cost = (cost_fun head), marker = Battlemap.Marker.CanGoTo } result ) ) else - (grid_to_range_indicators (can_cross_fun) location dist tail result) + (grid_to_range_indicators + (can_cross_fun) + (cost_fun) + location + tail + result + ) generate : ( Battlemap.Location.Type -> Int -> Int -> (Battlemap.Location.Type -> Bool) -> + (Battlemap.Location.Type -> Int) -> (Dict.Dict Battlemap.Location.Ref Type) ) -generate location dist atk_dist can_cross_fun = - (search - Dict.empty - (grid_to_range_indicators - (can_cross_fun) - location - atk_dist - (generate_grid location atk_dist (-atk_dist) []) +generate location dist atk_dist can_cross_fun cost_fun = + (Dict.filter + (\loc_ref range_indicator -> + (range_indicator.distance <= atk_dist) + ) + (search Dict.empty + (grid_to_range_indicators + (can_cross_fun) + (cost_fun) + location + (generate_grid location atk_dist (-atk_dist) []) + Dict.empty + ) + dist + atk_dist ) - dist - atk_dist ) get_marker : Type -> Battlemap.Marker.Type |