Skip to content

Commit 96049be

Browse files
committed
Made use-item take a locator.
1 parent c353d56 commit 96049be

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

tests/lib.hy

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(require
22
hyrule [do-n unless])
33
(import
4+
metadict [MetaDict]
45
simalq.geometry [Pos at Direction]
56
simalq.un-iq [iq-quest]
67
simalq.game-state [G]
@@ -103,14 +104,17 @@
103104
(do-n n-times
104105
(take-turn (Shoot (getattr Direction (str direction-abbr))))))
105106

106-
(defn use-item [thing [target-x None] [target-y None]]
107+
(defn use-item [thing [locator None]]
108+
(setv target (if locator
109+
(locate locator)
110+
(MetaDict :x None :y None)))
107111
(when (isinstance thing int)
108-
(return (take-turn (UseItem thing target-x target-y))))
112+
(return (take-turn (UseItem thing target.x target.y))))
109113
(try
110114
(setv inv-was (.copy G.player.inventory))
111115
(setv (get G.player.inventory 0) None)
112116
(.pick-up (mk-tile None thing))
113-
(take-turn (UseItem 0 target-x target-y))
117+
(take-turn (UseItem 0 target.x target.y))
114118
(finally
115119
(setv (cut G.player.inventory) inv-was))))
116120

tests/test_item.hy

+20-20
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
(assert-at 'E "jar of poison")
164164
(assert (= G.player.hp 100))
165165
(if use-bomb?
166-
(use-item "poison-gas bomb" 1 2)
166+
(use-item "poison-gas bomb" 'E)
167167
(shoot 'E))
168168
(assert-at 'E (if use-bomb? "jar of poison" 'floor))
169169
; The player takes 20 damage.
@@ -493,21 +493,21 @@
493493

494494
; Unlike IQ, walls can be added regardless of what's already on the
495495
; target square.
496-
(use-item "wall-making wand" 0 0)
496+
(use-item "wall-making wand" [0 0])
497497
(assert-at [0 0] "wall" 'player)
498-
(use-item "wall-making wand" 1 0)
498+
(use-item "wall-making wand" [1 0])
499499
(assert-at [1 0] "wall" "orc")
500-
(use-item "wall-making wand" 2 0)
500+
(use-item "wall-making wand" [2 0])
501501
(assert-at [2 0] "wall" "wall")
502-
(use-item "wall-making wand" 3 0)
502+
(use-item "wall-making wand" [3 0])
503503
(assert-at [3 0] "wall"))
504504

505505

506506
(defn test-wand-phase []
507507
(init [])
508508
(defn phase [start end]
509509
(set-square 'E #* start)
510-
(use-item "phase wand" 1 0)
510+
(use-item "phase wand" 'E)
511511
(assert-at 'E #* end))
512512

513513
(phase
@@ -532,14 +532,14 @@
532532
(init
533533
[:tiles ["orc" "wall" "pillar"]])
534534

535-
(cant (use-item "wall-destroying wand" 1 0) "There isn't a destructible tile there.")
536-
(use-item "wall-destroying wand" 2 0)
535+
(cant (use-item "wall-destroying wand" 'E) "There isn't a destructible tile there.")
536+
(use-item "wall-destroying wand" [2 0])
537537
(assert-at [2 0] 'floor)
538-
(use-item "wall-destroying wand" 3 0)
538+
(use-item "wall-destroying wand" [3 0])
539539
(assert-at [3 0] 'floor)
540540
(set-square [3 0] "wall" "wall")
541541
(assert-at [3 0] "wall" "wall")
542-
(use-item "wall-destroying wand" 3 0)
542+
(use-item "wall-destroying wand" [3 0])
543543
(assert-at [3 0] "wall"))
544544

545545

@@ -549,8 +549,8 @@
549549
[]
550550
[])
551551

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

@@ -596,7 +596,7 @@
596596
:if (= (% (+ x y) 2) 0)]
597597
(setv (. (top [x y]) hp) hp))
598598

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

626626

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

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

@@ -700,11 +700,11 @@
700700
(ecase usage
701701
'use (do
702702
; Actually use the bomb.
703-
(use-item item-stem 1 0))
703+
(use-item item-stem 'E))
704704
'shoot (do
705705
; Shoot the bomb while it's on the floor. This creates a
706706
; less impressive explosion.
707-
(mk-tile [1 0] item-stem)
707+
(mk-tile 'E item-stem)
708708
(shoot 'E)))
709709
(for [[i dmg] (enumerate damages)]
710710
(assert-hp [(+ i 1) 0] (- starting-orc-hp dmg))))
@@ -731,7 +731,7 @@
731731

732732
; An earthquake bomb does 3 damage to monsters and 2 to cracked
733733
; walls.
734-
(use-item "earthquake bomb" 1 1)
734+
(use-item "earthquake bomb" [1 1])
735735
(assert-textmap :map-marks {"##" "cracked wall"} :text "
736736
##╷ . ##
737737
. ##. .

tests/test_monster.hy

+4-4
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@
492492
; they die instantly.
493493
(assert-at [2 0] "thorn tree")
494494
(assert-at [3 0] "thorn tree")
495-
(use-item "standard bomb" 2 0)
495+
(use-item "standard bomb" 'here)
496496
(assert-at [2 0] 'floor)
497497
(assert-at [3 0] 'floor))
498498

@@ -627,7 +627,7 @@
627627
:tiles ["floater" "wall"]])
628628
(assert-at 'E "floater")
629629
(assert (= G.player.hp 100))
630-
(use-item "wand of death" 3 0)
630+
(use-item "wand of death" [3 0])
631631
(assert-at 'E 'floor)
632632
(assert (= G.player.hp 100)))
633633

@@ -686,7 +686,7 @@
686686
████████
687687
@ ██O s ")
688688
; A slain adult gunk leaves behind a seed.
689-
(use-item "standard bomb" 1 1)
689+
(use-item "standard bomb" [1 1])
690690
(assert-textmap :map-marks marks :text "
691691
s s . .
692692
████████
@@ -779,7 +779,7 @@
779779

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

tests/test_scenery.hy

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272

273273
; Other means of destroying a wall don't cause chain reactions of breakage.
274274
(wk 'E)
275-
(use-item "wall-destroying wand" 3 2)
275+
(use-item "wall-destroying wand" [3 2])
276276
(assert-textmap :map-marks marks :text "
277277
. . . | .
278278
. . . . .

0 commit comments

Comments
 (0)