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
------------------------------------------------------------------------------
affect.h
*/

#ifndef _AFFECT_H
#define _AFFECT_H

#include "llist.h"
#include "io.h"
#include "streamable.h"
#include "bit.h"
#include "spell.h"

extern const bitType affect_type_list[];
extern const bitType mod_type_list[];

inline int lookupAffectType( const char * x )
	{	return lookupBit( affect_type_list, x );		}

inline const char * lookupAffectName( int x )
	{	return lookupBitName( affect_type_list, x );	}

inline int lookupModType( const char * x )
	{	return lookupBit( mod_type_list, x );			}

inline const char * lookupModName( int x )
	{	return lookupBitName( mod_type_list, x );		}

const int AFF_INVIS = 1;
const int AFF_BLIND	= 2;
const int AFF_SANCTUARY = 3;
const int AFF_SLEEP = 4;
const int AFF_CHARM = 5;
const int AFF_POISON = 6;
const int AFF_CURSE = 7;
const int AFF_GIANT = 8;
const int AFF_DET_INVIS = 9;
const int AFF_DET_HIDDEN = 10;
const int AFF_DET_MAGIC = 11;


const int MOD_STR = 1;
const int MOD_DEX = 2;
const int MOD_INT = 3;
const int MOD_WIS = 4;
const int MOD_CON = 5;
const int MOD_SPEED = 6;
const int MOD_HP = 7;
const int MOD_MANA = 8;
const int MOD_ENERGY = 9;
const int MOD_AGE = 10;
const int MOD_WEIGHT = 11;
const int MOD_ALIGN = 12;
const int MOD_ARMOR = 13;
const int MOD_DAMROLL = 14;
const int MOD_HITROLL = 15;


// Stat modifiers that aren't specifically finite in duration or
// resulting from a spell affect. Magic items that take affect when
// worn will apply Modifiers to the char which are negated when
// removed. There is no actual list data stucture -on- the char to
// hold Mods, rather the list of mods on an item is applied and negated
// when worn/removed


class Modifier
{
	private:
		int type;			// What does it modify? (str,int,hp)
		int amt;			// By how much does it mod?

	public:
		Modifier()
		:	type( 0 ), amt( 0 )
		{
		}

		Modifier( int t, int a )
		:	type( t ), amt( a )
		{
		}

		int getType() const { return type; }
		int getAmt() const { return amt; }
		const char * getName() { return lookupModName( type ); }
};


class Spell;

class Affect : public Streamable, public virtual VMObject
{
	private:
		static int total_count;
		const SpellType * spell;
		int type;					// const int affect types 
		int duration;				// How long it lasts, in hours.
		int level;					// strength or level

	public:
		LList< Modifier > mod_list;	// List of attribute mods

		Affect()
		:	spell(0), type(0), duration(0), level(0)
		{
			total_count++;
		}

		// The preferred way to create affects
		// Example:
		//
		//	SPELL( spell_giant_form )	
		//  {
		//		if( victim->isAffected( AFF_GIANT )
		//			return;
		//
		//		Affect *paf = new Affect( spell, AFF_GIANT, 10, level );
		//
		//		paf->addMod( MOD_STR, 2 );
		//		paf->addMod( MOD_DEX, -1 );
		//		paf->addMod( MOD_HP, 100 );
		//
		//		victim->addAffect( paf );
		//	}

		Affect( const SpellType *sp, int t, int d, int l )
		:	spell( sp ), type( t ), duration( d ), level( l )
		{
			total_count++;
		}

		~Affect() { total_count--; }
		virtual vmtype getVMType() { return VMT_AFFECT; }

		int writeTo( Output & ) const;
		int readFrom( StaticInput & );

		// Not implemented, shuts up Solaris Pro C++
		int writeTo( const String & ) const { return -1; }
		int readFrom( const String & ) { return -1; }

		int pulse() { return --duration; }
		void addMod( int, int );
		void setType( int x ) { type = x; }
		int getType() { return type; }
		void setTimer( int x ) { duration = x; }
		int getTimer() { return duration; }
		const SpellType * getSpellType() { return spell; }
		void setSpellType( const SpellType * x ) { spell = x; }
		int getLevel() const { return level; }
		void setLevel( int x ) { level = x; }

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


inline void Affect::addMod( int t, int a ) 
{
	Modifier *pmod = new Modifier( t, a );
	mod_list.add( pmod );
}

#endif