-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.elm
174 lines (140 loc) · 5.09 KB
/
Model.elm
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
module Model exposing (..)
{-| The "Model" is not a traditional Elm Architecture model, but an
individual fighter in a gang. "Model" refers to the physical token
used in the tabletop game.
From the rulebook:
> Each model fighter is defined by a set of characteristics namely:
> Move, Weapon Skill, Ballistic Skill, Strength, Toughness, Wounds,
> Initiative, Attacks and Leadership. Each characteristic is assigned a
> value of (usually) between 1 and 10. The higher value your model has
> for any characteristic the better – for example, a model with a
> Strength of 6 is stronger than a model with a Strength of
> 2.
-}
import Html.Events exposing (onClick)
import Svg exposing (..)
import Svg.Attributes exposing (..)
import Tabletop exposing (Position, Inch, posX, posY)
{-| From the rulebook:
> Move (M). A model’s move shows the number of inches it can move in a
> turn under normal circumstances. The usual number is 4 as almost all
> fighters move 4" per turn, although they can move faster when they
> are running or charging, as you’ll see later.
> Weapon Skill (WS). Weapon Skill is a measure of close combat ability
> – how good the person is at hand-to-hand fighting. A good swordsman
> or a skilled knife fighter would have a high value compared to a
> green juve, for example. An average value is 3.
> Ballistic Skill (BS). Ballistic Skill shows how good a shot the
> individual is. When you shoot a gun the chance of hitting a target
> depends upon your Ballistic Skill. An average score is 3 and a
> dead-eye shot might have a Ballistic Skill of 4, 5 or even higher.
> Strength (S). Strength simply shows how strong a person is! Strength
> is especially important when you fight hand-to-hand combat because
> the stronger you are the harder you can hit or thrust. A Strength
> value of 3 is about average.
> Toughness (T). Toughness is a measure of how easily an individual
> can withstand a hit from a weapon or a blow from a club, hand weapon
> or fist. The tougher you are the harder you are to wound or kill. An
> average value is 3.
> Wounds (W). A model’s Wounds value shows how many times a fighter
> can be wounded before he collapses and goes down dead or
> incapacitated. Most individuals have a Wound value of only 1 but
> tough old gang leaders and veteran gangers might have a value of 2
> or more.
> Initiative (I). The Initiative value represents alertness and
> reaction speed. It determines a fighter’s chance of dodging a sudden
> blow or gathering his wits while shells and bombs explode around
> him. An average Initiative value is 3.
> Attacks (A). The Attacks value indicates the number of ‘Attack dice’
> rolled when the model fights in hand- to-hand combat. Most
> individuals roll only one dice and so have an Attacks value of 1,
> but experienced fighters might have a higher value and roll
> correspondingly more dice. The more dice you roll the more chance
> you have of beating your opponent!
> Leadership (Ld). Leadership represents raw courage and
> self-control. The higher a person’s Leadership the more likely he is
> to remain steadfast in combat while others run off or are slain
> around him. An average Leadership value is 7.
-}
type alias Characteristics =
{ move : Inch
, weaponSkill : Int
, ballisticSkill : Int
, strength : Int
, toughness : Int
, wounds : Int
, initiative : Int
, attacks : Int
, leadership : Int
}
type alias Model =
{ profile : Characteristics
, position : Position
, hidden : Bool
, pinned : Bool
, injury : Maybe Injury
, remainingMove : Inch
}
averageFighterProfile : Characteristics
averageFighterProfile =
{ move = 4
, weaponSkill = 3
, ballisticSkill = 3
, strength = 3
, toughness = 3
, wounds = 1
, initiative = 3
, attacks = 1
, leadership = 7
}
averageFighter : Position -> Model
averageFighter pos =
{ profile = averageFighterProfile
, position = pos
, hidden = False
, pinned = False
, injury = Nothing
, remainingMove = averageFighterProfile.move
}
move : Model -> Position -> Model
move model pos =
{ model | position = pos }
attemptMove : Model -> Position -> Result ( String, Model ) Model
attemptMove model pos =
Ok { model | position = pos }
type Injury
= FleshWound
| Down
| OutOfAction
view : Model -> msg -> Svg msg
view model msg =
text'
[ fontSize "1"
, fontFamily "monospace"
, textAnchor "middle"
, fill "black"
, x
(model.position |> posX |> toString)
, y
(model.position |> posY |> toString)
, onClick msg
, Svg.Attributes.cursor "pointer"
]
[ text "@" ]
movementView : Model -> Position -> Svg msg
movementView model pos =
let
( modelX, modelY ) =
model.position
( newX, newY ) =
pos
in
line
[ x1 (modelX |> toString)
, y1 (modelY |> toString)
, x2 (newX |> toString)
, y2 (newY |> toString)
, stroke "white"
, strokeWidth "0.25"
]
[]