

;******************
;*** BONUS Get ***
;******************
;give bonus in A to player
; 400 points bonuses
;1-3 weapon
;5 pill
;4 missile
.BONUS_Get
	or A
	ret z
	
	cp 4
	jr C,BONUS_GiveModule
	jr Z,BONUS_GiveMissle
	cp 5
	jr Z,BONUS_GivePill
	cp 6
	jr Z,BONUS_GiveSpecial
	ret
.BONUS_GiveMissle
	ld A,1
	ld (MISSILE),A
	ret
.BONUS_GiveSpecial
	;LD A,32
 	;LD (EXBYTE),A
	ld A,12-1	;give 5K !
	call SCORE_Add
	ret
.BONUS_GivePill
	ld A,(PILL1)
	or A
	jr nz,BONUS_GivePill2
	ld A,1
	ld (PILL1),A
	ld BC,(SHIPX)
	ld (PILL1X),BC
	ret
.BONUS_GivePill2
	ld A,1
	ld (PILL2),A
	ld BC,(SHIPX)
	ld (PILL2X),BC
	ret
	
.BONUS_GiveModule
	;ld (BALLPOW),A
	;if not the same weapon, re-init it !
	ld B,A
	ld A,(BALLPOW)
	cp B
	ld A,B
	ld (BALLPOW),A
	call nz,LASER_Init	
	
	;increase powa
	ld A,(BALLTYPE)
	or A
	jr z,BONUS_GiveModule1
	cp 1
	jr z,BONUS_GiveModule2
	cp 2
	ret nz	;got max , no more !
	
.BONUS_GiveModule3
	ld A,3
	ld (BALLTYPE),A
	ld A,(BALL2)
	ld (BALL3),A
	xor A
	ld (BALL1),A
	ld (BALL2),A
	ld BC,(BALL2X)
	ld (BALL3X),BC
	ret

.BONUS_GiveModule2
	inc A
	ld (BALLTYPE),A
	ld A,(BALL1)
	ld (BALL2),A
	xor A
	ld (BALL1),A
	ld (BALL3),A
	ld BC,(BALL1X)
	ld (BALL2X),BC
	ret

.BONUS_GiveModule1
	inc A
	ld (BALLTYPE),A
	ld A,MOD_ActionFloatFront
	ld (BALL1),A
	xor A
	ld (BALL2),A
	ld (BALL3),A
	ld (ATTATCH),A
	ld A,(SHIPY)
	ld B,A
	dec B
	ld C,29
	ld (BALL1X),BC
	ret

;*************************
;*** JEWELS management***
;*************************
;

;spawn a jewel , L = jewel type

.JEW_Spawn
	LD A,(JEW1)
 	AND A
 	JR NZ,JEW_Spawn_NotFree
;
	LD (JEW1X),BC
 	LD A,L
	LD (JEW1),A
 	LD A,(FRAME)
	DEC A
 	AND 7
 	LD (JEW1P),A
	ret
;
.JEW_Spawn_NotFree	
	LD (JEW2X),BC
 	LD A,L
	LD (JEW2),A
 	LD A,(FRAME)
	DEC A
 	AND 7
 	LD (JEW2P),A
	ret

.JEW_CallBack
	push AF
	push HL
	
	;get master
	inc H
	inc H
	inc H
	inc H
	ld A,(HL)
	cp #FF	;#FF is player
	jr nz,JEW_CallBackDone
	
	;jewels give 400
	ld A,3
	call SCORE_Add
	
	ld HL,(JEW_Current)
	ld A,(HL)
	ld (HL),0
	call BONUS_Get
	
	ld A,sfx_bonus
	call SND_SfxPlay
	
	ld HL,14
	add HL,SP
	ld SP,HL
	ret
	
.JEW_CallBackDone	
	pop HL
	pop AF
	ret

.JEW_Update
	SetMaster NeutralMaster
	SetCallBack	JEW_CallBack
	
	ld HL,JEW1
	call JEW_UpdateIt
	ld HL,JEW2
	call JEW_UpdateIt
	ret
.JEW_UpdateIt
	ld A,(HL)
	or A
	ret z
	
	ld (JEW_Current),HL
	
	inc HL
	inc HL
	ld C,(HL)
	inc HL
	ld B,(HL)
	
	;compute current sprite
	dec A
	add A
	add A
	ld E,A
	
	ld A,(FRAME)
	and 7
	call z,JEW_Move
	sra A
	
	dec HL
	ld (HL),C
		
	add E
	add 170
	call USPGADD
	call SPNS_CallBack
	
	ret
	
.JEW_Move
	dec C
	ld A,C
	cp #FD
	jr z,JEW_Kill
	xor A
	ret	
.JEW_Kill	
	ld HL,(JEW_Current)
	ld (HL),0
	pop HL	
	ret
.JEW_Current
	dw 0
	