Skip to content

Commit

Permalink
Made use-item take a locator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodiologist committed Feb 17, 2024
1 parent c353d56 commit 96049be
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
10 changes: 7 additions & 3 deletions tests/lib.hy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(require
hyrule [do-n unless])
(import
metadict [MetaDict]
simalq.geometry [Pos at Direction]
simalq.un-iq [iq-quest]
simalq.game-state [G]
Expand Down Expand Up @@ -103,14 +104,17 @@
(do-n n-times
(take-turn (Shoot (getattr Direction (str direction-abbr))))))

(defn use-item [thing [target-x None] [target-y None]]
(defn use-item [thing [locator None]]
(setv target (if locator
(locate locator)
(MetaDict :x None :y None)))
(when (isinstance thing int)
(return (take-turn (UseItem thing target-x target-y))))
(return (take-turn (UseItem thing target.x target.y))))
(try
(setv inv-was (.copy G.player.inventory))
(setv (get G.player.inventory 0) None)
(.pick-up (mk-tile None thing))
(take-turn (UseItem 0 target-x target-y))
(take-turn (UseItem 0 target.x target.y))
(finally
(setv (cut G.player.inventory) inv-was))))

Expand Down
40 changes: 20 additions & 20 deletions tests/test_item.hy
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
(assert-at 'E "jar of poison")
(assert (= G.player.hp 100))
(if use-bomb?
(use-item "poison-gas bomb" 1 2)
(use-item "poison-gas bomb" 'E)
(shoot 'E))
(assert-at 'E (if use-bomb? "jar of poison" 'floor))
; The player takes 20 damage.
Expand Down Expand Up @@ -493,21 +493,21 @@

; Unlike IQ, walls can be added regardless of what's already on the
; target square.
(use-item "wall-making wand" 0 0)
(use-item "wall-making wand" [0 0])
(assert-at [0 0] "wall" 'player)
(use-item "wall-making wand" 1 0)
(use-item "wall-making wand" [1 0])
(assert-at [1 0] "wall" "orc")
(use-item "wall-making wand" 2 0)
(use-item "wall-making wand" [2 0])
(assert-at [2 0] "wall" "wall")
(use-item "wall-making wand" 3 0)
(use-item "wall-making wand" [3 0])
(assert-at [3 0] "wall"))


(defn test-wand-phase []
(init [])
(defn phase [start end]
(set-square 'E #* start)
(use-item "phase wand" 1 0)
(use-item "phase wand" 'E)
(assert-at 'E #* end))

(phase
Expand All @@ -532,14 +532,14 @@
(init
[:tiles ["orc" "wall" "pillar"]])

(cant (use-item "wall-destroying wand" 1 0) "There isn't a destructible tile there.")
(use-item "wall-destroying wand" 2 0)
(cant (use-item "wall-destroying wand" 'E) "There isn't a destructible tile there.")
(use-item "wall-destroying wand" [2 0])
(assert-at [2 0] 'floor)
(use-item "wall-destroying wand" 3 0)
(use-item "wall-destroying wand" [3 0])
(assert-at [3 0] 'floor)
(set-square [3 0] "wall" "wall")
(assert-at [3 0] "wall" "wall")
(use-item "wall-destroying wand" 3 0)
(use-item "wall-destroying wand" [3 0])
(assert-at [3 0] "wall"))


Expand All @@ -549,8 +549,8 @@
[]
[])

(cant (use-item "wand of exit" 1 0) "You can only make an exit on an empty square.")
(use-item "wand of exit" 0 1)
(cant (use-item "wand of exit" 'E) "You can only make an exit on an empty square.")
(use-item "wand of exit" 'N)
(wk 'N)
(assert (= G.level-n 3)))

Expand Down Expand Up @@ -596,7 +596,7 @@
:if (= (% (+ x y) 2) 0)]
(setv (. (top [x y]) hp) hp))

(use-item "wand of death" 2 2)
(use-item "wand of death" [2 2])
; Undead, undead generators, cracked walls, and (contra IQ) negatons
; are immune to wands of death. The rightmost column is outside the
; burst radius.
Expand All @@ -616,11 +616,11 @@
(set-square 'E
"orc" "wall" "exit" "pile of gold" "negaton" "Void" "hole")
; Everything except the Void is destroyed by annihilation.
(use-item "wand of annihilation" 1 0)
(use-item "wand of annihilation" 'E)
(assert-at 'E "Void")
; Contra IQ, we allow the player to kill herself with a wand of
; annihilation, because it's funny.
(use-item "wand of annihilation" 0 0)
(use-item "wand of annihilation" 'here)
(cant (wk 'E) "You're dead. You can undo or load a saved game."))


Expand All @@ -630,7 +630,7 @@
:tiles ["wall" ["orc" :hp 10] ["orc" :hp 10] "web" "wall" ["orc" :hp 10]]])

(assert (= G.player.hp 100))
(use-item "wand of flame" 2 0)
(use-item "wand of flame" [2 0])
; The player is unhurt.
(assert (= G.player.hp 100))
; The wall is unaffected.
Expand All @@ -652,7 +652,7 @@
"pile of gold" "treasure chest" "key"
"phase trigger" "phasing wall (in phase)" "cracked wall" "orc"]])
(defn remote [x]
(use-item "wand of remote action" x 0))
(use-item "wand of remote action" [x 0]))
(setv G.rules.reality-bubble-size 20)
(setv nothing "There isn't anything you can affect there.")

Expand Down Expand Up @@ -700,11 +700,11 @@
(ecase usage
'use (do
; Actually use the bomb.
(use-item item-stem 1 0))
(use-item item-stem 'E))
'shoot (do
; Shoot the bomb while it's on the floor. This creates a
; less impressive explosion.
(mk-tile [1 0] item-stem)
(mk-tile 'E item-stem)
(shoot 'E)))
(for [[i dmg] (enumerate damages)]
(assert-hp [(+ i 1) 0] (- starting-orc-hp dmg))))
Expand All @@ -731,7 +731,7 @@

; An earthquake bomb does 3 damage to monsters and 2 to cracked
; walls.
(use-item "earthquake bomb" 1 1)
(use-item "earthquake bomb" [1 1])
(assert-textmap :map-marks {"##" "cracked wall"} :text "
##╷ . ##
. ##. .
Expand Down
8 changes: 4 additions & 4 deletions tests/test_monster.hy
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
; they die instantly.
(assert-at [2 0] "thorn tree")
(assert-at [3 0] "thorn tree")
(use-item "standard bomb" 2 0)
(use-item "standard bomb" 'here)
(assert-at [2 0] 'floor)
(assert-at [3 0] 'floor))

Expand Down Expand Up @@ -627,7 +627,7 @@
:tiles ["floater" "wall"]])
(assert-at 'E "floater")
(assert (= G.player.hp 100))
(use-item "wand of death" 3 0)
(use-item "wand of death" [3 0])
(assert-at 'E 'floor)
(assert (= G.player.hp 100)))

Expand Down Expand Up @@ -686,7 +686,7 @@
████████
@ ██O s ")
; A slain adult gunk leaves behind a seed.
(use-item "standard bomb" 1 1)
(use-item "standard bomb" [1 1])
(assert-textmap :map-marks marks :text "
s s . .
████████
Expand Down Expand Up @@ -779,7 +779,7 @@

; Contra IQ, killing a turret with a wand of death scores points.
(setv G.score 0)
(use-item "wand of death" 0 0)
(use-item "wand of death" 'here)
(assert-at 'NE 'floor)
(assert (= G.score 150)))

Expand Down
2 changes: 1 addition & 1 deletion tests/test_scenery.hy
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@

; Other means of destroying a wall don't cause chain reactions of breakage.
(wk 'E)
(use-item "wall-destroying wand" 3 2)
(use-item "wall-destroying wand" [3 2])
(assert-textmap :map-marks marks :text "
. . . | .
. . . . .
Expand Down

0 comments on commit 96049be

Please sign in to comment.