MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / SetType

Method SetType

neo/d3xp/script/Script_Program.cpp:957–989  ·  view source on GitHub ↗

============ idScriptObject::SetType Allocates an object and initializes memory. ============ */

Source from the content-addressed store, hash-verified

955============
956*/
957bool idScriptObject::SetType( const char *typeName ) {
958 size_t size;
959 idTypeDef *newtype;
960
961 // lookup the type
962 newtype = gameLocal.program.FindType( typeName );
963
964 // only allocate memory if the object type changes
965 if ( newtype != type ) {
966 Free();
967 if ( !newtype ) {
968 gameLocal.Warning( "idScriptObject::SetType: Unknown type '%s'", typeName );
969 return false;
970 }
971
972 if ( !newtype->Inherits( &type_object ) ) {
973 gameLocal.Warning( "idScriptObject::SetType: Can't create object of type '%s'. Must be an object type.", newtype->Name() );
974 return false;
975 }
976
977 // set the type
978 type = newtype;
979
980 // allocate the memory
981 size = type->Size();
982 data = ( byte * )Mem_Alloc( size );
983 }
984
985 // init object memory
986 ClearObject();
987
988 return true;
989}
990
991/*
992============

Callers 3

FinishSetupMethod · 0.45
GetWeaponDefMethod · 0.45
SpawnMethod · 0.45

Calls 6

Mem_AllocFunction · 0.85
FindTypeMethod · 0.45
WarningMethod · 0.45
InheritsMethod · 0.45
NameMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected