void Powerup::spawn( const Vector &origin ) { SpawnArgs args; Entity *ent; Item *item; if ( _timeLeft <= 0.0f ) return; args.setArg( "model", _modelName ); ent = args.Spawn(); if ( !ent || !ent->isSubclassOf( Item ) ) return; item = (Item *)ent; item->setOrigin( origin ); item->ProcessPendingEvents(); item->PlaceItem(); item->setOrigin( origin ); //item->velocity = Vector( G_CRandom( 100.0f ), G_CRandom( 100.0f ), 200.0f + G_Random( 200.0f ) ); item->edict->clipmask = CONTENTS_SOLID | CONTENTS_PLAYERCLIP; item->_nextPickupTime = level.time + 1.0f; item->setAmount( (int)( _timeLeft + 1.0f ) ); item->setRespawn( false ); }
void Rune::spawn( const Vector &origin ) { SpawnArgs args; Entity *ent; Item *item; args.setArg( "model", _modelName ); ent = args.Spawn(); if ( !ent || !ent->isSubclassOf( Item ) ) return; item = (Item *)ent; item->setOrigin( origin ); item->ProcessPendingEvents(); item->PlaceItem(); item->setOrigin( origin ); //item->velocity = Vector( G_CRandom( 100.0f ), G_CRandom( 100.0f ), 200.0f + G_Random( 200.0f ) ); item->edict->clipmask = CONTENTS_SOLID | CONTENTS_PLAYERCLIP; item->_nextPickupTime = level.time + 1.0f; item->animate->RandomAnimate( "idle" ); if ( item->isSubclassOf( Rune ) ) { Rune *rune = (Rune *)item; rune->setOriginalOrigin( getOriginalOrigin(), true ); rune->PostEvent( EV_Rune_Respawn, 60.0f ); } }
bool HoldableItemSpawnPowerup::use( void ) { SpawnArgs args; Entity *ent; Item *item; if ( _powerupToSpawn.length() == 0 ) return true; if ( _owner ) { args.setArg( "model", _powerupToSpawn ); ent = args.Spawn(); if ( !ent || !ent->isSubclassOf( Item ) ) return true; item = (Item *)ent; item->setOrigin( _owner->centroid ); item->ProcessPendingEvents(); item->PlaceItem(); item->setOrigin( _owner->centroid ); if ( _owner->isSubclassOf( Player ) ) { Vector viewAngles; Vector viewDir; Player *player = (Player *)_owner; Vector pos; player->GetPlayerView( &pos, &viewAngles ); //viewAngles = player->GetVAngles(); viewAngles.AngleVectors( &viewDir ); viewDir.normalize(); viewDir *= 500.0f; item->velocity = viewDir; item->setOrigin( pos ); } else { item->velocity = Vector( G_CRandom( 100.0f ), G_CRandom( 100.0f ), 200.0f + G_Random( 200.0f ) ); } item->edict->clipmask = CONTENTS_SOLID | CONTENTS_PLAYERCLIP; item->_nextPickupTime = level.time + 1.0f; item->setRespawn( false ); // Powerup is only gets half time item->setAmount( item->getAmount() / 2.0f ); // Get rid of the spawned powerup in 10 seconds item->PostEvent( EV_Remove, 10.0f ); return true; } return false; }
/* ============== SpawnEntities Creates a server's entity / program execution context by parsing textual entity definitions out of an ent file. ============== */ void Level::SpawnEntities( const char *themapname, const char *entities, int levelTime ) { int inhibit,count=0; const char *value; SpawnArgs args; char *spawnpos; // Init the level variables Init(); spawnpos = const_cast<char*>(strchr( themapname, '$' )); if ( spawnpos ) { mapname = str( themapname, 0, spawnpos - themapname ); spawnpoint = spawnpos + 1; } else { mapname = themapname; spawnpoint = ""; } // set up time so functions still have valid times setTime( levelTime, 1000 / 20 ); if ( !LoadingServer ) { // Get rid of anything left over from the last level //CleanUp( false ); // Set up for a new map thePathManager.Init( mapname ); } setSkill( skill->integer ); // reset out count of the number of game traces sv_numtraces = 0; // parse world entities = args.Parse( entities ); spawn_entnum = ENTITYNUM_WORLD; args.Spawn(); if ( !world ) Com_Error( ERR_FATAL, "No world\n" ); if ( g_gametype->integer == GT_MULTIPLAYER || g_gametype->integer == GT_BOT_SINGLE_PLAYER ) { multiplayerManager.initMultiplayerGame(); } // parse ents inhibit = 0; for( entities = args.Parse( entities ); entities != NULL; entities = args.Parse( entities ) ) { // remove things (except the world) from different skill levels or deathmatch spawnflags = 0; value = args.getArg( "spawnflags" ); if ( value ) { spawnflags = atoi( value ); if ( inhibitEntity( spawnflags ) ) { inhibit++; continue; } } args.Spawn(); count++; gi.ProcessLoadingScreen( "$$SpawningEntities$$" ); } gi.DPrintf( "%i entities spawned\n", count ); gi.DPrintf( "%i entities inhibited\n", inhibit ); // Process the spawn events L_ProcessPendingEvents(); if ( multiplayerManager.inMultiplayer() ) { multiplayerManager.initItems(); } // Setup bots if ( gi.Cvar_VariableIntegerValue( "bot_enable" ) && multiplayerManager.inMultiplayer() ) { BotAIShutdown( 0 ); BotAISetup( 0 ); BotAILoadMap( 0 ); G_InitBots( 0 ); } if ( !LoadingServer || game.autosaved ) { Start(); } postLoad(); //------------------------------------------------------------------------------- // // Deletion Note: // Since hNodeController is an Entity, it is deleted // when all the other entities are deleted in the clean up function // specifically the line // // // if ( active_edicts.next->entity ) // { // delete active_edicts.next->entity; // } // // // Since it is already being deleted like this // We do not need to explcitily delete the controller... In fact // you will error out if you try to. //-------------------------------------------------------------------------------- hNodeController = new HelperNodeController; if ( hNodeController ) hNodeController->SetTargetName( "HelperNodeController" ); // // if this is a single player game, spawn the single player in now // this allows us to read persistant data into the player before the client // is completely ready // if ( game.maxclients == 1 ) { spawn_entnum = 0; new Player; } }