Skip to content

Commit 58f606c

Browse files
committed
Implemented dragons.
1 parent d73cbe9 commit 58f606c

File tree

3 files changed

+103
-3
lines changed

3 files changed

+103
-3
lines changed

simalq/tile/monster.hy

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,4 +1039,79 @@
10391039
:flavor "Who is this amazingly good-looking woman? Her stiff, robotic movements make her too clumsy to use a bow, but you hate to see that beautiful face scratched. It feels personal. Maybe there's some way you can just take her out without having to give her a lot of unsightly wounds.")
10401040
10411041
1042+
(defclass Dragon [Approacher]
1043+
1044+
(field-defaults
1045+
regen-power 0)
1046+
(setv mutable-fields #("regen_power"))
1047+
1048+
(setv
1049+
regen-frequency NotImplemented
1050+
grow-threshold None
1051+
grow-stem None
1052+
regen-limit 16)
1053+
1054+
(defmeth suffix-dict []
1055+
(dict
1056+
#** (.suffix-dict (super))
1057+
:pw @regen-power))
1058+
(defmeth info-bullets []
1059+
(.info-bullets (super)
1060+
#("Regeneration power" @regen-power)
1061+
#("Regeneration frequency" @regen-frequency)
1062+
#("Growth threshold" @grow-threshold)
1063+
#("Next life stage" @grow-stem)))
1064+
1065+
(setv grow-help "adds its regeneration frequency to its regeneration power. If the sum is ≥1, the integer part is removed to add to the monster's HP. Then, if the monster has a growth threshold and its HP is greater or equal, it advances to its next life stage (and loses all regeneration power).")
1066+
1067+
(defmeth act []
1068+
(doc f"Approach and Grow — The monster approaches per `Approach`. Then, it {@grow-help}")
1069+
(@approach)
1070+
(@regen))
1071+
1072+
(defmeth regen []
1073+
(+= @regen-power @regen-frequency)
1074+
(setv @hp (max
1075+
@hp
1076+
(min @regen-limit (+ @hp (pop-integer-part @regen-power)))))
1077+
(when (and (is-not @grow-threshold None) (>= @hp @grow-threshold))
1078+
(@make @pos @grow-stem :hp @hp)
1079+
(@rm-from-map)))
1080+
1081+
(setv flavor "Dragons are very, very large reptiles that hatch from eggs and grow stronger at an alarming rate. Their claws are razor-sharp from birth. As an adult, they can spew gouts of super-hot flame.\n\n Do not meddle in the affairs of dragons, for you are crunchy and taste good with ketchup."))
1082+
1083+
(deftile "e " "a dragon egg" Dragon
1084+
:iq-ix 195
1085+
:destruction-points 20
1086+
1087+
:regen-frequency (f/ 4 5)
1088+
:grow-threshold 4
1089+
:grow-stem "wyrmling"
1090+
1091+
:act (meth []
1092+
(doc f"Grow — The monster {@grow-help}")
1093+
(@regen)))
1094+
1095+
(deftile "D " "a wyrmling" Dragon
1096+
:color 'brown
1097+
:iq-ix 196
1098+
; Renamed from IQ's "wyrm" to make its youth more obvious.
1099+
:destruction-points 50
1100+
1101+
:damage-melee 8
1102+
1103+
:regen-frequency (f/ 3 5)
1104+
:grow-threshold 8
1105+
:grow-stem "dragon")
1106+
1107+
(deftile "D " "a dragon" Dragon
1108+
:iq-ix 197
1109+
1110+
:damage-melee 20
1111+
:damage-shot 20
1112+
1113+
:regen-frequency (f/ 2 5)
1114+
:destruction-points 250)
1115+
1116+
10421117
)

simalq/tile/unimplemented.hy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
[152 "random_gate"]
2222
[187 "magical_mirror"]
23-
[195 "dragon_egg"]
24-
[196 "wyrm"]
25-
[197 "dragon"]
2623
[202 "rotation_trap"]
2724
[203 "krogg"]
2825
[204 "vampire"]

tests/test_monster.hy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,3 +1014,31 @@
10141014
(use-item "wand of death" [3 0])
10151015
(assert-at 'E 'floor)
10161016
(assert (= G.player.hp 100)))
1017+
1018+
1019+
(defn test-dragon []
1020+
(init
1021+
:starting-hp 10,000
1022+
[:tiles ['floor "dragon egg"]])
1023+
1024+
; It takes a 1-HP dragon egg 4 turns to hatch. The newly created
1025+
; wyrmling doesn't get to move or attack on the same turn.
1026+
(wait 3)
1027+
(assert-at [2 0] "dragon egg")
1028+
(wait)
1029+
(assert-at [2 0] "wyrmling")
1030+
(assert-hp [2 0] 4)
1031+
; The wyrmling can now move and attack.
1032+
(wait)
1033+
(assert (= G.player.hp 10,000))
1034+
(assert-at 'E "wyrmling")
1035+
(wait)
1036+
(assert (= G.player.hp 9,992))
1037+
; After a total of 7 turns after hatching, the wyrmling becomes a
1038+
; dragon.
1039+
(wait 5)
1040+
(assert-at 'E "dragon")
1041+
(assert-hp 'E 8)
1042+
; The dragon can continue gaining HP, up to 16.
1043+
(wait 50)
1044+
(assert-hp 'E 16))

0 commit comments

Comments
 (0)