/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


		#include "binding_helpers.h"
		#include "scene3d/mtrigger.h"

		using namespace GS::S3D;
		using namespace GS::Core;
		using namespace GS::Script;


//------------------------------------------------------------------------------
SQInteger			TriggerGetItemList(HSQUIRRELVM vm)
{
	__SQ_GETSINGLESAFEPTR(t, MTrigger, typetag_Trigger)
	sq_newarray(vm, 0);
	ListForeachPtr(Trigger::ItemInTrigger *, i, t->items_in_trigger)
		if	(i->inside)
		{
			CObject::Push(vm, (void *)i, typetag_Item);
			sq_arrayappend(vm, -2);
		}
	return 1;
}
SQInteger			TriggerTestItem(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETSAFEPTR(t, MTrigger, typetag_Trigger)
	__SQ_GETSAFEPTR(i, MItem, typetag_Item)
	__SQ_GETEND

	ListForeachPtr(Trigger::ItemInTrigger *, _i, t->items_in_trigger)
		if	(_i->inside && (i == (MItem *)_i->item->mitem))
			__SQ_RETURNBOOL(true)

	__SQ_RETURNBOOL(false)
}
SQInteger			TriggerPosInside(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETSAFEPTR(t, MTrigger, typetag_Trigger)
	__SQ_GETVECTOR(p)
	__SQ_GETEND

	__SQ_RETURNBOOL(t->IsInside(p))
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
void				RegisterTriggerBinding(HSQUIRRELVM vm)
{
/*#
	Topic: Trigger
	Type: Trigger
	Related: Item
#*/

/*#
	Section: TriggerGeneral
	Desc: Trigger general functions.
#*/
	/*#
		Func: TriggerGetItemList
		Proto: array:Item
		Desc: Return an array of items currently inside this trigger.
	#*/
	sq_register(vm, TriggerGetItemList, "TriggerGetItemList", _SC(".x"));
	/*#
		Func: TriggerTestItem
		Proto: bool:Item trigger,Item item
		Desc: Test if a given item is currently inside this trigger.
	#*/
	sq_register(vm, TriggerTestItem, "TriggerTestItem", _SC(".xx"));
	/*#
		Func: TriggerPosInside
		Proto: bool:Item trigger,Vector p
		Desc: Test if a given p is currently inside this trigger.
	#*/
	sq_register(vm, TriggerPosInside, "TriggerPosInside", _SC(".xx"));
}
//------------------------------------------------------------------------------
