surfaceeffects.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/surfaceeffects.cpp $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 6/14/02 10:48a $*
  29. * *
  30. * $Revision:: 56 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "surfaceeffects.h"
  36. #include "w3d_file.h"
  37. #include "part_emt.h"
  38. #include "assets.h"
  39. #include "pscene.h"
  40. #include "debug.h"
  41. #include "wwstring.h"
  42. #include "crandom.h"
  43. #include "physcon.h"
  44. #include "wwaudio.h"
  45. #include "rndstrng.h"
  46. #include "sound3d.h"
  47. #include "phys.h"
  48. #include "wwprofile.h"
  49. #include "gameobjref.h"
  50. #include "physicalgameobj.h"
  51. #include "combat.h"
  52. #include "ccamera.h"
  53. #include "effectrecycler.h"
  54. #include "timeddecophys.h"
  55. #define RECYCLE_EMITTERS 1
  56. const float _MAX_SURFACE_EFFECT_DISTANCE2 = 50.0f * 50.0f; // no surface effects created farther than this from camera
  57. const float _SURFACE_EFFECT_NEAR_DISTANCE2 = 10.0f * 10.0f; // force surface effects within this distance
  58. #define SECTION_BULLET_STOPPING "Bullet_Stopping"
  59. #define SECTION_DAMAGE_WARHEAD "Damage_Warhead"
  60. #define SECTION_DAMAGE_RATE "Damage_Rate"
  61. SurfaceEffectsManager::MODE SurfaceEffectsManager::Mode = SurfaceEffectsManager::MODE_FULL;
  62. int SurfaceEffectsManager::OverrideSurfaceType = -1;
  63. bool _IsSurfaceEffectsInitted = false;
  64. // If there exist more than this many particle buffers, don't make emitters
  65. #define PARTICLE_BUFFER_LIMIT 5
  66. /*
  67. ** These are the names for each Hitter Type. If you add a hitter type, add the name here
  68. */
  69. static const char * _HitterTypeName[ SurfaceEffectsManager::NUM_HITTER_TYPES ] = {
  70. "None", // HITTER_TYPE_NONE, // used to shut off persistant effects
  71. "Generic Object", // HITTER_TYPE_GENERIC_OBJECT, // generic dynamic object
  72. "Footstep Run", // HITTER_TYPE_FOOTSTEP_RUN,
  73. "Footstep Walk", // HITTER_TYPE_FOOTSTEP_WALK,
  74. "Footstep Crouched", // HITTER_TYPE_FOOTSTEP_CROUCHED,
  75. "Footstep Jump", // HITTER_TYPE_FOOTSTEP_JUMP,
  76. "Footstep Land", // HITTER_TYPE_FOOTSTEP_LAND,
  77. "Bullet", // HITTER_TYPE_BULLET,
  78. "Bullet Fire", // HITTER_TYPE_BULLET_FIRE,
  79. "Bullet Grenade", // HITTER_TYPE_BULLET_GRENADE,
  80. "Bullet Chem", // HITTER_TYPE_BULLET_CHEM,
  81. "Bullet Electric", // HITTER_TYPE_BULLET_ELECTRIC,
  82. "Bullet Laser", // HITTER_TYPE_BULLET_LASER,
  83. "Bullet Squish", // HITTER_TYPE_BULLET_SQUISH,
  84. "Bullet Tib Spray", // HITTER_TYPE_BULLET_TIB_SPRAY,
  85. "Bullet Tib", // HITTER_TYPE_BULLET_TIB_BULLET,
  86. "Bullet Shotgun", // HITTER_TYPE_BULLET_SHOTGUN,
  87. "Bullet Silenced", // HITTER_TYPE_BULLET_SILENCED,
  88. "Bullet Sniper", // HITTER_TYPE_BULLET_SNIPER,
  89. "Bullet Water", // HITTER_TYPE_BULLET_WATER,
  90. "Eject Casing", // HITTER_TYPE_EJECT_CASING, // casings ejected from weapons (all are assumed to make the same sounds)
  91. "Shell Shotgun", // HITTER_TYPE_SHELL_SHOTGUN,
  92. "Tire Rolling", // HITTER_TYPE_TIRE_ROLLING, // wheels on humvees, etc...
  93. "Tire Sliding", // HITTER_TYPE_TIRE_SLIDING,
  94. "Track Rolling", // HITTER_TYPE_TRACK_ROLLING, // tank tracks...
  95. "Track Sliding", // HITTER_TYPE_TRACK_SLIDING,
  96. "Footstep Ladder", // HITTER_TYPE_FOOTSTEP_LADDER,
  97. };
  98. /*
  99. ** Recycler for all "fire-and-forget" surface effect emitters
  100. */
  101. #if (RECYCLE_EMITTERS)
  102. static EffectRecyclerClass _EmitterRecycler;
  103. #endif
  104. /*
  105. ** Persistant Surface Effects
  106. */
  107. class PersistantSurfaceEffectClass
  108. {
  109. public:
  110. PersistantSurfaceEffectClass( void );
  111. ~PersistantSurfaceEffectClass( void );
  112. int CurrentSurfaceType;
  113. int CurrentHitterType;
  114. friend SurfaceEffectsManager;
  115. };
  116. class PersistantSurfaceSoundClass : public PersistantSurfaceEffectClass
  117. {
  118. public:
  119. PersistantSurfaceSoundClass( void );
  120. ~PersistantSurfaceSoundClass( void );
  121. void Set_Sound( const char * name );
  122. AudibleSoundClass * Sound;
  123. friend SurfaceEffectsManager;
  124. };
  125. class PersistantSurfaceEmitterClass : public PersistantSurfaceEffectClass
  126. {
  127. private:
  128. PersistantSurfaceEmitterClass( void );
  129. ~PersistantSurfaceEmitterClass( void );
  130. void Set_Emitter( const char * name );
  131. ParticleEmitterClass * Emitter;
  132. friend SurfaceEffectsManager;
  133. };
  134. /*
  135. ** PersistantSurfaceEffectClass
  136. */
  137. PersistantSurfaceEffectClass::PersistantSurfaceEffectClass(void) :
  138. CurrentSurfaceType( -1 ),
  139. CurrentHitterType( -1 )
  140. {
  141. }
  142. PersistantSurfaceEffectClass::~PersistantSurfaceEffectClass(void)
  143. {
  144. }
  145. /*
  146. ** PersistantSurfaceSoundClass
  147. */
  148. PersistantSurfaceSoundClass::PersistantSurfaceSoundClass( void ) :
  149. Sound( NULL )
  150. {
  151. }
  152. PersistantSurfaceSoundClass::~PersistantSurfaceSoundClass( void )
  153. {
  154. Set_Sound( NULL );
  155. }
  156. void PersistantSurfaceSoundClass::Set_Sound( const char * name )
  157. {
  158. // Stop Old Sound
  159. if ( Sound != NULL ) {
  160. Sound->Stop();
  161. Sound->Remove_From_Scene();
  162. Sound->Release_Ref();
  163. Sound = NULL;
  164. }
  165. // Start new Sound
  166. if ( name != NULL ) {
  167. Sound = WWAudioClass::Get_Instance()->Create_Continuous_Sound( name );
  168. if ( Sound != NULL ) {
  169. Sound->Add_To_Scene( true );
  170. }
  171. }
  172. }
  173. /*
  174. ** PersistantSurfaceEmitterClass
  175. */
  176. PersistantSurfaceEmitterClass::PersistantSurfaceEmitterClass( void ) :
  177. Emitter( NULL )
  178. {
  179. }
  180. PersistantSurfaceEmitterClass::~PersistantSurfaceEmitterClass( void )
  181. {
  182. Set_Emitter( NULL );
  183. }
  184. void PersistantSurfaceEmitterClass::Set_Emitter( const char * name )
  185. {
  186. // Stop Old Emitter
  187. if ( Emitter != NULL ) {
  188. // Check if it is in the scene, it may ahve already been remove by completion
  189. if ( Emitter->Peek_Scene() != NULL ) {
  190. PhysicsSceneClass::Get_Instance()->Remove_Render_Object( Emitter );
  191. }
  192. Emitter->Stop();
  193. Emitter->Release_Ref();
  194. Emitter = NULL;
  195. }
  196. // Start new Emitter
  197. if ( name != NULL ) {
  198. Emitter = (ParticleEmitterClass *)WW3DAssetManager::Get_Instance()->Create_Render_Obj( name );
  199. if ( Emitter ) {
  200. SET_REF_OWNER( Emitter );
  201. // Emitter->Set_Remove_On_Complete( false );
  202. Emitter->Start();
  203. PhysicsSceneClass::Get_Instance()->Add_Render_Object( Emitter );
  204. }
  205. }
  206. }
  207. /*
  208. ** Surface Effect Database
  209. */
  210. class SurfaceEffectClass {
  211. public:
  212. RandomStringClass Sound;
  213. RandomStringClass Emitter;
  214. RandomStringClass Decal;
  215. float DecalSize;
  216. float DecalSizeRandom;
  217. };
  218. SurfaceEffectClass * SurfaceEffectsDatabase[SURFACE_TYPE_MAX][SurfaceEffectsManager::NUM_HITTER_TYPES];
  219. bool SurfaceStopsBullets[SURFACE_TYPE_MAX];
  220. int SurfaceDamageWarhead[SURFACE_TYPE_MAX];
  221. float SurfaceDamageRate[SURFACE_TYPE_MAX];
  222. /*
  223. ** These are the physics object types for each Hitter Type. These are only used to pass
  224. ** the friction and drag constants on to the physics system. If your hitter type does not
  225. ** correspond to a physics object type, put a -1 for its entry here.
  226. */
  227. const int HitterPhysicsTypes[SurfaceEffectsManager::NUM_HITTER_TYPES] =
  228. {
  229. -1, //"Bullet",
  230. -1, //"Eject Casing"
  231. -1, //"Footstep Run",
  232. -1, //"Footstep Walk",
  233. -1, //"Footstep Crouch",
  234. PhysicsConstants::DYNAMIC_OBJ_TYPE_TIRE, //"Tire Rolling",
  235. -1, //"Tire Sliding",
  236. PhysicsConstants::DYNAMIC_OBJ_TYPE_TRACK, //"Track Rolling",
  237. -1, //"Track Sliding",
  238. PhysicsConstants::DYNAMIC_OBJ_TYPE_GENERIC, //"Generic Object"
  239. -1,
  240. };
  241. #define SURFACE_EFFECTS_INI_FILENAME "surfaceeffects.ini"
  242. bool SurfaceEffectsManagerDebug = false;
  243. void SurfaceEffectsManager::Toggle_Debug( void )
  244. {
  245. SurfaceEffectsManagerDebug = !SurfaceEffectsManagerDebug;
  246. }
  247. /*
  248. **
  249. */
  250. void SurfaceEffectsManager::Init( void )
  251. {
  252. if (_IsSurfaceEffectsInitted) {
  253. Shutdown();
  254. }
  255. for ( int i = 0; i < SURFACE_TYPE_MAX; i++ ) {
  256. SurfaceStopsBullets[i] = true;
  257. SurfaceDamageWarhead[i] = 0;
  258. SurfaceDamageRate[i] = 0;
  259. }
  260. // Read Database INI file
  261. INIClass * ini = Get_INI( SURFACE_EFFECTS_INI_FILENAME );
  262. if ( ini != NULL ) {
  263. WWASSERT( ini && ini->Section_Count() > 0 );
  264. int surface;
  265. // Read Bullet Stopping
  266. for ( surface = 0; surface < SURFACE_TYPE_MAX; surface++ ) {
  267. SurfaceStopsBullets[ surface ] = ini->Get_Bool( SECTION_BULLET_STOPPING, SURFACE_TYPE_STRINGS[surface], true );
  268. }
  269. // Read Surface Damage Data
  270. for ( surface = 0; surface < SURFACE_TYPE_MAX; surface++ ) {
  271. StringClass warhead(0,true);
  272. ini->Get_String(warhead,SECTION_DAMAGE_WARHEAD, SURFACE_TYPE_STRINGS[surface] );
  273. if ( !warhead.Is_Empty() ) {
  274. SurfaceDamageWarhead[surface] = ArmorWarheadManager::Get_Warhead_Type( warhead );
  275. }
  276. SurfaceDamageRate[surface] = ini->Get_Float( SECTION_DAMAGE_RATE, SURFACE_TYPE_STRINGS[surface], 0 );
  277. if ( SurfaceDamageRate[surface] != 0 ) {
  278. // Debug_Say(( "Surface %s Rate %f Warhead %s\n", SURFACE_TYPE_STRINGS[surface],
  279. // SurfaceDamageRate[surface], ArmorWarheadManager::Get_Warhead_Name( SurfaceDamageWarhead[surface] ) ));
  280. }
  281. }
  282. for ( surface = 0; surface < SURFACE_TYPE_MAX; surface++ ) {
  283. for ( int hitter = 0; hitter < NUM_HITTER_TYPES; hitter++ ) {
  284. StringClass section_name;
  285. section_name.Format( "%s_%s", SURFACE_TYPE_STRINGS[surface], _HitterTypeName[hitter] );
  286. if ( ini->Entry_Count( section_name ) == 0 ) {
  287. SurfaceEffectsDatabase[ surface ][ hitter ] = NULL;
  288. continue;
  289. }
  290. // Debug_Say(( "Surface Effect Section %s\n", section_name ));
  291. // create the effect
  292. SurfaceEffectClass * surface_effect = new SurfaceEffectClass;
  293. // Read sounds
  294. for ( int sound = 0; ; sound++ ) {
  295. StringClass sound_entry(0,true);
  296. sound_entry.Format( "Sound%d", sound );
  297. StringClass sound_name(0,true);
  298. ini->Get_String(sound_name, section_name, sound_entry );
  299. if ( sound_name.Is_Empty() ) {
  300. break;
  301. }
  302. // Debug_Say(( "Add Sound %s\n", sound_name ));
  303. surface_effect->Sound.Add_String( sound_name );
  304. }
  305. // Read emitters
  306. for ( int emitter = 0; ; emitter++ ) {
  307. StringClass emitter_entry(0,true);
  308. emitter_entry.Format( "Emitter%d", emitter );
  309. StringClass emitter_name(0,true);
  310. ini->Get_String(emitter_name, section_name, emitter_entry );
  311. if ( emitter_name.Is_Empty() ) {
  312. break;
  313. }
  314. // Debug_Say(( "Add Emitter %s\n", emitter_name ));
  315. surface_effect->Emitter.Add_String( emitter_name );
  316. }
  317. // Read decals
  318. for ( int decal = 0; ; decal++ ) {
  319. StringClass decal_entry(0,true);
  320. decal_entry.Format( "Decal%d", decal );
  321. StringClass decal_name(0,true);
  322. ini->Get_String(decal_name, section_name, decal_entry );
  323. if ( decal_name.Is_Empty() ) {
  324. break;
  325. }
  326. // Debug_Say(( "Add Decal %s\n", decal_name ));
  327. surface_effect->Decal.Add_String( decal_name );
  328. }
  329. surface_effect->DecalSize = ini->Get_Float( section_name, "DecalSize", 1 );
  330. surface_effect->DecalSizeRandom = ini->Get_Float( section_name, "DecalSizeRandom", 0 );
  331. // save the effect
  332. SurfaceEffectsDatabase[ surface ][ hitter ] = surface_effect;
  333. // (gth) if this is one of the physics "hitter types" copy the
  334. // constants into the physics engine
  335. if (HitterPhysicsTypes[hitter] != -1) {
  336. float friction = ini->Get_Float( section_name,
  337. "Friction",
  338. PhysicsConstants::DefaultContactFriction );
  339. float drag = ini->Get_Float( section_name,
  340. "Drag",
  341. PhysicsConstants::DefaultContactDrag );
  342. PhysicsConstants::Set_Contact_Friction_Coefficient( HitterPhysicsTypes[hitter],
  343. surface,
  344. friction );
  345. PhysicsConstants::Set_Contact_Drag_Coefficient( HitterPhysicsTypes[hitter],
  346. surface,
  347. drag );
  348. }
  349. }
  350. }
  351. Release_INI( ini );
  352. ini = NULL;
  353. } else {
  354. Debug_Say(("SurfaceEffectsManager::Init - Unable to load %s\n", SURFACE_EFFECTS_INI_FILENAME ));
  355. }
  356. WWASSERT(ini == NULL);
  357. _IsSurfaceEffectsInitted = true;
  358. }
  359. void SurfaceEffectsManager::Shutdown( void )
  360. {
  361. #if (RECYCLE_EMITTERS)
  362. _EmitterRecycler.Reset();
  363. #endif
  364. for ( int surface = 0; surface < SURFACE_TYPE_MAX; surface++ ) {
  365. for ( int hitter = 0; hitter < NUM_HITTER_TYPES; hitter++ ) {
  366. if ( SurfaceEffectsDatabase[ surface ][ hitter ] ) {
  367. delete SurfaceEffectsDatabase[ surface ][ hitter ];
  368. SurfaceEffectsDatabase[ surface ][ hitter ] = NULL;
  369. }
  370. }
  371. }
  372. _IsSurfaceEffectsInitted = false;
  373. }
  374. const char * SurfaceEffectsManager::Hitter_Type_Name( int hitter )
  375. {
  376. return _HitterTypeName[ hitter ];
  377. }
  378. void SurfaceEffectsManager::Apply_Effect
  379. (
  380. int surface_type,
  381. int hitter_type,
  382. const Matrix3D & tm,
  383. PhysClass * hit_obj,
  384. PhysicalGameObj * creator,
  385. bool allow_decals,
  386. bool allow_emitters
  387. )
  388. {
  389. WWPROFILE( "Apply Surface Effect" );
  390. bool ok = ( (surface_type >= 0) &&
  391. (surface_type < SURFACE_TYPE_MAX) &&
  392. (hitter_type >=0 ) &&
  393. (hitter_type < NUM_HITTER_TYPES) );
  394. if (!ok) {
  395. WWDEBUG_SAY(("Invalid surface params. surface_type: %d hitter_type: %d\r\n",surface_type,hitter_type));
  396. return;
  397. }
  398. // Return if all surface effects are currently disabled
  399. if ( Mode == MODE_OFF ) {
  400. return;
  401. }
  402. // If the user has specified an override type, use it.
  403. if (OverrideSurfaceType != -1) { surface_type = OverrideSurfaceType; }
  404. // Return if we don't find any surface effect settings for this combination of surface_type, hitter_type
  405. SurfaceEffectClass * surface_effect = SurfaceEffectsDatabase[ surface_type ][ hitter_type ];
  406. if ( surface_effect == NULL ) {
  407. if ( SurfaceEffectsManagerDebug ) {
  408. Debug_Say(( "No Surface Effect for %s and %s\n", SURFACE_TYPE_STRINGS[surface_type], _HitterTypeName[hitter_type] ));
  409. }
  410. return;
  411. }
  412. const char * sound_name = surface_effect->Sound.Get_String();
  413. const char * emitter_name = surface_effect->Emitter.Get_String();
  414. const char * decal_name = surface_effect->Decal.Get_String();
  415. if ( SurfaceEffectsManagerDebug ) {
  416. Debug_Say(( "Applying Surface Effect for %s and %s\n--Sound:%s Emitter:%s Decal:%s\n",
  417. SURFACE_TYPE_STRINGS[surface_type],
  418. _HitterTypeName[hitter_type],
  419. sound_name ? sound_name : "none",
  420. emitter_name ? emitter_name : "none",
  421. decal_name ? decal_name : "none" ));
  422. }
  423. // Create the sound
  424. if ( sound_name ) {
  425. WWPROFILE( "Sound" );
  426. // I may need to plug an owner in here
  427. RefCountedGameObjReference *owner_ref = new RefCountedGameObjReference;
  428. owner_ref->Set_Ptr( creator );
  429. WWAudioClass::Get_Instance()->Create_Instant_Sound( sound_name, tm, owner_ref, 0, CLASSID_PSEUDO3D );
  430. REF_PTR_RELEASE( owner_ref );
  431. }
  432. // Return if this effect is far from the camera or not within the view frustum
  433. // But, do this after the sound is created!!!
  434. Vector3 effect_point;
  435. tm.Get_Translation(&effect_point);
  436. float dist2 = (effect_point - COMBAT_CAMERA->Get_Position()).Length2();
  437. if ( (dist2 > _SURFACE_EFFECT_NEAR_DISTANCE2) ) {
  438. if ( (dist2 > _MAX_SURFACE_EFFECT_DISTANCE2) ||
  439. (CollisionMath::Overlap_Test(COMBAT_CAMERA->Get_Frustum(),effect_point) == CollisionMath::OUTSIDE) )
  440. {
  441. return;
  442. }
  443. }
  444. // Create the emitter
  445. if ((allow_emitters) && (emitter_name) && (Mode != MODE_NO_EMITTERS)) {
  446. WWPROFILE( "Emitter" );
  447. #if (RECYCLE_EMITTERS)
  448. _EmitterRecycler.Spawn_Effect(emitter_name,tm);
  449. #else
  450. ParticleEmitterClass * emitter = (ParticleEmitterClass *)WW3DAssetManager::Get_Instance()->Create_Render_Obj( emitter_name );
  451. if ( emitter ) {
  452. SET_REF_OWNER( emitter );
  453. emitter->Set_Transform( tm );
  454. emitter->Start();
  455. emitter->Enable_Remove_On_Complete(true);
  456. PhysicsSceneClass::Get_Instance()->Add_Render_Object( emitter );
  457. emitter->Release_Ref();
  458. }
  459. #endif
  460. }
  461. // Create decal, (will only apply to static physics objects)
  462. if ((allow_decals) && (decal_name)) {
  463. WWPROFILE( "Decal" );
  464. float size = surface_effect->DecalSize;
  465. size += FreeRandom.Get_Float( -surface_effect->DecalSizeRandom, surface_effect->DecalSizeRandom );
  466. StringClass new_name( true );
  467. Strip_Path_From_Filename( new_name, decal_name );
  468. // If this is a glass decal, we enable "apply_to_translucent_meshes" and we
  469. // also pass in the object that was hit so the decal is *only* applied to that
  470. // object. Otherwise, we use normal decal processing which collects the meshes
  471. // that overlap the volume and applies the decal to all of them
  472. if ((surface_type == SURFACE_TYPE_GLASS) || (surface_type == SURFACE_TYPE_GLASS_PERMEABLE)) {
  473. PhysicsSceneClass::Get_Instance()->Create_Decal( tm, new_name, size, false, true, hit_obj );
  474. } else {
  475. PhysicsSceneClass::Get_Instance()->Create_Decal( tm, new_name, size );
  476. }
  477. }
  478. }
  479. PersistantSurfaceSoundClass * SurfaceEffectsManager::Create_Persistant_Sound( void )
  480. {
  481. return new PersistantSurfaceSoundClass;
  482. }
  483. void SurfaceEffectsManager::Destroy_Persistant_Sound( PersistantSurfaceSoundClass * effect )
  484. {
  485. delete effect;
  486. }
  487. void SurfaceEffectsManager::Update_Persistant_Sound( PersistantSurfaceSoundClass * effect,
  488. int surface_type, int hitter_type, const Matrix3D & tm )
  489. {
  490. WWASSERT( surface_type >= 0 );
  491. WWASSERT( surface_type < SURFACE_TYPE_MAX );
  492. WWASSERT( hitter_type >= 0 );
  493. WWASSERT( hitter_type < NUM_HITTER_TYPES );
  494. if ( Mode == MODE_OFF ) {
  495. return;
  496. }
  497. // If the user has specified an override type, use it.
  498. if (OverrideSurfaceType != -1) { surface_type = OverrideSurfaceType; }
  499. // If something changed, re-lookup the sound
  500. if ( ( surface_type != effect->CurrentSurfaceType ) || ( hitter_type != effect->CurrentHitterType ) ) {
  501. effect->CurrentSurfaceType = surface_type;
  502. effect->CurrentHitterType = hitter_type;
  503. SurfaceEffectClass * surface_effect = SurfaceEffectsDatabase[ surface_type ][ hitter_type ];
  504. if ( surface_effect == NULL ) {
  505. if ( SurfaceEffectsManagerDebug ) {
  506. Debug_Say(( "No Surface Effect for %s and %s\n", SURFACE_TYPE_STRINGS[surface_type], _HitterTypeName[hitter_type] ));
  507. }
  508. effect->Set_Sound( NULL );
  509. } else {
  510. const char * sound_name = surface_effect->Sound.Get_String();
  511. if ( SurfaceEffectsManagerDebug ) {
  512. Debug_Say(( "Applying Persistant Surface Sound for %s and %s Sound:%s\n",
  513. SURFACE_TYPE_STRINGS[surface_type],
  514. _HitterTypeName[hitter_type],
  515. sound_name ? sound_name : "none" ));
  516. }
  517. effect->Set_Sound( sound_name );
  518. }
  519. }
  520. // Update Position
  521. if ( effect->Sound != NULL ) {
  522. effect->Sound->Set_Transform( tm );
  523. }
  524. }
  525. PersistantSurfaceEmitterClass * SurfaceEffectsManager::Create_Persistant_Emitter( void )
  526. {
  527. return new PersistantSurfaceEmitterClass;
  528. }
  529. void SurfaceEffectsManager::Destroy_Persistant_Emitter( PersistantSurfaceEmitterClass * effect )
  530. {
  531. delete effect;
  532. }
  533. void SurfaceEffectsManager::Update_Persistant_Emitter( PersistantSurfaceEmitterClass * effect,
  534. int surface_type, int hitter_type, const Matrix3D & tm )
  535. {
  536. WWASSERT( surface_type >= 0 );
  537. WWASSERT( surface_type < SURFACE_TYPE_MAX );
  538. WWASSERT( hitter_type >= 0 );
  539. WWASSERT( hitter_type < NUM_HITTER_TYPES );
  540. if ( Mode != MODE_FULL ) {
  541. return;
  542. }
  543. // If the user has specified an override type, use it.
  544. if (OverrideSurfaceType != -1) { surface_type = OverrideSurfaceType; }
  545. // If something changed, re-lookup the emitter
  546. if ( ( surface_type != effect->CurrentSurfaceType ) || ( hitter_type != effect->CurrentHitterType ) ) {
  547. effect->CurrentSurfaceType = surface_type;
  548. effect->CurrentHitterType = hitter_type;
  549. SurfaceEffectClass * surface_effect = SurfaceEffectsDatabase[ surface_type ][ hitter_type ];
  550. if ( surface_effect == NULL ) {
  551. if ( SurfaceEffectsManagerDebug ) {
  552. Debug_Say(( "No Surface Effect for %s and %s\n", SURFACE_TYPE_STRINGS[surface_type], _HitterTypeName[hitter_type] ));
  553. }
  554. effect->Set_Emitter( NULL );
  555. } else {
  556. const char * emitter_name = surface_effect->Emitter.Get_String();
  557. if ( SurfaceEffectsManagerDebug ) {
  558. Debug_Say(( "Applying Persistant Surface Emitter for %s and %s Emitter:%s\n",
  559. SURFACE_TYPE_STRINGS[surface_type],
  560. _HitterTypeName[hitter_type],
  561. emitter_name ? emitter_name : "none" ));
  562. }
  563. effect->Set_Emitter( emitter_name );
  564. }
  565. }
  566. // Update the transform
  567. if ( effect->Emitter != NULL ) {
  568. effect->Emitter->Set_Transform( tm );
  569. }
  570. }
  571. bool SurfaceEffectsManager::Does_Surface_Stop_Bullets( int surface_type )
  572. {
  573. WWASSERT( surface_type >= 0 );
  574. WWASSERT( surface_type < SURFACE_TYPE_MAX );
  575. return SurfaceStopsBullets[ surface_type ];
  576. }
  577. void SurfaceEffectsManager::Apply_Damage( int surface_type, PhysicalGameObj * obj )
  578. {
  579. #ifndef PARAM_EDITING_ON
  580. // If the user has specified an override type, use it.
  581. if (OverrideSurfaceType != -1) { surface_type = OverrideSurfaceType; }
  582. if ( SurfaceDamageRate[surface_type] > 0 ) {
  583. OffenseObjectClass offense_obj( SurfaceDamageRate[surface_type], SurfaceDamageWarhead[surface_type] );
  584. obj->Apply_Damage_Extended( offense_obj, TimeManager::Get_Frame_Seconds() );
  585. }
  586. #endif //PARAM_EDITING_ON
  587. }
  588. bool SurfaceEffectsManager::Is_Surface_Permeable( int surface )
  589. {
  590. switch (surface) {
  591. case SURFACE_TYPE_FOLIAGE_PERMEABLE:
  592. case SURFACE_TYPE_GLASS_PERMEABLE:
  593. case SURFACE_TYPE_ICE_PERMEABLE:
  594. case SURFACE_TYPE_CLOTH_PERMEABLE:
  595. case SURFACE_TYPE_ELECTRICAL_PERMEABLE:
  596. case SURFACE_TYPE_FLAMMABLE_PERMEABLE:
  597. case SURFACE_TYPE_STEAM_PERMEABLE:
  598. case SURFACE_TYPE_WATER_PERMEABLE:
  599. case SURFACE_TYPE_TIBERIUM_WATER_PERMEABLE:
  600. return true;
  601. }
  602. return false;
  603. }
  604. void SurfaceEffectsManager::Set_Override_Surface_Type(int type)
  605. {
  606. if ((type < 0) || (type >= SURFACE_TYPE_MAX)) {
  607. OverrideSurfaceType = -1;
  608. } else {
  609. OverrideSurfaceType = type;
  610. }
  611. PhysicsConstants::Set_Override_Surface_Type(OverrideSurfaceType);
  612. }