summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'elm/battlemap/src/Battlemap')
-rw-r--r--elm/battlemap/src/Battlemap/Direction.elm17
-rw-r--r--elm/battlemap/src/Battlemap/Location.elm44
-rw-r--r--elm/battlemap/src/Battlemap/Marker.elm5
-rw-r--r--elm/battlemap/src/Battlemap/Navigator.elm141
-rw-r--r--elm/battlemap/src/Battlemap/Navigator/Move.elm157
-rw-r--r--elm/battlemap/src/Battlemap/Navigator/Path.elm168
-rw-r--r--elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm287
-rw-r--r--elm/battlemap/src/Battlemap/Tile.elm25
8 files changed, 0 insertions, 844 deletions
diff --git a/elm/battlemap/src/Battlemap/Direction.elm b/elm/battlemap/src/Battlemap/Direction.elm
deleted file mode 100644
index 5aad141..0000000
--- a/elm/battlemap/src/Battlemap/Direction.elm
+++ /dev/null
@@ -1,17 +0,0 @@
-module Battlemap.Direction exposing (Type(..), opposite_of)
-
-type Type =
- None
- | Left
- | Right
- | Up
- | Down
-
-opposite_of : Type -> Type
-opposite_of d =
- case d of
- Left -> Right
- Right -> Left
- Up -> Down
- Down -> Up
- None -> None
diff --git a/elm/battlemap/src/Battlemap/Location.elm b/elm/battlemap/src/Battlemap/Location.elm
deleted file mode 100644
index 36f0c4d..0000000
--- a/elm/battlemap/src/Battlemap/Location.elm
+++ /dev/null
@@ -1,44 +0,0 @@
-module Battlemap.Location exposing (..)
-
-import Battlemap.Direction
-
-type alias Type =
- {
- x : Int,
- y : Int
- }
-
-type alias Ref = (Int, Int)
-
-neighbor : Type -> Battlemap.Direction.Type -> Type
-neighbor loc dir =
- case dir of
- Battlemap.Direction.Right -> {loc | x = (loc.x + 1)}
- Battlemap.Direction.Left -> {loc | x = (loc.x - 1)}
- Battlemap.Direction.Up -> {loc | y = (loc.y - 1)}
- Battlemap.Direction.Down -> {loc | y = (loc.y + 1)}
- Battlemap.Direction.None -> loc
-
-get_ref : Type -> Ref
-get_ref l =
- (l.x, l.y)
-
-from_ref : Ref -> Type
-from_ref (x, y) =
- {x = x, y = y}
-
-dist : Type -> Type -> Int
-dist loc_a loc_b =
- if (loc_a.x > loc_b.x)
- then
- if (loc_a.y > loc_b.y)
- then
- ((loc_a.x - loc_b.x) + (loc_a.y - loc_b.y))
- else
- ((loc_a.x - loc_b.x) + (loc_b.y - loc_a.y))
- else
- if (loc_a.y > loc_b.y)
- then
- ((loc_b.x - loc_a.x) + (loc_a.y - loc_b.y))
- else
- ((loc_b.x - loc_a.x) + (loc_b.y - loc_a.y))
diff --git a/elm/battlemap/src/Battlemap/Marker.elm b/elm/battlemap/src/Battlemap/Marker.elm
deleted file mode 100644
index ebefce6..0000000
--- a/elm/battlemap/src/Battlemap/Marker.elm
+++ /dev/null
@@ -1,5 +0,0 @@
-module Battlemap.Marker exposing (Type(..))
-
-type Type =
- CanAttack
- | CanGoTo
diff --git a/elm/battlemap/src/Battlemap/Navigator.elm b/elm/battlemap/src/Battlemap/Navigator.elm
deleted file mode 100644
index 6687b18..0000000
--- a/elm/battlemap/src/Battlemap/Navigator.elm
+++ /dev/null
@@ -1,141 +0,0 @@
-module Battlemap.Navigator exposing
- (
- Type,
- Summary,
- new,
- get_current_location,
- get_remaining_points,
- get_range_markers,
- get_summary,
- try_adding_step,
- try_getting_path_to
- )
-
-import Dict
-
-import Battlemap.Location
-import Battlemap.Direction
-import Battlemap.Marker
-
-import Battlemap.Navigator.Path
-import Battlemap.Navigator.RangeIndicator
-
---------------------------------------------------------------------------------
--- TYPES -----------------------------------------------------------------------
---------------------------------------------------------------------------------
-type alias Type =
- {
- starting_location: Battlemap.Location.Type,
- movement_dist: Int,
- attack_dist: Int,
- path: Battlemap.Navigator.Path.Type,
- range_indicators:
- (Dict.Dict
- Battlemap.Location.Ref
- Battlemap.Navigator.RangeIndicator.Type
- )
- }
-
-type alias Summary =
- {
- starting_location: Battlemap.Location.Type,
- path: (List Battlemap.Direction.Type),
- markers: (List (Battlemap.Location.Ref, Battlemap.Marker.Type))
- }
---------------------------------------------------------------------------------
--- LOCAL -----------------------------------------------------------------------
---------------------------------------------------------------------------------
-
-
---------------------------------------------------------------------------------
--- EXPORTED --------------------------------------------------------------------
---------------------------------------------------------------------------------
-
-new : (
- Battlemap.Location.Type ->
- Int ->
- Int ->
- (Battlemap.Location.Type -> Bool) -> Type
- )
-new start_loc mov_dist atk_dist can_cross_fun =
- {
- starting_location = start_loc,
- movement_dist = mov_dist,
- attack_dist = atk_dist,
- path = (Battlemap.Navigator.Path.new start_loc mov_dist),
- range_indicators =
- (Battlemap.Navigator.RangeIndicator.generate
- start_loc
- mov_dist
- atk_dist
- (can_cross_fun)
- )
- }
-
-get_current_location : Type -> Battlemap.Location.Type
-get_current_location navigator =
- (Battlemap.Navigator.Path.get_current_location navigator.path)
-
-get_remaining_points : Type -> Int
-get_remaining_points navigator =
- (Battlemap.Navigator.Path.get_remaining_points navigator.path)
-
-get_range_markers : (
- Type ->
- (List
- (Battlemap.Location.Ref, Battlemap.Navigator.RangeIndicator.Type)
- )
- )
-get_range_markers navigator = (Dict.toList navigator.range_indicators)
-
-get_summary : Type -> Summary
-get_summary navigator =
- {
- starting_location = navigator.starting_location,
- path = (Battlemap.Navigator.Path.get_summary navigator.path),
- markers =
- (List.map
- (\(loc, range_indicator) ->
- (
- loc,
- (Battlemap.Navigator.RangeIndicator.get_marker
- range_indicator
- )
- )
- )
- (Dict.toList
- navigator.range_indicators
- )
- )
- }
-
-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 =
- case
- (Battlemap.Navigator.Path.try_following_direction
- can_cross
- cost_fun
- (Just navigator.path)
- dir
- )
- of
- (Just path) -> (Just {navigator | path = path})
- Nothing -> Nothing
-
-try_getting_path_to : (
- Type ->
- Battlemap.Location.Ref ->
- (Maybe (List Battlemap.Direction.Type))
- )
-try_getting_path_to navigator loc_ref =
- case (Dict.get loc_ref navigator.range_indicators) of
- (Just target) ->
- (Just (Battlemap.Navigator.RangeIndicator.get_path target))
- Nothing -> Nothing
-
diff --git a/elm/battlemap/src/Battlemap/Navigator/Move.elm b/elm/battlemap/src/Battlemap/Navigator/Move.elm
deleted file mode 100644
index 9d7a17b..0000000
--- a/elm/battlemap/src/Battlemap/Navigator/Move.elm
+++ /dev/null
@@ -1,157 +0,0 @@
-module Battlemap.Navigator.Move exposing (to)
-
-import Set
-import List
-
-import Battlemap
-import Battlemap.Direction
-import Battlemap.Location
-import Battlemap.Tile
-import Battlemap.Navigator
-
-import Character
-
-import Util.List
-
-can_move_to_new_tile : (
- Battlemap.Navigator.Type ->
- Battlemap.Type ->
- Battlemap.Location.Type ->
- Bool
- )
-can_move_to_new_tile nav battlemap next_location =
- (
- (nav.remaining_points > 0)
- && (Battlemap.has_location battlemap next_location)
- && (nav.current_location /= next_location)
- &&
- (not
- (Set.member
- (Battlemap.Location.get_ref next_location)
- nav.visited_locations
- )
- )
- )
-
-battlemap_move_to : (
- Battlemap.Type ->
- Battlemap.Location.Type ->
- Battlemap.Direction.Type ->
- Battlemap.Location.Type ->
- Battlemap.Type
- )
-battlemap_move_to battlemap current_loc dir next_loc =
- (Battlemap.apply_to_tile_unsafe
- (Battlemap.apply_to_tile_unsafe
- battlemap
- current_loc
- (Battlemap.Tile.set_direction dir)
- )
- next_loc
- (Battlemap.Tile.set_direction dir)
- )
-
-navigator_move_to : (
- Battlemap.Navigator.Type ->
- Battlemap.Direction.Type ->
- Battlemap.Location.Type ->
- Battlemap.Navigator.Type
- )
-navigator_move_to nav dir next_loc =
- {nav |
- current_location = next_loc,
- visited_locations =
- (Set.insert
- (Battlemap.Location.get_ref nav.current_location)
- nav.visited_locations
- ),
- previous_directions = (dir :: nav.previous_directions),
- remaining_points = (nav.remaining_points - 1)
- }
-
-battlemap_backtrack : (
- Battlemap.Type ->
- Battlemap.Location.Type ->
- Battlemap.Type
- )
-battlemap_backtrack battlemap current_loc =
- (Battlemap.apply_to_tile_unsafe
- battlemap
- current_loc
- (Battlemap.Tile.set_direction
- Battlemap.Direction.None
- )
- )
-
-navigator_backtrack : (
- Battlemap.Navigator.Type ->
- Battlemap.Location.Type ->
- (List Battlemap.Direction.Type) ->
- Battlemap.Navigator.Type
- )
-navigator_backtrack nav next_loc prev_dir_tail =
- {nav |
- current_location = next_loc,
- visited_locations =
- (Set.remove
- (Battlemap.Location.get_ref next_loc)
- nav.visited_locations
- ),
- previous_directions = prev_dir_tail,
- remaining_points = (nav.remaining_points + 1)
- }
-
-to : (
- Battlemap.Type ->
- Battlemap.Navigator.Type ->
- Battlemap.Direction.Type ->
- (List Character.Type) ->
- (Battlemap.Type, Battlemap.Navigator.Type)
- )
-to battlemap nav dir char_list =
- let
- next_location = (Battlemap.Location.neighbor nav.current_location dir)
- is_occupied =
- (List.any
- (\c -> ((Character.get_location c) == next_location))
- char_list
- )
- in
- if (not is_occupied)
- then
- if (can_move_to_new_tile nav battlemap next_location)
- then
- (
- (battlemap_move_to
- battlemap
- nav.current_location
- dir
- next_location
- ),
- (navigator_move_to
- nav
- dir
- next_location
- )
- )
- else
- case (Util.List.pop nav.previous_directions) of
- Nothing -> (battlemap, nav)
- (Just (head, tail)) ->
- if (head == (Battlemap.Direction.opposite_of dir))
- then
- (
- (battlemap_backtrack
- battlemap
- nav.current_location
- ),
- (navigator_backtrack
- nav
- next_location
- tail
- )
- )
- else
- (battlemap, nav)
- else
- (battlemap, nav)
diff --git a/elm/battlemap/src/Battlemap/Navigator/Path.elm b/elm/battlemap/src/Battlemap/Navigator/Path.elm
deleted file mode 100644
index 53e12c0..0000000
--- a/elm/battlemap/src/Battlemap/Navigator/Path.elm
+++ /dev/null
@@ -1,168 +0,0 @@
-module Battlemap.Navigator.Path exposing
- (
- Type,
- new,
- get_current_location,
- get_remaining_points,
- get_summary,
- try_following_direction
- )
-
-import Set
-
-import Util.List
-
-import Battlemap.Direction
-import Battlemap.Location
-
---------------------------------------------------------------------------------
--- TYPES -----------------------------------------------------------------------
---------------------------------------------------------------------------------
-type alias Type =
- {
- current_location : Battlemap.Location.Type,
- visited_locations : (Set.Set Battlemap.Location.Ref),
- previous_directions : (List Battlemap.Direction.Type),
- previous_points : (List Int),
- remaining_points : Int
- }
-
---------------------------------------------------------------------------------
--- LOCAL -----------------------------------------------------------------------
---------------------------------------------------------------------------------
-has_been_to : (
- Type ->
- Battlemap.Location.Type ->
- Bool
- )
-has_been_to path location =
- (
- (path.current_location == location)
- ||
- (Set.member
- (Battlemap.Location.get_ref location)
- path.visited_locations
- )
- )
-
-try_moving_to : (
- Type ->
- Battlemap.Direction.Type ->
- Battlemap.Location.Type ->
- Int ->
- (Maybe Type)
- )
-try_moving_to path dir next_loc cost =
- let
- remaining_points = (path.remaining_points - cost)
- in
- if (remaining_points >= 0)
- then
- (Just
- {path |
- current_location = next_loc,
- visited_locations =
- (Set.insert
- (Battlemap.Location.get_ref path.current_location)
- path.visited_locations
- ),
- previous_directions = (dir :: path.previous_directions),
- previous_points =
- (path.remaining_points :: path.previous_points),
- remaining_points = remaining_points
- }
- )
- else
- Nothing
-
-try_backtracking_to : (
- Type ->
- Battlemap.Direction.Type ->
- Battlemap.Location.Type ->
- (Maybe Type)
- )
-try_backtracking_to path dir location =
- case
- (
- (Util.List.pop path.previous_directions),
- (Util.List.pop path.previous_points)
- )
- of
- (
- (Just (prev_dir_head, prev_dir_tail)),
- (Just (prev_pts_head, prev_pts_tail))
- ) ->
- if (prev_dir_head == (Battlemap.Direction.opposite_of dir))
- then
- (Just
- {path |
- current_location = location,
- visited_locations =
- (Set.remove
- (Battlemap.Location.get_ref location)
- path.visited_locations
- ),
- previous_directions = prev_dir_tail,
- previous_points = prev_pts_tail,
- remaining_points = prev_pts_head
- }
- )
- else
- Nothing
- (_, _) ->
- Nothing
-
---------------------------------------------------------------------------------
--- EXPORTED --------------------------------------------------------------------
---------------------------------------------------------------------------------
-
-new : Battlemap.Location.Type -> Int -> Type
-new start points =
- {
- current_location = start,
- visited_locations = Set.empty,
- previous_directions = [],
- previous_points = [],
- remaining_points = points
- }
-
-get_current_location : Type -> Battlemap.Location.Type
-get_current_location path = path.current_location
-
-get_remaining_points : Type -> Int
-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 =
- case maybe_path of
- (Just path) ->
- let
- next_location =
- (Battlemap.Location.neighbor
- path.current_location
- dir
- )
- in
- if (can_cross next_location)
- then
- if (has_been_to path next_location)
- then
- (try_backtracking_to path dir next_location)
- else
- (try_moving_to
- path
- dir
- next_location
- (cost_fun next_location)
- )
- else
- Nothing
- Nothing -> Nothing
diff --git a/elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm b/elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm
deleted file mode 100644
index a8cac8e..0000000
--- a/elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm
+++ /dev/null
@@ -1,287 +0,0 @@
-module Battlemap.Navigator.RangeIndicator exposing
- (
- Type,
- generate,
- get_marker,
- get_path
- )
-
-import Dict
-import List
-
-import Battlemap.Direction
-import Battlemap.Location
-import Battlemap.Marker
-
-import Util.List
-
-type alias Type =
- {
- distance: Int,
- path: (List Battlemap.Direction.Type),
- node_cost: Int,
- marker: Battlemap.Marker.Type
- }
-
-generate_row : (
- Battlemap.Location.Type ->
- Int ->
- Int ->
- Int ->
- (List Battlemap.Location.Type) ->
- (List Battlemap.Location.Type)
- )
-generate_row src max_x_mod curr_y curr_x_mod curr_row =
- if (curr_x_mod > max_x_mod)
- then
- curr_row
- else
- (generate_row
- src
- max_x_mod
- curr_y
- (curr_x_mod + 1)
- ({x = (src.x + curr_x_mod), y = curr_y} :: curr_row)
- )
-
-generate_grid : (
- Battlemap.Location.Type ->
- Int ->
- Int ->
- (List Battlemap.Location.Type) ->
- (List Battlemap.Location.Type)
- )
-generate_grid src dist curr_y_mod curr_list =
- if (curr_y_mod > dist)
- then
- curr_list
- else
- let
- new_limit = (dist - (abs curr_y_mod))
- in
- (generate_grid
- src
- dist
- (curr_y_mod + 1)
- (
- (generate_row
- src
- new_limit
- (src.y + curr_y_mod)
- (-new_limit)
- []
- )
- ++ curr_list
- )
- )
-
-get_closest : (
- Battlemap.Location.Ref ->
- Type ->
- (Battlemap.Location.Ref, Type) ->
- (Battlemap.Location.Ref, Type)
- )
-get_closest ref indicator (prev_ref, prev_indicator) =
- if (indicator.distance < prev_indicator.distance)
- then
- (ref, indicator)
- else
- (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 dist atk_dist indicator remaining directions =
- case (Util.List.pop directions) of
- Nothing -> remaining
- (Just (head, tail)) ->
- let
- neighbor_loc = (Battlemap.Location.neighbor loc head)
- neighbor_indicator =
- (Dict.get
- (Battlemap.Location.get_ref neighbor_loc)
- remaining
- )
- in
- case neighbor_indicator of
- Nothing ->
- (handle_neighbors
- loc
- dist
- atk_dist
- indicator
- remaining
- tail
- )
- (Just neighbor) ->
- let
- 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)
- && (new_dist <= atk_dist)
- )
- then
- (Dict.insert
- (Battlemap.Location.get_ref neighbor_loc)
- {neighbor |
- distance = new_dist,
- path = (head :: indicator.path)
- }
- remaining
- )
- else
- remaining
- )
- tail
- )
-
-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 atk_dist =
- if (Dict.isEmpty remaining)
- then
- result
- else
- let
- (min_loc_ref, min) =
- (Dict.foldl
- (get_closest)
- (
- (-1,-1),
- {
- distance = (atk_dist + 1),
- path = [],
- node_cost = 99,
- marker = Battlemap.Marker.CanAttack
- }
- )
- remaining
- )
- in
- (search
- (Dict.insert
- min_loc_ref
- {min |
- marker =
- (
- if (min.distance > dist)
- then
- Battlemap.Marker.CanAttack
- else
- Battlemap.Marker.CanGoTo
- )
- }
- result
- )
- (handle_neighbors
- (Battlemap.Location.from_ref min_loc_ref)
- dist
- atk_dist
- min
- (Dict.remove min_loc_ref remaining)
- [
- Battlemap.Direction.Left,
- Battlemap.Direction.Right,
- Battlemap.Direction.Up,
- Battlemap.Direction.Down
- ]
- )
- dist
- atk_dist
- )
-
-grid_to_range_indicators : (
- (Battlemap.Location.Type -> Bool) ->
- 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 =
- 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)
- location
- dist
- tail
- (Dict.insert
- (Battlemap.Location.get_ref head)
- {
- distance =
- (
- if ((location.x == head.x) && (location.y == head.y))
- then
- 0
- else
- (dist + 1)
- ),
- path = [],
- node_cost = 1,
- marker = Battlemap.Marker.CanGoTo
- }
- result
- )
- )
- else
- (grid_to_range_indicators (can_cross_fun) location dist tail result)
-
-generate : (
- Battlemap.Location.Type ->
- Int ->
- Int ->
- (Battlemap.Location.Type -> Bool) ->
- (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) [])
- Dict.empty
- )
- dist
- atk_dist
- )
-
-get_marker : Type -> Battlemap.Marker.Type
-get_marker indicator = indicator.marker
-
-get_path : Type -> (List Battlemap.Direction.Type)
-get_path indicator = indicator.path
diff --git a/elm/battlemap/src/Battlemap/Tile.elm b/elm/battlemap/src/Battlemap/Tile.elm
deleted file mode 100644
index 255310a..0000000
--- a/elm/battlemap/src/Battlemap/Tile.elm
+++ /dev/null
@@ -1,25 +0,0 @@
-module Battlemap.Tile exposing
- (
- Type,
- get_location,
- get_icon_id,
- get_cost
- )
-
-import Battlemap.Location
-
-type alias Type =
- {
- location : Battlemap.Location.Type,
- icon_id : String,
- crossing_cost : Int
- }
-
-get_location : Type -> Battlemap.Location.Type
-get_location tile = tile.location
-
-get_icon_id : Type -> String
-get_icon_id tile = tile.icon_id
-
-get_cost : Type -> Int
-get_cost tile = tile.crossing_cost