state rx_cansetactive

	getactor[THISACTOR].yvel tx_can 
	ifvarn tx_can 0
	{
		setvar sectorid 0
		whilevarvarn sectorid NUMSECTORS 
		{
			headspritesect spriteid sectorid
			whilevarn spriteid -1 
			{
				getactorvar[spriteid].se_xvel rx_can
				ifvarvare tx_can rx_can { 
					getactorvar[spriteid].active tmp addvar tmp 1 setactorvar[spriteid].active tmp 
					ifvare actorvar[spriteid].status 1 setactorvar[spriteid].status 0 else setactorvar[spriteid].status 1	
					setactorvar[spriteid].activatedby THISACTOR					
				}
				nextspritesect spriteid spriteid
			}
			addvar sectorid 1
		}
	}

ends

state se64_check //SERETURN = 0/1
setvar sectorid 0
whilevarvarn sectorid NUMSECTORS 
{
	headspritesect spriteid sectorid
	whilevarn spriteid -1 
	{
		getactor[spriteid].picnum picnum
		ifvare picnum SECTOREFFECTOR
		{
			getactor[spriteid].lotag lotag
			getactor[THISACTOR].yvel tx_can 
			getactorvar[spriteid].se_xvel rx_can
			ifvarvare rx_can tx_can	{ ifvare lotag 64 getactorvar[spriteid].rot_moving SERETURN else ifvare lotag 69 getactorvar[spriteid].rot_moving SERETURN else ifvare lotag 70 getactorvar[spriteid].rot_moving SERETURN }
		}
		nextspritesect spriteid spriteid
	}
	addvar sectorid 1
}
ends

include blcons/objects/moving_sector_actors.con
include blcons/objects/trigger.con //-10fps
include blcons/objects/lighteffector.con //-1fps
include blcons/objects/switches.con
include blcons/objects/tc_locker.con //-1fps
include blcons/objects/timeactivator.con
include blcons/objects/triggerquote.con //-3fps
include blcons/objects/triggersound.con
include blcons/objects/guns.con
include blcons/objects/spawner.con
include blcons/objects/spritetoactor.con //-1 fps
include blcons/objects/damagesect.con
include blcons/objects/aplayer.con

state newsectoreffector

	ifactor MUSICANDSFX
	{
		ifvare msfx_kill 1 killit
	}

	ifactor SECTOREFFECTOR // Light of particles in polymer
	{
		getactor[THISACTOR].lotag lotag
		ifvare lotag 6
		{
			getactor[THISACTOR].zvel tr_bits
			ifvarg se_xvel 0
			ifvare tr_bits 1
			{
				ifvare active 1 { 
					ifvare sprite[THISACTOR].statnum 7 {
						setvar LOTAGSAVED 388
					}
					ifvarg LOTAGSAVED 0 soundoncevar LOTAGSAVED
					//setactor[THISACTOR].statnum 3 
					changespritestat THISACTOR 3
				} else { 
					ifvarg LOTAGSAVED 0 { stopsoundvar LOTAGSAVED setvar LOTAGSAVED 0 } 
					//setactor[THISACTOR].statnum 7 
					changespritestat THISACTOR 7
				}
			}
		}
		ifvare lotag 7
		{
			getactor[THISACTOR].xvel rx_can
			getactor[THISACTOR].zvel tr_bits
			ifvarg rx_can 0
			ifvare tr_bits 1
			{
				ifvare active 1 { changespritestat THISACTOR 9 /* setactor[THISACTOR].statnum 9 */ } else { changespritestat THISACTOR 3 /* setactor[THISACTOR].statnum 3 */ }
			}
		}
		ifvare lotag 24
		{
			getactor[THISACTOR].xvel rx_can
			getactor[THISACTOR].zvel tr_bits
			
			ifvarg rx_can 0
			ifvarand tr_bits 1
			{
				ifvare active 1 { changespritestat THISACTOR 3 /* setactor[THISACTOR].statnum 3 */ } else { changespritestat THISACTOR 9 /* setactor[THISACTOR].statnum 9 */}
				ifvare active 1
				{	
					getactor[THISACTOR].ang ang
					subvarvar ang wallang
					cos mycos ang
					sin mysin ang
					mulvarvar mycos se_yvel
					mulvarvar mysin se_yvel
					shiftvarr mycos 14
					shiftvarr mysin 14

					ifvarand sector[sectnum1].floorstat 4 {
						setvarvar tmp mycos
						setvarvar mycos mysin
						setvarvar mysin tmp
						mulvarvar mysin -1
					}

					getsector[sectnum1].floorxpanning se_panningX
					setvarvar se_panningX savepanningx
					ifvarand sector[sectnum1].floorstat 16
						mulvar mycos -1	
					ifvarand sector[sectnum1].floorstat 4 {
						mulvar mycos -1	
						ifvarand sector[sectnum1].floorstat 64 
							mulvar mycos -1	
					}	
					subvarvar se_panningX mycos
					modvar se_panningX 255
					ifvarvarg se_panningX 255 setvar se_panningX 0
					
					getsector[sectnum1].floorypanning se_panningY
					ifvarand sector[sectnum1].floorstat 64 {
						mulvar mysin -1		
						ifvarand sector[sectnum1].floorstat 4
						mulvar mysin -1	
					}
						
					ifvarand sector[sectnum1].floorstat 32
						mulvar mysin -1	
					addvarvar se_panningY mysin
					modvar se_panningY 255
					ifvarvarg se_panningY 255 setvar se_panningY 0

					setsector[sectnum1].floorxpanning se_panningX
					setvarvar savepanningx se_panningX
					setsector[sectnum1].floorypanning se_panningY
				} 
				
				ifvarg pl_yvel 0 { setactor[THISACTOR].yvel pl_yvel } else {
					setvarvar tmp se_yvel
					mulvar tmp 256
					setactor[THISACTOR].yvel tmp
				}
			} 
		}
		ifvare lotag 49 // Light of particles in polymer
		{
			getactor[light_spawner].statnum astatnum
			getactor[light_spawner].sectnum sectnum
			ifvarg light_spawner 0
			{
				ifvarn astatnum 1024
				ifvarn sectnum 4096
				{
					getactor[light_spawner].x x
					getactor[light_spawner].y y
					getactor[light_spawner].z z
					
					setactor[THISACTOR].x x
					setactor[THISACTOR].y y
					ifspawnedby PROXIMITYFLOOR 
					{ 
						subvar z 128
						ifvarl COUNTER 2048 addvar COUNTER 64 
							else setvar COUNTER 0
						sin light_radius COUNTER
						divvar light_radius 16
						ifvarl light_radius 0 mulvar light_radius -1
						setactor[THISACTOR].hitag light_radius 
					}
					setactor[THISACTOR].z z
					changespritesect THISACTOR sectnum
				} else killit
			}
		}
		ifvare lotag 65 //WALL PANNING
		{
			getactor[THISACTOR].zvel tr_bits
			getactor[THISACTOR].hitag hitag
			ifvarand tr_bits 3 { divvar hitag 8 }
			
			ifvarand tr_bits 16
			{
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				getactor[THISACTOR].z z
				getactor[THISACTOR].ang ang
				getactor[THISACTOR].sectnum sectorid
				cos mycos ang
				sin mysin ang
				hitscan x y z sectorid mycos mysin 0 RETURN se_walltmp RETURN RETURN RETURN RETURN 0x00000030h //4294901808
				ifvarn se_walltmp -1
				{
				ifvarand tr_bits 1  { getwall[se_walltmp].xpanning se_panning subvarvar se_panning hitag ifvarvarl se_panning -255 setvar se_panning 0 setwall[se_walltmp].xpanning se_panning }
				ifvarand tr_bits 2  { getwall[se_walltmp].xpanning se_panning addvarvar se_panning hitag ifvarvarg se_panning 255 setvar se_panning 0 setwall[se_walltmp].xpanning se_panning }
				ifvarand tr_bits 4  { getwall[se_walltmp].ypanning se_panning subvarvar se_panning hitag ifvarvarl se_panning -255 setvar se_panning 0 setwall[se_walltmp].ypanning se_panning }
				ifvarand tr_bits 8  { getwall[se_walltmp].ypanning se_panning addvarvar se_panning hitag ifvarvarg se_panning 255 setvar se_panning 0 setwall[se_walltmp].ypanning se_panning }
				}
			} else ifvarand tr_bits 32 
			{	
				ifvare active 1
				{
					getactor[THISACTOR].x x
					getactor[THISACTOR].y y
					getactor[THISACTOR].z z
					getactor[THISACTOR].ang ang
					getactor[THISACTOR].sectnum sectorid
					cos mycos ang
					sin mysin ang
					hitscan x y z sectorid mycos mysin 0 RETURN se_walltmp RETURN RETURN RETURN RETURN 0x00000030h //4294901808
					ifvarn se_walltmp -1
					{
					ifvarand tr_bits 1  { getwall[se_walltmp].xpanning se_panning subvarvar se_panning hitag ifvarvarl se_panning -255 setvar se_panning 0 setwall[se_walltmp].xpanning se_panning }
					ifvarand tr_bits 2  { getwall[se_walltmp].xpanning se_panning addvarvar se_panning hitag ifvarvarg se_panning 255 setvar se_panning 0 setwall[se_walltmp].xpanning se_panning }
					ifvarand tr_bits 4  { getwall[se_walltmp].ypanning se_panning subvarvar se_panning hitag ifvarvarl se_panning -255 setvar se_panning 0 setwall[se_walltmp].ypanning se_panning }
					ifvarand tr_bits 8  { getwall[se_walltmp].ypanning se_panning addvarvar se_panning hitag ifvarvarg se_panning 255 setvar se_panning 0 setwall[se_walltmp].ypanning se_panning }
					}
				}
			}
			else
			{
				getactor[THISACTOR].sectnum sectnum1
				getsector[sectnum1].wallnum wallnum
				getsector[sectnum1].wallptr wallptr
				setvar tmp 0
				setvar se_walltmp 0
				ifvarl wallnum 1 break
				whilevarvarn tmp wallnum
				{
					ifvarand tr_bits 1 { ifvarvarn se_walltmp wallptr { setvarvar se_walltmp wallptr getwall[se_walltmp].xpanning se_panning subvarvar se_panning hitag ifvarvarl se_panning -255 setvar se_panning 0 setwall[se_walltmp].xpanning se_panning } }
					ifvarand tr_bits 2 { ifvarvarn se_walltmp wallptr { setvarvar se_walltmp wallptr getwall[se_walltmp].xpanning se_panning addvarvar se_panning hitag ifvarvarg se_panning 255 setvar se_panning 0 setwall[se_walltmp].xpanning se_panning } }
					ifvarand tr_bits 4 { ifvarvarn se_walltmp wallptr { setvarvar se_walltmp wallptr getwall[se_walltmp].ypanning se_panning subvarvar se_panning hitag ifvarvarl se_panning -255 setvar se_panning 0 setwall[se_walltmp].ypanning se_panning } }
					ifvarand tr_bits 8 { ifvarvarn se_walltmp wallptr { setvarvar se_walltmp wallptr getwall[se_walltmp].ypanning se_panning addvarvar se_panning hitag ifvarvarg se_panning 255 setvar se_panning 0 setwall[se_walltmp].ypanning se_panning } }
				
					addvar wallptr 1
					addvar tmp 1
				}
			}
			
		}
		ifvare lotag 66 //PLAYER POSITION CHANGE
		{
			getactor[THISACTOR].zvel tr_bits
			getactor[THISACTOR].sectnum sect2
			getplayer[THISACTOR].cursectnum sect1
			getactor[THISACTOR].hitag hitag
			getplayer[THISACTOR].posx px
			getplayer[THISACTOR].posy py
			getactor[THISACTOR].ang se_ang
			ifvarand tr_bits 1
			{
				ifvarg active 1 setvar active 0
				ifvare active 1
				{	
					cos se_x se_ang
					sin se_y se_ang
					divvarvar se_x 4096
					divvarvar se_y 4096
					mulvarvar se_x hitag
					mulvarvar se_y hitag
					
					setvarvar x2 px
					addvar x2 168
					rotatepoint px py x2 py se_ang x3 y3

					updatesector x3 y3 temp
					ifvarn temp -1
					{
						addvarvar px se_x
						addvarvar py se_y
						updatesector px py tmp2
						ifvarn tmp2 -1
						ifvarvare sect2 sect1
						{
						setplayer[THISACTOR].posx px
						setplayer[THISACTOR].posy py
						}
					}
				}
			} else
			{		
				getactor[THISACTOR].sectnum sect2
				cos se_x se_ang
				sin se_y se_ang
				divvarvar se_x 4096
				divvarvar se_y 4096
				mulvarvar se_x hitag
				mulvarvar se_y hitag
					
				setvarvar x2 px
				addvar x2 168
				rotatepoint px py x2 py se_ang x3 y3

				updatesectorz x3 y3 sprite[THISACTOR].z temp
				ifvarvare temp sect2 ifvarn temp -1
				{
					addvarvar px se_x
					addvarvar py se_y
					updatesector px py tmp2
					ifvarn tmp2 -1
					ifvarvare sect2 sect1
					{
						setplayer[THISACTOR].posx px
						setplayer[THISACTOR].posy py
					}
				}
			}
		}
		/*
		1  - floor x
		2  - floor -x
		4  - floor y
		8  - floor -y
		16 - ceiling x
		32 - ceiling -x
		68 - ceiling y
		128 - ceiling -y
		*/
		ifvare lotag 67
		{
			ifvarg active 1 setvar active 0
			ifvare active 1
			{
				getactor[THISACTOR].zvel tr_bits
				getactor[THISACTOR].hitag hitag
				getactor[THISACTOR].sectnum sectnum1
				ifvarand tr_bits 17 { subvarvar se_panning hitag ifvarvarl se_panning -255 setvar se_panning 0 }
				ifvarand tr_bits 34 { addvarvar se_panning hitag ifvarvarg se_panning 255 setvar se_panning 0 }
				ifvarand tr_bits 68 { subvarvar se_panning hitag ifvarvarl se_panning -255 setvar se_panning 0 }
				ifvarand tr_bits 136 { addvarvar se_panning hitag ifvarvarg se_panning 255 setvar se_panning 0 }
				
				ifvarand tr_bits 3 setsector[sectnum1].floorxpanning se_panning
				ifvarand tr_bits 12 setsector[sectnum1].floorypanning se_panning
				
				ifvarand tr_bits 48 setsector[sectnum1].ceilingxpanning se_panning
				ifvarand tr_bits 192 setsector[sectnum1].ceilingypanning se_panning
			}
		}
		ifvare lotag 68 //Floating wave
		{	
			setvarvar hitag se_hitag
			ifvare se_xvel 0 setvar se_xvel 64
			addvarvar hitag se_xvel
			modvar hitag 2048
			setactorvar[THISACTOR].se_hitag hitag
			sin se_sinez hitag
			mulvarvar se_sinez se_yvel
			divvar se_sinez 16069

			getactor[THISACTOR].sectnum sect2
			ifvarand se_zvel 1 {
				getsector[sect2].floorz z
				addvarvar z se_sinez
				setsector[sect2].floorz z
				ifvare se_hastror 1 
					setsector[se_trorsect].ceilingz z 
				getsector[sect2].wallptr wallptr
				addvar wallptr 2
				getwall[wallptr].nextsector sectnum
				getwall[wallptr].x x
				getwall[wallptr].y y
				ifvarn sectnum -1 getflorzofslope sectnum x y z 
				subvar wallptr 1
				getwall[wallptr].x x2
				getwall[wallptr].y y2
				subvarvar x2 x
				subvarvar y2 y
				mulvarvar x2 x2
				mulvarvar y2 y2
				addvarvar x2 y2
				sqrt x2 WALLDIST
				mulvarvar WALLDIST 10
				divvar WALLDIST 256
				getsector[sect2].floorz z2
				subvarvar z z2
				mulvarvar z 10
				divvarvar z WALLDIST
				setsector[sect2].floorslope z
				ifvare se_hastror 1 
					setsector[se_trorsect].ceilingslope z
			}
			ifvarand se_zvel 2
			{
				getsector[sect2].ceilingz z
				subvarvar z se_sinez
				setsector[sect2].ceilingz z
				getsector[sect2].wallptr wallptr
				addvar wallptr 2
				getwall[wallptr].nextsector sectnum
				getwall[wallptr].x x
				getwall[wallptr].y y
				ifvarn sectnum -1 getceilzofslope sectnum x y z 
				subvar wallptr 1
				getwall[wallptr].x x2
				getwall[wallptr].y y2
				subvarvar x2 x
				subvarvar y2 y
				mulvarvar x2 x2
				mulvarvar y2 y2
				addvarvar x2 y2
				sqrt x2 WALLDIST
				mulvarvar WALLDIST 10
				divvar WALLDIST 256
				getsector[sect2].ceilingz z2
				subvarvar z z2
				mulvarvar z 10
				divvarvar z WALLDIST
				setsector[sect2].ceilingslope z
			}
			ifvarand se_zvel 4
			{
				getactor[THISACTOR].ang ang
				setvarvar tmp 327680
				divvarvar tmp se_yvel
				sin se_y hitag
				divvarvar se_y tmp
				cos se_x hitag
				divvarvar se_x tmp
				
				getsector[sect2].wallnum wallnum
				getsector[sect2].wallptr wallptr
				setvar tmp 0
				whilevarvarn tmp wallnum
				{ 
					getwall[wallptr].x x
					getwall[wallptr].y y
					ifvare ang 512 addvarvar x se_x else ifvare ang 1536 addvarvar x se_x else
					ifvare ang 0 addvarvar y se_y else ifvare ang 1024 addvarvar y se_y else
					{
						addvarvar x se_x
						addvarvar y se_y
					}
					dragpoint wallptr x y
					addvar wallptr 1
					addvar tmp 1
				}
			}
		}	
		state se_eventgame
	}
ends

actor TRAINSCALE
getactor[THISACTOR].z coorz1

ifvare active 0
{
	addvar peractor 64
	cos coorz2 peractor
	divvar coorz2 500
	addvarvar coorz1 coorz2
} 
else ifvarn peractor3 3
{
	ifvarg coorz1 -3000 ifvare peractor3 0 { subvar coorz1 64 } else setvar peractor3 1
	
	ifvare peractor3 1 
	{ 
		addvar peractor2 1 
		addvar peractor 64
		cos coorz2 peractor
		divvar coorz2 500
		addvarvar coorz1 coorz2
		ifvarg peractor2 26 setvar peractor3 2 
	}
	ifvare peractor3 2
	{ 
		ifvarg coorz1 -5300 subvar coorz1 64 else 
		{ state rx_cansetactive setvar peractor3 3 }

	}
} else setactorvar[THISACTOR].active 0
setactor[THISACTOR].z coorz1
enda

actor BRKW_ACTOR 10
cstat 33024 sizeat 32 32
getwall[broken_id].cstat acstat
ifvarand acstat 80 nullop else killit
findnearspritevar PR_NAPALM bwall_veclen spriteid
ifvarn spriteid -1
{
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[spriteid].x x2
	getactor[spriteid].y y2
	subvarvar x2 x //создание вектора до центра взрывной волны
	subvarvar y2 y
	mulvarvar x2 bwall_vecx
	mulvarvar y2 bwall_vecy
	addvarvar x2 y2
	divvarvar x2 bwall_veclen
	setvarvar bwall_prjvel x2 // определения проекции вектора до центра взрывной волны на вектор стены
	ifvarg bwall_prjvel 0 {
		setvarvar x2 bwall_x2
		setvarvar y2 bwall_y2 } 
	else { 
		setvarvar x2 bwall_x1
		setvarvar y2 bwall_y1 }
	ifvarl bwall_prjvel 0 mulvar bwall_prjvel -1 //поправка всегда должна быть больше 0
	subvarvar x2 x //создание вектора
	subvarvar y2 y
	setvarvar bwall_tmp2 x2
	setvarvar bwall_tmp3 y2
	mulvarvar bwall_tmp2 bwall_tmp2
	mulvarvar bwall_tmp3 bwall_tmp3
	addvarvar bwall_tmp2 bwall_tmp3
	sqrt bwall_tmp2 bwall_tmp3
	ifvarvarg bwall_prjvel bwall_tmp3 setvarvar bwall_prjvel bwall_tmp3
	mulvarvar x2 bwall_prjvel
	mulvarvar y2 bwall_prjvel
	ifvarg bwall_tmp3 0
	{ divvarvar x2 bwall_tmp3
	divvarvar y2 bwall_tmp3 } else
	{ setvar x2 0 setvar y2 0 }
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	addvarvar x x2
	addvarvar y y2
	setactor[THISACTOR].x x
	setactor[THISACTOR].y y
	getwall[broken_id].nextsector sectorid
	ifvarn sectorid -1
	{
		getsector[sectorid].floorz bwall_z1
		getsector[sectorid].ceilingz bwall_z2
		getactor[spriteid].z z
		ifvarvarg z bwall_z2 ifvarvarl z bwall_z1 setactor[THISACTOR].z z
	}
}
ifhitweapon 
{ ifwasweapon PR_NAPALM { state brokenwalls killit } 
ifwasweapon RADIUSEXPLOSION { state brokenwalls killit } 
}
enda













