summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2017-10-20 14:01:31 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2017-10-20 14:01:31 +0200 |
commit | 9942e31832d785e3b9a102c79583da1ceccb199e (patch) | |
tree | 7fb13349559b7039db722a59904dedfbbc9ad555 | |
parent | ad2f07e15042d4387d49c8ee935990b5260d1638 (diff) |
Tries, and fails, to fix the Attack Range issue.
-rw-r--r-- | src/battlemap/src/Battlemap.elm | 65 | ||||
-rw-r--r-- | src/battlemap/src/Battlemap/Navigator.elm | 14 | ||||
-rw-r--r-- | src/battlemap/src/Battlemap/Navigator/Path.elm | 11 | ||||
-rw-r--r-- | src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm | 131 | ||||
-rw-r--r-- | src/battlemap/src/Constants/Movement.elm | 10 | ||||
-rw-r--r-- | src/battlemap/src/Model/RequestDirection.elm | 19 | ||||
-rw-r--r-- | src/battlemap/src/Model/SelectCharacter.elm | 9 |
7 files changed, 140 insertions, 119 deletions
diff --git a/src/battlemap/src/Battlemap.elm b/src/battlemap/src/Battlemap.elm index 8449559..a3a0c76 100644 --- a/src/battlemap/src/Battlemap.elm +++ b/src/battlemap/src/Battlemap.elm @@ -19,6 +19,10 @@ import Battlemap.Tile import Battlemap.Direction import Battlemap.Location +import Character + +import Constants.Movement + -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -46,6 +50,37 @@ has_location bmap loc = && (loc.y < bmap.height) ) +tile_cost_function : ( + Type -> + Battlemap.Location.Type -> + (List Character.Type) -> + Battlemap.Location.Type -> + Int + ) +tile_cost_function bmap start_loc char_list loc = + if + ( + (Battlemap.Location.get_ref start_loc) + == + (Battlemap.Location.get_ref loc) + ) + then + 0 + else + case + (Array.get (location_to_index bmap loc) bmap.content) + of + (Just tile) -> + if + (List.any + (\c -> ((Character.get_location c) == loc)) + char_list + ) + then + Constants.Movement.cost_when_occupied_tile + else + (Battlemap.Tile.get_cost tile) + Nothing -> Constants.Movement.cost_when_out_of_bounds -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -84,11 +119,11 @@ set_navigator : ( Battlemap.Location.Type -> Int -> Int -> - (Battlemap.Location.Type -> Bool) -> + (List Character.Type) -> Type -> Type ) -set_navigator start_loc movement_points attack_range can_cross bmap = +set_navigator start_loc movement_points attack_range character_list bmap = {bmap | navigator = (Just @@ -96,13 +131,10 @@ set_navigator start_loc movement_points attack_range can_cross bmap = start_loc movement_points attack_range - (\loc -> ((can_cross loc) && (has_location bmap loc))) - (\loc -> - case - (Array.get (location_to_index bmap loc) bmap.content) - of - (Just tile) -> (Battlemap.Tile.get_cost tile) - Nothing -> 99 + (tile_cost_function + bmap + start_loc + character_list ) ) ) @@ -110,11 +142,11 @@ set_navigator start_loc movement_points attack_range can_cross bmap = try_adding_step_to_navigator : ( Type -> - (Battlemap.Location.Type -> Bool) -> + (List Character.Type) -> Battlemap.Direction.Type -> (Maybe Type) ) -try_adding_step_to_navigator bmap can_cross dir = +try_adding_step_to_navigator bmap character_list dir = case bmap.navigator of (Just navigator) -> let @@ -122,13 +154,10 @@ try_adding_step_to_navigator bmap can_cross dir = (Battlemap.Navigator.try_adding_step navigator dir - (\loc -> ((can_cross loc) && (has_location bmap loc))) - (\loc -> - case - (Array.get (location_to_index bmap loc) bmap.content) - of - (Just tile) -> (Battlemap.Tile.get_cost tile) - Nothing -> 99 + (tile_cost_function + bmap + (Battlemap.Navigator.get_starting_location navigator) + character_list ) ) in diff --git a/src/battlemap/src/Battlemap/Navigator.elm b/src/battlemap/src/Battlemap/Navigator.elm index 6db917a..aa664a1 100644 --- a/src/battlemap/src/Battlemap/Navigator.elm +++ b/src/battlemap/src/Battlemap/Navigator.elm @@ -4,6 +4,7 @@ module Battlemap.Navigator exposing Summary, new, get_current_location, + get_starting_location, get_remaining_points, get_range_markers, get_summary, @@ -56,11 +57,10 @@ new : ( Battlemap.Location.Type -> Int -> Int -> - (Battlemap.Location.Type -> Bool) -> (Battlemap.Location.Type -> Int) -> Type ) -new start_loc mov_dist atk_dist can_cross_fun cost_fun = +new start_loc mov_dist atk_dist cost_fun = { starting_location = start_loc, movement_dist = mov_dist, @@ -71,7 +71,6 @@ new start_loc mov_dist atk_dist can_cross_fun cost_fun = start_loc mov_dist (mov_dist + atk_dist) - (can_cross_fun) (cost_fun) ) } @@ -80,9 +79,12 @@ get_current_location : Type -> Battlemap.Location.Type get_current_location navigator = (Battlemap.Navigator.Path.get_current_location navigator.path) +get_starting_location : Type -> Battlemap.Location.Type +get_starting_location navigator = navigator.starting_location + get_remaining_points : Type -> Int get_remaining_points navigator = - (Battlemap.Navigator.Path.get_remaining_points navigator.path) + (Battlemap.Navigator.Path.get_remaining_points navigator.path) get_range_markers : ( Type -> @@ -126,14 +128,12 @@ clear_path navigator = try_adding_step : ( Type -> Battlemap.Direction.Type -> - (Battlemap.Location.Type -> Bool) -> (Battlemap.Location.Type -> Int) -> (Maybe Type) ) -try_adding_step navigator dir can_cross cost_fun = +try_adding_step navigator dir cost_fun = case (Battlemap.Navigator.Path.try_following_direction - can_cross cost_fun (Just navigator.path) dir diff --git a/src/battlemap/src/Battlemap/Navigator/Path.elm b/src/battlemap/src/Battlemap/Navigator/Path.elm index 53e12c0..d0a430f 100644 --- a/src/battlemap/src/Battlemap/Navigator/Path.elm +++ b/src/battlemap/src/Battlemap/Navigator/Path.elm @@ -15,6 +15,8 @@ import Util.List import Battlemap.Direction import Battlemap.Location +import Constants.Movement + -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -134,14 +136,14 @@ get_remaining_points path = path.remaining_points get_summary : Type -> (List Battlemap.Direction.Type) get_summary path = path.previous_directions + try_following_direction : ( - (Battlemap.Location.Type -> Bool) -> (Battlemap.Location.Type -> Int) -> (Maybe Type) -> Battlemap.Direction.Type -> (Maybe Type) ) -try_following_direction can_cross cost_fun maybe_path dir = +try_following_direction cost_fun maybe_path dir = case maybe_path of (Just path) -> let @@ -150,8 +152,9 @@ try_following_direction can_cross cost_fun maybe_path dir = path.current_location dir ) + next_location_cost = (cost_fun next_location) in - if (can_cross next_location) + if (next_location_cost <= Constants.Movement.max_points) then if (has_been_to path next_location) then @@ -161,7 +164,7 @@ try_following_direction can_cross cost_fun maybe_path dir = path dir next_location - (cost_fun next_location) + next_location_cost ) else Nothing diff --git a/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm b/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm index 67aef1c..3b2495b 100644 --- a/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm +++ b/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm @@ -13,6 +13,8 @@ import Battlemap.Direction import Battlemap.Location import Battlemap.Marker +import Constants.Movement + import Util.List -------------------------------------------------------------------------------- @@ -147,22 +149,31 @@ handle_neighbors loc dist atk_dist indicator remaining directions = atk_dist indicator ( - if (new_dist < neighbor.distance) + if + ( + (new_dist < neighbor.distance) + || + ( + (neighbor.distance > dist) + && (new_range < neighbor.range) + ) + ) then (Dict.insert (Battlemap.Location.get_ref neighbor_loc) - {neighbor | - distance = new_dist, - range = - ( - if (new_dist > dist) - then - new_range - else - 0 - ), - path = (head :: indicator.path) - } + if (new_dist > dist) + then + {neighbor | + distance = dist, + range = new_range, + path = (head :: indicator.path) + } + else + {neighbor | + distance = new_dist, + range = 0, + path = (head :: indicator.path) + } remaining ) else @@ -190,10 +201,10 @@ search result remaining dist atk_dist = ( (-1,-1), { - distance = 999999, + distance = Constants.Movement.cost_when_out_of_bounds, path = [], - node_cost = 999999, - range = 999999, + node_cost = Constants.Movement.cost_when_out_of_bounds, + range = Constants.Movement.cost_when_out_of_bounds, marker = Battlemap.Marker.CanAttack } ) @@ -233,56 +244,56 @@ search result remaining dist atk_dist = ) grid_to_range_indicators : ( - (Battlemap.Location.Type -> Bool) -> (Battlemap.Location.Type -> Int) -> Battlemap.Location.Type -> (List Battlemap.Location.Type) -> (Dict.Dict Battlemap.Location.Ref Type) -> (Dict.Dict Battlemap.Location.Ref Type) ) -grid_to_range_indicators can_cross_fun cost_fun location grid result = +grid_to_range_indicators cost_fun location grid result = case (Util.List.pop grid) of Nothing -> result (Just (head, tail)) -> - if (can_cross_fun head) - then - (grid_to_range_indicators - (can_cross_fun) - (cost_fun) - location - tail - (Dict.insert - (Battlemap.Location.get_ref head) - ( - if ((location.x == head.x) && (location.y == head.y)) - then - { - distance = 0, - path = [], - node_cost = (cost_fun head), - range = 0, - marker = Battlemap.Marker.CanGoTo - } - else - { - distance = 99999, - path = [], - node_cost = (cost_fun head), - range = 99999, - marker = Battlemap.Marker.CanGoTo - } + let + head_cost = (cost_fun head) + in + if (head_cost /= Constants.Movement.cost_when_out_of_bounds) + then + (grid_to_range_indicators + (cost_fun) + location + tail + (Dict.insert + (Battlemap.Location.get_ref head) + ( + if ((location.x == head.x) && (location.y == head.y)) + then + { + distance = 0, + path = [], + node_cost = head_cost, + range = 0, + marker = Battlemap.Marker.CanGoTo + } + else + { + distance = Constants.Movement.max_points, + path = [], + node_cost = head_cost, + range = Constants.Movement.max_points, + marker = Battlemap.Marker.CanGoTo + } + ) + result ) + ) + else + (grid_to_range_indicators + (cost_fun) + location + tail result ) - ) - else - (grid_to_range_indicators - (can_cross_fun) - (cost_fun) - location - tail - result - ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -291,23 +302,15 @@ 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 cost_fun = +generate location dist atk_dist cost_fun = (Dict.filter - (\loc_ref range_indicator -> - ( - (range_indicator.distance <= dist) - || - (range_indicator.range <= (atk_dist - dist)) - ) - ) + (\loc_ref range_indicator -> (range_indicator.range <= (atk_dist - dist))) (search Dict.empty (grid_to_range_indicators - (can_cross_fun) (cost_fun) location (generate_grid location atk_dist (-atk_dist) []) diff --git a/src/battlemap/src/Constants/Movement.elm b/src/battlemap/src/Constants/Movement.elm new file mode 100644 index 0000000..a2a5c1e --- /dev/null +++ b/src/battlemap/src/Constants/Movement.elm @@ -0,0 +1,10 @@ +module Constants.Movement exposing (..) + +max_points : Int +max_points = 200 + +cost_when_occupied_tile : Int +cost_when_occupied_tile = 201 + +cost_when_out_of_bounds : Int +cost_when_out_of_bounds = 255 diff --git a/src/battlemap/src/Model/RequestDirection.elm b/src/battlemap/src/Model/RequestDirection.elm index cf600e6..44c4225 100644 --- a/src/battlemap/src/Model/RequestDirection.elm +++ b/src/battlemap/src/Model/RequestDirection.elm @@ -20,24 +20,7 @@ make_it_so model dir = new_bmap = (Battlemap.try_adding_step_to_navigator model.battlemap - (\loc -> - (List.all - (\char -> - ( - ((Character.get_ref char) == char_id) - || - ( - (Battlemap.Location.get_ref - (Character.get_location char) - ) - /= - (Battlemap.Location.get_ref loc) - ) - ) - ) - (Dict.values model.characters) - ) - ) + (Dict.values model.characters) dir ) in diff --git a/src/battlemap/src/Model/SelectCharacter.elm b/src/battlemap/src/Model/SelectCharacter.elm index 06fef25..3795f07 100644 --- a/src/battlemap/src/Model/SelectCharacter.elm +++ b/src/battlemap/src/Model/SelectCharacter.elm @@ -21,14 +21,7 @@ make_it_so model char_id = (Character.get_location char) (Character.get_movement_points char) (Character.get_attack_range char) - (\loc -> - (loc == (Character.get_location char)) - || - (List.all - (\c -> ((Character.get_location c) /= loc)) - (Dict.values model.characters) - ) - ) + (Dict.values model.characters) model.battlemap ) } |