Skip to content

Commit a998ca9

Browse files
committed
Edited some docstrings, comments, and whitespace.
1 parent f6ca0f6 commit a998ca9

10 files changed

+65
-23
lines changed

simalq/cmdline.hy

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"The command-line interface."
2+
3+
14
(require
25
hyrule [unless])
36
(import

simalq/color.hy

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"Color definitions."
2+
3+
14
(setv
25

36
by-name (dfor

simalq/commands.hy

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"Interface and logic for player commands and actions."
2+
3+
14
(require
25
hyrule [case ecase ebranch do-n unless]
36
simalq.macros [defdataclass])
@@ -20,7 +23,7 @@
2023
"Something the player wants to do, translated from user input.")
2124

2225
(defdataclass Action [Command]
23-
"A discrete effect that the player can have on the gamestate.")
26+
"A discrete effect that the player can have on the game state.")
2427
(defdataclass Wait [Action]
2528
"Do nothing, passing your turn (or, more precisely, passing
2629
one opportunity for an action).")
@@ -60,7 +63,6 @@
6063
wait key) to get info on a tile under the cursor, and any other key
6164
to exit look mode. If there's more than one tile on the selected
6265
square, you'll be prompted to choose one when you try to get info.")
63-
6466
(defdataclass ShiftHistory [Command]
6567
"{details}"
6668
; Undo or redo.
@@ -89,7 +91,6 @@
8991
None)
9092

9193

92-
9394
(defn do-command [cmd]
9495
"This function is only for commands that aren't actions; see
9596
`do-action` for actions."
@@ -187,16 +188,19 @@
187188
(ecase G.player.game-over-state
188189
'dead "You're dead"
189190
'won "You won the game")))))
190-
(when (and (.player-has? StatusEffect.Para) (is-not (type action) Wait))
191+
(when (and
192+
(.player-has? StatusEffect.Para)
193+
(is-not (type action) Wait))
191194
(raise (CommandError "You're paralyzed. You can only wait for it to pass.")))
192195

193196
(ebranch (in (type action) it)
194197

195198
[Wait]
196-
; Nothing to do. This action should always succeed.
199+
; Nothing to do. This action should always be allowed.
197200
None
198201

199202
[Walk UseControllableTeleporter] (do
203+
200204
(defn pat [pos]
201205
"`at`, but excluding tiles we should ignore due to passwall."
202206
(gfor
@@ -206,21 +210,25 @@
206210
tile.passwallable
207211
(.player-has? StatusEffect.Pass)))
208212
tile))
213+
209214
(setv d action.direction)
210215
(setv [target wly] (walkability G.player.pos d :monster? F))
211216
(when (= wly 'out-of-bounds)
212217
(raise (CommandError "The border of the dungeon blocks your movement.")))
213218
(when (= wly 'blocked-diag)
214219
(raise (CommandError "That diagonal is blocked by a neighbor.")))
220+
215221
(for [tile (pat target)]
216222
(when (.hook-player-bump tile G.player.pos)
217223
(return)))
218224
(when (= wly 'bump)
219225
(raise (CommandError "Your way is blocked.")))
226+
220227
(for [tile (pat G.player.pos)]
221228
(.hook-player-walk-from tile target))
222229
(for [tile (pat target)]
223230
(.hook-player-walk-to tile G.player.pos))
231+
224232
; No exceptions have stopped us, so go.
225233
(setv pos-was G.player.pos)
226234
(.move G.player target)
@@ -231,6 +239,7 @@
231239
(return))))
232240

233241
[Shoot] (do
242+
234243
(setv
235244
d action.direction
236245
target G.player.pos
@@ -239,6 +248,7 @@
239248
(when G.player.magic-arrows
240249
(setv magic? T)
241250
(-= G.player.magic-arrows 1))
251+
242252
(defn animate []
243253
(flash-map :flash-time-s .1
244254
G.player.pos
@@ -247,6 +257,7 @@
247257
color.flash-player-shot-mundane)
248258
targets
249259
{}))
260+
250261
(do-n G.rules.reality-bubble-size
251262
(setv target (+ target d))
252263
(unless target
@@ -277,8 +288,8 @@
277288
(unless (and magic? (!= tile.pos target))
278289
(return)))
279290
tile.blocks-player-shots
280-
; The arrow won't be able to leave this square, although
281-
; it can affect other tiles in the square.
291+
; The arrow can't leave this square, although it can
292+
; affect other tiles in the square.
282293
(setv blocked T)))
283294
(when blocked
284295
(animate)
@@ -302,6 +313,7 @@
302313
(when target
303314
(raise (CommandError "That item can't use a target.")))
304315
(.use item)))
316+
; All usable items are destroyed after one use.
305317
(setv (get G.player.inventory action.item-ix) None))))
306318

307319

@@ -312,10 +324,12 @@
312324
should then end.
313325
314326
Return a selected `Pos` or `None`."
327+
315328
(setv focus G.player.pos)
316329
(hy.I.simalq/main.io-mode
317330
:draw (fn []
318-
(hy.I.simalq/main.print-main-screen focus :status-bar F :tile-list 'nonpickable))
331+
(hy.I.simalq/main.print-main-screen
332+
focus :status-bar F :tile-list 'nonpickable))
319333
:on-input (fn [key]
320334
(nonlocal focus)
321335
(setv dir-v (hy.I.simalq/keyboard.read-dir-key key))

simalq/game_state.hy

+5-5
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
; changing, such as monsters moving around.
122122
level-n None
123123
; An integer indicating the level we're currently playing.
124-
; Numbered starting from 1.
124+
; Numbered starting from 1, so `(get G.quest.levels n)` is
125+
; counted as level `(- n 1)`.
125126
score 0
126127
; How many points the player has accumulated.
127128
turn-n 0
@@ -146,7 +147,7 @@
146147
reality-bubble-size 6
147148
; The reality bubble is the (Chebyshev) radius around the
148149
; player in which monsters etc. get to act. It's a square
149-
; spanning `2 * reality-bubble-size + 1` map squares on each
150+
; spanning `(+ (* 2 reality-bubble-size) 1)` map squares on each
150151
; side, with the player in the center.
151152
player-hp-factor (f/ 1)
152153
; Multiplies the player's starting HP and healing.
@@ -179,9 +180,8 @@
179180
; Damage per turn (to the player) from poisonous fountains.
180181
dainty-monsters T])
181182
; Whether monsters will only step on empty floor (with some
182-
; exceptions, like spiders walking on webs). Otherwise,
183-
; monsters obey similar rules as the player does regarding
184-
; blocking tiles.
183+
; exceptions, like spiders walking on webs). Otherwise, monsters
184+
; can move through items and some kinds of scenery.
185185

186186

187187
(setv G (Global))

simalq/geometry.hy

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"Types for level geometry and functions to operate on them."
2+
3+
14
(require
25
hyrule [unless do-n]
36
simalq.macros [defdataclass defmeth])
@@ -17,8 +20,8 @@
1720
; Booleans.
1821
data
1922
; A tuple of tuples representing the squares of the map. Each
20-
; tile is itself a list representing a stack of tiles on that
21-
; square. An empty stack means that the tile has only floor.
23+
; square is itself a list representing a stack of tiles. An
24+
; empty stack means that the square has only plain floor.
2225
width height
2326
; Cached map dimensions for speed.
2427
each-turn
@@ -51,8 +54,8 @@
5154
:fields [name x y]
5255
:frozen T)
5356
((fn []
54-
; Define the direction constants (`Direction.N`, `.NE`, etc.)
55-
; and collections thereof (`Direction.orths`, `.diags`, `.all`).
57+
; Define the direction constants (`Direction.N`, `.NE`, etc.) and
58+
; related conveniences (e.g., `Direction.orths`).
5659
(setv Direction.orths (tuple (map Direction
5760
["north" "east" "south" "west"]
5861
[0 1 0 -1]
@@ -211,7 +214,7 @@
211214
p)))
212215

213216
(defn burst-size [size [article? True]]
214-
"Describes the size of a `burst`."
217+
"Describe the size of a `burst` in prose."
215218
(setv n (- (* 2 size) 1))
216219
(.format "{}{}-by-{} burst"
217220
(if article?

simalq/macros.hy

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44

55
(defmacro defdataclass [class-name superclasses #* rest]
6+
"Syntactic sugar for common uses of data classes."
7+
68
(setv rest (list rest) docstring [])
79
(when (and rest (isinstance (get rest 0) hy.models.String))
810
(.append docstring (.pop rest 0)))
@@ -172,9 +174,11 @@
172174
#** (if p-kwargs {p-kwargs collected-kwargs} {})))
173175

174176
(defn parse-params [params]
177+
"A subroutine for `defmacro-kwargs` and `match-params`."
175178
(import
176179
funcparserlib.parser [maybe many]
177180
hy.model-patterns [SYM FORM sym brackets pexpr])
181+
178182
(setv msym (>> SYM hy.mangle))
179183
(defn pvalue [root wanted]
180184
(>> (pexpr (+ (sym root) wanted)) (fn [x] (get x 0))))

simalq/quest_definition/__init__.hy

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ quest definitions from other files in this directory."
7070
; The requested tiles are placed in a line east of the player
7171
; start.
7272
[map None]
73-
; Overrides `width`, `height`, `tiles`, and possibly
74-
; `player-start` if provided.
73+
; A string passed to `parse-text-map`. It overrides `width`,
74+
; `height`, `tiles`, and possibly `player-start` if provided.
7575
[map-marks #()]
7676
[title None]
7777
[next-level None]
@@ -119,6 +119,7 @@ quest definitions from other files in this directory."
119119
(setv player-start #(x y))
120120
(= mapsym ". ")
121121
None
122+
; A few mapsyms have a default associated tile for convenience.
122123
(= mapsym "██")
123124
(mk-tile p "wall")
124125
(= mapsym "> ")

simalq/save_load.hy

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"Code for saving games and loading saved games. Each saved game is a
2+
ZIP archive with two members:
3+
- `state.pkl`, a pickled `Global` object
4+
- `meta.json`, a JSON file of metadata."
5+
6+
;; --------------------------------------------------------------
7+
;; * Imports
8+
;; --------------------------------------------------------------
9+
110
(require
211
hyrule [unless])
312
(import

simalq/strings.hy

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"Lists of strings to pick from pseudorandomly."
2+
3+
14
(setv meal-messages #(
25
"Finally, some good pizza."
36
"Macaroni with the chicken shtrips. Ugh!"

simalq/util.hy

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
(range a (+ b step) step))
2626

2727
(defn sign [x]
28+
"N.B. This function returns 0 for -0.0, and raises `TypeError` for NaN."
2829
(cond
2930
(< x 0) -1
3031
(> x 0) 1
@@ -114,16 +115,16 @@
114115

115116

116117
(defclass DamageType [Enum] (setv
117-
; These only apply to damage against monsters
118+
; These only apply to damage against monsters.
118119
PlayerMelee "sword attacks"
119120
MundaneArrow "mundane arrows"
120121
MagicArrow "magic arrows"
121122
Fire "fire"
122-
; These only apply to damage against the player
123+
; These only apply to damage against the player.
123124
MonsterMelee "monsters' melee attacks"
124125
MonsterShot "monsters' shots"
125126
Trap "traps"
126-
; These are equal-opportunity
127+
; These are equal-opportunity.
127128
Poison "poison"
128129
DeathMagic "death magic"))
129130

@@ -145,6 +146,7 @@
145146
(bool (get G.player.status-effects @)))
146147

147148
(defmeth add [duration]
149+
"Give the player this status effect for the given duration."
148150
(when (and (@bad?) (.player-has? StatusEffect.Prot))
149151
; Protection prevents harmful effects.
150152
(return))

0 commit comments

Comments
 (0)