



gamevar r0 0 0
gamevar r1 0 0
gamevar snow_step_incs 0 1

gamevar LOGO_FLAGS 127 0

define LITTLE_PIG_PAL 37
define XMAS_LOGO_DELAY 120
define XMAS_LOGO_TIME 120

define SNOW_STEP0 700
define SNOW_STEP1 701
define SNOW_STEP2 702
define SNOW_STEP3 703
// define XMAS_TREE 704
define XMAS_TALK01 705
define XMAS_TALK02 706
define XMAS_TALK03 707
define XMAS_TALK04 708
define XMAS_TALK05 709
define XMAS_TALK06 710
define XMAS_TALK07 711
define XMAS_TALK08 712
define XMAS_TALK09 713
define XMAS_TALK10 714
define XMAS_TALK11 715
define XMAS_TALK12 716
define XMAS_TALK13 717
define XMAS_TALK14 718
define JINGLE_BELL_ROCK 419
definesound SNOW_STEP0   snow00.wav     -128 128 2   0   12000
definesound SNOW_STEP1   snow01.wav     -128 128 2   0   12000
definesound SNOW_STEP2   snow02.wav     -128 128 2   0   12000
definesound SNOW_STEP3   snow03.wav     -128 128 2   0   12000
// definesound XMAS_TREE  xmastree.wav      0   0   255 2   0
definesound XMAS_TALK01  xmas01.voc      0   0   255 4   0
definesound XMAS_TALK02  xmas02.voc      0   0   255 4   0
definesound XMAS_TALK03  xmas03.voc      0   0   255 4   0
definesound XMAS_TALK04  xmas04.voc      0   0   255 4   0
definesound XMAS_TALK05  xmas05.voc      0   0   255 4   0
definesound XMAS_TALK06  xmas06.voc      0   0   255 4   0
definesound XMAS_TALK07  xmas07.voc      0   0   255 4   0
definesound XMAS_TALK08  xmas08.voc      0   0   255 4   0
definesound XMAS_TALK09  xmas09.voc      0   0   255 4   0
definesound XMAS_TALK10  xmas10.voc      0   0   255 4   0
definesound XMAS_TALK11  xmas11.voc      0   0   255 4   0
definesound XMAS_TALK12  xmas12.voc      0   0   255 4   0
definesound XMAS_TALK13  xmas13.voc      0   0   255 4   0
definesound XMAS_TALK14  xmas14.voc      0   0   255 4   0
definesound JINGLE_BELL_ROCK  jbrock04.wav      0   0   255 4   0

define FRESH_SNOW 3855
define SNOW_MAKER 3880
define FALLING_SNOW 3881
define FOOTPRINTSDISSOLVE 3883
define CONFETTI 3887
define CONFETTI_GROUND 3891
define LOGO_SPARK 3892
define LOGO_BLAST1 3893
define LOGO_BLAST2 3894
define LOGO_BLAST3 3895
define LOGO_BLAST4 3896

define SNOW_PRINT_PAL 81 // ExtCLUT White +2 EV
action DISSLV1 0
action DISSLV2 1
action DISSLV3 2
action DISSLV4 3

state vanish_gradual
  getactor[THISACTOR].htg_t 0 r0
  ifvare r0 1800 {
    cstator 2
    getactor[THISACTOR].z r1
    addvar r1 1
    setactor[THISACTOR].z r1
    ifactor FOOTPRINTS { cactor FOOTPRINTSDISSOLVE action DISSLV1 }
    ifactor FOOTPRINTS2 { cactor FOOTPRINTSDISSOLVE action DISSLV2 }
    ifactor FOOTPRINTS3 { cactor FOOTPRINTSDISSOLVE action DISSLV3 }
    ifactor FOOTPRINTS4 { cactor FOOTPRINTSDISSOLVE action DISSLV4 }
  }
  ifvare r0 3600 {
    cstator 512
    getactor[THISACTOR].z r1
    addvar r1 1
    setactor[THISACTOR].z r1
  }
  ifvarg r0 5400 killit
  addvar r0 1
  setactor[THISACTOR].htg_t 0 r0
ends

onevent EVENT_LOGO
  ifvarg totalclock XMAS_LOGO_DELAY {
    setvarvar r0 totalclock subvar r0 XMAS_LOGO_DELAY
    subvar r0 XMAS_LOGO_TIME
    ifvarl r0 0 {
      mulscale r1 r0 r0 8
      addvar r1 160
      rotatesprite 102 r1 65536 0 LOGO_SPARK 0 0 0 0 0 xdim ydim
      addvar r1 4
      rotatesprite 140 r1 65536 0 LOGO_SPARK 0 0 0 0 0 xdim ydim
      addvar r1 -3
      rotatesprite 180 r1 65536 0 LOGO_SPARK 0 0 0 0 0 xdim ydim
      addvar r1 2
      rotatesprite 214 r1 65536 0 LOGO_SPARK 0 0 0 0 0 xdim ydim
    } else {
      /* setvarvar r1 r0 shiftvarr r1 6 */ setvar r1 160
      ifvarl r0 128 {
        subvar r0 128 mulscale r0 r0 r0 7 mulvar r0 -1 addvar r0 128
        shiftvarl r0 9
      } else setvar r0 65536
      rotatesprite 102 r1 r0 0 LOGO_BLAST1 0 0 0 0 0 xdim ydim
      addvar r1 4
      rotatesprite 140 r1 r0 0 LOGO_BLAST2 0 0 0 0 0 xdim ydim
      addvar r1 -3
      rotatesprite 180 r1 r0 0 LOGO_BLAST3 0 0 0 0 0 xdim ydim
      addvar r1 2
      rotatesprite 214 r1 r0 0 LOGO_BLAST4 0 0 0 0 0 xdim ydim
    }
  }
endevent

onevent EVENT_DISPLAYMENU
  setvarvar r1 totalclock andvar r1 63 subvar r1 64
  whilevarn r1 -1 {
    setvar r0 0
    whilevarn r0 -1 {
      rotatesprite r0 r1 32768 0 FALLING_SNOW 0 0 33 0 0 xdim ydim
      addvar r0 64
      ifvarg r0 383 setvar r0 -1
    }
    addvar r1 64
    ifvarg r1 200 setvar r1 -1
  }
endevent

onevent EVENT_GAME
  ifspritepal SNOW_PRINT_PAL {
    ifactor FOOTPRINTS state vanish_gradual
    ifactor FOOTPRINTS2 state vanish_gradual
    ifactor FOOTPRINTS3 state vanish_gradual
    ifactor FOOTPRINTS4 state vanish_gradual
    ifactor FOOTPRINTSDISSOLVE state vanish_gradual
  }
  ifactor PIGCOP
    ifspritepal LITTLE_PIG_PAL sizeat 22 22
endevent

actor FOOTPRINTSDISSOLVE
enda

actor SNOW_MAKER
  cstat 32768
  ifrnd 8 ifpdistl 25000 spawn FALLING_SNOW
enda
move SNOW_FALL 32 96
move SNOW_FALL2 40 112
actor FALLING_SNOW
  ifmove 0 {
    cstat 642 sizeat 36 30
    ifrnd 128 cstator 4
    ifrnd 128 cstator 8
    move SNOW_FALL geth getv randomangle
  }
  ifnotmoving {
    ifmove SNOW_FALL move SNOW_FALL2 geth getv spin 
  } else {
    ifrnd 128 {
      ifmove SNOW_FALL move SNOW_FALL2 geth getv spin
    } else {
      ifmove SNOW_FALL2 move SNOW_FALL geth getv
    }
  }
  iffloordistl 4 killit
  ifgapzl 16 killit
  ifpdistl 16384 cstat 642 else cstator 32768
enda

state snowfix
  getplayer[THISACTOR].spritebridge r0
  ifvarn r0 0 {
    getplayer[THISACTOR].sbs r0
    getactor[r0].picnum r0
  } else {
    getactor[THISACTOR].sectnum r0
    getsector[r0].floorpicnum r0
  }
  ifvare r0 FRESH_SNOW {
    setplayer[THISACTOR].footprintcount 1
    setplayer[THISACTOR].footprintpal SNOW_PRINT_PAL
    ifp ponground {
      ifp prunning addvar snow_step_incs 2
      ifp pwalking addvar snow_step_incs 1
    } else setvar snow_step_incs 13
  } else ifvare r0 478 {
    ifp ponground {
      ifp prunning addvar snow_step_incs 2
      ifp pwalking addvar snow_step_incs 1
    } else setvar snow_step_incs 13
  }
  ifvarg snow_step_incs 13 {
    setvar snow_step_incs 0
    randvar r0 3
    addvar r0 SNOW_STEP0
    soundvar r0
  }
ends

move CONFETTI_GROW 256 -256
move CONFETTI_FALL 0 32
move CONFETTI_LIE 0
actor CONFETTI
  ifmove 0 {
    getactor[THISACTOR].z r0
    addvar r0 -16384
    setactor[THISACTOR].z r0
    sizeat 1 1
    cstat 128
    ifrnd 128 cstator 4
    ifrnd 128 cstator 8
    move CONFETTI_GROW geth getv
  }
  ifmove CONFETTI_GROW {
    getactor[THISACTOR].yrepeat r0 addvar r0 8
    ifvarg r0 30 setvar r0 30
    setactor[THISACTOR].yrepeat r0
    getactor[THISACTOR].xrepeat r0 addvar r0 8
    ifvarg r0 36 {
      setvar r0 36 
      move CONFETTI_FALL geth getv
    }
    setactor[THISACTOR].xrepeat r0
  }
  ifcount 600 killit
  iffloordistl 1 {
    getactor[THISACTOR].sectnum r0
    getsector[r0].floorstat r1
    ifvarand r1 2 nullop else { // If no floor slope
      getsector[r0].floorz r1
      setactor[THISACTOR].z r1
      qspawn CONFETTI_GROUND
    }
    killit
  }
enda
actor CONFETTI_GROUND
  ifmove 0 {
    move CONFETTI_LIE randomangle
    sizeat 32 32 cstat 32
    ifrnd 128 cstator 4
  }
enda











define TC_LOCKER 17 
define TRIGGERQUOTE 5120

define PL_STEP1 500
definesound PL_STEP1 DS_Steps/PL_STEP1.wav 0     0     0   0   0
define PL_STEP2 501
definesound PL_STEP2 DS_Steps/PL_STEP2.wav 0     0     0  0   0
define PL_STEP3 502
definesound PL_STEP3 DS_Steps/PL_STEP3.wav 0     0     0   0   0
define PL_STEP4 503
definesound PL_STEP4 DS_Steps/PL_STEP4.wav 0     0     0   0   0
define PL_STEP5 504
definesound PL_STEP5 DS_Steps/PL_STEP5.wav 0     0     0   0   0

define WADE_STEP1 505
definesound WADE_STEP1 NO.wav 0     0     0   0   0

define PL_DIRT1 506
definesound PL_DIRT1 DS_Steps/PL_DIRT1.wav 0     0     0   0   0
define PL_DIRT2 507
definesound PL_DIRT2 DS_Steps/PL_DIRT2.wav 0     0     0  0   0
define PL_DIRT3 508
definesound PL_DIRT3 DS_Steps/PL_DIRT3.wav 0     0     0   0   0
define PL_DIRT4 509
definesound PL_DIRT4 DS_Steps/PL_DIRT4.wav 0     0     0   0   0
define PL_DIRT5 510
definesound PL_DIRT5 DS_Steps/PL_DIRT5.wav 0     0     0   0   0

define PL_GRASS1 511
definesound PL_GRASS1 DS_Steps/PL_GRASS1.wav 0     0     0   0   0
define PL_GRASS2 512
definesound PL_GRASS2 DS_Steps/PL_GRASS2.wav 0     0     0  0   0
define PL_GRASS3 513
definesound PL_GRASS3 DS_Steps/PL_GRASS3.wav 0     0     0   0   0
define PL_GRASS4 514
definesound PL_GRASS4 DS_Steps/PL_GRASS4.wav 0     0     0   0   0
define PL_GRASS5 515
definesound PL_GRASS5 DS_Steps/PL_GRASS5.wav 0     0     0   0   0

define PL_METAL1 516
definesound PL_METAL1 DS_Steps/PL_METAL1.wav 0     0     0   0   0
define PL_METAL2 517
definesound PL_METAL2 DS_Steps/PL_METAL2.wav 0     0     0  0   0
define PL_METAL3 518
definesound PL_METAL3 DS_Steps/PL_METAL3.wav 0     0     0   0   0
define PL_METAL4 519
definesound PL_METAL4 DS_Steps/PL_METAL4.wav 0     0     0   0   0
define PL_METAL5 520
definesound PL_METAL5 DS_Steps/PL_METAL5.wav 0     0     0   0   0

define PL_RUG1 521
definesound PL_RUG1 DS_Steps/PL_RUG1.wav 0     0     0   0   0
define PL_RUG2 522
definesound PL_RUG2 DS_Steps/PL_RUG2.wav 0     0     0  0   0
define PL_RUG3 523
definesound PL_RUG3 DS_Steps/PL_RUG3.wav 0     0     0   0   0
define PL_RUG4 524
definesound PL_RUG4 DS_Steps/PL_RUG4.wav 0     0     0   0   0
define PL_RUG5 525
definesound PL_RUG5 DS_Steps/PL_RUG5.wav 0     0     0   0   0

define PL_WOOD1 526
definesound PL_WOOD1 DS_Steps/PL_WOOD1.wav 0     0     0   0   0
define PL_WOOD2 527
definesound PL_WOOD2 DS_Steps/PL_WOOD2.wav 0     0     0  0   0
define PL_WOOD3 528
definesound PL_WOOD3 DS_Steps/PL_WOOD3.wav 0     0     0   0   0
define PL_WOOD4 529
definesound PL_WOOD4 DS_Steps/PL_WOOD4.wav 0     0     0   0   0
define PL_WOOD5 530
definesound PL_WOOD5 DS_Steps/PL_WOOD5.wav 0     0     0   0   0

definequote  137        ACCESS CARD REQUIRED!
definequote  168        LOCKED!

gamevar tmp 0 0
gamevar pxvel 0 1
gamevar stepcount 0 1
gamevar PLAYERID 0 1
gamevar HITAGSET 0 2
gamevar LOTAGSET 0 2
gamevar autoclose_delay 0 2
gamevar COUNTER 0 2
gamevar rx_id_numbers 0 2
gamevar tx_can 0 2
gamevar rx_can 0 2
gamevar sectorid 0 2
gamevar spriteid 0 2
gamevar activate_autoclose 0 2
gamevar se_xvel 0 2
gamevar active 0 2
gamevar px 0 1
gamevar py 0 1
gamevar pz 0 1
gamevar psector 0 1
gamevar pang 0 1
gamevar phoriz 0 1
gamevar mycos 0 0
gamevar mysin 0 0
gamevar lk_sectnum 0 2
gamevar flpicnum 0 1
gamevar picnum 0 0
gamevar sect2 0 2
gamevar set 0 2
gamevar wallid 0 2
gamevar HITSECTOR 0 1
gamevar HITWALL 0 2
gamevar HITSPRITE 0 1
gamevar HITX 0 1
gamevar HITY 0 1
gamevar HITZ 0 1
gamevar WALLDIST 0 2
gamevar press_space 0 1
gamevar tr_bits 0 2
gamevar tr_lotag 0 2
gamevar wallnum 0 2
gamevar wallptr 0 2
gamevar lotag 0 2
gamevar VAR_SKULLKEY   0 1
gamevar VAR_EYEKEY     0 1
gamevar VAR_FIREKEY    0 1
gamevar VAR_DAGGERKEY  0 1
gamevar VAR_SPIDERKEY  0 1
gamevar VAR_MOONKEY    0 1
gamevar locker_unlock 0 2
gamevar wallhitag 0 2
gamevar sectnum 0 2
gamevar psectnum 0 1
gamevar x 0 0
gamevar y 0 0
gamevar z 0 0
gamevar mz 0 0
gamevar temp 0 0
gamevar ang 0 0
gamevar peractor 0 2
gamevar HITAG 0 2
gamevar wallactivator_dist 0 1
gamevar wallactivator_x 0 1
gamevar wallactivator_y 0 1
gamevar wallactivator_lotag 0 1
gamevar wallactivator_hitag 0 1
gamevar wallactivator_hitspace 0 1
gamevar xvel 0 0

state aplayer_hitwall
ifvarn HITWALL -1
{
	//getwall[HITWALL].picnum picnum
	//ifvarg picnum 5120
	{	
		getwall[HITWALL].lotag wallactivator_lotag
		getwall[HITWALL].hitag wallactivator_hitag
		ifvarg wallactivator_lotag 0
		{
				getplayer[THISACTOR].posx px
				getplayer[THISACTOR].posy py
				getplayer[THISACTOR].posy pz
				setvarvar wallactivator_x HITX
				setvarvar wallactivator_y HITY
				subvarvar wallactivator_x px
				subvarvar wallactivator_y py
				mulvarvar wallactivator_x wallactivator_x
				mulvarvar wallactivator_y wallactivator_y
				addvarvar wallactivator_x wallactivator_y
				sqrt wallactivator_x wallactivator_dist
		} else 
		ifvarg wallactivator_hitag 0
		{
				getplayer[THISACTOR].posx px
				getplayer[THISACTOR].posy py
				getplayer[THISACTOR].posy pz
				setvarvar wallactivator_x HITX
				setvarvar wallactivator_y HITY
				subvarvar wallactivator_x px
				subvarvar wallactivator_y py
				mulvarvar wallactivator_x wallactivator_x
				mulvarvar wallactivator_y wallactivator_y
				addvarvar wallactivator_x wallactivator_y
				sqrt wallactivator_x wallactivator_dist
		} else setvar wallactivator_dist -1
		ifvarl wallactivator_dist 1278 ifvarn wallactivator_dist -1
		{
			ifhitspace
			{
				ifvare wallactivator_hitspace 0
				{	
					ifvarg wallactivator_lotag 0
					{
					operateactivators wallactivator_lotag THISACTOR
					operatemasterswitches wallactivator_lotag
					operaterespawns wallactivator_lotag
					}
					ifvarg wallactivator_hitag 0
					{
						setvar sectorid 0
						whilevarvarn sectorid NUMSECTORS 
						{
							headspritesect spriteid sectorid
							whilevarn spriteid -1 
							{
								//getactor[spriteid].xvel rx_can
								getactorvar[spriteid].se_xvel rx_can
								
								ifvarvare wallactivator_hitag rx_can { getactorvar[spriteid].active tmp addvar tmp 1 setactorvar[spriteid].active tmp  }
								nextspritesect spriteid spriteid
							}
							addvar sectorid 1
						}
					}
					setvar wallactivator_hitspace 1
				}
			} else setvar wallactivator_hitspace 0
		}
	}
} else { setvar wallactivator_dist -1 setvar wallactivator_lotag 0 }
ends

onevent EVENT_LOADACTOR

	setvar spriteid 0
	whilevarn spriteid 16384
	{
		getactor[spriteid].xvel xvel
		setactorvar[spriteid].se_xvel xvel
		addvar spriteid 1
	}

endevent

onevent EVENT_GAME
ifactor APLAYER
{
	getplayer[THISACTOR].posx px
	getplayer[THISACTOR].posy py
	getplayer[THISACTOR].posz pz
	getplayer[THISACTOR].cursectnum psector
	getplayer[THISACTOR].ang pang
	getplayer[THISACTOR].horiz phoriz
	subvar phoriz 100
	mulvar phoriz -2048
	cos mycos pang
	sin mysin pang
	ifvarn psector -1 hitscan px py pz psector mycos mysin phoriz HITSECTOR HITWALL HITSPRITE HITX HITY HITZ CLIPMASK0 //1
	
	getactor[THISACTOR].xvel pxvel
	getplayer[THISACTOR].cursectnum psectnum
	getplayer[THISACTOR].posx x
	getplayer[THISACTOR].posy y
	getplayer[THISACTOR].posz z
	addvar z 9216
	getflorzofslope psectnum x y mz
	subvarvar mz z
	ifvarl mz 2048
	ifp palive
	{
		ifvarg pxvel 5
		{
		getsector[psectnum].floorpicnum flpicnum
		randvar stepcount 3
		addvar tmp 1
		ifvarg tmp 8 
		{
			switch flpicnum
			default
			ifvare stepcount 0 globalsound PL_STEP1 else
			ifvare stepcount 1 globalsound PL_STEP2 else
			ifvare stepcount 2 globalsound PL_STEP3 else
			ifvare stepcount 3 globalsound PL_STEP4 else
			ifvare stepcount 4 globalsound PL_STEP5
			break
			case 880 //wood
			case 884
			case 1188
			ifvare stepcount 0 globalsound PL_WOOD1 else
			ifvare stepcount 1 globalsound PL_WOOD2 else
			ifvare stepcount 2 globalsound PL_WOOD3 else
			ifvare stepcount 3 globalsound PL_WOOD4 else
			ifvare stepcount 4 globalsound PL_WOOD5
			break
			case 346 //metall
			ifvare stepcount 0 globalsound PL_METAL1 else
			ifvare stepcount 1 globalsound PL_METAL2 else
			ifvare stepcount 2 globalsound PL_METAL3 else
			ifvare stepcount 3 globalsound PL_METAL4 else
			ifvare stepcount 4 globalsound PL_METAL5
			break
			case 3700 //DS_Grass
			ifvare stepcount 0 globalsound PL_GRASS1 else
			ifvare stepcount 1 globalsound PL_GRASS2 else
			ifvare stepcount 2 globalsound PL_GRASS3 else
			ifvare stepcount 3 globalsound PL_GRASS4 else
			ifvare stepcount 4 globalsound PL_GRASS5
			break
			case 3701 //DS_Mud
			case 3702 //DS_Sand
			ifvare stepcount 0 globalsound PL_DIRT1 else
			ifvare stepcount 1 globalsound PL_DIRT2 else
			ifvare stepcount 2 globalsound PL_DIRT3 else
			ifvare stepcount 3 globalsound PL_DIRT4 else
			ifvare stepcount 4 globalsound PL_DIRT5
			break
			break
			case 898 //DS_RUG
			case 899 //DS_RUG
			ifvare stepcount 0 globalsound PL_RUG1 else
			ifvare stepcount 1 globalsound PL_RUG2 else
			ifvare stepcount 2 globalsound PL_RUG3 else
			ifvare stepcount 3 globalsound PL_RUG4 else
			ifvare stepcount 4 globalsound PL_RUG5
			break
			case 336 //DS_WadeStreaming
			case 889 //DS_Wade
			ifvare stepcount 0 globalsound WADE_STEP1
			break
      case FRESH_SNOW
      case 478
      break
			endswitch
			setvar tmp 0
		}
		} else 
		{
		stopsound PL_STEP1 stopsound PL_STEP2 stopsound PL_STEP3 stopsound PL_STEP4 stopsound PL_STEP5
		stopsound PL_WOOD1 stopsound PL_WOOD2 stopsound PL_WOOD3 stopsound PL_WOOD4 stopsound PL_WOOD5
		stopsound PL_METAL1 stopsound PL_METAL2 stopsound PL_METAL3 stopsound PL_METAL4 stopsound PL_METAL5
		stopsound PL_DIRT1 stopsound PL_DIRT2 stopsound PL_DIRT3 stopsound PL_DIRT4 stopsound PL_DIRT5
		stopsound PL_RUG1 stopsound PL_RUG2 stopsound PL_RUG3 stopsound PL_RUG4 stopsound PL_RUG5
		stopsound WADE_STEP1
		// stopsound 1 stopsound 2 stopsound 3 stopsound 4 stopsound 5
		
		stopsound WADE_STEP1
		}
	} else {
		stopsound PL_STEP1 stopsound PL_STEP2 stopsound PL_STEP3 stopsound PL_STEP4 stopsound PL_STEP5
		stopsound PL_WOOD1 stopsound PL_WOOD2 stopsound PL_WOOD3 stopsound PL_WOOD4 stopsound PL_WOOD5
		stopsound PL_METAL1 stopsound PL_METAL2 stopsound PL_METAL3 stopsound PL_METAL4 stopsound PL_METAL5
		stopsound PL_DIRT1 stopsound PL_DIRT2 stopsound PL_DIRT3 stopsound PL_DIRT4 stopsound PL_DIRT5
		stopsound PL_RUG1 stopsound PL_RUG2 stopsound PL_RUG3 stopsound PL_RUG4 stopsound PL_RUG5
		stopsound WADE_STEP1
		// stopsound 1 stopsound 2 stopsound 3 stopsound 4 stopsound 5
		}
	state aplayer_hitwall
}
endevent

action DELAY1 0
action DELAY2 0

state find_rx_tx_cannels
getactor[THISACTOR].yvel tx_can 
ifvarn tx_can 0
{
	setvar sectorid 0
	setvar rx_id_numbers 0
	whilevarvarn sectorid NUMSECTORS 
	{
		headspritesect spriteid sectorid
		whilevarn spriteid -1 
		{
			getactor[spriteid].xvel rx_can
			ifvarvare rx_can tx_can { addvar rx_id_numbers 1 } // количество акторов, которые надо активировать
			nextspritesect spriteid spriteid
		}
		addvar sectorid 1
	}
}
ends

// New Lock system ( TC_LOCKER )

eventloadactor TC_LOCKER
	getactor[THISACTOR].hitag HITAGSET
	getactor[THISACTOR].lotag LOTAGSET
	setactor[THISACTOR].hitag 0
	setactor[THISACTOR].lotag 0
	
	setvar spriteid 0
	whilevarn spriteid 16384
	{
		getactor[spriteid].picnum picnum
		ifvare picnum SECTOREFFECTOR
		{
			getactor[spriteid].sectnum sect2
			getactor[THISACTOR].sectnum sectnum
			getsector[sectnum].lotag tmp
			ifvare tmp 25 ifvarvare sect2 sectnum { getactor[spriteid].lotag lotag ifvare lotag 10 { setactor[spriteid].picnum 0 setactor[spriteid].cstat 32768 getactor[spriteid].hitag autoclose_delay } }
		} 
		ifvare picnum TRIGGERQUOTE
		{
			getactor[spriteid].zvel tr_bits
			getactor[spriteid].sectnum sect2
			getactor[THISACTOR].sectnum sectnum
			ifvarvare sect2 sectnum ifvare tr_bits 2
			{ getactorvar[spriteid].tr_lotag tr_lotag }
		}
		addvar spriteid 1
	}
	
	espawn ACTIVATOR 
	setactor[RETURN].lotag HITAGSET
	
	getactor[THISACTOR].zvel tr_bits 
	getactor[THISACTOR].sectnum sectorid
	getsector[sectorid].wallptr wallptr
	getsector[sectorid].wallnum wallnum
		state find_rx_tx_cannels
	setvar tmp 0
	ifvarl wallnum 1 break
	whilevarvarn tmp wallnum
	{ 
		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 peractor RETURN RETURN RETURN RETURN 0xFFFF0030h //4294901808
		ifvarand tr_bits 2 { setwall[wallptr].hitag 16384 setwall[peractor].hitag HITAGSET } else
		setwall[wallptr].hitag HITAGSET	

		addvar wallptr 1
		addvar tmp 1
	}
    cstat 32768
enda

/* TC_LOCKER tr_bits
1 - activated by key
2 - activated by one-wall without 16384
4 - locked side without quote and sound
8 - locked while active = 0
16 -locked side without sound and quotetrigger_bit2
*/

state operatelocker
operateactivators HITAGSET THISACTOR
ifvarg autoclose_delay 0 { setvar COUNTER 0 ifvare activate_autoclose 0 setvar activate_autoclose 1 else setvar activate_autoclose 0 }
ifvarg rx_id_numbers 0 
{  
	getactor[THISACTOR].yvel tx_can 
	ifvarn tx_can 0
	{
		
		setvar sectorid 0
		whilevarvarn sectorid NUMSECTORS 
		{
			headspritesect spriteid sectorid
			whilevarn spriteid -1 
			{
				//getactor[spriteid].xvel rx_can
				getactorvar[spriteid].se_xvel rx_can
				ifvarvare rx_can tx_can { getactorvar[spriteid].active tmp ifvare tmp 1 { setactorvar[spriteid].active 0 } else setactorvar[spriteid].active 1  }
				nextspritesect spriteid spriteid
			}
			addvar sectorid 1
		}
	}
}
ends

actor TC_LOCKER 0 DELAY1

getactorvar[THISACTOR].active active
ifvarg active 1 setactorvar[THISACTOR].active 1
 
getplayer[THISACTOR].i PLAYERID
getplayer[THISACTOR].posx px
getplayer[THISACTOR].posy py
getplayer[THISACTOR].posz pz
getplayer[THISACTOR].cursectnum psector
getplayer[THISACTOR].ang pang
getplayer[THISACTOR].horiz phoriz
subvar phoriz 100
mulvar phoriz -2048
cos mycos pang
sin mysin pang
ifvarn psector -1 hitscan px py pz psector mycos mysin phoriz RETURN HITWALL spriteid RETURN RETURN RETURN 1

	ifvarn HITWALL -1
	{
		getwall[HITWALL].nextsector lk_sectnum
		setvar sectorid 0
		whilevarvarn sectorid NUMSECTORS 
		{
			headspritesect spriteid sectorid
			whilevarn spriteid -1 
			{
				getactor[spriteid].picnum picnum
				switch picnum
				case TC_LOCKER
					getactor[spriteid].sectnum sect2
					ifvarvare sect2 lk_sectnum { setactorvar[spriteid].set 1 } else setactorvar[spriteid].set 0
				break
				endswitch
				nextspritesect spriteid spriteid
			}
			addvar sectorid 1
		}
	}
	
	
getactorvar[THISACTOR].set set
ifvarvare set 1
{		
	ifvarn HITWALL -1
	{
		getwall[HITWALL].nextwall wallid
		ifvarn wallid -1 { getwall[wallid].hitag HITAG } else setvar HITAG 0
		ifvarg HITAG 0
		{
			getplayer[THISACTOR].posx px
			getplayer[THISACTOR].posy py
			subvarvar HITX px
			subvarvar HITY py
			mulvarvar HITX HITX
			mulvarvar HITY HITY
			addvarvar HITX HITY
			sqrt HITX WALLDIST
		} else setvar WALLDIST -1
	} else { setvar WALLDIST -1 setvar HITAG 0 }
	ifvarl WALLDIST 1278 ifvarn WALLDIST -1
	{ 
		ifhitspace
		{
			ifvare press_space 0
			{	
				ifaction DELAY1
				{
					ifvarand tr_bits 1 //activated by key
					{
						ifvarvarn VAR_SKULLKEY 1
						ifvarvare HITAG HITAGSET
						ifvarvare LOTAGSET 1
						{
							quote 137
							soundonce 473
							action DELAY2
						}
						ifvarvarn VAR_EYEKEY 1
						ifvarvare HITAG HITAGSET
						ifvarvare LOTAGSET 2
						{
							quote 137
							soundonce 473
							action DELAY2
						}
						ifvarvarn VAR_FIREKEY 1
						ifvarvare HITAG HITAGSET
						ifvarvare LOTAGSET 3
						{
							quote 137
							soundonce 473
							action DELAY2
						}
						ifvarvarn VAR_DAGGERKEY 1
						ifvarvare HITAG HITAGSET
						ifvarvare LOTAGSET 4
						{
							quote 137
							soundonce 473
							action DELAY2
						}
						ifvarvarn VAR_SPIDERKEY 1
						ifvarvare HITAG HITAGSET
						ifvarvare LOTAGSET 5
						{
							quote 137
							soundonce 473
							action DELAY2
						}
						ifvarvarn VAR_MOONKEY 1
						ifvarvare HITAG HITAGSET
						ifvarvare LOTAGSET 6
						{
							quote 137
							soundonce 473
							action DELAY2
						}
					}
					ifvarand tr_bits 8 //locked while active = 0
					{
						getactorvar[THISACTOR].active active
						ifvarn active 1
						ifvarvare HITAG HITAGSET
						{
							ifvarand tr_bits 4 { ifvarg tr_lotag 0 { qstrcpy 8 tr_lotag quote 8 } } 
							else
							{
								quote 168
								soundonce 538
							}
							action DELAY2
						}
					}
					ifvarn active 1
					ifvare HITAG 16384
					{	
						ifvarand tr_bits 4 { ifvarg tr_lotag 0 { qstrcpy 8 tr_lotag quote 8 } } 
						else
						{
							quote 168
							soundonce 538
						}
						action DELAY2
					}
				}
				ifaction DELAY1
				{
					ifvarvare HITAG HITAGSET
					{
						state operatelocker
						action DELAY2
					}
				}
				setvar press_space 1
			} 
		}
		else 
		{
		setvar press_space 0
		ifaction DELAY2
		action DELAY1
		}
				ifvare active 1
				ifvare locker_unlock 0
				{
					getactor[THISACTOR].sectnum sectorid
					getsector[sectorid].wallptr wallptr
					getsector[sectorid].wallnum wallnum	
					setvar tmp 0
					ifvarl wallnum 1 break
					whilevarvarn tmp wallnum
					{
						getwall[wallptr].hitag wallhitag
						ifvarvarn wallhitag HITAGSET 
						{ 
							ifvarand tr_bits 1 
							{  
								ifvare LOTAGSET 1 ifvare VAR_SKULLKEY 1 { setwall[wallptr].hitag HITAGSET setvar locker_unlock 1 } else
								ifvare LOTAGSET 2 ifvare VAR_EYEKEY 1 { setwall[wallptr].hitag HITAGSET setvar locker_unlock 1 } else
								ifvare LOTAGSET 3 ifvare VAR_FIREKEY 1 { setwall[wallptr].hitag HITAGSET setvar locker_unlock 1 } else
								ifvare LOTAGSET 4 ifvare VAR_DAGGERKEY 1 { setwall[wallptr].hitag HITAGSET setvar locker_unlock 1 } else
								ifvare LOTAGSET 5 ifvare VAR_SPIDERKEY 1 { setwall[wallptr].hitag HITAGSET setvar locker_unlock 1 } else
								ifvare LOTAGSET 6 ifvare VAR_MOONKEY 1 { setwall[wallptr].hitag HITAGSET setvar locker_unlock 1 } else
								{ setactorvar[THISACTOR].active 0 }
							} else { setwall[wallptr].hitag HITAGSET setvar locker_unlock 1 }
						}
						addvar wallptr 1
						addvar tmp 1
					}
				}
	}
}
ifvare activate_autoclose 1
{
	addvar COUNTER 1
	ifvarvarg COUNTER autoclose_delay 
	{  
		operateactivators HITAGSET THISACTOR
		ifvarg rx_id_numbers 0 
		{  
			getactor[THISACTOR].yvel tx_can 
			ifvarn tx_can 0
			{
				setvar sectorid 0
				whilevarvarn sectorid NUMSECTORS 
				{
				headspritesect spriteid sectorid
				whilevarn spriteid -1 
				{
					//getactor[spriteid].xvel rx_can
					getactorvar[spriteid].se_xvel rx_can
					ifvarvare rx_can tx_can { getactorvar[spriteid].active tmp ifvare tmp 1 { setactorvar[spriteid].active 0 } else setactorvar[spriteid].active 1  }
					nextspritesect spriteid spriteid
				}
				addvar sectorid 1
				}
			}
		}
		setvar COUNTER 0 setvar activate_autoclose 0 
	}
}
enda
