SmokeEffects.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. #ifdef PRECOMPILEDHEADERS
  2. #include "TileEngine All.h"
  3. #else
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "wcheck.h"
  7. #include "stdlib.h"
  8. #include "debug.h"
  9. #include "soldier control.h"
  10. #include "weapons.h"
  11. #include "handle items.h"
  12. #include "worlddef.h"
  13. #include "worldman.h"
  14. #include "animation control.h"
  15. #include "tile animation.h"
  16. #include "handle items.h"
  17. #include "smokeeffects.h"
  18. #include "message.h"
  19. #include "isometric utils.h"
  20. #include "renderworld.h"
  21. #include "explosion control.h"
  22. #include "Random.h"
  23. #endif
  24. #include "SaveLoadGame.h"
  25. INT8 FromWorldFlagsToSmokeType( UINT8 ubWorldFlags );
  26. UINT8 FromSmokeTypeToWorldFlags( INT8 bType );
  27. #define NUM_SMOKE_EFFECT_SLOTS 25
  28. // GLOBAL FOR SMOKE LISTING
  29. SMOKEEFFECT gSmokeEffectData[ NUM_SMOKE_EFFECT_SLOTS ];
  30. UINT32 guiNumSmokeEffects = 0;
  31. INT32 GetFreeSmokeEffect( void );
  32. void RecountSmokeEffects( void );
  33. INT32 GetFreeSmokeEffect( void )
  34. {
  35. UINT32 uiCount;
  36. for(uiCount=0; uiCount < guiNumSmokeEffects; uiCount++)
  37. {
  38. if(( gSmokeEffectData[uiCount].fAllocated==FALSE ) )
  39. return( (INT32)uiCount );
  40. }
  41. if( guiNumSmokeEffects < NUM_SMOKE_EFFECT_SLOTS )
  42. return( (INT32) guiNumSmokeEffects++ );
  43. return( -1 );
  44. }
  45. void RecountSmokeEffects( void )
  46. {
  47. INT32 uiCount;
  48. for(uiCount=guiNumSmokeEffects-1; (uiCount >=0) ; uiCount--)
  49. {
  50. if( ( gSmokeEffectData[uiCount].fAllocated ) )
  51. {
  52. guiNumSmokeEffects=(UINT32)(uiCount+1);
  53. break;
  54. }
  55. }
  56. }
  57. // Returns NO_SMOKE_EFFECT if none there...
  58. INT8 GetSmokeEffectOnTile( INT16 sGridNo, INT8 bLevel )
  59. {
  60. UINT8 ubExtFlags;
  61. ubExtFlags = gpWorldLevelData[ sGridNo ].ubExtFlags[ bLevel ];
  62. // Look at worldleveldata to find flags..
  63. if ( ubExtFlags & ANY_SMOKE_EFFECT )
  64. {
  65. // Which smoke am i?
  66. return( FromWorldFlagsToSmokeType( ubExtFlags ) );
  67. }
  68. return( NO_SMOKE_EFFECT );
  69. }
  70. INT8 FromWorldFlagsToSmokeType( UINT8 ubWorldFlags )
  71. {
  72. if ( ubWorldFlags & MAPELEMENT_EXT_SMOKE )
  73. {
  74. return( NORMAL_SMOKE_EFFECT );
  75. }
  76. else if ( ubWorldFlags & MAPELEMENT_EXT_TEARGAS )
  77. {
  78. return( TEARGAS_SMOKE_EFFECT );
  79. }
  80. else if ( ubWorldFlags & MAPELEMENT_EXT_MUSTARDGAS )
  81. {
  82. return( MUSTARDGAS_SMOKE_EFFECT );
  83. }
  84. else if ( ubWorldFlags & MAPELEMENT_EXT_CREATUREGAS )
  85. {
  86. return( CREATURE_SMOKE_EFFECT );
  87. }
  88. else
  89. {
  90. return( NO_SMOKE_EFFECT );
  91. }
  92. }
  93. UINT8 FromSmokeTypeToWorldFlags( INT8 bType )
  94. {
  95. switch( bType )
  96. {
  97. case NORMAL_SMOKE_EFFECT:
  98. return( MAPELEMENT_EXT_SMOKE );
  99. break;
  100. case TEARGAS_SMOKE_EFFECT:
  101. return( MAPELEMENT_EXT_TEARGAS );
  102. break;
  103. case MUSTARDGAS_SMOKE_EFFECT:
  104. return( MAPELEMENT_EXT_MUSTARDGAS );
  105. break;
  106. case CREATURE_SMOKE_EFFECT:
  107. return( MAPELEMENT_EXT_CREATUREGAS );
  108. break;
  109. default:
  110. return( 0 );
  111. }
  112. }
  113. INT32 NewSmokeEffect( INT16 sGridNo, UINT16 usItem, INT8 bLevel, UINT8 ubOwner )
  114. {
  115. SMOKEEFFECT *pSmoke;
  116. INT32 iSmokeIndex;
  117. INT8 bSmokeEffectType=0;
  118. UINT8 ubDuration=0;
  119. UINT8 ubStartRadius=0;
  120. if( ( iSmokeIndex = GetFreeSmokeEffect() )==(-1) )
  121. return(-1);
  122. memset( &gSmokeEffectData[ iSmokeIndex ], 0, sizeof( SMOKEEFFECT ) );
  123. pSmoke = &gSmokeEffectData[ iSmokeIndex ];
  124. // Set some values...
  125. pSmoke->sGridNo = sGridNo;
  126. pSmoke->usItem = usItem;
  127. pSmoke->uiTimeOfLastUpdate = GetWorldTotalSeconds( );
  128. // Are we indoors?
  129. if ( GetTerrainType( sGridNo ) == FLAT_FLOOR )
  130. {
  131. pSmoke->bFlags |= SMOKE_EFFECT_INDOORS;
  132. }
  133. switch( usItem )
  134. {
  135. case MUSTARD_GRENADE:
  136. bSmokeEffectType = MUSTARDGAS_SMOKE_EFFECT;
  137. ubDuration = 5;
  138. ubStartRadius = 1;
  139. break;
  140. case TEARGAS_GRENADE:
  141. case GL_TEARGAS_GRENADE:
  142. bSmokeEffectType = TEARGAS_SMOKE_EFFECT;
  143. ubDuration = 5;
  144. ubStartRadius = 1;
  145. break;
  146. case BIG_TEAR_GAS:
  147. bSmokeEffectType = TEARGAS_SMOKE_EFFECT;
  148. ubDuration = 5;
  149. ubStartRadius = 1;
  150. break;
  151. case SMOKE_GRENADE:
  152. case GL_SMOKE_GRENADE:
  153. bSmokeEffectType = NORMAL_SMOKE_EFFECT;
  154. ubDuration = 5;
  155. ubStartRadius = 1;
  156. break;
  157. case SMALL_CREATURE_GAS:
  158. bSmokeEffectType = CREATURE_SMOKE_EFFECT;
  159. ubDuration = 3;
  160. ubStartRadius = 1;
  161. break;
  162. case LARGE_CREATURE_GAS:
  163. bSmokeEffectType = CREATURE_SMOKE_EFFECT;
  164. ubDuration = 3;
  165. ubStartRadius = Explosive[ Item[ LARGE_CREATURE_GAS ].ubClassIndex ].ubRadius;
  166. break;
  167. case VERY_SMALL_CREATURE_GAS:
  168. bSmokeEffectType = CREATURE_SMOKE_EFFECT;
  169. ubDuration = 2;
  170. ubStartRadius = 0;
  171. break;
  172. }
  173. pSmoke->ubDuration = ubDuration;
  174. pSmoke->ubRadius = ubStartRadius;
  175. pSmoke->bAge = 0;
  176. pSmoke->fAllocated = TRUE;
  177. pSmoke->bType = bSmokeEffectType;
  178. pSmoke->ubOwner = ubOwner;
  179. if ( pSmoke->bFlags & SMOKE_EFFECT_INDOORS )
  180. {
  181. // Duration is increased by 2 turns...indoors
  182. pSmoke->ubDuration += 3;
  183. }
  184. if ( bLevel )
  185. {
  186. pSmoke->bFlags |= SMOKE_EFFECT_ON_ROOF;
  187. }
  188. // ATE: FALSE into subsequent-- it's the first one!
  189. SpreadEffect( pSmoke->sGridNo, pSmoke->ubRadius, pSmoke->usItem, pSmoke->ubOwner, FALSE, bLevel, iSmokeIndex );
  190. return( iSmokeIndex );
  191. }
  192. // Add smoke to gridno
  193. // ( Replacement algorithm uses distance away )
  194. void AddSmokeEffectToTile( INT32 iSmokeEffectID, INT8 bType, INT16 sGridNo, INT8 bLevel )
  195. {
  196. ANITILE_PARAMS AniParams;
  197. ANITILE *pAniTile;
  198. SMOKEEFFECT *pSmoke;
  199. BOOLEAN fDissipating = FALSE;
  200. pSmoke = &gSmokeEffectData[ iSmokeEffectID ];
  201. if ( ( pSmoke->ubDuration - pSmoke->bAge ) < 2 )
  202. {
  203. fDissipating = TRUE;
  204. // Remove old one...
  205. RemoveSmokeEffectFromTile( sGridNo, bLevel );
  206. }
  207. // If smoke effect exists already.... stop
  208. if ( gpWorldLevelData[ sGridNo ].ubExtFlags[ bLevel ] & ANY_SMOKE_EFFECT )
  209. {
  210. return;
  211. }
  212. // OK, Create anitile....
  213. memset( &AniParams, 0, sizeof( ANITILE_PARAMS ) );
  214. AniParams.sGridNo = sGridNo;
  215. if ( bLevel == 0 )
  216. {
  217. AniParams.ubLevelID = ANI_STRUCT_LEVEL;
  218. }
  219. else
  220. {
  221. AniParams.ubLevelID = ANI_ONROOF_LEVEL;
  222. }
  223. AniParams.sDelay = (INT16)( 300 + Random( 300 ) );
  224. if ( !( gGameSettings.fOptions[ TOPTION_ANIMATE_SMOKE ] ) )
  225. {
  226. AniParams.sStartFrame = (INT16)0;
  227. }
  228. else
  229. {
  230. AniParams.sStartFrame = (INT16)Random( 5 );
  231. }
  232. // Bare bones flags are...
  233. // AniParams.uiFlags = ANITILE_CACHEDTILE | ANITILE_FORWARD | ANITILE_OPTIMIZEFORSMOKEEFFECT | ANITILE_SMOKE_EFFECT | ANITILE_LOOPING;
  234. //AniParams.uiFlags = ANITILE_CACHEDTILE | ANITILE_FORWARD | ANITILE_SMOKE_EFFECT | ANITILE_LOOPING;
  235. if ( !( gGameSettings.fOptions[ TOPTION_ANIMATE_SMOKE ] ) )
  236. {
  237. AniParams.uiFlags = ANITILE_PAUSED | ANITILE_CACHEDTILE | ANITILE_FORWARD | ANITILE_SMOKE_EFFECT | ANITILE_LOOPING;
  238. }
  239. else
  240. {
  241. AniParams.uiFlags = ANITILE_CACHEDTILE | ANITILE_FORWARD | ANITILE_SMOKE_EFFECT | ANITILE_LOOPING | ANITILE_ALWAYS_TRANSLUCENT;
  242. }
  243. AniParams.sX = CenterX( sGridNo );
  244. AniParams.sY = CenterY( sGridNo );
  245. AniParams.sZ = (INT16)0;
  246. // Use the right graphic based on type..
  247. switch( bType )
  248. {
  249. case NORMAL_SMOKE_EFFECT:
  250. if ( !( gGameSettings.fOptions[ TOPTION_ANIMATE_SMOKE ] ) )
  251. {
  252. strcpy( AniParams.zCachedFile, "TILECACHE\\smkechze.STI" );
  253. }
  254. else
  255. {
  256. if ( fDissipating )
  257. {
  258. strcpy( AniParams.zCachedFile, "TILECACHE\\smalsmke.STI" );
  259. }
  260. else
  261. {
  262. strcpy( AniParams.zCachedFile, "TILECACHE\\SMOKE.STI" );
  263. }
  264. }
  265. break;
  266. case TEARGAS_SMOKE_EFFECT:
  267. if ( !( gGameSettings.fOptions[ TOPTION_ANIMATE_SMOKE ] ) )
  268. {
  269. strcpy( AniParams.zCachedFile, "TILECACHE\\tearchze.STI" );
  270. }
  271. else
  272. {
  273. if ( fDissipating )
  274. {
  275. strcpy( AniParams.zCachedFile, "TILECACHE\\smaltear.STI" );
  276. }
  277. else
  278. {
  279. strcpy( AniParams.zCachedFile, "TILECACHE\\TEARGAS.STI" );
  280. }
  281. }
  282. break;
  283. case MUSTARDGAS_SMOKE_EFFECT:
  284. if ( !( gGameSettings.fOptions[ TOPTION_ANIMATE_SMOKE ] ) )
  285. {
  286. strcpy( AniParams.zCachedFile, "TILECACHE\\mustchze.STI" );
  287. }
  288. else
  289. {
  290. if ( fDissipating )
  291. {
  292. strcpy( AniParams.zCachedFile, "TILECACHE\\smalmust.STI" );
  293. }
  294. else
  295. {
  296. strcpy( AniParams.zCachedFile, "TILECACHE\\MUSTARD2.STI" );
  297. }
  298. }
  299. break;
  300. case CREATURE_SMOKE_EFFECT:
  301. if ( !( gGameSettings.fOptions[ TOPTION_ANIMATE_SMOKE ] ) )
  302. {
  303. strcpy( AniParams.zCachedFile, "TILECACHE\\spit_gas.STI" );
  304. }
  305. else
  306. {
  307. if ( fDissipating )
  308. {
  309. strcpy( AniParams.zCachedFile, "TILECACHE\\spit_gas.STI" );
  310. }
  311. else
  312. {
  313. strcpy( AniParams.zCachedFile, "TILECACHE\\spit_gas.STI" );
  314. }
  315. }
  316. break;
  317. }
  318. // Create tile...
  319. pAniTile = CreateAnimationTile( &AniParams );
  320. // Set world flags
  321. gpWorldLevelData[ sGridNo ].ubExtFlags[ bLevel ] |= FromSmokeTypeToWorldFlags( bType );
  322. // All done...
  323. // Re-draw..... :(
  324. SetRenderFlags(RENDER_FLAG_FULL);
  325. }
  326. void RemoveSmokeEffectFromTile( INT16 sGridNo, INT8 bLevel )
  327. {
  328. ANITILE *pAniTile;
  329. UINT8 ubLevelID;
  330. // Get ANI tile...
  331. if ( bLevel == 0 )
  332. {
  333. ubLevelID = ANI_STRUCT_LEVEL;
  334. }
  335. else
  336. {
  337. ubLevelID = ANI_ONROOF_LEVEL;
  338. }
  339. pAniTile = GetCachedAniTileOfType( sGridNo, ubLevelID, ANITILE_SMOKE_EFFECT );
  340. if ( pAniTile != NULL )
  341. {
  342. DeleteAniTile( pAniTile );
  343. SetRenderFlags( RENDER_FLAG_FULL );
  344. }
  345. // Unset flags in world....
  346. // ( // check to see if we are the last one....
  347. if ( GetCachedAniTileOfType( sGridNo, ubLevelID, ANITILE_SMOKE_EFFECT ) == NULL )
  348. {
  349. gpWorldLevelData[ sGridNo ].ubExtFlags[ bLevel ] &= ( ~ANY_SMOKE_EFFECT );
  350. }
  351. }
  352. void DecaySmokeEffects( UINT32 uiTime )
  353. {
  354. SMOKEEFFECT *pSmoke;
  355. UINT32 cnt, cnt2;
  356. BOOLEAN fUpdate = FALSE;
  357. BOOLEAN fSpreadEffect;
  358. INT8 bLevel;
  359. UINT16 usNumUpdates = 1;
  360. for ( cnt = 0; cnt < guiNumMercSlots; cnt++ )
  361. {
  362. if ( MercSlots[ cnt ] )
  363. {
  364. // reset 'hit by gas' flags
  365. MercSlots[ cnt ]->fHitByGasFlags = 0;
  366. }
  367. }
  368. // ATE: 1 ) make first pass and delete/mark any smoke effect for update
  369. // all the deleting has to be done first///
  370. // age all active tear gas clouds, deactivate those that are just dispersing
  371. for ( cnt = 0; cnt < guiNumSmokeEffects; cnt++ )
  372. {
  373. fSpreadEffect = TRUE;
  374. pSmoke = &gSmokeEffectData[ cnt ];
  375. if ( pSmoke->fAllocated )
  376. {
  377. if ( pSmoke->bFlags & SMOKE_EFFECT_ON_ROOF )
  378. {
  379. bLevel = 1;
  380. }
  381. else
  382. {
  383. bLevel = 0;
  384. }
  385. // Do things differently for combat /vs realtime
  386. // always try to update during combat
  387. if (gTacticalStatus.uiFlags & INCOMBAT )
  388. {
  389. fUpdate = TRUE;
  390. }
  391. else
  392. {
  393. // ATE: Do this every so ofte, to acheive the effect we want...
  394. if ( ( uiTime - pSmoke->uiTimeOfLastUpdate ) > 10 )
  395. {
  396. fUpdate = TRUE;
  397. usNumUpdates = ( UINT16 ) ( ( uiTime - pSmoke->uiTimeOfLastUpdate ) / 10 );
  398. }
  399. }
  400. if ( fUpdate )
  401. {
  402. pSmoke->uiTimeOfLastUpdate = uiTime;
  403. for ( cnt2 = 0; cnt2 < usNumUpdates; cnt2++ )
  404. {
  405. pSmoke->bAge++;
  406. if ( pSmoke->bAge == 1 )
  407. {
  408. // ATE: At least mark for update!
  409. pSmoke->bFlags |= SMOKE_EFFECT_MARK_FOR_UPDATE;
  410. fSpreadEffect = FALSE;
  411. }
  412. else
  413. {
  414. fSpreadEffect = TRUE;
  415. }
  416. if ( fSpreadEffect )
  417. {
  418. // if this cloud remains effective (duration not reached)
  419. if ( pSmoke->bAge <= pSmoke->ubDuration)
  420. {
  421. // ATE: Only mark now and increse radius - actual drawing is done
  422. // in another pass cause it could
  423. // just get erased...
  424. pSmoke->bFlags |= SMOKE_EFFECT_MARK_FOR_UPDATE;
  425. // calculate the new cloud radius
  426. // cloud expands by 1 every turn outdoors, and every other turn indoors
  427. // ATE: If radius is < maximun, increase radius, otherwise keep at max
  428. if ( pSmoke->ubRadius < Explosive[ Item[ pSmoke->usItem ].ubClassIndex ].ubRadius )
  429. {
  430. pSmoke->ubRadius++;
  431. }
  432. }
  433. else
  434. {
  435. // deactivate tear gas cloud (use last known radius)
  436. SpreadEffect( pSmoke->sGridNo, pSmoke->ubRadius, pSmoke->usItem, pSmoke->ubOwner, ERASE_SPREAD_EFFECT, bLevel, cnt );
  437. pSmoke->fAllocated = FALSE;
  438. break;
  439. }
  440. }
  441. }
  442. }
  443. else
  444. {
  445. // damage anyone standing in cloud
  446. SpreadEffect( pSmoke->sGridNo, pSmoke->ubRadius, pSmoke->usItem, pSmoke->ubOwner, REDO_SPREAD_EFFECT, 0, cnt );
  447. }
  448. }
  449. }
  450. for ( cnt = 0; cnt < guiNumSmokeEffects; cnt++ )
  451. {
  452. pSmoke = &gSmokeEffectData[ cnt ];
  453. if ( pSmoke->fAllocated )
  454. {
  455. if ( pSmoke->bFlags & SMOKE_EFFECT_ON_ROOF )
  456. {
  457. bLevel = 1;
  458. }
  459. else
  460. {
  461. bLevel = 0;
  462. }
  463. // if this cloud remains effective (duration not reached)
  464. if ( pSmoke->bFlags & SMOKE_EFFECT_MARK_FOR_UPDATE )
  465. {
  466. SpreadEffect( pSmoke->sGridNo, pSmoke->ubRadius, pSmoke->usItem, pSmoke->ubOwner, TRUE, bLevel, cnt );
  467. pSmoke->bFlags &= (~SMOKE_EFFECT_MARK_FOR_UPDATE);
  468. }
  469. }
  470. }
  471. AllTeamsLookForAll( TRUE );
  472. }
  473. BOOLEAN SaveSmokeEffectsToSaveGameFile( HWFILE hFile )
  474. {
  475. /*
  476. UINT32 uiNumBytesWritten;
  477. UINT32 uiCnt=0;
  478. UINT32 uiNumSmokeEffects=0;
  479. //loop through and count the number of smoke effects
  480. for( uiCnt=0; uiCnt<guiNumSmokeEffects; uiCnt++)
  481. {
  482. if( gSmokeEffectData[ uiCnt ].fAllocated )
  483. uiNumSmokeEffects++;
  484. }
  485. //Save the Number of Smoke Effects
  486. FileWrite( hFile, &uiNumSmokeEffects, sizeof( UINT32 ), &uiNumBytesWritten );
  487. if( uiNumBytesWritten != sizeof( UINT32 ) )
  488. {
  489. return( FALSE );
  490. }
  491. if( uiNumSmokeEffects != 0 )
  492. {
  493. //loop through and save the number of smoke effects
  494. for( uiCnt=0; uiCnt < guiNumSmokeEffects; uiCnt++)
  495. {
  496. //if the smoke is active
  497. if( gSmokeEffectData[ uiCnt ].fAllocated )
  498. {
  499. //Save the Smoke effect Data
  500. FileWrite( hFile, &gSmokeEffectData[ uiCnt ], sizeof( SMOKEEFFECT ), &uiNumBytesWritten );
  501. if( uiNumBytesWritten != sizeof( SMOKEEFFECT ) )
  502. {
  503. return( FALSE );
  504. }
  505. }
  506. }
  507. }
  508. */
  509. return( TRUE );
  510. }
  511. BOOLEAN LoadSmokeEffectsFromLoadGameFile( HWFILE hFile )
  512. {
  513. UINT32 uiNumBytesRead;
  514. UINT32 uiCount;
  515. UINT32 uiCnt=0;
  516. INT8 bLevel;
  517. //no longer need to load smoke effects. They are now in temp files
  518. if( guiSaveGameVersion < 75 )
  519. {
  520. //Clear out the old list
  521. memset( gSmokeEffectData, 0, sizeof( SMOKEEFFECT ) * NUM_SMOKE_EFFECT_SLOTS );
  522. //Load the Number of Smoke Effects
  523. FileRead( hFile, &guiNumSmokeEffects, sizeof( UINT32 ), &uiNumBytesRead );
  524. if( uiNumBytesRead != sizeof( UINT32 ) )
  525. {
  526. return( FALSE );
  527. }
  528. //This is a TEMP hack to allow us to use the saves
  529. if( guiSaveGameVersion < 37 && guiNumSmokeEffects == 0 )
  530. {
  531. //Load the Smoke effect Data
  532. FileRead( hFile, gSmokeEffectData, sizeof( SMOKEEFFECT ), &uiNumBytesRead );
  533. if( uiNumBytesRead != sizeof( SMOKEEFFECT ) )
  534. {
  535. return( FALSE );
  536. }
  537. }
  538. //loop through and load the list
  539. for( uiCnt=0; uiCnt<guiNumSmokeEffects;uiCnt++)
  540. {
  541. //Load the Smoke effect Data
  542. FileRead( hFile, &gSmokeEffectData[ uiCnt ], sizeof( SMOKEEFFECT ), &uiNumBytesRead );
  543. if( uiNumBytesRead != sizeof( SMOKEEFFECT ) )
  544. {
  545. return( FALSE );
  546. }
  547. //This is a TEMP hack to allow us to use the saves
  548. if( guiSaveGameVersion < 37 )
  549. break;
  550. }
  551. //loop through and apply the smoke effects to the map
  552. for(uiCount=0; uiCount < guiNumSmokeEffects; uiCount++)
  553. {
  554. //if this slot is allocated
  555. if( gSmokeEffectData[uiCount].fAllocated )
  556. {
  557. if ( gSmokeEffectData[uiCount].bFlags & SMOKE_EFFECT_ON_ROOF )
  558. {
  559. bLevel = 1;
  560. }
  561. else
  562. {
  563. bLevel = 0;
  564. }
  565. SpreadEffect( gSmokeEffectData[uiCount].sGridNo, gSmokeEffectData[uiCount].ubRadius, gSmokeEffectData[uiCount].usItem, gSmokeEffectData[uiCount].ubOwner, TRUE, bLevel, uiCount );
  566. }
  567. }
  568. }
  569. return( TRUE );
  570. }
  571. BOOLEAN SaveSmokeEffectsToMapTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
  572. {
  573. UINT32 uiNumSmokeEffects=0;
  574. HWFILE hFile;
  575. UINT32 uiNumBytesWritten=0;
  576. CHAR8 zMapName[ 128 ];
  577. UINT32 uiCnt;
  578. //get the name of the map
  579. GetMapTempFileName( SF_SMOKE_EFFECTS_TEMP_FILE_EXISTS, zMapName, sMapX, sMapY, bMapZ );
  580. //delete file the file.
  581. FileDelete( zMapName );
  582. //loop through and count the number of smoke effects
  583. for( uiCnt=0; uiCnt<guiNumSmokeEffects; uiCnt++)
  584. {
  585. if( gSmokeEffectData[ uiCnt ].fAllocated )
  586. uiNumSmokeEffects++;
  587. }
  588. //if there are no smoke effects
  589. if( uiNumSmokeEffects == 0 )
  590. {
  591. //set the fact that there are no smoke effects for this sector
  592. ReSetSectorFlag( sMapX, sMapY, bMapZ, SF_SMOKE_EFFECTS_TEMP_FILE_EXISTS );
  593. return( TRUE );
  594. }
  595. //Open the file for writing
  596. hFile = FileOpen( zMapName, FILE_ACCESS_WRITE | FILE_OPEN_ALWAYS, FALSE );
  597. if( hFile == 0 )
  598. {
  599. //Error opening file
  600. return( FALSE );
  601. }
  602. //Save the Number of Smoke Effects
  603. FileWrite( hFile, &uiNumSmokeEffects, sizeof( UINT32 ), &uiNumBytesWritten );
  604. if( uiNumBytesWritten != sizeof( UINT32 ) )
  605. {
  606. //Close the file
  607. FileClose( hFile );
  608. return( FALSE );
  609. }
  610. //loop through and save the number of smoke effects
  611. for( uiCnt=0; uiCnt < guiNumSmokeEffects; uiCnt++)
  612. {
  613. //if the smoke is active
  614. if( gSmokeEffectData[ uiCnt ].fAllocated )
  615. {
  616. //Save the Smoke effect Data
  617. FileWrite( hFile, &gSmokeEffectData[ uiCnt ], sizeof( SMOKEEFFECT ), &uiNumBytesWritten );
  618. if( uiNumBytesWritten != sizeof( SMOKEEFFECT ) )
  619. {
  620. //Close the file
  621. FileClose( hFile );
  622. return( FALSE );
  623. }
  624. }
  625. }
  626. //Close the file
  627. FileClose( hFile );
  628. SetSectorFlag( sMapX, sMapY, bMapZ, SF_SMOKE_EFFECTS_TEMP_FILE_EXISTS );
  629. return( TRUE );
  630. }
  631. BOOLEAN LoadSmokeEffectsFromMapTempFile( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
  632. {
  633. UINT32 uiNumBytesRead;
  634. UINT32 uiCount;
  635. UINT32 uiCnt=0;
  636. HWFILE hFile;
  637. UINT32 uiNumBytesWritten=0;
  638. CHAR8 zMapName[ 128 ];
  639. INT8 bLevel;
  640. GetMapTempFileName( SF_SMOKE_EFFECTS_TEMP_FILE_EXISTS, zMapName, sMapX, sMapY, bMapZ );
  641. //Open the file for reading, Create it if it doesnt exist
  642. hFile = FileOpen( zMapName, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE );
  643. if( hFile == 0 )
  644. {
  645. //Error opening map modification file
  646. return( FALSE );
  647. }
  648. //Clear out the old list
  649. ResetSmokeEffects();
  650. //Load the Number of Smoke Effects
  651. FileRead( hFile, &guiNumSmokeEffects, sizeof( UINT32 ), &uiNumBytesRead );
  652. if( uiNumBytesRead != sizeof( UINT32 ) )
  653. {
  654. FileClose( hFile );
  655. return( FALSE );
  656. }
  657. //loop through and load the list
  658. for( uiCnt=0; uiCnt<guiNumSmokeEffects;uiCnt++)
  659. {
  660. //Load the Smoke effect Data
  661. FileRead( hFile, &gSmokeEffectData[ uiCnt ], sizeof( SMOKEEFFECT ), &uiNumBytesRead );
  662. if( uiNumBytesRead != sizeof( SMOKEEFFECT ) )
  663. {
  664. FileClose( hFile );
  665. return( FALSE );
  666. }
  667. }
  668. //loop through and apply the smoke effects to the map
  669. for(uiCount=0; uiCount < guiNumSmokeEffects; uiCount++)
  670. {
  671. //if this slot is allocated
  672. if( gSmokeEffectData[uiCount].fAllocated )
  673. {
  674. if ( gSmokeEffectData[uiCount].bFlags & SMOKE_EFFECT_ON_ROOF )
  675. {
  676. bLevel = 1;
  677. }
  678. else
  679. {
  680. bLevel = 0;
  681. }
  682. SpreadEffect( gSmokeEffectData[uiCount].sGridNo, gSmokeEffectData[uiCount].ubRadius, gSmokeEffectData[uiCount].usItem, gSmokeEffectData[uiCount].ubOwner, TRUE, bLevel, uiCount );
  683. }
  684. }
  685. FileClose( hFile );
  686. return( TRUE );
  687. }
  688. void ResetSmokeEffects()
  689. {
  690. //Clear out the old list
  691. memset( gSmokeEffectData, 0, sizeof( SMOKEEFFECT ) * NUM_SMOKE_EFFECT_SLOTS );
  692. guiNumSmokeEffects = 0;
  693. }
  694. void UpdateSmokeEffectGraphics( )
  695. {
  696. UINT32 uiCnt;
  697. SMOKEEFFECT *pSmoke;
  698. INT8 bLevel;
  699. //loop through and save the number of smoke effects
  700. for( uiCnt=0; uiCnt < guiNumSmokeEffects; uiCnt++)
  701. {
  702. pSmoke = &gSmokeEffectData[ uiCnt ];
  703. //if the smoke is active
  704. if( gSmokeEffectData[ uiCnt ].fAllocated )
  705. {
  706. if ( gSmokeEffectData[uiCnt].bFlags & SMOKE_EFFECT_ON_ROOF )
  707. {
  708. bLevel = 1;
  709. }
  710. else
  711. {
  712. bLevel = 0;
  713. }
  714. SpreadEffect( pSmoke->sGridNo, pSmoke->ubRadius, pSmoke->usItem, pSmoke->ubOwner, ERASE_SPREAD_EFFECT, bLevel, uiCnt );
  715. SpreadEffect( pSmoke->sGridNo, pSmoke->ubRadius, pSmoke->usItem, pSmoke->ubOwner, TRUE, bLevel, uiCnt );
  716. }
  717. }
  718. }