; Landscape.include



Move_Right
	bsr Scroll_Plane1
	bsr Get_new_height
	bsr Draw_Land_Right
	rts
	

Get_new_height
	add.w #1,DISTANCE
	move.w DISTANCE,d0

	cmp.w #1,d0
	beq set_sect1
	cmp.w #1000,d0
	beq set_sect2
	cmp.w #4000,d0
	beq set_sect3
	cmp.w #6000,d0
	beq set_sect4
	cmp.w #8000,d0
	beq set_sect5
	cmp.w #11000,d0
	beq set_sect6
	cmp.w #13000,d0
	beq set_sect7
	cmp.w #15000,d0
	beq set_sect8
	cmp.w #16350,d0
	beq set_end

	cmp.w #15000,d0
	bgt section_B
	cmp.w #13000,d0
	bgt section_D
	cmp.w #11000,d0
	bgt section_A
	cmp.w #8000,d0
	bgt section_A
	cmp.w #6000,d0
	bgt section_E
	cmp.w #4000,d0
	bgt section_C
	cmp.w #1000,d0
	bgt section_B
	bra section_A


set_sect1				;into section
	move.w #$fff,enemy_colour
	move.w #1,level
	bsr Print_level
	move.w #0,XL7	
	move.w #0,TOP
	move.w #0,COUNT
	move.w #0,TYPE
	move.w #8,HEIGHT
	bsr set_height
	bsr Reset_table1
	bra section_A
set_sect2				;slight mountains
	move.w #$4ff,enemy_colour
	move.w #2,level
	bsr Print_level
	move.w #0,XL7	
	move.w #0,TOP
	move.w #0,COUNT
	move.w #0,TYPE
	move.w #8,HEIGHT
	bsr set_height
	bsr Reset_table2
	bra section_B
set_sect3				;roofed section
	move.w #$0f3,enemy_colour
	move.w #3,level
	bsr Print_level
	move.w #0,XL7
	move.w #1,TOP
	move.w #0,COUNT
	move.w #0,TYPE
	move.w #8,HEIGHT
	move.w #80,TOUGH
	bsr set_height
	bsr Reset_table3
	bsr All_sprites_off
	bra section_C
set_sect4				;roofed section plus spikers
	move.w #$ff0,enemy_colour
	move.w #4,level
	bsr Print_level
	move.w #7600,shut_off
	move.w #63,XL7
	move.w #1,TOP
	move.w #0,COUNT
	move.w #0,TYPE
	move.w #8,HEIGHT
	move.w #150,TOUGH
	bsr set_height
	bsr Reset_table4
	bra section_E
set_sect5				;fireballs section
	move.w #$3f3,enemy_colour
	move.w #5,level
	bsr Print_level
	move.w #10800,shut_off
	move.w #31,XL7
	move.w #0,TOP
	move.w #0,COUNT
	move.w #0,TYPE
	move.w #8,HEIGHT
	move.w #150,TOUGH
	bsr set_height
	bsr Reset_table5
	bsr All_sprites_off
	bsr Prepare_fireball
	bra section_A
set_sect6				;violent section
	move.w #$f00,enemy_colour
	move.w #6,level
	bsr Print_level
	bsr All_sprites_off
	move.w #12800,shut_off
	move.w #$ffff,XL7
	move.w #0,TOP
	move.w #0,COUNT
	move.w #0,TYPE
	move.w #8,HEIGHT
	bsr set_height
	bsr Reset_table6
	bsr Prepare_ackack
	bra section_A
set_sect7		;maze
	move.w #$361,enemy_colour
	move.w #7,level
	bsr Print_level
	move.w #0,XL7
	move.w #1,TOP
	move.w #19,COUNT
	move.w #0,TYPE
	move.w #8,HEIGHT
	move.w #40,TOUGH
	move.w #20,MAX_COUNT
	move.w #0,TRANS
	bsr set_height
	bsr Reset_table7
	bsr All_sprites_off
	bra section_D

set_sect8
	move.w #$002,enemy_colour
	move.w #8,level
	bsr Print_level
	move.w #0,XL7
	move.w #0,TOP
	move.w #0,COUNT
	move.w #0,TYPE
	move.w #8,HEIGHT
	move.w #100,TOUGH
	bsr set_height
	bsr Reset_table8
	bra section_B
set_end
	move.w #13000,DISTANCE
	tst.w level_complete
	beq set_sect7
	move.w #1,DISTANCE
	add.w #1,clocked
	add.w #1,lives
	add.w #1000,score
	bsr Print_details
	bsr Reset_level_2
	bra set_sect1


Draw_Land_Right

	tst.w TOP			;Is there a roof on the screen?
	beq land_8

	;Solid tunnel landscape

	bsr waitblit
	move.l #SCREEN1+46,a0
	move.w #190,d0
tunnel_1
	move.w #$c000,(a0)
	add.l #48,a0
	sub.w #1,d0
	tst.w d0
	bne tunnel_1
	
	;tunnel - 2. make hole

	move.l #SCREEN1+46,a0
	move.w HEIGHT,d1
	mulu.w #48,d1
	add.l d1,a0
	move.w TOUGH,d0
tunnel_2
	move.w #$0000,(a0)
	add.l #48,a0
	sub.w #1,d0
	tst.w d0
	bne tunnel_2
	rts


;Normal lumpy landscape

land_8
	bsr waitblit
	move.l #SCREEN1+46,a0
	move.w #190,d0
	move.w HEIGHT,d1
land_5
	move.w #0,d2
	cmp.w d1,d0
	bgt.s land_6
	move.w #$c000,d2
land_6
	move.w d2,(a0)
	add.l #48,a0
	sub.w #1,d0
	tst.w d0
	bne.s land_5
	rts

section_A
	add.w #1,COUNT
	cmp.w #2,COUNT
	bne one_3
	move.w #0,COUNT
	move.w #16,d1
	bsr random_height
	sub.w #8,d0
	move.w HEIGHT,d2
	add.w d0,d2
	cmp.w #20,d2
	blt one_4
one_1
	cmp.w #100,d2
	bgt one_5
one_2
	move.w d2,HEIGHT
one_3
	tst.w XL7
	beq one_6
	cmp.w #6,level
	beq one_60
	bsr Fireballs
one_60
	cmp.w #9600,DISTANCE
	bne one_61
	move.w #15,XL7
one_61
	cmp.w #12400,DISTANCE
	bne one_62
	move.w #7,XL7
one_62
	cmp.w #12700,DISTANCE
	bne one_6
	move.w #3,XL7
one_6
	rts
one_4
	move.w #20,d2
	bra one_2
one_5
	move.w #100,d2
	bra one_2
	



; Section B is a series of flats and smooths of random length

section_B
	tst.w COUNT
	bne two_1	;Needs reseting/starting? 
	eor.w #1,TYPE				; 0 - lumpy, 1 - smooth
	move.w #12,d1
	bsr random_height
	add.w #10,d0
	move.w TYPE,d1
	lsl.w #6,d1
	add.w d1,d0
	move.w d0,MAX_COUNT			; length of section
two_1
	add.w #1,COUNT
	move.w MAX_COUNT,d0
	cmp.w COUNT,d0
	beq two_4

	cmp.w #1,TYPE
	bne two_7

	cmp.w #16100,DISTANCE
	blt two_10
	cmp.w #16106,DISTANCE
	bgt two_10
	move.w #37,HEIGHT
	move.w #2,COUNT
	bra two_7
		
two_10
	move.w #20,d1				; Choose a new height
	bsr random_height
	sub.w #10,d0



	move.w HEIGHT,d2
	add.w d0,d2

	cmp.w #20,d2
	blt two_5
two_2
	cmp.w #170,d2
	bgt two_6
two_3
	move.w d2,HEIGHT
	rts
two_4
	move.w #0,COUNT
two_7
	rts
two_5			
	move.w #20,d2
	bra two_3
two_6
	move.w #170,d2
	bra two_3
	

; Section C is a series of flats and smooths of random length
; height limited as it includes a roof section


section_C
	tst.w COUNT
	bne three_1	;Needs reseting/starting? 
	eor.w #1,TYPE				; 0 - lumpy, 1 - smooth
	move.w #12,d1
	bsr random_height
	add.w #10,d0
	move.w TYPE,d1
	lsl.w #6,d1
	add.w d1,d0
	move.w d0,MAX_COUNT			; length of section
three_1
	add.w #1,COUNT
	move.w MAX_COUNT,d0
	cmp.w COUNT,d0
	beq three_4

	cmp.w #1,TYPE
	bne three_7

	move.w #11,d1				; Choose a new height
	bsr random_height
	sub.w #5,d0
	move.w HEIGHT,d2
	add.w d0,d2

	cmp.w #2,d2
	blt three_5
three_2
	cmp.w #80,d2
	bgt three_6
three_3
	move.w d2,HEIGHT
	rts
three_4
	move.w #0,COUNT
three_7
	rts
three_5			
	move.w #2,d2
	bra three_3
three_6
	move.w #80,d2
	bra three_3
	


; Section D is a maze

section_D
	add.w #1,COUNT
	move.w MAX_COUNT,d0
	cmp.w COUNT,d0
	bne four_2					;Not end of a section

	move.w #0,COUNT
	eor.w #1,TRANS				;Change the section type
	tst.w TRANS
	beq four_1					;go start a passage
								;else start a transition tube
	move.w #26,MAX_COUNT

four_4
	move.w #120,d1				; Choose a new height
	bsr random_height
	add.w #4,d0
	move.w d0,NEWHEIGHT
	cmp.w HEIGHT,d0
	blt four_6	
	move.w d0,d1
	sub.w HEIGHT,d1

four_5
	cmp.w #20,d1
	blt four_4	
	move.w NEWHEIGHT,d0
	cmp.w HEIGHT,d0
	blt four_3
	move.w NEWHEIGHT,d2
	sub.w HEIGHT,d2	; d2=nh-h
	add.w #40,d2
	move.w d2,TOUGH
	rts

four_6
	move.w HEIGHT,d1
	sub.w d0,d1
	bra four_5

four_3	
	move.w HEIGHT,d2
	sub.w d0,d2	;d2=h-nh
	add.w #40,d2	
	move.w d2,TOUGH
	move.w d0,HEIGHT	
	rts
four_1
	move.w NEWHEIGHT,d1
	move.w d1,HEIGHT
	move.w #40,d1
	bsr random_height
	add.w #40,d0
	move.w d0,MAX_COUNT
	move.w #40,TOUGH
	rts
four_2
	rts
	

; Section E is a series of flats and smooths of random length
; very height limited as it includes a roof section and whizzers!


section_E
	tst.w COUNT
	bne five_1	;Needs reseting/starting? 
	eor.w #1,TYPE				; 0 - lumpy, 1 - smooth
	move.w #12,d1
	bsr random_height
	add.w #10,d0
	move.w TYPE,d1
	lsl.w #6,d1
	add.w d1,d0
	move.w d0,MAX_COUNT			; length of section
five_1
	add.w #1,COUNT
	move.w MAX_COUNT,d0
	cmp.w COUNT,d0
	beq five_4

	cmp.w #1,TYPE
	bne five_7

	move.w #8,d1				; Choose a new height
	bsr random_height
	sub.w #4,d0
	move.w HEIGHT,d2
	add.w d0,d2

	cmp.w #6,d2
	blt five_5
five_2
	cmp.w #160,d2
	bgt five_6
five_3
	move.w d2,HEIGHT
	bra five_7
five_4
	move.w #0,COUNT
five_7
	;tst.w XL7
	;beq five_8
	;bsr Whizzers *****WARNING***
five_8
	rts
five_5			
	move.w #6,d2
	bra five_3
five_6
	move.w #140,d2
	bra five_3
	


set_height
	move.l #$4523,LANDSEED
	move.w #$6,LANDSEED+4
	rts

random_height
		; Returns number in d0 between 0 and d1. trashes d6,d7
	moveq	#32,d0
rhlp
	move.b	LANDSEED+2,d6
	move.b	LANDSEED+4,d7	
	lsr.b	#3,d6
	eor.b	d6,d7
	roxr.b	#1,d7
	roxl.w	LANDSEED
	roxl.w	LANDSEED+2
	roxl.w	LANDSEED+4
	dbra	d0,rhlp
	move.l	LANDSEED,d0
	mulu	d1,d0
	lsr.l	#8,d0
	lsr.l	#8,d0
	rts

Print_level
	bsr Blank_zones
	bsr Light_zone

	tst.w game_flag
	bne pl1
	bsr Sound4
pl1
	rts

Blank_zones
	move.l #SCREEN3+9224,a0
	move.l #SCREEN5+9224,a1
	bsr blob_dark
	bsr blob_dark
	bsr blob_dark
	bsr blob_dark
	bsr blob_dark
	bsr blob_dark
	bsr blob_dark
	bsr blob_dark
	rts

Light_zone
	move.l #SCREEN3+9220,a0
	move.l #SCREEN5+9220,a1
	moveq #0,d0
	move.w level,d0
	tst.w d0
	beq lz
	lsl.l #2,d0
	add.l d0,a0
	add.l d0,a1
	move.l #$f,d0
	move.l d0,(a0)
	move.l d0,48(a0)
	move.l #$ffffffff,d0
	move.l d0,(a1)
	move.l d0,48(a1)
	add.w #4,a0
	add.w #4,a1
lz
	rts


blob_dark
	move.l #$f,d0
	move.l d0,(a0)
	move.l d0,48(a0)
	move.l d0,(a1)
	move.l d0,48(a1)
	add.w #4,a0
	add.w #4,a1
	rts

Choose_level
	;decide where player restarts after 'accident'
	move.w DISTANCE,d0
	cmp.w #1000,d0
	blt cl1
	cmp.w #4000,d0
	blt cl2
	cmp.w #6000,d0
	blt cl3
	cmp.w #8000,d0
	blt cl4
	cmp.w #11000,d0
	blt cl5
	cmp.w #13000,d0
	blt cl6
	
	move.w #13000-1,DISTANCE	;
	rts
cl6
	move.w #11000-1,DISTANCE
	rts
cl5
	move.w #8000-1,DISTANCE
	rts
cl4
	move.w #6000-1,DISTANCE
	rts
cl3
	move.w #4000-1,DISTANCE
	rts
cl2
	move.w #1000-1,DISTANCE
	rts
cl1
	move.w #0,DISTANCE
	rts
 

	include "Source:Squabble/number.include"

	even
starcount
	dc.w 0
starplace
	dc.w 0
level
	dc.w 0

HEIGHT dc.w 50
NEWHEIGHT dc.w 50
COUNT dc.w 0
MAX_COUNT dc.w 20
TYPE dc.w 0
TOP dc.w 0
TOUGH dc.w 40
TRANS dc.w 0
DISTANCE dc.w 0
LANDSEED
	dc.l	$4523
	dc.w	$6





	even

