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
------------------------------------------------------------------------------
editobj.cc
*/

#include "config.h"
#include "string.h"
#include "llist.h"
#include "index.h"
#include "hash.h"
#include "server.h"
#include "bit.h"
#include "spell.h"
#include "edit.h"
#include "pc.h"
#include "object.h"
#include "area.h"
#include "room.h"
#include "global.h"
#include "trigs.h"

void ObjectEditor::command( const String & arg )
{
	String str;
	String str2;
	String str3;
	String arg1;
	String arg2;
	String arg3;
	int i;
	int val1;
	int val2;
	Index index1;
	Modifier * mod;
	struct TriggerData * td;

	arg.startArgs();
	arg1 = arg.getArg();
	arg2 = arg.getArgRest();

	if( !obj && !(bool)arg1 )
	{
		pc->out( "No object to edit.\n\r" );
		return;
	}
	else if( !area )
		area = pc->inRoom()->getArea();
/*
	if( arg1 == "new" || arg1 == "create" )
	{
		index1 = arg2;
		if( !(bool)index1.getKey() )
		{
			pc->out( "Usage:  new [scope:]<index>\n\r" );
			return;
		}

		if( !(bool)index1.getScope() )
		{
			area = pc->inRoom()->getArea();
			index1.setScope( area->getKey() );
		}
		else
		{
			area = lookupArea( index1.getScope() );
			if( !area )
			{
				pc->out( "No such area(scope) " );
				pc->out( index1.getScope() );
				pc->out( ".\n\r" );
				return;
			}
		}

		if( area->lookupObj( index1.getKey() ) )
		{
			pc->out( "Object " );
			pc->out( index1.asString() );
			pc->out( " already exists.\n\r" );
			return;
		}
 	
		setIndex( index1 );
		obj = new Object( ITEM_UNUSED );
		obj->setShort( "no short" );
		obj->setLong( "no long" );
		area->addObj( index1.getKey(), obj );
		pc->out( "New object created.\n\r" );
		return;
	}
	else*/ if( arg1 == "list" )
	{
		Object * pObj;
		for_each( area->objIndex, pObj )
			str.sprintfAdd( "%15s - %s\n\r", area->objIndex.getKey().chars(),
										pObj->getShort().chars() );
		pc->out( str );
		return;
	}

	if( !obj )
	{
		pc->out( "No object to edit.\n\r" );
		return;
	}

	if( !(bool)arg || arg[0] == '\n' )
	{
		// Display object and return
		str << "Index: " << getIndex().asString() << "\n\r";
		obj->describeItself( str );
		pc->out( str );
		return;
	}

	if( arg1 == "name" || arg1 == "keywords" )
	{
		obj->setName( arg.getArgRest() );
		pc->out( "\n\rKeywords set to : " );
		pc->out( obj->getName() );
		pc->out( "\n\r" );
		return;
	}
	else if( arg1 == "save" )
	{
		area->save();
		area->rmDirtyBit();
		pc->out( "Zone saved.\n\r" );
		return;
	}
	else if( arg1 == "short" )
	{
		obj->setShort( arg.getArgRest() );
		pc->out( "\n\rShort set to : " );
		pc->out( obj->getShort() );
		pc->out( "\n\r" );
		return;
	}
	else if( arg1 == "long" )
	{
		obj->setLong( arg.getArgRest() );
		pc->out( "\n\rLong set to : " );
		pc->out( obj->getLong() );
		pc->out( "\n\r" );
		return;
	}
	else if( arg1 == "size" )
	{
		if( ( val1 = lookupSize( arg2 ) ) )
		{
			obj->setSize( val1 );
			pc->out( "Size set.\n\r" );	
			return;
		} 
		pc->out( "Invalid size.\n\r" );
		return;
	}
/*	else if( arg1 == "type" )
	{
		arg2 = arg.getArg();
		if( !(bool)arg2 )
		{
			pc->out( "Change object type to what?\n\r" );
			return;
		}

		val1 = lookupObjType( arg2 );
		if( val1 == UNDEFINED )
		{
			pc->out( "Invalid type.\n\r" );
			return;
		}

		obj->setType( val1 );
		pc->out( "Type changed.\n\r" );
		return;
	}
*/	else if( arg1 == "addmod" || arg1 == "addaffect" )
	{
		arg2.startArgs();
		arg3 = arg2.getArg();
		if( !(bool)arg2 && !(bool)arg3 )
		{
			pc->out( "addmod <mod-type> <mod-amount>\n\r" );
			return;
		}

		if( !( val1 = lookupModType( arg3 ) ) )
		{
			pc->out( "Invalid mod type, type 'mod-types'\n\r" );
			return;
 		}

		val2 = arg2.asInt();
		mod = new Modifier( val1, val2 );
		obj->mod_list.addTop( mod );
		pc->out( "Modifier added.\n\r" );
		return;
	}
	else if( arg1 == "help" || arg1 == "?" )
	{
		pc->view( "../help/oedit.hlp" );
		pc->page( "" );
		return;
	}
	else if( arg1 == "obj-bits" || arg1 == "object-bits" )
	{
		pc->view( "../help/obj-bits.hlp" );
		pc->page( "" );
		return;
	}
	else if( arg1 == "wear-bits" || arg1 == "wear-pos" )
	{
		pc->view( "../help/wear-bits.hlp" );
		pc->page( "" );
		return;
	}
	else if( arg1 == "obj-types" || arg1 == "object-types" )
	{
		pc->view( "../help/obj-types.hlp" );
		pc->page( "" );
		return;
	}
	else if( arg1 == "dam-types" || arg1 == "damage-types" )
	{
		pc->view( "../help/dam-types.hlp" );
		pc->page( "" );
		return;
	}
	else if( arg1 == "set" )
		{
		pc->out( obj->setVals(arg2) );
		return;
	}
	else if ( arg1 == "trigadd" )
	{
		void * fun;

		arg2.startArgs();
		arg1 = arg2.getArg();
		str2 = arg2.getArg();
		
		val1 = lookupBit( otrig_types, arg1 );
		if ( val1 == 0 )
		{
			pc->out("No such bit.\n\r");
			return;
		}

		fun = lookupOtrig( val1, str2.chars() );
		if ( fun == NULL )
		{
			pc->out("No such function for that type of trigger.\n\r");
			return;
		}

		for_each(obj->triggers, td )
		{
			if ( td->type == val1 )
				break;
		}

		if ( td != NULL )
		{
			pc->out("Replacing old trigger.\n\r");
			obj->removeTrigger(td);
		}

		td = new (struct TriggerData);
		td->type = val1;
		td->fun = fun;
		obj->addTrigger(td);
		pc->out("Trigger added.\n\r");
		return;

	}
	else if ( arg1 == "trigdel" )
	{
		val1 = lookupBit( otrig_types, arg2 );
		if ( val1 == 0 )
		{
			pc->out("No such bit.\n\r");
			return;
		}

		for_each(obj->triggers, td )
		{
			if ( td->type == val1 )
				break;
		}

		if ( td == NULL )
		{
			pc->out("This object has no such trigger.\n\r");
			return;
		}

		obj->removeTrigger(td);
		pc->out("Trigger removed.\n\r");
		return;
	}
	else if ( arg1 == "triglist" )
	{
		if ( !(bool)arg2 )
		{
			// list types of triggers
			str << "Trigger types for Objectss " <<endl;
			for ( i=1; otrig_types[i].name; i++ )
			{
				str << otrig_types[i].name << endl;
			}
			pc->out(str);
			return;
		}
		else
		{
			// list triggers for given type
			const char * name;
			val1 = lookupBit( otrig_types, arg2 );
			if ( val1 == 0 )
			{
				pc->out("No such bit.\n\r");
				return;
			}
			str << "Triggers for type " << arg2 << ":" << endl;	
			for ( i = 0; ; i++ )
			{
				name = getOtrigName(val1, i);
				if ( !name )
					break;
				str << name << endl;
			}
			pc->out(str);
			return;
		}
	}



	if( ( val1 = getObjBit( arg1 ) ) )
	{
		obj->toggleObjBit( arg1 );
		pc->out( "Object bit toggled.\n\r" );
		return;
	}

	if( ( val1 = getWearBit( arg1 ) ) )
	{
		obj->toggleWearBit( arg1 );
		pc->out( "Wear bit toggled.\n\r" );
		return;
	}

	pc->out( "Invalid command.\n\r" );


}