shithub: pokecrystal

ref: 98e6878429a2c74b5293426204e0013c322d50a3
dir: /home/battle_vars.asm/

View raw version
GetBattleVar:: ; 39e1
; Preserves hl.
	push hl
	call GetBattleVarAddr
	pop hl
	ret
; 39e7

GetBattleVarAddr:: ; 39e7
; Get variable from pair a, depending on whose turn it is.
; There are 21 variable pairs.

	push bc

	ld hl, .BattleVarPairs
	ld c, a
	ld b, 0
	add hl, bc
	add hl, bc

	ld a, [hli]
	ld h, [hl]
	ld l, a

; Enemy turn uses the second byte instead.
; This lets battle variable calls be side-neutral.
	ld a, [hBattleTurn]
	and a
	jr z, .get_var
	inc hl

.get_var
; var id
	ld a, [hl]
	ld c, a
	ld b, 0

	ld hl, .BattleVarPointers
	add hl, bc
	add hl, bc

	ld a, [hli]
	ld h, [hl]
	ld l, a

	ld a, [hl]

	pop bc
	ret

.BattleVarPairs:
	dw .Substatus1
	dw .Substatus2
	dw .Substatus3
	dw .Substatus4
	dw .Substatus5
	dw .Substatus1Opp
	dw .Substatus2Opp
	dw .Substatus3Opp
	dw .Substatus4Opp
	dw .Substatus5Opp
	dw .Status
	dw .StatusOpp
	dw .MoveAnim
	dw .MoveEffect
	dw .MovePower
	dw .MoveType
	dw .CurMove
	dw .LastCounter
	dw .LastCounterOpp
	dw .LastMove
	dw .LastMoveOpp

;                       player                     enemy
.Substatus1:      db PLAYER_SUBSTATUS_1,     ENEMY_SUBSTATUS_1
.Substatus1Opp:   db ENEMY_SUBSTATUS_1,      PLAYER_SUBSTATUS_1
.Substatus2:      db PLAYER_SUBSTATUS_2,     ENEMY_SUBSTATUS_2
.Substatus2Opp:   db ENEMY_SUBSTATUS_2,      PLAYER_SUBSTATUS_2
.Substatus3:      db PLAYER_SUBSTATUS_3,     ENEMY_SUBSTATUS_3
.Substatus3Opp:   db ENEMY_SUBSTATUS_3,      PLAYER_SUBSTATUS_3
.Substatus4:      db PLAYER_SUBSTATUS_4,     ENEMY_SUBSTATUS_4
.Substatus4Opp:   db ENEMY_SUBSTATUS_4,      PLAYER_SUBSTATUS_4
.Substatus5:      db PLAYER_SUBSTATUS_5,     ENEMY_SUBSTATUS_5
.Substatus5Opp:   db ENEMY_SUBSTATUS_5,      PLAYER_SUBSTATUS_5
.Status:          db PLAYER_STATUS,          ENEMY_STATUS
.StatusOpp:       db ENEMY_STATUS,           PLAYER_STATUS
.MoveAnim:        db PLAYER_MOVE_ANIMATION,  ENEMY_MOVE_ANIMATION
.MoveEffect:      db PLAYER_MOVE_EFFECT,     ENEMY_MOVE_EFFECT
.MovePower:       db PLAYER_MOVE_POWER,      ENEMY_MOVE_POWER
.MoveType:        db PLAYER_MOVE_TYPE,       ENEMY_MOVE_TYPE
.CurMove:         db PLAYER_CUR_MOVE,        ENEMY_CUR_MOVE
.LastCounter:     db PLAYER_COUNTER_MOVE,    ENEMY_COUNTER_MOVE
.LastCounterOpp:  db ENEMY_COUNTER_MOVE,     PLAYER_COUNTER_MOVE
.LastMove:        db PLAYER_LAST_MOVE,       ENEMY_LAST_MOVE
.LastMoveOpp:     db ENEMY_LAST_MOVE,        PLAYER_LAST_MOVE

.BattleVarPointers:
	dw wPlayerSubStatus1,           wEnemySubStatus1
	dw wPlayerSubStatus2,           wEnemySubStatus2
	dw wPlayerSubStatus3,           wEnemySubStatus3
	dw wPlayerSubStatus4,           wEnemySubStatus4
	dw wPlayerSubStatus5,           wEnemySubStatus5
	dw wBattleMonStatus,            wEnemyMonStatus
	dw wPlayerMoveStructAnimation,  wEnemyMoveStructAnimation
	dw wPlayerMoveStructEffect,     wEnemyMoveStructEffect
	dw wPlayerMoveStructPower,      wEnemyMoveStructPower
	dw wPlayerMoveStructType,       wEnemyMoveStructType
	dw wCurPlayerMove,              wCurEnemyMove
	dw wLastPlayerCounterMove,      wLastEnemyCounterMove
	dw wLastPlayerMove,             wLastEnemyMove
; 3a90