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.

408 lines
9.2 KiB

7 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.
*
****/
/*
===== 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"
extern int gmsgItemPickup;
class CWorldItem : public CBaseEntity
{
public:
8 years ago
void KeyValue( KeyValueData *pkvd );
void Spawn( void );
int m_iType;
7 years ago
};
8 years ago
LINK_ENTITY_TO_CLASS( world_items, CWorldItem )
7 years ago
8 years ago
void CWorldItem::KeyValue( KeyValueData *pkvd )
7 years ago
{
8 years ago
if( FStrEq( pkvd->szKeyName, "type" ) )
7 years ago
{
8 years ago
m_iType = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
else
CBaseEntity::KeyValue( pkvd );
}
void CWorldItem::Spawn( void )
{
CBaseEntity *pEntity = NULL;
8 years ago
switch( m_iType )
7 years ago
{
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 )
7 years ago
{
9 years ago
ALERT( at_console, "unable to create world_item %d\n", m_iType );
7 years ago
}
else
{
pEntity->pev->target = pev->target;
pEntity->pev->targetname = pev->targetname;
pEntity->pev->spawnflags = pev->spawnflags;
}
8 years ago
REMOVE_ENTITY( edict() );
7 years ago
}
void CItem::Spawn( void )
{
pev->movetype = MOVETYPE_TOSS;
pev->solid = SOLID_TRIGGER;
UTIL_SetOrigin( this, pev->origin );
8 years ago
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 16 ) );
9 years ago
SetTouch( &CItem::ItemTouch );
7 years ago
8 years ago
if( DROP_TO_FLOOR(ENT( pev ) ) == 0 )
7 years ago
{
9 years ago
ALERT(at_error, "Item %s fell out of level at %f,%f,%f\n", STRING( pev->classname ), pev->origin.x, pev->origin.y, pev->origin.z);
7 years ago
UTIL_Remove( this );
return;
}
}
extern int gEvilImpulse101;
void CItem::ItemTouch( CBaseEntity *pOther )
{
// if it's not a player, ignore
8 years ago
if( !pOther->IsPlayer() )
7 years ago
{
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 ) )
7 years ago
{
// no? Ignore the touch.
return;
}
8 years ago
if( MyTouch( pPlayer ) )
7 years ago
{
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 )
7 years ago
{
Respawn();
}
else
{
UTIL_Remove( this );
}
}
8 years ago
else if( gEvilImpulse101 )
7 years ago
{
UTIL_Remove( this );
}
}
CBaseEntity* CItem::Respawn( void )
{
SetTouch( NULL );
pev->effects |= EF_NODRAW;
UTIL_SetOrigin( this, g_pGameRules->VecItemRespawnSpot( this ) );// blip to whereever you should respawn.
9 years ago
SetThink( &CItem::Materialize );
7 years ago
AbsoluteNextThink( g_pGameRules->FlItemRespawnTime( this ) );
return this;
}
void CItem::Materialize( void )
{
8 years ago
if( pev->effects & EF_NODRAW )
7 years ago
{
// changing from invisible state to visible.
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "items/suitchargeok1.wav", 1, ATTN_NORM, 0, 150 );
7 years ago
pev->effects &= ~EF_NODRAW;
pev->effects |= EF_MUZZLEFLASH;
}
9 years ago
SetTouch( &CItem::ItemTouch );
SetThink( NULL );
7 years ago
}
#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();
7 years ago
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_suit.mdl" );
7 years ago
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
if ( pPlayer->pev->deadflag != DEAD_NO )
{
return FALSE;
}
8 years ago
if( pPlayer->pev->weapons & ( 1<<WEAPON_SUIT ) )
7 years ago
return FALSE;
8 years ago
if( pev->spawnflags & SF_SUIT_SHORTLOGON )
EMIT_SOUND_SUIT( pPlayer->edict(), "!HEV_A0" ); // short version of suit logon,
7 years ago
else
8 years ago
EMIT_SOUND_SUIT( pPlayer->edict(), "!HEV_AAx" ); // long version of suit logon
7 years ago
8 years ago
pPlayer->pev->weapons |= ( 1 << WEAPON_SUIT );
7 years ago
return TRUE;
}
};
8 years ago
LINK_ENTITY_TO_CLASS( item_suit, CItemSuit )
7 years ago
class CItemBattery : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/w_battery.mdl" );
8 years ago
CItem::Spawn();
7 years ago
}
void Precache( void )
{
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/w_battery.mdl" );
7 years ago
if (pev->noise)
PRECACHE_SOUND( STRING(pev->noise) ); //LRC
7 years ago
else
PRECACHE_SOUND( "items/gunpickup2.wav" );
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
8 years ago
if( pPlayer->pev->deadflag != DEAD_NO )
7 years ago
{
return FALSE;
}
8 years ago
if( ( pPlayer->pev->armorvalue < MAX_NORMAL_BATTERY ) &&
( pPlayer->pev->weapons & ( 1 << WEAPON_SUIT ) ) )
7 years ago
{
int pct;
char szcharge[64];
if (pev->armorvalue)
pPlayer->pev->armorvalue += pev->armorvalue;
else
9 years ago
pPlayer->pev->armorvalue += gSkillData.batteryCapacity;
pPlayer->pev->armorvalue = Q_min( pPlayer->pev->armorvalue, MAX_NORMAL_BATTERY );
7 years ago
if (pev->noise)
EMIT_SOUND( pPlayer->edict(), CHAN_ITEM, STRING(pev->noise), 1, ATTN_NORM ); //LRC
else
9 years ago
EMIT_SOUND( pPlayer->edict(), CHAN_ITEM, "items/gunpickup2.wav", 1, ATTN_NORM );
7 years ago
MESSAGE_BEGIN( MSG_ONE, gmsgItemPickup, NULL, pPlayer->pev );
8 years ago
WRITE_STRING( STRING( pev->classname ) );
7 years ago
MESSAGE_END();
// Suit reports new power level
// For some reason this wasn't working in release build -- round it.
8 years ago
pct = (int)( (float)( pPlayer->pev->armorvalue * 100.0 ) * ( 1.0 / MAX_NORMAL_BATTERY ) + 0.5 );
pct = ( pct / 5 );
if( pct > 0 )
7 years ago
pct--;
8 years ago
7 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;
7 years ago
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( item_battery, CItemBattery )
7 years ago
class CItemAntidote : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_antidote.mdl" );
CItem::Spawn();
7 years ago
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_antidote.mdl" );
7 years ago
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
8 years ago
pPlayer->SetSuitUpdate( "!HEV_DET4", FALSE, SUIT_NEXT_IN_1MIN );
7 years ago
pPlayer->m_rgItems[ITEM_ANTIDOTE] += 1;
return TRUE;
}
};
LINK_ENTITY_TO_CLASS( item_antidote, CItemAntidote )
7 years ago
class CItemSecurity : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_security.mdl" );
CItem::Spawn();
7 years ago
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_security.mdl" );
7 years ago
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
pPlayer->m_rgItems[ITEM_SECURITY] += 1;
return TRUE;
}
};
LINK_ENTITY_TO_CLASS( item_security, CItemSecurity )
7 years ago
class CItemLongJump : public CItem
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_longjump.mdl" );
CItem::Spawn();
7 years ago
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_longjump.mdl" );
7 years ago
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
8 years ago
if( pPlayer->m_fLongJump )
7 years ago
{
return FALSE;
}
8 years ago
if( ( pPlayer->pev->weapons & ( 1 << WEAPON_SUIT ) ) )
7 years ago
{
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 ) );
7 years ago
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 )
/*
// advanced NVG
extern int gmsgNVG; // we need to send this message
class CItemNVG : public CItem
{
void Spawn()
{
Precache();
SET_MODEL( ENT( pev ), "models/w_longjump.mdl" ); // you'll want to change this
CItem::Spawn();
}
void Precache()
{
PRECACHE_MODEL( "models/w_longjump.mdl" ); // you'll want to change this
PRECACHE_SOUND( "buttons/blip1.wav" );
}
BOOL MyTouch( CBasePlayer *pPlayer )
{
if( pPlayer->m_fNVG ) // does the player already have it
{
return FALSE; // if so, quit
}
if( ( pPlayer->pev->weapons & ( 1 << WEAPON_SUIT ) ) )
{
pPlayer->m_fNVG = TRUE; // player now has night vision goggles
// make the client.dll print out the symbol on ammo history
MESSAGE_BEGIN( MSG_ONE, gmsgItemPickup, NULL, pPlayer->pev );
WRITE_STRING( STRING( pev->classname ) );
MESSAGE_END();
// ... and tell them that we now have an NVG
MESSAGE_BEGIN( MSG_ONE, gmsgNVG, NULL, pPlayer->pev );
WRITE_BYTE( 1 );
WRITE_BYTE( pPlayer->m_flNVGBattery );
MESSAGE_END();
// play a sound to tell the player he's picked up the NVG
EMIT_SOUND( pPlayer->edict(), CHAN_WEAPON, "buttons/blip1.wav", 0.8, ATTN_NORM );
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( item_nvg, CItemNVG );*/
// advanced NVG