action GUNSLEEP -5 1 1 1 1
action GUNOPENING -4 3 1 1 10
action GUNOPED -1 1 1 1 1
action GUNFIRING 0 2 1 1 10
action GUNCLOSING -1 4 1 -1 10
action GUNDYING 124 3 1 1 10
action GUNDEAD 127 1 1 1 1

spritenoshade GUNFIRE
defineprojectile GUNFIRE PROJ_WORKSLIKE 32770
defineprojectile GUNFIRE PROJ_HITRADIUS 0
defineprojectile GUNFIRE PROJ_EXTRA 0
defineprojectile GUNFIRE PROJ_SPAWNS -1
defineprojectile GUNFIRE PROJ_VEL 350
defineprojectile GUNFIRE PROJ_XREPEAT 2
defineprojectile GUNFIRE PROJ_YREPEAT 2
defineprojectile GUNFIRE PROJ_CSTAT 128
actor GUNFIRE 0 FRAMEMINUS7 enda

gamevar guntype 0 2
gamevar guncount 0 2
eventloadactor FIREGUN
getactor[THISACTOR].hitag HITAGSET
setactor[THISACTOR].hitag 0
getactor[THISACTOR].lotag LOTAGSET
setactor[THISACTOR].lotag 0
getactor[THISACTOR].extra gun_extra
getactor[THISACTOR].owner guntype

getactor[THISACTOR].zvel guncount
ifvarn gun_extra -1 setvar gun_deadly 1
enda

state tommygunstate
	shoot TOMMYFIRST
	sound TOM
ends

state firegunstate
	eshoot GUNFIRE
	setactorvar[RETURN].fire_dist LOTAGSET
	getactor[THISACTOR].yrepeat yrepeat
	mulvar yrepeat 64
	getactor[THISACTOR].z z
	subvarvar z yrepeat
	setactor[RETURN].z z
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].ang temp
	setvarvar x2 x
	subvarvar x2 128
	rotatepoint x y x2 y temp x3 y3 
	setactor[RETURN].x x3
	setactor[RETURN].y y3
	randvar tmp 10
	ifrnd 128  addvarvar temp tmp else subvarvar temp tmp
	setactor[RETURN].ang temp
	setvar zvel 0
	randvar tmp 768
	subvar tmp 384
	addvarvar zvel tmp
	setactor[RETURN].zvel zvel
ends

actor FIREGUN 0 GUNSLEEP cstat 80
getactor[THISACTOR].pal pal
ifvare pal 1 { ifmultiplayer nullop else killit } else
{
	ifvare active 1 { 
		ifaction GUNSLEEP action GUNOPENING
		ifaction GUNCLOSING action GUNOPENING
	}
	else 
	{ 
		ifaction GUNOPED action GUNCLOSING
		ifaction GUNFIRING action GUNCLOSING
		ifaction GUNCLOSING ifactioncount 4 { cstat 80 setvar activateguntime 0 action GUNSLEEP }
		setvar COUNTER 0
	}
	
	
	ifaction GUNOPED
	{ addvar activateguntime 1 ifvarvarg activateguntime guncount { action GUNFIRING setvar activateguntime 0 } }
	
	ifaction GUNFIRING 
	{ 
		cstat 336 //weapon hit available
		strength 10
		ifvare gun_deadly 1
		{
			getactor[THISACTOR].htextra htextra
			ifvarg htextra 0 { subvarvar gun_extra htextra }
			ifhitweapon ifvarl gun_extra 1 action GUNDYING
		}
		
		ifvarn guntype 1 {
			state firegunstate
			state firegunstate
			state firegunstate
			state firegunstate
			soundonce SPRAYFIR 
		} else state tommygunstate
		
		

		ifvarn HITAGSET 0 
		{ 
		ifvarvarn COUNTER HITAGSET addvarvar COUNTER 1 
		ifvarvare COUNTER HITAGSET { action GUNCLOSING setvar active 0 }
		}
	}
	ifaction GUNOPENING ifactioncount 3 action GUNOPED
	ifaction GUNDYING ifactioncount 3 { cstat 80 action GUNDEAD }
}
enda

eventloadactor SHOOTER1
getactor[THISACTOR].hitag activateguntime
setactor[THISACTOR].hitag 0
getactor[THISACTOR].lotag shoottime
setactor[THISACTOR].lotag 0
getactor[THISACTOR].zvel proj_shoot
setactor[THISACTOR].zvel 0
setvarvar COUNTER shoottime
getactor[THISACTOR].xvel rx_can
enda

useractor 4 SHOOTER1
ifspritepal 1 { ifmultiplayer spritepal 0 else killit }
setactor[THISACTOR].xvel rx_can
getactorvar[THISACTOR].active activategun
ifvare activategun 1
{
	ifvarn activateguntime 0 
	{ 
		ifvarvarn FIRECOUNT activateguntime addvarvar FIRECOUNT 1 
		ifvarvare FIRECOUNT activateguntime { setactorvar[THISACTOR].active 0 }
	}

	ifvarvarn COUNTER shoottime addvar COUNTER 1
	ifvarvare COUNTER shoottime { eshootvar proj_shoot getactor[RETURN].picnum picnum ifvare picnum PR_NAPALM { setactor[RETURN].xvel 500 } action ONE setvar COUNTER 0 }
} else setvar FIRECOUNT 0
ifaction ONE ifactioncount 4 action TWO
ifaction TWO ifactioncount 4 action NULL
enda

action ASHOTER1 373
action ASHOTER2 374

eventloadactor SHOOTER2
getactor[THISACTOR].hitag activateguntime
setactor[THISACTOR].hitag 0
getactor[THISACTOR].lotag shoottime
setactor[THISACTOR].lotag 0
getactor[THISACTOR].zvel proj_shoot
setactor[THISACTOR].zvel 0
setvarvar COUNTER shoottime
getactor[THISACTOR].xvel rx_can
getactor[THISACTOR].yvel guntype
ifvare guntype 1
	setvarvar FIRECOUNT activateguntime
enda

useractor 4 SHOOTER2
setactor[THISACTOR].xvel rx_can
getactorvar[THISACTOR].active activategun
ifvare activategun 1
{

	ifvarn guntype 1 {
		ifvarn activateguntime 0 
		{ 
			ifvarvarn FIRECOUNT activateguntime addvarvar FIRECOUNT 1 
			ifvarvare FIRECOUNT activateguntime { setactorvar[THISACTOR].active 0 }
		}

		ifvarvarn COUNTER shoottime addvar COUNTER 1
		ifvarvare COUNTER shoottime { eshootvar proj_shoot getactor[RETURN].picnum picnum ifvare picnum PR_NAPALM { setactor[RETURN].xvel 500 } action ASHOTER1 setvar COUNTER 0 }
	} else {
	
		ifvarvarn FIRECOUNT activateguntime addvarvar FIRECOUNT 1 
		ifvarvare FIRECOUNT activateguntime { eshootvar proj_shoot getactor[RETURN].picnum picnum ifvare picnum PR_NAPALM { setactor[RETURN].xvel 500 } action ASHOTER1 setvar COUNTER 0 setvar FIRECOUNT 0 }
	}
	
	
} else ifvarn guntype 1 setvar FIRECOUNT 0
ifaction ASHOTER1 ifactioncount 4 action ASHOTER2
ifaction ASHOTER2 ifactioncount 4 action NULL
enda
