Skip to content

Commit

Permalink
Allow info_loadout to spawn other same weapon types (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
TotallyMehis committed Jun 23, 2020
1 parent 7672ea1 commit bfd3b6e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
41 changes: 31 additions & 10 deletions mp/src/game/server/zmr/zmr_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "zmr/zmr_shareddefs.h"
#include "npcs/zmr_zombiebase_shared.h"
#include "zmr/weapons/zmr_base.h"
#include "zmr_mapitemaction.h"

#include "zmr_entities.h"

Expand Down Expand Up @@ -1676,22 +1677,23 @@ void CZMEntLoadout::DistributeToPlayer( CZMPlayer* pPlayer )

void CZMEntLoadout::GiveWeapon( CZMPlayer* pPlayer, int loadout_wep )
{
const char* weps[] = {
"weapon_zm_pistol",
"weapon_zm_shotgun",
"weapon_zm_rifle",
"weapon_zm_mac10",
// Loadout is a mix of items and item classes.
const char* loadouts[LO_MAX] = {
"Pistol",
"Shotgun",
"Rifle",
"SMG",
"weapon_zm_molotov",
"weapon_zm_sledge",
"weapon_zm_improvised",
"weapon_zm_revolver",
"BigPistol",
};

COMPILE_TIME_ASSERT( ARRAYSIZE( weps ) >= LO_MAX );
COMPILE_TIME_ASSERT( ARRAYSIZE( loadouts ) >= LO_MAX );

Assert( loadout_wep >= 0 && loadout_wep < LO_MAX );

const char* wepname = weps[loadout_wep];
const char* loadoutClass = loadouts[loadout_wep];


bool ammo = false;
Expand All @@ -1710,11 +1712,30 @@ void CZMEntLoadout::GiveWeapon( CZMPlayer* pPlayer, int loadout_wep )
}


CZMBaseWeapon* pWeapon = ToZMBaseWeapon( pPlayer->Weapon_Create( wepname ) );
CUtlVector<const ZMItemAction::ItemBaseData_t*> items;

// See if it's a single item.
auto* pData = ZMItemAction::g_ZMMapItemSystem.GetItemData( loadoutClass );

if ( pData )
{
items.AddToTail( pData );
}
else
{
// It's a class. Get all the items.
auto flag = ZMItemAction::g_ZMMapItemSystem.GetClassFlag( loadoutClass );
ZMItemAction::g_ZMMapItemSystem.GetMapItemsByClass( flag, items );
}


// Get a random weapon from the items.
const char* wepname = items.Count() > 0 ? items[random->RandomInt( 0, items.Count() - 1 )]->m_pszClassname : "";
auto* pWeapon = ToZMBaseWeapon( pPlayer->Weapon_Create( wepname ) );

if ( !pWeapon )
{
Warning( "Failed to give player loadout weapon %s!\n", wepname );
Warning( "Failed to give player loadout '%s'!\n", loadoutClass );
return;
}

Expand Down
7 changes: 7 additions & 0 deletions mp/src/game/server/zmr/zmr_mapitemaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,13 @@ const ItemBaseData_t* CZMMapItemSystem::GetItemData( int index )
return nullptr;
}

const ItemBaseData_t* CZMMapItemSystem::GetItemData( const char* itemclass )
{
int index = FindItemByClassname( itemclass );

return GetItemData( index );
}

bool CZMMapItemSystem::AffectsItem( const char* classname )
{
return FindItemByClassname( classname ) != -1;
Expand Down
1 change: 1 addition & 0 deletions mp/src/game/server/zmr/zmr_mapitemaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace ZMItemAction
static unsigned int GetItemFlags( const char* classname );
static unsigned int GetClassFlag( const char* classname );
static const ItemBaseData_t* GetItemData( int index );
static const ItemBaseData_t* GetItemData( const char* itemclass );
static bool GetMapItemsByClass( unsigned int flags, CUtlVector<const ItemBaseData_t*>& items );


Expand Down

0 comments on commit bfd3b6e

Please sign in to comment.