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.

417 lines
10 KiB

/***
*
* 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.
*
****/
/*
===== items.cpp ========================================================
functions governing the selection/use of weapons for players
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "weapons.h"
#include "player.h"
#include "skill.h"
#include "items.h"
#include "gamerules.h"
#include "game.h"
extern int gmsgItemPickup;
class CWorldItem : public CBaseEntity
{
public:
8 years ago
void KeyValue( KeyValueData *pkvd );
void Spawn( void );
int m_iType;
};
8 years ago
LINK_ENTITY_TO_CLASS( world_items, CWorldItem )
8 years ago
void CWorldItem::KeyValue( KeyValueData *pkvd )
{
8 years ago
if( FStrEq( pkvd->szKeyName, "type" ) )
{
8 years ago
m_iType = atoi( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else
CBaseEntity::KeyValue( pkvd );
}
void CWorldItem::Spawn( void )
{
CBaseEntity *pEntity = NULL;
8 years ago
switch( m_iType )
{
case 44: // ITEM_BATTERY:
pEntity = CBaseEntity::Create( "item_battery", pev->origin, pev->angles );
break;
case 42: // ITEM_ANTIDOTE:
pEntity = CBaseEntity::Create( "item_antidote", pev->origin, pev->angles );
break;
case 43: // ITEM_SECURITY:
pEntity = CBaseEntity::Create( "item_security", pev->origin, pev->angles );
break;
case 45: // ITEM_SUIT:
pEntity = CBaseEntity::Create( "item_suit", pev->origin, pev->angles );
break;
}
8 years ago
if( !pEntity )
{
ALERT( at_console, "unable to create world_item %d\n", m_iType );
}
else
{
pEntity->pev->target = pev->target;
pEntity->pev->targetname = pev->targetname;
pEntity->pev->spawnflags = pev->spawnflags;
}
8 years ago
REMOVE_ENTITY( edict() );
}
void CItem::Spawn( void )
{
pev->movetype = MOVETYPE_TOSS;
pev->solid = SOLID_TRIGGER;
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity = Vector( 0, 0, 0 );
UTIL_SetOrigin( pev, pev->origin );
8 years ago
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 16 ) );
SetTouch( &CItem::ItemTouch );
8 years ago
if( DROP_TO_FLOOR(ENT( pev ) ) == 0 )
{
ALERT(at_error, "Item %s fell out of level at %f,%f,%f\n", STRING( pev->classname ), (double)pev->origin.x, (double)pev->origin.y, (double)pev->origin.z);
UTIL_Remove( this );
return;
}
m_SpawnPoint = pev->origin;
m_SpawnAngles = pev->angles;
}
extern int gEvilImpulse101;
void CItem::ItemTouch( CBaseEntity *pOther )
{
pev->velocity = ( pev->velocity + pOther->pev->velocity) / 2;
pev->avelocity = pev->avelocity / 3;
// if it's not a player, ignore
8 years ago
if( !pOther->IsPlayer() )
{
if( pev->velocity.Length() < 5 )
pev->velocity = Vector( 0, 0 ,0 );
SetThink( &CItem::Materialize );
pev->nextthink = g_pGameRules->FlItemRespawnTime( this );
if( ( pOther->pev->solid == SOLID_BSP || pOther->entindex() == 0 ) && pev->movetype == MOVETYPE_BOUNCE && pev->velocity.Length() )
switch( RANDOM_LONG( 0, 2 ) )
{
case 0:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete1.wav", 0.15, ATTN_NORM );break;
case 1:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete2.wav", 0.15, ATTN_NORM );break;
case 2:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete3.wav", 0.15, ATTN_NORM );break;
}
else if( !( pev->flags & FL_ONGROUND ) || !( (pOther->pev->solid == SOLID_BSP) || (pOther->entindex() <= 1) ) )
pev->movetype = MOVETYPE_TOSS;
return;
}
CBasePlayer *pPlayer = (CBasePlayer *)pOther;
// ok, a player is touching this item, but can he have it?
8 years ago
if( !g_pGameRules->CanHaveItem( pPlayer, this ) )
{
// no? Ignore the touch.
return;
}
8 years ago
if( MyTouch( pPlayer ) )
{
SUB_UseTargets( pOther, USE_TOGGLE, 0 );
SetTouch( NULL );
// player grabbed the item.
g_pGameRules->PlayerGotItem( pPlayer, this );
8 years ago
if( g_pGameRules->ItemShouldRespawn( this ) == GR_ITEM_RESPAWN_YES )
{
Respawn();
}
else
{
UTIL_Remove( this );
}
}
8 years ago
else if( gEvilImpulse101 )
{
UTIL_Remove( this );
}
else
{
pev->movetype = MOVETYPE_TOSS;
pev->velocity = Vector( 0 ,0 ,0 );
}
}
CBaseEntity* CItem::Respawn( void )
{
SetTouch( NULL );
pev->effects |= EF_NODRAW;
UTIL_SetOrigin( pev, m_SpawnPoint );// blip to whereever you should respawn.
SetThink( &CItem::Materialize );
pev->nextthink = g_pGameRules->FlItemRespawnTime( this );
if( mp_coop.value)
pev->target = 0;
return this;
}
float CItem::TouchGravGun( CBaseEntity *attacker, int stage)
{
if( stage == 2 )
if( (attacker->pev->origin - pev->origin ).Length() < 90 )
Touch( attacker );
if( pev->movetype == MOVETYPE_FOLLOW )
return 0;
if( pev->movetype == MOVETYPE_NONE )
return 0;
if( pev->effects & EF_NODRAW )
return 0;
//if( pev->mins == pev->maxs )
//return 0;
if( stage == 2 )
{
UTIL_MakeVectors( attacker->pev->v_angle + attacker->pev->punchangle);
float atarget = UTIL_VecToAngles(gpGlobals->v_forward).y;
pev->angles.y = UTIL_AngleMod(pev->angles.y);
atarget = UTIL_AngleMod(atarget);
pev->avelocity.y = UTIL_AngleDiff(atarget, pev->angles.y) * 10;
}
if( stage == 3 )
{
pev->avelocity.y = pev->avelocity.y*1.5 + RANDOM_FLOAT(100, -100);
}
SetThink( &CItem::Materialize );
pev->nextthink = g_pGameRules->FlItemRespawnTime( this );
if( ( pev->movetype == MOVETYPE_TOSS ) && ( stage > 1 ) )
{
pev->movetype = MOVETYPE_BOUNCE;
pev->velocity = Vector( 0, 0, 0 );
}
return 400;
}
void CItem::Materialize( void )
{
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity = Vector( 0, 0, 0 );
pev->movetype = MOVETYPE_TOSS;
8 years ago
if( pev->effects & EF_NODRAW )
{
// changing from invisible state to visible.
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "items/suitchargeok1.wav", 1, ATTN_NORM, 0, 150 );
pev->effects &= ~EF_NODRAW;
pev->effects |= EF_MUZZLEFLASH;
if( m_SpawnPoint == Vector( 0, 0, 0 ) )
{
m_SpawnPoint = pev->origin;
m_SpawnAngles = pev->angles;
}
}
if( m_SpawnPoint != Vector( 0, 0, 0 ) )
{
pev->angles = m_SpawnAngles;
UTIL_SetOrigin( pev, m_SpawnPoint );// blip to whereever you should respawn.
}
SetTouch( &CItem::ItemTouch );
SetThink( NULL );
}
#define SF_SUIT_SHORTLOGON 0x0001
class CItemSuit : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_suit.mdl" );
CItem::Spawn();
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_suit.mdl" );
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
if( !mp_coop.value && pPlayer->pev->weapons & ( 1<<WEAPON_SUIT ) )
return FALSE;
// no sounds in coop
if( !mp_coop.value )
{
if( pev->spawnflags & SF_SUIT_SHORTLOGON )
EMIT_SOUND_SUIT( pPlayer->edict(), "!HEV_A0" ); // short version of suit logon,
else
EMIT_SOUND_SUIT( pPlayer->edict(), "!HEV_AAx" ); // long version of suit logon
}
8 years ago
pPlayer->pev->weapons |= ( 1 << WEAPON_SUIT );
return TRUE;
}
};
8 years ago
LINK_ENTITY_TO_CLASS( item_suit, CItemSuit )
class CItemBattery : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_battery.mdl" );
CItem::Spawn();
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_battery.mdl" );
PRECACHE_SOUND( "items/gunpickup2.wav" );
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
8 years ago
if( pPlayer->pev->deadflag != DEAD_NO )
{
return FALSE;
}
8 years ago
if( ( pPlayer->pev->armorvalue < MAX_NORMAL_BATTERY ) &&
( pPlayer->pev->weapons & ( 1 << WEAPON_SUIT ) ) )
{
int pct;
char szcharge[64];
pPlayer->pev->armorvalue += gSkillData.batteryCapacity;
pPlayer->pev->armorvalue = Q_min( pPlayer->pev->armorvalue, MAX_NORMAL_BATTERY );
EMIT_SOUND( pPlayer->edict(), CHAN_ITEM, "items/gunpickup2.wav", 1, ATTN_NORM );
MESSAGE_BEGIN( MSG_ONE, gmsgItemPickup, NULL, pPlayer->pev );
8 years ago
WRITE_STRING( STRING( pev->classname ) );
MESSAGE_END();
// Suit reports new power level
// For some reason this wasn't working in release build -- round it.
pct = (int)( (float)( pPlayer->pev->armorvalue * 100.0f ) * ( 1.0f / MAX_NORMAL_BATTERY ) + 0.5f );
8 years ago
pct = ( pct / 5 );
if( pct > 0 )
pct--;
8 years ago
sprintf( szcharge,"!HEV_%1dP", pct );
8 years ago
//EMIT_SOUND_SUIT( ENT( pev ), szcharge );
pPlayer->SetSuitUpdate( szcharge, FALSE, SUIT_NEXT_IN_30SEC);
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( item_battery, CItemBattery )
class CItemAntidote : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_antidote.mdl" );
CItem::Spawn();
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_antidote.mdl" );
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
8 years ago
pPlayer->SetSuitUpdate( "!HEV_DET4", FALSE, SUIT_NEXT_IN_1MIN );
pPlayer->m_rgItems[ITEM_ANTIDOTE] += 1;
return TRUE;
}
};
LINK_ENTITY_TO_CLASS( item_antidote, CItemAntidote )
class CItemSecurity : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_security.mdl" );
CItem::Spawn();
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_security.mdl" );
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
pPlayer->m_rgItems[ITEM_SECURITY] += 1;
return TRUE;
}
};
LINK_ENTITY_TO_CLASS( item_security, CItemSecurity )
class CItemLongJump : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_longjump.mdl" );
CItem::Spawn();
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_longjump.mdl" );
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
8 years ago
if( pPlayer->m_fLongJump )
{
return FALSE;
}
8 years ago
if( ( pPlayer->pev->weapons & ( 1 << WEAPON_SUIT ) ) )
{
pPlayer->m_fLongJump = TRUE;// player now has longjump module
g_engfuncs.pfnSetPhysicsKeyValue( pPlayer->edict(), "slj", "1" );
MESSAGE_BEGIN( MSG_ONE, gmsgItemPickup, NULL, pPlayer->pev );
8 years ago
WRITE_STRING( STRING( pev->classname ) );
MESSAGE_END();
EMIT_SOUND_SUIT( pPlayer->edict(), "!HEV_A1" ); // Play the longjump sound UNDONE: Kelly? correct sound?
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( item_longjump, CItemLongJump )