summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-05-09 22:07:36 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-05-09 22:07:36 +0200 |
commit | beceea45a9840c306f8db79d4d02db400bd6426c (patch) | |
tree | 5468c43fcf27112ec7170392bd38dc5df9d1539a /src/shared/battle-map/BattleMap/Struct/Location.elm | |
parent | c61ecd8b3c9a5e9354a4cd9c3a66650b9057332b (diff) |
Adds danger zone calculation.
Diffstat (limited to 'src/shared/battle-map/BattleMap/Struct/Location.elm')
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/Location.elm | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/shared/battle-map/BattleMap/Struct/Location.elm b/src/shared/battle-map/BattleMap/Struct/Location.elm index da3b8ef..6b07e90 100644 --- a/src/shared/battle-map/BattleMap/Struct/Location.elm +++ b/src/shared/battle-map/BattleMap/Struct/Location.elm @@ -6,6 +6,8 @@ import Json.Decode.Pipeline import Json.Encode +import Set + -- Battle Map ------------------------------------------------------------------ import BattleMap.Struct.Direction @@ -98,4 +100,43 @@ get_full_neighborhood loc = {loc | x = (loc.x + 1), y = (loc.y + 1)} ] - +add_neighborhood_to_set : ( + Int -> + Int -> + Int -> + Type -> + (Set.Set Ref) -> + (Set.Set Ref) + ) +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)) + current_height = (loc.y + height_mod) + in + if ((current_height < 0) || (current_height >= map_height)) + then current_width_result + else + (List.foldl + (\width_mod current_result -> + let new_location_x = (loc.x + width_mod) in + if + ( + (new_location_x < 0) + || (new_location_x >= map_width) + ) + then current_result + else + (Set.insert + (new_location_x, current_height) + current_result + ) + ) + current_width_result + (List.range (-abs_width_mod) abs_width_mod) + ) + ) + set + (List.range (-tdist) tdist) + ) |