summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-06-12 18:08:31 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-06-12 18:08:31 +0200
commit9eaf4c0a006e2a08fdd1e2248978c4ac5cdaef3b (patch)
tree8fdb40547999938c4bd055bdae09443dd681293a /src/shared/battle-map/BattleMap/Struct/Map.elm
parentf3f09c301fdb1acf9fb7e77db92bfed3147ab215 (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/shared/battle-map/BattleMap/Struct/Map.elm')
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Map.elm52
1 files changed, 52 insertions, 0 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 |