roh/conf/area/
roh/game/talk/
roh/help/
roh/monsters/ocean/
roh/objects/ocean/
roh/player/
roh/rooms/area/1/
roh/rooms/misc/
roh/rooms/ocean/
roh/src-2.44b/
/*
 * structs.h
 *	 Main data structure and type definitions
 *   ____            _
 *  |  _ \ ___  __ _| |_ __ ___  ___
 *  | |_) / _ \/ _` | | '_ ` _ \/ __|
 *  |  _ <  __/ (_| | | | | | | \__ \
 *  |_| \_\___|\__,_|_|_| |_| |_|___/
 *
 * Permission to use, modify and distribute is granted via the
 *  Creative Commons - Attribution - Non Commercial - Share Alike 3.0 License
 *    http://creativecommons.org/licenses/by-nc-sa/3.0/
 *
 * 	Copyright (C) 2007-2009 Jason Mitchell, Randi Mitchell
 * 	   Contributions by Tim Callahan, Jonathan Hseu
 *  Based on Mordor (C) Brooke Paul, Brett J. Vickers, John P. Freeman
 *
 */
#ifndef MSTRUCT_H
#define MSTRUCT_H

class Object;
class Creature;
class Player;
class Monster;
class Exit;
class BaseRoom;
class Room;
class Faction;
class Socket;
class MapMarker;
class EffectInfo;
class AlchemyEffect;

enum AlcoholState {
	ALCOHOL_SOBER = 0,
	ALCOHOL_TIPSY = 1,
	ALCOHOL_DRUNK = 2,
	ALCOHOL_INEBRIATED = 3
};

enum Sex {
	SEX_NONE = 0,
	SEX_FEMALE = 1,
	SEX_MALE = 2
};

enum Coin {
	MIN_COINS = 0,

	COPPER = 	0,
	SILVER =	1,
	GOLD =		2,
	PLATINUM = 	3,
	ALANTHIUM = 4,

	MAX_COINS =	4
};


enum EffectParentType {
	EFFECT_NO_PARENT,
	EFFECT_CREATURE,
	EFFECT_ROOM,
	EFFECT_EXIT
};

// this class holds effect information and makes effects portable
// across multiple objects
class Effects {
public:
	void load(xmlNodePtr rootNode, Creature* cParent=0, BaseRoom* rParent=0, Exit* xParent=0);
	void save(xmlNodePtr rootNode, const char* name) const;
	EffectInfo* getEffect(const bstring& effect) const;
	bool addEffect(const bstring& effect, void* applier, ApplyFrom aFrom, bool show, Creature* cParent=0, BaseRoom* rParent=0, Exit* xParent=0, const Creature* onwer=0);
	bool addEffect(EffectInfo* newEffect, bool show, Creature* parent=0, BaseRoom* rParent=0, Exit* xParent=0);
	bool addEffect(const bstring& effect, long duration, int strength, bool show, Creature* cParent=0, BaseRoom* rParent=0, Exit* xParent=0, const Creature* onwer=0);
	bool removeEffect(const bstring& effect, bool show, bool remPerm, Creature* cParent=0, BaseRoom* rParent=0, Exit* xParent=0);
	bool removeEffect(EffectInfo* toDel, bool show, Creature* cParent=0, BaseRoom* rParent=0, Exit* xParent=0);
	bool removeOppositeEffect(const EffectInfo *effect, Creature* cParent=0, BaseRoom* rParent=0, Exit* xParent=0);
	void removeAll();
	void removeOwner(const Creature* owner);
	void copy(const Effects* source, Creature* cParent=0);
	bool hasPoison() const;
	bool removePoison();
	bool hasDisease() const;
	bool removeDisease();
	bool removeCurse();
	bstring getEffectsString(const Creature* viewer);
	bstring getEffectsList() const;

	void pulse(time_t t, BaseRoom* rParent=0, Exit* xParent=0);

	static EffectParentType getParentType(Creature* cParent=0, BaseRoom* rParent=0, Exit *xParent=0);

	std::list<EffectInfo*> list;
};


class Money {
public:
	Money();
	void load(xmlNodePtr curNode);
	void save(const char* name, xmlNodePtr curNode) const;

	bool isZero() const;
	void zero();

	bool operator==(const Money& mn) const;
	bool operator!=(const Money& mn) const;
	unsigned long operator[](Coin c) const;
	unsigned long get(Coin c) const;

	void set(unsigned long n, Coin c);
	void add(unsigned long n, Coin c);
	void sub(unsigned long n, Coin c);
	void set(Money mn);
	void add(Money mn);
	void sub(Money mn);

	bstring str() const;

	static bstring coinNames(Coin c);
protected:
	unsigned long m[MAX_COINS+1];
};


class Dice {
public:
	Dice();
	Dice(unsigned short n, unsigned short s, short p);
	bool operator==(const Dice& d) const;
	bool operator!=(const Dice& d) const;
	void clear();
	void load(xmlNodePtr curNode);
	void save(xmlNodePtr curNode, const char* name) const;

	int roll() const;
	int average() const;
	int low() const;
	int high() const;
	bstring str() const;

	unsigned short getNumber() const;
	unsigned short getSides() const;
	short getPlus() const;

	void setNumber(unsigned short n);
	void setSides(unsigned short s);
	void setPlus(short p);
protected:
	unsigned short number;
	unsigned short sides;
	short plus;
};


class MudFlag {
public:
	MudFlag();

	int id;
	bstring name;
	bstring desc;
};


class CatRef {
public:
	CatRef();
	void	setDefault(const Creature* target);
	void	clear();
	xmlNodePtr save(xmlNodePtr curNode, const char* childName, bool saveNonZero, int pos=0) const;
	void	load(xmlNodePtr curNode);
	CatRef& operator=(const CatRef& cr);
	bool	operator==(const CatRef& cr) const;
	bool	operator!=(const CatRef& cr) const;
	bstring rstr() const;
	bstring str(bstring current = "", char color = '\0') const;
	void	setArea(bstring c);
	bool	isArea(bstring c) const;

	bstring	area;
	short	id;
};

class Carry {
public:
	Carry();
	xmlNodePtr save(xmlNodePtr curNode, const char* childName, bool saveNonZero, int pos=0) const;
	void	load(xmlNodePtr curNode);
	bstring str(bstring current = "", char color = '\0') const;
	Carry& operator=(const Carry& cry);
	bool	operator==(const Carry& cry) const;
	bool	operator!=(const Carry& cry) const;

	CatRef info;
	int numTrade;
};

class Range {
public:
	Range();

	void	load(xmlNodePtr curNode);
	xmlNodePtr save(xmlNodePtr curNode, const char* childName, int pos=0) const;
	Range&	operator=(const Range& r);
	bool operator==(const Range& r) const;
	bool operator!=(const Range& r) const;
	bool	belongs(CatRef cr) const;
	bstring	str() const;
	bool	isArea(bstring c) const;

	CatRef	low;
	short	high;
};

// Object list tags
typedef struct obj_tag {
public:
	obj_tag() { next_tag = 0; obj = 0; };
	struct obj_tag 	*next_tag;
	struct Object	*obj;
} otag;


// Creature list tags
typedef struct crt_tag {
public:
	crt_tag() { next_tag = 0; crt = 0; };
	struct crt_tag	*next_tag;
	Creature* crt;
} ctag;


// Room list tags
typedef struct rom_tag {
public:
	rom_tag() { next_tag = 0; rom = 0; };
	struct rom_tag	*next_tag;
	Room* rom;
} rtag;


// Exit list tags
typedef struct ext_tag {
public:
	ext_tag() { next_tag = 0; ext = 0; };
	struct ext_tag	*next_tag;
	Exit* ext;
} xtag;


// Enemy list tags
typedef struct enm_tag {
public:
	enm_tag() { next_tag = 0; enemy[0] = 0; damage = 0; owner[0] = 0; };
	struct enm_tag	*next_tag;
	char			enemy[80];
	int				damage;
	char			owner[80];
} etag;


typedef struct vstat {
public:
	vstat() { num[0] = num[1] = num[2] = num[3] = num[4] = 0;
			hp = mp = pp = pp = 0; level = cls = cls2 = race = 0; };
	int		num[5];
	int		hp;
	int		mp;
	int		pp;
	int		rp;
	char	level;
	char	cls;
	char	cls2;
	char	race;
} vstat;


// Talk list tags
typedef struct tlk_tag {
public:
	tlk_tag() { next_tag = 0; key = 0; response = 0; type = 0; action = 0; target = 0; on_cmd = 0; if_cmd = 0;
			test_for = 0; do_act = 0; success = 0; if_goto_cmd = 0; not_goto_cmd = 0; goto_cmd = 0; arg1 = arg2 = 0; };
	struct tlk_tag	*next_tag;
	char		*key;
	char		*response;
	char		type;
	char		*action;
	char		*target;
	char		on_cmd;          // action functions
	char		if_cmd;          // if # command succesful
	char		test_for;        // test for condition in Room
	char		do_act;          // do action
	char		success;         // command was succesful
	char		if_goto_cmd;     // used to jump to new cmd point
	char		not_goto_cmd;    // jump to cmd if not success
	char		goto_cmd;        // unconditional goto cmd
	int			arg1;
	int			arg2;
} ttag;


typedef struct tic {
public:
	tic() {amountCur = amountMax = amountTmp = 0; interval = intervalMax = intervalTmp = 0; };
	char	amountCur;
	char	amountMax;
	char	amountTmp;

	long	interval;
	long	intervalMax;
	long	intervalTmp;
} tic;


typedef struct spellTimer {
public:
	spellTimer() { interval = ltime = misc = misc2 = castLevel = 0; };
	long		interval;
	long		ltime;
	short		misc;
	short		misc2;
	char		castLevel;
} spellTimer;


// Daily-use operation struct
typedef struct daily {
public:
	daily() { max = cur = ltime = 0; };
	short		max;
	short		cur;
	long		ltime;
} daily;


// Timed operation struct
typedef struct lasttime {
public:
	lasttime() { interval = ltime = misc = 0; };
	long		interval;
	long		ltime;
	short		misc;
} lasttime;
typedef struct crlasttime {
public:
	crlasttime() { interval = ltime = 0; };
	long		interval;
	long		ltime;
	CatRef		cr;
} crlasttime;



typedef struct lockout {
public:
	lockout() { address[0] = password[0] = userid[0] = 0; };
	char		address[80];
	char		password[20];
	char		userid[9];
} lockout;


// we need this forward declaration so command list pointers can
// be stored inside the cmd class
class cmdReturn;

#define CMD_NOT_FOUND	-1
#define CMD_NOT_UNIQUE	-2
#define CMD_NOT_AUTH	-3

#define MAX_TOKEN_SIZE	50

class Command;

typedef struct cmd {
public:
	cmd() { ret = num = 0;
			memset(fullstr, 0, sizeof(fullstr));
			memset(str, 0, sizeof(str));
			memset(val, 0, sizeof(val));
			myCommand=0;
	      };
	int			num;
	char		fullstr[256];
	char		str[COMMANDMAX][MAX_TOKEN_SIZE];
	long		val[COMMANDMAX];

	int			ret;
	Command	*myCommand;
} cmd;




typedef struct osp_t {
	int		splno;
	Realm	realm;
	int		mp;
	Dice	damage;
	char	bonus_type;
	bool	drain;
} osp_t;


typedef struct osong_t {
	int     songno;
	Dice	damage;
} osong_t;


typedef struct saves {
public:
	saves() { chance = gained = misc = 0; };
	short	chance;	// Percent chance to save.
	short	gained;
	short	misc;
} saves;



class AreaRoom;
class BaseRoom;

class Anchor {
public:
	Anchor();
	Anchor(bstring a, const Player* player);
	~Anchor();
	void reset();

	Anchor& operator=(const Anchor& a);
	void load(xmlNodePtr curNode);
	void save(xmlNodePtr curNode) const;

	void bind(const Player* player);
	void bind(const Room* uRoom);
	void bind(const AreaRoom* aRoom);
	void setRoom(CatRef r);

	bool is(const BaseRoom* room) const;
	bool is(const Player* player) const;
	bool is(const Room* uRoom) const;
	bool is(const AreaRoom* aRoom) const;

	bstring getAlias() const;
	bstring getRoomName() const;
	CatRef getRoom() const;
	const MapMarker* getMapMarker() const;
protected:
	bstring alias;
	bstring roomName;
	CatRef room;
	MapMarker *mapmarker;
};


// These are special defines to reuse creature structure while still
// making the code readable.


// moved here to accomodate global use throughout mordor
// General queue tag data struct
typedef struct queue_tag {
public:
	queue_tag() { next = prev = 0; };
	bstring				str;
	struct queue_tag	*next;
	struct queue_tag	*prev;
} qtag;


// Sparse pointer array for rooms
typedef struct rsparse {
public:
	rsparse() { rom = 0; q_rom = 0; };
	Room *rom;
	qtag			*q_rom;
} rsparse;


// Sparse pointer array for creatures
typedef struct msparse {
public:
	msparse() { mob = 0; q_mob = 0; };
	Monster *mob;
	qtag			*q_mob;
} msparse;


// Sparse pointer array for objects
typedef struct osparse {
public:
	osparse() {obj = 0; q_obj = 0; };
	Object			*obj;
	qtag			*q_obj;
} osparse;


typedef struct tagPlayer {
	Player* ply;
	Socket* sock;
//	iobuf	*io;
//	extra	*extr;
} plystruct;


typedef struct {
	short	hpstart;
	short	mpstart;
	short	hp;
	short	mp;
	short	ndice;
	short	sdice;
	short	pdice;
} class_stats_struct;


typedef struct {
	short    poison;	// Poison, disease, noxious clouds, etc...
	short    death;     // Deadly traps, massive damage, energy drain attacks, massive tramples, disintegrate spells, fatally wounds from touch, etc..
	short    breath;    // Exploding monsters, firey dragon breath, exploding traps...
	short    mental;    // Charm spells, hold-person spells, confusion spells, teleport traps, mp drain traps...
	short    spells;    // Offensive spell damage, stun spells, dispel-magic traps/spells, other adverse spell effects..
} saves_struct;


typedef struct {
	short	hp;
	short	mp;
	short	armor;
	short	thaco;
	short	ndice;
	short	sdice;
	short	pdice;
	short	str;
	short	dex;
	short	con;
	short	intel;
	short	pie;
	long	realms;
} creatureStats;


typedef struct quest {
public:
	quest() { num = exp = 0; name = 0; };
	int		num;
	int		exp;
	char	*name;
} quest, *questPtr;


// Base class for Command, Spell, Song, etc
class MudMethod {
public:
    virtual ~MudMethod() {};
    bstring name;
    bstring desc;
    int priority;


    bstring getName();
    bstring getDesc();
};

class Spell: public MudMethod {
public:
    ~Spell() {};
};

class Song: public MudMethod {
public:
    ~Song() {};
};

class Command: public MudMethod {
public:
    ~Command() {};
    bool	(*auth)(const Creature *);

    virtual int execute(Creature* player, cmd* cmnd) = 0;
};

// these are supplemental to the cmd class
class CrtCommand: public Command {
public:
    CrtCommand(bstring pCmdStr, int pPriority, int (*pFn)(Creature* player, cmd* cmnd), bool (*pAuth)(const Creature *), bstring pDesc): fn(pFn)
        {
                name = pCmdStr;
                priority = pPriority;
                auth = pAuth;
                desc = pDesc;
        };
    ~CrtCommand() {};
    int (*fn)(Creature* player, cmd* cmnd);
    int execute(Creature* player, cmd* cmnd);
};

class PlyCommand: public Command {
public:
    PlyCommand(bstring pCmdStr, int pPriority, int (*pFn)(Player* player, cmd* cmnd), bool (*pAuth)(const Creature *), bstring pDesc): fn(pFn)
        {
                name = pCmdStr;
                priority = pPriority;
                auth = pAuth;
                desc = pDesc;
        };
    ~PlyCommand() {};
    int (*fn)(Player* player, cmd* cmnd);
    int execute(Creature* player, cmd* cmnd);
};

typedef int (*PFNCOMPARE)(const void *, const void *);

#endif