-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fish.es
350 lines (314 loc) · 10.4 KB
/
Fish.es
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
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
337
%{
#include "StdH.h"
#include "Models/Enemies/Fish/Fish.h"
%}
uses "Entities/EnemyDive";
%{
static EntityInfo eiFish = {
EIBT_FLESH, 100.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f,
};
#define DISTANCE_ELECTRICITY 8.0f
%}
class CFish : CEnemyDive {
name "Fish";
thumbnail "Thumbnails\\Fish.tbn";
properties:
0 BOOL m_bAttackingByElectricity = FALSE,
1 FLOAT m_tmElectricityTimeStart = 0.0f,
components:
0 class CLASS_BASE "Classes\\EnemyDive.ecl",
1 model MODEL_FISH "Models\\Enemies\\Fish\\Fish.mdl",
2 texture TEXTURE_FISH "Models\\Enemies\\Fish\\Fish1.tex",
3 model MODEL_GLOW "Models\\Enemies\\Fish\\Glow.mdl",
4 texture TEXTURE_GLOW "Models\\Enemies\\Fish\\Glow.tex",
5 texture TEXTURE_SPECULAR "Models\\SpecularTextures\\Medium.tex",
// ************** SOUNDS **************
50 sound SOUND_IDLE "Models\\Enemies\\Fish\\Sounds\\Idle.wav",
51 sound SOUND_SIGHT "Models\\Enemies\\Fish\\Sounds\\Sight.wav",
52 sound SOUND_WOUND "Models\\Enemies\\Fish\\Sounds\\Wound.wav",
53 sound SOUND_DEATH "Models\\Enemies\\Fish\\Sounds\\Death.wav",
54 sound SOUND_ATTACK "Models\\Enemies\\Fish\\Sounds\\Attack.wav",
55 sound SOUND_WOUNDAIR "Models\\Enemies\\Fish\\Sounds\\WoundAir.wav",
56 sound SOUND_DEATHAIR "Models\\Enemies\\Fish\\Sounds\\DeathAir.wav",
functions:
// describe how this enemy killed player
virtual CTString GetPlayerKillDescription(const CTString &strPlayerName, const EDeath &eDeath)
{
CTString str;
str.PrintF(TRANS("%s was electrocuted by a fish"), strPlayerName);
return str;
}
virtual const CTFileName &GetComputerMessageName(void) const {
static DECLARE_CTFILENAME(fnm, "Data\\Messages\\Enemies\\Fish.txt");
return fnm;
};
void Precache(void) {
CEnemyBase::Precache();
PrecacheModel(MODEL_GLOW );
PrecacheTexture(TEXTURE_GLOW);
PrecacheSound(SOUND_IDLE);
PrecacheSound(SOUND_SIGHT);
PrecacheSound(SOUND_WOUND);
PrecacheSound(SOUND_DEATH);
PrecacheSound(SOUND_WOUNDAIR);
PrecacheSound(SOUND_DEATHAIR);
PrecacheSound(SOUND_ATTACK);
};
/* Entity info */
void *GetEntityInfo(void)
{
return &eiFish;
};
/* Receive damage */
void ReceiveDamage(CEntity *penInflictor, enum DamageType dmtType,
FLOAT fDamageAmmount, const FLOAT3D &vHitPoint, const FLOAT3D &vDirection)
{
if (dmtType==DMT_DROWNING) {
//en_tmMaxHoldBreath = -5.0f;
fDamageAmmount/=2.0f;
}
// fish can't harm fish
if (!IsOfClass(penInflictor, "Fish")) {
CEnemyDive::ReceiveDamage(penInflictor, dmtType, fDamageAmmount, vHitPoint, vDirection);
}
};
// damage anim
INDEX AnimForDamage(FLOAT fDamage)
{
m_bAttackingByElectricity = FALSE;
INDEX iAnim = FISH_ANIM_WOUND;
StartModelAnim(iAnim, 0);
return iAnim;
};
// death
INDEX AnimForDeath(void) {
if (!m_bInLiquid) {
return AnimForDamage(10.0f);
}
INDEX iAnim;
switch (IRnd()%3) {
default: iAnim = FISH_ANIM_DEATH; break;
case 0: iAnim = FISH_ANIM_DEATH; break;
case 1: iAnim = FISH_ANIM_DEATH02; break;
case 2: iAnim = FISH_ANIM_DEATH03; break;
}
StartModelAnim(iAnim, 0);
return iAnim;
};
void DeathNotify(void)
{
m_bAttackingByElectricity = FALSE;
en_fDensity = 500.0f;
};
void RenderParticles(void)
{
if( m_bAttackingByElectricity && m_penEnemy!=NULL)
{
// render one lightning toward enemy
FLOAT3D vSource = GetPlacement().pl_PositionVector;
FLOAT3D vTarget = m_penEnemy->GetPlacement().pl_PositionVector;
FLOAT3D vDirection = (vTarget-vSource).Normalize();
Particles_Ghostbuster(vSource, vTarget, 32, 1.0f);
// random lightnings arround
for( INDEX i=0; i<4; i++)
{
FLOAT3D vDirection = vSource;
vDirection(1) += ((FLOAT(rand())/RAND_MAX)-0.5f) * DISTANCE_ELECTRICITY/1.0f;
vDirection(2) += ((FLOAT(rand())/RAND_MAX)-0.5f) * DISTANCE_ELECTRICITY/1.0f;
vDirection(3) += ((FLOAT(rand())/RAND_MAX)-0.5f) * DISTANCE_ELECTRICITY/1.0f;
Particles_Ghostbuster(vSource, vDirection, 32, 1.0f);
}
}
CEnemyBase::RenderParticles();
}
// virtual anim functions
void StandingAnim(void)
{
StartModelAnim(FISH_ANIM_IDLE, AOF_LOOPING|AOF_NORESTART);
};
void WalkingAnim(void)
{
if (m_bInLiquid) {
StartModelAnim(FISH_ANIM_SWIM, AOF_LOOPING|AOF_NORESTART);
} else {
StartModelAnim(FISH_ANIM_WOUND, AOF_LOOPING|AOF_NORESTART);
}
};
void RunningAnim(void)
{
WalkingAnim();
};
void RotatingAnim(void)
{
WalkingAnim();
};
// virtual sound functions
void IdleSound(void)
{
PlaySound(m_soSound, SOUND_IDLE, SOF_3D|SOF_NOFILTER);
};
void SightSound(void)
{
PlaySound(m_soSound, SOUND_SIGHT, SOF_3D|SOF_NOFILTER);
};
void WoundSound(void)
{
if (m_bInLiquid) {
PlaySound(m_soSound, SOUND_WOUND, SOF_3D|SOF_NOFILTER);
} else {
PlaySound(m_soSound, SOUND_WOUNDAIR, SOF_3D|SOF_NOFILTER);
}
};
void DeathSound(void)
{
if (m_bInLiquid) {
PlaySound(m_soSound, SOUND_DEATH, SOF_3D|SOF_NOFILTER);
} else {
PlaySound(m_soSound, SOUND_DEATHAIR, SOF_3D|SOF_NOFILTER);
}
};
BOOL AdjustShadingParameters(FLOAT3D &vLightDirection, COLOR &colLight, COLOR &colAmbient)
{
FLOAT fTimePassed = _pTimer->GetLerpedCurrentTick()-m_tmElectricityTimeStart;
if( m_bAttackingByElectricity && (fTimePassed>0))
{
FLOAT fDieFactor = 1.0f;
if( fTimePassed > 0.25f)
{
// calculate light dying factor
fDieFactor = 1.0-(ClampUp(fTimePassed-0.25f,0.5f)/0.5f);
}
// adjust light fx
FLOAT fR = 0.7f+0.1f*(FLOAT(rand())/RAND_MAX);
FLOAT fG = 0.7f+0.2f*(FLOAT(rand())/RAND_MAX);
FLOAT fB = 0.7f+0.3f*(FLOAT(rand())/RAND_MAX);
colAmbient = RGBToColor( fR*128*fDieFactor, fG*128*fDieFactor, fB*128*fDieFactor);
colLight = C_WHITE;
return CEnemyBase::AdjustShadingParameters(vLightDirection, colLight, colAmbient);
}
return CEnemyBase::AdjustShadingParameters(vLightDirection, colLight, colAmbient);
};
procedures:
/************************************************************
* A T T A C K E N E M Y *
************************************************************/
DiveHit(EVoid) : CEnemyDive::DiveHit
{
if (CalcDist(m_penEnemy) > DISTANCE_ELECTRICITY)
{
// swim to enemy
m_fShootTime = _pTimer->CurrentTick() + 0.25f;
return EReturn();
}
// wait to allow enemy to go aoutside bite range
autowait(0.6f);
m_bAttackingByElectricity = TRUE;
m_tmElectricityTimeStart = _pTimer->CurrentTick();
AddAttachmentToModel(this, *GetModelObject(), FISH_ATTACHMENT_GLOW, MODEL_GLOW, TEXTURE_GLOW, 0, 0, 0);
CModelObject &moGlow = GetModelObject()->GetAttachmentModel(FISH_ATTACHMENT_GLOW)->amo_moModelObject;
moGlow.StretchModel(FLOAT3D(4.0f, 4.0f, 4.0f));
// bite
StartModelAnim(FISH_ANIM_ATTACK, 0);
PlaySound(m_soSound, SOUND_ATTACK, SOF_3D|SOF_NOFILTER);
if (CalcDist(m_penEnemy)<DISTANCE_ELECTRICITY)
{
// damage enemy
InflictRangeDamage(this, DMT_CLOSERANGE, 15.0f, GetPlacement().pl_PositionVector, 1.0f, DISTANCE_ELECTRICITY);
// push target away
FLOAT3D vSpeed;
GetHeadingDirection(0.0f, vSpeed);
vSpeed = vSpeed * 30.0f;
KickEntity(m_penEnemy, vSpeed);
}
autowait(0.5f);
m_bAttackingByElectricity = FALSE;
GetModelObject()->RemoveAttachmentModel(FISH_ATTACHMENT_GLOW);
StandingAnim();
autowait(0.2f + FRnd()/3);
return EReturn();
};
Hit(EVoid) : CEnemyBase::Hit
{
jump DiveHit();
}
/************************************************************
* M A I N *
************************************************************/
Main(EVoid) {
// declare yourself as a model
InitAsModel();
// fish must not go upstairs, or it will get out of water
SetPhysicsFlags((EPF_MODEL_WALKING|EPF_HASGILLS)&~EPF_ONBLOCK_CLIMBORSLIDE|EPF_ONBLOCK_SLIDE);
SetCollisionFlags(ECF_MODEL);
SetFlags(GetFlags()|ENF_ALIVE);
SetHealth(30.0f);
m_fMaxHealth = 30.0f;
en_tmMaxHoldBreath = 15.0f;
en_fDensity = 1000.0f;
m_EedtType = EDT_GROUND_DIVE;
// set your appearance
SetModel(MODEL_FISH);
SetModelMainTexture(TEXTURE_FISH);
SetModelSpecularTexture(TEXTURE_SPECULAR);
// rotation speeds
m_fDiveWalkSpeed = 15.0f;
m_fDiveAttackRunSpeed = 20.0f;
m_fDiveCloseRunSpeed = 25.0f;
m_fWalkSpeed = 15.0f;
m_aWalkRotateSpeed = 900.0f;
m_fAttackRunSpeed = 10.0f;
m_fCloseRunSpeed = 12.0f;
// translation speeds
m_aDiveWalkRotateSpeed = 360.0f;
m_aDiveAttackRotateSpeed = 1800.0f;
m_aDiveCloseRotateSpeed = 3600.0f;
// distances
m_fDiveIgnoreRange = 200.0f;
m_fDiveAttackDistance = 100.0f;
m_fDiveCloseDistance = 15.0f;
m_fDiveStopDistance = 2.0f;
// frequencies
m_fDiveAttackFireTime = 0.0f;
m_fDiveCloseFireTime = 0.0f;
// damage/explode properties
m_fBlowUpAmount = 80.0f;
m_fBodyParts = 2;
m_fDamageWounded = 1.0f;
m_iScore = 500;
{
// translation speeds
m_aWalkRotateSpeed = 360.0f;
m_aAttackRotateSpeed = 1800.0f;
m_aCloseRotateSpeed = 3600.0f;
// distances
m_fIgnoreRange = 200.0f;
m_fAttackDistance = 100.0f;
m_fCloseDistance = 15.0f;
m_fStopDistance = 2.0f;
// frequencies
m_fAttackFireTime = 0.0f;
m_fCloseFireTime = 0.0f;
}
// set stretch factors for height and width
GetModelObject()->StretchModel(FLOAT3D(1.0f, 1.0f, 1.0f));
ModelChangeNotify();
en_fAcceleration = 200.0f;
en_fDeceleration = 200.0f;
// continue behavior in base class
jump CEnemyDive::MainLoop();
};
};