/*
	This script file is part of the Sonic 3 A.I.R. script software distribution.
	Copyright (C) 2017-2024 by Eukaryot

	Published under the GNU GPLv3 open source software license, see license.txt
	or https://www.gnu.org/licenses/gpl-3.0.en.html
*/



//-------------------------------------------------------//
// Sinking stone block                                   //
//-------------------------------------------------------//

//# address-hook(0x04279e) end(0x0427dc)
function void fn04279e()
{
	objA0.mapping_offset = 0x042834
	objA0.render_flags |= render_flag.WORLD
	objA0.box_size.x = 0x10
	objA0.box_size.y = 0x10
	objA0.sprite_priority = 0x0280
	u16[A0 + 0x46] = objA0.position.y.u16
	if (global.act == 0)
	{
		objA0.sprite_attributes = (sprite_attribute.PALETTE.LINE2 | 0x00d3)
	}
	else
	{
		objA0.animation.sprite = 1
		objA0.sprite_attributes = (sprite_attribute.PALETTE.LINE2 | 0x0090)
	}

	objA0.update_address = 0x0427e2
	fn0427e2()
}


//# address-hook(0x0427e2) end(0x04282e)
function void fn0427e2()
{
	D0.u8 = objA0.flags2a & (object.flag.P1_ON_OBJECT | object.flag.P2_ON_OBJECT)
	if (D0.u8 == 0)
	{
		if (objA0.flags2e != 0)
		{
			--objA0.flags2e
		}
	}
	else
	{
		if (objA0.flags2e != 0x40)
		{
			++objA0.flags2e
		}
	}

	D0.u8 = objA0.flags2e
	LookupSinCos()
	D0.s16 >>= 3
	D0.u16 += u16[A0 + 0x46]
	objA0.position.y.u16 = D0.u16

	D1.u16 = 0x1b
	D2.u16 = 0x10
	D3.u16 = 0x11
	D4.u16 = objA0.position.x.u16
	fn01dc56()

	DrawOrUnloadObject()
}
