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

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

// Player Aliases
private alias object.pushing : player.pushing

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

private alias 0 : OCTUS_SETUP
private alias 4 : OCTUS_FALL


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

event ObjectUpdate
	temp0 = false
	
	// Check collision between every MissionBlock and Octus
	foreach (TypeName[MissionBlock], arrayPos0, ACTIVE_ENTITIES)
		foreach (TypeName[Octus], arrayPos1, ACTIVE_ENTITIES)
			BoxCollisionTest(C_SOLID, arrayPos0, -16, -16, 16, 16, arrayPos1, -21, -12, 21, 13)
			if checkResult == COL_TOP
				if object[arrayPos1].state == OCTUS_FALL
					object[arrayPos1].timer = 0
					object[arrayPos1].yvel = 0
					object[arrayPos1].animationTimer = 0
					object[arrayPos1].state = OCTUS_SETUP
				end if
			end if
		next
		
		// Huh? A Mission Block's value0 is never referenced or used at all beyond here, what's this supposed to mean?
		temp0 |= object[arrayPos0].value0
	next
	
	if temp0 == false
		// If that flag was not set, then reset Player 1's pushing value
		// (but like, why?? these are Octuses, the player doesn't matter here...
		//  this mission is in SCZ where pushing shouldn't be done anyways, but i still don't see why this exists at all)
		player[0].pushing = 0
	end if
end event


event ObjectDraw
	// This object doesn't even load a sheet, nor does it set up any Sprite Frames, and yet it tries to draw with... something
	
	DrawSprite(0)
end event


event ObjectStartup
	// Not sure why checkResult isn't just looked at directly here, though this object seems to be based off the M027 version of the MBC so it may come from editing off that
	// This object is only used in the Mission_Zone10 folder at all anyways, this is kinda redundant...
	CheckCurrentStageFolder("Mission_Zone10")
	temp0 = checkResult
	if temp0 == true
		foreach (TypeName[MBC_M040], arrayPos0, ALL_ENTITIES)
			object[arrayPos0].priority = PRIORITY_ACTIVE
		next
	else
		foreach (TypeName[MBC_M040], 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
