/
MonsterHunt.uc
1237 lines (1074 loc) · 34 KB
/
MonsterHunt.uc
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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//****************************************************************
// MonsterHunt rebuild
// Requires XC_Engine v24, uses route mapper (XC_CORE 10)
// All subclasses should also have their config in MonsterHunt.ini
class MonsterHunt expands TeamGamePlus
config(MonsterHunt);
const MHS = class'MHCR_Statics';
var() config int MonsterSkill; //0 to 7 in v1...
var() config int Lives;
var() config bool bUseTeamSkins;
var() config bool bReplaceUIWeapons;
var() config bool bAIDebug;
var() config int DamageToScore;
var() config string HunterTeamName;
var() config string HunterTeamIcon;
var() config string ClientExtensionClass;
var bool bCountMonstersAgain; //Monster counting isn't immediate, helps other mutators properly affect monsters before we do it
var bool bCheckEndLivesAgain;
var bool bSkipThisMonster; //Mutator doesn't want this monster to be difficulty-scaled
var bool bQueryEnemies;
var int PathQueryTag;
//User-define kill scores
var() config name MonsterKillType[10];
var() config int MonsterKillScore[10];
var localized string TimeOutMessage;
var(Debug) MonsterWaypoint WaypointList;
var(Debug) MonsterEnd EndList;
var(Debug) MonsterAuthenticator AuthenticatorList;
var(Debug) MonsterBriefing Briefing;
var(Debug) MonsterTriggerMarker TriggerMarkers;
var(Debug) ScriptedPawn ReachableEnemy;
var(Debug) private int MonstersPerZone[64]; //ACCESSOR: GetMonstersPerZone( byte ZoneNumber)
/*************************************************************************************
// Important functions to use in order to easily subclass MH without package dependancy
function int GetMonstersPerZone( byte ZoneNumber);
function bool ShouldDefer( Pawn Seeker, Actor Goal, out NavigationPoint DeferTo, out byte SuperDefer);
*/
// Prevent monsters from attacking each other upon bump
function AnnoyedBy_Replacement( Pawn Other) {}
event InitGame(string Options, out string Error)
{
local Mutator M;
local Actor A;
local Texture T;
local class<MonsterBriefing> BriefingClass;
//Force settings
bUseTranslocator = False; //Warning: TranslocDest points will be unlinked with this
bNoMonsters = False;
MaxAllowedTeams = 1;
//Beta auto-upgrade
if ( ClientExtensionClass == "MonsterBetaCL_0.MHCL_MonsterBriefing"
|| ClientExtensionClass == "MonsterBetaCL_1.MHCL_MonsterBriefing" )
ClientExtensionClass = "MonsterBetaCL_2.MHCL_MonsterBriefing";
BriefingClass = class<MonsterBriefing>( DynamicLoadObject(ClientExtensionClass,class'class') );
if ( BriefingClass == None )
{
Error = "Failed to load client extension "$ClientExtensionClass$", check MonsterHunt.ini";
return;
}
ReplaceFunction( class'ScriptedPawn', class'MonsterHunt', 'AnnoyedBy', 'AnnoyedBy_Replacement');
Super.InitGame( Options, Error);
Difficulty = Min( 3, MonsterSkill);
//Validate UI replacements of MonsterBase
For ( M=BaseMutator ; M!=None ; M=M.NextMutator )
if ( M.IsA('MonsterBase') )
{
MonsterBase(M).ValidateWeapons();
break;
}
Briefing = Spawn( BriefingClass);
T = Texture( DynamicLoadObject(HunterTeamIcon,class'Texture', true) );
if ( T == None ) T = Texture( DynamicLoadObject(HunterTeamIcon,class'IceTexture', true) );
if ( T == None ) T = Texture( DynamicLoadObject(HunterTeamIcon,class'FireTexture', true) );
if ( T == None ) T = Texture( DynamicLoadObject(HunterTeamIcon,class'WetTexture', true) );
if ( T != None )
{
Briefing.HuntersIcon = T;
if ( Level.NetMode != NM_Standalone )
AddToPackageMap( Left(HunterTeamIcon, InStr(HunterTeamIcon,".")) );
}
bCountMonstersAgain = true;
}
event PostLogin( PlayerPawn NewPlayer )
{
//Don't update player's Team in his URL
Super(DeathMatchPlus).PostLogin(NewPlayer);
//Prevent monsters from attacking spectators
if ( NewPlayer.PlayerReplicationInfo != None && NewPlayer.PlayerReplicationInfo.bIsSpectator )
{
NewPlayer.Visibility = 0;
NewPlayer.Health = 0;
}
}
function Timer()
{
local Pawn P;
local float DivChance;
Super.Timer();
//Can be used to override ReachableEnemy even if it's set
if ( bQueryEnemies )
{
For ( P=Level.PawnList ; P!=None ; P=P.NextPawn )
if ( (P.PlayerReplicationInfo == None) && P.IsA('ScriptedPawn') && P.bCollideActors && (P.AttitudeToPlayer < ATTITUDE_Friendly) )
{
DivChance += 1;
if ( FRand() < 1/DivChance )
ReachableEnemy = ScriptedPawn(P);
}
bQueryEnemies = false;
}
}
//Recont everything right after match starts
function StartMatch()
{
Super.StartMatch();
GameReplicationInfo.Timer();
}
function CheckEndGame()
{
local int KnockedOut;
local PlayerReplicationInfo PRI;
if ( bGameEnded || (Lives <= 0) )
return;
bCheckEndLivesAgain = False;
//Task bots to attack?
ForEach AllActors( class'PlayerReplicationInfo', PRI)
if ( Spectator(PRI.Owner) == None )
{
if ( (PRI.Deaths > 0) && (PRI.Deaths >= Lives) )
KnockedOut++;
else
return; //Game not ended
}
if ( KnockedOut > 0 )
EndGame("No hunters");
}
function bool SetEndCams(string Reason)
{
local MonsterEnd E;
local bool bWon;
local TeamInfo BestTeam;
local int i;
local pawn P, Best;
local PlayerPawn player;
// find prick that touched the MonsterEnd actor
For ( E=EndList ; E!=None ; E=E.NextEnd )
if ( E.TriggerTime == Level.TimeSeconds ) //This one caused the event
{
ForEach E.TouchingActors( class'Pawn', P)
if ( P.bIsPlayer && (P.PlayerReplicationInfo != None) && (P.PlayerReplicationInfo.Team == 0) )
{
Best = P;
break;
}
break;
}
// find individual winner
if ( Best == None )
{
for ( P=Level.PawnList; P!=None; P=P.nextPawn )
if ( P.bIsPlayer && P.PlayerReplicationInfo != None && ((Best == None) || (P.PlayerReplicationInfo.Score > Best.PlayerReplicationInfo.Score)) )
Best = P;
}
if ( Reason ~= "No hunters" )
GameReplicationInfo.GameEndedComments = "Hunting party eliminated!";
else if ( Reason ~= "Timelimit" )
GameReplicationInfo.GameEndedComments = TimeOutMessage;
else
{
bWon = true;
GameReplicationInfo.GameEndedComments = GameEndedMessage;
}
EndTime = Level.TimeSeconds + 3.0;
for ( P=Level.PawnList; P!=None; P=P.nextPawn )
{
player = PlayerPawn(P);
if ( Player != None )
{
PlayWinMessage(Player, bWon);
player.bBehindView = true;
if ( Player == Best )
Player.ViewTarget = None;
else
Player.ViewTarget = Best;
player.ClientGameEnded();
}
P.GotoState('GameEnded');
}
CalcEndStats();
return true;
}
function bool RestartPlayer( Pawn aPlayer)
{
local bool Result;
if ( Bot(aPlayer) != None )
Bot(aPlayer).OrderTag = 'Respawn';
aPlayer.Visibility = aPlayer.default.Visibility;
if ( (Lives > 0) && (aPlayer.PlayerReplicationInfo != None) && (aPlayer.PlayerReplicationInfo.Deaths >= Lives) )
{
if ( bRestartLevel && (Level.NetMode == NM_Standalone) ) //This is coop code
return True;
BroadcastMessage( aPlayer.PlayerReplicationInfo.PlayerName $ " has been lost!", True, 'MonsterCriticalEvent');
if ( !aPlayer.IsA('PlayerPawn') )
{
aPlayer.PlayerReplicationInfo.bIsSpectator = True;
aPlayer.PlayerReplicationInfo.bWaitingPlayer = True;
aPlayer.GotoState('GameEnded');
return False;
}
aPlayer.PlayerRestartState = 'PlayerSpectating';
}
Result = Super.RestartPlayer(aPlayer);
if ( aPlayer.bHidden )
aPlayer.Visibility = 0;
return Result;
}
//If a pawn is spawned, let game we want to count all monsters again
function bool IsRelevant( Actor Other)
{
local bool Result;
if ( Other.bIsPawn )
bCountMonstersAgain = true;
Result = Super.IsRelevant( Other);
if ( (ScriptedPawn(Other) != None) && Result && !bSkipThisMonster )
SetPawnDifficulty( MonsterSkill, ScriptedPawn(Other) );
bSkipThisMonster = false;
return Result;
}
// Fix monster dropped weapons/items breaking the client's inventory chain
function bool PickupQuery( Pawn Other, Inventory item )
{
local bool bResult;
bResult = Super.PickupQuery( Other, Item);
if ( bResult && Item.bAlwaysRelevant )
Item.bAlwaysRelevant = false;
return bResult;
}
function bool ChangeTeam(Pawn Other, int NewTeam)
{
local bool Result;
local string SkinName, FaceName;
Result = Super.ChangeTeam( Other, 0); //Add to red team
if ( !bUseTeamSkins )
{
Other.static.GetMultiSkin(Other, SkinName, FaceName); //Apply non-team skin
Other.static.SetMultiSkin(Other, SkinName, FaceName, NewTeam);
}
return Result;
}
static function string CreatureKillMessage(name damageType, pawn Other)
{
local string message;
local int i;
message = Super.CreatureKillMessage( damageType, Other);
i = InStr( message, ".");
if ( i != -1 )
message = Left( message, i) $ Mid( message, i+1);
return message;
}
function Killed( Pawn Killer, Pawn Other, name DamageType)
{
if ( ScriptedPawn(Killer) != None )
MonsterKill( ScriptedPawn(Killer), Other, DamageType);
else
Super.Killed( Killer, Other, DamageType);
if ( (Lives > 0) && Other.bIsPlayer && (Other.PlayerReplicationInfo != None) && (Other.PlayerReplicationInfo.Deaths >= Lives) )
bCheckEndLivesAgain = true;
}
function MonsterKill( ScriptedPawn Killer, Pawn Other, name DamageType)
{
local string Msg;
if ( Other == None || Killer == None )
return;
Other.DieCount++;
Killer.KillCount++;
BaseMutator.ScoreKill(Killer, Other);
if ( Other.PlayerReplicationInfo != None )
{
Other.PlayerReplicationInfo.Deaths += 1;
Other.PlayerReplicationInfo.Score -= 5;
if ( ReachableEnemy == None || ReachableEnemy.bDeleteMe || Killer.bIsBoss )
ReachableEnemy = Killer;
Msg = Killer.KillMessage( DamageType, Other);
}
else if ( ScriptedPawn(Other) != None )
{
if ( Other != Killer )
{
Msg = Other.GetHumanName() $ CreatureKillMessage(DamageType,Other) $ Killer.GetHumanName();
while ( Left(Msg,1) == " " )
Msg = Mid(Msg,1);
Msg = Caps(Left(Msg,1)) $ Mid(Msg,1);
}
}
if ( Msg != "" )
BroadcastMessage( Msg, false, 'DeathMessage');
}
function ScoreKill( Pawn Killer, Pawn Other)
{
local int i;
local bool bSpecialScore;
local ScriptedPawn S;
local MonsterPlayerData MPD;
local float ScoreStart;
bCountMonstersAgain = true;
S = ScriptedPawn(Other);
if ( (S != None) && S.bIsBoss && (Briefing != None) )
{
Briefing.KilledBosses++;
Briefing.BossCount--;
}
if ( (Killer != None) && Killer.bIsPlayer && (Killer.PlayerReplicationInfo != None) && (S != None) )
{
if ( S.bIsPlayer )
S.bIsPlayer = false; //Prevent skaarj log bug on non-XCGE servers (?)
//Record initial score
ScoreStart = Killer.PlayerReplicationInfo.Score;
Super(GameInfo).ScoreKill( Killer, Other);
BroadcastMessage( Killer.GetHumanName() @ "killed" $ Other.GetHumanName());
For ( i=0 ; i<10 && (MonsterKillType[i] != '') ; i++ )
if ( Other.IsA(MonsterKillType[i]) )
{
bSpecialScore = true;
Killer.PlayerReplicationInfo.Score += MonsterKillScore[i];
break;
}
if ( !bSpecialScore )
Killer.PlayerReplicationInfo.Score += Sqrt( float(Other.default.Health) * 0.01 );
if ( Briefing != None )
{
Briefing.KilledMonsters++;
MPD = Briefing.GetPlayerData( Killer.PlayerReplicationInfo.PlayerID);
}
if ( MPD != None ) MPD.MonsterKills++;
if ( S.bIsBoss )
{
Killer.PlayerReplicationInfo.Score += 9;
if ( MPD != None ) MPD.BossKills++;
}
//Add score difference to team
Teams[0].Score += Killer.PlayerReplicationInfo.Score - ScoreStart;
}
else
{
Super(GameInfo).ScoreKill( Killer, Other);
if ( Other.PlayerReplicationInfo != None )
{
if ( Lives <= 0 )
{
if ( Killer == Other )
Killer.PlayerReplicationInfo.Score -= 4;
}
}
}
}
//Entry point from old MH.u
function SetPawnDifficulty( int Diff, ScriptedPawn S)
{
local int i;
local int SkillScale;
local int StrenghtScale;
local float fTmp;
local name OtherDamages[6];
SkillScale = 80 + int(Sqrt(Diff) * 15.0); //Skill has a cap
StrenghtScale = 80 + Diff * 10; //Strenght on the other side doesn't
//CombatStyle and Aggresiveness affect monster preference to charge or stay at a distance, do not alter
if ( !S.bIsBoss && (S.Event != '') && (S.Health > 1500) ) //Count as boss
{
S.bIsBoss = true;
S.Health = int(float(S.Health) * (float(StrenghtScale) * 0.01 - 0.15 * S.Skill)); //Avoid increasing health over boss status
}
else
S.Health = int(float(S.Health) * float(StrenghtScale) * 0.01); //Avoid going over the 32 bit INT cap
S.SightRadius = S.SightRadius * SkillScale / 100;
S.RefireRate = S.RefireRate * SkillScale / 100;
S.ProjectileSpeed = S.ProjectileSpeed * SkillScale / 100;
S.GroundSpeed = S.GroundSpeed * SkillScale / 100;
S.AirSpeed = S.AirSpeed * SkillScale / 100;
S.WaterSpeed = S.WaterSpeed * SkillScale / 100;
//Adjust damages generically
OtherDamages[0] = 'WhipDamage';
OtherDamages[1] = 'PunchDamage';
OtherDamages[2] = 'StrikeDamage';
OtherDamages[3] = 'StingDamage';
OtherDamages[4] = 'ClawDamage';
OtherDamages[5] = 'BiteDamage';
For ( i=0 ; i<6 ; i++ )
{
fTmp = float( S.GetPropertyText( string(OtherDamages[i]) ) );
if ( fTmp != 0 )
{
fTmp *= StrenghtScale * 0.01;
S.SetPropertyText( string(OtherDamages[i]),string(int(fTmp)) );
}
}
}
function byte AssessBotAttitude(Bot aBot, Pawn Other)
{
local ScriptedPawn S;
S = ScriptedPawn(Other);
if ( S != None )
{
if ( S.AttitudeToPlayer >= ATTITUDE_Friendly )
return 3;
if ( S.AttitudeToPlayer == ATTITUDE_Ignore )
return 2;
if ( S.IsA('Nali') || S.IsA('Cow') )
{
if ( S.AlarmTag != '' )
return 3;
if ( S.AttitudeToPlayer == ATTITUDE_Fear )
return 2;
}
}
return Super.AssessBotAttitude( aBot, Other);
}
//Nearby hunters
function int NearbyTeammates( Pawn Other, float Distance, bool bVisible)
{
local Pawn P;
local int i;
ForEach PawnActors (class'Pawn', P, Distance, Other.Location, true)
{
if ( P.PlayerReplicationInfo.Team != Other.PlayerReplicationInfo.Team || (bVisible && !Other.FastTrace(P.Location + VRand()*P.CollisionRadius) ) )
continue;
i++;
}
return i;
}
//Generic DeferTo return, good for package independant mods
//SuperDefer = 1 means that no pathfinding should be done
function bool ShouldDefer( Pawn Seeker, Actor Goal, out NavigationPoint DeferTo, out byte SuperDefer)
{
if ( MonsterWaypoint(Goal) != None )
DeferTo = MonsterWaypoint(Goal).DeferTo;
else if ( MonsterEnd(Goal) != None )
DeferTo = MonsterEnd(Goal).DeferTo;
else if ( (MHE_Base(Goal) != None) && (MHE_Base(Goal).DeferTo != None) )
{
if ( !MHE_Base(Goal).ShouldDefer( Seeker) ) //Bot already reached DeferTo
Goto SUPER_GOAL;
DeferTo = MHE_Base(Goal).DeferTo;
}
else if ( (Inventory(Goal) != None) && (Inventory(Goal).MyMarker != None) )
{
if ( MHS.static.ActorsTouching(Seeker,Inventory(Goal).MyMarker) )
Goto SUPER_GOAL;
DeferTo = Inventory(Goal).MyMarker;
}
return DeferTo != None;
SUPER_GOAL: //Force bot into Goal no matter what
SuperDefer = 1;
return true;
}
//Returns 'tag' of whatever needs to be unlocked to reach next path
function Name EvaluateNextNodeTeleporter( Pawn Other)
{
local Actor A, B;
local vector HitLocation, HitNormal;
local Teleporter Tele[2];
local int i;
While ( i<3 )
{
Tele[0] = Teleporter(Other.RouteCache[i]);
Tele[1] = Teleporter(Other.RouteCache[++i]);
if ( (Tele[0] != None) && (Tele[1] != None) && !Tele[0].bEnabled
&& (Tele[0].URL ~= string(Tele[1].Tag)) ) //SpecialHandling can be especially annoying
return Tele[0].Tag;
}
return '';
}
//Returns 'tag' of whatever needs to be unlocked to reach next path
function Name EvaluateNextNodeDoor( Pawn Other)
{
local Actor A, B;
local vector HitLocation, HitNormal;
local NavigationPoint NextPath;
NextPath = NavigationPoint(Other.MoveTarget);
if ( NextPath == None )
NextPath = Other.RouteCache[0];
if ( (NextPath == None) || (NextPath.UpstreamPaths[0] == -1) ) //Not selected by navigation code
return '';
ForEach Other.TraceActors( class'Actor', A, HitLocation, HitNormal, NextPath.Location)
if ( A.IsA('Mover') && (InStr( string(A.InitialState),"Trigger") != -1) && !Mover(A).bInterpolating && !Mover(A).bDelaying && (Mover(A).SavedTrigger == None) )
{
//Detect active trigger via trace //BIG EXTENT TO EASE DETECTION
ForEach Other.TraceActors( class'Actor', B, HitLocation, HitNormal, HitLocation+HitNormal*Other.CollisionRadius, Other.Location, vect(40,40,70) )
if ( B.Event == A.Tag )
{
if ( (Trigger(B) != None) && !Trigger(B).bInitiallyActive )
break;
return '';
}
return A.Tag;
}
return '';
}
//Returns 'tag' of what will unlock an obstructed path (if any)
function name HandleObstrucedPath( Pawn Other, out NavigationPoint ObstructedPath, out int BlockType)
{
local Actor A, B;
local vector HitLocation, HitNormal;
local NavigationPoint NextPath;
local Teleporter Tele[2];
local int i;
local bool bHasTrigger;
//Evaluate elevator (outside)
if ( (LiftExit(Other.RouteCache[0]) != None) && (LiftCenter(Other.RouteCache[1]) != None) )
{
}
//Evaluate teleporter
For ( i=0 ; i<2 ; i++ )
{
Tele[0] = Teleporter(Other.RouteCache[i]);
Tele[1] = Teleporter(Other.RouteCache[i+1]);
if ( (Tele[0] != None) && (Tele[1] != None) && !Tele[0].bEnabled && (Tele[0].URL ~= string(Tele[1].Tag)) )
{
BlockType = 2;
ObstructedPath = Tele[0];
return Tele[0].Tag;
}
}
//Evaluate door
For ( i=0 ; i<2 ; i++ )
{
NextPath = Other.RouteCache[i];
if ( (NextPath != None) && (NextPath.upstreamPaths[0] != -1) ) //Selected by navigation code
{
ForEach Other.TraceActors( class'Actor', A, HitLocation, HitNormal, NextPath.Location)
if ( A.IsA('Mover') && (Mover(A).myMarker == None) //Unmarked lift
&& (InStr( string(A.InitialState),"Trigger") != -1) && !Mover(A).bInterpolating && !Mover(A).bDelaying && (Mover(A).SavedTrigger == None) )
{
bHasTrigger = false;
//Detect active trigger via trace //BIG EXTENT TO EASE DETECTION
ForEach Other.TraceActors( class'Actor', B, HitLocation, HitNormal, HitLocation+HitNormal*Other.CollisionRadius, Other.Location, vect(40,40,70) )
if ( B.Event == A.Tag )
{
bHasTrigger = bHasTrigger && ((Trigger(B) == None) || Trigger(B).bInitiallyActive);
break;
}
if ( !bHasTrigger )
{
BlockType = 1;
ObstructedPath = NextPath;
return A.Tag;
}
}
}
}
return '';
}
//Find what triggers this 'tag' and evaluate reachability
//List all available MHE_Base actors
//Requires Route Mapper to have run
//BlockType codes:
// - 1: Door
// - 2: Teleporter
function bool ModifyObjective( Pawn Other, out Actor Objective)
{
local MHE_Base Events[16], Link;
local int iE, i;
local float Dist;
local FV_PathBlocker FVPB;
local NavigationPoint NextPath;
local name RequiredEvent;
local int BlockType;
RequiredEvent = HandleObstrucedPath( Other, NextPath, BlockType);
if ( (NextPath == None) || (RequiredEvent == '') || (BlockType == 0) )
return false;
//Prepare a list of available events (direct triggers and chained triggers)
Briefing.EnumerateTriggers( RequiredEvent, Events, iE);
//Don't block aggresively
if ( iE == 0 )
{
if ( bAIDebug )
Log("Unable to find trigger chain for"@RequiredEvent@"["$Other.PlayerReplicationInfo.PlayerName@"-"@BlockType$"]",'MonsterHunt');
return false;
}
//Sort by distance
Briefing.SortEventsByProximity( Other.Location, Events, iE);
//Get nearest attraction point
//Start with stuff that aren't objective markers
For ( i=0 ; i<iE ; i++ )
if ( !Events[i].ShouldDefer(Other) || !Events[i].bAttractBots )
{
Dist = VSize( Events[i].Location - Other.Location);
if ( Dist > 1500 )
break;
//Attraction point is nearby, send bot instead of altering objective
if ( AttractTo(Other,Events[i]) && (Other.MoveTarget == Events[i]) )
return false;
if ( Dist < 200 && Other.FastTrace(Events[i].Location) )
{
if ( bAIDebug )
Log("Forcing ugly attraction deferment for event"@RequiredEvent@"["$Other.PlayerReplicationInfo.PlayerName@"-"@BlockType$"]",'MonsterHunt');
Other.MoveTarget = Events[i];
return false;
}
}
//Lock the paths, we need to find a route
FVPB = Briefing.GetPathBlocker( RequiredEvent);
if ( BlockType == 1 ) FVPB.SetupBlock( NextPath, RequiredEvent);
else if ( BlockType == 2 ) FVPB.SetupTeleporter( Teleporter(NextPath) );
if ( bAIDebug )
Log("Blocking route that leads to"@RequiredEvent@"["$Other.PlayerReplicationInfo.PlayerName@"-"@BlockType$"] via"@NextPath.Name,'MonsterHunt');
//Notify MHE_Base we're becoming an objective, allows MHE_Base to self-modify
For ( i=0 ; i<iE ; i++ )
Events[i].RequiredForEvent();
For ( i=0 ; i<iE ; i++ ) //bCompleted check already done
if ( Events[i].bAttractBots && (Events[i].DeferTo != None) )
{
if ( !Events[i].ShouldDefer( Other) ) //Direct attraction
{
Other.MoveTarget = Events[i];
return false;
}
if ( AttractTo( Other, Events[i].DeferTo) )
{
Objective = Events[i].DeferTo;
Other.MoveTarget = Other;
Other.SpecialGoal = Other;
Other.SpecialPause = 0.2;
return true;
}
}
}
// Selects a weapon nearby the bot
function Inventory SelectRandomWeapon( Pawn CheckFor)
{
return Briefing.SelectRandomWeapon( CheckFor);
}
// This will ONLY return a non-NavigationPoint instance when it is directly reachable
function Actor SelectNearestEndpoint( Pawn Seeker, Actor Goal)
{
local NavigationPoint Nearest, N;
local float Dist, BestDist, LowestWeight;
local byte SuperDefer;
local vector CloserPoint;
if ( ShouldDefer( Seeker, Goal, Nearest, SuperDefer) && (SuperDefer != 0) )
return Goal; // Goal is directly reachable >>> force mode
if ( Nearest != None ) // Override
Goal = Nearest;
if ( (NavigationPoint(Goal) != None) && (NavigationPoint(Goal).StartPath != None) )
return Goal; //Goal is mapped NavigationPoint
// If goal is reachable, return it
if ( Seeker.ActorReachable(Goal) )
return Goal;
CloserPoint = Goal.Location + Normal( Seeker.Location - Goal.Location) * (Seeker.CollisionRadius + Goal.CollisionRadius);
if ( Seeker.PointReachable(CloserPoint) )
return Goal;
// Find nearby mapped NavigationPoint actors, then use special trace
BestDist = 500 + int(Goal.bIsPawn) * 2500;
LowestWeight = 10000000;
ForEach NavigationActors( class'NavigationPoint', N, BestDist, Goal.Location)
if ( N.StartPath != None )
LowestWeight = Min( LowestWeight, float(N.VisitedWeight));
ForEach NavigationActors( class'NavigationPoint', N, BestDist, Goal.Location)
if ( N.StartPath != None )
{
Dist = VSize( Goal.Location - N.Location) + (float(N.VisitedWeight)-LowestWeight) * 0.33;
if ( Dist < BestDist )
{
CloserPoint = Goal.Location + Normal( N.Location - Goal.Location) * (Seeker.CollisionRadius + Goal.CollisionRadius);
if ( FastTrace( N.Location, CloserPoint) )
{
Nearest = N;
BestDist = Dist;
}
}
}
return Nearest;
}
//Sets MoveTarget on pawn
//Can be called recursively once
function bool AttractTo( Pawn Seeker, Actor Goal)
{
local NavigationPoint N, Nearest;
local float Dist, BestDist;
local byte NoPathFinding;
local vector Vect;
local Actor EndPoint;
EndPoint = SelectNearestEndpoint( Seeker, Goal);
if ( (NavigationPoint(EndPoint) != None) && NavigationPoint(EndPoint).StartPath != None )
{
// Build route and discard paths Seeker is touching
// SpecialHandling may modify result
Seeker.MoveTarget = BuildRouteCache( NavigationPoint(EndPoint), Seeker.RouteCache, Seeker);
// Override EndPoint if already reached
if ( (Seeker.MoveTarget == EndPoint) && MHS.static.ActorsTouching( Seeker, EndPoint) )
{
if ( !Goal.bIsPawn ) //Shoot mode, don't override >>> TODO: EXPAND SHOOT CASES
Seeker.MoveTarget = Goal;
}
return true;
}
if ( EndPoint == None )
return false;
Seeker.MoveTarget = EndPoint;
return true;
}
function bool FindSpecialAttractionFor( Bot aBot)
{
local MonsterWaypoint W, BestW;
local MHE_Base MHE;
local Inventory GoalInv;
local float ChanceW;
local MonsterEnd E;
local Actor NewDest, NewObjective;
local int Limit, MonsterLimit;
local int BotID;
local float BotState;
local ScriptedPawn Enemy;
local byte NoAttractionCheck;
local bool bAttract;
if ( aBot.LastAttractCheck == Level.TimeSeconds )
return false;
if ( aBot.Health < 1 ) //Is this even needed?
{
aBot.GotoState('GameEnded');
return False;
}
if ( (aBot.OrderObject != None) && aBot.OrderObject.bDeleteMe )
aBot.OrderObject = None;
aBot.LastAttractCheck = Level.TimeSeconds;
//Force attack for now...
if ( (aBot.Orders == 'Attack') || (aBot.Orders == 'Freelance') )
{
BotID = aBot.PlayerReplicationInfo.PlayerID + Asc(aBot.PlayerReplicationInfo $ "A");
BotState = BotID + Level.TimeSeconds * 0.5;
//The more conditions, the more the bot is likely to charge
Limit = 3
+ int(aBot.Orders == 'Attack')
+ int(Inventory(aBot.OrderObject) != None) * 2 //Going for item anyways
+ int(aBot.Enemy == None) * 2
+ int(aBot.Weapon != none && aBot.Weapon.AiRating > 0.4 + FRand() * 0.2) * 2
+ aBot.Health/150
+ NearbyTeammates(aBot, 500+aBot.Health, aBot.Enemy!=None) / 2
+ int(MonstersPerZone[aBot.Region.ZoneNumber] == 0)
- int(aBot.Health < 68);
BotState = BotState % Limit;
//3 seconds for inventory grabbing
if ( BotState < 1.5 )
return False;
//Initiate Route Mapper
MapRoutes( aBot);
//Send bot to get an item
if ( aBot.OrderTag == 'Respawn' )
{
aBot.OrderObject = SelectRandomWeapon( aBot);
aBot.OrderTag = '';
}
GoalInv = Inventory(aBot.OrderObject);
if ( GoalInv != None )
{
if ( (aBot.FindInventoryType(GoalInv.Class) != None) || MHS.static.ActorsTouching(aBot,GoalInv) || !AttractTo( aBot, GoalInv) )
aBot.OrderObject = None;
else
Goto ATTRACT_DEST;
}
//8-12 seconds prioritizing monsters (if MonsterLimit is too low the bot bounces back and forth!!)
MonsterLimit = 4
+ int(ScriptedPawn(aBot.OrderObject) != None) * 2
+ Limit / 8
- int(Inventory(aBot.OrderObject) != None) * 10; //Do not go for monsters when going for weapon
Enemy = ScriptedPawn(aBot.Enemy);
if ( Enemy == None ) Enemy = ScriptedPawn(aBot.OrderObject);
if ( Enemy == None ) Enemy = ReachableEnemy;
if ( Enemy != None && (BotState < MonsterLimit) )
{
if ( AttractTo( aBot, Enemy) )
{
if ( (aBot.Enemy == Enemy && Enemy.bIsBoss) || ReachableEnemy == None || ReachableEnemy.bDeleteMe )
ReachableEnemy = Enemy;
if ( aBot.OrderObject == None )
aBot.OrderObject = Enemy;
if ( aBot.MoveTarget == Enemy ) //Don't charge
return False;
Goto ATTRACT_DEST;
}
else if ( Enemy == ReachableEnemy )
ReachableEnemy = None;
}
//Additional objective!
MHE = MHE_Base(aBot.OrderObject);
if ( MHE != None )
{
if ( !MHE.bAttractBots || MHE.bCompleted || (MHE.DeferTo == None) )
aBot.OrderObject = None;
else if ( AttractTo( aBot, MHE) )
Goto ATTRACT_DEST;
}
//Otherwise prioritize the main objectives (sorted by priority)
//Start with previously assigned goal
BestW = MonsterWaypoint(aBot.OrderObject);
if ( (BestW != None) && BestW.bEnabled && !BestW.bVisited && AttractTo( aBot, BestW) )
Goto ATTRACT_DEST;
BestW = None;
ChanceW = 0;
Limit = 0;
For ( W=WaypointList ; W!=None ; W=W.NextWaypoint )
if ( W.bEnabled && !W.bVisited )
{
if ( Limit <= 0 )
Limit = W.Position;
else if ( W.Position > Limit ) //Don't seek past next objective
break;
if ( AttractTo(aBot,W) && (FRand() < 1.0/(ChanceW+=1)) ) //Only query reachable objectives, pick random
{
BestW = W;
NewDest = aBot.MoveTarget;
}
}
//Assign objective and attract
if ( NewDest != None )
{
aBot.OrderObject = BestW;
aBot.MoveTarget = NewDest;
Goto ATTRACT_DEST;
}
For ( E=EndList ; E!=None ; E=E.NextEnd )
{
if ( !E.bInitiallyActive && E.bReachedByPlayer )
continue;
if ( AttractTo(aBot,E) )
{
NewDest = aBot.MoveTarget;
if ( E.bCollideActors && E.bInitiallyActive ) //Prioritize
Goto ATTRACT_DEST;
}
}
if ( NewDest != None )
Goto ATTRACT_DEST;
//Defer to enemy if failed to find objective
if ( Enemy != None && BotState >= MonsterLimit )
{
if ( AttractTo( aBot, Enemy) )
{
aBot.OrderObject = Enemy;
if ( aBot.MoveTarget == Enemy ) //Don't charge
return False;
Goto ATTRACT_DEST;
}
else if ( Enemy == ReachableEnemy )
ReachableEnemy = None;
}
bQueryEnemies = (FRand() < 0.01) || (ReachableEnemy == None);
//Defer to a MHE_Event objective if failed to find anything else
MHE = Briefing.GetNextBotAttractor();
if ( (MHE != None) && AttractTo( aBot, MHE.DeferTo) )
{
aBot.OrderObject = MHE;
Goto ATTRACT_DEST;
}
}
return False;
ATTRACT_DEST:
NewDest = aBot.OrderObject;
if ( ModifyObjective( aBot, NewObjective) && (aBot.Orders != 'Follow') )
aBot.OrderObject = NewObjective;
SetAttractionStateFor(aBot);
return true;
}
//****************************************
// Utilitary methods
function ResetPerZoneCounter()
{
local int i;
For ( i=0 ; i<64 ; i++ )
MonstersPerZone[i] = 0;
}
function int GetMonstersPerZone( byte ZoneNumber) //ACCESSOR