// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: MBC_M027 Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

// Octus Aliases
private alias object.value0 : object.timer

private alias 0 : OCTUS_SETUP
private alias 4 : OCTUS_FALL


// ========================
// Events
// ========================

event ObjectUpdate
	foreach (TypeName[MissionBlock], arrayPos0, ACTIVE_ENTITIES)
		foreach (TypeName[Octus], arrayPos1, ACTIVE_ENTITIES)
			// Have each Mission Block in the level check against collision for each Octus in the level
			BoxCollisionTest(C_SOLID, arrayPos0, -16, -16, 16, 16, arrayPos1, -21, -12, 21, 13)
			if checkResult == COL_TOP
				if object[arrayPos1].state == OCTUS_FALL
					// If the Octus is falling, then make it assume the Mission Block is normal ground
					object[arrayPos1].timer = 0
					object[arrayPos1].yvel = 0
					object[arrayPos1].animationTimer = 0
					object[arrayPos1].state = OCTUS_SETUP
				end if
			end if
		next
	next
end event


event ObjectDraw
	// huh?
	// This object doesn't have a sheet loaded, nor any Sprite Frames, so what's this doing here...?
	// And because the object is PRIORITY_ACTIVE, this is *always* getting drawn, at all times offscreen
	DrawSprite(0)
end event


event ObjectStartup
	// See if we're in the OOZ Mission folder and in act 1
	CheckCurrentStageFolder("Mission_Zone07")
	temp0 = checkResult
	CheckEqual(stage.actNum, 1)
	temp0 &= checkResult
	if temp0 == true
		// If we are, then make each Mission Block Collision for Mission 27 Object active
		foreach (TypeName[MBC_M027], arrayPos0, ALL_ENTITIES)
			object[arrayPos0].priority = PRIORITY_ACTIVE
		next
	else
		// If we aren't, then delete each Mission Block Collision for Mission 27 Object in the scene
		// Quite the mouthful, isn't it?
		foreach (TypeName[MBC_M027], arrayPos0, ALL_ENTITIES)
			object[arrayPos0].type = TypeName[Blank Object]
		next
	end if
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
