vmtypes.cpp
mud++0.33/src/vmtypes.cpp · 9.4 KB
From the archive mud++0.33.tar.gz
Download the archive « Back to the archive contents
/*
....[@@@..[@@@..............[@.................. 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-list@mailhost.net
------------------------------------------------------------------------------
vmtypes.cc
*/
#include "vmtypes.h"
#include "vmobject.h"
#include "string.h"
#include "erratum.h"
#include "vmarray.h"
#include "vmfields.h"
vmptr clone_VMObject( vmptr vobj )
{
if ( vobj.o )
vobj.o->getHandle();
return vobj;
}
void del_VMObject( vmptr vobj )
{
if ( vobj.o )
vobj.o->freeHandle();
}
vmptr clone_String( vmptr vstr )
{
vmptr ret;
ret.s = new String( *(vstr.s) );
return ret;
}
void del_String( vmptr vstr )
{
delete vstr.s;
}
// used for vmint, vmfloat and constant structs like SpellType
vmptr clone_value( vmptr val )
{
return val;
}
void del_value( vmptr )
{
// do nothing
}
vmptr clone_array( vmptr vmarr )
{
if ( vmarr.a )
vmarr.a->reference();
return vmarr;
}
void del_array( vmptr vmarr )
{
if ( vmarr.a )
vmarr.a->dereference();
}
vmptr clone_unknown( vmptr )
{
vmptr fake;
Error::dump("Tried to clone unsupported vmtype");
fake.i = 0;
return fake; // shouldn't be reached
}
void del_unknown( vmptr )
{
Error::dump("Tried to delete unsupported vmtype");
}
char * setfield_proxy(VMachine *, void *, int, vmptr)
{
return "This object is not implemented at the moment.";
}
bool getfield_proxy(VMachine*, void *, int)
{
return "This object is not implemented at the moment.";
}
char * setfield_error(VMachine *, void *, int, vmptr)
{
return "This object has no public fields.";
}
bool getfield_error(VMachine*, void *, int)
{
return "This object has no public fields.";
}
fieldmap null_fieldmap[1] =
{
{ NULL, 0 }
};
struct s_vmtype_table vmtype_table[VMT_MAX_TYPE+1];
// What (5-1)FU stands for ?
// For Future Use - when we will add next fields to table, we will just
// need to replace this symbol by templates for needed variables
struct s_vmtype_table_proto
{
vmtype type;
struct s_vmtype_table data;
};
struct s_vmtype_table_proto vmtype_table_proto[VMT_MAX_TYPE+1] =
{
{ VMT_NULL ,
{ "NULL", VMT_NULL , clone_value, del_value ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_TOPOFSTACK ,
{ "TopOfStack", VMT_NULL , clone_unknown, del_unknown ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_INT ,
{ "int", VMT_NULL , clone_value, del_value ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_FLOAT ,
{ "float", VMT_NULL , clone_value, del_value ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_STRING ,
{ "String", VMT_NULL , clone_String, del_String ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_VMOBJECT ,
{ "VMObject", VMT_NULL , clone_VMObject, del_VMObject ,
setfield_VMObject, getfield_VMObject, fieldmap_VMObject /*4FU*/ } },
{ VMT_MUDOBJECT ,
{ "MudObject", VMT_VMOBJECT , clone_VMObject, del_VMObject ,
setfield_MudObject, getfield_MudObject, fieldmap_MudObject /*4FU*/ } },
{ VMT_THING ,
{ "Thing", VMT_MUDOBJECT , clone_VMObject, del_VMObject ,
setfield_Thing, getfield_Thing, fieldmap_Thing /*4FU*/ } },
{ VMT_CHAR ,
{ "Char", VMT_THING , clone_VMObject, del_VMObject ,
setfield_Char, getfield_Char, fieldmap_Char /*4FU*/ } },
{ VMT_NPC ,
{ "NPC", VMT_CHAR , clone_VMObject, del_VMObject ,
setfield_NPC, getfield_NPC, fieldmap_NPC /*4FU*/ } },
{ VMT_PC ,
{ "PC", VMT_CHAR , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_SHOPKEEPER ,
{ "ShopeKeeper", VMT_NPC , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_ROOM ,
{ "Room", VMT_MUDOBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_EXIT ,
{ "Exit", VMT_VMOBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_REPOP ,
{ "Repop", VMT_VMOBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJECT ,
{ "Object", VMT_THING , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_ACTION ,
{ "Action", VMT_VMOBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_AFFECT ,
{ "Affect", VMT_VMOBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_ATTACK ,
{ "Attack", VMT_VMOBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_AREA ,
{ "Area", VMT_MUDOBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_TRASH ,
{ "ObjTrash", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_JEWEL ,
{ "ObjJewel", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_GOLD ,
{ "ObjGold", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_CONTAINER ,
{ "ObjContainer", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_LIQUID_CONTAINER ,
{ "ObjLiquidContainer", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_ARMOR ,
{ "ObjArmor", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_CLOTH ,
{ "ObjCloth", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_WEAPON ,
{ "ObjWeapon", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_STAFF ,
{ "ObjStaff", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_WAND ,
{ "ObjWand", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_ORB ,
{ "ObjOrb", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_CORPSE ,
{ "ObjCorpse", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_ENERGY ,
{ "ObjEnergy", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_SCROLL ,
{ "ObjScroll", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_POTION ,
{ "ObjPotion", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_FOOD ,
{ "ObjFood", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_KEY ,
{ "ObjKey", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_STAFF ,
{ "ObjStaff", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_OBJ_COMPASS ,
{ "ObjCompass", VMT_OBJECT , clone_VMObject, del_VMObject ,
setfield_proxy, getfield_proxy, null_fieldmap /*4FU*/ } },
{ VMT_ARRAY,
{ "array(?)", VMT_NULL, clone_array, del_array ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_ARRAY_INT,
{ "array(int)", VMT_ARRAY, clone_array, del_array ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_ARRAY_FLOAT,
{ "array(float)", VMT_ARRAY, clone_array, del_array ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_ARRAY_STRING,
{ "array(string)", VMT_ARRAY, clone_array, del_array ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
{ VMT_ARRAY_VMOBJECT,
{ "array(vmobject)", VMT_ARRAY, clone_array, del_array ,
setfield_error, getfield_error, null_fieldmap /*4FU*/ } },
// false entry
{ VMT_NULL,
{ NULL, VMT_NULL, NULL, NULL ,
NULL, NULL, null_fieldmap /*4FU*/ } },
};
void init_vm_type_table()
{
int i;
for ( i=0; i <= VMT_MAX_TYPE; i++ )
vmtype_table[i].name = NULL;
for ( i =0; vmtype_table_proto[i].data.name ; i++)
{
vmtype_table[vmtype_table_proto[i].type] = vmtype_table_proto[i].data;
}
}
int vmtype_lookup( const char * name)
{
int i;
for ( i=0; i < VMT_MAX_TYPE; i++ )
{
if ( !vmtype_table[i].name)
continue;
if ( !strcmp(vmtype_table[i].name, name) )
return i;
}
return -1;
}
int fieldname_lookup( vmtype type, const char * name )
{
int i;
fieldmap * fm;
while( true )
{
fm = vmtype_table[type].fieldnames;
if ( fm->name == NULL )
return -1;
for ( i=0; fm[i].name != NULL; i++ )
{
if ( !strcmp( fm[i].name, name ) )
return fm[i].id;
}
type = vmtype_table[type].parent;
}
}