forked from JACoders/OpenJK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI_Atst.cpp
336 lines (281 loc) · 7.88 KB
/
AI_Atst.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
/*
===========================================================================
Copyright (C) 2000 - 2013, Raven Software, Inc.
Copyright (C) 2001 - 2013, Activision, Inc.
Copyright (C) 2013 - 2015, OpenJK contributors
This file is part of the OpenJK source code.
OpenJK is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
#include "g_headers.h"
#include "b_local.h"
#define MIN_MELEE_RANGE 640
#define MIN_MELEE_RANGE_SQR ( MIN_MELEE_RANGE * MIN_MELEE_RANGE )
#define MIN_DISTANCE 128
#define MIN_DISTANCE_SQR ( MIN_DISTANCE * MIN_DISTANCE )
#define TURN_OFF 0x00000100//G2SURFACEFLAG_NODESCENDANTS
#define LEFT_ARM_HEALTH 40
#define RIGHT_ARM_HEALTH 40
extern void G_SoundOnEnt( gentity_t *ent, soundChannel_t channel, const char *soundPath );
/*
-------------------------
NPC_ATST_Precache
-------------------------
*/
void NPC_ATST_Precache(void)
{
G_SoundIndex( "sound/chars/atst/atst_damaged1" );
G_SoundIndex( "sound/chars/atst/atst_damaged2" );
RegisterItem( FindItemForWeapon( WP_ATST_MAIN )); //precache the weapon
RegisterItem( FindItemForWeapon( WP_BOWCASTER )); //precache the weapon
RegisterItem( FindItemForWeapon( WP_ROCKET_LAUNCHER )); //precache the weapon
G_EffectIndex( "env/med_explode2" );
// G_EffectIndex( "smaller_chunks" );
G_EffectIndex( "blaster/smoke_bolton" );
G_EffectIndex( "droidexplosion1" );
}
//-----------------------------------------------------------------
static void ATST_PlayEffect( gentity_t *self, const int boltID, const char *fx )
{
if ( boltID >=0 && fx && fx[0] )
{
mdxaBone_t boltMatrix;
vec3_t org, dir;
gi.G2API_GetBoltMatrix( self->ghoul2, self->playerModel,
boltID,
&boltMatrix, self->currentAngles, self->currentOrigin, (cg.time?cg.time:level.time),
NULL, self->s.modelScale );
gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, org );
gi.G2API_GiveMeVectorFromMatrix( boltMatrix, NEGATIVE_Y, dir );
G_PlayEffect( fx, org, dir );
}
}
/*
-------------------------
G_ATSTCheckPain
Called by NPC's and player in an ATST
-------------------------
*/
void G_ATSTCheckPain( gentity_t *self, gentity_t *other, vec3_t point, int damage, int mod,int hitLoc )
{
int newBolt;
if ( rand() & 1 )
{
G_SoundOnEnt( self, CHAN_LESS_ATTEN, "sound/chars/atst/atst_damaged1" );
}
else
{
G_SoundOnEnt( self, CHAN_LESS_ATTEN, "sound/chars/atst/atst_damaged2" );
}
if ((hitLoc==HL_ARM_LT) && (self->locationDamage[HL_ARM_LT] > LEFT_ARM_HEALTH))
{
if (self->locationDamage[hitLoc] >= LEFT_ARM_HEALTH) // Blow it up?
{
newBolt = gi.G2API_AddBolt( &self->ghoul2[self->playerModel], "*flash3" );
if ( newBolt != -1 )
{
// G_PlayEffect( "small_chunks", self->playerModel, self->genericBolt1, self->s.number);
ATST_PlayEffect( self, self->genericBolt1, "env/med_explode2" );
G_PlayEffect( "blaster/smoke_bolton", self->playerModel, newBolt, self->s.number);
}
gi.G2API_SetSurfaceOnOff( &self->ghoul2[self->playerModel], "head_light_blaster_cann", TURN_OFF );
}
}
else if ((hitLoc==HL_ARM_RT) && (self->locationDamage[HL_ARM_RT] > RIGHT_ARM_HEALTH)) // Blow it up?
{
if (self->locationDamage[hitLoc] >= RIGHT_ARM_HEALTH)
{
newBolt = gi.G2API_AddBolt( &self->ghoul2[self->playerModel], "*flash4" );
if ( newBolt != -1 )
{
// G_PlayEffect( "small_chunks", self->playerModel, self->genericBolt2, self->s.number);
ATST_PlayEffect( self, self->genericBolt2, "env/med_explode2" );
G_PlayEffect( "blaster/smoke_bolton", self->playerModel, newBolt, self->s.number);
}
gi.G2API_SetSurfaceOnOff( &self->ghoul2[self->playerModel], "head_concussion_charger", TURN_OFF );
}
}
}
/*
-------------------------
NPC_ATST_Pain
-------------------------
*/
void NPC_ATST_Pain( gentity_t *self, gentity_t *inflictor, gentity_t *other, vec3_t point, int damage, int mod,int hitLoc )
{
G_ATSTCheckPain( self, other, point, damage, mod, hitLoc );
NPC_Pain( self, inflictor, other, point, damage, mod );
}
/*
-------------------------
ATST_Hunt
-------------------------`
*/
void ATST_Hunt( qboolean visible, qboolean advance )
{
if ( NPCInfo->goalEntity == NULL )
{//hunt
NPCInfo->goalEntity = NPC->enemy;
}
NPCInfo->combatMove = qtrue;
NPC_MoveToGoal( qtrue );
}
/*
-------------------------
ATST_Ranged
-------------------------
*/
void ATST_Ranged( qboolean visible, qboolean advance, qboolean altAttack )
{
if ( TIMER_Done( NPC, "atkDelay" ) && visible ) // Attack?
{
TIMER_Set( NPC, "atkDelay", Q_irand( 500, 3000 ) );
if (altAttack)
{
ucmd.buttons |= BUTTON_ATTACK|BUTTON_ALT_ATTACK;
}
else
{
ucmd.buttons |= BUTTON_ATTACK;
}
}
if ( NPCInfo->scriptFlags & SCF_CHASE_ENEMIES )
{
ATST_Hunt( visible, advance );
}
}
/*
-------------------------
ATST_Attack
-------------------------
*/
void ATST_Attack( void )
{
qboolean altAttack=qfalse;
int blasterTest,chargerTest,weapon;
if ( NPC_CheckEnemyExt() == qfalse )//!NPC->enemy )//
{
NPC->enemy = NULL;
return;
}
NPC_FaceEnemy( qtrue );
// Rate our distance to the target, and our visibilty
float distance = (int) DistanceHorizontalSquared( NPC->currentOrigin, NPC->enemy->currentOrigin );
distance_e distRate = ( distance > MIN_MELEE_RANGE_SQR ) ? DIST_LONG : DIST_MELEE;
qboolean visible = NPC_ClearLOS( NPC->enemy );
qboolean advance = (qboolean)(distance > MIN_DISTANCE_SQR);
// If we cannot see our target, move to see it
if ( visible == qfalse )
{
if ( NPCInfo->scriptFlags & SCF_CHASE_ENEMIES )
{
ATST_Hunt( visible, advance );
return;
}
}
// Decide what type of attack to do
switch ( distRate )
{
case DIST_MELEE:
NPC_ChangeWeapon( WP_ATST_MAIN );
break;
case DIST_LONG:
NPC_ChangeWeapon( WP_ATST_SIDE );
// See if the side weapons are there
blasterTest = gi.G2API_GetSurfaceRenderStatus( &NPC->ghoul2[NPC->playerModel], "head_light_blaster_cann" );
chargerTest = gi.G2API_GetSurfaceRenderStatus( &NPC->ghoul2[NPC->playerModel], "head_concussion_charger" );
// It has both side weapons
if (!(blasterTest & TURN_OFF) && !(chargerTest & TURN_OFF))
{
weapon = Q_irand( 0, 1); // 0 is blaster, 1 is charger (ALT SIDE)
if (weapon) // Fire charger
{
altAttack = qtrue;
}
else
{
altAttack = qfalse;
}
}
else if (!(blasterTest & TURN_OFF)) // Blaster is on
{
altAttack = qfalse;
}
else if (!(chargerTest & TURN_OFF)) // Blaster is on
{
altAttack = qtrue;
}
else
{
NPC_ChangeWeapon( WP_NONE );
}
break;
}
NPC_FaceEnemy( qtrue );
ATST_Ranged( visible, advance,altAttack );
}
/*
-------------------------
ATST_Patrol
-------------------------
*/
void ATST_Patrol( void )
{
if ( NPC_CheckPlayerTeamStealth() )
{
NPC_UpdateAngles( qtrue, qtrue );
return;
}
//If we have somewhere to go, then do that
if (!NPC->enemy)
{
if ( UpdateGoal() )
{
ucmd.buttons |= BUTTON_WALKING;
NPC_MoveToGoal( qtrue );
NPC_UpdateAngles( qtrue, qtrue );
}
}
}
/*
-------------------------
ATST_Idle
-------------------------
*/
void ATST_Idle( void )
{
NPC_BSIdle();
NPC_SetAnim( NPC, SETANIM_BOTH, BOTH_STAND1, SETANIM_FLAG_NORMAL );
}
/*
-------------------------
NPC_BSDroid_Default
-------------------------
*/
void NPC_BSATST_Default( void )
{
if ( NPC->enemy )
{
if( (NPCInfo->scriptFlags & SCF_CHASE_ENEMIES) )
{
NPCInfo->goalEntity = NPC->enemy;
}
ATST_Attack();
}
else if ( NPCInfo->scriptFlags & SCF_LOOK_FOR_ENEMIES )
{
ATST_Patrol();
}
else
{
ATST_Idle();
}
}