//===========================================================================//
// File:	AnimationTrigger.hpp                                                 
// Project: MechWarrior 4
// Contents: 
//			Helper class to deal with animation triggers
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 07/01/98  JSE  Initial coding, 
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Fasa Interactive, Inc.
// All Rights reserved worldwide
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL
//===========================================================================//

#pragma once


#include "MW4.hpp"


namespace MechWarrior4 
{


	typedef void
	(*TriggerMessageHandler)(
		int trigger_value,
		void *pass_data
	);

	

	class TriggerJointValue
	{
	public:

		TriggerJointValue()
		{
			jointNumber = -1;
			triggerNumber = -1;
		}

		TriggerJointValue(int joint_number, int trigger_number)
		{
			jointNumber = joint_number;
			triggerNumber = trigger_number;
		}

		int jointNumber;
		int triggerNumber;

		TriggerJointValue&
			operator=(const TriggerJointValue& value)
				{
					Check_Pointer(this); Check_Pointer(&value);
					jointNumber = value.jointNumber; triggerNumber = value.triggerNumber;
					return *this;
				}

		bool
			operator==(const TriggerJointValue& value) const
				{
					return
						jointNumber == value.jointNumber &&
						triggerNumber == value.triggerNumber;
				}
		bool
			operator!=(const TriggerJointValue& value) const
				{
					return
						jointNumber != value.jointNumber ||
							triggerNumber != value.triggerNumber;
				}
		bool
			operator>(const TriggerJointValue& value) const
				{
					return
						(jointNumber == value.jointNumber) ? 
							(triggerNumber > value.triggerNumber) :
							(jointNumber > value.jointNumber);
				}

		bool
			operator<(const TriggerJointValue& value) const
				{
					return
						(jointNumber == value.jointNumber) ? 
							(triggerNumber < value.triggerNumber) :
							(jointNumber < value.jointNumber);
				}
	};

	//##########################################################################
	//#########################    AnimationTriggerManager    ##################
	//##########################################################################
	
	class AnimationTrigger:
		public Stuff::Plug
	{
	public:
		
		AnimationTrigger(TriggerMessageHandler trigger_message_handler):
			Plug(DefaultData)
		{
			Check_Pointer(trigger_message_handler);
			triggerMessageHandler = trigger_message_handler;
		}
		~AnimationTrigger(){};

		int triggerNumber;

		TriggerMessageHandler triggerMessageHandler;

	};

	//##########################################################################
	//#########################    AnimationTrigger    #########################
	//##########################################################################
	

	class AnimationTriggerManager:
		public Stuff::Plug
	{
	public:
		AnimationTriggerManager();
		~AnimationTriggerManager();


		Stuff::SortedChainOf<AnimationTrigger*, TriggerJointValue>
			animationTriggers;

		void RegisterTriggerCallback(int joint_number, int trigger_number, TriggerMessageHandler trigger_message_handler);
		void DispatchTriggerMessage(int joint_number, int trigger_values, void *pass_data);

	};
}

