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

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

private alias object.value0 : object.endSlot
private alias object.value1 : object.startSlot


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

event ObjectUpdate
	arrayPos0 = object.startSlot
	while arrayPos0 < object.endSlot
		object[arrayPos0].priority = PRIORITY_ACTIVE
		arrayPos0++
	loop
end event


event ObjectDraw
	arrayPos0 = object.startSlot
	while arrayPos0 < object.endSlot
		if stage.state == STAGE_RUNNING
			object[arrayPos0].priority = PRIORITY_INACTIVE
		else
			object[arrayPos0].priority = PRIORITY_ACTIVE
		end if
		arrayPos0++
	loop
end event


event ObjectStartup
	foreach (TypeName[Belt Activation], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].priority = PRIORITY_XBOUNDS
		arrayPos1 = arrayPos0
		object[arrayPos0].endSlot = object[arrayPos0].propertyValue

		temp0 = false
		while temp0 == false
			if object[arrayPos1].type == TypeName[Belt Platform]
				object[arrayPos0].startSlot = arrayPos1
				temp0 = true
			else
				arrayPos1++
				if arrayPos1 >= 0x420
					// Hit the temp object list, break
					temp0 = true
				end if
			end if
		loop
		object[arrayPos0].endSlot += object[arrayPos0].startSlot
	next
end event


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

event RSDKDraw
	DrawSprite(0)
	
	if editor.showGizmos == true
		editor.drawingOverlay = true
		
		arrayPos0 = object.entityPos
		
		GetObjectType(temp0, "Belt Platform")
		
		checkResult = true
		while checkResult == true
			checkNotEqual(object[arrayPos0].type, temp0)
			arrayPos0 += checkResult
			
			if arrayPos0 >= 0x420
				checkResult = false
			end if
		loop
		
		arrayPos1 = arrayPos0
		arrayPos1 += object.propertyValue
		
		while arrayPos0 < arrayPos1
			DrawLine(object.xpos, object.ypos, object[arrayPos0].xpos, object[arrayPos0].ypos, 0xFF, 0xFF, 0x00)
			arrayPos0++
		loop
		
		editor.drawingOverlay = false
	end if
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 168, 18) // "trigger" - #0

	SetVariableAlias(ALIAS_VAR_PROPVAL, "activateCount")
end event
