Пример #1
0
void World::Init(SpacePartition* pSpacePartition)
{
	Profile("World Init");

	mSpacePartition = pSpacePartition;

    if( SoundSubsystem::Instance() )
    {
    	SoundSubsystem::Instance()->SetSFXMasterVolume( 0 );
    }

    // Inserts a camera.
    SpawnEntity( Camera::StaticClass() );
    SetCurrentCamera(0);

    SpawnEntity( SkyDome::StaticClass() );
    //SpawnEntity( Terrain::StaticClass() );

    //SpawnEntity( Class::GetClassByName("TestTexture2D"),     Vector3f(-20, 20,-30) );
    //SpawnEntity( Class::GetClassByName("TestCubemap"),       Vector3f( 0,  20,-30) );
    //SpawnEntity( Class::GetClassByName("TestRenderTexture"), Vector3f( 20, 20,-30) );
    //SpawnEntity( Class::GetClassByName("TestShaderProgram"),   Vector3f(  0,  0, -50) );
    //SpawnEntity( Class::GetClassByName("TestUI"),            Vector3f(  0,  0,  0) );

    //SpawnEntity( Level::StaticClass() );

    //SpawnEntity( Class::GetClassByName("ODETestObject"), Vector3f(-20,10,-20) );
	
    if( SoundSubsystem::Instance() )
    {
    	SoundSubsystem::Instance()->SetSFXMasterVolume( 255 );
    }

    mWorldInitialized = true;
}
Пример #2
0
void GameLogic::Initialize()
{
  double angInc = 360.0/1000.0;
  //SpawnEntity(EntityID::ParticleManager, 400, 300);
  SpawnEntity(EntityID::ParticleSystem, 400, 300);
  SpawnEntity(EntityID::Icecream, 0, 0);
  //ENTLIST->AddEntity(new PerlinNoise(40));
  for (int i =0; i < 1000; ++i)
  {
    //SpawnEntity(EntityID::ParticleGroup, 400+std::cos(angle)*150, std::sin(angle)*150+250);
    angle += angInc;
  }
  angle = 0;
};
///////////////////
// Process the car
void Car_ProcessCar(carsim_t *psCar, CModel *pcTrack, CCar *pcCar, CCamera *pcCam, double dt, bool bPaused)
{
	double fixed = 0.025f;
	double t=0;

    double time = (double)SDL_GetTicks() * 0.001;

    // Fixed time-step physics simulation
    while(psCar->dTime < time) {

        dt = time - psCar->dTime;
        if(dt > fixed)
            dt = fixed;

        // Don't simulate cars when paused (only the camera)
        if(!bPaused)
		    Car_SimulateCar(psCar, pcTrack, dt);

		Car_SetupCamera(psCar, pcCam, dt);
        
        psCar->dTime += dt;
    }
    psCar->dTime = time;

   
    if(!bPaused)
        Car_CheckCollisions(psCar, pcCar, pcTrack);

    // Do some sparks
    if( psCar->bCollision ) {
        for(int i=0;i<5;i++)
            SpawnEntity(ent_spark, 0, psCar->cColPoint, CVec(GetRandomNum()*15,GetRandomNum()*15,GetRandomNum()*15), 2);
    }

}
//------------------------------------------------------------------------
bool CVehicleActionEntityAttachment::Init(IVehicle *pVehicle, const CVehicleParams &table)
{
	m_pVehicle = pVehicle;

	CVehicleParams entityAttachmentTable = table.findChild("EntityAttachment");

	if(!entityAttachmentTable)
		return false;

	if(entityAttachmentTable.haveAttr("helper"))
		m_pHelper = m_pVehicle->GetHelper(entityAttachmentTable.getAttr("helper"));

	if(entityAttachmentTable.haveAttr("class"))
	{
		IEntityClassRegistry *pClassRegistry = gEnv->pEntitySystem->GetClassRegistry();
		assert(pClassRegistry);

		m_entityClassName = entityAttachmentTable.getAttr("class");

		if(IEntityClass *pEntityClass = pClassRegistry->FindClass(m_entityClassName.c_str()))
		{
			SpawnEntity();
			return true;
		}
	}

	return false;
}
//------------------------------------------------------------------------
bool CVehicleActionEntityAttachment::Init(IVehicle* pVehicle, const SmartScriptTable &table)
{
	m_pVehicle = pVehicle;

	SmartScriptTable entityAttachmentTable;
	if (!table->GetValue("EntityAttachment", entityAttachmentTable))
		return false;

	char* pHelperName;
	if (entityAttachmentTable->GetValue("helper", pHelperName))
		m_pHelper = m_pVehicle->GetHelper(pHelperName);

	char* pEntityClassName;
	if (entityAttachmentTable->GetValue("class", pEntityClassName))
	{
		IEntityClassRegistry* pClassRegistry = gEnv->pEntitySystem->GetClassRegistry();
		assert(pClassRegistry);

		if (IEntityClass* pEntityClass = pClassRegistry->FindClass(pEntityClassName))
		{
			m_entityClassName = pEntityClassName;

			SpawnEntity();

			return true;
		}
	}

	return false;
}
Пример #6
0
//-----------------------------------------------------------------------------
// Purpose: Spawn an instance of the entity
//-----------------------------------------------------------------------------
void CEnvEntityMaker::SpawnEntityAtEntityOriginFromScript( HSCRIPT hEntity )
{
	CBaseEntity *pTargetEntity = ToEnt( hEntity );
	if ( pTargetEntity )
	{
		SpawnEntity( pTargetEntity->GetAbsOrigin(), pTargetEntity->GetAbsAngles() );
	}
}
Пример #7
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CEnvEntityMaker::InputForceSpawnAtEntityOrigin( inputdata_t &inputdata )
{
	CBaseEntity *pTargetEntity = gEntList.FindEntityByName( NULL, inputdata.value.String(), this, inputdata.pActivator, inputdata.pCaller );
		
	if( pTargetEntity )
	{
		SpawnEntity( pTargetEntity->GetAbsOrigin(), pTargetEntity->GetAbsAngles() );
	}
}
Пример #8
0
//-----------------------------------------------------------------------------
// Purpose: Spawn an instance of the entity
//-----------------------------------------------------------------------------
void CEnvEntityMaker::SpawnEntityAtNamedEntityOriginFromScript( const char *pszName )
{
	CBaseEntity *pTargetEntity = gEntList.FindEntityByName( NULL, pszName, this, NULL, NULL );

	if( pTargetEntity )
	{
		SpawnEntity( pTargetEntity->GetAbsOrigin(), pTargetEntity->GetAbsAngles() );
	}
}
//-----------------------------------------------------------------------------
// Purpose: Check to see if we should spawn another instance
//-----------------------------------------------------------------------------
void CEnvEntityMaker::CheckSpawnThink( void )
{
	SetNextThink( gpGlobals->curtime + 0.5f );

	// Do we have an instance?
	if ( m_hCurrentInstance )
	{
		// If Wait-For-Destruction is set, abort immediately
		if ( m_spawnflags & SF_ENTMAKER_WAITFORDESTRUCTION )
			return;
	}

	// Do we have a blocker?
	if ( m_hCurrentBlocker )
	{
		// If it hasn't moved, abort immediately
		if ( m_vecBlockerOrigin == m_hCurrentBlocker->GetAbsOrigin() )
			return;
	}

	// Check to see if there's enough room to spawn
	trace_t tr;
	UTIL_TraceHull( GetAbsOrigin(), GetAbsOrigin(), m_vecEntityMins, m_vecEntityMaxs, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr );
	if ( tr.m_pEnt || tr.startsolid )
	{
		// Store off our blocker to check later
		m_hCurrentBlocker = tr.m_pEnt;
		if ( m_hCurrentBlocker )
		{
			m_vecBlockerOrigin = m_hCurrentBlocker->GetAbsOrigin();
		}
		return;
	}

	// We're clear, now check to see if the player's looking
	if ( !(m_spawnflags & SF_ENTMAKER_IGNOREFACING) )
	{
		for ( int i = 1; i <= gpGlobals->maxClients; i++ )
		{
			CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
			if ( pPlayer )
			{
				// Only spawn if the player's looking away from me
				Vector vLookDir = pPlayer->EyeDirection3D();
				Vector vTargetDir = GetAbsOrigin() - pPlayer->EyePosition();
				VectorNormalize(vTargetDir);

				float fDotPr = DotProduct(vLookDir,vTargetDir);
				if ( fDotPr > 0 )
					return;
			}
		}
	}

	// Clear, no player watching, so spawn!
	SpawnEntity();
}
Пример #10
0
uint8 CEntitiesFactory::Init(CWorld &world) {
	uint8 ret = 0;
	
	Init();

	m_world = &world;

	for (std::vector<SEntityParams *>::iterator itr = g_entitiesParams.begin();
	itr != g_entitiesParams.end(); ++itr) {
		CEntity * et = SpawnEntity(*itr);
		world.AddEntity(et);
	}

	return ret;
}
//------------------------------------------------------------------------
void CVehicleActionEntityAttachment::Reset()
{
	if(m_entityId)
	{
		IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
		assert(pEntitySystem);

		pEntitySystem->RemoveEntity(m_entityId);
	}

	SpawnEntity();

	if(m_timer > 0.0f)
		m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);

	m_timer = 0.0f;
}
Пример #12
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CEnvEntityMaker::Activate( void )
{
	BaseClass::Activate();

	// check for valid template
	if ( m_iszTemplate == NULL_STRING )
	{
		Warning( "env_entity_maker %s has no template entity!\n", GetEntityName().ToCStr() );
		UTIL_Remove( this );
		return;
	}

	// Spawn an instance
	if ( m_spawnflags & SF_ENTMAKER_AUTOSPAWN )
	{
		SpawnEntity();
	}
}
Пример #13
0
//-----------------------------------------------------------------------------
// Purpose: Spawns the entities, checking for space if flagged to do so.
//-----------------------------------------------------------------------------
void CEnvEntityMaker::InputForceSpawn( inputdata_t &inputdata )
{
	CPointTemplate *pTemplate = FindTemplate();
	if (!pTemplate)
		return;

	if ( HasSpawnFlags( SF_ENTMAKER_CHECK_FOR_SPACE ) && !HasRoomToSpawn() )
	{
		m_pOutputOnFailedSpawn.FireOutput( this, this );
		return;
	}

	if ( HasSpawnFlags( SF_ENTMAKER_CHECK_PLAYER_LOOKING ) && IsPlayerLooking() )
	{
		m_pOutputOnFailedSpawn.FireOutput( this, this );
		return;
	}

	SpawnEntity();
}
Пример #14
0
//-----------------------------------------------------------------------------
// Purpose: Check to see if we should spawn another instance
//-----------------------------------------------------------------------------
void CEnvEntityMaker::CheckSpawnThink( void )
{
	SetNextThink( gpGlobals->curtime + 0.5f );

	// Do we have an instance?
	if ( m_hCurrentInstance )
	{
		// If Wait-For-Destruction is set, abort immediately
		if ( m_spawnflags & SF_ENTMAKER_WAITFORDESTRUCTION )
			return;
	}

	// Check to see if there's enough room to spawn
	if ( !HasRoomToSpawn() )
		return;

	// We're clear, now check to see if the player's looking
	if ( !( HasSpawnFlags( SF_ENTMAKER_IGNOREFACING ) ) && IsPlayerLooking() )
		return;

	// Clear, no player watching, so spawn!
	SpawnEntity();
}
Пример #15
0
//-----------------------------------------------------------------------------
// Purpose: Spawn an instance of the entity
//-----------------------------------------------------------------------------
void CEnvEntityMaker::SpawnEntityAtLocationFromScript( const Vector &vecAlternateOrigin, const Vector &vecAlternateAngles )
{
	SpawnEntity( vecAlternateOrigin, *((QAngle *)&vecAlternateAngles) );
}
Пример #16
0
//-----------------------------------------------------------------------------
// Purpose: Spawn an instance of the entity
//-----------------------------------------------------------------------------
void CEnvEntityMaker::SpawnEntityFromScript()
{
	SpawnEntity();
}
Пример #17
0
bool Map::LoadFromFile(const std::string &file) {
	std::string path = GetPath() + "examples/" + file;

	SML global;
	global.ReadFile(path);

	height = global.GetFragment("global").GetValueAsInt("height");
	width = global.GetFragment("global").GetValueAsInt("width");
	spawnX = global.GetFragment("global").GetValueAsInt("spawnX");
	spawnY = global.GetFragment("global").GetValueAsInt("spawnY");

	structures = new Structure **[height];
	for (int i = 0; i < height; ++i) {
		structures[i] = new Structure *[width];
		for (int j = 0; j < width; ++j)
			structures[i][j] = NULL;
	}

	std::string map = global.GetFragment("global").GetValue("map");
	int mapSize = map.size();

	for (int i = 0; i < height; ++i) {
		for (int j = 0; j < width; j++) {
			if ((i * width) + j >= mapSize) {
				std::cout << i << " * " << width << " + " << j << " - " << mapSize << std::endl;
			}

			char c = map[(i * width) + j];
			switch (c) {
			case 'X':
				structures[i][j] = new Wall(this, j, i);
				break;
			case '-':
				structures[i][j] = new Door(this, j, i);
				break;
			}
		}
	}

	global.ForEach([this](const std::string &key, const SML_Fragment &fragment) {
		if (fragment.GetValue("type") == "portal") {
			int posX = fragment.GetValueAsInt("posX");
			int posY = fragment.GetValueAsInt("posY");
			std::string lvl = fragment.GetValue("level");

			SpawnEntity(new Portal(posX, posY, lvl));
		} else if (fragment.GetValue("type") == "doorSwitch") {
			int posX = fragment.GetValueAsInt("posX");
			int posY = fragment.GetValueAsInt("posY");
			int xFrom = fragment.GetValueAsInt("xFrom");
			int xTo = fragment.GetValueAsInt("xTo");
			int yFrom = fragment.GetValueAsInt("yFrom");
			int yTo = fragment.GetValueAsInt("yTo");

			SpawnEntity(new DoorSwitch(posX, posY, xFrom, xTo, yFrom, yTo));
		} else if (fragment.GetValue("type") == "enemy") {
			int posX = fragment.GetValueAsInt("posX");
			int posY = fragment.GetValueAsInt("posY");
			std::string eType = fragment.GetValue("eType");
			int hp = fragment.GetValueAsInt("hp");
			int dmg = fragment.GetValueAsInt("damage");
			int ch = fragment.GetValueAsChar("char");
			short color = fragment.GetColor("color");
			int movSpeed = fragment.GetValueAsInt("movSpeed");
			int attSpeed = fragment.GetValueAsInt("attSpeed");

			SpawnEntity(new Enemy(posX, posY, eType, hp, dmg, ch, color, movSpeed, attSpeed));
		} else if (fragment.GetValue("type") == "NPC") {
			int posX = fragment.GetValueAsInt("posX");
			int posY = fragment.GetValueAsInt("posY");
			std::string text = fragment.GetValue("text");
			std::string questID = fragment.GetValue("questID");
			int ch = fragment.GetValueAsChar("char");
			short color = fragment.GetColor("color");

			SpawnEntity(new NPC(posX, posY, ch, color, text, questID));
		} else if (fragment.GetValue("type") == "quest") {
			std::string ID = fragment.GetValue("ID");
			std::string text = fragment.GetValue("text");
			std::string objective = fragment.GetValue("object");
			int times = fragment.GetValueAsInt("times");
			short type = fragment.GetValueAsInt("qType");

			quests.push_back(new Quest(ID, text, objective, type, times));
		} else if (fragment.GetValue("type") == "item") {
			int posX = fragment.GetValueAsInt("posX");
			int posY = fragment.GetValueAsInt("posY");
			int movSpeed = fragment.GetValueAsInt("movSpeed");
			int armor = fragment.GetValueAsInt("armor");
			int damage = fragment.GetValueAsInt("damage");
			char ch = fragment.GetValueAsChar("char");
			short color = fragment.GetColor("color");

			SpawnEntity(new ItemGiver(posX, posY, movSpeed, armor, damage, ch, color));
		}
	});

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &inputdata - 
//-----------------------------------------------------------------------------
void CEnvEntityMaker::InputForceSpawn( inputdata_t &inputdata )
{
	SpawnEntity();
}