mud++0.26/etc/
mud++0.26/etc/guilds/
mud++0.26/log/
mud++0.26/mudC/
mud++0.26/player/
mud++0.26/src/unix/
/*
....[@@@..[@@@..............[@.................. 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-list@mailhost.net
------------------------------------------------------------------------------
object.h
*/

#ifndef _OBJECT_H
#define _OBJECT_H

#include "thing.h"
#include "streamable.h"
#include "action.h"
#include "mudobj.h"
#include "trigs.h"

extern const bitType	obj_type_list[];
extern const bitType	obj_bit_list[];
extern const bitType	wear_bit_list[];


const int OBJ_UNUSED		= 0;
const int OBJ_INVISIBLE		= 1;	// obsolete, use invis member of class Thing
const int OBJ_HIDDEN		= 2;
const int OBJ_NOTAKE		= 3;
const int OBJ_NODROP		= 4;
const int OBJ_EDIBLE		= 5;
const int OBJ_NOSAVE		= 6;
const int OBJ_GOOD			= 7;
const int OBJ_EVIL			= 8;
const int OBJ_ANTIGOOD		= 9;
const int OBJ_ANTIEVIL		= 10;
const int OBJ_ANTINEUTRAL	= 11;
const int OBJ_MAGIC			= 12;
const int OBJ_GLOW			= 13;
const int OBJ_SANCTUARY		= 14;
const int OBJ_POISONED		= 15;


const int ITEM_UNUSED			= 0;
const int ITEM_TRASH			= 1;
const int ITEM_JEWEL			= 2;
const int ITEM_GOLD				= 3;
const int ITEM_CONTAINER		= 4;
const int ITEM_LIQUID_CONTAINER	= 5;
const int ITEM_ARMOR			= 6;
const int ITEM_CLOTH			= 7;
const int ITEM_WEAPON			= 8;
const int ITEM_CORPSE			= 9;
const int ITEM_ENERGY			= 10;
const int ITEM_COMPASS			= 11;
const int ITEM_MIN_MAGIC		= 100; //--
const int ITEM_WAND				= 100;
const int ITEM_STAFF			= 101;
const int ITEM_ORB				= 102;
const int ITEM_SCROLL			= 103;
const int ITEM_POTION			= 104;
const int ITEM_FOOD				= 105;
const int ITEM_KEY				= 106;
const int ITEM_MAX_MAGIC		= 120; //--


const int WEAR_NONE		= 0; 
const int WEAR_HEAD		= 1;
const int WEAR_FACE		= 2;
const int WEAR_NECK		= 3;
const int WEAR_BACK		= 4;
const int WEAR_BODY		= 5;
const int WEAR_ARMS		= 6;
const int WEAR_WRIST	= 7;
const int WEAR_HANDS	= 8;
const int WEAR_HOLD		= 9; 
const int WEAR_FINGER	= 10;
const int WEAR_WAIST	= 11;
const int WEAR_LEGS		= 12;
const int WEAR_FEET		= 13;
const int WEAR_SHIELD	= 14;
const int WEAR_WIELD	= 15;


// Wear positions  - bitnums correspond to array positions in eq_list[]

const int EQ_UNDEFINED	=	0;
const int EQ_MIN		=	1;
const int EQ_HEAD		=	1;
const int EQ_FACE		=	2;
const int EQ_NECK_1		=	3;
const int EQ_NECK_2		=	4;
const int EQ_BACK		=	5;
const int EQ_BODY		=	6;
const int EQ_ARMS		=	7;
const int EQ_WRIST_L	=	8;
const int EQ_WRIST_R	=	9;
const int EQ_HANDS		=	10;   
const int EQ_HOLD_L		=	11;
const int EQ_HOLD_R		=	12;
const int EQ_FINGER_L	=	13;
const int EQ_FINGER_R	=	14;
const int EQ_WAIST		=	15;
const int EQ_LEGS		=	16;
const int EQ_FEET		=	17;
const int EQ_SHIELD_L	=	18;
const int EQ_SHIELD_R	=	19;
const int EQ_WIELD_L	=	20;
const int EQ_WIELD_R	=	21;
const int EQ_MAX		=	21; 

const int POISON_LIGHT		= 5;
const int POISON_MEDIUM		= 10;
const int POISON_SERIOUS	= 15;	
const int POISON_LETHAL		= 20;
const int POISON_LETHAL_TOUCH = 25;

const int MAX_WEAR_BIT_FIELDS	=	1;
const int MAX_OBJ_BIT_FIELDS	=	1;

struct SpellType;
class Spell;
class Modifier;
class Affect;
class Object;
class Char;

class Object : public Thing, public virtual Streamable 
{
	private:
		static int total_count;
	protected:
		//Index index;
		unsigned long wear_bits [ MAX_WEAR_BIT_FIELDS ];
		unsigned long obj_bits [ MAX_OBJ_BIT_FIELDS ];
		int condition;
		int material;
		short wear_pos;
		long cost;
		Object *in_obj;
		Char *in_char;
		Repop *repop;

	public:
		LList<Spell> spell_list;	// Spell(s) the object may cast. 
		LList<Modifier> mod_list;	// Magical mods that affect wearer
		LList<Object> inv;

		Object()
		:	wear_pos( 0 ), cost( 0 ),
			in_obj( 0 ), in_char( 0 ), repop( 0 )
		{
			total_count++;
			memset( (void *)wear_bits, 0, sizeof( wear_bits[0] ) * MAX_WEAR_BIT_FIELDS );
			memset( (void *)obj_bits, 0, sizeof( obj_bits[0] ) * MAX_OBJ_BIT_FIELDS );
		}

		// Copy constructor - don't use directly
		// use Object::clone

		Object( const Object &x )
		:	Thing( (Thing&)x ), wear_pos( 0 ),
			cost( x.cost ), in_obj( 0 ), in_char( 0 ), repop( 0 ),
			spell_list( x.spell_list ), mod_list( x.mod_list )
		{
			total_count++;
			memcpy( (void *)wear_bits, (void * )x.wear_bits,
					sizeof( wear_bits[0] ) * MAX_WEAR_BIT_FIELDS );
			memcpy( (void *)obj_bits, (void *)x.obj_bits,
					sizeof( obj_bits[0] ) * MAX_OBJ_BIT_FIELDS );
		}

		virtual ~Object();
		static Object * createObject( int type );
		virtual Object * clone() const { return new Object(*this); }
		virtual Object * asObj() { return this; }
		virtual void extract();
		int readFrom( InFile &in );
		int writeTo( OutFile & ) const;
		virtual int readFromTypeSpecific(InFile & ) {return 0; }
		virtual int writeToTypeSpecific( OutFile &  ) const {return 0;}
		void setObjBit( const String & );
		void clrObjBit( const String & );
		void toggleObjBit( const String & );
		bool objBitSet( int x ) const { return IS_SET( obj_bits, x ); }
		void toggleWearBit( int bit );
		void toggleWearBit( const String & );
		void setWearBit( const String & );
		void clrWearBit( const String & );
		bool wearBitSet( int x ) const { return IS_SET( wear_bits, x ); }
		void out( const char * ) {}
		void out( const String & ) {}
		void setRepop( Repop * x ) { repop = x; }
		Repop * getRepop() { return repop; }
		void toWorld();
		void fromWorld();
		void toChar( Char * );
		void fromChar();
		void toRoom( Room * );
		void fromRoom();
		void toObj( Object * );
		void fromObj();
		Char *inChar() { return in_char; } 
		Char *carriedBy() { return in_char; }
		Object *inObj() { return in_obj; }
		void addAffect( Affect * ) {} 
		void rmAffect( int ) {} 
		Affect * getAffect( int ) { return 0; } 
		virtual const char *typeName() const {return "genericObject";}
		bool isWearable() const;
		int wearPos() const { return wear_pos; }
		bool worn() const { return (bool)wear_pos; }
		void setWearPos( int pos );
		void setCost( int x ) { cost = x; }
		int getCost() { return cost; }

		virtual bool isGold() const { return false; }
		virtual bool isWeapon() const  { return false; }
		virtual bool isContainer() const { return false; }
		virtual bool isLiquidContainer() const { return false; }
		virtual bool isArmor() const { return false; }	
		virtual bool isClothing() const { return false; }	
		virtual bool isFood() const { return false; }	
		virtual bool isCorpse() const { return false; }
		virtual bool isJewel() const { return false; }
		virtual bool isScroll() const { return false; }
		virtual bool isPotion() const { return false; }
		virtual bool isWand() const { return false; }
		virtual bool isStaff() const { return false; }
		virtual bool isOrb() const { return false; }
		virtual bool isKey() const { return false; }
		virtual bool isCompass() const { return false; }

		virtual bool isType( int type )	
			{ return (type == ITEM_UNUSED) ? true : false; }

		// Interface for ObjectEditor
		virtual void reportVals( String & str ) const;
		virtual char * setVals( const String & str );

		Spell * getSpell1(); // Just for utility
		Spell * getSpell2();
		Spell * getSpell3();
		Spell * getSpell4();

		void cast( MudObject * );

		// inventory methods
		void addObjInv( Object * );
		inline Object * getObjInv( const char * str)
				{ return getObjInv( String(str) ); }
		Object * getObjInv( const String & );
		Object * getObjInv( countedThing &);
//		Object * getObjInv( int );
		void rmObjInv( Object * );

		bool isObject( void ) const { return true; }

		static int getTotalCount() { return total_count; }
		// Triggers part
		bool TgCreated( Room *where, Repop * by );
		bool TgUpdate();
		bool TgTimerOut();
		bool TgPicked( Char *caller, Room * from );
		bool TgDropped( Char *caller, Room * to );
		bool TgGiven( Char *from, Char * to );
		bool TgWorn( Char * caller );
		bool TgRemoved( Char * caller );
		bool TgUsed(Char * caller, MudObject * target); // or Thing *
		bool TgLookedAt( Char * caller );
		bool TgItemPutInto( Char * caller, Object * what );
		bool TgItemGetFrom( Char * caller, Object * what );

};

extern const bitType obj_bits[];
extern LList<Object> objects;

inline void Object::fromWorld()
	{	objects.remove( this ); }

inline void Object::toWorld()
	{	objects.add( this ); }

inline int lookupObjType( const char * x )
	{	return lookupBit( obj_type_list, x );	}

inline const char * lookupObjTypeName( int x )
	{	return lookupBitName( obj_type_list, x );	}

inline int getObjBit( const String & x )
	{	return lookupBit( obj_bit_list, x );	}

inline const char * getObjBitName( int x )
	{	return lookupBitName( obj_bit_list, x );	}

inline int getWearBit( const String & x )
	{	return lookupBit( wear_bit_list, x );	}

inline const char * getWearBitName( int x )
	{	return lookupBitName( wear_bit_list, x );	}


// Derived classes
#include "objtypes.h"

#endif