@@ -174,7 +174,7 @@ void ZR_CreateOverlay(const char* pszOverlayParticlePath, float flAlpha, float f
174
174
UTIL_AddEntityIOEvent (particle, " Kill" , nullptr , nullptr , " " , flLifeTime + 1.0 );
175
175
}
176
176
177
- ZRModelEntry::ZRModelEntry (ZRModelEntry * modelEntry) :
177
+ ZRModelEntry::ZRModelEntry (std::shared_ptr< ZRModelEntry> modelEntry) :
178
178
szModelPath(modelEntry->szModelPath),
179
179
szColor(modelEntry->szColor)
180
180
{
@@ -237,7 +237,7 @@ ZRClass::ZRClass(ordered_json jsonKeys, std::string szClassname) :
237
237
238
238
for (auto & [key, jsonModelEntry] : jsonKeys[" models" ].items ())
239
239
{
240
- ZRModelEntry * modelEntry = new ZRModelEntry (jsonModelEntry);
240
+ std::shared_ptr< ZRModelEntry> modelEntry = std::make_shared< ZRModelEntry> (jsonModelEntry);
241
241
vecModels.AddToTail (modelEntry);
242
242
}
243
243
};
@@ -303,7 +303,7 @@ void ZRClass::Override(ordered_json jsonKeys, std::string szClassname)
303
303
304
304
for (auto & [key, jsonModelEntry] : jsonKeys[" models" ].items ())
305
305
{
306
- ZRModelEntry * modelEntry = new ZRModelEntry (jsonModelEntry);
306
+ std::shared_ptr< ZRModelEntry> modelEntry = std::make_shared< ZRModelEntry> (jsonModelEntry);
307
307
vecModels.AddToTail (modelEntry);
308
308
}
309
309
}
@@ -460,13 +460,13 @@ void CZRPlayerClassManager::LoadPlayerClass()
460
460
461
461
if (bHuman)
462
462
{
463
- ZRHumanClass * pHumanClass;
463
+ std::shared_ptr< ZRHumanClass> pHumanClass;
464
464
if (!szBase.empty ())
465
465
{
466
- ZRHumanClass * pBaseHumanClass = GetHumanClass (szBase.c_str ());
466
+ std::shared_ptr< ZRHumanClass> pBaseHumanClass = GetHumanClass (szBase.c_str ());
467
467
if (pBaseHumanClass)
468
468
{
469
- pHumanClass = new ZRHumanClass (pBaseHumanClass);
469
+ pHumanClass = std::make_shared< ZRHumanClass> (pBaseHumanClass);
470
470
pHumanClass->Override (jsonClass, szClassName);
471
471
}
472
472
else
@@ -476,7 +476,7 @@ void CZRPlayerClassManager::LoadPlayerClass()
476
476
}
477
477
}
478
478
else
479
- pHumanClass = new ZRHumanClass (jsonClass, szClassName);
479
+ pHumanClass = std::make_shared< ZRHumanClass> (jsonClass, szClassName);
480
480
481
481
m_HumanClassMap.Insert (hash_32_fnv1a_const (szClassName.c_str ()), pHumanClass);
482
482
@@ -487,13 +487,13 @@ void CZRPlayerClassManager::LoadPlayerClass()
487
487
}
488
488
else
489
489
{
490
- ZRZombieClass * pZombieClass;
490
+ std::shared_ptr< ZRZombieClass> pZombieClass;
491
491
if (!szBase.empty ())
492
492
{
493
- ZRZombieClass * pBaseZombieClass = GetZombieClass (szBase.c_str ());
493
+ std::shared_ptr< ZRZombieClass> pBaseZombieClass = GetZombieClass (szBase.c_str ());
494
494
if (pBaseZombieClass)
495
495
{
496
- pZombieClass = new ZRZombieClass (pBaseZombieClass);
496
+ pZombieClass = std::make_shared< ZRZombieClass> (pBaseZombieClass);
497
497
pZombieClass->Override (jsonClass, szClassName);
498
498
}
499
499
else
@@ -503,7 +503,7 @@ void CZRPlayerClassManager::LoadPlayerClass()
503
503
}
504
504
}
505
505
else
506
- pZombieClass = new ZRZombieClass (jsonClass, szClassName);
506
+ pZombieClass = std::make_shared< ZRZombieClass> (jsonClass, szClassName);
507
507
508
508
m_ZombieClassMap.Insert (hash_32_fnv1a_const (szClassName.c_str ()), pZombieClass);
509
509
if (bTeamDefault)
@@ -526,9 +526,9 @@ void split(const std::string& s, char delim, Out result)
526
526
*result++ = item;
527
527
}
528
528
529
- void CZRPlayerClassManager::ApplyBaseClass (ZRClass* pClass, CCSPlayerPawn * pPawn)
529
+ void CZRPlayerClassManager::ApplyBaseClass (std::shared_ptr< ZRClass> pClass, CCSPlayerPawn* pPawn)
530
530
{
531
- ZRModelEntry * pModelEntry = pClass->GetRandomModelEntry ();
531
+ std::shared_ptr< ZRModelEntry> pModelEntry = pClass->GetRandomModelEntry ();
532
532
Color clrRender;
533
533
V_StringToColor (pModelEntry->szColor .c_str (), clrRender);
534
534
@@ -547,36 +547,45 @@ void CZRPlayerClassManager::ApplyBaseClass(ZRClass* pClass, CCSPlayerPawn *pPawn
547
547
if (const auto pPlayer = pController != nullptr ? pController->GetZEPlayer () : nullptr )
548
548
{
549
549
pPlayer->SetMaxSpeed (pClass->flSpeed );
550
+ pPlayer->SetActiveZRClass (pClass);
551
+ pPlayer->SetActiveZRModel (pModelEntry);
550
552
}
551
553
552
554
// This has to be done a bit later
553
555
UTIL_AddEntityIOEvent (pPawn, " SetScale" , nullptr , nullptr , pClass->flScale );
554
556
}
555
557
556
558
// only changes that should not (directly) affect gameplay
557
- void CZRPlayerClassManager::ApplyBaseClassVisuals (ZRClass * pClass, CCSPlayerPawn * pPawn)
559
+ void CZRPlayerClassManager::ApplyBaseClassVisuals (std::shared_ptr< ZRClass> pClass, CCSPlayerPawn* pPawn)
558
560
{
559
- ZRModelEntry * pModelEntry = pClass->GetRandomModelEntry ();
561
+ std::shared_ptr< ZRModelEntry> pModelEntry = pClass->GetRandomModelEntry ();
560
562
Color clrRender;
561
563
V_StringToColor (pModelEntry->szColor .c_str (), clrRender);
562
564
563
565
pPawn->SetModel (pModelEntry->szModelPath .c_str ());
564
566
pPawn->m_clrRender = clrRender;
565
567
pPawn->AcceptInput (" Skin" , pModelEntry->GetRandomSkin ());
566
568
569
+ const auto pController = reinterpret_cast <CCSPlayerController*>(pPawn->GetController ());
570
+ if (const auto pPlayer = pController != nullptr ? pController->GetZEPlayer () : nullptr )
571
+ {
572
+ pPlayer->SetActiveZRClass (pClass);
573
+ pPlayer->SetActiveZRModel (pModelEntry);
574
+ }
575
+
567
576
// This has to be done a bit later
568
577
UTIL_AddEntityIOEvent (pPawn, " SetScale" , nullptr , nullptr , pClass->flScale );
569
578
}
570
579
571
- ZRHumanClass* CZRPlayerClassManager::GetHumanClass (const char * pszClassName)
580
+ std::shared_ptr< ZRHumanClass> CZRPlayerClassManager::GetHumanClass (const char * pszClassName)
572
581
{
573
582
uint16 index = m_HumanClassMap.Find (hash_32_fnv1a_const (pszClassName));
574
583
if (!m_HumanClassMap.IsValidIndex (index ))
575
584
return nullptr ;
576
585
return m_HumanClassMap[index ];
577
586
}
578
587
579
- void CZRPlayerClassManager::ApplyHumanClass (ZRHumanClass * pClass, CCSPlayerPawn * pPawn)
588
+ void CZRPlayerClassManager::ApplyHumanClass (std::shared_ptr< ZRHumanClass> pClass, CCSPlayerPawn* pPawn)
580
589
{
581
590
ApplyBaseClass (pClass, pPawn);
582
591
CCSPlayerController *pController = CCSPlayerController::FromPawn (pPawn);
@@ -609,7 +618,7 @@ void CZRPlayerClassManager::ApplyPreferredOrDefaultHumanClass(CCSPlayerPawn *pPa
609
618
610
619
// Get the human class user preference, or default if no class is set
611
620
int iSlot = pController->GetPlayerSlot ();
612
- ZRHumanClass* humanClass = nullptr ;
621
+ std::shared_ptr< ZRHumanClass> humanClass = nullptr ;
613
622
const char * sPreferredHumanClass = g_pUserPreferencesSystem->GetPreference (iSlot, HUMAN_CLASS_KEY_NAME);
614
623
615
624
// If the preferred human class exists and can be applied, override the default
@@ -633,7 +642,7 @@ void CZRPlayerClassManager::ApplyPreferredOrDefaultHumanClassVisuals(CCSPlayerPa
633
642
634
643
// Get the human class user preference, or default if no class is set
635
644
int iSlot = pController->GetPlayerSlot ();
636
- ZRHumanClass* humanClass = nullptr ;
645
+ std::shared_ptr< ZRHumanClass> humanClass = nullptr ;
637
646
const char * sPreferredHumanClass = g_pUserPreferencesSystem->GetPreference (iSlot, HUMAN_CLASS_KEY_NAME);
638
647
639
648
// If the preferred human class exists and can be applied, override the default
@@ -647,18 +656,18 @@ void CZRPlayerClassManager::ApplyPreferredOrDefaultHumanClassVisuals(CCSPlayerPa
647
656
return ;
648
657
}
649
658
650
- ApplyBaseClassVisuals ((ZRClass *) humanClass, pPawn);
659
+ ApplyBaseClassVisuals (humanClass, pPawn);
651
660
}
652
661
653
- ZRZombieClass* CZRPlayerClassManager::GetZombieClass (const char * pszClassName)
662
+ std::shared_ptr< ZRZombieClass> CZRPlayerClassManager::GetZombieClass (const char * pszClassName)
654
663
{
655
664
uint16 index = m_ZombieClassMap.Find (hash_32_fnv1a_const (pszClassName));
656
665
if (!m_ZombieClassMap.IsValidIndex (index ))
657
666
return nullptr ;
658
667
return m_ZombieClassMap[index ];
659
668
}
660
669
661
- void CZRPlayerClassManager::ApplyZombieClass (ZRZombieClass * pClass, CCSPlayerPawn * pPawn)
670
+ void CZRPlayerClassManager::ApplyZombieClass (std::shared_ptr< ZRZombieClass> pClass, CCSPlayerPawn* pPawn)
662
671
{
663
672
ApplyBaseClass (pClass, pPawn);
664
673
CCSPlayerController *pController = CCSPlayerController::FromPawn (pPawn);
@@ -673,7 +682,7 @@ void CZRPlayerClassManager::ApplyPreferredOrDefaultZombieClass(CCSPlayerPawn *pP
673
682
674
683
// Get the zombie class user preference, or default if no class is set
675
684
int iSlot = pController->GetPlayerSlot ();
676
- ZRZombieClass* zombieClass = nullptr ;
685
+ std::shared_ptr< ZRZombieClass> zombieClass = nullptr ;
677
686
const char * sPreferredZombieClass = g_pUserPreferencesSystem->GetPreference (iSlot, ZOMBIE_CLASS_KEY_NAME);
678
687
679
688
// If the preferred zombie class exists and can be applied, override the default
@@ -690,7 +699,7 @@ void CZRPlayerClassManager::ApplyPreferredOrDefaultZombieClass(CCSPlayerPawn *pP
690
699
ApplyZombieClass (zombieClass, pPawn);
691
700
}
692
701
693
- void CZRPlayerClassManager::GetZRClassList (int iTeam, CUtlVector<ZRClass*> & vecClasses, CCSPlayerController* pController)
702
+ void CZRPlayerClassManager::GetZRClassList (int iTeam, CUtlVector<std::shared_ptr< ZRClass>>& vecClasses, CCSPlayerController* pController)
694
703
{
695
704
if (iTeam == CS_TEAM_T || iTeam == CS_TEAM_NONE)
696
705
{
@@ -1187,7 +1196,7 @@ void ZR_InfectMotherZombie(CCSPlayerController *pVictimController, std::vector<S
1187
1196
pVictimController->SwitchTeam (CS_TEAM_T);
1188
1197
pVictimPawn->EmitSound (" zr.amb.scream" );
1189
1198
1190
- ZRZombieClass * pClass = g_pZRPlayerClassManager->GetZombieClass (" MotherZombie" );
1199
+ std::shared_ptr< ZRZombieClass> pClass = g_pZRPlayerClassManager->GetZombieClass (" MotherZombie" );
1191
1200
if (pClass)
1192
1201
g_pZRPlayerClassManager->ApplyZombieClass (pClass, pVictimPawn);
1193
1202
else
@@ -1730,7 +1739,7 @@ CON_COMMAND_CHAT(zclass, "<teamname/class name/number> - Find and select your Z:
1730
1739
return ;
1731
1740
}
1732
1741
1733
- CUtlVector<ZRClass* > vecClasses;
1742
+ CUtlVector<std::shared_ptr< ZRClass> > vecClasses;
1734
1743
int iSlot = player->GetPlayerSlot ();
1735
1744
bool bListingZombie = true ;
1736
1745
bool bListingHuman = true ;
@@ -1773,7 +1782,7 @@ CON_COMMAND_CHAT(zclass, "<teamname/class name/number> - Find and select your Z:
1773
1782
{
1774
1783
const char * sClassName = vecClasses[i]->szClassName .c_str ();
1775
1784
bool bClassMatches = !V_stricmp (sClassName , args[1 ]) || (V_StringToInt32 (args[1 ], -1 ) - 1 ) == i;
1776
- ZRClass* pClass = vecClasses[i];
1785
+ std::shared_ptr< ZRClass> pClass = vecClasses[i];
1777
1786
1778
1787
if (bClassMatches)
1779
1788
{
0 commit comments