summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'elm/battlemap/src')
-rw-r--r--elm/battlemap/src/Battlemap.elm64
-rw-r--r--elm/battlemap/src/Battlemap/Navigator.elm9
-rw-r--r--elm/battlemap/src/Battlemap/Navigator/Path.elm167
-rw-r--r--elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm1
-rw-r--r--elm/battlemap/src/Battlemap/Tile.elm10
-rw-r--r--elm/battlemap/src/Event.elm1
-rw-r--r--elm/battlemap/src/Model.elm1
-rw-r--r--elm/battlemap/src/Shim/Battlemap/Tile.elm9
8 files changed, 117 insertions, 145 deletions
diff --git a/elm/battlemap/src/Battlemap.elm b/elm/battlemap/src/Battlemap.elm
index e07ae2d..888295a 100644
--- a/elm/battlemap/src/Battlemap.elm
+++ b/elm/battlemap/src/Battlemap.elm
@@ -11,12 +11,10 @@ module Battlemap exposing
import Array
import Battlemap.Navigator
-import Battlemap.Navigator.RangeIndicator
import Battlemap.Tile
import Battlemap.Direction
import Battlemap.Location
-import Util.Array
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -44,31 +42,12 @@ has_location bmap loc =
&& (loc.y < bmap.height)
)
-add_marker_to_tiles : (
- Type ->
- (Battlemap.Location.Ref, Battlemap.Navigator.RangeIndicator.Type) ->
- (Array.Array Battlemap.Tile.Type) ->
- (Array.Array Battlemap.Tile.Type)
- )
-add_marker_to_tiles bmap (location, indicator) tiles =
- (Util.Array.update_unsafe
- (location_to_index bmap (Battlemap.Location.from_ref location))
- (
- (Battlemap.Tile.set_marker
- (Just
- (Battlemap.Navigator.RangeIndicator.get_marker indicator)
- )
- )
- )
- tiles
- )
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
reset : Type -> Type
reset bmap =
{bmap |
- content = (Array.map (Battlemap.Tile.reset) bmap.content),
navigator = Nothing
}
@@ -97,44 +76,45 @@ set_navigator : (
Type
)
set_navigator start_loc movement_points attack_range can_cross bmap =
- let
- new_navigator =
- (Battlemap.Navigator.new
- start_loc
- movement_points
- attack_range
- (\loc -> ((can_cross loc) && (has_location bmap loc)))
+ {bmap |
+ navigator =
+ (Just
+ (Battlemap.Navigator.new
+ start_loc
+ movement_points
+ attack_range
+ (\loc -> ((can_cross loc) && (has_location bmap loc)))
+ )
)
- new_range_markers = (Battlemap.Navigator.get_range_markers new_navigator)
- in
- {bmap |
- content =
- (List.foldr
- (add_marker_to_tiles bmap)
- bmap.content
- new_range_markers
- ),
- navigator = (Just new_navigator)
- }
+ }
add_step_to_navigator : (
Type ->
Battlemap.Direction.Type ->
(Battlemap.Location.Type -> Bool) ->
+ (Battlemap.Location.Type -> Int) ->
(Maybe Type)
-add_step_to_navigator bmap dir can_cross =
+ )
+add_step_to_navigator bmap dir can_cross cost_fun =
case bmap.navigator of
(Just navigator) ->
let
new_navigator =
(Battlemap.Navigator.add_step
navigator
- (\loc -> ((can_cross loc) && (has_location bmap loc)))
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 -> 0
+ )
)
in
case new_navigator of
- (Just _) -> {bmap | navigator = new_navigator}
+ (Just _) -> (Just {bmap | navigator = new_navigator})
Nothing -> Nothing
_ -> Nothing
diff --git a/elm/battlemap/src/Battlemap/Navigator.elm b/elm/battlemap/src/Battlemap/Navigator.elm
index 9cdfc1f..2c2734d 100644
--- a/elm/battlemap/src/Battlemap/Navigator.elm
+++ b/elm/battlemap/src/Battlemap/Navigator.elm
@@ -11,6 +11,7 @@ module Battlemap.Navigator exposing
import Dict
import Battlemap.Location
+import Battlemap.Direction
import Battlemap.Navigator.Path
import Battlemap.Navigator.RangeIndicator
@@ -81,15 +82,17 @@ add_step : (
Type ->
Battlemap.Direction.Type ->
(Battlemap.Location.Type -> Bool) ->
+ (Battlemap.Location.Type -> Int) ->
(Maybe Type)
)
-add_step navigator dir can_cross =
+add_step navigator dir can_cross cost_fun =
case
- (Battlemap.Navigator.Path.follow_direction
+ (Battlemap.Navigator.Path.try_following_direction
can_cross
+ cost_fun
(Just navigator.path)
dir
)
of
- (Just path) -> (Just {navigator | path = path}
+ (Just path) -> (Just {navigator | path = path})
Nothing -> Nothing
diff --git a/elm/battlemap/src/Battlemap/Navigator/Path.elm b/elm/battlemap/src/Battlemap/Navigator/Path.elm
index 5ce2d4c..a20c0b7 100644
--- a/elm/battlemap/src/Battlemap/Navigator/Path.elm
+++ b/elm/battlemap/src/Battlemap/Navigator/Path.elm
@@ -4,14 +4,15 @@ module Battlemap.Navigator.Path exposing
new,
get_current_location,
get_remaining_points,
- follow_directions
+ try_following_direction
)
import Set
+import Util.List
+
import Battlemap.Direction
import Battlemap.Location
-import Battlemap.Tile
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
@@ -21,104 +22,94 @@ 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_not_been_to : (
+has_been_to : (
Type ->
Battlemap.Location.Type ->
Bool
)
-has_not_been_to path location =
+has_been_to path location =
(
- (path.current_location /= location)
- &&
- (not
- (Set.member
- (Battlemap.Location.get_ref location)
- path.visited_locations
- )
+ (path.current_location == location)
+ ||
+ (Set.member
+ (Battlemap.Location.get_ref location)
+ path.visited_locations
)
)
-move_to : (
+try_moving_to : (
Type ->
Battlemap.Direction.Type ->
Battlemap.Location.Type ->
Int ->
- Type
+ (Maybe Type)
)
-move_to path dir next_loc cost =
- {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),
+try_moving_to path dir next_loc cost =
+ let
remaining_points = (path.remaining_points - cost)
- }
-
-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
- )
-try_backtracking_to path location dir =
- case (Util.List.pop nav.previous_directions) of
- (Just (head, tail)) ->
- if (head == (Battlemap.Direction.opposite_of dir))
- then
- (backtrack_to
- nav
- next_location
- tail
- )
- )
- else
- (battlemap, nav)
- Nothing -> (battlemap, nav)
- move_to path next_location
- if (can_move_to_new_tile path next_location)
- then
- else
- {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)
- }
-
+ 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
-to : (
+try_backtracking_to : (
Type ->
Battlemap.Direction.Type ->
- (Battlemap.Type, Battlemap.Navigator.Type)
+ Battlemap.Location.Type ->
+ (Maybe Type)
)
-to battlemap nav dir char_list =
+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 --------------------------------------------------------------------
@@ -130,6 +121,7 @@ new start points =
current_location = start,
visited_locations = Set.empty,
previous_directions = [],
+ previous_points = [],
remaining_points = points
}
@@ -139,32 +131,35 @@ get_current_location path = path.current_location
get_remaining_points : Type -> Int
get_remaining_points path = path.remaining_points
-follow_direction : (
+try_following_direction : (
(Battlemap.Location.Type -> Bool) ->
+ (Battlemap.Location.Type -> Int) ->
(Maybe Type) ->
Battlemap.Direction.Type ->
(Maybe Type)
)
-follow_direction can_cross cost_fun maybe_path dir =
+try_following_direction can_cross cost_fun maybe_path dir =
case maybe_path of
(Just path) ->
let
next_location =
(Battlemap.Location.neighbor
- nav.current_location
+ path.current_location
dir
)
in
- if (can_cross path next_location)
+ if (can_cross next_location)
then
- if (has_not_been_to path next_location)
+ if (has_been_to path next_location)
then
- (Just (move_to path next_location dir))
+ (try_backtracking_to path dir next_location)
else
- (try_backtracking_to path next_location dir)
+ (try_moving_to
+ path
+ dir
+ next_location
+ (cost_fun next_location)
+ )
else
Nothing
- else
- (battlemap, nav)
-
Nothing -> Nothing
diff --git a/elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm b/elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm
index c370d03..9f31d49 100644
--- a/elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm
+++ b/elm/battlemap/src/Battlemap/Navigator/RangeIndicator.elm
@@ -7,7 +7,6 @@ module Battlemap.Navigator.RangeIndicator exposing
import Dict
import List
-import Debug
import Battlemap.Direction
import Battlemap.Location
diff --git a/elm/battlemap/src/Battlemap/Tile.elm b/elm/battlemap/src/Battlemap/Tile.elm
index d761225..e90e9bc 100644
--- a/elm/battlemap/src/Battlemap/Tile.elm
+++ b/elm/battlemap/src/Battlemap/Tile.elm
@@ -2,11 +2,10 @@ module Battlemap.Tile exposing
(
Type,
set_character,
- get_character
+ get_character,
+ get_cost
)
-import Battlemap.Direction
-import Battlemap.Marker
import Battlemap.Location
import Character
@@ -15,7 +14,7 @@ type alias Type =
{
location : Battlemap.Location.Ref,
floor_level : Int,
- char_level : (Maybe Character.Ref),
+ char_level : (Maybe Character.Ref)
}
set_character : (Maybe Character.Ref) -> Type -> Type
@@ -23,3 +22,6 @@ set_character char_ref tile = {tile | char_level = char_ref}
get_character : Type -> (Maybe Character.Ref)
get_character tile = tile.char_level
+
+get_cost : Type -> Int
+get_cost tile = tile.floor_level
diff --git a/elm/battlemap/src/Event.elm b/elm/battlemap/src/Event.elm
index b591bf4..5debff1 100644
--- a/elm/battlemap/src/Event.elm
+++ b/elm/battlemap/src/Event.elm
@@ -1,6 +1,5 @@
module Event exposing (Type(..))
-import Battlemap
import Battlemap.Direction
import Battlemap.Location
diff --git a/elm/battlemap/src/Model.elm b/elm/battlemap/src/Model.elm
index 80a4c2e..ed067d3 100644
--- a/elm/battlemap/src/Model.elm
+++ b/elm/battlemap/src/Model.elm
@@ -13,7 +13,6 @@ import Dict
import Battlemap
import Battlemap.Location
-import Battlemap.Tile
import Error
diff --git a/elm/battlemap/src/Shim/Battlemap/Tile.elm b/elm/battlemap/src/Shim/Battlemap/Tile.elm
index 4f5b40b..2335d3d 100644
--- a/elm/battlemap/src/Shim/Battlemap/Tile.elm
+++ b/elm/battlemap/src/Shim/Battlemap/Tile.elm
@@ -23,20 +23,15 @@ from_int map_width index i =
{
location = location,
floor_level = (i - 10),
- nav_level = Battlemap.Direction.None,
- char_level = (Just (toString (i - 10))),
- mod_level = Nothing
+ char_level = (Just (toString (i - 10)))
}
else
{
location = location,
floor_level = i,
- nav_level = Battlemap.Direction.None,
- char_level = Nothing,
- mod_level = Nothing
+ char_level = Nothing
}
-
generate : Int -> (Array.Array Battlemap.Tile.Type)
generate map_width =
let