forked from beginnerToSourceSDK/SWATEliteForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttackOfficerAction.uc
189 lines (153 loc) · 5.28 KB
/
AttackOfficerAction.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
///////////////////////////////////////////////////////////////////////////////
// AttackOfficerAction.uc - AttackOfficerAction class
// The action that causes the AI to attack a particular enemy with any weapon it
// has
class AttackOfficerAction extends SwatCharacterAction dependsOn(ISwatEnemy);
///////////////////////////////////////////////////////////////////////////////
import enum EnemySkill from ISwatEnemy;
///////////////////////////////////////////////////////////////////////////////
//
// AttackOfficerAction variables
// behaviors we use
var protected MoveToAttackOfficerGoal CurrentMoveToAttackOfficerGoal;
var protected AttackTargetGoal CurrentAttackTargetGoal;
// config variables
var config private float MinPassiveAttackOfficerPercentageChance;
var config private float MaxPassiveAttackOfficerPercentageChance;
var config private float MinAggressiveAttackOfficerPercentageChance;
var config private float MaxAggressiveAttackOfficerPercentageChance;
var config private float LowSkillSuccessAfterFiringChance;
var config private float MediumSkillSuccessAfterFiringChance;
var config private float HighSkillSuccessAfterFiringChance;
///////////////////////////////////////////////////////////////////////////////
//
// Officer Target
function Pawn GetOfficerTarget()
{
return ISwatEnemy(m_Pawn).GetEnemyCommanderAction().GetCurrentEnemy();
}
///////////////////////////////////////////////////////////////////////////////
//
// Selection Heuristic
function float selectionHeuristic( AI_Goal goal )
{
// if we don't have a pawn yet, set it
if (m_Pawn == None)
{
m_Pawn = AI_CharacterResource(goal.resource).m_pawn;
assert(m_Pawn != None);
}
assert(m_Pawn.IsA('SwatEnemy'));
if (ISwatAI(m_Pawn).HasUsableWeapon() && (GetOfficerTarget() != None))
{
if (ISwatAI(m_Pawn).IsAggressive())
{
// return a random value that is above the minimum chance
return FClamp(FRand(), MinAggressiveAttackOfficerPercentageChance, MaxAggressiveAttackOfficerPercentageChance);
}
else
{
// return a random value that is at least the minimum chance
return FClamp(FRand(), MinPassiveAttackOfficerPercentageChance, MaxPassiveAttackOfficerPercentageChance);
}
}
else
{
return 0.0;
}
}
///////////////////////////////////////////////////////////////////////////////
//
// Cleanup
function cleanup()
{
super.cleanup();
if (CurrentMoveToAttackOfficerGoal != None)
{
CurrentMoveToAttackOfficerGoal.Release();
CurrentMoveToAttackOfficerGoal = None;
}
if (CurrentAttackTargetGoal != None)
{
CurrentAttackTargetGoal.Release();
CurrentAttackTargetGoal = None;
}
}
///////////////////////////////////////////////////////////////////////////////
//
// Attack Target Success Chance
function float GetSkillSpecificSuccessAfterFiringChance()
{
local EnemySkill CurrentEnemySkill;
CurrentEnemySkill = ISwatEnemy(m_Pawn).GetEnemySkill();
switch(CurrentEnemySkill)
{
case EnemySkill_Low:
return LowSkillSuccessAfterFiringChance;
case EnemySkill_Medium:
return MediumSkillSuccessAfterFiringChance;
case EnemySkill_High:
return HighSkillSuccessAfterFiringChance;
default:
assert(false);
return 0.0;
}
}
///////////////////////////////////////////////////////////////////////////////
//
// State Code
latent function MoveToAttackEnemy()
{
ISwatEnemy(m_Pawn).BecomeAThreat();
CurrentMoveToAttackOfficerGoal = new class'MoveToAttackOfficerGoal'(movementResource(), achievingGoal.Priority, GetOfficerTarget());
assert(CurrentMoveToAttackOfficerGoal != None);
CurrentMoveToAttackOfficerGoal.AddRef();
CurrentMoveToAttackOfficerGoal.SetRotateTowardsPointsDuringMovement(true);
// we want to use cover while moving
CurrentMoveToAttackOfficerGoal.SetUseCoveredPaths();
// post the move to goal
CurrentMoveToAttackOfficerGoal.postGoal(self);
}
latent function AttackEnemyWithWeapon()
{
CurrentAttackTargetGoal = new class'AttackTargetGoal'(weaponResource(), GetOfficerTarget());
assert(CurrentAttackTargetGoal != None);
CurrentAttackTargetGoal.AddRef();
// set the chance that the attack target completes after firing once
CurrentAttackTargetGoal.SetChanceToSucceedAfterFiring(GetSkillSpecificSuccessAfterFiringChance());
// post the attack target goal
waitForGoal(CurrentAttackTargetGoal.postGoal(self));
CurrentAttackTargetGoal.unPostGoal(self);
if (! class'Pawn'.static.checkConscious(GetOfficerTarget()))
{
ISwatEnemy(m_Pawn).GetEnemySpeechManagerAction().TriggerDownedOfficerSpeech();
}
}
private latent function FinishUpMoveToAttackBehavior()
{
if (CurrentMoveToAttackOfficerGoal != None)
{
if (CurrentMoveToAttackOfficerGoal.achievingAction != None)
{
MoveToAttackOfficerAction(CurrentMoveToAttackOfficerGoal.achievingAction).FinishUp();
WaitForGoal(CurrentMoveToAttackOfficerGoal);
}
CurrentMoveToAttackOfficerGoal.unPostGoal(self);
CurrentMoveToAttackOfficerGoal.Release();
CurrentMoveToAttackOfficerGoal = None;
}
}
state Running
{
Begin:
waitForResourcesAvailable(achievingGoal.priority, achievingGoal.priority);
MoveToAttackEnemy();
AttackEnemyWithWeapon();
FinishUpMoveToAttackBehavior();
succeed();
}
///////////////////////////////////////////////////////////////////////////////
defaultproperties
{
satisfiesGoal = class'EngageOfficerGoal'
}