aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-05-09 22:07:36 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-05-09 22:07:36 +0200
commitbeceea45a9840c306f8db79d4d02db400bd6426c (patch)
tree5468c43fcf27112ec7170392bd38dc5df9d1539a
parentc61ecd8b3c9a5e9354a4cd9c3a66650b9057332b (diff)
downloadtacticians-client-beceea45a9840c306f8db79d4d02db400bd6426c.zip
tacticians-client-beceea45a9840c306f8db79d4d02db400bd6426c.tar.bz2
Adds danger zone calculation.
-rw-r--r--src/battle/src/Struct/Model.elm55
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Location.elm43
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Marker.elm5
3 files changed, 85 insertions, 18 deletions
diff --git a/src/battle/src/Struct/Model.elm b/src/battle/src/Struct/Model.elm
index 01cf4fe..1d36d1f 100644
--- a/src/battle/src/Struct/Model.elm
+++ b/src/battle/src/Struct/Model.elm
@@ -36,6 +36,7 @@ import Struct.Flags
import Battle.Struct.Omnimods
-- Battle Characters -----------------------------------------------------------
+import BattleCharacters.Struct.Character
import BattleCharacters.Struct.Armor
import BattleCharacters.Struct.Portrait
import BattleCharacters.Struct.Glyph
@@ -101,7 +102,6 @@ type alias Type =
battle_id : String,
session_token : String,
player_ix : Int,
- player_characters_ix : (Set.Set Int),
ui : Struct.UI.Type,
char_turn : Struct.CharacterTurn.Type,
timeline : (Array.Array Struct.TurnResult.Type)
@@ -149,7 +149,6 @@ new flags =
),
session_token = flags.token,
player_ix = 0,
- player_characters_ix = (Set.empty),
ui = (Struct.UI.default),
char_turn = (Struct.CharacterTurn.new),
timeline = (Array.empty)
@@ -169,21 +168,7 @@ new flags =
add_character : Struct.Character.Type -> Type -> Type
add_character char model =
- {model |
- characters =
- (Array.push
- char
- model.characters
- ),
- player_characters_ix =
- if ((Struct.Character.get_player_ix char) == model.player_ix)
- then
- (Set.insert
- (Struct.Character.get_index char)
- model.player_characters_ix
- )
- else model.player_characters_ix
- }
+ {model | characters = (Array.push char model.characters)}
add_weapon : BattleCharacters.Struct.Weapon.Type -> Type -> Type
add_weapon wp model =
@@ -382,3 +367,39 @@ invalidate err model =
clear_error : Type -> Type
clear_error model = {model | error = Nothing}
+
+generate_danger_zone : Type -> (Set.Set BattleMap.Struct.Location.Ref)
+generate_danger_zone model =
+ (Array.foldl
+ (\char danger_zone ->
+ let
+ char_weapon =
+ (BattleCharacters.Struct.Character.get_active_weapon
+ (Struct.Character.get_base_character char)
+ )
+ in
+ if
+ (
+ (Struct.Character.is_alive char)
+ && ((Struct.Character.get_player_ix char) /= model.player_ix)
+ &&
+ (
+ (BattleCharacters.Struct.Weapon.get_defense_range char_weapon)
+ == 0
+ )
+ )
+ then
+ (BattleMap.Struct.Location.add_neighborhood_to_set
+ (BattleMap.Struct.Map.get_width model.map)
+ (BattleMap.Struct.Map.get_height model.map)
+ (BattleCharacters.Struct.Weapon.get_attack_range
+ char_weapon
+ )
+ (Struct.Character.get_location char)
+ danger_zone
+ )
+ else danger_zone
+ )
+ (Set.empty)
+ model.characters
+ )
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)
+ )
diff --git a/src/shared/battle-map/BattleMap/Struct/Marker.elm b/src/shared/battle-map/BattleMap/Struct/Marker.elm
index 21a1731..53204cb 100644
--- a/src/shared/battle-map/BattleMap/Struct/Marker.elm
+++ b/src/shared/battle-map/BattleMap/Struct/Marker.elm
@@ -1,9 +1,11 @@
module BattleMap.Struct.Marker exposing
(
Type,
+ DataType,
new,
get_locations,
set_locations,
+ get_data,
is_in_locations,
decoder,
encode
@@ -84,6 +86,9 @@ get_locations marker = marker.locations
set_locations : (Set.Set BattleMap.Struct.Location.Ref) -> Type -> Type
set_locations locations marker = {marker | locations = locations}
+get_data : Type -> DataType
+get_data marker = marker.data
+
is_in_locations : BattleMap.Struct.Location.Ref -> Type -> Bool
is_in_locations loc_ref marker = (Set.member loc_ref marker.locations)