ocsenave@347
|
1
|
rlm@218
|
2 (ns com.aurellem.gb.hxc
|
ocsenave@308
|
3 (:use (com.aurellem.gb assembly characters gb-driver util mem-util
|
ocsenave@281
|
4 constants species))
|
rlm@218
|
5 (:import [com.aurellem.gb.gb_driver SaveState]))
|
rlm@218
|
6
|
rlm@218
|
7
|
ocsenave@243
|
8
|
ocsenave@249
|
9
|
ocsenave@249
|
10 ; ************* HANDWRITTEN CONSTANTS
|
ocsenave@249
|
11
|
ocsenave@243
|
12 (def pkmn-types
|
ocsenave@272
|
13 [:normal ;;0
|
ocsenave@272
|
14 :fighting ;;1
|
ocsenave@272
|
15 :flying ;;2
|
ocsenave@272
|
16 :poison ;;3
|
ocsenave@272
|
17 :ground ;;4
|
ocsenave@272
|
18 :rock ;;5
|
ocsenave@272
|
19 :bird ;;6
|
ocsenave@272
|
20 :bug ;;7
|
ocsenave@272
|
21 :ghost ;;8
|
ocsenave@244
|
22 :A
|
ocsenave@244
|
23 :B
|
ocsenave@244
|
24 :C
|
ocsenave@244
|
25 :D
|
ocsenave@244
|
26 :E
|
ocsenave@244
|
27 :F
|
ocsenave@244
|
28 :G
|
ocsenave@244
|
29 :H
|
ocsenave@244
|
30 :I
|
ocsenave@244
|
31 :J
|
ocsenave@244
|
32 :K
|
ocsenave@272
|
33 :fire ;;20 (0x14)
|
ocsenave@272
|
34 :water ;;21 (0x15)
|
ocsenave@272
|
35 :grass ;;22 (0x16)
|
ocsenave@272
|
36 :electric ;;23 (0x17)
|
ocsenave@272
|
37 :psychic ;;24 (0x18)
|
ocsenave@272
|
38 :ice ;;25 (0x19)
|
ocsenave@272
|
39 :dragon ;;26 (0x1A)
|
ocsenave@244
|
40 ])
|
ocsenave@243
|
41
|
ocsenave@243
|
42
|
ocsenave@246
|
43 ;; question: when status effects claim to take
|
ocsenave@246
|
44 ;; their accuracy from the move accuracy, does
|
ocsenave@246
|
45 ;; this mean that the move always "hits" but the
|
ocsenave@246
|
46 ;; status effect may not?
|
ocsenave@246
|
47
|
ocsenave@246
|
48 (def move-effects
|
ocsenave@246
|
49 ["normal damage"
|
ocsenave@246
|
50 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?
|
ocsenave@246
|
51 "0x4C chance of poison"
|
ocsenave@246
|
52 "leech half of inflicted damage"
|
ocsenave@246
|
53 "0x19 chance of burn"
|
ocsenave@246
|
54 "0x19 chance of freeze"
|
ocsenave@246
|
55 "0x19 chance of paralyze"
|
ocsenave@259
|
56 "user faints; opponent defense halved during attack."
|
ocsenave@246
|
57 "leech half of inflicted damage ONLY if sleeping opponent."
|
ocsenave@246
|
58 "imitate last attack"
|
ocsenave@246
|
59 "user atk +1"
|
ocsenave@246
|
60 "user def +1"
|
ocsenave@246
|
61 "user spd +1"
|
ocsenave@246
|
62 "user spc +1"
|
ocsenave@246
|
63 "user acr +1" ;; unused?!
|
ocsenave@246
|
64 "user evd +1"
|
ocsenave@246
|
65 "get post-battle $ = 2*level*uses"
|
ocsenave@246
|
66 "0xFE acr, no matter what."
|
ocsenave@246
|
67 "opponent atk -1" ;; acr taken from move acr?
|
ocsenave@246
|
68 "opponent def -1" ;;
|
ocsenave@246
|
69 "opponent spd -1" ;;
|
ocsenave@246
|
70 "opponent spc -1" ;;
|
ocsenave@246
|
71 "opponent acr -1";;
|
ocsenave@246
|
72 "opponent evd -1"
|
ocsenave@246
|
73 "converts user's type to opponent's."
|
ocsenave@246
|
74 "(haze)"
|
ocsenave@246
|
75 "(bide)"
|
ocsenave@246
|
76 "(thrash)"
|
ocsenave@246
|
77 "(teleport)"
|
ocsenave@246
|
78 "(fury swipes)"
|
ocsenave@246
|
79 "attacks 2-5 turns" ;; unused? like rollout?
|
ocsenave@246
|
80 "0x19 chance of flinch"
|
ocsenave@246
|
81 "opponent sleep for 1-7 turns"
|
ocsenave@246
|
82 "0x66 chance of poison"
|
ocsenave@246
|
83 "0x4D chance of burn"
|
ocsenave@246
|
84 "0x4D chance of freeze"
|
ocsenave@246
|
85 "0x4D chance of paralyze"
|
ocsenave@246
|
86 "0x4D chance of flinch"
|
ocsenave@246
|
87 "one-hit KO"
|
ocsenave@246
|
88 "charge one turn, atk next."
|
ocsenave@246
|
89 "fixed damage, leaves 1HP." ;; how is dmg determined?
|
ocsenave@246
|
90 "fixed damage." ;; cf seismic toss, dragon rage, psywave.
|
ocsenave@246
|
91 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)
|
ocsenave@246
|
92 "charge one turn, atk next. (can't be hit when charging)"
|
ocsenave@246
|
93 "atk hits twice."
|
ocsenave@246
|
94 "user takes 1 damage if misses."
|
ocsenave@246
|
95 "evade status-lowering effects" ;;caused by you or also your opponent?
|
ocsenave@246
|
96 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"
|
ocsenave@246
|
97 "atk causes recoil dmg = 1/4 dmg dealt"
|
ocsenave@246
|
98 "confuses opponent" ;; acr taken from move acr
|
ocsenave@246
|
99 "user atk +2"
|
ocsenave@246
|
100 "user def +2"
|
ocsenave@246
|
101 "user spd +2"
|
ocsenave@246
|
102 "user spc +2"
|
ocsenave@246
|
103 "user acr +2" ;; unused!
|
ocsenave@246
|
104 "user evd +2" ;; unused!
|
ocsenave@246
|
105 "restores up to half of user's max hp." ;; broken: fails if the difference
|
ocsenave@246
|
106 ;; b/w max and current hp is one less than a multiple of 256.
|
ocsenave@246
|
107 "(transform)"
|
ocsenave@246
|
108 "opponent atk -2"
|
ocsenave@246
|
109 "opponent def -2"
|
ocsenave@246
|
110 "opponent spd -2"
|
ocsenave@246
|
111 "opponent spc -2"
|
ocsenave@246
|
112 "opponent acr -2"
|
ocsenave@246
|
113 "opponent evd -2"
|
ocsenave@246
|
114 "doubles user spc when attacked"
|
ocsenave@246
|
115 "doubles user def when attacked"
|
ocsenave@249
|
116 "just poisons opponent" ;;acr taken from move acr
|
ocsenave@249
|
117 "just paralyzes opponent" ;;
|
ocsenave@246
|
118 "0x19 chance opponent atk -1"
|
ocsenave@246
|
119 "0x19 chance opponent def -1"
|
ocsenave@246
|
120 "0x19 chance opponent spd -1"
|
ocsenave@246
|
121 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19
|
ocsenave@246
|
122 "0x19 chance opponent acr -1"
|
ocsenave@246
|
123 "0x19 chance opponent evd -1"
|
ocsenave@246
|
124 "???" ;; unused? no effect?
|
ocsenave@246
|
125 "???" ;; unused? no effect?
|
ocsenave@246
|
126 "0x19 chance opponent confused"
|
ocsenave@246
|
127 "atk hits twice. 0x33 chance opponent poisioned."
|
ocsenave@246
|
128 "broken. crash the game after attack."
|
ocsenave@246
|
129 "(substitute)"
|
ocsenave@246
|
130 "unless opponent faints, user must recharge after atk. some
|
ocsenave@246
|
131 exceptions apply."
|
ocsenave@246
|
132 "(rage)"
|
ocsenave@246
|
133 "(mimic)"
|
ocsenave@246
|
134 "(metronome)"
|
ocsenave@246
|
135 "(leech seed)"
|
ocsenave@246
|
136 "does nothing (splash)"
|
ocsenave@246
|
137 "(disable)"
|
ocsenave@246
|
138 ])
|
ocsenave@246
|
139
|
ocsenave@249
|
140 ;; ************** HARDCODED DATA
|
ocsenave@246
|
141
|
ocsenave@249
|
142 (defn hxc-thunk
|
ocsenave@259
|
143 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
|
ocsenave@249
|
144 splits it into a collection by 0x50. If rom is not supplied, uses the
|
ocsenave@249
|
145 original rom data."
|
ocsenave@249
|
146 [start length]
|
ocsenave@249
|
147 (fn self
|
ocsenave@249
|
148 ([rom]
|
ocsenave@249
|
149 (take-nth 2
|
ocsenave@249
|
150 (partition-by #(= % 0x50)
|
ocsenave@249
|
151 (take length
|
ocsenave@249
|
152 (drop start rom)))))
|
ocsenave@249
|
153 ([]
|
ocsenave@249
|
154 (self com.aurellem.gb.gb-driver/original-rom))))
|
ocsenave@246
|
155
|
ocsenave@249
|
156 (def hxc-thunk-words
|
ocsenave@249
|
157 "Same as hxc-thunk, except it interprets the rom data as characters,
|
ocsenave@249
|
158 returning a collection of strings."
|
ocsenave@249
|
159 (comp
|
ocsenave@249
|
160 (partial comp (partial map character-codes->str))
|
ocsenave@249
|
161 hxc-thunk))
|
ocsenave@249
|
162
|
ocsenave@249
|
163 ;; --------------------------------------------------
|
ocsenave@246
|
164
|
ocsenave@288
|
165
|
ocsenave@288
|
166
|
ocsenave@288
|
167 (defn hxc-pokenames-raw
|
ocsenave@288
|
168 "The hardcoded names of the 190 species in memory. List begins at
|
ocsenave@288
|
169 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
|
ocsenave@288
|
170 long, these names are stripped of padding. See also, hxc-pokedex-names"
|
ocsenave@288
|
171 ([]
|
ocsenave@288
|
172 (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@288
|
173 ([rom]
|
ocsenave@288
|
174 (let [count-species 190
|
ocsenave@288
|
175 name-length 10]
|
ocsenave@288
|
176 (map character-codes->str
|
ocsenave@288
|
177 (partition name-length
|
ocsenave@288
|
178 (map #(if (= 0x50 %) 0x00 %)
|
ocsenave@288
|
179 (take (* count-species name-length)
|
ocsenave@288
|
180 (drop 0xE8000
|
ocsenave@288
|
181 rom))))))))
|
ocsenave@288
|
182 (def hxc-pokenames
|
ocsenave@288
|
183 (comp
|
ocsenave@288
|
184 (partial map format-name)
|
ocsenave@288
|
185 hxc-pokenames-raw))
|
ocsenave@288
|
186
|
ocsenave@288
|
187
|
ocsenave@288
|
188
|
ocsenave@288
|
189
|
ocsenave@288
|
190 (defn hxc-pokedex-names
|
ocsenave@288
|
191 "The names of the pokemon in hardcoded pokedex order. List begins at
|
ocsenave@288
|
192 ROM@410B1. See also, hxc-pokenames."
|
ocsenave@288
|
193 ([] (hxc-pokedex-names
|
ocsenave@288
|
194 com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@288
|
195 ([rom]
|
ocsenave@288
|
196 (let [names (hxc-pokenames rom)]
|
ocsenave@288
|
197 (#(mapv %
|
ocsenave@288
|
198 ((comp range count keys) %))
|
ocsenave@288
|
199 (zipmap
|
ocsenave@288
|
200 (take (count names)
|
ocsenave@288
|
201 (drop 0x410b1 rom))
|
ocsenave@288
|
202
|
ocsenave@288
|
203 names)))))
|
ocsenave@288
|
204
|
ocsenave@288
|
205
|
ocsenave@288
|
206
|
ocsenave@306
|
207 ;; http://hax.iimarck.us/topic/581/
|
ocsenave@307
|
208 (defn hxc-cry
|
ocsenave@307
|
209 "The pokemon cry data in internal order. List begins at ROM@39462"
|
ocsenave@308
|
210 ([](hxc-cry com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@307
|
211 ([rom]
|
ocsenave@307
|
212 (zipmap
|
ocsenave@307
|
213 (hxc-pokenames rom)
|
ocsenave@307
|
214 (map
|
ocsenave@307
|
215 (fn [[cry-id pitch length]]
|
ocsenave@307
|
216 {:cry-id cry-id
|
ocsenave@307
|
217 :pitch pitch
|
ocsenave@307
|
218 :length length}
|
ocsenave@307
|
219 )
|
ocsenave@307
|
220 (partition 3
|
ocsenave@308
|
221 (drop 0x39462 rom))))))
|
ocsenave@306
|
222
|
ocsenave@307
|
223 (defn hxc-cry-groups
|
ocsenave@308
|
224 ([] (hxc-cry-groups com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@307
|
225 ([rom]
|
ocsenave@307
|
226 (map #(mapv first
|
ocsenave@307
|
227 (filter
|
ocsenave@307
|
228 (fn [[k v]]
|
ocsenave@307
|
229 (= % (:cry-id v)))
|
ocsenave@308
|
230 (hxc-cry)))
|
ocsenave@307
|
231 ((comp
|
ocsenave@307
|
232 range
|
ocsenave@307
|
233 count
|
ocsenave@307
|
234 set
|
ocsenave@307
|
235 (partial map :cry-id)
|
ocsenave@307
|
236 vals
|
ocsenave@307
|
237 hxc-cry)
|
ocsenave@307
|
238 rom))))
|
ocsenave@306
|
239
|
ocsenave@288
|
240
|
ocsenave@307
|
241 (defn cry-conversion!
|
ocsenave@307
|
242 "Convert Porygon's cry in ROM to be the cry of the given pokemon."
|
ocsenave@307
|
243 [pkmn]
|
ocsenave@307
|
244 (write-rom!
|
ocsenave@307
|
245 (rewrite-memory
|
ocsenave@307
|
246 (vec(rom))
|
ocsenave@307
|
247 0x3965D
|
ocsenave@307
|
248 (map second
|
ocsenave@307
|
249 ((hxc-cry) pkmn)))))
|
ocsenave@307
|
250
|
ocsenave@288
|
251 (def hxc-items-raw
|
ocsenave@249
|
252 "The hardcoded names of the items in memory. List begins at
|
ocsenave@249
|
253 ROM@045B7"
|
ocsenave@249
|
254 (hxc-thunk-words 0x45B7 870))
|
ocsenave@246
|
255
|
ocsenave@246
|
256 (def hxc-types
|
ocsenave@246
|
257 "The hardcoded type names in memory. List begins at ROM@27D99,
|
ocsenave@246
|
258 shortly before hxc-titles."
|
ocsenave@249
|
259 (hxc-thunk-words 0x27D99 102))
|
ocsenave@246
|
260
|
ocsenave@246
|
261 (def hxc-titles
|
ocsenave@246
|
262 "The hardcoded names of the trainer titles in memory. List begins at
|
ocsenave@246
|
263 ROM@27E77"
|
ocsenave@249
|
264 (hxc-thunk-words 0x27E77 196))
|
ocsenave@246
|
265
|
ocsenave@259
|
266
|
ocsenave@288
|
267 (def hxc-pokedex-text-raw
|
ocsenave@259
|
268 "The hardcoded pokedex entries in memory. List begins at
|
ocsenave@259
|
269 ROM@B8000, shortly before move names."
|
ocsenave@259
|
270 (hxc-thunk-words 0xB8000 14754))
|
ocsenave@259
|
271
|
ocsenave@288
|
272
|
ocsenave@288
|
273
|
ocsenave@288
|
274 (def hxc-items
|
ocsenave@288
|
275 "The hardcoded names of the items in memory, presented as
|
ocsenave@288
|
276 keywords. List begins at ROM@045B7. See also, hxc-items-raw."
|
ocsenave@288
|
277 (comp (partial map format-name) hxc-items-raw))
|
ocsenave@288
|
278
|
ocsenave@285
|
279 (defn hxc-pokedex-text
|
ocsenave@285
|
280 "The hardcoded pokedex entries in memory, presented as an
|
ocsenave@285
|
281 associative hash map. List begins at ROM@B8000."
|
ocsenave@285
|
282 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@285
|
283 ([rom]
|
ocsenave@285
|
284 (zipmap
|
ocsenave@285
|
285 (hxc-pokedex-names rom)
|
ocsenave@285
|
286 (cons nil ;; for missingno.
|
ocsenave@288
|
287 (hxc-pokedex-text-raw rom)))))
|
ocsenave@259
|
288
|
ocsenave@272
|
289 ;; In red/blue, pokedex stats are in internal order.
|
ocsenave@272
|
290 ;; In yellow, pokedex stats are in pokedex order.
|
ocsenave@259
|
291
|
ocsenave@259
|
292 (defn hxc-pokedex-stats
|
ocsenave@272
|
293 "The hardcoded pokedex stats (species height weight) in memory. List
|
ocsenave@272
|
294 begins at ROM@40687"
|
ocsenave@259
|
295 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@259
|
296 ([rom]
|
ocsenave@288
|
297 (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom))
|
ocsenave@288
|
298 pkmn-count (count pokedex-names)
|
ocsenave@259
|
299 ]
|
ocsenave@259
|
300 ((fn capture-stats
|
ocsenave@259
|
301 [n stats data]
|
ocsenave@259
|
302 (if (zero? n) stats
|
ocsenave@259
|
303 (let [[species
|
ocsenave@259
|
304 [_
|
ocsenave@259
|
305 height-ft
|
ocsenave@259
|
306 height-in
|
ocsenave@259
|
307 weight-1
|
ocsenave@259
|
308 weight-2
|
ocsenave@259
|
309 _
|
ocsenave@259
|
310 dex-ptr-1
|
ocsenave@259
|
311 dex-ptr-2
|
ocsenave@259
|
312 dex-bank
|
ocsenave@259
|
313 _
|
ocsenave@259
|
314 & data]]
|
ocsenave@259
|
315 (split-with (partial not= 0x50) data)]
|
ocsenave@259
|
316 (recur (dec n)
|
ocsenave@259
|
317 (assoc stats
|
ocsenave@285
|
318 (pokedex-names (- pkmn-count (dec n)))
|
ocsenave@259
|
319 {:species
|
ocsenave@285
|
320 (format-name (character-codes->str species))
|
ocsenave@259
|
321 :height-ft
|
ocsenave@259
|
322 height-ft
|
ocsenave@259
|
323 :height-in
|
ocsenave@259
|
324 height-in
|
ocsenave@259
|
325 :weight
|
ocsenave@259
|
326 (/ (low-high weight-1 weight-2) 10.)
|
ocsenave@259
|
327
|
ocsenave@259
|
328 ;; :text
|
ocsenave@259
|
329 ;; (character-codes->str
|
ocsenave@259
|
330 ;; (take-while
|
ocsenave@259
|
331 ;; (partial not= 0x50)
|
ocsenave@259
|
332 ;; (drop
|
ocsenave@259
|
333 ;; (+ 0xB8000
|
ocsenave@259
|
334 ;; -0x4000
|
ocsenave@259
|
335 ;; (low-high dex-ptr-1 dex-ptr-2))
|
ocsenave@259
|
336 ;; rom)))
|
ocsenave@259
|
337 })
|
ocsenave@259
|
338
|
ocsenave@259
|
339 data)
|
ocsenave@259
|
340
|
ocsenave@259
|
341
|
ocsenave@259
|
342 )))
|
ocsenave@259
|
343
|
ocsenave@259
|
344 pkmn-count
|
ocsenave@259
|
345 {}
|
ocsenave@259
|
346 (drop 0x40687 rom))) ))
|
ocsenave@259
|
347
|
ocsenave@259
|
348
|
ocsenave@259
|
349
|
ocsenave@259
|
350
|
ocsenave@259
|
351
|
ocsenave@259
|
352
|
ocsenave@259
|
353
|
ocsenave@246
|
354 (def hxc-places
|
ocsenave@246
|
355 "The hardcoded place names in memory. List begins at
|
ocsenave@249
|
356 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
|
ocsenave@249
|
357 (hxc-thunk-words 0x71500 560))
|
ocsenave@246
|
358
|
ocsenave@246
|
359
|
ocsenave@249
|
360 (defn hxc-dialog
|
ocsenave@249
|
361 "The hardcoded dialogue in memory, including in-game alerts. Dialog
|
ocsenave@249
|
362 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."
|
ocsenave@249
|
363 ([rom]
|
ocsenave@249
|
364 (map character-codes->str
|
ocsenave@249
|
365 (take-nth 2
|
ocsenave@249
|
366 (partition-by #(= % 0x57)
|
ocsenave@249
|
367 (take 0x0F728
|
ocsenave@249
|
368 (drop 0x98000 rom))))))
|
ocsenave@249
|
369 ([]
|
ocsenave@249
|
370 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
|
ocsenave@249
|
371
|
ocsenave@246
|
372
|
ocsenave@246
|
373 (def hxc-move-names
|
ocsenave@246
|
374 "The hardcoded move names in memory. List begins at ROM@BC000"
|
ocsenave@249
|
375 (hxc-thunk-words 0xBC000 1551))
|
ocsenave@246
|
376
|
ocsenave@249
|
377
|
ocsenave@249
|
378 (defn hxc-move-data
|
ocsenave@246
|
379 "The hardcoded (basic (move effects)) in memory. List begins at
|
ocsenave@249
|
380 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
|
ocsenave@249
|
381 :fx-txt}. The move descriptions are handwritten, not hardcoded."
|
ocsenave@249
|
382 ([]
|
ocsenave@249
|
383 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@249
|
384 ([rom]
|
ocsenave@249
|
385 (let [names (vec (hxc-move-names rom))
|
ocsenave@249
|
386 move-count (count names)
|
ocsenave@281
|
387 move-size 6
|
ocsenave@281
|
388 types pkmn-types ;;; !! hardcoded types
|
ocsenave@281
|
389 ]
|
ocsenave@249
|
390 (zipmap (map format-name names)
|
ocsenave@249
|
391 (map
|
ocsenave@281
|
392 (fn [[idx effect power type-id accuracy pp]]
|
ocsenave@249
|
393 {:name (names (dec idx))
|
ocsenave@249
|
394 :power power
|
ocsenave@249
|
395 :accuracy accuracy
|
ocsenave@249
|
396 :pp pp
|
ocsenave@281
|
397 :type (types type-id)
|
ocsenave@249
|
398 :fx-id effect
|
ocsenave@249
|
399 :fx-txt (get move-effects effect)
|
ocsenave@249
|
400 }
|
ocsenave@249
|
401 )
|
ocsenave@249
|
402
|
ocsenave@249
|
403 (partition move-size
|
ocsenave@249
|
404 (take (* move-size move-count)
|
ocsenave@249
|
405 (drop 0x38000 rom))))))))
|
ocsenave@246
|
406
|
ocsenave@246
|
407
|
ocsenave@246
|
408
|
ocsenave@249
|
409 (defn hxc-move-data*
|
ocsenave@249
|
410 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
|
ocsenave@249
|
411 ([]
|
ocsenave@249
|
412 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@249
|
413 ([rom]
|
ocsenave@249
|
414 (let [names (vec (hxc-move-names rom))
|
ocsenave@249
|
415 move-count (count names)
|
ocsenave@249
|
416 move-size 6
|
ocsenave@249
|
417 format-name (fn [s]
|
ocsenave@249
|
418 (keyword (.toLowerCase
|
ocsenave@249
|
419 (apply str
|
ocsenave@249
|
420 (map #(if (= % \space) "-" %) s)))))
|
ocsenave@249
|
421 ]
|
ocsenave@249
|
422 (zipmap (map format-name names)
|
ocsenave@249
|
423 (map
|
ocsenave@249
|
424 (fn [[idx effect power type accuracy pp]]
|
ocsenave@249
|
425 {:name (names (dec idx))
|
ocsenave@249
|
426 :power power
|
ocsenave@249
|
427 :accuracy (hex accuracy)
|
ocsenave@249
|
428 :pp pp
|
ocsenave@249
|
429 :fx-id (hex effect)
|
ocsenave@249
|
430 :fx-txt (get move-effects effect)
|
ocsenave@249
|
431 }
|
ocsenave@249
|
432 )
|
ocsenave@249
|
433
|
ocsenave@249
|
434 (partition move-size
|
ocsenave@249
|
435 (take (* move-size move-count)
|
ocsenave@249
|
436 (drop 0x38000 rom))))))))
|
ocsenave@243
|
437
|
ocsenave@243
|
438
|
ocsenave@283
|
439 (defn hxc-machines
|
ocsenave@312
|
440 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."
|
ocsenave@283
|
441 ([] (hxc-machines
|
ocsenave@283
|
442 com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@283
|
443 ([rom]
|
ocsenave@283
|
444 (let [moves (hxc-move-names rom)]
|
ocsenave@283
|
445 (zipmap
|
ocsenave@283
|
446 (range)
|
ocsenave@283
|
447 (take-while
|
ocsenave@283
|
448 (comp not nil?)
|
ocsenave@283
|
449 (map (comp
|
ocsenave@283
|
450 format-name
|
ocsenave@283
|
451 (zipmap
|
ocsenave@283
|
452 (range)
|
ocsenave@283
|
453 moves)
|
ocsenave@283
|
454 dec)
|
ocsenave@283
|
455 (take 100
|
ocsenave@283
|
456 (drop 0x1232D rom))))))))
|
ocsenave@285
|
457
|
ocsenave@285
|
458
|
ocsenave@259
|
459
|
ocsenave@259
|
460 (defn internal-id
|
ocsenave@259
|
461 ([rom]
|
ocsenave@259
|
462 (zipmap
|
ocsenave@288
|
463 (hxc-pokenames rom)
|
ocsenave@259
|
464 (range)))
|
ocsenave@259
|
465 ([]
|
ocsenave@259
|
466 (internal-id com.aurellem.gb.gb-driver/original-rom)))
|
ocsenave@285
|
467
|
ocsenave@285
|
468
|
ocsenave@285
|
469
|
ocsenave@259
|
470
|
ocsenave@259
|
471
|
ocsenave@263
|
472 ;; nidoran gender change upon levelup
|
ocsenave@263
|
473 ;; (->
|
ocsenave@263
|
474 ;; @current-state
|
ocsenave@263
|
475 ;; rom
|
ocsenave@263
|
476 ;; vec
|
ocsenave@263
|
477 ;; (rewrite-memory
|
ocsenave@263
|
478 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
|
ocsenave@263
|
479 ;; [1 1 15])
|
ocsenave@263
|
480 ;; (rewrite-memory
|
ocsenave@263
|
481 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
|
ocsenave@263
|
482 ;; [1 1 3])
|
ocsenave@263
|
483 ;; (write-rom!)
|
ocsenave@263
|
484
|
ocsenave@263
|
485 ;; )
|
ocsenave@263
|
486
|
ocsenave@259
|
487
|
ocsenave@259
|
488
|
ocsenave@259
|
489
|
ocsenave@249
|
490 (defn hxc-advantage
|
ocsenave@292
|
491 ;; in-game multipliers are stored as 10x their effective value
|
ocsenave@292
|
492 ;; to allow for fractional multipliers like 1/2
|
ocsenave@292
|
493
|
ocsenave@292
|
494 "The hardcoded type advantages in memory, returned as tuples of
|
ocsenave@292
|
495 atk-type def-type multiplier. By default (i.e. if not listed here),
|
ocsenave@292
|
496 the multiplier is 1. List begins at 0x3E62D."
|
ocsenave@249
|
497 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@249
|
498 ([rom]
|
ocsenave@249
|
499 (map
|
ocsenave@249
|
500 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
|
ocsenave@249
|
501 (get pkmn-types def (hex def))
|
ocsenave@249
|
502 (/ mult 10)])
|
ocsenave@249
|
503 (partition 3
|
ocsenave@249
|
504 (take-while (partial not= 0xFF)
|
ocsenave@249
|
505 (drop 0x3E62D rom))))))
|
ocsenave@243
|
506
|
ocsenave@243
|
507
|
ocsenave@281
|
508
|
ocsenave@263
|
509 (defn format-evo
|
ocsenave@347
|
510 "Parse a sequence of evolution data, returning a map. First is the
|
ocsenave@347
|
511 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the
|
ocsenave@347
|
512 method of evolution is by item (only stones will actually make pokemon
|
ocsenave@347
|
513 evolve, for some auxillary reason.) Finally, the minimum level for
|
ocsenave@347
|
514 evolution to occur (level 1 means no limit, which is used for trade
|
ocsenave@347
|
515 and item evolutions), followed by the internal id of the pokemon
|
ocsenave@347
|
516 into which to evolve. Hence, level up and trade evolutions are
|
ocsenave@347
|
517 described with 3
|
ocsenave@347
|
518 bytes; item evolutions with four."
|
ocsenave@263
|
519 [coll]
|
ocsenave@263
|
520 (let [method (first coll)]
|
ocsenave@263
|
521 (cond (empty? coll) []
|
ocsenave@263
|
522 (= 0 method) [] ;; just in case
|
ocsenave@263
|
523 (= 1 method) ;; level-up evolution
|
ocsenave@263
|
524 (conj (format-evo (drop 3 coll))
|
ocsenave@263
|
525 {:method :level-up
|
ocsenave@263
|
526 :min-level (nth coll 1)
|
ocsenave@263
|
527 :into (dec (nth coll 2))})
|
ocsenave@263
|
528
|
ocsenave@263
|
529 (= 2 method) ;; item evolution
|
ocsenave@263
|
530 (conj (format-evo (drop 4 coll))
|
ocsenave@263
|
531 {:method :item
|
ocsenave@263
|
532 :item (dec (nth coll 1))
|
ocsenave@263
|
533 :min-level (nth coll 2)
|
ocsenave@263
|
534 :into (dec (nth coll 3))})
|
ocsenave@243
|
535
|
ocsenave@263
|
536 (= 3 method) ;; trade evolution
|
ocsenave@263
|
537 (conj (format-evo (drop 3 coll))
|
ocsenave@263
|
538 {:method :trade
|
ocsenave@263
|
539 :min-level (nth coll 1) ;; always 1 for trade.
|
ocsenave@263
|
540 :into (dec (nth coll 2))}))))
|
ocsenave@243
|
541
|
ocsenave@243
|
542
|
ocsenave@263
|
543 (defn hxc-ptrs-evolve
|
ocsenave@267
|
544 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,
|
ocsenave@263
|
545 in internal order."
|
ocsenave@263
|
546 ([]
|
ocsenave@263
|
547 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@259
|
548 ([rom]
|
ocsenave@288
|
549 (let [
|
ocsenave@288
|
550 pkmn-count (count (hxc-pokenames-raw)) ;; 190
|
ocsenave@259
|
551 ptrs
|
ocsenave@263
|
552 (map (fn [[a b]] (low-high a b))
|
ocsenave@259
|
553 (partition 2
|
ocsenave@259
|
554 (take (* 2 pkmn-count)
|
ocsenave@263
|
555 (drop 0x3b1e5 rom))))]
|
ocsenave@263
|
556 (map (partial + 0x34000) ptrs)
|
ocsenave@263
|
557
|
ocsenave@263
|
558 )))
|
ocsenave@263
|
559
|
ocsenave@267
|
560
|
ocsenave@267
|
561 (defn hxc-learnsets
|
ocsenave@267
|
562 "Hardcoded map associating pokemon names to lists of pairs [lvl
|
ocsenave@267
|
563 move] of abilities they learn as they level up. The data
|
ocsenave@347
|
564 exists at ROM@34000, sorted by internal order. Pointers to the data
|
ocsenave@267
|
565 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"
|
ocsenave@267
|
566 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@267
|
567 ([rom]
|
ocsenave@267
|
568 (apply assoc
|
ocsenave@267
|
569 {}
|
ocsenave@267
|
570 (interleave
|
ocsenave@288
|
571 (hxc-pokenames rom)
|
ocsenave@267
|
572 (map (comp
|
ocsenave@268
|
573 (partial map
|
ocsenave@268
|
574 (fn [[lvl mv]] [lvl (dec mv)]))
|
ocsenave@267
|
575 (partial partition 2)
|
ocsenave@267
|
576 ;; keep the learnset data
|
ocsenave@267
|
577 (partial take-while (comp not zero?))
|
ocsenave@267
|
578 ;; skip the evolution data
|
ocsenave@267
|
579 rest
|
ocsenave@267
|
580 (partial drop-while (comp not zero?)))
|
ocsenave@267
|
581 (map #(drop % rom)
|
ocsenave@267
|
582 (hxc-ptrs-evolve rom)))))))
|
ocsenave@267
|
583
|
ocsenave@267
|
584 (defn hxc-learnsets-pretty
|
ocsenave@267
|
585 "Live hxc-learnsets except it reports the name of each move --- as
|
ocsenave@267
|
586 it appears in rom --- rather than the move index."
|
ocsenave@267
|
587 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@267
|
588 ([rom]
|
ocsenave@267
|
589 (let [moves (vec(map format-name (hxc-move-names)))]
|
ocsenave@267
|
590 (into {}
|
ocsenave@267
|
591 (map (fn [[pkmn learnset]]
|
ocsenave@268
|
592 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])
|
ocsenave@267
|
593 learnset)])
|
ocsenave@267
|
594 (hxc-learnsets rom))))))
|
ocsenave@267
|
595
|
ocsenave@267
|
596
|
ocsenave@267
|
597
|
ocsenave@267
|
598
|
ocsenave@263
|
599 (defn hxc-evolution
|
ocsenave@263
|
600 "Hardcoded evolution data in memory. The data exists at ROM@34000,
|
ocsenave@263
|
601 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
|
ocsenave@263
|
602 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@263
|
603 ([rom]
|
ocsenave@259
|
604 (apply assoc {}
|
ocsenave@259
|
605 (interleave
|
ocsenave@288
|
606 (hxc-pokenames rom)
|
ocsenave@259
|
607 (map
|
ocsenave@259
|
608 (comp
|
ocsenave@259
|
609 format-evo
|
ocsenave@263
|
610 (partial take-while (comp not zero?))
|
ocsenave@263
|
611 #(drop % rom))
|
ocsenave@263
|
612 (hxc-ptrs-evolve rom)
|
ocsenave@263
|
613 )))))
|
ocsenave@259
|
614
|
ocsenave@263
|
615 (defn hxc-evolution-pretty
|
ocsenave@263
|
616 "Like hxc-evolution, except it uses the names of items and pokemon
|
ocsenave@263
|
617 --- grabbed from ROM --- rather than their numerical identifiers."
|
ocsenave@263
|
618 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@263
|
619 ([rom]
|
ocsenave@263
|
620 (let
|
ocsenave@288
|
621 [poke-names (vec (hxc-pokenames rom))
|
ocsenave@288
|
622 item-names (vec (hxc-items rom))
|
ocsenave@263
|
623 use-names
|
ocsenave@263
|
624 (fn [m]
|
ocsenave@263
|
625 (loop [ks (keys m) new-map m]
|
ocsenave@263
|
626 (let [k (first ks)]
|
ocsenave@263
|
627 (cond (nil? ks) new-map
|
ocsenave@263
|
628 (= k :into)
|
ocsenave@263
|
629 (recur
|
ocsenave@263
|
630 (next ks)
|
ocsenave@263
|
631 (assoc new-map
|
ocsenave@263
|
632 :into
|
ocsenave@263
|
633 (poke-names
|
ocsenave@263
|
634 (:into
|
ocsenave@263
|
635 new-map))))
|
ocsenave@263
|
636 (= k :item)
|
ocsenave@263
|
637 (recur
|
ocsenave@263
|
638 (next ks)
|
ocsenave@263
|
639 (assoc new-map
|
ocsenave@263
|
640 :item
|
ocsenave@263
|
641 (item-names
|
ocsenave@263
|
642 (:item new-map))))
|
ocsenave@263
|
643 :else
|
ocsenave@263
|
644 (recur
|
ocsenave@263
|
645 (next ks)
|
ocsenave@263
|
646 new-map)
|
ocsenave@263
|
647 ))))]
|
ocsenave@259
|
648
|
ocsenave@263
|
649 (into {}
|
ocsenave@263
|
650 (map (fn [[pkmn evo-coll]]
|
ocsenave@263
|
651 [pkmn (map use-names evo-coll)])
|
ocsenave@263
|
652 (hxc-evolution rom))))))
|
ocsenave@243
|
653
|
ocsenave@243
|
654
|
ocsenave@273
|
655 (defn hxc-pokemon-base
|
ocsenave@273
|
656 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@273
|
657 ([rom]
|
ocsenave@273
|
658 (let [entry-size 28
|
ocsenave@273
|
659 pkmn-count (count (hxc-pokedex-text rom))
|
ocsenave@285
|
660 pokemon (rest (hxc-pokedex-names))
|
ocsenave@273
|
661 types (apply assoc {}
|
ocsenave@273
|
662 (interleave
|
ocsenave@273
|
663 (range)
|
ocsenave@273
|
664 pkmn-types)) ;;!! softcoded
|
ocsenave@273
|
665 moves (apply assoc {}
|
ocsenave@273
|
666 (interleave
|
ocsenave@273
|
667 (range)
|
ocsenave@273
|
668 (map format-name
|
ocsenave@273
|
669 (hxc-move-names rom))))
|
ocsenave@288
|
670 machines (hxc-machines)
|
ocsenave@273
|
671 ]
|
ocsenave@285
|
672 (zipmap
|
ocsenave@285
|
673 pokemon
|
ocsenave@285
|
674 (map
|
ocsenave@285
|
675 (fn [[n
|
ocsenave@285
|
676 rating-hp
|
ocsenave@285
|
677 rating-atk
|
ocsenave@285
|
678 rating-def
|
ocsenave@285
|
679 rating-speed
|
ocsenave@285
|
680 rating-special
|
ocsenave@285
|
681 type-1
|
ocsenave@285
|
682 type-2
|
ocsenave@285
|
683 rarity
|
ocsenave@285
|
684 rating-xp
|
ocsenave@285
|
685 pic-dimensions ;; tile_width|tile_height (8px/tile)
|
ocsenave@285
|
686 ptr-pic-obverse-1
|
ocsenave@285
|
687 ptr-pic-obverse-2
|
ocsenave@285
|
688 ptr-pic-reverse-1
|
ocsenave@285
|
689 ptr-pic-reverse-2
|
ocsenave@285
|
690 move-1
|
ocsenave@285
|
691 move-2
|
ocsenave@285
|
692 move-3
|
ocsenave@285
|
693 move-4
|
ocsenave@285
|
694 growth-rate
|
ocsenave@285
|
695 &
|
ocsenave@285
|
696 TMs|HMs]]
|
ocsenave@285
|
697 (let
|
ocsenave@285
|
698 [base-moves
|
ocsenave@285
|
699 (mapv moves
|
ocsenave@285
|
700 ((comp
|
ocsenave@285
|
701 ;; since the game uses zero as a delimiter,
|
ocsenave@285
|
702 ;; it must also increment all move indices by 1.
|
ocsenave@285
|
703 ;; heren we decrement to correct this.
|
ocsenave@285
|
704 (partial map dec)
|
ocsenave@285
|
705 (partial take-while (comp not zero?)))
|
ocsenave@285
|
706 [move-1 move-2 move-3 move-4]))
|
ocsenave@285
|
707
|
ocsenave@285
|
708 types
|
ocsenave@285
|
709 (set (list (types type-1)
|
ocsenave@285
|
710 (types type-2)))
|
ocsenave@285
|
711 TMs|HMs
|
ocsenave@285
|
712 (map
|
ocsenave@285
|
713 (comp
|
ocsenave@285
|
714 (partial map first)
|
ocsenave@285
|
715 (partial remove (comp zero? second)))
|
ocsenave@285
|
716 (split-at
|
ocsenave@285
|
717 50
|
ocsenave@285
|
718 (map vector
|
ocsenave@285
|
719 (rest(range))
|
ocsenave@285
|
720 (reduce concat
|
ocsenave@285
|
721 (map
|
ocsenave@285
|
722 #(take 8
|
ocsenave@285
|
723 (concat (bit-list %)
|
ocsenave@285
|
724 (repeat 0)))
|
ocsenave@285
|
725
|
ocsenave@273
|
726 TMs|HMs)))))
|
ocsenave@285
|
727
|
ocsenave@285
|
728 TMs (vec (first TMs|HMs))
|
ocsenave@285
|
729 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))
|
ocsenave@285
|
730
|
ocsenave@285
|
731
|
ocsenave@285
|
732 ]
|
ocsenave@285
|
733
|
ocsenave@285
|
734
|
ocsenave@285
|
735 {:dex# n
|
ocsenave@285
|
736 :base-moves base-moves
|
ocsenave@285
|
737 :types types
|
ocsenave@285
|
738 :TMs TMs
|
ocsenave@285
|
739 :HMs HMs
|
ocsenave@285
|
740 :base-hp rating-hp
|
ocsenave@285
|
741 :base-atk rating-atk
|
ocsenave@285
|
742 :base-def rating-def
|
ocsenave@285
|
743 :base-speed rating-speed
|
ocsenave@285
|
744 :base-special rating-special
|
ocsenave@310
|
745 :o0 pic-dimensions
|
ocsenave@310
|
746 :o1 ptr-pic-obverse-1
|
ocsenave@310
|
747 :o2 ptr-pic-obverse-2
|
ocsenave@285
|
748 }))
|
ocsenave@285
|
749
|
ocsenave@285
|
750 (partition entry-size
|
ocsenave@285
|
751 (take (* entry-size pkmn-count)
|
ocsenave@285
|
752 (drop 0x383DE
|
ocsenave@285
|
753 rom))))))))
|
ocsenave@285
|
754
|
ocsenave@285
|
755
|
ocsenave@310
|
756 (defn hxc-intro-pkmn
|
ocsenave@310
|
757 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's
|
ocsenave@310
|
758 internal id is stored at ROM@5EDB."
|
ocsenave@310
|
759 ([] (hxc-intro-pkmn
|
ocsenave@310
|
760 com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@310
|
761 ([rom]
|
ocsenave@310
|
762 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))
|
ocsenave@310
|
763
|
ocsenave@310
|
764 (defn sxc-intro-pkmn!
|
ocsenave@310
|
765 "Set the hardcoded pokemon to display in Prof. Oak's introduction."
|
ocsenave@310
|
766 [pokemon]
|
ocsenave@310
|
767 (write-rom!
|
ocsenave@310
|
768 (rewrite-rom 0x5EDB
|
ocsenave@310
|
769 [
|
ocsenave@310
|
770 (inc
|
ocsenave@310
|
771 ((zipmap
|
ocsenave@310
|
772 (hxc-pokenames)
|
ocsenave@310
|
773 (range))
|
ocsenave@310
|
774 pokemon))])))
|
ocsenave@285
|
775
|
ocsenave@310
|
776
|
ocsenave@282
|
777 (defn hxc-item-prices
|
ocsenave@282
|
778 "The hardcoded list of item prices in memory. List begins at ROM@4495"
|
ocsenave@282
|
779 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@282
|
780 ([rom]
|
ocsenave@288
|
781 (let [items (hxc-items rom)
|
ocsenave@282
|
782 price-size 3]
|
ocsenave@282
|
783 (zipmap items
|
ocsenave@282
|
784 (map (comp
|
ocsenave@282
|
785 ;; zero-cost items are "priceless"
|
ocsenave@282
|
786 #(if (zero? %) :priceless %)
|
ocsenave@282
|
787 decode-bcd butlast)
|
ocsenave@282
|
788 (partition price-size
|
ocsenave@282
|
789 (take (* price-size (count items))
|
ocsenave@282
|
790 (drop 0x4495 rom))))))))
|
ocsenave@273
|
791
|
ocsenave@281
|
792 (defn hxc-shops
|
ocsenave@281
|
793 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@281
|
794 ([rom]
|
ocsenave@288
|
795 (let [items (zipmap (range) (hxc-items rom))
|
ocsenave@281
|
796
|
ocsenave@281
|
797 ;; temporarily softcode the TM items
|
ocsenave@281
|
798 items (into
|
ocsenave@281
|
799 items
|
ocsenave@281
|
800 (map (juxt identity
|
ocsenave@281
|
801 (comp keyword
|
ocsenave@281
|
802 (partial str "tm-")
|
ocsenave@281
|
803 (partial + 1 -200)
|
ocsenave@281
|
804 ))
|
ocsenave@281
|
805 (take 200 (drop 200 (range)))))
|
ocsenave@282
|
806
|
ocsenave@281
|
807 ]
|
ocsenave@281
|
808
|
ocsenave@281
|
809 ((fn parse-shop [coll [num-items & items-etc]]
|
ocsenave@282
|
810 (let [inventory (take-while
|
ocsenave@282
|
811 (partial not= 0xFF)
|
ocsenave@282
|
812 items-etc)
|
ocsenave@281
|
813 [separator & items-etc] (drop num-items (rest items-etc))]
|
ocsenave@281
|
814 (if (= separator 0x50)
|
ocsenave@281
|
815 (map (partial mapv (comp items dec)) (conj coll inventory))
|
ocsenave@281
|
816 (recur (conj coll inventory) items-etc)
|
ocsenave@281
|
817 )
|
ocsenave@281
|
818 ))
|
ocsenave@281
|
819
|
ocsenave@281
|
820 '()
|
ocsenave@282
|
821 (drop 0x233C rom))
|
ocsenave@281
|
822
|
ocsenave@281
|
823
|
ocsenave@281
|
824 )))
|
ocsenave@281
|
825
|
ocsenave@281
|
826
|
ocsenave@273
|
827
|
ocsenave@292
|
828
|
ocsenave@292
|
829
|
ocsenave@292
|
830 (defn hxc-ptrs-wild
|
ocsenave@292
|
831 "A list of the hardcoded wild encounter data in memory. Pointers
|
ocsenave@292
|
832 begin at ROM@0CB95; data begins at ROM@0x04D89"
|
ocsenave@292
|
833 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@292
|
834 ([rom]
|
ocsenave@292
|
835 (let [ptrs
|
ocsenave@292
|
836 (map (fn [[a b]] (+ a (* 0x100 b)))
|
ocsenave@292
|
837 (take-while (partial not= (list 0xFF 0xFF))
|
ocsenave@292
|
838 (partition 2 (drop 0xCB95 rom))))]
|
ocsenave@292
|
839 ptrs)))
|
ocsenave@292
|
840
|
ocsenave@292
|
841
|
ocsenave@292
|
842
|
ocsenave@292
|
843 (defn hxc-wilds
|
ocsenave@292
|
844 "A list of the hardcoded wild encounter data in memory. Pointers
|
ocsenave@292
|
845 begin at ROM@0CB95; data begins at ROM@0x04D89"
|
ocsenave@292
|
846 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))
|
ocsenave@292
|
847 ([rom]
|
ocsenave@292
|
848 (let [pokenames (zipmap (range) (hxc-pokenames rom))]
|
ocsenave@292
|
849 (map
|
ocsenave@292
|
850 (partial map (fn [[a b]] {:species (pokenames (dec b)) :level
|
ocsenave@292
|
851 a}))
|
ocsenave@292
|
852 (partition 10
|
ocsenave@292
|
853
|
ocsenave@292
|
854 (take-while (comp (partial not= 1)
|
ocsenave@292
|
855 first)
|
ocsenave@292
|
856 (partition 2
|
ocsenave@292
|
857 (drop 0xCD8C rom))
|
ocsenave@292
|
858
|
ocsenave@292
|
859 ))))))
|
ocsenave@292
|
860
|
ocsenave@292
|
861
|
ocsenave@292
|
862
|
ocsenave@292
|
863
|
ocsenave@292
|
864
|
ocsenave@292
|
865
|
ocsenave@292
|
866
|
ocsenave@292
|
867
|
ocsenave@292
|
868
|
ocsenave@292
|
869
|
ocsenave@292
|
870
|
ocsenave@292
|
871
|
ocsenave@292
|
872
|
ocsenave@292
|
873
|
ocsenave@249
|
874 ;; ********************** MANIPULATION FNS
|
ocsenave@249
|
875
|
ocsenave@249
|
876
|
ocsenave@285
|
877 (defn same-type
|
ocsenave@285
|
878 ([pkmn move]
|
ocsenave@288
|
879 (same-type
|
ocsenave@285
|
880 com.aurellem.gb.gb-driver/original-rom pkmn move))
|
ocsenave@285
|
881 ([rom pkmn move]
|
ocsenave@285
|
882 (((comp :types (hxc-pokemon-base rom)) pkmn)
|
ocsenave@285
|
883 ((comp :type (hxc-move-data rom)) move))))
|
ocsenave@285
|
884
|
ocsenave@285
|
885
|
ocsenave@249
|
886
|
ocsenave@249
|
887
|
ocsenave@249
|
888 (defn submap?
|
ocsenave@249
|
889 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."
|
ocsenave@249
|
890 [map-small map-big]
|
ocsenave@249
|
891 (cond (empty? map-small) true
|
ocsenave@249
|
892 (and
|
ocsenave@249
|
893 (contains? map-big (ffirst map-small))
|
ocsenave@249
|
894 (= (get map-big (ffirst map-small))
|
ocsenave@249
|
895 (second (first map-small))))
|
ocsenave@249
|
896 (recur (next map-small) map-big)
|
ocsenave@249
|
897
|
ocsenave@249
|
898 :else false))
|
ocsenave@249
|
899
|
ocsenave@249
|
900
|
ocsenave@249
|
901 (defn search-map [proto-map maps]
|
ocsenave@249
|
902 "Returns all the maps that make the same associations as proto-map."
|
ocsenave@249
|
903 (some (partial submap? proto-map) maps))
|
ocsenave@249
|
904
|
rlm@252
|
905 (defn filter-vals
|
rlm@252
|
906 "Returns a map consisting of all the pairs [key val] for
|
rlm@252
|
907 which (pred key) returns true."
|
rlm@252
|
908 [pred map]
|
rlm@252
|
909 (reduce (partial apply assoc) {}
|
rlm@252
|
910 (filter (fn [[k v]] (pred v)) map)))
|
ocsenave@249
|
911
|
ocsenave@249
|
912
|
ocsenave@249
|
913 (defn search-moves
|
rlm@252
|
914 "Returns a subcollection of all hardcoded moves with the
|
rlm@252
|
915 given attributes. Attributes consist of :name :power
|
rlm@252
|
916 :accuracy :pp :fx-id
|
rlm@252
|
917 (and also :fx-txt, but it contains the same information
|
rlm@252
|
918 as :fx-id)"
|
ocsenave@249
|
919 ([attribute-map]
|
rlm@252
|
920 (search-moves
|
rlm@252
|
921 com.aurellem.gb.gb-driver/original-rom attribute-map))
|
ocsenave@249
|
922 ([rom attribute-map]
|
rlm@252
|
923 (filter-vals (partial submap? attribute-map)
|
rlm@252
|
924 (hxc-move-data rom))))
|
ocsenave@249
|
925
|
ocsenave@249
|
926
|
ocsenave@249
|
927
|
ocsenave@249
|
928
|
ocsenave@243
|
929
|
ocsenave@283
|
930 ;; note: 0x2f31 contains the names "TM" "HM"?
|
ocsenave@283
|
931
|
ocsenave@246
|
932 ;; note for later: credits start at F1290
|
ocsenave@243
|
933
|
ocsenave@346
|
934 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??
|
ocsenave@243
|
935
|
ocsenave@346
|
936 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)
|
ocsenave@346
|
937
|
ocsenave@346
|
938 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.
|
ocsenave@346
|
939 ;; The first instance is for Machines; the second, for stones.
|
ocsenave@243
|
940
|
ocsenave@347
|
941 ;; 0x251A (in indexable mem): image decompression routine seems to begin here.
|
ocsenave@347
|
942
|
ocsenave@347
|
943
|
ocsenave@246
|
944 (comment
|
ocsenave@243
|
945
|
rlm@218
|
946 (def hxc-later
|
rlm@218
|
947 "Running this code produces, e.g. hardcoded names NPCs give
|
rlm@218
|
948 their pokemon. Will sort through it later."
|
rlm@218
|
949 (print (character-codes->str(take 10000
|
rlm@218
|
950 (drop 0x71597
|
rlm@218
|
951 (rom (root)))))))
|
rlm@218
|
952
|
rlm@218
|
953 (let [dex
|
rlm@218
|
954 (partition-by #(= 0x50 %)
|
rlm@218
|
955 (take 2540
|
rlm@218
|
956 (drop 0x40687
|
rlm@218
|
957 (rom (root)))))]
|
rlm@218
|
958 (def dex dex)
|
rlm@218
|
959 (def hxc-species
|
rlm@218
|
960 (map character-codes->str
|
rlm@218
|
961 (take-nth 4 dex))))
|
ocsenave@259
|
962 )
|