From 499c0981df958643097f96365138df689432e5b4 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Thu, 13 Jun 2019 13:32:43 +0200 Subject: Adds AoO pathfinding & temporary representation. The animation manager does not work correctly though: when a move action has been interrupted, it will rewind like if there was only the last movement part, yet play back all parts, landing the character at the wrong location. --- .../battle-map/BattleMap/Struct/Location.elm | 2 +- src/shared/battle-map/BattleMap/Struct/Map.elm | 24 +++++++++++++++++++--- src/shared/battle-map/BattleMap/Struct/Marker.elm | 15 ++++++++++++++ src/shared/battle-map/BattleMap/View/Tile.elm | 17 +++++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) (limited to 'src/shared') diff --git a/src/shared/battle-map/BattleMap/Struct/Location.elm b/src/shared/battle-map/BattleMap/Struct/Location.elm index 6b07e90..d3243c2 100644 --- a/src/shared/battle-map/BattleMap/Struct/Location.elm +++ b/src/shared/battle-map/BattleMap/Struct/Location.elm @@ -112,7 +112,7 @@ add_neighborhood_to_set map_width map_height tdist loc set = (List.foldl (\height_mod current_width_result -> let - abs_width_mod = (abs (tdist - height_mod)) + abs_width_mod = (abs (tdist - (abs height_mod))) current_height = (loc.y + height_mod) in if ((current_height < 0) || (current_height >= map_height)) diff --git a/src/shared/battle-map/BattleMap/Struct/Map.elm b/src/shared/battle-map/BattleMap/Struct/Map.elm index 8be6300..d2c950f 100644 --- a/src/shared/battle-map/BattleMap/Struct/Map.elm +++ b/src/shared/battle-map/BattleMap/Struct/Map.elm @@ -6,6 +6,8 @@ module BattleMap.Struct.Map exposing get_height, get_markers, set_markers, + remove_marker, + add_marker, get_tile_data_function, get_omnimods_at, get_tiles, @@ -243,9 +245,25 @@ get_tile_data_function bmap occupied_tiles start_loc loc = then case (Array.get (location_to_index loc bmap) bmap.content) of (Just tile) -> - if ((loc /= start_loc) && (List.member loc occupied_tiles)) - then (Constants.Movement.cost_when_occupied_tile, 0) - else ((BattleMap.Struct.TileInstance.get_cost tile), 0) + ( + ( + if ((loc /= start_loc) && (List.member loc occupied_tiles)) + then Constants.Movement.cost_when_occupied_tile + else (BattleMap.Struct.TileInstance.get_cost tile) + ), + (Set.foldl + (\trigger dangers_count -> + case (Dict.get trigger bmap.markers) of + Nothing -> dangers_count + (Just marker) -> + if (BattleMap.Struct.Marker.is_dangerous marker) + then (dangers_count + 1) + else dangers_count + ) + 0 + (BattleMap.Struct.TileInstance.get_triggers tile) + ) + ) Nothing -> (Constants.Movement.cost_when_out_of_bounds, 0) else diff --git a/src/shared/battle-map/BattleMap/Struct/Marker.elm b/src/shared/battle-map/BattleMap/Struct/Marker.elm index 53204cb..7012e4b 100644 --- a/src/shared/battle-map/BattleMap/Struct/Marker.elm +++ b/src/shared/battle-map/BattleMap/Struct/Marker.elm @@ -3,8 +3,10 @@ module BattleMap.Struct.Marker exposing Type, DataType, new, + new_melee_attack, get_locations, set_locations, + is_dangerous, get_data, is_in_locations, decoder, @@ -80,6 +82,13 @@ new = data = None } +new_melee_attack : Int -> (Set.Set BattleMap.Struct.Location.Ref) -> Type +new_melee_attack char_ix locations = + { + locations = locations, + data = (MeleeAttackZone {character_ix = char_ix}) + } + get_locations : Type -> (Set.Set BattleMap.Struct.Location.Ref) get_locations marker = marker.locations @@ -159,3 +168,9 @@ encode marker = ) ] ) + +is_dangerous : Type -> Bool +is_dangerous marker = + case marker.data of + (MeleeAttackZone _) -> True + _ -> False diff --git a/src/shared/battle-map/BattleMap/View/Tile.elm b/src/shared/battle-map/BattleMap/View/Tile.elm index d2bf044..1d92493 100644 --- a/src/shared/battle-map/BattleMap/View/Tile.elm +++ b/src/shared/battle-map/BattleMap/View/Tile.elm @@ -10,6 +10,8 @@ import Html import Html.Attributes import Html.Events +import Set + -- Battle Map ------------------------------------------------------------------ import Constants.UI import Constants.IO @@ -56,6 +58,21 @@ get_content_html : ( ) get_content_html tile = ( + (Html.div + [ + (Html.Attributes.class "tile-icon-dg") + ] + ( + case + (Set.size + (BattleMap.Struct.TileInstance.get_triggers tile) + ) + of + 0 -> [] + other -> [(Html.text (String.fromInt other))] + ) + ) + :: (Html.div [ (Html.Attributes.class "tile-icon-bg"), -- cgit v1.2.3-70-g09d2