This repository has been archived by the owner on Aug 30, 2018. It is now read-only.
forked from ppittle/AlienSwarmDirectorMod
-
Notifications
You must be signed in to change notification settings - Fork 2
/
asw_player_experience.cpp
838 lines (734 loc) · 24.2 KB
/
asw_player_experience.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
#include "cbase.h"
#ifdef CLIENT_DLL
#define CASW_Equip_Req C_ASW_Equip_Req
#include "c_asw_player.h"
#include "c_asw_marine.h"
#include "c_asw_game_resource.h"
#include "c_asw_marine_resource.h"
#include "asw_input.h"
#include "c_asw_weapon.h"
#include "c_asw_game_resource.h"
#include "clientmode_asw.h"
#include "c_asw_objective.h"
#include "c_asw_debrief_stats.h"
#include "asw_hud_objective.h"
#include "asw_equip_req.h"
#include "achievementmgr.h"
#include "asw_achievements.h"
#include "asw_medal_store.h"
#include "asw_equipment_list.h"
#include "asw_marine_profile.h"
#include "clientmode_asw.h"
#ifndef _X360
#include "steam/isteamuserstats.h"
#include "steam/isteamfriends.h"
#include "steam/isteamutils.h"
#include "steam/steam_api.h"
#include "c_asw_steamstats.h"
#endif
#define CASW_Marine C_ASW_Marine
#define CASW_Marine_Resource C_ASW_Marine_Resource
#define CASW_Weapon C_ASW_Weapon
#define CASW_Debrief_Stats C_ASW_Debrief_Stats
#define CASW_Objective C_ASW_Objective
#else
#include "player.h"
#include "asw_player.h"
#include "asw_marine.h"
#include "asw_marine_resource.h"
#include "asw_weapon.h"
#include "asw_objective.h"
#include "asw_debrief_stats.h"
#include "asw_achievements.h"
#ifndef _X360
#include "steam/isteamgameserverstats.h"
#include "gameinterface.h"
#endif
#endif
#include "asw_gamerules.h"
#include "asw_shareddefs.h"
#include "asw_weapon_parse.h"
#include "asw_medals_shared.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern ConVar asw_skill;
ConVar asw_show_xp_details( "asw_show_xp_details", "0", FCVAR_REPLICATED, "Output XP rewards to the console" );
// Experience levels. NOTE: Level shown in the UI is one higher than used in code
int g_iLevelExperience[ ASW_NUM_EXPERIENCE_LEVELS ]=
{
1000, // XP under this = 1evel 1 in UI
2050,
3150,
4300,
5500, // XP under this = 1evel 5 in UI
6750,
8050,
9400,
10800,
12250, // XP under this = 1evel 10 in UI
13750,
15300,
16900,
18550,
20250, // XP under this = 1evel 15 in UI
22000,
23800,
25650,
27550,
29500, // XP under this = 1evel 20 in UI
31500,
33550,
35650,
37800,
40000, // XP under this = 1evel 25 in UI
42250, // XP under this = level 26 in UI, XP equal to this = level 27 in the UI
};
int g_iXPAward[ ASW_NUM_XP_TYPES ]=
{
1000, // ASW_XP_MISSION,
100, // ASW_XP_KILLS,
100, // ASW_XP_TIME,
100, // ASW_XP_FRIENDLY_FIRE,
100, // ASW_XP_DAMAGE_TAKEN,
50, // ASW_XP_HEALING,
50, // ASW_XP_HACKING
};
// scalar applied to XP required to level, based on your current promotion
float g_flPromotionXPScale[ ASW_PROMOTION_CAP + 1 ]=
{
1.0f,
1.0f,
1.0f,
1.0f,
2.0f,
4.0f,
6.0f,
};
#define ASW_MISSION_XP_AWARD_ON_FAILURE 750 // XP award divided up between objectives
// NOTE: If you change this, update the labels in CExperienceReport::OnThink too
float g_flXPDifficultyScale[5]=
{
0.5f, // easy
1.0f, // normal
1.2f, // hard
1.4f, // insane
1.5f, // imba
};
// Weapon unlocks
struct ASW_Weapon_Unlock
{
ASW_Weapon_Unlock( const char *szWeaponClass, int iLevel )
{
m_pszWeaponClass = szWeaponClass;
m_iLevel = iLevel;
}
const char *m_pszWeaponClass;
int m_iLevel; // player level needed to unlock
};
// Keep Equipment.res in the same order as this
ASW_Weapon_Unlock g_WeaponUnlocks[]=
{
ASW_Weapon_Unlock( "asw_weapon_normal_armor", 1 ),//
ASW_Weapon_Unlock( "asw_weapon_shotgun", 2 ),
ASW_Weapon_Unlock( "asw_weapon_buff_grenade", 3 ),//
ASW_Weapon_Unlock( "asw_weapon_tesla_gun", 4 ),
ASW_Weapon_Unlock( "asw_weapon_hornet_barrage", 5 ),//
ASW_Weapon_Unlock( "asw_weapon_railgun", 6 ),
ASW_Weapon_Unlock( "asw_weapon_freeze_grenades", 7 ),//
ASW_Weapon_Unlock( "asw_weapon_heal_gun", 8 ),
ASW_Weapon_Unlock( "asw_weapon_stim", 9 ),//
ASW_Weapon_Unlock( "asw_weapon_pdw", 10 ),
ASW_Weapon_Unlock( "asw_weapon_tesla_trap", 11 ),//
ASW_Weapon_Unlock( "asw_weapon_flamer", 12 ),
ASW_Weapon_Unlock( "asw_weapon_electrified_armor", 13 ),//
ASW_Weapon_Unlock( "asw_weapon_sentry_freeze", 14 ),
ASW_Weapon_Unlock( "asw_weapon_mines", 15 ),//
ASW_Weapon_Unlock( "asw_weapon_minigun", 16 ),
ASW_Weapon_Unlock( "asw_weapon_flashlight", 17 ),//
ASW_Weapon_Unlock( "asw_weapon_sniper_rifle", 18 ),
ASW_Weapon_Unlock( "asw_weapon_fist", 19 ),//
ASW_Weapon_Unlock( "asw_weapon_sentry_flamer", 20 ),
ASW_Weapon_Unlock( "asw_weapon_grenades", 21 ),//
ASW_Weapon_Unlock( "asw_weapon_chainsaw", 22 ),
ASW_Weapon_Unlock( "asw_weapon_night_vision", 23 ),//
ASW_Weapon_Unlock( "asw_weapon_sentry_cannon", 24 ),
ASW_Weapon_Unlock( "asw_weapon_smart_bomb", 25 ),//
ASW_Weapon_Unlock( "asw_weapon_grenade_launcher", 26 ), // ASW_NUM_EXPERIENCE_LEVELS
};
// given an Experience total, this tells you the player's level
int LevelFromXP( int iExperience, int iPromotion )
{
iExperience = MIN( iExperience, ASW_XP_CAP * g_flPromotionXPScale[ iPromotion ] );
for ( int i = 0; i < NELEMS( g_iLevelExperience ); i++ )
{
int iRequiredXP = (int) ( g_flPromotionXPScale[ iPromotion ] * g_iLevelExperience[ i ] );
if ( iExperience < iRequiredXP )
{
return i;
}
}
return NELEMS( g_iLevelExperience );
}
void CASW_Player::CalculateEarnedXP()
{
for ( int i = 0; i < ASW_NUM_XP_TYPES; i++ )
{
m_iEarnedXP[ i ] = 0;
m_iStatNumXP[ i ] = 0;
}
// no XP if you don't have a marine resource
if ( !ASWGameResource() || !ASWGameResource()->GetFirstMarineResourceForPlayer( this ) )
return;
if ( ASWGameRules() && ASWGameRules()->m_bCheated.Get() )
return;
#ifdef CLIENT_DLL
if ( engine->IsPlayingDemo() )
return;
#endif
int iNumObjectives = 0;
float flNumObjectivesComplete = 0;
float flPartialScale = 1.0f; // this is used to scale XP rewards that should be small if you've only completed part of the mission
if ( ASWGameRules()->GetMissionSuccess() )
{
// XP for completing the mission
m_iEarnedXP[ ASW_XP_MISSION ] = g_iXPAward[ ASW_XP_MISSION ];
m_iStatNumXP[ ASW_XP_MISSION ] = 100;
}
else
{
// if failed the mission, award XP per completed objective
for ( int i = 0; i < ASW_MAX_OBJECTIVES; i++ )
{
CASW_Objective *pObjective = ASWGameResource()->GetObjective( i );
if ( pObjective )
{
iNumObjectives++;
flNumObjectivesComplete += pObjective->GetObjectiveProgress();
}
}
if ( iNumObjectives > 0 )
{
flPartialScale = ( flNumObjectivesComplete / (float) iNumObjectives );
m_iEarnedXP[ ASW_XP_MISSION ] += g_iXPAward[ ASW_XP_MISSION ] * flPartialScale;
m_iStatNumXP[ ASW_XP_MISSION ] = flPartialScale * 100.0f;
}
else
{
flPartialScale = 0.0f;
}
}
// query debrief stats to see how much XP we should award based on performance
CASW_Debrief_Stats *pDebrief = GetDebriefStats();
if ( pDebrief )
{
CASW_Marine_Resource *pMR = ASWGameResource()->GetFirstMarineResourceForPlayer( this );
if ( pMR )
{
int iMarineIndex = ASWGameResource()->GetMarineResourceIndex( pMR );
if ( iMarineIndex != -1 )
{
// XP per kill, capped
m_iEarnedXP[ ASW_XP_KILLS ] = clamp( pDebrief->GetKills( iMarineIndex ), 0, g_iXPAward[ ASW_XP_KILLS ] );
m_iStatNumXP[ ASW_XP_KILLS ] = pDebrief->GetKills( iMarineIndex );
if ( ASWGameRules()->GetMissionSuccess() )
{
// FF
m_iEarnedXP[ ASW_XP_FRIENDLY_FIRE ] = clamp( g_iXPAward[ ASW_XP_FRIENDLY_FIRE ] - pDebrief->GetFriendlyFire( iMarineIndex ), 0, g_iXPAward[ ASW_XP_FRIENDLY_FIRE ] );
m_iStatNumXP[ ASW_XP_FRIENDLY_FIRE ] = pDebrief->GetFriendlyFire( iMarineIndex );
}
if ( ASWGameRules()->GetMissionSuccess() )
{
// damage taken
m_iEarnedXP[ ASW_XP_DAMAGE_TAKEN ] = clamp( g_iXPAward[ ASW_XP_DAMAGE_TAKEN ] - pDebrief->GetDamageTaken( iMarineIndex ), 0, g_iXPAward[ ASW_XP_DAMAGE_TAKEN ] );
m_iStatNumXP[ ASW_XP_DAMAGE_TAKEN ] = pDebrief->GetDamageTaken( iMarineIndex );
}
// healing
m_iEarnedXP[ ASW_XP_HEALING ] = clamp( pDebrief->GetHealthHealed( iMarineIndex ) / 10, 0, g_iXPAward[ ASW_XP_HEALING ] );
m_iStatNumXP[ ASW_XP_HEALING ] = pDebrief->GetHealthHealed( iMarineIndex );
// hacking
if ( pDebrief->GetFastHacks( iMarineIndex ) >= 2 )
{
m_iEarnedXP[ ASW_XP_HACKING ] = g_iXPAward[ ASW_XP_HACKING ];
}
else if ( pDebrief->GetFastHacks( iMarineIndex ) >= 1 )
{
m_iEarnedXP[ ASW_XP_HACKING ] = g_iXPAward[ ASW_XP_HACKING ] / 2;
}
else
{
m_iEarnedXP[ ASW_XP_HACKING ] = 0;
}
m_iStatNumXP[ ASW_XP_HACKING ] = pDebrief->GetFastHacks( iMarineIndex );
}
if ( ASWGameRules()->GetMissionSuccess() )
{
// time
int speedrun_time = pDebrief->GetSpeedrunTime();
int nTimeTaken = pDebrief->GetTimeTaken();
// award full XP if you get less than the speedrun_time
const float flMaxTime = 5.0f * 60.0f; // max of 5 minutes over
if ( nTimeTaken <= speedrun_time )
{
m_iEarnedXP[ ASW_XP_TIME ] = g_iXPAward[ ASW_XP_TIME ];
m_iStatNumXP[ ASW_XP_TIME ] = nTimeTaken;
}
else
{
float flReduction = 1.0f - clamp( static_cast<float>( nTimeTaken - speedrun_time ) / flMaxTime, 0.0f, 1.0f );
m_iEarnedXP[ ASW_XP_TIME ] = g_iXPAward[ ASW_XP_TIME ] * flReduction;
m_iStatNumXP[ ASW_XP_TIME ] = nTimeTaken;
}
}
// medals XP
#ifdef GAME_DLL
const char *szMedalString = pMR->m_MedalsAwarded.Get();
#else
const char *szMedalString = pMR->m_MedalsAwarded;
#endif
const char *p = szMedalString;
char token[128];
p = nexttoken( token, p, ' ' );
while ( Q_strlen( token ) > 0 )
{
int iMedalIndex = atoi(token);
m_iEarnedXP[ ASW_XP_MEDALS ] += GetXPForMedal( iMedalIndex );
if (p)
p = nexttoken( token, p, ' ' );
else
token[0] = '\0';
}
// achievement XP
#ifdef GAME_DLL
CUtlVector<int> *pAchievementsEarned = &pMR->m_aAchievementsEarned;
#else
CUtlVector<int> *pAchievementsEarned = &m_aNonLocalPlayerAchievementsEarned;
if ( IsLocalPlayer() )
{
pAchievementsEarned = &GetClientModeASW()->m_aAchievementsEarned;
}
#endif
for ( int i = 0; i < pAchievementsEarned->Count(); i++ )
{
m_iEarnedXP[ ASW_XP_MEDALS ] += GetXPForMedal( -(*pAchievementsEarned)[i] );
}
}
}
for ( int i = 0; i < ASW_XP_TOTAL; i++ )
{
m_iEarnedXP[ ASW_XP_TOTAL ] += m_iEarnedXP[ i ];
}
// apply difficulty bonus
if ( ASWGameRules() )
{
m_iEarnedXP[ ASW_XP_TOTAL ] *= g_flXPDifficultyScale[ ASWGameRules()->GetSkillLevel() - 1 ];
}
if ( asw_show_xp_details.GetBool() )
{
Msg( "[%s] Awarding XP to player %s:\n", IsServerDll() ? "Server" : "Client", GetPlayerName() );
Msg( " EarnedXP[ ASW_XP_MISSION ] = %d\n", m_iEarnedXP[ ASW_XP_MISSION ] );
Msg( " EarnedXP[ ASW_XP_KILLS ] = %d\n", m_iEarnedXP[ ASW_XP_KILLS ] );
Msg( " EarnedXP[ ASW_XP_TIME ] = %d\n", m_iEarnedXP[ ASW_XP_TIME ] );
Msg( " EarnedXP[ ASW_XP_FRIENDLY_FIRE ] = %d\n", m_iEarnedXP[ ASW_XP_FRIENDLY_FIRE ] );
Msg( " EarnedXP[ ASW_XP_DAMAGE_TAKEN ] = %d\n", m_iEarnedXP[ ASW_XP_DAMAGE_TAKEN ] );
Msg( " EarnedXP[ ASW_XP_HEALING ] = %d\n", m_iEarnedXP[ ASW_XP_HEALING ] );
Msg( " EarnedXP[ ASW_XP_HACKING ] = %d\n", m_iEarnedXP[ ASW_XP_HACKING ] );
Msg( " EarnedXP[ ASW_XP_MEDALS ] = %d\n", m_iEarnedXP[ ASW_XP_MEDALS ] );
Msg( " EarnedXP[ ASW_XP_TOTAL ] = %d (Difficulty scale = %f)\n", m_iEarnedXP[ ASW_XP_TOTAL ], ASWGameRules() ? ( ASWGameRules()->GetSkillLevel() - 1 ) : 1.0f );
}
}
int CASW_Player::GetLevel()
{
return LevelFromXP( GetExperience(), GetPromotion() );
}
int CASW_Player::GetLevelBeforeDebrief()
{
return LevelFromXP( GetExperienceBeforeDebrief(), GetPromotion() );
}
void CASW_Player::RequestExperience()
{
#ifdef CLIENT_DLL
// pull XP/level out of the medal store. Steam stats will overwrite these numbers if stat get is successful and USE_XP_FROM_STEAM is defined
if ( IsLocalPlayer() && GetMedalStore() )
{
m_iExperience = GetMedalStore()->GetExperience();
m_iPromotion = GetMedalStore()->GetPromotion();
}
#endif
#if !defined(NO_STEAM) && !defined(DEBUG)
#ifdef CLIENT_DLL
#if !defined(USE_XP_FROM_STEAM)
// if we're not pulling XP from Steam stats, then we don't request it for other players
// (instead we wait for the server to network their XP)
if ( !IsLocalPlayer() )
return;
#endif
Assert( steamapicontext->SteamUserStats() );
if ( steamapicontext->SteamUserStats() )
{
if ( IsLocalPlayer( this ) )
{
steamapicontext->SteamUserStats()->RequestCurrentStats();
}
else
{
player_info_t pi;
if ( engine->GetPlayerInfo( entindex(), &pi ) && pi.friendsID )
{
CSteamID steamID( pi.friendsID, 1, steamapicontext->SteamUtils()->GetConnectedUniverse(), k_EAccountTypeIndividual );
Msg( "Requesting Steam stats for %s (%s)\n", pi.name ? pi.name : "NULL", pi.friendsName ? pi.friendsName : "NULL" );
steamapicontext->SteamUserStats()->RequestUserStats( steamID );
}
}
m_bPendingSteamStats = true;
m_flPendingSteamStatsStart = gpGlobals->curtime;
}
#else
Assert( Steam3Server().SteamGameServerStats() );
if ( Steam3Server().SteamGameServerStats() )
{
CSteamID steamID;
if ( GetSteamID( &steamID ) )
{
SteamAPICall_t hSteamAPICall = Steam3Server().SteamGameServerStats()->RequestUserStats( steamID );
if ( hSteamAPICall != 0 )
{
m_CallbackGSStatsReceived.Set( hSteamAPICall, this, &CASW_Player::Steam_OnGSStatsReceived );
}
}
m_bPendingSteamStats = true;
m_flPendingSteamStatsStart = gpGlobals->curtime;
}
#endif
#endif
}
void CASW_Player::AwardExperience()
{
#ifdef CLIENT_DLL
if ( !GetClientModeASW() || GetClientModeASW()->HasAwardedExperience( this ) || !ASWGameRules() || !ASWGameResource() )
return;
#else
if ( m_bHasAwardedXP || !ASWGameRules() || !ASWGameResource() )
return;
#endif
if ( IsX360() )
return;
m_iExperience = GetExperience(); // make sure m_iExperience has the correct number (no change if local player, otherwise using networked value)
m_iExperienceBeforeDebrief = m_iExperience;
CalculateEarnedXP();
Msg( "%s: AwardExperience: Pre XP is %d\n", IsServerDll() ? "S" : "C", m_iExperience );
m_iExperience += m_iEarnedXP[ ASW_XP_TOTAL ];
m_iExperience = MIN( m_iExperience, ASW_XP_CAP * g_flPromotionXPScale[ GetPromotion() ] );
#ifdef CLIENT_DLL
if ( IsLocalPlayer() )
{
#if !defined(NO_STEAM)
// only upload if Steam is running
if ( steamapicontext->SteamUserStats() )
{
if( GetLocalASWPlayer() == this )
g_ASW_Steamstats.PrepStatsForSend( this );
steamapicontext->SteamUserStats()->SetStat( "experience", m_iExperience );
g_ASW_AchievementMgr.UploadUserData( GetSplitScreenPlayerSlot() );
if ( GetMedalStore() )
{
GetMedalStore()->SetExperience( m_iExperience );
GetMedalStore()->SetPromotion( m_iPromotion );
GetMedalStore()->SaveMedalStore();
}
}
#endif // NO_STEAM
GetClientModeASW()->SetAwardedExperience( this );
}
#else
m_bHasAwardedXP = true;
#endif
Msg( "%s: Awarded %d XP for player %s (total is now %d)\n", IsServerDll() ? "S" : "C", m_iEarnedXP[ ASW_XP_TOTAL ], GetPlayerName(), m_iExperience );
}
#ifdef CLIENT_DLL
#ifdef _DEBUG
ConVar asw_unlock_all_weapons( "asw_unlock_all_weapons", "0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "If enabled, all weapons will be available in the briefing" );
#endif
int CASW_Player::GetWeaponLevelRequirement( const char *szWeaponClass )
{
for ( int i = 0; i < NELEMS( g_WeaponUnlocks ); i++ )
{
if ( !Q_stricmp( szWeaponClass, g_WeaponUnlocks[ i ].m_pszWeaponClass ) )
{
return g_WeaponUnlocks[ i ].m_iLevel;
}
}
return -1;
}
bool CASW_Player::IsWeaponUnlocked( const char *szWeaponClass )
{
#ifdef _DEBUG
if ( asw_unlock_all_weapons.GetBool() )
return true;
#endif
if ( C_ASW_Equip_Req::ForceWeaponUnlocked( szWeaponClass ) )
return true;
int iPlayerLevel = GetLevel();
int iWeaponReq = GetWeaponLevelRequirement( szWeaponClass );
if ( iWeaponReq == -1 )
{
// if it's not in the list of unlocked weapons, assume it's unlocked by default
return true;
}
return iWeaponReq <= iPlayerLevel;
}
const char* CASW_Player::GetNextWeaponClassUnlocked()
{
int iPlayerLevel = GetLevel();
for ( int i = 0; i < NELEMS( g_WeaponUnlocks ); i++ )
{
//Msg( "GetNextWeaponClassUnlocked: player level = %d weapon %s level = %d\n", iPlayerLevel, g_WeaponUnlocks[ i ].m_pszWeaponClass, g_WeaponUnlocks[ i ].m_iLevel );
if ( g_WeaponUnlocks[ i ].m_iLevel > iPlayerLevel )
{
return g_WeaponUnlocks[ i ].m_pszWeaponClass;
}
}
return "";
}
const char *CASW_Player::GetWeaponUnlockedAtLevel( int nLevel )
{
for ( int i = 0; i < NELEMS( g_WeaponUnlocks ); i++ )
{
if ( g_WeaponUnlocks[ i ].m_iLevel == nLevel )
{
return g_WeaponUnlocks[ i ].m_pszWeaponClass;
}
}
return "";
}
#if !defined(NO_STEAM)
//-----------------------------------------------------------------------------
// Purpose: called when stat download is complete
//-----------------------------------------------------------------------------
void CASW_Player::Steam_OnUserStatsReceived( UserStatsReceived_t *pUserStatsReceived )
{
Assert( steamapicontext->SteamUserStats() );
if ( !steamapicontext->SteamUserStats() )
return;
if ( pUserStatsReceived->m_eResult != k_EResultOK )
{
//Msg( "CASW_Player: failed to download stats from Steam, EResult %d\n", pUserStatsReceived->m_eResult );
//Msg( " m_nGameID = %I64u\n", pUserStatsReceived->m_nGameID );
//Msg( " SteamID = %I64u\n", pUserStatsReceived->m_steamIDUser.ConvertToUint64() );
m_bPendingSteamStats = false;
return;
}
CSteamID steamID;
if ( IsLocalPlayer() )
{
steamID = steamapicontext->SteamUser()->GetSteamID();
}
else
{
player_info_t pi;
if ( !engine->GetPlayerInfo( entindex(), &pi ) )
return;
if ( !pi.friendsID )
return;
CSteamID steamIDForPlayer( pi.friendsID, 1, steamapicontext->SteamUtils()->GetConnectedUniverse(), k_EAccountTypeIndividual );
steamID = steamIDForPlayer;
Msg( "Steam_OnUserStatsReceived for non local player %s (%s)\n", pi.name ? pi.name : "NULL", pi.friendsName ? pi.friendsName : "NULL" );
}
if ( steamID != pUserStatsReceived->m_steamIDUser )
return;
#ifdef USE_XP_FROM_STEAM
if ( steamapicontext->SteamUserStats()->GetUserStat( steamID, "experience", &m_iExperience ) )
{
m_bPendingSteamStats = false;
}
else
{
Msg( "Error retrieving experience stat for player %s.\n", GetPlayerName() );
}
if ( !steamapicontext->SteamUserStats()->GetUserStat( steamID, "promotion", &m_iPromotion ) )
{
Msg( "Error retrieving promotion stat for player %s.\n", GetPlayerName() );
}
#else
if ( IsLocalPlayer( this ) )
{
if ( GetMedalStore() )
{
if ( !GetMedalStore()->m_bFoundNewClientDat ) // if we failed to find the new client dat, then take steam numbers
{
if ( steamapicontext->SteamUserStats()->GetUserStat( steamID, "experience", &m_iExperience ) )
{
m_bPendingSteamStats = false;
}
else
{
Msg( "Error retrieving experience stat for player %s.\n", GetPlayerName() );
}
if ( !steamapicontext->SteamUserStats()->GetUserStat( steamID, "promotion", &m_iPromotion ) )
{
Msg( "Error retrieving promotion stat for player %s.\n", GetPlayerName() );
}
KeyValues *kv = new KeyValues( "XPUpdate" );
kv->SetInt( "xp", m_iExperience );
kv->SetInt( "pro", m_iPromotion );
engine->ServerCmdKeyValues( kv ); // kv gets deleted in here
}
}
}
m_bPendingSteamStats = false;
#endif
// Fetch the rest of the steam stats here
if( GetLocalASWPlayer() == this )
g_ASW_Steamstats.FetchStats( steamID, this );
if ( IsLocalPlayer() && GetLevel() >= ASW_NUM_EXPERIENCE_LEVELS )
{
CAchievementMgr *pAchievementMgr = dynamic_cast<CAchievementMgr *>( engine->GetAchievementMgr() );
if ( !pAchievementMgr )
return;
pAchievementMgr->OnAchievementEvent( ACHIEVEMENT_ASW_UNLOCK_ALL_WEAPONS, STEAM_PLAYER_SLOT );
}
}
void CASW_Player::Steam_OnUserStatsStored( UserStatsStored_t *pUserStatsStored )
{
if ( !IsLocalPlayer( this ) )
return;
CSteamID steamID = steamapicontext->SteamUser()->GetSteamID();
if ( k_EResultOK != pUserStatsStored->m_eResult )
{
DevMsg( "CASW_Player: failed to upload stats to Steam, EResult %d\n", pUserStatsStored->m_eResult );
#ifdef USE_XP_FROM_STEAM
steamapicontext->SteamUserStats()->GetStat( "experience", &m_iExperience );
steamapicontext->SteamUserStats()->GetStat( "promotion", &m_iPromotion );
#endif
// Set stats to whatever is stored on steam
if( GetLocalASWPlayer() == this )
g_ASW_Steamstats.FetchStats( steamID, this );
}
}
#endif
void asw_debug_xp_f()
{
C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
if ( pPlayer )
{
Msg( "Local player Level = %d\n", pPlayer->GetLevel() );
Msg( "Local player XP = %d\n", pPlayer->GetExperience() );
Msg( "Local player earned XP = %d\n", pPlayer->GetEarnedXP( ASW_XP_TOTAL ) );
Msg( "Local player promotion level = %d\n", pPlayer->GetPromotion() );
}
}
ConCommand asw_debug_xp( "asw_debug_xp", asw_debug_xp_f, "Lists XP details for local player", FCVAR_NONE );
void CASW_Player::AcceptPromotion()
{
if ( GetExperience() < ASW_XP_CAP * g_flPromotionXPScale[ GetPromotion() ] )
return;
if ( GetPromotion() >= ASW_PROMOTION_CAP )
return;
m_iExperience = 0;
m_iPromotion++;
#if !defined(NO_STEAM)
// only upload if Steam is running
if ( steamapicontext->SteamUserStats() )
{
steamapicontext->SteamUserStats()->SetStat( "experience", m_iExperience );
steamapicontext->SteamUserStats()->SetStat( "promotion", m_iPromotion );
steamapicontext->SteamUserStats()->SetStat( "level", 1 );
steamapicontext->SteamUserStats()->SetStat( "level.xprequired", 0 );
g_ASW_AchievementMgr.UploadUserData( GetSplitScreenPlayerSlot() );
if ( GetMedalStore() )
{
GetMedalStore()->ClearNewWeapons();
GetMedalStore()->SetExperience( m_iExperience );
GetMedalStore()->SetPromotion( m_iPromotion );
GetMedalStore()->SaveMedalStore();
}
KeyValues *kv = new KeyValues( "XPUpdate" );
kv->SetInt( "xp", m_iExperience );
kv->SetInt( "pro", m_iPromotion );
engine->ServerCmdKeyValues( kv ); // kv gets deleted in here
}
#endif // NO_STEAM
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, -1 /*SOUND_FROM_LOCAL_PLAYER*/, "ASW_XP.LevelUp" );
engine->ClientCmd( VarArgs( "cl_promoted %d", m_iPromotion ) );
// reset the player's selected equipment
if ( !ASWGameResource() || !ASWEquipmentList() )
return;
C_ASW_Marine_Resource *pMR = ASWGameResource()->GetFirstMarineResourceForPlayer( this );
if ( !pMR )
return;
CASW_Marine_Profile *pProfile = pMR->GetProfile();
if ( !pProfile )
return;
for ( int i = 0; i < ASW_NUM_INVENTORY_SLOTS; i++ )
{
const char *szWeaponClass = pProfile->m_DefaultWeaponsInSlots[ i ];
int nWeaponIndex = ASWEquipmentList()->GetIndexForSlot( i, szWeaponClass );
engine->ClientCmd( VarArgs( "cl_loadout %d %d %d", pProfile->m_ProfileIndex, i, nWeaponIndex ) );
}
}
#else
// SERVER
#if !defined(NO_STEAM)
void CASW_Player::Steam_OnGSStatsReceived( GSStatsReceived_t *pGSStatsReceived, bool bError )
{
Assert( Steam3Server().SteamGameServerStats() );
if ( !Steam3Server().SteamGameServerStats() )
return;
if ( pGSStatsReceived->m_eResult != k_EResultOK )
{
Msg( "CASW_Player: Server failed to download stats from Steam, EResult %d\n", pGSStatsReceived->m_eResult );
//Msg( " SteamID = %I64u\n", pGSStatsReceived->m_steamIDUser.ConvertToUint64() );
m_bPendingSteamStats = false;
return;
}
CSteamID steamIDForPlayer;
if ( !GetSteamID( &steamIDForPlayer ) )
return;
if ( steamIDForPlayer != pGSStatsReceived->m_steamIDUser )
return;
#ifdef USE_XP_FROM_STEAM
if ( Steam3Server().SteamGameServerStats()->GetUserStat( steamIDForPlayer, "experience", &m_iExperience ) )
{
m_bPendingSteamStats = false;
}
else
{
Msg( "Server error retrieving experience stat for player %s.\n", GetPlayerName() );
}
Steam3Server().SteamGameServerStats()->GetUserStat( steamIDForPlayer, "promotion", &m_iPromotion )
#endif
}
#endif // NO_STEAM
#endif
int GetXPForMedal( int nMedal )
{
return 50; // TODO: Different XP for different medal types?
}
int CASW_Player::GetExperience()
{
#ifdef USE_XP_FROM_STEAM
return m_iExperience; // stat taken from steam stats
#else
#ifdef CLIENT_DLL
if ( IsLocalPlayer() )
{
return m_iExperience; // XP read from medal store
}
#endif
return m_iNetworkedXP.Get(); // XP networked down from the server
#endif
}
int CASW_Player::GetPromotion()
{
#ifdef USE_XP_FROM_STEAM
return m_iPromotion; // stat taken from steam stats
#else
#ifdef CLIENT_DLL
if ( IsLocalPlayer() )
{
return m_iPromotion; // XP read from medal store
}
#endif
return m_iNetworkedPromotion.Get(); // XP networked down from the server
#endif
}