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
------------------------------------------------------------------------------
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			= VMT_OBJ_TRASH;
const int ITEM_JEWEL			= VMT_OBJ_JEWEL;
const int ITEM_GOLD				= VMT_OBJ_GOLD;
const int ITEM_CONTAINER		= VMT_OBJ_CONTAINER;
const int ITEM_LIQUID_CONTAINER	= VMT_OBJ_LIQUID_CONTAINER;
const int ITEM_ARMOR			= VMT_OBJ_ARMOR;
const int ITEM_CLOTH			= VMT_OBJ_CLOTH;
const int ITEM_WEAPON			= VMT_OBJ_WEAPON;
const int ITEM_CORPSE			= VMT_OBJ_CORPSE;
const int ITEM_ENERGY			= VMT_OBJ_ENERGY;
const int ITEM_COMPASS			= VMT_OBJ_COMPASS;
//const int ITEM_MIN_MAGIC		= VMT_OBJ_; //--
const int ITEM_WAND				= VMT_OBJ_WAND;
const int ITEM_STAFF			= VMT_OBJ_STAFF;
const int ITEM_ORB				= VMT_OBJ_ORB;
const int ITEM_SCROLL			= VMT_OBJ_SCROLL;
const int ITEM_POTION			= VMT_OBJ_POTION;
const int ITEM_FOOD				= VMT_OBJ_FOOD;
const int ITEM_KEY				= VMT_OBJ_KEY;
//const int ITEM_MAX_MAGIC		= VMT_OBJ_; //--



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();
		virtual vmtype getVMType() { return VMT_OBJECT; }
		static Object * createObject( int type );
		virtual Object * clone() const { return new Object(*this); }
		virtual Object * asObj() { return this; }
		virtual void extract();
		int readFrom( StaticInput &in );
		int writeTo( Output & ) const;
		virtual int readFromTypeSpecific(StaticInput & ) {return 0; }
		virtual int writeToTypeSpecific( Output &  ) 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 );
		void describeItself( String &);

		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

/*
class ObjTemplate : public Object
{
	protected:
		int values;

	public:

		ObjTemplate()
		: values(0)
		{}

		ObjTemplate( const ObjTemplate & x)
		: Object(x), values(x.values)
		{}

		virtual ~ObjTemplate() {}
		virtual Object * clone() const { return new ObjTemplate(*this); }
		virtual vmtype getVMType() { return VMT_OBJ_TEMPLATE; }

		virtual int readFromTypeSpecific( StaticInput & in );
		virtual int writeToTypeSpecific( Output & out ) const;
		virtual void reportVals( String & str ) const;
		virtual char * setVals( const String & str );

		virtual bool isTemplate() const { return true; }
		virtual const char *typeName() const 
			{ return lookupObjTypeName(VMT_OBJ_TEMPLATE); }
		virtual bool isType( int type )
			{ return (type == VMT_OBJ_TEMPLATE ) ? true : Object::isType(type); }

		int getValues() { return values; }
		void setValues(int x) { values = x; }
};
*/

class ObjWeapon : public Object
{
	protected:
		int dam_type;
		int min_dam;
		int max_dam;

	public:

		ObjWeapon() 
		:	dam_type(0), min_dam(0), max_dam(0)
		{ }

		ObjWeapon( const ObjWeapon & x )
		:	Object( x ), dam_type(x.dam_type), min_dam(x.min_dam),
			max_dam(x.max_dam)
		{ }
	
		virtual ~ObjWeapon() {}
		virtual Object * clone() const { return new ObjWeapon(*this); }
		virtual vmtype getVMType() { return VMT_OBJ_WEAPON; }
		virtual void reportVals( String & str ) const;
		virtual char * setVals( const String & str );

		virtual int readFromTypeSpecific( StaticInput & in );
		virtual int writeToTypeSpecific( Output & out ) const;

		virtual bool isWeapon() const { return true; }
		virtual const char *typeName() const 
			{ return lookupObjTypeName(VMT_OBJ_WEAPON); }
		virtual bool isType( int type )
			{ return (type == VMT_OBJ_WEAPON ) ? true : Object::isType(type); }


		int getDamType() const { return dam_type; }
		void setDamType( int x ) { dam_type = x; }
		int getMinDam() const { return min_dam; }
		int getMaxDam() const { return max_dam; }

};

class ObjFood : public Object
{
	protected:
		int food_worth;

	public:

		ObjFood()
		: food_worth(0)
		{}

		ObjFood( const ObjFood & x)
		: Object(x), food_worth(x.food_worth)
		{}

		virtual ~ObjFood() {}
		virtual Object * clone() const { return new ObjFood(*this); }
		virtual vmtype getVMType() { return VMT_OBJ_FOOD; }

		virtual int readFromTypeSpecific( StaticInput & in );
		virtual int writeToTypeSpecific( Output & out ) const;
		virtual void reportVals( String & str ) const;
		virtual char * setVals( const String & str );


		virtual bool isFood() const { return true; }
		virtual const char *typeName() const 
			{ return lookupObjTypeName(VMT_OBJ_FOOD); }
		virtual bool isType( int type )
			{ return (type == VMT_OBJ_FOOD ) ? true : Object::isType(type); }


		int getFoodWorth() { return food_worth; }
		void setFoodWorth(int x) { food_worth = x; }

};


class ObjLiquidContainer : public Object
{
	protected:
		int amount;

	public:

		ObjLiquidContainer()
		: amount(0)
		{}

		ObjLiquidContainer( const ObjLiquidContainer & x)
		: Object(x), amount(x.amount)
		{}

		virtual ~ObjLiquidContainer() {}
		virtual Object * clone() const { return new ObjLiquidContainer(*this); }
		virtual vmtype getVMType() { return VMT_OBJ_LIQUID_CONTAINER; }

		virtual int readFromTypeSpecific( StaticInput & in );
		virtual int writeToTypeSpecific( Output & out ) const;
		virtual void reportVals( String & str ) const;
		virtual char * setVals( const String & str );


		virtual bool isLiquidContainer() const { return true; }
		virtual const char *typeName() const 
			{ return lookupObjTypeName(VMT_OBJ_LIQUID_CONTAINER); }
		virtual bool isType( int type )
			{ return (type == VMT_OBJ_LIQUID_CONTAINER ) ? true : Object::isType(type); }


		int getAmount() { return amount; }
		void setAmount(int x) { amount = x; }
		
};

class ObjCorpse : public Object
{
	protected:
		int values;

	public:

		ObjCorpse()
		: values(0)
		{}

		ObjCorpse( const ObjCorpse & x)
		: Object(x), values(x.values)
		{}

		virtual ~ObjCorpse() {}
		virtual Object * clone() const { return new ObjCorpse(*this); }
		virtual vmtype getVMType() { return VMT_OBJ_CORPSE; }

		virtual int readFromTypeSpecific( StaticInput & ) {return 0;}
		virtual int writeToTypeSpecific( Output & ) const {return 0;}

		virtual bool isCorpse() const { return true; }
		virtual const char *typeName() const 
			{ return lookupObjTypeName(VMT_OBJ_CORPSE); }
		virtual bool isType( int type )
			{ return (type == VMT_OBJ_CORPSE ) ? true : Object::isType(type); }


		int getValues() { return values; }
		void setValues(int x) { values = x; }

};

class ObjGold : public Object
{
	protected:
		int values;

	public:

		ObjGold()
		: values(0)
		{}

		ObjGold( const ObjGold & x)
		: Object(x), values(x.values)
		{}

		virtual ~ObjGold() {}
		virtual Object * clone() const { return new ObjGold(*this); }
		virtual vmtype getVMType() { return VMT_OBJ_GOLD; }

		virtual int readFromTypeSpecific( StaticInput & ) {return 0;}
		virtual int writeToTypeSpecific( Output & ) const {return 0;}

		virtual bool isGold() const { return true; }
		virtual const char *typeName() const 
			{ return lookupObjTypeName(VMT_OBJ_GOLD); }
		virtual bool isType( int type )
			{ return (type == VMT_OBJ_GOLD ) ? true : Object::isType(type); }


		int getValues() { return values; }
		void setValues(int x) { values = x; }

};



class ObjArmor : public Object
{
	protected:
		int values;

	public:

		ObjArmor()
		: values(0)
		{}

		ObjArmor( const ObjArmor & x)
		: Object(x), values(x.values)
		{}

		virtual ~ObjArmor() {}
		virtual Object * clone() const { return new ObjArmor(*this); }
		virtual vmtype getVMType() { return VMT_OBJ_ARMOR; }

		virtual int readFromTypeSpecific( StaticInput & ) {return 0;}
		virtual int writeToTypeSpecific( Output & ) const {return 0;}

		virtual bool isArmor() const { return true; }
		virtual const char *typeName() const 
			{ return lookupObjTypeName(VMT_OBJ_ARMOR); }
		virtual bool isType( int type )
			{ return (type == VMT_OBJ_ARMOR ) ? true : Object::isType(type); }

		int getValues() { return values; }
		void setValues(int x) { values = x; }
};



class ObjContainer : public Object
{
	protected:
		int values;

	public:

		ObjContainer()
		: values(0)
		{}

		ObjContainer( const ObjContainer & x)
		: Object(x), values(x.values)
		{}

		virtual ~ObjContainer() {}
		virtual Object * clone() const { return new ObjContainer(*this); }
		virtual vmtype getVMType() { return VMT_OBJ_CONTAINER; }

		virtual int readFromTypeSpecific( StaticInput & ) {return 0;}
		virtual int writeToTypeSpecific( Output & ) const {return 0;}

		virtual bool isContainer() const { return true; }
		virtual const char *typeName() const 
			{ return lookupObjTypeName(VMT_OBJ_CONTAINER); }
		virtual bool isType( int type )
			{ return (type == VMT_OBJ_CONTAINER ) ? true : Object::isType(type); }

		int getValues() { return values; }
		void setValues(int x) { values = x; }
};


#endif