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/
/*
 * rooms.h
 *	 Header file for Exit / BaseRoom / AreaRoom / Room classes
 *   ____            _
 *  |  _ \ ___  __ _| |_ __ ___  ___
 *  | |_) / _ \/ _` | | '_ ` _ \/ __|
 *  |  _ <  __/ (_| | | | | | | \__ \
 *  |_| \_\___|\__,_|_|_| |_| |_|___/
 *
 * 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 ROOMS_H_
#define ROOMS_H_

// define some limits
#define NUM_RANDOM_SLOTS	50
#define NUM_PERM_SLOTS		50

class Room;
class AreaRoom;
class Fishing;

class Track {
public:
	Track();
	void	load(xmlNodePtr curNode);
	void	save(xmlNodePtr curNode) const;

	short getNum() const;
	Size getSize() const;
	bstring getDirection() const;

	void setNum(short n);
	void setSize(Size s);
	void setDirection(bstring dir);
protected:
	short	num;
	Size	size;
	bstring	direction;
};

class WanderInfo {
public:
	WanderInfo();
	CatRef	getRandom() const;
	void	load(xmlNodePtr curNode);
	void	save(xmlNodePtr curNode) const;
	void	show(const Player* player, bstring area="") const;

	std::map<int, CatRef> random;

	short getTraffic() const;
	void setTraffic(short t);
protected:
	short	traffic;
};


#include "area.h"


class Location {
public:
	Location();
	void save(xmlNodePtr rootNode, bstring name) const;
	void load(xmlNodePtr curNode);
	bstring str() const;
	bool	operator==(const Location& l) const;
	bool	operator!=(const Location& l) const;
	BaseRoom* loadRoom(Player* player=0) const;
	short getId() const;

	CatRef room;
	MapMarker mapmarker;
};


#define EXIT_KEY_LENGTH 20
class Exit: public MudObject {
public:
	Exit();
	~Exit();
	int readFromXml(xmlNodePtr rootNode, BaseRoom* room);
	int saveToXml(xmlNodePtr parentNode) const;

	void escapeText();

	short getLevel() const;
	bstring getOpen() const;
	short getTrap() const;
	short getKey() const;
	bstring getKeyArea() const;
	short getToll() const;
	bstring getPassPhrase() const;
	short getPassLanguage() const;
	Size getSize() const;
	bstring getEnter() const;

	void setLevel(short lvl);
	void setOpen(bstring o);
	void setTrap(short t);
	void setKey(short k);
	void setKeyArea(bstring k);
	void setToll(short t);
	void setPassPhrase(bstring phrase);
	void setPassLanguage(short lang);
	void setSize(Size s);
	void setEnter(bstring e);

	bstring blockedByStr(char color, bstring spell, bstring effectName, bool detectMagic, bool canSee) const;
	Exit* getReturnExit(const BaseRoom* parent, BaseRoom** targetRoom) const;
	void doDispelMagic(BaseRoom* parent);
	bool isWall(bstring name) const;
	bool isConcealed(const Creature* viewer=0) const;

// Effects
	bool isEffected(const bstring& effect) const;
	bool hasPermEffect(const bstring& effect) const;
	EffectInfo* getEffect(const bstring& effect) const;
	bool addEffect(const bstring& effect, void* applier, ApplyFrom aFrom, bool show, BaseRoom* rParent, const Creature* owner=0);
	bool addEffect(EffectInfo* newEffect, bool show, BaseRoom* rParent);
	bool addEffect(const bstring& effect, long duration, int strength, bool show, BaseRoom* rParent, const Creature* owner=0);
	bool addPermEffect(const bstring& effect, int strength, bool show, BaseRoom* rParent);
	bool removeEffect(const bstring& effect, bool show, bool remPerm, BaseRoom* rParent);
	bool removeEffect(EffectInfo* toDel, bool show, BaseRoom* rParent);
	bool removeOppositeEffect(const EffectInfo *effect, BaseRoom* rParent);
	bool pulseEffects(time_t t, BaseRoom* rParent);
	bool doEffectDamage(Creature* target);

	void addEffectReturnExit(bstring effect, long duration, int strength, const Creature* owner);
	void removeEffectReturnExit(bstring effect, BaseRoom* rParent);
protected:
	short	level;
	bstring open;			// output on open
	short	trap; 			// Exit trap
	short	key;			// more keys when short
	bstring keyArea;
	short	toll;			// exit toll cost
	bstring passphrase;
	short	passlang;
	Size	size;
	bstring enter;

public:
	// almost ready to be made protected - just need to get
	// loading of flags done
	char		flags[16]; 		// Max exit flags 128 now

	struct		lasttime ltime;	// Timed open/close

	char		desc_key[3][EXIT_KEY_LENGTH]; // Exit keys

	char		clanFlags[4]; 	// clan allowed flags
	char		classFlags[4];	// class allowed flags
	char		raceFlags[4]; 	// race allowed flags
	short		randExit[5]; 	// Randomly chosen room

	Location target;
	Effects effects;

	bool flagIsSet(int flag) const;
	void setFlag(int flag);
	void clearFlag(int flag);
	bool toggleFlag(int flag);

	bool raceRestrict(const Creature* creature) const;
	bool classRestrict(const Creature* creature) const;
	bool clanRestrict(const Creature* creature) const;
	bool alignRestrict(const Creature* creature) const;
};


class BaseRoom: public MudObject {
protected:
	void BaseDestroy();
	bstring	version;	// What version of the mud this object was saved under

public:
	xtag	*first_ext;		// Exits
	otag	*first_obj;		// Items
	ctag	*first_mon;		// Monsters
	ctag	*first_ply;		// Players

	char	misc[64]; 		// miscellaneous space
	Effects effects;

public:
	BaseRoom();
	virtual ~BaseRoom() {};

	void readExitsXml(xmlNodePtr curNode);

	bool isSunlight() const;
	// handles darkmetal and unique
	void killMortalObjectsOnFloor();
	void killMortalObjects(bool floor=true);
	void killUniques();

	bool isCombat() const;

	Creature* findCreature(Creature* searcher, const cmd* cmnd, int num=1);
        
        Creature* findCreaturePython(Creature* searcher, const bstring& name, bool monFirst = true, bool firstAggro = false, bool exactMatch = false );


        Creature* findCreature(Creature* searcher, const bstring& name, const int num, bool monFirst = true, bool firstAggro = false, bool exactMatch = false);
        Creature* findCreature(Creature* searcher, const bstring& name, const int num, bool monFirst, bool firstAggro, bool exactMatch, int& retVal);


        
	Monster* findMonster(Creature* searcher, const cmd* cmnd, int num=1);
	Monster* findMonster(Creature* searcher, const bstring& name, const int num, bool firstAggro = false, bool exactMatch = false);
	Player* findPlayer(Creature* searcher, const cmd* cmnd, int num=1);
	Player* findPlayer(Creature* searcher, const bstring& name, const int num, bool exactMatch = false);

        MudObject* findTarget(Creature* searcher, const cmd* cmnd, int num=1);
        MudObject* findTarget(Creature* searcher,  const bstring& name, const int num, bool monFirst= true, bool firstAggro = false, bool exactMatch = false);
        MudObject* findTarget(Creature* searcher,  const bstring& name, const int num, bool monFirst, bool firstAggro, bool exactMatch, int& retVal);

	Monster* getGuardingExit(const Exit* exit) const;
	void addExit(Exit *ext);
	void checkExits();
	bool deityRestrict(const Creature* creature) const;
	int maxCapacity() const;
	bool isFull() const;
	int countVisPly() const;
	int countCrt() const;
	Monster* getTollkeeper();

	void wake(bstring str, bool noise) const;
	bool isMagicDark() const;
	bool isNormalDark() const;
	bool isUnderwater() const;
	bool isOutdoors() const;
	bool isDropDestroy() const;
	bool magicBonus() const;
	bool isForest() const;
	bool vampCanSleep(Socket* sock) const;
	int getMaxMobs() const;
	int dmInRoom() const;
	void arrangeExits(Player* player=0);
	bool isWinter() const;

	Room *getUniqueRoom();
	AreaRoom *getAreaRoom();
	const Room *getConstUniqueRoom() const;
	const AreaRoom *getConstAreaRoom() const;

	virtual bool flagIsSet(int flag) const = 0;
	bool hasRealmBonus(Realm realm) const;
	bool hasOppositeRealmBonus(Realm realm) const;
	WanderInfo* getWanderInfo();
	void expelPlayers();

	bstring fullName() const;
	bstring getVersion() const;
	void setVersion(bstring v);
	int whatTraining(int extra=0) const;

	virtual const Fishing* getFishing() const = 0;

// Effects
	bool isEffected(const bstring& effect) const;
	bool hasPermEffect(const bstring& effect) const;
	EffectInfo* getEffect(const bstring& effect) const;
	bool addEffect(const bstring& effect, void* applier, ApplyFrom aFrom, bool show, const Creature* owner=0);
	bool addEffect(EffectInfo* newEffect, bool show = true);
	bool addEffect(const bstring& effect, long duration, int strength, bool show, const Creature* owner=0);
	bool addPermEffect(const bstring& effect, int strength = 1, bool show = true);
	bool removeEffect(const bstring& effect, bool show = true, bool remPerm = true);
	bool removeEffect(EffectInfo* toDel, bool show = true);
	bool removeOppositeEffect(const EffectInfo *effect);
	bool pulseEffects(time_t t);
	void addEffectsIndex();
	bool removeEffectsIndex();
	bool needsEffectsIndex() const;
};


class Room: public BaseRoom {
public:
	Room();
	~Room();

	void escapeText();
	int readFromXml(xmlNodePtr rootNode);
	int saveToXml(xmlNodePtr rootNode, int permOnly) const;
	int saveToFile(int permOnly, LoadType saveType=LS_NORMAL);

	bstring getShortDescription() const;
	bstring getLongDescription() const;
	short getLowLevel() const;
	short getHighLevel() const;
	short getMaxMobs() const;
	short getTrap() const;
	CatRef getTrapExit() const;
	short getTrapWeight() const;
	short getTrapStrength() const;
	bstring getFaction() const;
	long getBeenHere() const;
	short getTerrain() const;
	int getRoomExperience() const;
	Size getSize() const;

	void setShortDescription(const bstring& desc);
	void setLongDescription(const bstring& desc);
	void appendShortDescription(const bstring& desc);
	void appendLongDescription(const bstring& desc);
	void setLowLevel(short lvl);
	void setHighLevel(short lvl);
	void setMaxMobs(short m);
	void setTrap(short t);
	void setTrapExit(CatRef t);
	void setTrapWeight(short weight);
	void setTrapStrength(short strength);
	void setFaction(bstring f);
	void incBeenHere();
	void setTerrain(short t);
	void setRoomExperience(int exp);
	void setSize(Size s);

protected:
	char	flags[16];  // Max flags - 128
	bstring	fishing;

	bstring short_desc;		// Descriptions
	bstring long_desc;
	short	lowLevel;		// Lowest level allowed in
	short	highLevel;		// Highest level allowed in
	short	maxmobs;

	short	trap;
	CatRef 	trapexit;
	short	trapweight;
	short	trapstrength;
	bstring faction;

	long	beenhere;		// # times room visited

	int		roomExp;
	Size	size;
public:

	CatRef	info;

	Track	track;
	WanderInfo wander;			// Random monster info
	std::map<int, crlasttime> permMonsters;	// Permanent/reappearing monsters
	std::map<int, crlasttime> permObjects;	// Permanent/reappearing items

	char	last_mod[24]; 	// Last staff member to modify room.
	struct lasttime lasttime[16]; 	// For timed room things, like darkness spells.

	char	lastModTime[32]; // date created (first *saved)

	char	lastPly[32];
	char	lastPlyTime[32];

public:

	int getWeight();
	void validatePerms();
	void addPermCrt();
	void addPermObj();

	void destroy();

	bool flagIsSet(int flag) const;
	void setFlag(int flag);
	void clearFlag(int flag);
	bool toggleFlag(int flag);

	bool moveRoom(CatRef origin, CatRef target);
	bstring getFishingStr() const;
	void setFishing(bstring id);
	const Fishing* getFishing() const;
};

class AreaRoom: public BaseRoom {
public:
	AreaRoom(Area *a, const MapMarker *m=0);
	~AreaRoom();
	void reset();
	WanderInfo* getRandomWanderInfo();

	bool	canDelete();
	void	recycle();
	bool	updateExit(bstring dir);
	void	updateExits();
	bool	isInteresting(Player *looker);
	bool	isRoad() const;
	bool	isWater() const;
	bool	canSave() const;
	void	save(Player* player=0) const;
	void 	load(xmlNodePtr rootNode);
	CatRef	getUnique(Creature* creature, bool skipDec=false);
	void	setMapMarker(const MapMarker* m);
	bool	moveRoom(CatRef origin, CatRef target);
	bool	spawnHerbs();

	bool flagIsSet(int flag) const;

	const Fishing* doGetFishing(short y, short x) const;
	const Fishing* getFishing() const;

	// any attempt to enter this area room (from any direction)
	// will lead you to a unique room
	CatRef		unique;

	Area		*area;
	MapMarker	mapmarker;

	bool getNeedsCompass() const;
	bool getDecCompass() const;
	bool getStayInMemory() const;

	void setNeedsCompass(bool need);
	void setDecCompass(bool dec);
	void setStayInMemory(bool stay);
protected:
	bool	needsCompass;
	bool	decCompass;
	bool	stayInMemory;
};


#endif /*ROOMS_H_*/