-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevilProjectile.es
More file actions
285 lines (234 loc) · 7.94 KB
/
DevilProjectile.es
File metadata and controls
285 lines (234 loc) · 7.94 KB
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
/* 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. */
511
%{
#include "StdH.h"
%}
uses "Entities/BasicEffects";
uses "Entities/Light";
// input parameter for launching the projectile
event EDevilProjectile {
CEntityPointer penLauncher, // who launched it
CEntityPointer penTarget, // target entity
};
%{
#define FLY_TIME 15.0f
#define ROTATE_SPEED 200.0f
#define MOVING_SPEED 30.0f
#define MOVING_FREQUENCY 0.1f
%}
class CDevilProjectile : CMovableModelEntity {
name "Devil projectile";
thumbnail "";
properties:
1 CEntityPointer m_penLauncher, // who lanuched it
2 CEntityPointer m_penTarget, // target entity
10 FLOAT m_fIgnoreTime = 0.0f, // time when laucher will be ignored
11 FLOAT m_fStartTime = 0.0f, // start time when launched
12 FLOAT3D m_vDesiredAngle = FLOAT3D(0,0,0),
13 BOOL m_bFly = FALSE,
20 CSoundObject m_soEffect, // sound channel
{
CLightSource m_lsLightSource;
}
components:
1 class CLASS_BASIC_EFFECT "Classes\\BasicEffect.ecl",
2 class CLASS_LIGHT "Classes\\Light.ecl",
// ********* PLAYER ROCKET *********
10 model MODEL_FLARE "Models\\Enemies\\Devil\\Flare.mdl",
11 texture TEXTURE_FLARE "Models\\Enemies\\Devil\\12.tex",
functions:
/* Read from stream. */
void Read_t( CTStream *istr) // throw char *
{
CMovableModelEntity::Read_t(istr);
// setup light source
SetupLightSource();
};
/* Get static light source information. */
CLightSource *GetLightSource(void)
{
if (!IsPredictor()) {
return &m_lsLightSource;
} else {
return NULL;
}
};
// Setup light source
void SetupLightSource(void)
{
// setup light source
CLightSource lsNew;
lsNew.ls_ulFlags = LSF_NONPERSISTENT|LSF_DYNAMIC;
lsNew.ls_rHotSpot = 0.0f;
lsNew.ls_colColor = RGBToColor(0, 128, 128);
lsNew.ls_rFallOff = 5.0f;
lsNew.ls_plftLensFlare = NULL;
lsNew.ls_ubPolygonalMask = 0;
lsNew.ls_paoLightAnimation = NULL;
m_lsLightSource.ls_penEntity = this;
m_lsLightSource.SetLightSource(lsNew);
};
/************************************************************
* MOVING FUNCTIONS *
************************************************************/
// calculate rotation
void CalcHeadingRotation(ANGLE aWantedHeadingRelative, ANGLE &aRotation) {
// normalize it to [-180,+180] degrees
aWantedHeadingRelative = NormalizeAngle(aWantedHeadingRelative);
// if desired position is left
if (aWantedHeadingRelative < -ROTATE_SPEED*MOVING_FREQUENCY) {
// start turning left
aRotation = -ROTATE_SPEED;
// if desired position is right
} else if (aWantedHeadingRelative > ROTATE_SPEED*MOVING_FREQUENCY) {
// start turning right
aRotation = +ROTATE_SPEED;
// if desired position is more-less ahead
} else {
aRotation = aWantedHeadingRelative/MOVING_FREQUENCY;
}
};
// calculate angle from position
void CalcAngleFromPosition() {
// target enemy body
FLOAT3D vTarget;
/* EntityInfo *peiTarget = (EntityInfo*) (m_penTarget->GetEntityInfo());
GetEntityInfoPosition(m_penTarget, peiTarget->vTargetCenter, vTarget);*/
vTarget = m_penTarget->GetPlacement().pl_PositionVector;
vTarget += FLOAT3D(m_penTarget->en_mRotation(1, 2),
m_penTarget->en_mRotation(2, 2),
m_penTarget->en_mRotation(3, 2)) * 2.0f;
// find relative orientation towards the desired position
m_vDesiredAngle = (vTarget - GetPlacement().pl_PositionVector).Normalize();
};
// rotate entity to desired angle
void RotateToAngle() {
// find relative heading towards the desired angle
ANGLE aRotation;
CalcHeadingRotation(GetRelativeHeading(m_vDesiredAngle), aRotation);
// start rotating
SetDesiredRotation(ANGLE3D(aRotation, 0, 0));
};
// fly move in direction
void FlyInDirection() {
RotateToAngle();
// target enemy body
FLOAT3D vTarget;
/* EntityInfo *peiTarget = (EntityInfo*) (m_penTarget->GetEntityInfo());
GetEntityInfoPosition(m_penTarget, peiTarget->vTargetCenter, vTarget);*/
vTarget = m_penTarget->GetPlacement().pl_PositionVector;
vTarget += FLOAT3D(m_penTarget->en_mRotation(1, 2),
m_penTarget->en_mRotation(2, 2),
m_penTarget->en_mRotation(3, 2)) * 2.0f;
// determine translation speed
FLOAT3D vTranslation = (vTarget - GetPlacement().pl_PositionVector) * !en_mRotation;
vTranslation(1) = 0.0f;
vTranslation.Normalize();
vTranslation *= MOVING_SPEED;
// start moving
SetDesiredTranslation(vTranslation);
};
// fly entity to desired position
void FlyToPosition() {
CalcAngleFromPosition();
FlyInDirection();
};
// rotate entity to desired position
void RotateToPosition() {
CalcAngleFromPosition();
RotateToAngle();
};
// stop moving entity
void StopMoving() {
StopRotating();
StopTranslating();
};
// stop rotating entity
void StopRotating() {
SetDesiredRotation(ANGLE3D(0, 0, 0));
};
// stop translating
void StopTranslating() {
SetDesiredTranslation(FLOAT3D(0.0f, 0.0f, 0.0f));
};
/************************************************************
* C O M M O N F U N C T I O N S *
************************************************************/
void ProjectileTouch(CEntityPointer penHit) {
// direct damage
FLOAT3D vDirection;
AnglesToDirectionVector(GetPlacement().pl_OrientationAngle, vDirection);
InflictDirectDamage(penHit, m_penLauncher, DMT_PROJECTILE, 15.0f,
GetPlacement().pl_PositionVector, vDirection);
};
/************************************************************
* P R O C E D U R E S *
************************************************************/
procedures:
Fly(EVoid) {
// bounce loop
m_bFly = TRUE;
while(m_bFly && m_fStartTime+FLY_TIME > _pTimer->CurrentTick()) {
wait(0.1f) {
on (EBegin) : {
FlyToPosition();
resume;
}
on (EPass epass) : {
BOOL bHit;
// ignore launcher within 1 second
bHit = epass.penOther!=m_penLauncher || _pTimer->CurrentTick()>m_fIgnoreTime;
// ignore twister
bHit &= !IsOfClass(epass.penOther, "Twister");
if (bHit) {
ProjectileTouch(epass.penOther);
m_bFly = FALSE;
stop;
}
resume;
}
on (ETouch etouch) : {
// clear time limit for launcher
m_fIgnoreTime = 0.0f;
resume;
}
on (ETimer) : { stop; }
}
}
return EEnd();
};
// --->>> MAIN
Main(EDevilProjectile eLaunch) {
// remember the initial parameters
ASSERT(eLaunch.penLauncher!=NULL);
ASSERT(eLaunch.penTarget!=NULL);
m_penLauncher = eLaunch.penLauncher;
m_penTarget = eLaunch.penTarget;
// set appearance
InitAsModel();
SetPhysicsFlags(EPF_PROJECTILE_FLYING);
SetCollisionFlags(ECF_PROJECTILE_MAGIC);
SetModel(MODEL_FLARE);
SetModelMainTexture(TEXTURE_FLARE);
// setup light source
SetupLightSource();
// remember lauching time
m_fIgnoreTime = _pTimer->CurrentTick() + 1.0f;
// fly
m_fStartTime = _pTimer->CurrentTick();
autocall Fly() EEnd;
// cease to exist
Destroy();
return;
}
};