/*
....[@@@..[@@@..............[@.................. 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
------------------------------------------------------------------------------
interface1.cpp
*/
#include "config.h"
#include "interface.h"
#include "io.h"
#include "area.h"
#include "global.h"
#include "pc.h"
void dump_string_P_pPC_s( VMachine * vm )
{
vmstack * args = vm->initp(2);
String * str = args[1].val.s;
Cout << "VMachine interface function dumped string: " << *str << endl;
}
void out_string_P_pPC_s( VMachine * vm )
{
vmstack * args = vm->initp(2);
PC * pc = (PC*) args[0].val.o;
String * str = args[1].val.s;
pc->out( *str );
}
void out_time_P_pPC( VMachine * vm )
{
char buf[ 256 ];
struct rusage r;
getrusage( RUSAGE_SELF, &r );
vmstack * args = vm->initp(1);
PC * pc = (PC*) args[0].val.o;
sprintf( buf, "USER: %d.%dusec\n\rSYS : %d.%dusec\n\r", r.ru_utime.tv_sec, r.ru_utime.tv_usec,
r.ru_stime.tv_sec, r.ru_stime.tv_usec );
pc->out( buf );
}
void getObjPrototype_P_s ( VMachine * vm )
{
vmstack * args = vm->initp(1);
String * str = args[0].val.s;
// cut & paste from do_ofind
String strName;
String strArea;
Object * ptr;
Area *area;
bool wildcard = false;
bool global = false;
if( !(bool)str )
{
vm->push_null_obj( VMT_OBJECT);
return;
}
// Use index object to parse arg
Index tempIndex( *str );
strName = tempIndex.getKey();
strArea = tempIndex.getScope();
HashTable<Object> *objHashTable;
if( strArea == "*" )
global = true;
if( strName == "*" )
wildcard = true;
if( !global )
{
if( !( area = lookupArea( strArea ) ) )
{
vm->push_null_obj( VMT_OBJECT );
return;
}
objHashTable = &area->objIndex;
for_each( (*objHashTable), ptr )
{
if( !wildcard && !ptr->isName( strName ) )
{
objHashTable->next();
continue;
}
vm->push_obj( VMT_OBJECT, ptr );
return;
}
}
else
{
for_each( areas, area )
{
objHashTable = &area->objIndex;
for_each( (*objHashTable), ptr )
{
if( !wildcard && !ptr->isName( strName ) )
continue;
vm->push_obj( VMT_OBJECT, ptr );
return;
}
}
}
vm->push_null_obj( VMT_OBJECT );
}
void copyObject_P_pObject( VMachine * vm )
{
vmstack * args = vm->initp(1);
Object * obj = (Object *) args[0].val.o;
if ( !obj )
{
vm->push_null_obj( VMT_OBJECT );
return;
}
obj = obj->clone();
obj->fromCWorld();
vm->push_obj( VMT_OBJECT, obj );
}
void toRoom_P_pObject_pRoom( VMachine * vm )
{
vmstack * args = vm->initp(2);
Object * obj = (Object *) args[0].val.o;
Room * room = (Room *) args[1].val.o;
if ( !obj || !room )
return;
// it is error prone, we need to work on security
room->addObjInv(obj);
obj->toCWorld();
}
void inRoom_P_pThing( VMachine * vm )
{
vmstack * args = vm->initp(1);
Thing * thing = (Thing*) args[0].val.o;
if ( !thing )
{
// crit_error ? it is a method - should be not null 'this'
vm->push_null_obj( VMT_ROOM );
return;
}
vm->push_obj( VMT_ROOM, thing->inRoom() );
}
void getChar_P_pRoom_s( VMachine * vm )
{
vmstack * args = vm->initp(2);
Room * room = (Room*) args[0].val.o;
String * str = (String*) args[1].val.s;
if( !room )
{
vm->push_null_obj( VMT_CHAR );
return;
}
vm->push_obj( VMT_CHAR, room->getChar( *str ) );
}
void say_P_pChar_s( VMachine * vm )
{
vmstack * args = vm->initp(2);
Char * ch = (Char*) args[0].val.o;
String * str = (String*) args[1].val.s;
if( !ch )
return;
ch->say( *str );
}
void new_array_of_int_P_i( VMachine * vm )
{
vmstack * args = vm->initp(1);
int size = args[0].val.i;
vmptr ret;
VMarray * arr;
if ( size <=0 ) size = 1;
arr = new VMarray( VMT_INT, size );
int i;
for ( i =0; i < size; i++ )
{
arr->table()[i].val.i =0;
arr->table()[i].type = VMT_INT;
}
ret.o = arr;
vm->push( VMT_ARRAY_INT, ret );
}
void new_array_of_float_P_i( VMachine * vm )
{
vmstack * args = vm->initp(1);
int size = args[0].val.i;
vmptr ret;
VMarray * arr;
if ( size <=0 ) size = 1;
arr = new VMarray( VMT_FLOAT, size );
int i;
for ( i =0; i < size; i++ )
{
arr->table()[i].val.f =0;
arr->table()[i].type = VMT_FLOAT;
}
ret.o = arr;
vm->push( VMT_ARRAY_FLOAT, ret );
}
void new_array_of_string_P_i( VMachine * vm )
{
vmstack * args = vm->initp(1);
int size = args[0].val.i;
vmptr ret;
VMarray * arr;
if ( size <=0 )
size = 1;
arr = new VMarray( VMT_STRING, size );
int i;
for ( i =0; i < size; i++ )
{
arr->table()[i].val.s = new String();
arr->table()[i].type = VMT_STRING;
// Cout << "Initialized array with " << *(arr->table[i].s) <<endl;
}
ret.o = arr;
vm->push( VMT_ARRAY_STRING, ret );
}
void new_array_of_vmobject_P_i( VMachine * vm )
{
vmstack * args = vm->initp(1);
int size = args[0].val.i;
vmptr ret;
VMarray * arr;
if ( size <=0 ) size = 1;
arr = new VMarray( VMT_VMOBJECT, size );
int i;
for ( i =0; i < size; i++ )
{
arr->table()[i].val.o =0;
arr->table()[i].type = VMT_VMOBJECT;
}
ret.o = arr;
vm->push( VMT_ARRAY_VMOBJECT, ret );
}