aboutsummaryrefslogtreecommitdiff
blob: 570f82c2ae58f9a8898a1200accf158de23eb04e (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
import Event
import Error

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)
               )
         }
      )
   )


make_it_so : Model.Type -> Character.Ref -> Model.Type
make_it_so model char_id =
   case (Dict.get char_id model.characters) of
      Nothing ->
         (Model.invalidate
            model
            (Error.new
               Error.Programming
               "SelectCharacter: Unknown char selected."
            )
         )
      (Just char) ->
         let
            new_range_indicator =
               (Battlemap.RangeIndicator.generate
                  model.battlemap
                  char.location
                  char.movement_points
                  (char.movement_points + char.atk_dist)
               )
         in
            {model |
               state = Model.MovingCharacterWithClick,
               battlemap =
                  (
                     (Dict.foldl
                        (display_range char.movement_points)
                        (Battlemap.apply_to_all_tiles
                           model.battlemap
                           (Battlemap.Tile.reset)
                        )
                        new_range_indicator
                     )
                  ),
               selection =
                  (Just
                     {
                        character = char_id,
                        navigator =
                           (Battlemap.Navigator.new
                              char.location
                              char.movement_points
                           ),
                        range_indicator = new_range_indicator
                     }
                  )
            }

apply_to : Model.Type -> Character.Ref -> Model.Type
apply_to model char_id =
   case (Model.get_state model) of
      _ -> (make_it_so model char_id)