| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'client/elm')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/RangeIndicator.elm | 50 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Character.elm | 3 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Shim/Model.elm | 9 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Update/SelectCharacter.elm | 19 | 
4 files changed, 64 insertions, 17 deletions
| diff --git a/client/elm/battlemap/src/Battlemap/RangeIndicator.elm b/client/elm/battlemap/src/Battlemap/RangeIndicator.elm index d6c00cc..9276e49 100644 --- a/client/elm/battlemap/src/Battlemap/RangeIndicator.elm +++ b/client/elm/battlemap/src/Battlemap/RangeIndicator.elm @@ -84,12 +84,14 @@ get_closest ref indicator (prev_ref, prev_indicator) =  handle_neighbors : (        Battlemap.Location.Type -> +      Int -> +      Int ->        Type ->        (Dict.Dict Battlemap.Location.Ref Type) ->        (List Battlemap.Direction.Type) ->        (Dict.Dict Battlemap.Location.Ref Type)     ) -handle_neighbors loc indicator remaining directions = +handle_neighbors loc dist atk_dist indicator remaining directions =     case (Util.List.pop directions) of        Nothing -> remaining        (Just (head, tail)) -> @@ -102,16 +104,38 @@ handle_neighbors loc indicator remaining directions =                 )           in              case neighbor_indicator of -               Nothing -> (handle_neighbors loc indicator remaining tail) +               Nothing -> +                  (handle_neighbors +                     loc +                     dist +                     atk_dist +                     indicator +                     remaining +                     tail +                  )                 (Just neighbor) ->                    let -                     new_dist = (indicator.distance + neighbor.node_cost) +                     is_attack_range = (indicator.distance >= dist) +                     new_dist = +                        ( +                           if (is_attack_range) +                           then +                              (indicator.distance + 1) +                           else +                              (indicator.distance + neighbor.node_cost) +                        )                    in                       (handle_neighbors                          loc +                        dist +                        atk_dist                          indicator                          ( -                           if (new_dist < neighbor.distance) +                           if +                              ( +                                 (new_dist < neighbor.distance) +                                 && (new_dist <= atk_dist) +                              )                             then                                (Dict.insert                                   (Battlemap.Location.get_ref neighbor_loc) @@ -131,10 +155,11 @@ search : (        (Dict.Dict Battlemap.Location.Ref Type) ->        (Dict.Dict Battlemap.Location.Ref Type) ->        Int -> +      Int ->        (Dict.Dict Battlemap.Location.Ref Type)     ) -search result remaining dist = -   if (Dict.isEmpty (Debug.log "Search call" remaining)) +search result remaining dist atk_dist = +   if (Dict.isEmpty remaining)     then        result     else @@ -145,7 +170,7 @@ search result remaining dist =                 (                    (-1,-1),                    { -                     distance = (dist + 1), +                     distance = (atk_dist + 1),                       path = [],                       node_cost = 99                    } @@ -157,6 +182,8 @@ search result remaining dist =              (Dict.insert min_loc_ref min result)              (handle_neighbors                 (Battlemap.Location.from_ref min_loc_ref) +               dist +               atk_dist                 min                 (Dict.remove min_loc_ref remaining)                 [ @@ -167,6 +194,7 @@ search result remaining dist =                 ]              )              dist +            atk_dist           )  grid_to_range_indicators : ( @@ -214,17 +242,19 @@ generate : (        Battlemap.Type ->        Battlemap.Location.Type ->        Int -> +      Int ->        (Dict.Dict Battlemap.Location.Ref Type)     ) -generate battlemap location dist = +generate battlemap location dist atk_dist =     (search        Dict.empty        (grid_to_range_indicators           battlemap           location -         dist -         (generate_grid location dist (-dist) []) +         atk_dist +         (generate_grid location atk_dist (-atk_dist) [])           Dict.empty        )        dist +      atk_dist     ) diff --git a/client/elm/battlemap/src/Character.elm b/client/elm/battlemap/src/Character.elm index 6b6a7c7..41cfc84 100644 --- a/client/elm/battlemap/src/Character.elm +++ b/client/elm/battlemap/src/Character.elm @@ -9,7 +9,8 @@ type alias Type =        icon : String,        portrait : String,        location : Battlemap.Location.Type, -      movement_points : Int +      movement_points : Int, +      atk_dist : Int     }  type alias Ref = String diff --git a/client/elm/battlemap/src/Shim/Model.elm b/client/elm/battlemap/src/Shim/Model.elm index 4a0146d..5738aa4 100644 --- a/client/elm/battlemap/src/Shim/Model.elm +++ b/client/elm/battlemap/src/Shim/Model.elm @@ -21,7 +21,8 @@ generate =                 icon = "Icon2",                 portrait = "Portrait2",                 location = {x = 0, y = 1}, -               movement_points = 5 +               movement_points = 5, +               atk_dist = 1              }              (Dict.insert                 "1" @@ -31,7 +32,8 @@ generate =                    icon = "Icon1",                    portrait = "Portrait1",                    location = {x = 1, y = 0}, -                  movement_points = 4 +                  movement_points = 4, +                  atk_dist = 2                 }                 (Dict.insert                    "0" @@ -41,7 +43,8 @@ generate =                       icon = "Icon0",                       portrait = "Portrait0",                       location = {x = 0, y = 0}, -                     movement_points = 3 +                     movement_points = 3, +                     atk_dist = 1                    }                    Dict.empty                 ) diff --git a/client/elm/battlemap/src/Update/SelectCharacter.elm b/client/elm/battlemap/src/Update/SelectCharacter.elm index 4e23e92..b2b28ca 100644 --- a/client/elm/battlemap/src/Update/SelectCharacter.elm +++ b/client/elm/battlemap/src/Update/SelectCharacter.elm @@ -14,16 +14,28 @@ import Battlemap.RangeIndicator  import Model  display_range : ( +      Int ->        Battlemap.Location.Ref ->        Battlemap.RangeIndicator.Type ->        Battlemap.Type ->        Battlemap.Type     ) -display_range loc_ref indicator bmap = +display_range dist loc_ref indicator bmap =     (Battlemap.apply_to_tile_unsafe        bmap        (Battlemap.Location.from_ref loc_ref) -      (\e -> {e | mod_level = (Just Battlemap.Tile.CanBeReached)}) +      (\e -> +         {e | +            mod_level = +               ( +                  if (indicator.distance <= dist) +                  then +                     (Just Battlemap.Tile.CanBeReached) +                  else +                     (Just Battlemap.Tile.CanBeAttacked) +               ) +         } +      )     ) @@ -38,6 +50,7 @@ apply_to model char_id =                    model.battlemap                    char.location                    char.movement_points +                  (char.movement_points + char.atk_dist)                 )           in              {model | @@ -45,7 +58,7 @@ apply_to model char_id =                 battlemap =                    (                       (Dict.foldl -                        (display_range) +                        (display_range char.movement_points)                          (Battlemap.apply_to_all_tiles                             model.battlemap                             (Battlemap.Tile.reset_tile) | 


