Skip to content

Commit 74df27d

Browse files
committed
emulate squad-wide pickups by allowing materials picked up by other marines to count as pickups of materials of the same type that are not located in the mission.
1 parent e31611c commit 74df27d

File tree

7 files changed

+205
-10
lines changed

7 files changed

+205
-10
lines changed

src/game/client/swarm/vgui/asw_hud_chat.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ static const char *const s_szItemPickupMessages[] =
374374
"#rd_player_found_promo_item",
375375
"#rd_player_found_crafting_material",
376376
"#rd_player_found_crafting_materials",
377+
"#rd_player_found_crafting_materials_assist"
377378
};
378379

379380
void CHudChat::MsgFunc_RDItemPickupMsg( bf_read &msg )
@@ -424,6 +425,28 @@ void CHudChat::MsgFunc_RDItemPickupMsg( bf_read &msg )
424425
return;
425426
}
426427

428+
if ( iMessage == 2 )
429+
{
430+
C_ASW_Player *pLocalPlayer = C_ASW_Player::GetLocalASWPlayer();
431+
if ( pLocalPlayer && pPlayer != pLocalPlayer && pLocalPlayer->GetNPC() && pLocalPlayer->GetNPC()->GetHealth() > 0 )
432+
{
433+
for ( int i = 0; i < NUM_RD_CRAFTING_MATERIAL_TYPES; i++ )
434+
{
435+
if ( g_RD_Crafting_Material_Info[i].m_iItemDef != iDef )
436+
{
437+
continue;
438+
}
439+
440+
if ( g_RD_Crafting_Material_Rarity_Info[g_RD_Crafting_Material_Info[i].m_iRarity].m_bAllowPickupAssist )
441+
{
442+
ReactiveDropInventory::PickUpCraftingMaterialAssist( static_cast< RD_Crafting_Material_t >( i ) );
443+
}
444+
445+
break;
446+
}
447+
}
448+
}
449+
427450
wchar_t wszItemName[256];
428451
wszItemName[0] = COLOR_ACHIEVEMENT;
429452
V_UTF8ToUnicode( pDef->Name.Get(), &wszItemName[1], sizeof( wszItemName ) - sizeof( wchar_t ) );

src/game/shared/swarm/rd_crafting_defs.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ const RD_Crafting_Material_Info g_RD_Crafting_Material_Info[] =
8888

8989
const RD_Crafting_Material_Rarity_Info g_RD_Crafting_Material_Rarity_Info[] =
9090
{
91-
{ "#rd_crafting_material_rarity_industrial", "RD_Crafting_Material_Found.Industrial", true },
92-
{ "#rd_crafting_material_rarity_bulk", "RD_Crafting_Material_Found.Bulk", true },
93-
{ "#rd_crafting_material_rarity_alien", "RD_Crafting_Material_Found.Alien", true },
94-
{ "#rd_crafting_material_rarity_tech", "RD_Crafting_Material_Found.Tech", true },
95-
{ "#rd_crafting_material_rarity_salvaged", "RD_Crafting_Material_Found.Salvaged", true },
91+
{ "#rd_crafting_material_rarity_industrial", "RD_Crafting_Material_Found.Industrial", true, true },
92+
{ "#rd_crafting_material_rarity_bulk", "RD_Crafting_Material_Found.Bulk", true, true },
93+
{ "#rd_crafting_material_rarity_alien", "RD_Crafting_Material_Found.Alien", true, true },
94+
{ "#rd_crafting_material_rarity_tech", "RD_Crafting_Material_Found.Tech", true, true },
95+
{ "#rd_crafting_material_rarity_salvaged", "RD_Crafting_Material_Found.Salvaged", true, true },
9696
};
9797

9898
// hard-coded so we don't have to search the entire item ID space to figure out which items can appear in a box.

src/game/shared/swarm/rd_crafting_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct RD_Crafting_Material_Rarity_Info
8282
const char *m_szDisplayName;
8383
const char *m_szPickupSound;
8484
bool m_bCanFindInMission;
85+
bool m_bAllowPickupAssist;
8586
};
8687

8788
struct RD_Crafting_Contains_Any_List

src/game/shared/swarm/rd_inventory_command.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,30 @@ static bool PreValidateInventoryCommand( CASW_Player *pPlayer, EInventoryCommand
461461
Warning( "Player %s sent invalid InvCmdInit - out of range location number for material pickup (%d).\n", pPlayer->GetASWNetworkID(), args[0] );
462462
return false;
463463
}
464+
#endif
465+
break;
466+
case INVCMD_MATERIAL_PICKUP_ASSIST:
467+
#ifdef RD_7A_DROPS
468+
if ( args.Count() != 2 )
469+
{
470+
Warning( "Player %s sent invalid InvCmdInit - wrong number of args for material pickup assist (%d).\n", pPlayer->GetASWNetworkID(), args.Count() );
471+
return false;
472+
}
473+
if ( args[0] < 0 || args[0] >= NUM_RD_CRAFTING_MATERIAL_TYPES )
474+
{
475+
Warning( "Player %s sent invalid InvCmdInit - out of range location number for material pickup assist (%d).\n", pPlayer->GetASWNetworkID(), args[0] );
476+
return false;
477+
}
478+
if ( !g_RD_Crafting_Material_Rarity_Info[g_RD_Crafting_Material_Info[args[0]].m_iRarity].m_bAllowPickupAssist )
479+
{
480+
Warning( "Player %s sent invalid InvCmdInit - invalid item type for material pickup assist (%d).\n", pPlayer->GetASWNetworkID(), args[0] );
481+
return false;
482+
}
483+
if ( args[1] < 0 )
484+
{
485+
Warning( "Player %s sent invalid InvCmdInit - negative quantity for material pickup assist (%d).\n", pPlayer->GetASWNetworkID(), args[1] );
486+
return false;
487+
}
464488
#endif
465489
break;
466490
case INVCMD_PROMO_DROP:
@@ -848,10 +872,25 @@ static void ExecuteInventoryCommand( CASW_Player *pPlayer, EInventoryCommand eCm
848872

849873
CReliableBroadcastRecipientFilter filter;
850874
UserMessageBegin( filter, "RDItemPickupMsg" );
851-
WRITE_BYTE( 2 );
852-
WRITE_BYTE( pPlayer->entindex() );
853-
WRITE_LONG( g_RD_Crafting_Material_Info[eMaterial].m_iItemDef );
854-
WRITE_LONG( nTotalQuantity );
875+
WRITE_BYTE( 2 );
876+
WRITE_BYTE( pPlayer->entindex() );
877+
WRITE_LONG( g_RD_Crafting_Material_Info[eMaterial].m_iItemDef );
878+
WRITE_LONG( nTotalQuantity );
879+
MessageEnd();
880+
#endif
881+
break;
882+
}
883+
case INVCMD_MATERIAL_PICKUP_ASSIST:
884+
{
885+
#ifdef RD_7A_DROPS
886+
// don't bother checking the inventory result for now; just require one so it's hard to make a fake message
887+
888+
CReliableBroadcastRecipientFilter filter;
889+
UserMessageBegin( filter, "RDItemPickupMsg" );
890+
WRITE_BYTE( 3 );
891+
WRITE_BYTE( pPlayer->entindex() );
892+
WRITE_LONG( g_RD_Crafting_Material_Info[args[0]].m_iItemDef );
893+
WRITE_LONG( args[1] );
855894
MessageEnd();
856895
#endif
857896
break;

src/game/shared/swarm/rd_inventory_command.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum EInventoryCommand
88
INVCMD_MARINE_RESOURCE_EQUIPS,
99
INVCMD_MATERIAL_SPAWN,
1010
INVCMD_MATERIAL_PICKUP,
11+
INVCMD_MATERIAL_PICKUP_ASSIST,
1112
INVCMD_PROMO_DROP,
1213
};
1314

src/game/shared/swarm/rd_inventory_shared.cpp

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
11921192
case CRAFT_DELETE:
11931193
return true;
11941194
case CRAFT_PICKUP_MATERIAL:
1195+
case CRAFT_PICKUP_MATERIAL_ASSIST:
11951196
case CRAFT_BTS:
11961197
case CRAFT_DROP:
11971198
case CRAFT_PROMO:
@@ -1225,6 +1226,7 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
12251226
case CRAFT_DYNAMIC_PROPERTY_INIT_RETRY:
12261227
return pTask->m_iAccessoryDef != BaseModUI::ItemShowcase::MODE_ITEM_DROP;
12271228
case CRAFT_PICKUP_MATERIAL:
1229+
case CRAFT_PICKUP_MATERIAL_ASSIST:
12281230
// returning false to avoid popping up modal errors during gameplay
12291231
return false;
12301232
case CRAFT_BTS:
@@ -1348,6 +1350,51 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
13481350
args.AddToTail( pTask->m_iAccessoryDef );
13491351
UTIL_RD_SendInventoryCommand( INVCMD_MATERIAL_PICKUP, args, pTask->m_hResult );
13501352
}
1353+
#endif
1354+
break;
1355+
case CRAFT_PICKUP_MATERIAL_ASSIST:
1356+
#ifdef RD_7A_DROPS
1357+
{
1358+
RD_Crafting_Material_t eMaterialType = static_cast< RD_Crafting_Material_t >( pTask->m_iAccessoryDef );
1359+
RD_Crafting_Material_Rarity_t eMaterialRarity = g_RD_Crafting_Material_Info[eMaterialType].m_iRarity;
1360+
const char *szPickupSound = g_RD_Crafting_Material_Rarity_Info[eMaterialRarity].m_szPickupSound;
1361+
1362+
if ( szPickupSound )
1363+
{
1364+
CLocalPlayerFilter filter;
1365+
C_BaseEntity::EmitSound( filter, -1/*SOUND_FROM_LOCAL_PLAYER*/, szPickupSound );
1366+
}
1367+
1368+
uint32 nCount{};
1369+
pInventory->GetResultItems( pTask->m_hResult, NULL, &nCount );
1370+
CUtlVector<SteamItemDetails_t> diff;
1371+
diff.AddMultipleToTail( nCount );
1372+
pInventory->GetResultItems( pTask->m_hResult, diff.Base(), &nCount );
1373+
1374+
int added = 0;
1375+
FOR_EACH_VEC( diff, i )
1376+
{
1377+
if ( diff[i].m_unFlags & ( k_ESteamItemConsumed | k_ESteamItemRemoved ) )
1378+
{
1379+
continue;
1380+
}
1381+
1382+
if ( const ItemInstance_t *pCached = GetLocalItemCache( diff[i].m_itemId ) )
1383+
{
1384+
diff[i].m_unQuantity = MAX( 0, int( diff[i].m_unQuantity ) - pCached->Quantity );
1385+
}
1386+
1387+
if ( diff[i].m_iDefinition == g_RD_Crafting_Material_Info[eMaterialType].m_iItemDef )
1388+
{
1389+
added = diff[i].m_unQuantity;
1390+
}
1391+
}
1392+
1393+
CUtlVector<int> args;
1394+
args.AddToTail( eMaterialType );
1395+
args.AddToTail( added );
1396+
UTIL_RD_SendInventoryCommand( INVCMD_MATERIAL_PICKUP_ASSIST, args, pTask->m_hResult );
1397+
}
13511398
#endif
13521399
break;
13531400
case CRAFT_BTS:
@@ -2174,7 +2221,8 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
21742221
}
21752222

21762223
Assert( eMaterial > RD_CRAFTING_MATERIAL_NONE && eMaterial < NUM_RD_CRAFTING_MATERIAL_TYPES );
2177-
if ( eMaterial <= 0 || eMaterial >= NUM_RD_CRAFTING_MATERIAL_TYPES)
2224+
Assert( g_RD_Crafting_Material_Rarity_Info[g_RD_Crafting_Material_Info[eMaterial].m_iRarity].m_bCanFindInMission );
2225+
if ( eMaterial <= 0 || eMaterial >= NUM_RD_CRAFTING_MATERIAL_TYPES )
21782226
{
21792227
Warning( "Cannot pick up crafting material at location %d with out of range type %d!\n", iLocation, eMaterial );
21802228
return;
@@ -2206,6 +2254,77 @@ static class CRD_Inventory_Manager final : public CAutoGameSystem, public CGameE
22062254

22072255
m_CraftingMaterialToken[iLocation] = k_SteamItemInstanceIDInvalid;
22082256
// leave m_CraftingMaterialType[iLocation] set
2257+
if ( ItemInstance_t *pConsumed = GetLocalItemCacheForModify( m_CraftingMaterialToken[iLocation] ) )
2258+
{
2259+
pConsumed->Quantity--;
2260+
}
2261+
2262+
}
2263+
2264+
void PickUpCraftingMaterialAssist( RD_Crafting_Material_t eMaterial )
2265+
{
2266+
GET_INVENTORY_OR_BAIL;
2267+
2268+
Assert( eMaterial > RD_CRAFTING_MATERIAL_NONE && eMaterial < NUM_RD_CRAFTING_MATERIAL_TYPES );
2269+
Assert( g_RD_Crafting_Material_Rarity_Info[g_RD_Crafting_Material_Info[eMaterial].m_iRarity].m_bCanFindInMission );
2270+
Assert( g_RD_Crafting_Material_Rarity_Info[g_RD_Crafting_Material_Info[eMaterial].m_iRarity].m_bAllowPickupAssist );
2271+
if ( eMaterial <= 0 || eMaterial >= NUM_RD_CRAFTING_MATERIAL_TYPES )
2272+
{
2273+
Warning( "Cannot pick up crafting material for assist with out of range type %d!\n", eMaterial );
2274+
return;
2275+
}
2276+
2277+
CUtlVector<ReactiveDropInventory::ItemInstance_t> optin;
2278+
ReactiveDropInventory::GetItemsForSlot( optin, "crafting_material_beta_opt_in" );
2279+
if ( !rd_crafting_material_pickups.GetBool() || !optin.Count() )
2280+
{
2281+
// we're pretending we don't have any material tokens.
2282+
return;
2283+
}
2284+
2285+
SteamItemDef_t generate[1] = { g_RD_Crafting_Material_Info[eMaterial].m_iRedeemDef };
2286+
SteamItemInstanceID_t consume[1] = { k_SteamItemInstanceIDInvalid };
2287+
uint32 one[1] = { 1 };
2288+
2289+
CUtlVector<ItemInstance_t> tokens;
2290+
GetItemsForDef( tokens, g_RD_Crafting_Material_Info[eMaterial].m_iTokenDef );
2291+
2292+
FOR_EACH_VEC( tokens, i )
2293+
{
2294+
int count = tokens[i].Quantity;
2295+
for ( int iLocation = 0; iLocation < RD_MAX_CRAFTING_MATERIAL_SPAWN_LOCATIONS; iLocation++ )
2296+
{
2297+
if ( m_CraftingMaterialToken[iLocation] == tokens[i].ItemID )
2298+
{
2299+
count--;
2300+
}
2301+
}
2302+
2303+
if ( count > 0 )
2304+
{
2305+
consume[0] = tokens[i].ItemID;
2306+
break;
2307+
}
2308+
}
2309+
2310+
if ( consume[0] == k_SteamItemInstanceIDInvalid )
2311+
{
2312+
// don't have a spare token.
2313+
return;
2314+
}
2315+
2316+
SteamInventoryResult_t *pResult = AddCraftItemTask( CRAFT_PICKUP_MATERIAL_ASSIST, eMaterial, consume[0] );
2317+
pInventory->ExchangeItems( pResult, generate, one, 1, consume, one, 1 );
2318+
2319+
if ( rd_debug_inventory.GetBool() )
2320+
{
2321+
Msg( "[C] Sent request to pick up %s (assist) (handle: %08x)\n", g_RD_Crafting_Material_Info[eMaterial].m_szName, *pResult );
2322+
}
2323+
2324+
if ( ItemInstance_t *pConsumed = GetLocalItemCacheForModify( consume[0] ) )
2325+
{
2326+
pConsumed->Quantity--;
2327+
}
22092328
}
22102329
#endif
22112330

@@ -3489,6 +3608,15 @@ namespace ReactiveDropInventory
34893608

34903609
s_RD_Inventory_Manager.PickUpCraftingMaterialAtLocation( iLocation, eMaterial );
34913610
}
3611+
void PickUpCraftingMaterialAssist( RD_Crafting_Material_t eMaterial )
3612+
{
3613+
if ( engine->IsPlayingDemo() )
3614+
{
3615+
return;
3616+
}
3617+
3618+
s_RD_Inventory_Manager.PickUpCraftingMaterialAssist( eMaterial );
3619+
}
34923620
int GetCraftingMaterialsFound()
34933621
{
34943622
int nCount = 0;

src/game/shared/swarm/rd_inventory_shared.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ namespace ReactiveDropInventory
190190
void DeleteNotificationItem( SteamItemInstanceID_t id );
191191
#ifdef RD_7A_DROPS
192192
void PickUpCraftingMaterialAtLocation( int iLocation, RD_Crafting_Material_t eMaterial );
193+
void PickUpCraftingMaterialAssist( RD_Crafting_Material_t eMaterial );
193194
int GetCraftingMaterialsFound();
194195
int GetCraftingMaterialsMissed();
195196
#endif
@@ -207,6 +208,8 @@ namespace ReactiveDropInventory
207208
CRAFT_CLAIM_MAJOR,
208209
// picking up a crafting material. silent while in progress. in-game notification when complete.
209210
CRAFT_PICKUP_MATERIAL,
211+
// someone else picked up a material, and we get it too.
212+
CRAFT_PICKUP_MATERIAL_ASSIST,
210213
// behind-the-scenes item exchange. no notification.
211214
CRAFT_BTS,
212215
// set dynamic properties on newly created item to 0. modal while in progress. notifies user when complete (replaces notification from craft task that queued this).

0 commit comments

Comments
 (0)