Exemplo n.º 1
0
// creates a new particletype from the given file
// NB: this changes the value of szFile.
ParticleType *ParticleSystem::ParseType( char *&szFile )
{
	ParticleType *pType = new ParticleType();

	// parse the .aur file
	char szToken[1024];

	szFile = gEngfuncs.COM_ParseFile(szFile, szToken);
	while ( stricmp( szToken, "}" ) )
	{
		if (!szFile)
			break;

		if ( !stricmp( szToken, "name" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			strncpy(pType->m_szName, szToken, sizeof(pType->m_szName) );

			ParticleType *pTemp = GetType(szToken);
			if (pTemp)
			{
				// there's already a type with this name
				if (pTemp->m_bIsDefined)
					gEngfuncs.Con_Printf("Warning: Particle type %s is defined more than once!\n", szToken);

				// copy all our data into the existing type, throw away the type we were making
				*pTemp = *pType;
				delete pType;
				pType = pTemp;
				pType->m_bIsDefined = true; // record the fact that it's defined, so we won't need to add it to the list
			}
		}
		else if ( !stricmp( szToken, "gravity" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_Gravity = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "windyaw" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_WindYaw = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "windstrength" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_WindStrength = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "sprite" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_hSprite = SPR_Load( szToken );
		}
		else if ( !stricmp( szToken, "startalpha" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_StartAlpha = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "endalpha" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_EndAlpha = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "startred" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_StartRed = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "endred" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_EndRed = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "startgreen" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_StartGreen = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "endgreen" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_EndGreen = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "startblue" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_StartBlue = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "endblue" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_EndBlue = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "startsize" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_StartSize = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "sizedelta" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_SizeDelta = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "endsize" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_EndSize = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "startangle" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_StartAngle = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "angledelta" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_AngleDelta = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "startframe" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_StartFrame = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "endframe" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_EndFrame = RandomRange( szToken );
			pType->m_bEndFrame = true;
		}
		else if ( !stricmp( szToken, "framerate" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_FrameRate = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "lifetime" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_Life = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "spraytype" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			ParticleType *pTemp = GetType(szToken);

			if (pTemp) pType->m_pSprayType = pTemp;
			else pType->m_pSprayType = AddPlaceholderType(szToken);
		}
		else if ( !stricmp( szToken, "overlaytype" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			ParticleType *pTemp = GetType(szToken);

			if (pTemp) pType->m_pOverlayType = pTemp;
			else pType->m_pOverlayType = AddPlaceholderType(szToken);
		}
		else if ( !stricmp( szToken, "sprayrate" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_SprayRate = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "sprayforce" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_SprayForce = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "spraypitch" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_SprayPitch = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "sprayyaw" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_SprayYaw = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "drag" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_Drag = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "bounce" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_Bounce = RandomRange( szToken );
			if (pType->m_Bounce.m_fMin != 0 || pType->m_Bounce.m_fMax != 0)
				pType->m_bBouncing = true;
		}
		else if ( !stricmp( szToken, "bouncefriction" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			pType->m_BounceFriction = RandomRange( szToken );
		}
		else if ( !stricmp( szToken, "rendermode" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			if ( !stricmp( szToken, "additive" ) )
			{
				pType->m_iRenderMode = kRenderTransAdd;
			}
			else if ( !stricmp( szToken, "solid" ) )
			{
				pType->m_iRenderMode = kRenderTransAlpha;
			}
			else if ( !stricmp( szToken, "texture" ) )
			{
				pType->m_iRenderMode = kRenderTransTexture;
			}
			else if ( !stricmp( szToken, "color" ) )
			{
				pType->m_iRenderMode = kRenderTransColor;
			}
		}
		else if ( !stricmp( szToken, "drawcondition" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			if ( !stricmp( szToken, "empty" ) )
			{
				pType->m_iDrawCond = CONTENTS_EMPTY;
			}
			else if ( !stricmp( szToken, "water" ) )
			{
				pType->m_iDrawCond = CONTENTS_WATER;
			}
			else if ( !stricmp( szToken, "solid" ) )
			{
				pType->m_iDrawCond = CONTENTS_SOLID;
			}
			else if ( !stricmp( szToken, "special" ) || !stricmp( szToken, "special1" ) )
			{
				pType->m_iDrawCond = CONTENT_SPECIAL1;
			}
			else if ( !stricmp( szToken, "special2" ) )
			{
				pType->m_iDrawCond = CONTENT_SPECIAL2;
			}
			else if ( !stricmp( szToken, "special3" ) )
			{
				pType->m_iDrawCond = CONTENT_SPECIAL3;
			}
		}
		else if ( !stricmp( szToken, "collision" ) )
		{
			szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
			if ( !stricmp( szToken, "none" ) )
			{
				pType->m_iCollision = COLLISION_NONE;
			}
			else if ( !stricmp( szToken, "die" ) )
			{
				pType->m_iCollision = COLLISION_DIE;
			}
			else if ( !stricmp( szToken, "bounce" ) )
			{
				pType->m_iCollision = COLLISION_BOUNCE;
			}
		}
		// get the next token
		szFile = gEngfuncs.COM_ParseFile(szFile, szToken);
	}

	if (!pType->m_bIsDefined)
	{
		// if this is a newly-defined type, we need to add it to the list
		pType->m_pNext = m_pFirstType;
		m_pFirstType = pType;
		pType->m_bIsDefined = true;
	}

	return pType;
}
Exemplo n.º 2
0
ParticleSystem::ParticleSystem( int iEntIndex, char *szFilename )
{
	int iParticles = 100; // default

	m_iEntIndex = iEntIndex;
	m_pNextSystem = NULL;
	m_pFirstType = NULL;

	if ( !c_bCosTableInit )
	{
		for ( int i = 0; i < 360 + 90; i++ )
		{
			c_fCosTable[i] = cos( i * M_PI / 180.0 );
		}
		c_bCosTableInit = true;
	}

	const char *memFile;
	const char *szFile = (char *)LOAD_FILE( szFilename, NULL );
	char *szToken;

	if( !szFile )
	{
		ALERT( at_error, "particle %s not found.\n", szFilename );
		return;
	}
	else
	{
		memFile = szFile;		
		szToken = COM_ParseToken( &szFile );

		while ( szToken )
		{
			if ( !stricmp( szToken, "particles" ) )
			{
				szToken = COM_ParseToken( &szFile );
				iParticles = atof(szToken);
			}
			else if ( !stricmp( szToken, "maintype" ) )
			{
				szToken = COM_ParseToken( &szFile );
				m_pMainType = AddPlaceholderType(szToken);
			}
			else if ( !stricmp( szToken, "attachment" ) )
			{
				szToken = COM_ParseToken( &szFile );
				m_iEntAttachment = atof(szToken);
			}
			else if ( !stricmp( szToken, "killcondition" ) )
			{
				szToken = COM_ParseToken( &szFile );
				if ( !stricmp( szToken, "empty" ) )
				{
					m_iKillCondition = CONTENTS_EMPTY;
				}
				else if ( !stricmp( szToken, "water" ) )
				{
					m_iKillCondition = CONTENTS_WATER;
				}
				else if ( !stricmp( szToken, "solid" ) )
				{
					m_iKillCondition = CONTENTS_SOLID;
				}
			}
			else if ( !stricmp( szToken, "{" ) )
			{
				// parse new type
				this->ParseType( &szFile ); // parses the type, moves the file pointer
			}

			szToken = COM_ParseToken( &szFile );
		}
	}
		
	FREE_FILE( (void *)memFile );
	AllocateParticles( iParticles );
}
Exemplo n.º 3
0
ParticleSystem::ParticleSystem( int iEntIndex, char *szFilename )
{
	int iParticles = 100; // default

	m_iEntIndex = iEntIndex;
	m_iEntAttachment = 0;
	
	m_pNextSystem = NULL;
	m_pFirstType = NULL;
	if (!c_bCosTableInit)
	{
		for (int i = 0; i < 360+90; i++)
		{
			c_fCosTable[i] = cos(i*M_PI/180.0);
		}
		c_bCosTableInit = true;
	}
          
//          gEngfuncs.Con_Printf("ParticleSystem: idx %d\n", m_iEntIndex );
	
	char *szFile = (char *)gEngfuncs.COM_LoadFile( szFilename, 5, NULL);
	char szToken[1024];

	if (!szFile)
	{
		gEngfuncs.Con_Printf("Particle %s not found.\n", szFilename );
		return;
	}
	else
	{
		szFile = gEngfuncs.COM_ParseFile(szFile, szToken);

		while (szFile)
		{
			if ( !stricmp( szToken, "particles" ) )
			{
				szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
				iParticles = atof(szToken);
			}
			else if ( !stricmp( szToken, "maintype" ) )
			{
				szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
				m_pMainType = AddPlaceholderType(szToken);
			}
			else if ( !stricmp( szToken, "attachment" ) )
			{
				szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
				m_iEntAttachment = atoi(szToken);
//				gEngfuncs.Con_Printf("m_iEntAttachment %d\n", m_iEntAttachment );
			}
			else if ( !stricmp( szToken, "killcondition" ) )
			{
				szFile = gEngfuncs.COM_ParseFile(szFile,szToken);
				if ( !stricmp( szToken, "empty" ) )
				{
					m_iKillCondition = CONTENTS_EMPTY;
				}
				else if ( !stricmp( szToken, "water" ) )
				{
					m_iKillCondition = CONTENTS_WATER;
				}
				else if ( !stricmp( szToken, "solid" ) )
				{
					m_iKillCondition = CONTENTS_SOLID;
				}
			}
			else if ( !stricmp( szToken, "{" ) )
			{
				// parse new type
				this->ParseType( szFile ); // parses the type, moves the file pointer
			}

			szFile = gEngfuncs.COM_ParseFile(szFile, szToken);
		}
	}
		
	gEngfuncs.COM_FreeFile( szFile );
	AllocateParticles(iParticles);
}
Exemplo n.º 4
0
//============================================
CParticleSystem :: CParticleSystem( cl_entity_t *ent, const char *szFilename, int attachment, float lifetime )
{
	int iParticles = 100; // default
	m_iKillCondition = CONTENTS_NONE;
	m_iEntAttachment = attachment;
	m_pActiveParticle = NULL;
	m_pMainParticle = NULL;
	m_fLifeTime = lifetime;
	m_pNextSystem = NULL;
	m_iLightingModel = 0;
	m_pFirstType = NULL;
	m_pEntity = ent;
	enable = true;

	entityMatrix.Identity();

	if( !c_bCosTableInit )
	{
		for( int i = 0; i < 360 + 90; i++ )
			c_fCosTable[i] = cos( i * M_PI / 180.0f );
		c_bCosTableInit = true;
	}

	char *afile = (char *)gEngfuncs.COM_LoadFile( (char *)szFilename, 5, NULL );
	char szToken[1024];
	char *pfile = afile;

	if( !pfile )
	{
		ALERT( at_error, "couldn't load %s.\n", szFilename );
		return;
	}
	else
	{
		pfile = COM_ParseFile( pfile, szToken );

		while( pfile )
		{
			if( !Q_stricmp( szToken, "particles" ))
			{
				pfile = COM_ParseFile( pfile, szToken );
				iParticles = Q_atoi( szToken );
			}
			else if( !Q_stricmp( szToken, "maintype" ))
			{
				pfile = COM_ParseFile( pfile, szToken );
				m_pMainType = AddPlaceholderType( szToken );
			}
			else if( !Q_stricmp( szToken, "attachment" ))
			{
				pfile = COM_ParseFile( pfile, szToken );
				m_iEntAttachment = Q_atoi( szToken );
			}
			else if( !Q_stricmp( szToken, "lightmodel" ))
			{
				pfile = COM_ParseFile( pfile, szToken );
				m_iLightingModel = Q_atoi( szToken );
			}
			else if( !Q_stricmp( szToken, "killcondition" ))
			{
				pfile = COM_ParseFile( pfile, szToken );

				if( !Q_stricmp( szToken, "empty" ))
				{
					m_iKillCondition = CONTENTS_EMPTY;
				}
				else if( !Q_stricmp( szToken, "water" ))
				{
					m_iKillCondition = CONTENTS_WATER;
				}
				else if( !Q_stricmp( szToken, "solid" ))
				{
					m_iKillCondition = CONTENTS_SOLID;
				}
			}
			else if( !Q_stricmp( szToken, "{" ))
			{
				// parse new type
				this->ParseType( pfile );
			}

			pfile = COM_ParseFile( pfile, szToken );
		}
	}
		
	gEngfuncs.COM_FreeFile( afile );
	AllocateParticles( iParticles );
}