Skip to content

Commit

Permalink
slightly better handling for marine equip slot
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed Oct 17, 2023
1 parent 7c9c57d commit efe3b2e
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/game/client/swarm/asw_briefing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,10 @@ const CRD_ItemInstance &CASW_Briefing::GetEquippedSuit( int nLobbySlot )

C_ASW_Player *pPlayer = m_LobbySlotMapping[nLobbySlot].m_hPlayer.Get();
C_ASW_Marine_Resource *pMR = m_LobbySlotMapping[nLobbySlot].m_hMR.Get();
if ( !pPlayer || !pMR )
if ( !pPlayer || !pMR || pMR->m_MarineProfileIndexDynamic < 0 || pMR->m_MarineProfileIndexDynamic >= ASW_NUM_MARINES_PER_LOADOUT )
return s_empty;

return pPlayer->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->GetProfileIndex()];
return pPlayer->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->m_MarineProfileIndexDynamic];
}

const CRD_ItemInstance &CASW_Briefing::GetEquippedWeapon( int nLobbySlot, int nWeaponSlot )
Expand Down
4 changes: 2 additions & 2 deletions src/game/client/swarm/c_asw_fx_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ static const CRD_ItemInstance &GetItemInstanceFromRenderable( IClientRenderable
if ( C_ASW_Marine *pMarine = C_ASW_Marine::AsMarine( pEnt ) )
{
C_ASW_Marine_Resource *pMR = pMarine->GetMarineResource();
if ( pMR && pMR->m_OriginalCommander )
if ( pMR && pMR->m_OriginalCommander && pMR->m_MarineProfileIndexDynamic >= 0 && pMR->m_MarineProfileIndexDynamic < ASW_NUM_MARINES_PER_LOADOUT )
{
return pMR->m_OriginalCommander->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->GetProfileIndex()];
return pMR->m_OriginalCommander->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->m_MarineProfileIndexDynamic];
}
}

Expand Down
19 changes: 5 additions & 14 deletions src/game/client/swarm/c_asw_marine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,26 +1074,17 @@ void C_ASW_Marine::OnDataChanged( DataUpdateType_t updateType )
CreateBackpack( GetASWWeapon( GetActiveASWWeapon() == GetASWWeapon( 0 ) ? 1 : 0 ) );

C_ASW_Marine_Resource *pMR = GetMarineResource();
if ( pMR && pMR->m_OriginalCommander )
if ( pMR && pMR->m_OriginalCommander && pMR->m_MarineProfileIndexDynamic >= 0 && pMR->m_MarineProfileIndexDynamic < ASW_NUM_MARINES_PER_LOADOUT )
{
static KeyValues *s_pKVAccessoryPosition[ASW_NUM_MARINE_PROFILES]{};
constexpr const char *const s_szAccessoryPositionFiles[ASW_NUM_MARINE_PROFILES] =
{
"scripts/strange_device_positions_marine_sarge.txt",
"scripts/strange_device_positions_marine_wildcat.txt",
"scripts/strange_device_positions_marine_faith.txt",
"scripts/strange_device_positions_marine_crash.txt",
"scripts/strange_device_positions_marine_jaeger.txt",
"scripts/strange_device_positions_marine_wolfe.txt",
"scripts/strange_device_positions_marine_bastille.txt",
"scripts/strange_device_positions_marine_vegas.txt",
};

int iProfile = pMR->GetProfileIndex();
Assert( iProfile >= 0 && iProfile < ASW_NUM_MARINE_PROFILES );
COMPILE_TIME_ASSERT( ASW_NUM_MARINE_PROFILES == 8 );

C_RD_Weapon_Accessory::CreateWeaponAccessories( this, pMR->m_OriginalCommander->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + iProfile], m_hWeaponAccessory, s_pKVAccessoryPosition[iProfile], s_szAccessoryPositionFiles[iProfile] );
char szFileName[MAX_PATH];
V_snprintf( szFileName, sizeof( szFileName ), "scripts/strange_device_positions_marine_%s.txt", pMR->GetProfile()->m_PortraitName );

C_RD_Weapon_Accessory::CreateWeaponAccessories( this, pMR->m_OriginalCommander->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->m_MarineProfileIndexDynamic], m_hWeaponAccessory, s_pKVAccessoryPosition[iProfile], szFileName );
}

// We want to think every frame.
Expand Down
2 changes: 2 additions & 0 deletions src/game/client/swarm/c_asw_marine_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ END_RECV_TABLE();
IMPLEMENT_CLIENTCLASS_DT( C_ASW_Marine_Resource, DT_ASW_Marine_Resource, CASW_Marine_Resource )
RecvPropDataTable( "mr_timelines", 0, 0, &REFERENCE_RECV_TABLE( DT_MR_Timelines ) ),
RecvPropIntWithMinusOneFlag( RECVINFO( m_MarineProfileIndex ) ),
RecvPropIntWithMinusOneFlag( RECVINFO( m_MarineProfileIndexDynamic ) ),
RecvPropEHandle( RECVINFO( m_MarineEntity ) ),
RecvPropEHandle( RECVINFO( m_OriginalCommander ) ),
RecvPropEHandle( RECVINFO( m_Commander ) ),
Expand Down Expand Up @@ -62,6 +63,7 @@ extern ConVar asw_skill_healing_charges_step;
C_ASW_Marine_Resource::C_ASW_Marine_Resource()
{
m_MarineProfileIndex = -1;
m_MarineProfileIndexDynamic = -1;
m_iScannerSoundSkip = 3;
m_fScannerTime = RandomFloat(1.0f, 2.5f);
m_bPlayedBlipSound = false;
Expand Down
1 change: 1 addition & 0 deletions src/game/client/swarm/c_asw_marine_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class C_ASW_Marine_Resource : public C_BaseEntity
CASW_Marine_Profile* GetProfile(void);
int GetProfileIndex() { return m_MarineProfileIndex; }
int m_MarineProfileIndex;
int m_MarineProfileIndexDynamic;
C_ASW_Marine* GetMarineEntity();
C_ASW_Player* GetCommander();
int GetCommanderIndex() { return m_iCommanderIndex; }
Expand Down
9 changes: 6 additions & 3 deletions src/game/server/swarm/asw_marine_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ LINK_ENTITY_TO_CLASS( asw_marine_resource, CASW_Marine_Resource );
//---------------------------------------------------------
BEGIN_DATADESC( CASW_Marine_Resource )
DEFINE_FIELD( m_MarineProfileIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_MarineProfileIndexDynamic, FIELD_INTEGER ),
DEFINE_FIELD( m_MarineEntity, FIELD_EHANDLE ),
DEFINE_FIELD( m_OriginalCommander, FIELD_EHANDLE ),
DEFINE_FIELD( m_bHadOriginalCommander, FIELD_BOOLEAN ),
Expand Down Expand Up @@ -107,6 +108,7 @@ IMPLEMENT_SERVERCLASS_ST( CASW_Marine_Resource, DT_ASW_Marine_Resource )
// Timeline data only gets sent at mission end
SendPropDataTable( "mr_timelines", 0, &REFERENCE_SEND_TABLE( DT_MR_Timelines ), SendProxy_SendMarineResourceTimelinesDataTable ),
SendPropIntWithMinusOneFlag( SENDINFO( m_MarineProfileIndex ), NumBitsForCount( ASW_NUM_MARINE_PROFILES + 1 ) ),
SendPropIntWithMinusOneFlag( SENDINFO( m_MarineProfileIndexDynamic ), NumBitsForCount( ASW_NUM_MARINES_PER_LOADOUT + 1 ) ),
SendPropEHandle( SENDINFO( m_MarineEntity ) ),
SendPropEHandle( SENDINFO( m_OriginalCommander ) ),
SendPropEHandle( SENDINFO( m_Commander ) ),
Expand Down Expand Up @@ -138,6 +140,7 @@ CASW_Marine_Resource::CASW_Marine_Resource()
{
m_bAwardedMedals = false;
m_MarineProfileIndex = -1;
m_MarineProfileIndexDynamic = -1;
m_bInfested = false;
m_bHadOriginalCommander = false;
m_OriginalCommander = NULL;
Expand Down Expand Up @@ -352,24 +355,24 @@ void CASW_Marine_Resource::SetMarineEntity(CASW_Marine* marine)
m_MarineEntity = marine;
}

void CASW_Marine_Resource::SetProfileIndex(int ProfileIndex)
void CASW_Marine_Resource::SetProfileIndex( int ProfileIndex, int DynamicIndex = -1 )
{
m_MarineProfileIndex = ProfileIndex;
m_MarineProfileIndexDynamic = DynamicIndex;
}

int CASW_Marine_Resource::GetProfileIndex()
{
return m_MarineProfileIndex;
}

CASW_Marine_Profile* CASW_Marine_Resource::GetProfile()
CASW_Marine_Profile *CASW_Marine_Resource::GetProfile()
{
Assert( MarineProfileList() );

return MarineProfileList()->GetProfile( m_MarineProfileIndex );
}


CASW_Marine* CASW_Marine_Resource::GetMarineEntity()
{
return m_MarineEntity;
Expand Down
5 changes: 3 additions & 2 deletions src/game/server/swarm/asw_marine_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class CASW_Marine_Resource : public CBaseEntity
CASW_Marine_Resource();
virtual ~CASW_Marine_Resource();

CNetworkVar( int, m_MarineProfileIndex );
CNetworkVar( int, m_MarineProfileIndex );
CNetworkVar( int, m_MarineProfileIndexDynamic );

CNetworkHandle (CASW_Marine, m_MarineEntity); // the actual marine
CNetworkHandle (CASW_Player, m_OriginalCommander); // the player who was first in charge of this marine
Expand Down Expand Up @@ -88,7 +89,7 @@ class CASW_Marine_Resource : public CBaseEntity

void SetMarineEntity(CASW_Marine* marine);
CASW_Marine* GetMarineEntity();
void SetProfileIndex(int ProfileIndex);
void SetProfileIndex( int ProfileIndex, int DynamicIndex );
int GetProfileIndex();
CASW_Marine_Profile* GetProfile();
bool IsInfested() { return m_bInfested; }
Expand Down
3 changes: 2 additions & 1 deletion src/game/shared/swarm/asw_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,8 @@ CASW_Marine_Resource *CAlienSwarm::RosterSelect( CASW_Player *pPlayer, int iProf

CASW_Marine_Resource *pMR = ( CASW_Marine_Resource * )CreateEntityByName( "asw_marine_resource" );
pMR->SetCommander( pPlayer );
pMR->SetProfileIndex( iProfileIndex );
COMPILE_TIME_ASSERT( ASW_NUM_MARINE_PROFILES == ASW_NUM_MARINES_PER_LOADOUT ); // TODO
pMR->SetProfileIndex( iProfileIndex, iProfileIndex );
if ( bForceInhabited )
{
pMR->SetInhabited( true );
Expand Down
39 changes: 33 additions & 6 deletions src/game/shared/swarm/rd_inventory_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,13 +924,23 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
if ( !pPlayer )
continue;

for ( int i = 0; i < RD_STEAM_INVENTORY_NUM_MEDAL_SLOTS; i++ )
{
CRD_ItemInstance &medalInstance = pPlayer->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MEDAL + i];

ModifyAccessoryDynamicPropValue( pPlayer->GetNPC(), pPlayer, medalInstance, iAccessoryID, iPropertyIndex, iAmount, bRelative, bAllowCheating );
}

CASW_Marine_Resource *pMR = pGameResource->GetFirstMarineResourceForPlayer( pPlayer );
if ( !pMR || pMR->m_OriginalCommander.Get() != pPlayer || ( !pMR->IsInhabited() && pMR->GetHealthPercent() > 0 ) )
continue;

CRD_ItemInstance &suitInstance = pPlayer->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->GetProfileIndex()];
if ( pMR->m_MarineProfileIndexDynamic >= 0 && pMR->m_MarineProfileIndexDynamic < ASW_NUM_MARINES_PER_LOADOUT )
{
CRD_ItemInstance &suitInstance = pPlayer->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->m_MarineProfileIndexDynamic];

ModifyAccessoryDynamicPropValue( pMR->GetMarineEntity(), pPlayer, suitInstance, iAccessoryID, iPropertyIndex, iAmount, bRelative, bAllowCheating );
ModifyAccessoryDynamicPropValue( pMR->GetMarineEntity(), pPlayer, suitInstance, iAccessoryID, iPropertyIndex, iAmount, bRelative, bAllowCheating );
}

for ( int j = 0; j < ASW_NUM_INVENTORY_SLOTS; j++ )
{
Expand Down Expand Up @@ -961,12 +971,19 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
return;
#endif

for ( int i = 0; i < RD_STEAM_INVENTORY_NUM_MEDAL_SLOTS; i++ )
{
CRD_ItemInstance &medalInstance = pNPC->GetCommander()->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MEDAL + i];

ModifyAccessoryDynamicPropValue( pNPC, pNPC->GetCommander(), medalInstance, iAccessoryID, iPropertyIndex, iAmount, bRelative, bAllowCheating );
}

if ( CASW_Marine *pMarine = CASW_Marine::AsMarine( pNPC ) )
{
CASW_Marine_Resource *pMR = pMarine->GetMarineResource();
if ( pMR && pMR->m_OriginalCommander.Get() == pMR->m_Commander.Get() )
if ( pMR && pMR->m_OriginalCommander.Get() == pMR->m_Commander.Get() && pMR->m_MarineProfileIndexDynamic >= 0 && pMR->m_MarineProfileIndexDynamic < ASW_NUM_MARINES_PER_LOADOUT )
{
CRD_ItemInstance &suitInstance = pMR->m_OriginalCommander->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->GetProfileIndex()];
CRD_ItemInstance &suitInstance = pMR->m_OriginalCommander->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->m_MarineProfileIndexDynamic];

ModifyAccessoryDynamicPropValue( pNPC, pMR->m_OriginalCommander, suitInstance, iAccessoryID, iPropertyIndex, iAmount, bRelative, bAllowCheating );
}
Expand Down Expand Up @@ -997,6 +1014,13 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
return;
#endif

for ( int i = 0; i < RD_STEAM_INVENTORY_NUM_MEDAL_SLOTS; i++ )
{
CRD_ItemInstance &medalInstance = pNPC->GetCommander()->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MEDAL + i];

ModifyAccessoryDynamicPropValue( pNPC, pNPC->GetCommander(), medalInstance, iAccessoryID, iPropertyIndex, iAmount, bRelative, bAllowCheating );
}

if ( CASW_Marine *pMarine = CASW_Marine::AsMarine( pNPC ) )
{
CASW_Marine_Resource *pMR = pMarine->GetMarineResource();
Expand All @@ -1006,9 +1030,12 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
#endif
)
{
CRD_ItemInstance &suitInstance = pMR->m_OriginalCommander->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->GetProfileIndex()];
if ( pMR->m_MarineProfileIndexDynamic >= 0 && pMR->m_MarineProfileIndexDynamic < ASW_NUM_MARINES_PER_LOADOUT )
{
CRD_ItemInstance &suitInstance = pMR->m_OriginalCommander->m_EquippedItemDataStatic[RD_STEAM_INVENTORY_EQUIP_SLOT_FIRST_MARINE + pMR->m_MarineProfileIndexDynamic];

ModifyAccessoryDynamicPropValue( pMarine, pMR->m_OriginalCommander, suitInstance, iAccessoryID, iPropertyIndex, iAmount, bRelative, bAllowCheating );
ModifyAccessoryDynamicPropValue( pMarine, pMR->m_OriginalCommander, suitInstance, iAccessoryID, iPropertyIndex, iAmount, bRelative, bAllowCheating );
}
}
}

Expand Down

0 comments on commit efe3b2e

Please sign in to comment.