ref: c6b12b07b302b82765181b2521e1e0f2ca5f7725
parent: aeee49d29be52d56b542706cf6524eb9b2c4c279
author: Remy Oukaour <remy.oukaour@gmail.com>
date: Sun Dec 24 15:11:03 EST 2017
Group Pokérus files in engine/pokerus/
--- a/engine/pokerus.asm
+++ /dev/null
@@ -1,160 +1,0 @@
-GivePokerusAndConvertBerries: ; 2ed44
- call ConvertBerriesToBerryJuice
- ld hl, PartyMon1PokerusStatus
- ld a, [PartyCount]
- ld b, a
- ld de, PARTYMON_STRUCT_LENGTH
-; Check to see if any of your Pokemon already has Pokerus.
-; If so, sample its spread through your party.
-; This means that you cannot get Pokerus de novo while
-; a party member has an active infection.
-.loopMons
- ld a, [hl]
- and $f
- jr nz, .TrySpreadPokerus
- add hl, de
- dec b
- jr nz, .loopMons
-
-; If we haven't been to Goldenrod City at least once,
-; prevent the contraction of Pokerus.
- ld hl, StatusFlags2
- bit 6, [hl]
- ret z
- call Random
- ld a, [hRandomAdd]
- and a
- ret nz
- ld a, [hRandomSub]
- cp $3
- ret nc ; 3/65536 chance (00 00, 00 01 or 00 02)
- ld a, [PartyCount]
- ld b, a
-.randomMonSelectLoop
- call Random
- and $7
- cp b
- jr nc, .randomMonSelectLoop
- ld hl, PartyMon1PokerusStatus
- call GetPartyLocation ; get pokerus byte of random mon
- ld a, [hl]
- and $f0
- ret nz ; if it already has pokerus, do nothing
-.randomPokerusLoop ; Simultaneously sample the strain and duration
- call Random
- and a
- jr z, .randomPokerusLoop
- ld b, a
- and $f0
- jr z, .load_pkrs
- ld a, b
- and $7
- inc a
-.load_pkrs
- ld b, a ; this should come before the label
- swap b
- and $3
- inc a
- add b
- ld [hl], a
- ret
-
-.TrySpreadPokerus:
- call Random
- cp 1 + 33 percent
- ret nc ; 1/3 chance
-
- ld a, [PartyCount]
- cp 1
- ret z ; only one mon, nothing to do
-
- ld c, [hl]
- ld a, b
- cp 2
- jr c, .checkPreviousMonsLoop ; no more mons after this one, go backwards
-
- call Random
- cp 1 + 50 percent
- jr c, .checkPreviousMonsLoop ; 1/2 chance, go backwards
-.checkFollowingMonsLoop
- add hl, de
- ld a, [hl]
- and a
- jr z, .infectMon
- ld c, a
- and $3
- ret z ; if mon has cured pokerus, stop searching
- dec b ; go on to next mon
- ld a, b
- cp 1
- jr nz, .checkFollowingMonsLoop ; no more mons left
- ret
-
-.checkPreviousMonsLoop
- ld a, [PartyCount]
- cp b
- ret z ; no more mons
- ld a, l
- sub e
- ld l, a
- ld a, h
- sbc d
- ld h, a
- ld a, [hl]
- and a
- jr z, .infectMon
- ld c, a
- and $3
- ret z ; if mon has cured pokerus, stop searching
- inc b ; go on to next mon
- jr .checkPreviousMonsLoop
-
-.infectMon
- ld a, c
- and $f0
- ld b, a
- ld a, c
- swap a
- and $3
- inc a
- add b
- ld [hl], a
- ret
-
-; any berry held by a Shuckle may be converted to berry juice
-ConvertBerriesToBerryJuice: ; 2ede6
- ld hl, StatusFlags2
- bit 6, [hl]
- ret z
- call Random
- cp $10
- ret nc ; 1/16 chance
- ld hl, PartyMons
- ld a, [PartyCount]
-.partyMonLoop
- push af
- push hl
- ld a, [hl]
- cp SHUCKLE
- jr nz, .loopMon
- ld bc, MON_ITEM
- add hl, bc
- ld a, [hl]
- cp BERRY
- jr z, .convertToJuice
-
-.loopMon
- pop hl
- ld bc, PARTYMON_STRUCT_LENGTH
- add hl, bc
- pop af
- dec a
- jr nz, .partyMonLoop
- ret
-
-.convertToJuice
- ld a, BERRY_JUICE
- ld [hl], a
- pop hl
- pop af
- ret
--- /dev/null
+++ b/engine/pokerus/apply_pokerus_tick.asm
@@ -1,0 +1,26 @@
+ApplyPokerusTick: ; 13988
+; decreases all pokemon's pokerus counter by b. if the lower nybble reaches zero, the pokerus is cured.
+ ld hl, PartyMon1PokerusStatus ; PartyMon1 + MON_PKRS
+ ld a, [PartyCount]
+ and a
+ ret z ; make sure it's not wasting time on an empty party
+ ld c, a
+.loop
+ ld a, [hl]
+ and $f ; lower nybble is the number of days remaining
+ jr z, .next ; if already 0, skip
+ sub b ; subtract the number of days
+ jr nc, .ok ; max(result, 0)
+ xor a
+.ok
+ ld d, a ; back up this value because we need to preserve the strain (upper nybble)
+ ld a, [hl]
+ and $f0
+ add d
+ ld [hl], a ; this prevents a cured pokemon from recontracting pokerus
+.next
+ ld de, PARTYMON_STRUCT_LENGTH
+ add hl, de
+ dec c
+ jr nz, .loop
+ ret
--- /dev/null
+++ b/engine/pokerus/check_pokerus.asm
@@ -1,0 +1,25 @@
+CheckPokerus: ; 4d860
+; Return carry if a monster in your party has Pokerus
+
+; Get number of monsters to iterate over
+ ld a, [PartyCount]
+ and a
+ jr z, .NoPokerus
+ ld b, a
+; Check each monster in the party for Pokerus
+ ld hl, PartyMon1PokerusStatus
+ ld de, PARTYMON_STRUCT_LENGTH
+.Check:
+ ld a, [hl]
+ and $0f ; only the bottom nybble is used
+ jr nz, .HasPokerus
+; Next PartyMon
+ add hl, de
+ dec b
+ jr nz, .Check
+.NoPokerus:
+ and a
+ ret
+.HasPokerus:
+ scf
+ ret
--- /dev/null
+++ b/engine/pokerus/pokerus.asm
@@ -1,0 +1,160 @@
+GivePokerusAndConvertBerries: ; 2ed44
+ call ConvertBerriesToBerryJuice
+ ld hl, PartyMon1PokerusStatus
+ ld a, [PartyCount]
+ ld b, a
+ ld de, PARTYMON_STRUCT_LENGTH
+; Check to see if any of your Pokemon already has Pokerus.
+; If so, sample its spread through your party.
+; This means that you cannot get Pokerus de novo while
+; a party member has an active infection.
+.loopMons
+ ld a, [hl]
+ and $f
+ jr nz, .TrySpreadPokerus
+ add hl, de
+ dec b
+ jr nz, .loopMons
+
+; If we haven't been to Goldenrod City at least once,
+; prevent the contraction of Pokerus.
+ ld hl, StatusFlags2
+ bit 6, [hl]
+ ret z
+ call Random
+ ld a, [hRandomAdd]
+ and a
+ ret nz
+ ld a, [hRandomSub]
+ cp $3
+ ret nc ; 3/65536 chance (00 00, 00 01 or 00 02)
+ ld a, [PartyCount]
+ ld b, a
+.randomMonSelectLoop
+ call Random
+ and $7
+ cp b
+ jr nc, .randomMonSelectLoop
+ ld hl, PartyMon1PokerusStatus
+ call GetPartyLocation ; get pokerus byte of random mon
+ ld a, [hl]
+ and $f0
+ ret nz ; if it already has pokerus, do nothing
+.randomPokerusLoop ; Simultaneously sample the strain and duration
+ call Random
+ and a
+ jr z, .randomPokerusLoop
+ ld b, a
+ and $f0
+ jr z, .load_pkrs
+ ld a, b
+ and $7
+ inc a
+.load_pkrs
+ ld b, a ; this should come before the label
+ swap b
+ and $3
+ inc a
+ add b
+ ld [hl], a
+ ret
+
+.TrySpreadPokerus:
+ call Random
+ cp 1 + 33 percent
+ ret nc ; 1/3 chance
+
+ ld a, [PartyCount]
+ cp 1
+ ret z ; only one mon, nothing to do
+
+ ld c, [hl]
+ ld a, b
+ cp 2
+ jr c, .checkPreviousMonsLoop ; no more mons after this one, go backwards
+
+ call Random
+ cp 1 + 50 percent
+ jr c, .checkPreviousMonsLoop ; 1/2 chance, go backwards
+.checkFollowingMonsLoop
+ add hl, de
+ ld a, [hl]
+ and a
+ jr z, .infectMon
+ ld c, a
+ and $3
+ ret z ; if mon has cured pokerus, stop searching
+ dec b ; go on to next mon
+ ld a, b
+ cp 1
+ jr nz, .checkFollowingMonsLoop ; no more mons left
+ ret
+
+.checkPreviousMonsLoop
+ ld a, [PartyCount]
+ cp b
+ ret z ; no more mons
+ ld a, l
+ sub e
+ ld l, a
+ ld a, h
+ sbc d
+ ld h, a
+ ld a, [hl]
+ and a
+ jr z, .infectMon
+ ld c, a
+ and $3
+ ret z ; if mon has cured pokerus, stop searching
+ inc b ; go on to next mon
+ jr .checkPreviousMonsLoop
+
+.infectMon
+ ld a, c
+ and $f0
+ ld b, a
+ ld a, c
+ swap a
+ and $3
+ inc a
+ add b
+ ld [hl], a
+ ret
+
+; any berry held by a Shuckle may be converted to berry juice
+ConvertBerriesToBerryJuice: ; 2ede6
+ ld hl, StatusFlags2
+ bit 6, [hl]
+ ret z
+ call Random
+ cp $10
+ ret nc ; 1/16 chance
+ ld hl, PartyMons
+ ld a, [PartyCount]
+.partyMonLoop
+ push af
+ push hl
+ ld a, [hl]
+ cp SHUCKLE
+ jr nz, .loopMon
+ ld bc, MON_ITEM
+ add hl, bc
+ ld a, [hl]
+ cp BERRY
+ jr z, .convertToJuice
+
+.loopMon
+ pop hl
+ ld bc, PARTYMON_STRUCT_LENGTH
+ add hl, bc
+ pop af
+ dec a
+ jr nz, .partyMonLoop
+ ret
+
+.convertToJuice
+ ld a, BERRY_JUICE
+ ld [hl], a
+ pop hl
+ pop af
+ ret
--- a/engine/routines/applypokerustick.asm
+++ /dev/null
@@ -1,26 +1,0 @@
-ApplyPokerusTick: ; 13988
-; decreases all pokemon's pokerus counter by b. if the lower nybble reaches zero, the pokerus is cured.
- ld hl, PartyMon1PokerusStatus ; PartyMon1 + MON_PKRS
- ld a, [PartyCount]
- and a
- ret z ; make sure it's not wasting time on an empty party
- ld c, a
-.loop
- ld a, [hl]
- and $f ; lower nybble is the number of days remaining
- jr z, .next ; if already 0, skip
- sub b ; subtract the number of days
- jr nc, .ok ; max(result, 0)
- xor a
-.ok
- ld d, a ; back up this value because we need to preserve the strain (upper nybble)
- ld a, [hl]
- and $f0
- add d
- ld [hl], a ; this prevents a cured pokemon from recontracting pokerus
-.next
- ld de, PARTYMON_STRUCT_LENGTH
- add hl, de
- dec c
- jr nz, .loop
- ret
--- a/engine/routines/checkpokerus.asm
+++ /dev/null
@@ -1,25 +1,0 @@
-CheckPokerus: ; 4d860
-; Return carry if a monster in your party has Pokerus
-
-; Get number of monsters to iterate over
- ld a, [PartyCount]
- and a
- jr z, .NoPokerus
- ld b, a
-; Check each monster in the party for Pokerus
- ld hl, PartyMon1PokerusStatus
- ld de, PARTYMON_STRUCT_LENGTH
-.Check:
- ld a, [hl]
- and $0f ; only the bottom nybble is used
- jr nz, .HasPokerus
-; Next PartyMon
- add hl, de
- dec b
- jr nz, .Check
-.NoPokerus:
- and a
- ret
-.HasPokerus:
- scf
- ret
--- a/main.asm
+++ b/main.asm
@@ -62,7 +62,7 @@
INCLUDE "event/misc_scripts_2.asm"
INCLUDE "event/std_collision.asm"
INCLUDE "event/bug_contest/judging.asm"
-INCLUDE "engine/routines/applypokerustick.asm"
+INCLUDE "engine/pokerus/apply_pokerus_tick.asm"
INCLUDE "event/bug_contest/contest_2.asm"
INCLUDE "engine/routines/correcterrorsinplayerparty.asm"
INCLUDE "engine/routines/getsquareroot.asm"
@@ -140,7 +140,7 @@
INCLUDE "engine/mystery_gift_2.asm"
INCLUDE "engine/tmhm2.asm"
INCLUDE "battle/moves/move_descriptions.asm"
-INCLUDE "engine/pokerus.asm"
+INCLUDE "engine/pokerus/pokerus.asm"
INCLUDE "engine/start_battle.asm"
INCLUDE "engine/routines/placegraphic.asm"
@@ -228,7 +228,7 @@
INCLUDE "tilesets/tileset_headers.asm"
INCLUDE "engine/routines/flagpredef.asm"
INCLUDE "engine/routines/trademonfrontpic.asm"
-INCLUDE "engine/routines/checkpokerus.asm"
+INCLUDE "engine/pokerus/check_pokerus.asm"
INCLUDE "event/lucky_number.asm"
INCLUDE "engine/caught_data.asm"
INCLUDE "engine/search2.asm"