summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2017-12-08 16:53:55 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2017-12-08 16:53:55 +0100 |
commit | d05ffa34c39b87d080e0f1ed24bcb4ac88935d88 (patch) | |
tree | d5bdb64808be23b498a1a3286a341670c35c17ee | |
parent | 335b70e16d383298c5c06a97ecab51282395afab (diff) |
Slowly getting there...
-rw-r--r-- | src/battlemap/src/Struct/CharacterTurn.elm | 51 | ||||
-rw-r--r-- | src/battlemap/src/Struct/Navigator.elm | 24 | ||||
-rw-r--r-- | src/battlemap/src/Update/SelectCharacter.elm | 39 | ||||
-rw-r--r-- | src/battlemap/src/Update/SelectTile.elm | 171 |
4 files changed, 158 insertions, 127 deletions
diff --git a/src/battlemap/src/Struct/CharacterTurn.elm b/src/battlemap/src/Struct/CharacterTurn.elm index ce50eb3..c4dcecd 100644 --- a/src/battlemap/src/Struct/CharacterTurn.elm +++ b/src/battlemap/src/Struct/CharacterTurn.elm @@ -7,7 +7,9 @@ module Struct.CharacterTurn exposing set_controlled_character, get_state, get_path, - set_path, + lock_path, + try_getting_navigator, + set_navigator, add_target, remove_target, get_targets @@ -61,27 +63,19 @@ new = try_getting_controlled_character : Type -> (Maybe Struct.Character.Ref) try_getting_controlled_character ct = ct.controlled_character + set_controlled_character : ( Type -> Struct.Character.Type -> - (Struct.Location.Type -> Int) -> Type -) -set_controlled_character ct char mov_cost_fun = - { + ) +set_controlled_character ct char = + {ct | state = SelectedCharacter, controlled_character = (Just (Struct.Character.get_ref char)), path = [], targets = [], - navigator = - (Just - (Struct.Navigator.new - (Struct.Character.get_location char) - (Struct.Character.get_movement_points char) - (Struct.Character.get_attack_range char) - mov_cost_fun - ) - ) + navigator = Nothing } get_state : Type -> State @@ -90,25 +84,32 @@ get_state ct = ct.state get_path : Type -> (List Struct.Direction.Type) get_path ct = ct.path -try_locking_path : Type -> (Just Type) -try_locking_path ct = +lock_path : Type -> Type +lock_path ct = case ct.navigator of (Just old_nav) -> {ct | state = MovedCharacter, path = (Struct.Navigator.get_path old_nav), targets = [], - navigator = - (Just - (Struct.Navigator.new - (Struct.Navigator.get_current_location old_nav) - 0 - (Struct.Character.get_attack_range char) - mov_cost_fun - ) - ) + navigator = (Just (Struct.Navigator.lock_path old_nav)) } + Nothing -> + ct + +try_getting_navigator : Type -> (Maybe Struct.Navigator.Type) +try_getting_navigator ct = ct.navigator + +set_navigator : Type -> Struct.Navigator.Type -> Type +set_navigator ct navigator = + {ct | + state = SelectedCharacter, + path = [], + targets = [], + navigator = (Just navigator) + } + add_target : Type -> Struct.Character.Ref -> Type add_target ct target_ref = {ct | diff --git a/src/battlemap/src/Struct/Navigator.elm b/src/battlemap/src/Struct/Navigator.elm index 56ef255..dacefbd 100644 --- a/src/battlemap/src/Struct/Navigator.elm +++ b/src/battlemap/src/Struct/Navigator.elm @@ -10,6 +10,7 @@ module Struct.Navigator exposing get_path, get_summary, clear_path, + lock_path, try_adding_step, try_getting_path_to ) @@ -36,7 +37,8 @@ type alias Type = (Dict.Dict Struct.Location.Ref Struct.RangeIndicator.Type - ) + ), + cost_fun: (Struct.Location.Type -> Int) } type alias Summary = @@ -72,7 +74,8 @@ new start_loc mov_dist atk_dist cost_fun = mov_dist atk_dist (cost_fun) - ) + ), + cost_fun = cost_fun } get_current_location : Type -> Struct.Location.Type @@ -128,16 +131,27 @@ clear_path navigator = ) } +lock_path : Type -> Type +lock_path navigator = + {navigator | + range_indicators = + (Struct.RangeIndicator.generate + (Struct.Path.get_current_location navigator.path) + 0 + navigator.attack_dist + (navigator.cost_fun) + ) + } + try_adding_step : ( Type -> Struct.Direction.Type -> - (Struct.Location.Type -> Int) -> (Maybe Type) ) -try_adding_step navigator dir cost_fun = +try_adding_step navigator dir = case (Struct.Path.try_following_direction - cost_fun + (navigator.cost_fun) (Just navigator.path) dir ) diff --git a/src/battlemap/src/Update/SelectCharacter.elm b/src/battlemap/src/Update/SelectCharacter.elm index 5347dec..bddd12f 100644 --- a/src/battlemap/src/Update/SelectCharacter.elm +++ b/src/battlemap/src/Update/SelectCharacter.elm @@ -18,14 +18,6 @@ import Update.RequestDirection -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -autopilot : ( - Struct.Direction.Type -> - Struct.Model.Type -> - (Struct.Model.Type, (Cmd Struct.Event.Type)) - ) -autopilot dir model = - (Update.RequestDirection.apply_to model dir) - attack_character : ( Struct.Model.Type -> Struct.Character.Ref -> @@ -35,7 +27,8 @@ attack_character : ( ) attack_character model main_char_id target_char_id target_char = {model | - targets = [target_char_id], + char_turn = + (Struct.CharacterTurn.add_target target_char_id model.char_turn), ui = (Struct.UI.set_previous_action model.ui Nothing) } @@ -46,24 +39,26 @@ select_character : ( Struct.Model.Type ) select_character model target_char_id target_char = - if ((Struct.Character.is_enabled target_char)) + if (Struct.Character.is_enabled target_char) then {model | state = Struct.Model.Default, char_turn = - (Struct.CharacterTurn.set_controlled_character - model.char_turn - target_char_id + (Struct.CharacterTurn.set_navigator + (Struct.CharacterTurn.set_controlled_character + model.char_turn + target_char_id + ) + (Struct.Character.get_location target_char) + (Struct.Character.get_movement_points target_char) + (Struct.Character.get_attack_range target_char) + (Struct.Battlemap.get_movement_cost_function + (Dict.values model.characters) + (Struct.Character.get_location target_char) + model.battlemap + ) ), - ui = (Struct.UI.set_previous_action model.ui Nothing), - battlemap = --- (Struct.Battlemap.set_navigator --- (Struct.Character.get_location target_char) --- (Struct.Character.get_movement_points target_char) --- (Struct.Character.get_attack_range target_char) --- (Dict.values model.characters) - model.battlemap --- ) + ui = (Struct.UI.set_previous_action model.ui Nothing) } else {model | diff --git a/src/battlemap/src/Update/SelectTile.elm b/src/battlemap/src/Update/SelectTile.elm index 46f212f..42f7b29 100644 --- a/src/battlemap/src/Update/SelectTile.elm +++ b/src/battlemap/src/Update/SelectTile.elm @@ -5,10 +5,13 @@ module Update.SelectTile exposing (apply_to) -- Battlemap ------------------------------------------------------------------- import Struct.Battlemap import Struct.Character +import Struct.CharacterTurn import Struct.Direction +import Struct.Error import Struct.Event import Struct.Location import Struct.Model +import Struct.Navigator import Struct.UI import Update.EndTurn @@ -17,85 +20,105 @@ import Update.RequestDirection -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -autopilot : Struct.Direction.Type -> Struct.Model.Type -> Struct.Model.Type -autopilot dir model = - (Update.RequestDirection.apply_to model dir) +try_autopiloting : ( + Struct.Direction.Type -> + (Maybe Struct.Navigator.Type) -> + (Maybe Struct.Navigator.Type) + ) +try_autopiloting dir maybe_nav = + case maybe_nav of + (Just navigator) -> + (Struct.Navigator.try_adding_step navigator dir) + + Nothing -> Nothing go_to_tile : ( Struct.Model.Type -> - Struct.Character.Ref -> + Struct.Navigator.Type -> Struct.Location.Ref -> (Struct.Model.Type, (Cmd Struct.Event.Type)) ) -go_to_tile model char_ref loc_ref = - case -- (Struct.Battlemap.try_getting_navigator_location model.battlemap) - (Just {x = 0, y = 0}) - of - (Just nav_loc) -> - if (loc_ref == (Struct.Location.get_ref nav_loc)) - then - -- We are already there. - if - ( - (Struct.UI.get_previous_action model.ui) - == - (Just (Struct.UI.SelectedLocation loc_ref)) - ) - then - -- And we just clicked on that tile. - (Update.EndTurn.apply_to model) - else - -- And we didn't just click on that tile. - ( - {model | - ui = - (Struct.UI.set_previous_action - model.ui - (Just (Struct.UI.SelectedLocation loc_ref)) - ) - }, - Cmd.none - ) - else - -- We have to try getting there. - case - (Struct.Battlemap.try_getting_navigator_path_to - model.battlemap - loc_ref - ) - of - (Just path) -> - let - new_model = - (List.foldr - (autopilot) - {model | - battlemap = - (Struct.Battlemap.clear_navigator_path - model.battlemap - ) - } - path - ) - in - ( - {new_model | - ui = - (Struct.UI.set_previous_action - new_model.ui - (Just (Struct.UI.SelectedLocation loc_ref)) - ) - }, - Cmd.none - ) +go_to_tile model navigator loc_ref = + if + ( + loc_ref + == + (Struct.Location.get_ref + (Struct.Navigator.get_current_location navigator) + ) + ) + then + -- We are already there. + if + ( + (Struct.UI.get_previous_action model.ui) + == + (Just (Struct.UI.SelectedLocation loc_ref)) + ) + then + -- And we just clicked on that tile. + ( + {model | + char_turn = + (Struct.CharacterTurn.lock_path model.char_turn) + }, + Cmd.none + ) + else + -- And we didn't just click on that tile. + ( + {model | + ui = + (Struct.UI.set_previous_action + model.ui + (Just (Struct.UI.SelectedLocation loc_ref)) + ) + }, + Cmd.none + ) + else + -- We have to try getting there. + case + (Struct.Navigator.try_getting_path_to + navigator + loc_ref + ) + of + (Just path) -> + case (List.foldr (try_autopiloting) (Just navigator) path) of + (Just new_navigator) -> + ( + {model | + char_turn = + (Struct.CharacterTurn.set_navigator + model.char_turn + new_navigator + ), + ui = + (Struct.UI.set_previous_action + model.ui + (Just (Struct.UI.SelectedLocation loc_ref)) + ) + }, + Cmd.none + ) - Nothing -> -- Clicked outside of the range indicator - ((Struct.Model.reset model model.characters), Cmd.none) + Nothing -> + ( + (Struct.Model.invalidate + model + (Struct.Error.new + Struct.Error.Programming + "SelectTile/Navigator: Could not follow own path." + ) + ), + Cmd.none + ) - Nothing -> -- Clicked outside of the range indicator - ((Struct.Model.reset model model.characters), Cmd.none) + Nothing -> -- Clicked outside of the range indicator + ((Struct.Model.reset model model.characters), Cmd.none) --------------------------------------------------------------------------------- +------------------------------------------------ maybe_nav-------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- apply_to : ( @@ -104,10 +127,8 @@ apply_to : ( (Struct.Model.Type, (Cmd Struct.Event.Type)) ) apply_to model loc_ref = - case - (Struct.CharacterTurn model.char_turn) - of - (Just char_ref) -> - (go_to_tile model char_ref loc_ref) + case (Struct.CharacterTurn.try_getting_navigator model.char_turn) of + (Just navigator) -> + (go_to_tile model navigator loc_ref) _ -> ({model | state = (Struct.Model.InspectingTile loc_ref)}, Cmd.none) |