============ idScriptObject::SetType Allocates an object and initializes memory. ============ */
| 955 | ============ |
| 956 | */ |
| 957 | bool 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 | ============ |