| 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 | |
| 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')
| -rw-r--r-- | src/battlemap/src/Battlemap.elm | 9 | ||||
| -rw-r--r-- | src/battlemap/src/Battlemap/Navigator.elm | 9 | ||||
| -rw-r--r-- | src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm | 56 | ||||
| -rw-r--r-- | src/battlemap/src/View.elm | 5 | ||||
| -rw-r--r-- | src/battlemap/src/View/Status.elm | 32 | 
5 files changed, 69 insertions, 42 deletions
| diff --git a/src/battlemap/src/Battlemap.elm b/src/battlemap/src/Battlemap.elm index d2e4523..f79966a 100644 --- a/src/battlemap/src/Battlemap.elm +++ b/src/battlemap/src/Battlemap.elm @@ -88,6 +88,13 @@ set_navigator start_loc movement_points attack_range can_cross bmap =                 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 +               )              )           )     } @@ -112,7 +119,7 @@ try_adding_step_to_navigator bmap can_cross dir =                          (Array.get (location_to_index bmap loc) bmap.content)                       of                          (Just tile) -> (Battlemap.Tile.get_cost tile) -                        Nothing -> 0 +                        Nothing -> 99                    )                 )           in diff --git a/src/battlemap/src/Battlemap/Navigator.elm b/src/battlemap/src/Battlemap/Navigator.elm index 6687b18..c4231e6 100644 --- a/src/battlemap/src/Battlemap/Navigator.elm +++ b/src/battlemap/src/Battlemap/Navigator.elm @@ -55,9 +55,11 @@ new : (        Battlemap.Location.Type ->        Int ->        Int -> -      (Battlemap.Location.Type -> Bool) -> Type +      (Battlemap.Location.Type -> Bool) -> +      (Battlemap.Location.Type -> Int) -> +      Type     ) -new start_loc mov_dist atk_dist can_cross_fun = +new start_loc mov_dist atk_dist can_cross_fun cost_fun =     {        starting_location = start_loc,        movement_dist = mov_dist, @@ -67,8 +69,9 @@ new start_loc mov_dist atk_dist can_cross_fun =           (Battlemap.Navigator.RangeIndicator.generate              start_loc              mov_dist -            atk_dist +            (mov_dist + atk_dist)              (can_cross_fun) +            (cost_fun)           )     } 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 diff --git a/src/battlemap/src/View.elm b/src/battlemap/src/View.elm index 8a956d1..90c56cd 100644 --- a/src/battlemap/src/View.elm +++ b/src/battlemap/src/View.elm @@ -20,14 +20,11 @@ view model =              []              (View.Controls.view)           ), +         (View.Status.view model),           (View.Battlemap.get_html              model.battlemap              32              (Dict.values model.characters) -         ), -         (Html.div -            [] -            [ (View.Status.view model) ]           )        ]     ) diff --git a/src/battlemap/src/View/Status.elm b/src/battlemap/src/View/Status.elm index de2a167..973588d 100644 --- a/src/battlemap/src/View/Status.elm +++ b/src/battlemap/src/View/Status.elm @@ -35,18 +35,24 @@ moving_character_text model =  view : Model.Type -> (Html.Html Event.Type)  view model = -   (Html.text -      ( -         (case model.state of -            Model.Default -> "Click on a character to control it." -            Model.MovingCharacterWithButtons -> (moving_character_text model) -            Model.MovingCharacterWithClick -> (moving_character_text model) -            Model.FocusingTile -> "Error: Unimplemented." -         ) -         ++ " " ++ -         (case model.error of -            Nothing -> "" -            (Just error) -> (Error.to_string error) +   (Html.div +      [ +      ] +      [ +         (Html.text +            ( +               (case model.state of +                  Model.Default -> "Click on a character to control it." +                  Model.MovingCharacterWithButtons -> (moving_character_text model) +                  Model.MovingCharacterWithClick -> (moving_character_text model) +                  Model.FocusingTile -> "Error: Unimplemented." +               ) +               ++ " " ++ +               (case model.error of +                  Nothing -> "" +                  (Just error) -> (Error.to_string error) +               ) +            )           ) -      ) +      ]     ) | 


