summaryrefslogtreecommitdiff
blob: b2b28cab281829d636e3d345346e6094f1023a51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module Update.SelectCharacter exposing (apply_to)

import Dict

import Character

import Battlemap
import Battlemap.Direction
import Battlemap.Location
import Battlemap.Navigator
import Battlemap.Tile
import Battlemap.RangeIndicator

import Model

display_range : (
      Int ->
      Battlemap.Location.Ref ->
      Battlemap.RangeIndicator.Type ->
      Battlemap.Type ->
      Battlemap.Type
   )
display_range dist loc_ref indicator bmap =
   (Battlemap.apply_to_tile_unsafe
      bmap
      (Battlemap.Location.from_ref loc_ref)
      (\e ->
         {e |
            mod_level =
               (
                  if (indicator.distance <= dist)
                  then
                     (Just Battlemap.Tile.CanBeReached)
                  else
                     (Just Battlemap.Tile.CanBeAttacked)
               )
         }
      )
   )


apply_to : Model.Type -> Character.Ref -> Model.Type
apply_to model char_id =
   case (Dict.get char_id model.characters) of
      Nothing -> model
      (Just char) ->
         let
            new_range_indicator =
               (Battlemap.RangeIndicator.generate
                  model.battlemap
                  char.location
                  char.movement_points
                  (char.movement_points + char.atk_dist)
               )
         in
            {model |
               selection = (Just char_id),
               battlemap =
                  (
                     (Dict.foldl
                        (display_range char.movement_points)
                        (Battlemap.apply_to_all_tiles
                           model.battlemap
                           (Battlemap.Tile.reset_tile)
                        )
                        new_range_indicator
                     )
                  ),
               navigator =
                  (Just
                     (Battlemap.Navigator.new_navigator
                        char.location
                        char.movement_points
                     )
                  ),
               range_indicator = new_range_indicator
            }