halflife-thewastes-sdk/cl_dll/ParseBspEnt.cpp

234 lines
4.8 KiB
C++

/***
*
* Copyright (C) 2002 The Wastes Project, All Rights Reserved.
*
* This product contains software technology from Valve Software, LLC,
* Copyright © 1996-2001, Valve LLC, All rights reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* The Wastes Project. All other use, distribution, or modification is prohibited
* without written permission from The Wastes Project.
*
***/
#include "extdll.h"
#include "entity_state.h"
#include "pm_defs.h"
#include "pm_movevars.h"
#include "hud_iface.h"
#include "com_model.h"
#include "event_api.h"
#include "com_weapons.h"
#include "event_flags.h"
#include "dmc_bspfile.h"
#include "cl_util.h"
#include "ParseBspEnt.h"
#include "ParticleBase.h"
#include <vector>
using namespace std;
CBspWorldspawn g_Worldspawn;
extern vector<CBspEnvFog> g_EnvFogList;
//
// CBspEntity
//
CBspEntity::CBspEntity()
{
ResetVars();
}
void CBspEntity::ResetVars()
{
memset(szClassname,0,sizeof(szClassname));
memset(flOrigin,0,sizeof(flOrigin));
}
void CBspEntity::SetKeyValue( const char *pszKey, const char *pszValue )
{
float x,y,z;
if( stricmp( pszKey, "classname" ) == 0 )
{
strcpy( szClassname, pszValue );
}
else if( stricmp( pszKey, "origin" ) == 0 )
{
if( sscanf( pszValue, "%f %f %f", &x, &y, &z ) == 3 )
{
flOrigin[0] = x;
flOrigin[1] = y;
flOrigin[2] = z;
}
}
}
//
// CBspWorldspawn
//
void CBspWorldspawn::AddEntity()
{
g_Worldspawn.flFogcolor_b = this->flFogcolor_b;
g_Worldspawn.flFogcolor_end = this->flFogcolor_end;
g_Worldspawn.flFogcolor_g = this->flFogcolor_g;
g_Worldspawn.flFogcolor_r = this->flFogcolor_r;
g_Worldspawn.flFogcolor_start = this->flFogcolor_start;
memcpy( g_Worldspawn.flOrigin, this->flOrigin, sizeof( flOrigin ) );
g_Worldspawn.iEnableFog = this->iEnableFog;
strcpy( g_Worldspawn.szClassname, this->szClassname );
}
void CBspWorldspawn::ResetVars()
{
CBspEntity::ResetVars();
iEnableFog = 0;
flFogcolor_r = 0.0f;
flFogcolor_g = 0.0f;
flFogcolor_b = 0.0f;
flFogcolor_start = 0.0f;
flFogcolor_end = 0.0f;
}
void CBspWorldspawn::SetKeyValue( const char *pszKey, const char *pszValue )
{
int i;
float x;
if(stricmp(pszKey,"enablefog") == 0)
{
if(sscanf(pszValue,"%i",&i) == 1)
iEnableFog = i;
}
else if(stricmp(pszKey,"fogcolor_r") == 0)
{
if(sscanf(pszValue,"%f",&x) == 1)
flFogcolor_r = x;
}
else if(stricmp(pszKey,"fogcolor_g") == 0)
{
if(sscanf(pszValue,"%f",&x) == 1)
flFogcolor_g = x;
}
else if(stricmp(pszKey,"fogcolor_b") == 0)
{
if(sscanf(pszValue,"%f",&x) == 1)
flFogcolor_b = x;
}
else if(stricmp(pszKey,"fogcolor_start") == 0)
{
if(sscanf(pszValue,"%f",&x) == 1)
flFogcolor_start = x;
}
else if(stricmp(pszKey,"fogcolor_end") == 0)
{
if(sscanf(pszValue,"%f",&x) == 1)
flFogcolor_end = x;
}
else
CBspEntity::SetKeyValue( pszKey, pszValue );
}
//
// CBspEnvFog
//
void CBspEnvFog::AddEntity()
{
g_EnvFogList.push_back( *this );
}
void CBspEnvFog::ResetVars()
{
CBspEntity::ResetVars();
iRadius = 0;
iFogState = 0;
flFogcolor_r = 0.0f;
flFogcolor_g = 0.0f;
flFogcolor_b = 0.0f;
flFog_start = 0.0f;
flFog_end = 0.0f;
}
void CBspEnvFog::SetKeyValue( const char *pszKey, const char *pszValue )
{
int i;
float x;
if( stricmp( pszKey, "radius" ) == 0 )
{
if( sscanf( pszValue, "%i", &i ) == 1 )
iRadius = i;
}
else if( stricmp( pszKey, "fogstate" ) == 0 )
{
if( sscanf( pszValue, "%i", &i ) == 1 )
iFogState = i;
}
else if( stricmp( pszKey, "fogcolor_r" ) == 0 )
{
if( sscanf( pszValue, "%f", &x ) == 1 )
flFogcolor_r = x;
}
else if( stricmp( pszKey, "fogcolor_g" ) == 0 )
{
if( sscanf( pszValue, "%f", &x ) == 1 )
flFogcolor_g = x;
}
else if( stricmp( pszKey, "fogcolor_b" ) == 0 )
{
if( sscanf( pszValue, "%f", &x ) == 1 )
flFogcolor_b = x;
}
else if( stricmp( pszKey, "fog_start" ) == 0 )
{
if( sscanf( pszValue, "%f", &x ) == 1 )
flFog_start = x;
}
else if( stricmp( pszKey, "fog_end" ) == 0 )
{
if( sscanf( pszValue, "%f", &x ) == 1 )
flFog_end = x;
}
else
CBspEntity::SetKeyValue( pszKey, pszValue );
}
//
// CBspEnvParticleSystem
//
void CBspEnvParticleSystem::AddEntity()
{
if( iClientSide )
{
g_ParticleSystemManager.AddParticleSystem( szParticleSystem, flOrigin );
}
}
void CBspEnvParticleSystem::ResetVars()
{
CBspEntity::ResetVars();
iClientSide = 0;
memset( szParticleSystem, 0, sizeof( szParticleSystem ) );
}
void CBspEnvParticleSystem::SetKeyValue( const char *pszKey, const char *pszValue )
{
int i;
if( stricmp( pszKey, "client_side" ) == 0 )
{
if( sscanf( pszValue, "%i", &i ) == 1 )
iClientSide = i;
}
else if( stricmp( pszKey, "particle_system" ) == 0 )
{
strcpy( szParticleSystem, pszValue );
}
else
CBspEntity::SetKeyValue( pszKey, pszValue );
}