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

#ifndef _AREA_H
#define _AREA_H

#include "string.h"
#include "io.h"
#include "bit.h"
#include "vmobject.h"
#include "affect.h"
#include "vector.h"
#include "combat.h"
#include "hash.h"
#include "room.h"
#include "object.h"
#include "npc.h"
#include "mudobj.h"

class Area : virtual public Nameable, virtual public Streamable,
	public MudObject
{
	protected:
		String	file;
		String	key;
		String	author;
		String	repop_messg;
		String	builder;
		String	title;
		String	recall;
		int		version;
		int		min_level;
		int		max_level;
		int		security;
		int		a_flags;
		int		repop_time;
		int		timer;
		int		mods;
		int		dirty_bit;

	public:

		HashTable<Room> roomIndex;
		HashTable<Object> objIndex;
		HashTable<NPC> npcIndex;

		Area()
		:	repop_messg("Bonk!"),version(0), min_level(0), max_level(0),
			security(1), a_flags(0), repop_time(2), timer(0),
			mods(0), dirty_bit(0)
		{
		}

		Area( const String & x )
		:	key(x), version(0), min_level(0), max_level(0),
			repop_time(2), timer(0), mods(0), dirty_bit(0)
		{
			file << x << ".are";	
		}

		virtual vmtype getVMType() { return VMT_AREA; }
		
		void setDirtyBit() { dirty_bit = 1; }
		void rmDirtyBit() { dirty_bit = 0; }
		int getDirtyBit() { return dirty_bit; }

		void addAffect( Affect * ) {}	// area affects (conceivable)
		void rmAffect( int ) {}
		Affect * getAffect( int ) { return 0; }

		// Send text to all players in an area.
		virtual void outAllChar( const char * );
		virtual void outAllChar( const String & x ) { outAllChar( x.chars() ); }
		virtual void outAllCharExcept( const char *, PC * );
		virtual void outAllCharExcept( const String & x, PC * pc ) { outAllCharExcept( x.chars(), pc ); }

		void setKey( const String & x ) { key = x; }
		const String & getKey() const { return key; }
		int reload();

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

		void hardLink();
		const String & getFile() const { return file; }
		void setFile( const String & x ) { file = x; }
		const String & getBuilder() const { return builder; }
		const String & getAuthor() const { return author; }
		void setAuthor( const String & x ) { author = x; }
		const String & getRecall() const { return recall; }
		void setRecall( const String & x ) { recall = x; }
		int getVersion() { return version; }
		void setVersion( int x ) { version = x; }
 		void setBuilder( const String & x ) { builder = x; }
		int getSecurity() const { return security; }
		int getRepopTime() const { return repop_time; }
		void setRepopTime( int t ) { if( t > 0 ) repop_time = t; }
		const String & getRepopMessg() const { return repop_messg; }
		void setRepopMessg( const String & x ) { repop_messg = x; }
		void setTitle( const String & x ) { title = x; }
		const String & getTitle() { return title; }
		void setMinLevel( int x ) { min_level = x; }
		void setMaxLevel( int x ) { max_level = x; }
		int getMinLevel() { return min_level; }
		int getMaxLevel() { return max_level; }
		Object *lookupObj( const String & x ) { return objIndex.lookup( x ); }
		Object *lookupObj( const char * x ) { return objIndex.lookup( x ); }
		Object *createObj( const String & );
		void addObj( const String & x, Object * y ) { objIndex.add( x, y ); }
		NPC *lookupNPC( const String & x ) { return npcIndex.lookup( x ); }
		NPC *lookupNPC( const char * x ) { return npcIndex.lookup( x ); }
		NPC *createNPC( const String & );
		void addNPC( const String & x, NPC * y ) { npcIndex.add( x, y ); }
		Room * lookupRoom( const String & x ) { return roomIndex.lookup( x ); }
		Room * lookupRoom( const char * x ) { return roomIndex.lookup( x ); }
    
		void repop();
		void tick() { if( ++timer >= repop_time ) repop(); }
		void addRoom( Room * );
		void removeRoom( Room * );

		virtual bool isCastle( void ) const { return false; }
		bool isArea( void ) const { return true; }
		virtual Area * asArea() { return this; }
};

inline int Area::load()
{
	char buf[ 4096 ];
	InputFile in( file );
	if( in )
	{
		if( *in.getword( buf ) != 'A' )
			return -1;
		in.getword( buf ); // get the index
		return readFrom( in );
	}
	return -1;
}

inline int Area::save() const
{
	OutputFile out( file.chars() );
	if( out )
		return writeTo( out );
	return -1;
}
#endif