-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAirShockwave.es
More file actions
220 lines (180 loc) · 7.74 KB
/
AirShockwave.es
File metadata and controls
220 lines (180 loc) · 7.74 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
/* 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. */
// WARNING: probable sync bads, doesn't work right
349
%{
#include "StdH.h"
#include "ModelsMP/Enemies/AirElemental/ShockwaveBase.h"
#include "ModelsMP/Enemies/AirElemental/Shockwave.h"
%}
uses "Entities/BasicEffects";
// input parameter for launching the projectile
event EAirShockwave {
CEntityPointer penLauncher, // who launched it
FLOAT fHeight, // height in the beginning
FLOAT fEndWidth, // width along the X,Z axes in the end
FLOAT fDuration, // how long to live
};
%{
// shockwave
#define ECF_SHOCKAWAVE ( \
((ECBI_BRUSH|ECBI_MODEL|ECBI_CORPSE|ECBI_ITEM|ECBI_PROJECTILE_MAGIC|ECBI_PROJECTILE_SOLID)<<ECB_TEST) |\
((ECBI_BRUSH|ECBI_MODEL|ECBI_CORPSE|ECBI_ITEM|ECBI_PROJECTILE_MAGIC|ECBI_PROJECTILE_SOLID)<<ECB_PASS) |\
((ECBI_MODEL)<<ECB_IS))
#define EPF_SHOCKAWAVE ( \
EPF_ONBLOCK_STOP|EPF_ORIENTEDBYGRAVITY|EPF_ABSOLUTETRANSLATE)
#define SHOCKWAVE_HEIGHT 5.0f
#define SHOCKWAVE_WIDTH 0.1f
%}
class CAirShockwave : CMovableModelEntity {
name "AirShockwave";
thumbnail "";
properties:
1 CEntityPointer m_penLauncher, // who lanuched it
2 FLOAT m_fHeight = 0.0f, // beginning stretch
3 FLOAT m_fEndWidth = 0.0f, // ending stretch along the X,Z axes
4 FLOAT m_tmBegin = 0.0f, // time when animation began
5 FLOAT m_tmEnd = 0.0f, // time to destroy
6 FLOAT m_fDuration = 0.0f, // how long?
7 BOOL m_bGrowing = FALSE, // are we growing?
8 FLOAT m_tmLastGrow = 0.0f, // last grow time
9 FLOAT m_fFadeStartTime = 0.0f, // when the fading started
10 FLOAT m_fFadeStartPercent = 0.6f, // when to start the fading
// internal variables
20 FLOAT m_fStretchY = 0.0f,
21 FLOAT m_fBeginStretchXZ = 0.0f,
22 FLOAT m_fEndStretchXZ = 0.0f,
25 FLOATaabbox3D m_boxMaxSize = FLOATaabbox3D(FLOAT3D(0,0,0), FLOAT3D(1,1,1)),
30 BOOL m_bFadeOut = FALSE, // set this when fading out
components:
1 class CLASS_BASIC_EFFECT "Classes\\BasicEffect.ecl",
10 model MODEL_INVISIBLE "ModelsMP\\Enemies\\AirElemental\\ShockwaveBase.mdl",
11 model MODEL_SHOCKWAVE "ModelsMP\\Enemies\\AirElemental\\Shockwave.mdl",
12 texture TEXTURE_SHOCKWAVE "ModelsMP\\Enemies\\AirElemental\\Twister.tex",
functions:
// get the attachment that IS the AirShockwave
CModelObject *ShockwaveModel(void) {
CAttachmentModelObject &amo0 = *GetModelObject()->GetAttachmentModel(SHOCKWAVEBASE_ATTACHMENT_SHOCKWAVE);
return &(amo0.amo_moModelObject);
};
// per-frame adjustments here
BOOL AdjustShadingParameters(FLOAT3D &vLightDirection, COLOR &colLight, COLOR &colAmbient) {
// growing
if (m_bGrowing) {
FLOAT3D vSize;
FLOAT fLifeTime = _pTimer->GetLerpedCurrentTick() - m_tmBegin;
vSize(1) = (fLifeTime/m_fDuration)*(m_fEndStretchXZ-m_fBeginStretchXZ)+m_fBeginStretchXZ;
vSize(2) = m_fStretchY;
vSize(3) = vSize(1);
ShockwaveModel()->StretchModel(vSize);
// start fadeout if more than 70% of lifetime passed
if ((fLifeTime/m_fDuration)>m_fFadeStartPercent && !m_bFadeOut) {
m_bFadeOut = TRUE;
m_fFadeStartTime = _pTimer->GetLerpedCurrentTick();
}
// remember last grow time
m_tmLastGrow = _pTimer->GetLerpedCurrentTick();
}
// fading out
if (m_bFadeOut) {
FLOAT fTimeRemain = m_tmEnd - _pTimer->GetLerpedCurrentTick();
FLOAT fFadeTime = (1 - m_fFadeStartPercent)*m_fDuration;
if (fTimeRemain < 0.0f) { fTimeRemain = 0.0f; }
COLOR colAlpha = ShockwaveModel()->mo_colBlendColor;
colAlpha = (colAlpha&0xffffff00) + (COLOR(fTimeRemain/fFadeTime*0xff)&0xff);
ShockwaveModel()->mo_colBlendColor = colAlpha;
}
return CMovableModelEntity::AdjustShadingParameters(vLightDirection, colLight, colAmbient);
};
// throw away an entity when touched
void LaunchEntity(CEntity *pen) {
// don't launch air elemental and twisters and shockwaves and any items
if (IsOfClass(pen, "AirElemental") || IsOfClass(pen, "Twister")
|| IsDerivedFromClass(pen, "Item") || IsOfClass(pen, "AirShockwave")) {
return;
}
if (pen->GetPhysicsFlags()&EPF_MOVABLE) {
FLOAT3D vSpeed;
vSpeed = pen->GetPlacement().pl_PositionVector - GetPlacement().pl_PositionVector;
if (vSpeed(2)<vSpeed.Length()*0.5f) { vSpeed(2)=vSpeed.Length()*0.5f; }
vSpeed.Normalize();
vSpeed = vSpeed*50.0f;
((CMovableEntity &)*pen).GiveImpulseTranslationAbsolute(vSpeed);
}
};
void TestForCollisionAndLaunchEntity() {
// test the bounding box for all colliding entities
static CStaticStackArray<CEntity *> apenNearEntities;
FLOAT fLifeTime = _pTimer->CurrentTick() - m_tmBegin;
FLOAT fCurrentRadius = Lerp(SHOCKWAVE_WIDTH, m_fEndWidth, fLifeTime/m_fDuration)/2.0f;
FLOATaabbox3D m_boxCurrent = m_boxMaxSize;
m_boxCurrent += GetPlacement().pl_PositionVector;
// width of 'launch belt'
FLOAT fBeltWidth = m_fEndWidth*_pTimer->TickQuantum*2.0f/m_fDuration;
GetWorld()->FindEntitiesNearBox(m_boxCurrent, apenNearEntities);
for (INDEX i=0; i<apenNearEntities.Count(); i++)
{
FLOAT fDistance = DistanceTo(this, apenNearEntities[i]);
FLOATaabbox3D m_boxEntity;
apenNearEntities[i]->GetBoundingBox(m_boxEntity);
if (fDistance<(fCurrentRadius+fBeltWidth/2.0f) && fDistance>(fCurrentRadius-fBeltWidth/2.0f) &&
m_boxEntity.HasContactWith(m_boxCurrent)) {
LaunchEntity(apenNearEntities[i]);
}
}
CMovableModelEntity::PreMoving();
};
procedures:
// --->>> MAIN
Main(EAirShockwave eas) {
// remember the initial parameters
ASSERT(eas.penLauncher!=NULL);
ASSERT(eas.fHeight>0.0f);
ASSERT(eas.fEndWidth>0.1f);
ASSERT(eas.fDuration>0.0f);
m_penLauncher = eas.penLauncher;
m_fHeight = eas.fHeight;
m_fEndWidth = eas.fEndWidth;
m_fDuration = eas.fDuration;
// calculate stretches from parameters
m_fStretchY = m_fHeight/SHOCKWAVE_HEIGHT;
m_fBeginStretchXZ = 1.0f;
m_fEndStretchXZ = m_fEndWidth/SHOCKWAVE_WIDTH;
FLOAT3D v1 = FLOAT3D(-m_fEndWidth/2.0f, 0.0f, -m_fEndWidth/2.0f);
FLOAT3D v2 = FLOAT3D(+m_fEndWidth/2.0f, m_fHeight, +m_fEndWidth/2.0f);
m_boxMaxSize = FLOATaabbox3D(v1, v2);
// initialization
InitAsModel();
SetPhysicsFlags(EPF_SHOCKAWAVE);
SetCollisionFlags(ECF_SHOCKAWAVE);
SetFlags(GetFlags() | ENF_SEETHROUGH);
// set appearance
SetModel(MODEL_INVISIBLE);
AddAttachmentToModel(this, *GetModelObject(), SHOCKWAVEBASE_ATTACHMENT_SHOCKWAVE, MODEL_SHOCKWAVE, TEXTURE_SHOCKWAVE, 0, 0, 0);
GetModelObject()->StretchModel(FLOAT3D(1.0f, 1.0f, 1.0f));
ModelChangeNotify();
ShockwaveModel()->StretchModel(FLOAT3D(m_fBeginStretchXZ, m_fStretchY, m_fBeginStretchXZ));
autowait(_pTimer->TickQuantum);
m_tmBegin = _pTimer->CurrentTick();
m_tmEnd = m_tmBegin + m_fDuration;
m_tmLastGrow = _pTimer->CurrentTick();
m_bGrowing = TRUE;
while(_pTimer->CurrentTick()<m_tmEnd)
{
autowait(_pTimer->TickQuantum);
TestForCollisionAndLaunchEntity();
}
// cease to exist
Destroy();
return;
}
};