Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
4.4 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* 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
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
/*
===== lights.cpp ========================================================
spawn and think functions for editor-placed lights
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
class CLight : public CPointEntity
{
public:
9 years ago
virtual void KeyValue( KeyValueData* pkvd );
virtual void Spawn( void );
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
9 years ago
9 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
private:
9 years ago
int m_iStyle;
string_t m_iszPattern;
9 years ago
};
LINK_ENTITY_TO_CLASS( light, CLight )
9 years ago
9 years ago
TYPEDESCRIPTION CLight::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CLight, m_iStyle, FIELD_INTEGER ),
DEFINE_FIELD( CLight, m_iszPattern, FIELD_STRING ),
};
IMPLEMENT_SAVERESTORE( CLight, CPointEntity )
9 years ago
//
// Cache user-entity-field values until spawn is called.
//
9 years ago
void CLight::KeyValue( KeyValueData* pkvd )
9 years ago
{
9 years ago
if( FStrEq(pkvd->szKeyName, "style" ) )
9 years ago
{
9 years ago
m_iStyle = atoi( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
9 years ago
else if( FStrEq(pkvd->szKeyName, "pitch" ) )
9 years ago
{
9 years ago
pev->angles.x = atof( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
9 years ago
else if( FStrEq(pkvd->szKeyName, "pattern" ) )
9 years ago
{
m_iszPattern = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else
{
CPointEntity::KeyValue( pkvd );
}
}
/*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) LIGHT_START_OFF
Non-displayed light.
Default light value is 300
Default style is 0
If targeted, it will toggle between on or off.
*/
9 years ago
void CLight::Spawn( void )
9 years ago
{
9 years ago
if( FStringNull( pev->targetname ) )
{
// inert light
REMOVE_ENTITY(ENT( pev ) );
9 years ago
return;
}
9 years ago
if( m_iStyle >= 32 )
9 years ago
{
//CHANGE_METHOD(ENT(pev), em_use, light_use);
9 years ago
if( FBitSet( pev->spawnflags, SF_LIGHT_START_OFF ) )
LIGHT_STYLE( m_iStyle, "a" );
else if( m_iszPattern )
LIGHT_STYLE( m_iStyle, STRING( m_iszPattern ) );
9 years ago
else
9 years ago
LIGHT_STYLE( m_iStyle, "m" );
9 years ago
}
}
9 years ago
void CLight::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
9 years ago
{
9 years ago
if( m_iStyle >= 32 )
9 years ago
{
9 years ago
if( !ShouldToggle( useType, !FBitSet( pev->spawnflags, SF_LIGHT_START_OFF ) ) )
9 years ago
return;
9 years ago
if( FBitSet( pev->spawnflags, SF_LIGHT_START_OFF ) )
9 years ago
{
9 years ago
if( m_iszPattern )
LIGHT_STYLE( m_iStyle, STRING( m_iszPattern ) );
9 years ago
else
9 years ago
LIGHT_STYLE( m_iStyle, "m" );
ClearBits( pev->spawnflags, SF_LIGHT_START_OFF );
9 years ago
}
else
{
9 years ago
LIGHT_STYLE( m_iStyle, "a" );
SetBits( pev->spawnflags, SF_LIGHT_START_OFF );
9 years ago
}
}
}
//
// shut up spawn functions for new spotlights
//
LINK_ENTITY_TO_CLASS( light_spot, CLight )
9 years ago
class CEnvLight : public CLight
{
public:
9 years ago
void KeyValue( KeyValueData* pkvd );
void Spawn( void );
9 years ago
};
LINK_ENTITY_TO_CLASS( light_environment, CEnvLight )
9 years ago
void CEnvLight::KeyValue( KeyValueData* pkvd )
{
9 years ago
if( FStrEq(pkvd->szKeyName, "_light" ) )
9 years ago
{
int r, g, b, v, j;
char szColor[64];
j = sscanf( pkvd->szValue, "%d %d %d %d\n", &r, &g, &b, &v );
9 years ago
if( j == 1 )
9 years ago
{
g = b = r;
}
9 years ago
else if( j == 4 )
9 years ago
{
float vf = v / 255.0f;
r *= vf;
g *= vf;
b *= vf;
9 years ago
}
// simulate qrad direct, ambient,and gamma adjustments, as well as engine scaling
r = (int)( pow( r / 114.0, 0.6 ) * 264.0 );
g = (int)( pow( g / 114.0, 0.6 ) * 264.0 );
b = (int)( pow( b / 114.0, 0.6 ) * 264.0 );
9 years ago
pkvd->fHandled = TRUE;
sprintf( szColor, "%d", r );
CVAR_SET_STRING( "sv_skycolor_r", szColor );
sprintf( szColor, "%d", g );
CVAR_SET_STRING( "sv_skycolor_g", szColor );
sprintf( szColor, "%d", b );
CVAR_SET_STRING( "sv_skycolor_b", szColor );
}
else
{
CLight::KeyValue( pkvd );
}
}
9 years ago
void CEnvLight::Spawn( void )
9 years ago
{
char szVector[64];
UTIL_MakeAimVectors( pev->angles );
sprintf( szVector, "%f", gpGlobals->v_forward.x );
CVAR_SET_STRING( "sv_skyvec_x", szVector );
sprintf( szVector, "%f", gpGlobals->v_forward.y );
CVAR_SET_STRING( "sv_skyvec_y", szVector );
sprintf( szVector, "%f", gpGlobals->v_forward.z );
CVAR_SET_STRING( "sv_skyvec_z", szVector );
9 years ago
CLight::Spawn();
9 years ago
}