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

// ========================
// Function Declarations
// ========================

reserve function BridgeEnd_DebugDraw
reserve function BridgeEnd_DebugSpawn


// ========================
// Function Definitions
// ========================

private function BridgeEnd_DebugDraw
	// Bug Details:
	// -> For some reason this object is set up to draw different sprites for each direction, but
	//    because this object only has 1 Sprite Frame at all, this means that no sprite is rendered if
	//    the player entered Debug Mode while facing left
	// -> This feature is likely a carryover from this object being a modified copy of S1's GHZ Bridge End,
	//    where there were indeed separate (and correctly functioning) sprites for each direction
	temp0 = object.direction
	temp0 &= FLIP_X
	DrawSprite(temp0)
end function


private function BridgeEnd_DebugSpawn
	CreateTempObject(TypeName[Bridge End], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 4
	
	// this object's propertyValue isn't even used...
	// (this is leftover from S1'S GHZ Bridge End, it doesn't have any effect in this game though)
	object[tempObjectPos].propertyValue = object.direction
	object[tempObjectPos].propertyValue &= FLIP_X
end function


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

event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("EHZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 82, 61)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 111, 333)
	end if
	
	// An old v3-styled loop rather than a v4 foreach loop, once again this is leftover from this object
	//  being a copy of S1's Bridge End
	// (S1's GHZ was developed while v4 spec was still being made, foreaches presumably didn't exist at the time)
	arrayPos0 = 32
	while arrayPos0 < 0x420
		if object[arrayPos0].type == TypeName[Bridge End]
			object[arrayPos0].drawOrder = 4
		end if
		
		arrayPos0++
	loop
	
	SetTableValue(TypeName[Bridge End], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(BridgeEnd_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(BridgeEnd_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("EHZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 82, 61)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 111, 333)
	end if
	
	// it *is* set, but its not used
	// debugMode sets it to either 0/1 based on direction and in the original game it was used as a sort of "type", but in this game it isn't really used
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
