HoldableItem *HoldableItem::createHoldableItem( const str &className, const str &modelName, Sentient *sentient ) { str fullname; SpawnArgs args; ClassDef *cls; HoldableItem *holdableItem; fullname = "HoldableItem"; fullname += className; args.setArg( "classname", fullname.c_str() ); cls = args.getClassDef(); if ( !cls ) return NULL; if ( !checkInheritance( &HoldableItem::ClassInfo, cls ) ) return NULL; holdableItem = (HoldableItem *)cls->newInstance(); if ( !holdableItem ) return NULL; holdableItem->init( modelName, sentient ); return holdableItem; }
Rune *Rune::CreateRune( const str &className, const str &modelName, Sentient *sentient ) { str fullname; SpawnArgs args; ClassDef *cls; Rune *rune; fullname = "Rune"; fullname += className; args.setArg( "classname", fullname.c_str() ); cls = args.getClassDef(); if ( !cls ) return NULL; if ( !checkInheritance( &Rune::ClassInfo, cls ) ) return NULL; rune = (Rune *)cls->newInstance(); if ( !rune ) return NULL; rune->init( modelName, sentient ); return rune; }
Powerup *Powerup::CreatePowerup( const str &className, const str &modelName, Sentient *sentient ) { str fullname; SpawnArgs args; ClassDef *cls; Powerup *powerup; fullname = "Powerup"; fullname += className; args.setArg( "classname", fullname.c_str() ); cls = args.getClassDef(); if ( !cls ) return NULL; if ( !checkInheritance( &Powerup::ClassInfo, cls ) ) return NULL; powerup = (Powerup *)cls->newInstance(); if ( !powerup ) return NULL; powerup->init( modelName, sentient ); return powerup; }
void CL_ProcessCEntities() { // Iterate through client entities for( int i = s_entities.NumObjects(); i > 0; i-- ) { Entity *ent = s_entities.ObjectAt( i ); if( !checkInheritance( &Entity::ClassInfo, ent->classinfo() ) ) { continue; } if( ent->CanThink() ) { ent->Think(); } } }
Entity * CL_GetCEntity( int ent_num ) { // Iterate through simple client entities for( int i = 0; i < s_entities.NumObjects(); i++ ) { Entity * ent = ( Entity * )s_entities[ i ]; if( !checkInheritance( &Entity::ClassInfo, ent->classinfo() ) ) { continue; } int entnum = ent->GetNumber(); if( entnum != -1 && entnum == ent_num ) { return ent; } } return NULL; }
//==================== //Player::SpawnActor //==================== void Player::SpawnActor ( Event *ev ) { Entity *ent; str name; str text; Vector forward; Vector up; Vector delta; Vector v; int n; int i; ClassDef *cls; Event *e; if ( ev->NumArgs() < 1 ) { ScriptError( "Usage: actor [modelname] [keyname] [value]..." ); return; } name = ev->GetString( 1 ); if ( !name[ 0 ] ) { ScriptError( "Must specify a model name" ); return; } if ( !strstr( name.c_str(), ".tik" ) ) { name += ".tik"; } // create a new entity SpawnArgs args; args.setArg( "model", name.c_str() ); cls = args.getClassDef(); if ( cls == &Object::ClassInfo ) { cls = &Actor::ClassInfo; } if ( !cls || !checkInheritance( &Actor::ClassInfo, cls ) ) { ScriptError( "%s is not a valid Actor", name.c_str() ); return; } ent = ( Entity * )cls->newInstance(); e = new Event( EV_Model ); e->AddString( name.c_str() ); ent->PostEvent( e, EV_SPAWNARG ); angles.AngleVectors( &forward, NULL, &up ); v = origin + ( forward + up ) * 40; e = new Event( EV_SetOrigin ); e->AddVector( v ); ent->PostEvent( e, EV_SPAWNARG ); delta = origin - v; v = delta.toAngles(); e = new Event( EV_SetAngle ); e->AddFloat( v[ 1 ] ); ent->PostEvent( e, EV_SPAWNARG ); if ( ev->NumArgs() > 2 ) { n = ev->NumArgs(); for( i = 2; i <= n; i += 2 ) { e = new Event( ev->GetString( i ) ); e->AddToken( ev->GetString( i + 1 ) ); ent->PostEvent( e, EV_SPAWNARG ); } } }
//==================== //Player::SpawnEntity //==================== void Player::SpawnEntity ( Event *ev ) { Entity *ent; str name; ClassDef *cls; str text; Vector forward; Vector up; Vector delta; Vector v; int n; int i; Event *e; if ( ev->NumArgs() < 1 ) { ScriptError( "Usage: spawn entityname [keyname] [value]..." ); return; } name = ev->GetString( 1 ); if ( !name.length() ) { ScriptError( "Must specify an entity name" ); return; } // create a new entity SpawnArgs args; args.setArg( "classname", name.c_str() ); args.setArg( "model", name.c_str() ); cls = args.getClassDef(); if ( !cls ) { cls = &Entity::ClassInfo; } if ( !checkInheritance( &Entity::ClassInfo, cls ) ) { ScriptError( "%s is not a valid Entity", name.c_str() ); return; } ent = ( Entity * )cls->newInstance(); e = new Event( EV_Model ); e->AddString( name.c_str() ); ent->PostEvent( e, EV_PRIORITY_SPAWNARG ); angles.AngleVectors( &forward, NULL, &up ); v = origin + ( forward + up ) * 40; e = new Event( EV_SetOrigin ); e->AddVector( v ); ent->PostEvent( e, EV_SPAWNARG ); delta = origin - v; v.x = 0; v.y = delta.toYaw(); v.z = 0; e = new Event( EV_SetAngles ); e->AddVector( v ); ent->PostEvent( e, EV_SPAWNARG ); if ( ev->NumArgs() > 2 ) { n = ev->NumArgs(); for( i = 2; i <= n; i += 2 ) { e = new Event( ev->GetString( i ) ); e->AddToken( ev->GetString( i + 1 ) ); ent->PostEvent( e, EV_SPAWNARG ); } } e = new Event( EV_SetAnim ); e->AddString( "idle" ); ent->PostEvent( e, EV_SPAWNARG ); }