Skip to content

Commit c03c18b

Browse files
committed
Treat the player's starting HP as a rule.
1 parent 6cae198 commit c03c18b

File tree

9 files changed

+19
-23
lines changed

9 files changed

+19
-23
lines changed

simalq/game_state.hy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@
149149
; player in which monsters etc. get to act. It's a square
150150
; spanning `(+ (* 2 reality-bubble-size) 1)` map squares on each
151151
; side, with the player in the center.
152+
player-starting-hp 500
153+
; The HP the player starts with (at least before `player-hp-factor`).
152154
player-hp-factor (f/ 1)
153-
; Multiplies the player's starting HP and healing.
155+
; Multiplies `player-starting-hp` and all healing to the player.
154156
poison-factor (f/ 1)
155157
; Multiplies all ambient poison rates.
156158
max-keys 8

simalq/quest.hy

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
:fields [
1919
name authors title
2020
; Textual metadata
21-
starting-hp
22-
; An integer
2321
levels
2422
; A tuple of `Level` objects
2523
rules]
@@ -40,7 +38,7 @@
4038
(setattr G.rules k v)))
4139
(.initialize-states G)
4240
(setv G.player (Player :pos None))
43-
(setv G.player.hp (refactor-hp quest.starting-hp)))
41+
(setv G.player.hp (refactor-hp G.rules.player-starting-hp)))
4442

4543

4644
(defdataclass Level []

simalq/quest_definition/__init__.hy

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,15 @@ quest definitions from other files in this directory."
5252
(defn mk-quest [
5353
; Make a quest.
5454
#* levels
55-
[starting-hp 100]
5655
[name "Test Quest"]
5756
[authors "Mitt Lowporch and Cire Whyhall"]
5857
[title "Test Quest title"]
59-
[rules None]]
58+
#** rules]
6059
(pun (Quest
6160
:!name
6261
:!authors
6362
:!title
64-
:!starting-hp
65-
:rules (or rules (Rules))
63+
:rules (Rules #** rules)
6664
:levels (tuple (gfor
6765
[i level-args] (enumerate levels)
6866
(mk-level :n (+ i 1) #** (kwdict level-args)))))))

simalq/quest_definition/tutorial.hy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
(.replace x "\\n" "\n"))
1414

1515
(setv quest (mk-quest
16-
:starting-hp 500
1716
:name name
1817
:authors "Kodi B. Arfer"
1918
:title #[[An instructive introduction to Infinitesimal Quest 2 + ε, inspired by Yves Meynard's "Boot Camp 2".]]
19+
:player-starting-hp 500
2020

2121
#* (.values {
2222

simalq/un_iq.hy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
(setv quest-fmt (with-construct (kw-struct
9898
:n-levels Byte
9999
(Bytes 261)
100-
:starting-hp Int16ub
100+
:player-starting-hp Int16ub
101101
:title (iq-str 256)
102102
(Bytes 897)
103103
:levels (Array this.n-levels (kw-struct
@@ -175,8 +175,8 @@
175175
"Yves and Serge Meynard"
176176
"Yves Meynard")
177177
:title data.title
178-
:starting-hp data.starting-hp
179-
:rules (Rules)
178+
:rules (Rules
179+
:player-starting-hp data.player-starting-hp)
180180
:levels (tuple (gfor
181181
[level-n l] (enumerate data.levels)
182182
:do (+= level-n 1)

tests/lib.hy

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,21 @@
2121

2222
(defn init [
2323
#* levels
24-
[starting-hp 100]
2524
#** kwargs]
2625
"(Re)initialize the global state."
26+
(setv rules (dict :player-starting-hp 100))
2727
; Extract elements of `kwargs` that correspond to rules.
28-
(setv rules (dfor
29-
[k v] (list (.items kwargs))
30-
:if (in k Rules.__dataclass_fields__)
31-
k (.pop kwargs k)))
28+
(for [[k v] (list (.items kwargs))]
29+
(when (in k Rules.__dataclass_fields__)
30+
(setv (get rules k) (.pop kwargs k))))
3231
(when kwargs
3332
; Any remaining `kwargs` should specify the only level, per
3433
; `mk-level`, in place of a `levels` argument.
3534
(assert (not levels)))
3635
(unless levels
3736
(setv levels [kwargs]))
3837
(start-quest
39-
:quest (mk-quest #* levels :starting-hp starting-hp)
40-
:rules rules)
38+
:quest (mk-quest #* levels #** rules))
4139
(start-level 1))
4240

4341
(defn init-boot-camp [[level-n 1]]

tests/test_basic.hy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316

317317
(defn test-player-death []
318318
(init
319-
:starting-hp 20
319+
:player-starting-hp 20
320320
:player-start [1 0]
321321
:tiles [["Dark Knight" :hp 10] 'floor 'floor "orc"])
322322
(defn check [state-i player-hp orc-x]

tests/test_monster.hy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@
10171017

10181018
; Lords don't get to summon while attacking the player.
10191019
(init
1020-
:starting-hp 500
1020+
:player-starting-hp 500
10211021
:map "@ L .")
10221022
(wait 10)
10231023
(assert (= G.player.hp (- 500 (* 10 15))))
@@ -1156,7 +1156,7 @@
11561156

11571157
(defn test-dragon []
11581158
(init
1159-
:starting-hp 10,000
1159+
:player-starting-hp 10,000
11601160
:tiles ['floor "dragon egg"])
11611161

11621162
; It takes a 1-HP dragon egg 4 turns to hatch. The newly created

tests/test_un_iq.hy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
(setv quest (iq-quest "Boot Camp 2"))
3030
(assert (= quest.name "Boot Camp 2"))
3131
(assert (= quest.title "Boot Camp will teach you how to play Infinity Quest II"))
32-
(assert (= quest.starting-hp 500))
32+
(assert (= quest.rules.player-starting-hp 500))
3333
(assert (= (len quest.levels) 26)))
3434

3535

0 commit comments

Comments
 (0)