
// MAP CACHING
// savemapstate
// loadmapstate
// clearmapstate var

// lotag 69 SE two-way HUB transporter
// lotag 70 SE destination only HUB
// transporters go to another with the same hitag
// pal = the level number it takes you to (starts at 0)
// shade 10 SEs are send only (they are not destinations)
// extra 1 SEs do not use coordinate offsets

include GAME.CON

definevolumename 4 HUB TEST

definelevelname 4 0 hub1.map 03:04 01:32 SECTION 1
definelevelname 4 1 hub2.map 04:00 02:00 SECTION 2
definelevelname 4 2 hub3.map 03:30 01:45 SECTION 3
definelevelname 4 3 hub4.map 06:32 03:16 SECTION 4


gamevar lotag 0 2
gamevar hitag 0 2
gamevar act1 0 2
gamevar pdestination -1 131073
gamevar WAIT 0 2
gamevar mysector 0 2
gamevar temp 0 0
gamevar tempb 0 0
gamevar picnum 0 0
gamevar playerwait 0 131073
gamevar pang 0 131073
gamevar xoff 0 131073
gamevar yoff 0 131073
gamevar zoff 0 131073
gamevar savekeys 0 131073

eventloadactor SECTOREFFECTOR
getactor[THISACTOR].lotag lotag
getactor[THISACTOR].hitag hitag
getactor[THISACTOR].sectnum mysector
getactor[THISACTOR].extra act1
enda

state SEHUBSTATE

ifvare WAIT YES // wait for the player to leave the sector before re-activating
break

// don't change maps if this map just loaded
// this avoids problem caused by scroll lock being placed in a map changing sector
getplayer[THISACTOR].player_par temp
ifvarl temp 4
break

// don't change maps if the player is at the edge of the sector
// this avoids problem of the player going back and forth between maps with slight movement
getplayer[THISACTOR].cursectnum tempb
getplayer[THISACTOR].posx xoff
getplayer[THISACTOR].posy yoff
addvar xoff 128
addvar yoff 128
updatesector xoff yoff temp
ifvarvarn tempb temp break
subvar xoff 256
updatesector xoff yoff temp
ifvarvarn tempb temp break
subvar yoff 256
updatesector xoff yoff temp
ifvarvarn tempb temp break
addvar xoff 256
updatesector xoff yoff temp
ifvarvarn tempb temp break

getactor[THISACTOR].shade temp
ifvare temp 10
{
	setvar xoff 0
	setvar yoff 0
	setvar zoff 0
}
else
{
	getactor[THISACTOR].x temp
	getplayer[THISACTOR].posx xoff
	subvarvar xoff temp
	getactor[THISACTOR].y temp
	getplayer[THISACTOR].posy yoff
	subvarvar yoff temp
	getactor[THISACTOR].z temp
	getplayer[THISACTOR].posz zoff
	addvar zoff 8192
	subvarvar zoff temp
	ifvare act1 1 { setvar xoff 0 setvar yoff 0 setvar zoff 0 }
}


setvarvar pdestination hitag
getactor[THISACTOR].pal temp
setvar playerwait 2
getplayer[THISACTOR].ang pang
getplayer[THISACTOR].got_access savekeys
savemapstate
startlevel VOLUME temp

ends

onevent EVENT_GAME

ifvarn pdestination -1 ifactor APLAYER
{
	setplayer[THISACTOR].ang pang
	setplayer[THISACTOR].look_ang 0
	subvar playerwait 1
	ifvarl playerwait 1
	{
		loadmapstate
		setvar temp 0
		whilevarn temp 16384
		{
			getactor[temp].statnum tempb
			ifvare tempb 4
			{
				changespritestat temp 1
				setactor[temp].picnum SMALLSMOKE
				setactor[temp].cstat 32768
			}
			getactor[temp].picnum picnum
			ifvare picnum SMALLSMOKE
			setactor[temp].cstat 32768
			addvar temp 1
		}
		setvar temp 0
		whilevarn temp 16384
		{
			getactor[temp].picnum picnum
			ifvare picnum SECTOREFFECTOR
			{
				getactor[temp].statnum tempb
				getactor[temp].lotag lotag
				ifvarg lotag 68 ifvarl lotag 71
				ifvarn tempb 1024
				{
					getactor[temp].hitag hitag
					getactor[temp].shade tempb
					ifvarvare hitag pdestination
					ifvarn tempb 10
					{
						setactorvar[temp].WAIT YES
						getplayer[THISACTOR].i picnum
						getactor[temp].x tempb
						addvarvar tempb xoff
						setplayer[THISACTOR].posx tempb
						setactor[picnum].x tempb
						getactor[temp].y tempb
						addvarvar tempb yoff
						setplayer[THISACTOR].posy tempb
						setactor[picnum].y tempb
						getactor[temp].z tempb
						addvarvar tempb zoff
						setactor[picnum].z tempb
						subvar tempb 8192
						setplayer[THISACTOR].posz tempb
						getactor[temp].sectnum tempb
						setplayer[THISACTOR].cursectnum tempb
						changespritesect picnum tempb
						setplayer[THISACTOR].knuckle_incs 0
						setplayer[THISACTOR].kickback_pic 0
						setplayer[THISACTOR].got_access savekeys
						setvar temp 16383
					}
				}
			}
			addvar temp 1
		}
		setvar pdestination -1
	}
	
}

ifactor SECTOREFFECTOR ifvare lotag 69
{
	getplayer[THISACTOR].cursectnum temp
	ifvarvare temp mysector state SEHUBSTATE
	else setvar WAIT NO
}


	
endevent