
// 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

gamevar pdestination -1 131073
gamevar WAIT 0 2
gamevar playerwait 0 131073
gamevar pang 0 131073
gamevar xoff 0 131073
gamevar yoff 0 131073
gamevar zoff 0 131073
gamevar savekeys 0 131073


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 actorflags 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