halflife-thewastes-sdk/dlls/thewastes.cpp
2023-09-06 03:25:39 +03:00

223 lines
No EOL
5.4 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 "util.h"
#include "cbase.h"
#include "weapons.h"
#include "player.h"
#include "thewastes.h"
// Player items people can store on their person
playeritem_t MeleeItems[] = {
{ "weapon_combatknife", "", 0, CAT_MELEE },
{ "weapon_throwingknife", "weapon_throwingknife", 4, CAT_MELEE },
{ "weapon_baseballbat", "", 0, CAT_MELEE },
{ "weapon_sledgehammer", "", 0, CAT_MELEE },
{ "weapon_spear", "weapon_spear", 2, CAT_MELEE },
{ "weapon_cattleprod", "", 0, CAT_MELEE },
{ "weapon_katana", "", 0, CAT_MELEE },
};
playeritem_t SidearmItems[] = {
{ "weapon_beretta", "ammo_beretta", 1, CAT_SIDEARM },
{ "weapon_colt", "ammo_colt", 1, CAT_SIDEARM },
{ "weapon_deagle", "ammo_deagle", 1, CAT_SIDEARM },
{ "weapon_sawedoff", "ammo_buckshot", 1, CAT_SIDEARM },
{ "weapon_ruger", "ammo_ruger", 2, CAT_SIDEARM },
{ "weapon_handcannon", "ammo_handcannon", 2, CAT_SIDEARM },
};
playeritem_t PrimaryItems[] = {
{ "weapon_smg9", "ammo_smg9", 1, CAT_PRIMARY },
{ "weapon_sten", "ammo_sten", 1, CAT_PRIMARY },
{ "weapon_boltrifle", "ammo_boltrifle", 1, CAT_PRIMARY },
{ "weapon_mossberg", "ammo_buckshot", 1, CAT_PRIMARY },
{ "weapon_winchester", "ammo_winchester", 1, CAT_PRIMARY },
{ "weapon_akimboberettas", "ammo_beretta", 2, CAT_PRIMARY },
{ "weapon_akimbocolts", "ammo_colt", 1, CAT_PRIMARY },
{ "weapon_akimbodeagles", "ammo_deagle", 1, CAT_PRIMARY },
{ "weapon_akimbosawedoffs", "ammo_buckshot", 1, CAT_PRIMARY },
};
playeritem_t UniqueItems[] = {
{ "weapon_fnfal", "ammo_fnfal", 1, CAT_UNIQUE },
{ "weapon_tommygun", "ammo_tommygun", 1, CAT_UNIQUE },
{ "weapon_g11", "ammo_g11", 1, CAT_UNIQUE },
{ "weapon_jackhammer", "ammo_jackhammer", 1, CAT_UNIQUE },
};
playeritem_t OtherItems[] = {
// TODO: Bring back in when fixed!
// { "weapon_molotov", "weapon_molotov", 1, CAT_ITEM },
{ "weapon_fraggrenade", "weapon_fraggrenade", 1, CAT_ITEM },
{ "weapon_pipebomb", "weapon_pipebomb", 0, CAT_ITEM },
{ "extra_ammo", NULL, 0, CAT_ITEM },
};
playeritemlist_t g_MeleeItems = {
MeleeItems,
7,
};
playeritemlist_t g_SidearmItems = {
SidearmItems,
6,
};
playeritemlist_t g_PrimaryItems = {
PrimaryItems,
9,
};
playeritemlist_t g_UniqueItems = {
UniqueItems,
4,
};
playeritemlist_t g_OtherItems = {
OtherItems,
// 4,
3,
};
#ifndef CLIENT_DLL
// Spawns people with extra ammo
class CExtraAmmo : public CBasePlayerItem
{
public:
void Spawn()
{
pev->classname = MAKE_STRING( "extra_ammo" );
pev->solid = SOLID_TRIGGER;
UTIL_SetSize( pev, g_vecZero, g_vecZero );
}
void Touch( CBaseEntity *pOther )
{
if( pOther != NULL && pOther->IsPlayer() )
{
CBasePlayer *pPlayer = (CBasePlayer*)pOther;
// Sidearms
pPlayer->GiveNamedItem( "ammo_beretta" );
pPlayer->GiveNamedItem( "ammo_colt" );
pPlayer->GiveNamedItem( "ammo_deagle" );
pPlayer->GiveNamedItem( "ammo_ruger" );
pPlayer->GiveNamedItem( "ammo_handcannon" );
// Primary
pPlayer->GiveNamedItem( "ammo_smg9" );
pPlayer->GiveNamedItem( "ammo_sten" );
pPlayer->GiveNamedItem( "ammo_boltrifle" );
pPlayer->GiveNamedItem( "ammo_winchester" );
// Uniques
pPlayer->GiveNamedItem( "ammo_fnfal" );
pPlayer->GiveNamedItem( "ammo_tommygun" );
pPlayer->GiveNamedItem( "ammo_g11" );
pPlayer->GiveNamedItem( "ammo_buckshot" );
}
UTIL_Remove( this );
}
};
LINK_ENTITY_TO_CLASS( extra_ammo, CExtraAmmo );
#endif
void CWasteWeapon::Spawn()
{
CBasePlayerWeapon::Spawn();
}
void CWasteWeapon::ItemPostFrame()
{
if ((m_pPlayer->pev->button & IN_SPECIAL) && m_flNextPrimaryAttack <= 0.0)
{
SpecialMode();
m_pPlayer->pev->button &= ~IN_SPECIAL;
}
CBasePlayerWeapon::ItemPostFrame();
}
BOOL CWasteWeapon::UseDecrement()
{
#if defined( CLIENT_WEAPONS )
return TRUE;
#else
return FALSE;
#endif
}
void CWasteWeapon::SpecialMode()
{
}
// Simple solution
int CWasteWeapon::iGetWeight()
{
ItemInfo II;
GetItemInfo(&II);
return II.iWeight;
}
// Used for pistol whips (and melee weaps)
void FindHullIntersection( const Vector &vecSrc, TraceResult &tr, float *mins, float *maxs, edict_t *pEntity )
{
int i, j, k;
float distance;
float *minmaxs[2] = {mins, maxs};
TraceResult tmpTrace;
Vector vecHullEnd = tr.vecEndPos;
Vector vecEnd;
distance = 1e6f;
vecHullEnd = vecSrc + ((vecHullEnd - vecSrc)*2);
UTIL_TraceLine( vecSrc, vecHullEnd, dont_ignore_monsters, pEntity, &tmpTrace );
if ( tmpTrace.flFraction < 1.0 )
{
tr = tmpTrace;
return;
}
for ( i = 0; i < 2; i++ )
{
for ( j = 0; j < 2; j++ )
{
for ( k = 0; k < 2; k++ )
{
vecEnd.x = vecHullEnd.x + minmaxs[i][0];
vecEnd.y = vecHullEnd.y + minmaxs[j][1];
vecEnd.z = vecHullEnd.z + minmaxs[k][2];
UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, pEntity, &tmpTrace );
if ( tmpTrace.flFraction < 1.0 )
{
float thisDistance = (tmpTrace.vecEndPos - vecSrc).Length();
if ( thisDistance < distance )
{
tr = tmpTrace;
distance = thisDistance;
}
}
}
}
}
}