comparison clojure/com/aurellem/gb/hxc.clj @ 263:a44a2c459aeb

Corrected hxc-evolution so that pokemon with branched evolutions (i.e. eevee) will be fully included. As a result, altered hxc-evolution to return a list of hashes, one per evolution.
author Dylan Holmes <ocsenave@gmail.com>
date Mon, 26 Mar 2012 21:25:10 -0500
parents b2f9a0cb13e3
children 498af3c3cf15
comparison
equal deleted inserted replaced
262:868783405ac2 263:a44a2c459aeb
380 ([] 380 ([]
381 (internal-id com.aurellem.gb.gb-driver/original-rom))) 381 (internal-id com.aurellem.gb.gb-driver/original-rom)))
382 382
383 383
384 384
385 ;; nidoran gender change upon levelup
386 ;; (->
387 ;; @current-state
388 ;; rom
389 ;; vec
390 ;; (rewrite-memory
391 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
392 ;; [1 1 15])
393 ;; (rewrite-memory
394 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
395 ;; [1 1 3])
396 ;; (write-rom!)
397
398 ;; )
399
385 400
386 401
387 402
388 (defn hxc-advantage 403 (defn hxc-advantage
389 "The hardcoded type advantages in memory, returned as tuples of atk-type def-type multiplier. By default (i.e. if not listed here), 404 "The hardcoded type advantages in memory, returned as tuples of atk-type def-type multiplier. By default (i.e. if not listed here),
397 (partition 3 412 (partition 3
398 (take-while (partial not= 0xFF) 413 (take-while (partial not= 0xFF)
399 (drop 0x3E62D rom)))))) 414 (drop 0x3E62D rom))))))
400 415
401 416
402
403
404 (defn format-evo 417 (defn format-evo
405 [[method x y z & _]] 418 [coll]
406 (cond (= 0 method) 419 (let [method (first coll)]
407 {:method :none} 420 (cond (empty? coll) []
408 (= 1 method) 421 (= 0 method) [] ;; just in case
409 {:method :level-up 422 (= 1 method) ;; level-up evolution
410 :min-level x 423 (conj (format-evo (drop 3 coll))
411 :into y} 424 {:method :level-up
412 (= 2 method) 425 :min-level (nth coll 1)
413 {:method :item 426 :into (dec (nth coll 2))})
414 :item-id x 427
415 :min-level y 428 (= 2 method) ;; item evolution
416 :into z} 429 (conj (format-evo (drop 4 coll))
417 (= 3 method) 430 {:method :item
418 {:method :trade 431 :item (dec (nth coll 1))
419 :min-level x 432 :min-level (nth coll 2)
420 :into y})) 433 :into (dec (nth coll 3))})
421 434
422 (defn format-evo* 435 (= 3 method) ;; trade evolution
423 [[method x y z & _]] 436 (conj (format-evo (drop 3 coll))
424 (cond (= 0 method) 437 {:method :trade
425 {:method :none} 438 :min-level (nth coll 1) ;; always 1 for trade.
426 (= 1 method) 439 :into (dec (nth coll 2))}))))
427 {:method :level-up 440
428 :min-level x 441
429 :into (format-name (nth (hxc-pokenames) (dec y)))} 442 (defn hxc-ptrs-evolve
430 (= 2 method) 443 "A hardcoded collection of 190 pointers to evolution/learnset data,
431 {:method :item 444 in internal order."
432 :item (format-name (nth (hxc-items) (dec x))) 445 ([]
433 :min-level y 446 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))
434 :into (format-name (nth (hxc-pokenames) (dec z)))}
435 (= 3 method)
436 {:method :trade
437 :min-level x
438 :into (format-name (nth (hxc-pokenames) (dec y)))}))
439
440 (defn hxc-evolution
441 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
442 ([rom] 447 ([rom]
443 (let [names (hxc-pokenames rom) 448 (let [names (hxc-pokenames rom)
444 pkmn-count (count names) 449 pkmn-count (count names)
445 evo-data (drop 0x33fef rom)
446 ptrs 450 ptrs
447 (map (fn [[a b]](low-high a b)) 451 (map (fn [[a b]] (low-high a b))
448 (partition 2 452 (partition 2
449 (take (* 2 pkmn-count) 453 (take (* 2 pkmn-count)
450 (drop 0x3b1e5 rom)))) 454 (drop 0x3b1e5 rom))))]
451 ] 455 (map (partial + 0x34000) ptrs)
456
457 )))
458
459 (defn hxc-evolution
460 "Hardcoded evolution data in memory. The data exists at ROM@34000,
461 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
462 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
463 ([rom]
452 (apply assoc {} 464 (apply assoc {}
453 (interleave 465 (interleave
454 (map format-name (hxc-pokenames)) 466 (map format-name (hxc-pokenames))
455 (map 467 (map
456 (comp 468 (comp
457 format-evo 469 format-evo
458 (partial take 5) 470 (partial take-while (comp not zero?))
459 #(drop % rom) 471 #(drop % rom))
460 (partial + 0x34000)) 472 (hxc-ptrs-evolve rom)
461 ptrs))) 473 )))))
462 474
463 ))) 475 (defn hxc-evolution-pretty
464 476 "Like hxc-evolution, except it uses the names of items and pokemon
465 477 --- grabbed from ROM --- rather than their numerical identifiers."
466 (defn hxc-evolution* 478 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
467 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom)) 479 ([rom]
468 ([rom] 480 (let
469 (let [names (hxc-pokenames rom) 481 [poke-names (vec (map format-name (hxc-pokenames rom)))
470 pkmn-count (count names) 482 item-names (vec (map format-name (hxc-items rom)))
471 evo-data (drop 0x33fef rom) 483 use-names
472 ptrs 484 (fn [m]
473 (map (fn [[a b]](low-high a b)) 485 (loop [ks (keys m) new-map m]
474 (partition 2 486 (let [k (first ks)]
475 (take (* 2 pkmn-count) 487 (cond (nil? ks) new-map
476 (drop 0x3b1e5 rom)))) 488 (= k :into)
477 ] 489 (recur
478 (apply assoc {} 490 (next ks)
479 (interleave 491 (assoc new-map
480 (map format-name (hxc-pokenames)) 492 :into
481 (map 493 (poke-names
482 (comp 494 (:into
483 format-evo* 495 new-map))))
484 (partial take 5) 496 (= k :item)
485 #(drop % rom) 497 (recur
486 (partial + 0x34000)) 498 (next ks)
487 ptrs))) 499 (assoc new-map
488 500 :item
489 ))) 501 (item-names
490 502 (:item new-map))))
503 :else
504 (recur
505 (next ks)
506 new-map)
507 ))))]
508
509 (into {}
510 (map (fn [[pkmn evo-coll]]
511 [pkmn (map use-names evo-coll)])
512 (hxc-evolution rom))))))
513
491 514
492 515
493 516
494 517
495 ;; ********************** MANIPULATION FNS 518 ;; ********************** MANIPULATION FNS
533 com.aurellem.gb.gb-driver/original-rom attribute-map)) 556 com.aurellem.gb.gb-driver/original-rom attribute-map))
534 ([rom attribute-map] 557 ([rom attribute-map]
535 (filter-vals (partial submap? attribute-map) 558 (filter-vals (partial submap? attribute-map)
536 (hxc-move-data rom)))) 559 (hxc-move-data rom))))
537 560
538
539
540
541
542
543
544 561
545 562
546 563
547 564
548 ;; note for later: credits start at F1290 565 ;; note for later: credits start at F1290