forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransitionDamageFX.cpp
More file actions
489 lines (377 loc) · 16 KB
/
Copy pathTransitionDamageFX.cpp
File metadata and controls
489 lines (377 loc) · 16 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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** 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/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: TransitionDamageFX.cpp ///////////////////////////////////////////////////////////////////
// Author: Colin Day, March 2002
// Desc: Damage module capable of launching various effects on damage transitions
///////////////////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/Xfer.h"
#include "GameClient/Drawable.h"
#include "GameClient/FXList.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
#include "GameLogic/ObjectCreationList.h"
#include "GameLogic/Module/TransitionDamageFX.h"
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
TransitionDamageFXModuleData::TransitionDamageFXModuleData()
{
Int i, j;
for( i = 0; i < BODYDAMAGETYPE_COUNT; i++ )
{
for( j = 0; j < DAMAGE_MODULE_MAX_FX; j++ )
{
m_fxList[ i ][ j ].fx = nullptr;
m_fxList[ i ][ j ].locInfo.loc.x = 0.0f;
m_fxList[ i ][ j ].locInfo.loc.y = 0.0f;
m_fxList[ i ][ j ].locInfo.loc.z = 0.0f;
m_fxList[ i ][ j ].locInfo.locType = FX_DAMAGE_LOC_TYPE_COORD;
m_fxList[ i ][ j ].locInfo.randomBone = FALSE;
m_OCL[ i ][ j ].ocl = nullptr;
m_OCL[ i ][ j ].locInfo.loc.x = 0.0f;
m_OCL[ i ][ j ].locInfo.loc.y = 0.0f;
m_OCL[ i ][ j ].locInfo.loc.z = 0.0f;
m_OCL[ i ][ j ].locInfo.locType = FX_DAMAGE_LOC_TYPE_COORD;
m_OCL[ i ][ j ].locInfo.randomBone = FALSE;
m_particleSystem[ i ][ j ].particleSysTemplate = nullptr;
m_particleSystem[ i ][ j ].locInfo.loc.x = 0.0f;
m_particleSystem[ i ][ j ].locInfo.loc.y = 0.0f;
m_particleSystem[ i ][ j ].locInfo.loc.z = 0.0f;
m_particleSystem[ i ][ j ].locInfo.locType = FX_DAMAGE_LOC_TYPE_COORD;
m_particleSystem[ i ][ j ].locInfo.randomBone = FALSE;
}
}
m_damageFXTypes = DAMAGE_TYPE_FLAGS_ALL;
m_damageOCLTypes = DAMAGE_TYPE_FLAGS_ALL;
m_damageParticleTypes = DAMAGE_TYPE_FLAGS_ALL;
}
//-------------------------------------------------------------------------------------------------
/** Parse fx location info ... that is a named bone or a coord3d position */
//-------------------------------------------------------------------------------------------------
static void parseFXLocInfo( INI *ini, void *instance, FXLocInfo *locInfo )
{
const char *token = ini->getNextToken( ini->getSepsColon() );
if( stricmp( token, "bone" ) == 0 )
{
// save bone name and location type
locInfo->boneName = AsciiString( ini->getNextToken() );
locInfo->locType = FX_DAMAGE_LOC_TYPE_BONE;
//
// bones are followed by RandomBone:<Yes|No>, if random bone is yes, the bone name is
// assumed to be a "base bone name" and we will find all the bones with that prefix
// when picking an effect position. If it's no, the bone name is assumed to be explicit
//
token = ini->getNextToken( ini->getSepsColon() );
if( stricmp( token, "randombone" ) != 0 )
{
DEBUG_CRASH(( "parseFXLocInfo: Bone name not followed by RandomBone specifier\nPress IGNORE to see which INI file and line # is incorrect." ));
throw INI_INVALID_DATA;
}
// parse the Bool definition
ini->parseBool( ini, instance, &locInfo->randomBone, nullptr );
}
else if( stricmp( token, "loc" ) == 0 )
{
// save location and location type
locInfo->loc.x = ini->scanReal( ini->getNextSubToken("X") );
locInfo->loc.y = ini->scanReal( ini->getNextSubToken("Y") );
locInfo->loc.z = ini->scanReal( ini->getNextSubToken("Z") );
locInfo->locType = FX_DAMAGE_LOC_TYPE_COORD;
}
else
{
// error
throw INI_INVALID_DATA;
}
}
//-------------------------------------------------------------------------------------------------
/** In the form of:
* FXListSlot = <<Bone:BoneName BoneRandom:<Yes|No>> | <Loc: X:x Y:y Z:z>> FXList:FXListName */
//-------------------------------------------------------------------------------------------------
void TransitionDamageFXModuleData::parseFXList( INI *ini, void *instance,
void *store, const void *userData )
{
const char *token;
FXDamageFXListInfo *info = (FXDamageFXListInfo *)store;
// parse the location bone or location
parseFXLocInfo( ini, instance, &info->locInfo );
// make sure we have an "FXList:" token
token = ini->getNextToken( ini->getSepsColon() );
if( stricmp( token, "fxlist" ) != 0 )
{
// error
throw INI_INVALID_DATA;
}
// parse the fx list name
ini->parseFXList( ini, instance, &info->fx, nullptr );
}
//-------------------------------------------------------------------------------------------------
/** In the form of:
* OCLSlot = <<Bone:BoneName BoneRandom:<Yes|No>> | <Loc: X:x Y:y Z:z>> OCL:OCLName */
//-------------------------------------------------------------------------------------------------
void TransitionDamageFXModuleData::parseObjectCreationList( INI *ini, void *instance,
void *store, const void *userData )
{
const char *token;
FXDamageOCLInfo *info = (FXDamageOCLInfo *)store;
// parse the location bone or location
parseFXLocInfo( ini, instance, &info->locInfo );
// make sure we have an "OCL:" token
token = ini->getNextToken( ini->getSepsColon() );
if( stricmp( token, "ocl" ) != 0 )
{
// error
throw INI_INVALID_DATA;
}
// parse the ocl name
ini->parseObjectCreationList( ini, instance, store, &info->ocl );
}
//-------------------------------------------------------------------------------------------------
/** In the form of:
* ParticleSlot = <<Bone:BoneName BoneRandom:<Yes|No>> | <Loc: X:x Y:y Z:z>> PSys:PSysName */
//-------------------------------------------------------------------------------------------------
void TransitionDamageFXModuleData::parseParticleSystem( INI *ini, void *instance,
void *store, const void *userData )
{
const char *token;
FXDamageParticleSystemInfo *info = (FXDamageParticleSystemInfo *)store;
// parse the location bone or location
parseFXLocInfo( ini, instance, &info->locInfo );
// make sure we have an "PSys:" token
token = ini->getNextToken( ini->getSepsColon() );
if( stricmp( token, "psys" ) != 0 )
{
// error
throw INI_INVALID_DATA;
}
// parse the particle system name
ini->parseParticleSystemTemplate( ini, instance, store, &info->particleSysTemplate );
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
TransitionDamageFX::TransitionDamageFX( Thing *thing, const ModuleData* moduleData )
: DamageModule( thing, moduleData )
{
Int i, j;
for( i = 0; i < BODYDAMAGETYPE_COUNT; i++ )
for( j = 0; j < DAMAGE_MODULE_MAX_FX; j++ )
m_particleSystemID[ i ][ j ] = INVALID_PARTICLE_SYSTEM_ID;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
TransitionDamageFX::~TransitionDamageFX()
{
}
/*
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void TransitionDamageFX::onDelete()
{
//
// we would in theory delete any particle systems we have created and attached, but the
// particle system will automatically delete itself when the object is destroyed
//
}
*/
//-------------------------------------------------------------------------------------------------
/** Given an FXLoc info struct, return the effect position that we are supposed to use.
* The position is local to to the object */
//-------------------------------------------------------------------------------------------------
static Coord3D getLocalEffectPos( const FXLocInfo *locInfo, Drawable *draw, Bool useGameClientRandom = FALSE )
{
DEBUG_ASSERTCRASH( locInfo, ("getLocalEffectPos: locInfo is null") );
if( locInfo->locType == FX_DAMAGE_LOC_TYPE_BONE && draw )
{
if( locInfo->randomBone == FALSE )
{
Coord3D pos;
// get the bone position
Int count = draw->getPristineBonePositions( locInfo->boneName.str(), 0, &pos, nullptr, 1 );
// sanity, if bone not found revert back to location defined in struct (which is 0,0,0)
if( count == 0 )
return locInfo->loc;
// return the position retrieved
return pos;
}
else
{
const Int MAX_BONES = 32;
Coord3D positions[ MAX_BONES ];
// get the bone positions
Int boneCount;
boneCount = draw->getPristineBonePositions( locInfo->boneName.str(), 1, positions, nullptr, MAX_BONES );
// sanity, if bone not found revert back to location defined in struct (which is 0,0,0)
if( boneCount == 0 )
return locInfo->loc;
// pick one of the bone positions
Int pick = useGameClientRandom ? GameClientRandomValue( 0, boneCount - 1 ) : GameLogicRandomValue( 0, boneCount - 1 );
return positions[ pick ];
}
}
else
return locInfo->loc;
}
//-------------------------------------------------------------------------------------------------
/** Switching damage states */
//-------------------------------------------------------------------------------------------------
void TransitionDamageFX::onBodyDamageStateChange( const DamageInfo* damageInfo,
BodyDamageType oldState,
BodyDamageType newState )
{
Object *damageSource = nullptr;
Int i;
Drawable *draw = getObject()->getDrawable();
const TransitionDamageFXModuleData *modData = getTransitionDamageFXModuleData();
// get the source of the damage if present
if( damageInfo )
damageSource = TheGameLogic->findObjectByID( damageInfo->in.m_sourceID );
// remove any particle systems that might be emitting from our old state
for( i = 0; i < DAMAGE_MODULE_MAX_FX; i++ )
{
if( m_particleSystemID[ oldState ][ i ] != INVALID_PARTICLE_SYSTEM_ID )
{
TheParticleSystemManager->destroyParticleSystemByID( m_particleSystemID[ oldState ][ i ] );
m_particleSystemID[ oldState ][ i ] = INVALID_PARTICLE_SYSTEM_ID;
}
}
//
// when we are transitioning to a "worse" state we will play a set of effects for that
// new state to make the transition
//
if( IS_CONDITION_WORSE( newState, oldState ) )
{
const ParticleSystemTemplate *pSystemT;
Coord3D pos;
// if we are restricted by the damage type executing effect, bail out of here
const DamageInfo *lastDamageInfo = getObject()->getBodyModule()->getLastDamageInfo();
for( i = 0; i < DAMAGE_MODULE_MAX_FX; i++ )
{
// play fx list for our new state
if( modData->m_fxList[ newState ][ i ].fx )
{
if( lastDamageInfo == nullptr ||
getDamageTypeFlag( modData->m_damageFXTypes, lastDamageInfo->in.m_damageType ) )
{
pos = getLocalEffectPos( &modData->m_fxList[ newState ][ i ].locInfo, draw );
getObject()->convertBonePosToWorldPos( &pos, nullptr, &pos, nullptr );
FXList::doFXPos( modData->m_fxList[ newState ][ i ].fx, &pos );
}
}
// do any object creation list for our new state
if( damageSource && modData->m_OCL[ newState ][ i ].ocl )
{
if( lastDamageInfo == nullptr ||
getDamageTypeFlag( modData->m_damageOCLTypes, lastDamageInfo->in.m_damageType ) )
{
pos = getLocalEffectPos( &modData->m_OCL[ newState ][ i ].locInfo, draw );
getObject()->convertBonePosToWorldPos( &pos, nullptr, &pos, nullptr );
ObjectCreationList::create( modData->m_OCL[ newState ][ i ].ocl,
getObject(), &pos, damageSource->getPosition(), INVALID_ANGLE );
}
}
// get the template of the system to create
pSystemT = modData->m_particleSystem[ newState ][ i ].particleSysTemplate;
if( pSystemT )
{
if( lastDamageInfo == nullptr ||
getDamageTypeFlag( modData->m_damageParticleTypes, lastDamageInfo->in.m_damageType ) )
{
// create a new particle system based on the template provided
ParticleSystem* pSystem = TheParticleSystemManager->createParticleSystem( pSystemT );
if( pSystem )
{
// get the what is the position we're going to played the effect at
pos = getLocalEffectPos( &modData->m_particleSystem[ newState ][ i ].locInfo, draw, TRUE );
//
// set position on system given any bone position provided, the bone position is
// local to the object and that's what we want for the particle system ... the
// transformation into world space using the object position is taken care of in
// the particle system attachToObject method
//
pSystem->setPosition( &pos );
// attach to object
pSystem->attachToObject( getObject() );
// save the id of this particle system so we can remove it later if it still exists
m_particleSystemID[ newState ][ i ] = pSystem->getSystemID();
}
}
}
#if RETAIL_COMPATIBLE_CRC
// TheSuperHackers @fix stephanmeesters 18/05/2026 Fix issue where the creation of a certain particle system
// would influence game logic CRC due to the incorrect usage of game logic RNG. This code block is required to
// forward the game logic RNG and keep things consistent.
if(pSystemT)
{
if( lastDamageInfo == nullptr ||
getDamageTypeFlag( modData->m_damageParticleTypes, lastDamageInfo->in.m_damageType ) )
{
const FXLocInfo* locInfo = &modData->m_particleSystem[newState][i].locInfo;
if( locInfo->locType == FX_DAMAGE_LOC_TYPE_BONE && locInfo->randomBone && draw )
{
const Int MAX_BONES = 32;
Coord3D positions[ MAX_BONES ];
Int boneCount = draw->getPristineBonePositions( locInfo->boneName.str(), 1, positions, nullptr, MAX_BONES );
if( boneCount > 0 )
{
static_cast<void>(GameLogicRandomValue( 0, boneCount - 1 ));
}
}
}
}
#endif
}
}
}
// ------------------------------------------------------------------------------------------------
/** CRC */
// ------------------------------------------------------------------------------------------------
void TransitionDamageFX::crc( Xfer *xfer )
{
// extend base class
DamageModule::crc( xfer );
}
// ------------------------------------------------------------------------------------------------
/** Xfer method
* Version Info:
* 1: Initial version */
// ------------------------------------------------------------------------------------------------
void TransitionDamageFX::xfer( Xfer *xfer )
{
// version
XferVersion currentVersion = 1;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
// extend base class
DamageModule::xfer( xfer );
// particle systems ids
xfer->xferUser( m_particleSystemID, sizeof( ParticleSystemID ) * BODYDAMAGETYPE_COUNT * DAMAGE_MODULE_MAX_FX );
}
// ------------------------------------------------------------------------------------------------
/** Load post process */
// ------------------------------------------------------------------------------------------------
void TransitionDamageFX::loadPostProcess()
{
// extend base class
DamageModule::loadPostProcess();
}