summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-06-12 18:08:31 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-06-12 18:08:31 +0200 |
commit | 9eaf4c0a006e2a08fdd1e2248978c4ac5cdaef3b (patch) | |
tree | 8fdb40547999938c4bd055bdae09443dd681293a /src | |
parent | f3f09c301fdb1acf9fb7e77db92bfed3147ab215 (diff) |
Working on Attacks of Opportunity...
I think that the use of map markers to handle attacks of opportunity is
justified on the client: quick and cheap detection is key for the path finding
algorithm, and we don't need to propagate the changes to another copy of
the data.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/Map.elm | 52 | ||||
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/TileInstance.elm | 35 |
2 files changed, 82 insertions, 5 deletions
diff --git a/src/shared/battle-map/BattleMap/Struct/Map.elm b/src/shared/battle-map/BattleMap/Struct/Map.elm index 31333f8..8be6300 100644 --- a/src/shared/battle-map/BattleMap/Struct/Map.elm +++ b/src/shared/battle-map/BattleMap/Struct/Map.elm @@ -19,10 +19,15 @@ module BattleMap.Struct.Map exposing -- Elm ------------------------------------------------------------------------- import Array +import Set + import Dict import Json.Decode +-- Shared ---------------------------------------------------------------------- +import Util.Array + -- Battle ---------------------------------------------------------------------- import Battle.Struct.Omnimods @@ -80,6 +85,53 @@ get_markers map = map.markers set_markers : (Dict.Dict String BattleMap.Struct.Marker.Type) -> Type -> Type set_markers markers map = {map | markers = markers} +remove_marker : String -> Type -> Type +remove_marker marker_name map = + case (Dict.get marker_name map.markers) of + Nothing -> map + (Just marker) -> + {map | + markers = (Dict.remove marker_name map.markers), + content = + (Set.foldl + (\loc array -> + (Util.Array.update_unsafe + (location_to_index + (BattleMap.Struct.Location.from_ref loc) + map + ) + (BattleMap.Struct.TileInstance.remove_trigger + marker_name + ) + array + ) + ) + map.content + (BattleMap.Struct.Marker.get_locations marker) + ) + } + +add_marker : String -> BattleMap.Struct.Marker.Type -> Type -> Type +add_marker marker_name marker map = + {map | + markers = (Dict.insert marker_name marker map.markers), + content = + (Set.foldl + (\loc array -> + (Util.Array.update_unsafe + (location_to_index + (BattleMap.Struct.Location.from_ref loc) + map + ) + (BattleMap.Struct.TileInstance.add_trigger marker_name) + array + ) + ) + map.content + (BattleMap.Struct.Marker.get_locations marker) + ) + } + set_tile_to : BattleMap.Struct.Location.Type -> BattleMap.Struct.TileInstance.Type -> Type -> Type set_tile_to loc tile_inst map = {map | diff --git a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm index c8b4f09..87d2762 100644 --- a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm +++ b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm @@ -15,6 +15,9 @@ module BattleMap.Struct.TileInstance exposing get_border_variant_id, get_border_class_id, get_local_variant_ix, + remove_trigger, + add_trigger, + get_triggers, error, solve, set_location_from_index, @@ -25,6 +28,8 @@ module BattleMap.Struct.TileInstance exposing -- Elm ------------------------------------------------------------------------- import Dict +import Set + import Json.Encode import Json.Decode @@ -49,7 +54,7 @@ type alias Type = family : BattleMap.Struct.Tile.FamilyID, class_id : BattleMap.Struct.Tile.Ref, variant_id : BattleMap.Struct.Tile.VariantID, - triggers : (List String), + triggers : (Set.Set String), borders : (List Border) } @@ -91,7 +96,7 @@ default tile = variant_id = "0", crossing_cost = (BattleMap.Struct.Tile.get_cost tile), family = (BattleMap.Struct.Tile.get_family tile), - triggers = [], + triggers = (Set.empty), borders = [] } @@ -103,7 +108,7 @@ error x y = variant_id = "0", family = "0", crossing_cost = Constants.Movement.cost_when_out_of_bounds, - triggers = [], + triggers = (Set.empty), borders = [] } @@ -192,7 +197,10 @@ decoder = |> (Json.Decode.Pipeline.required "t" - (Json.Decode.list (Json.Decode.string)) + (Json.Decode.map + (Set.fromList) + (Json.Decode.list (Json.Decode.string)) + ) ) |> (Json.Decode.Pipeline.hardcoded @@ -246,8 +254,25 @@ encode tile_inst = ), ( "t", - (Json.Encode.list (Json.Encode.string) tile_inst.triggers) + (Json.Encode.list + (Json.Encode.string) + (Set.toList tile_inst.triggers) + ) ) ] ) +get_triggers : Type -> (Set.Set String) +get_triggers tile_inst = tile_inst.triggers + +add_trigger : String -> Type -> Type +add_trigger trigger tile_inst = + {tile_inst | + triggers = (Set.insert trigger tile_inst.triggers) + } + +remove_trigger : String -> Type -> Type +remove_trigger trigger tile_inst = + {tile_inst | + triggers = (Set.remove trigger tile_inst.triggers) + } |