mud++0.35/etc/
mud++0.35/etc/guilds/
mud++0.35/help/propert/
mud++0.35/mudC/
mud++0.35/player/
mud++0.35/src/interface/
mud++0.35/src/os/cygwin32/
mud++0.35/src/os/win32/
mud++0.35/src/os/win32/bcppbuilder/
mud++0.35/src/osaddon/
mud++0.35/src/util/
/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project.  All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion)         msmith@hom.net
MUD++ development mailing list    mudpp@van.ml.org
------------------------------------------------------------------------------
action.h
*/

#ifndef _ACTION_H
#define _ACTION_H

#include "io.h"
#include "streamable.h"
#include "nameable.h"
#include "vmobject.h"

class MudObject;

const int ACTION_NORMAL		= 0;	// A char command.  This is for the
					// doing ptr.  An action with this type
					// is something like a spell cast
const int ACTION_TRIGGER	= 1;	// something triggers the func
const int ACTION_COMMAND	= 2;	// a PC command triggers the func
const int ACTION_TICK		= 3;	// function called every "tick"
const int ACTION_MAX		= 4;

// Trigger actions are usually permenant
const int TRIGGER_ENTER			= 0;
const int TRIGGER_SAY			= 1;
const int TRIGGER_LEAVE			= 2;
const int TRIGGER_CAST			= 3;
const int TRIGGER_FIGHT			= 4;
const int TRIGGER_TIMER			= 5;
const int TRIGGER_GROUP_ENTER		= 6;
const int TRIGGER_GROUP_LEAVE		= 7;
const int MAX_TRIGGER_BITS		= 8;

typedef void ( *a_func )( MudObject *, MudObject *, void * );

class Action : public Streamable, public Nameable, public virtual VMObject
{
	private:
		static int total_count;
	protected:
		a_func da_func;
		MudObject *target;
		MudObject *owner;
		//int t_type
		//int a_type
		int total_time;
		int counter;
		int type;
		unsigned long	trigger_bits[MAX_TRIGGER_BITS];
		void *extra_data;
		String tag;	// possible tag for use with prompt.
				// (eg. when casting a spell <CASTING>
				// is added to prompt)

	public:
		Action( )
		:	da_func(0), target(0), owner(0), total_time(0),
			counter(0), type(0), extra_data(0), tag("None")
		{
			total_count++;
			memset( (void *)trigger_bits, 0,
			sizeof( trigger_bits[0] ) * MAX_TRIGGER_BITS );

		}

		Action( MudObject * own, a_func func )
		:	da_func(func), target(0), owner(own),
			total_time(0), counter(0), type(0), extra_data(0),
			tag("None")
		{
			total_count++;
		        memset( (void *)trigger_bits, 0,
			sizeof( trigger_bits[0] ) * MAX_TRIGGER_BITS );
		}

		Action( MudObject * own, MudObject * tar, a_func func )
		:	da_func(func), target(tar), owner(own),
			total_time(0), counter(0), type(0), extra_data(0),
			tag("None")
		{
			total_count++;
			memset( (void *)trigger_bits, 0,
			sizeof( trigger_bits[0] ) * MAX_TRIGGER_BITS );
		}

		~Action();
		void extract() { fromWorld(); }
		virtual vmtype getVMType() { return VMT_ACTION; }

		virtual void callDaFunc( void ) { da_func( owner, target, NULL ); }
		virtual void interrupt( void );
		a_func getDaFunc( void ) const { return da_func; }
		void setDaFunc( a_func func ) { da_func = func; }
		void setTarget( MudObject *x ) { target = x; }
		MudObject *getTarget( void ) const { return target; }
		void setOwner( MudObject *x ) { owner = x; }
		MudObject *getOwner( void ) const { return owner; }
		void setTotalTime( int t );
		int getTotalTime( void ) const { return total_time; }
		void setType( int );
		int getType( void ) const { return type; }
		void setTag( const char * x ) { tag = x; }
		void setTag( const String & x ) { tag = x; }
		const String & getTag( void ) const { return tag; }
		void resetCounter( void ) { counter = 0; }
		virtual void update( void );

		// This must be called on ANY action type
		void toWorld( void );

		void fromWorld( void );

		// These two methods either set the doing ptr or add to
		// the linked list depending on the owner and the action type
		// Set type 0 to set action ptr 
		void toOwner( void );
		void fromOwner( void );

		void toTarget( void );
		void fromTarget( void );
		void attach( void );
		void detach( void );

		void setExtraData( void * x ) { extra_data = x; }
		void *getExtraData( void ) const { return extra_data; }

		int readFrom( StaticInput & ) { return -1; }
		int writeTo( Output & ) const { return -1; }

		static int getTotalCount() { return total_count; }
};

#endif