Interactive Tiles.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. #ifdef PRECOMPILEDHEADERS
  2. #include "TileEngine All.h"
  3. #else
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include <time.h>
  7. #include "sgp.h"
  8. #include "himage.h"
  9. #include "vsurface.h"
  10. #include "vsurface_private.h"
  11. #include "wcheck.h"
  12. #include "sysutil.h"
  13. #include "renderworld.h"
  14. #include "interface.h"
  15. #include "Sound Control.h"
  16. #include "worlddef.h"
  17. #include "Interactive Tiles.h"
  18. #include "interface cursors.h"
  19. #include "worldman.h"
  20. #include "structure.h"
  21. #include "Animation Control.h"
  22. #include "points.h"
  23. #include "overhead.h"
  24. #include "structure wrap.h"
  25. #include "tile animation.h"
  26. #include "tile cache.h"
  27. #include "handle doors.h"
  28. #include "Strategicmap.h"
  29. #include "Quests.h"
  30. #include "Dialogue Control.h"
  31. #include "Random.h"
  32. #include "english.h"
  33. #include "handle items.h"
  34. #include "message.h"
  35. #include "handle ui.h"
  36. #endif
  37. #define MAX_INTTILE_STACK 10
  38. typedef struct
  39. {
  40. INT16 sGridNo;
  41. UINT8 ubFlags;
  42. INT16 sTileIndex;
  43. INT16 sMaxScreenY;
  44. INT16 sHeighestScreenY;
  45. BOOLEAN fFound;
  46. LEVELNODE *pFoundNode;
  47. INT16 sFoundGridNo;
  48. UINT16 usStructureID;
  49. BOOLEAN fStructure;
  50. } CUR_INTERACTIVE_TILE;
  51. typedef struct
  52. {
  53. INT8 bNum;
  54. CUR_INTERACTIVE_TILE bTiles[ MAX_INTTILE_STACK ];
  55. INT8 bCur;
  56. } INTERACTIVE_TILE_STACK_TYPE;
  57. INTERACTIVE_TILE_STACK_TYPE gCurIntTileStack;
  58. BOOLEAN gfCycleIntTile = FALSE;
  59. CUR_INTERACTIVE_TILE gCurIntTile;
  60. BOOLEAN gfOverIntTile = FALSE;
  61. // Values to determine if we should check or not
  62. INT16 gsINTOldRenderCenterX = 0;
  63. INT16 gsINTOldRenderCenterY = 0;
  64. UINT16 gusINTOldMousePosX = 0;
  65. UINT16 gusINTOldMousePosY = 0;
  66. BOOLEAN RefinePointCollisionOnStruct( INT16 sGridNo, INT16 sTestX, INT16 sTestY, INT16 sSrcX, INT16 sSrcY, LEVELNODE *pNode );
  67. BOOLEAN CheckVideoObjectScreenCoordinateInData( HVOBJECT hSrcVObject, UINT16 usIndex, INT32 iTextX, INT32 iTestY );
  68. BOOLEAN RefineLogicOnStruct( INT16 sGridNo, LEVELNODE *pNode );
  69. BOOLEAN InitInteractiveTileManagement( )
  70. {
  71. return( TRUE );
  72. }
  73. void ShutdownInteractiveTileManagement( )
  74. {
  75. }
  76. BOOLEAN AddInteractiveTile( INT16 sGridNo, LEVELNODE *pLevelNode, UINT32 uiFlags, UINT16 usType )
  77. {
  78. return( TRUE );
  79. }
  80. BOOLEAN StartInteractiveObject( INT16 sGridNo, UINT16 usStructureID, SOLDIERTYPE *pSoldier, UINT8 ubDirection )
  81. {
  82. STRUCTURE * pStructure;
  83. // ATE: Patch fix: Don't allow if alreay in animation
  84. if ( pSoldier->usAnimState == OPEN_STRUCT || pSoldier->usAnimState == OPEN_STRUCT_CROUCHED ||
  85. pSoldier->usAnimState == BEGIN_OPENSTRUCT || pSoldier->usAnimState == BEGIN_OPENSTRUCT_CROUCHED )
  86. {
  87. return( FALSE );
  88. }
  89. pStructure = FindStructureByID( sGridNo, usStructureID );
  90. if (pStructure == NULL)
  91. {
  92. return( FALSE );
  93. }
  94. if (pStructure->fFlags & STRUCTURE_ANYDOOR)
  95. {
  96. // Add soldier event for opening door....
  97. pSoldier->ubPendingAction = MERC_OPENDOOR;
  98. pSoldier->uiPendingActionData1 = usStructureID;
  99. pSoldier->sPendingActionData2 = sGridNo;
  100. pSoldier->bPendingActionData3 = ubDirection;
  101. pSoldier->ubPendingActionAnimCount = 0;
  102. }
  103. else
  104. {
  105. // Add soldier event for opening door....
  106. pSoldier->ubPendingAction = MERC_OPENSTRUCT;
  107. pSoldier->uiPendingActionData1 = usStructureID;
  108. pSoldier->sPendingActionData2 = sGridNo;
  109. pSoldier->bPendingActionData3 = ubDirection;
  110. pSoldier->ubPendingActionAnimCount = 0;
  111. }
  112. return( TRUE );
  113. }
  114. BOOLEAN CalcInteractiveObjectAPs( INT16 sGridNo, STRUCTURE * pStructure, INT16 *psAPCost, INT16 *psBPCost )
  115. {
  116. if (pStructure == NULL)
  117. {
  118. return( FALSE );
  119. }
  120. if (pStructure->fFlags & STRUCTURE_ANYDOOR)
  121. {
  122. // For doors, if open, we can safely add APs for closing
  123. // If closed, we do not know what to do yet...
  124. //if ( pStructure->fFlags & STRUCTURE_OPEN )
  125. //{
  126. *psAPCost = AP_OPEN_DOOR;
  127. *psBPCost = AP_OPEN_DOOR;
  128. //}
  129. //else
  130. //{
  131. // *psAPCost = 0;
  132. // *psBPCost = 0;
  133. //}
  134. }
  135. else
  136. {
  137. *psAPCost = AP_OPEN_DOOR;
  138. *psBPCost = AP_OPEN_DOOR;
  139. }
  140. return( TRUE );
  141. }
  142. BOOLEAN InteractWithInteractiveObject( SOLDIERTYPE *pSoldier, STRUCTURE *pStructure, UINT8 ubDirection )
  143. {
  144. BOOLEAN fDoor = FALSE;
  145. if (pStructure == NULL)
  146. {
  147. return( FALSE );
  148. }
  149. if (pStructure->fFlags & STRUCTURE_ANYDOOR)
  150. {
  151. fDoor = TRUE;
  152. }
  153. InteractWithOpenableStruct( pSoldier, pStructure, ubDirection, fDoor );
  154. return( TRUE );
  155. }
  156. BOOLEAN SoldierHandleInteractiveObject( SOLDIERTYPE *pSoldier )
  157. {
  158. STRUCTURE *pStructure;
  159. UINT16 usStructureID;
  160. INT16 sGridNo;
  161. sGridNo = pSoldier->sPendingActionData2;
  162. usStructureID = (UINT16)pSoldier->uiPendingActionData1;
  163. // HANDLE SOLDIER ACTIONS
  164. pStructure = FindStructureByID( sGridNo, usStructureID );
  165. if (pStructure == NULL)
  166. {
  167. //DEBUG MSG!
  168. return( FALSE );
  169. }
  170. return( HandleOpenableStruct( pSoldier, sGridNo, pStructure ) );
  171. }
  172. void HandleStructChangeFromGridNo( SOLDIERTYPE *pSoldier, INT16 sGridNo )
  173. {
  174. STRUCTURE *pStructure, *pNewStructure;
  175. INT16 sAPCost = 0, sBPCost = 0;
  176. ITEM_POOL *pItemPool;
  177. BOOLEAN fDidMissingQuote = FALSE;
  178. pStructure = FindStructure( sGridNo, STRUCTURE_OPENABLE );
  179. if ( pStructure == NULL )
  180. {
  181. #ifdef JA2TESTVERSION
  182. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_TESTVERSION, L"ERROR: Told to handle struct that does not exist at %d.", sGridNo );
  183. #endif
  184. return;
  185. }
  186. // Do sound...
  187. if ( !( pStructure->fFlags & STRUCTURE_OPEN ) )
  188. {
  189. // Play Opening sound...
  190. PlayJA2Sample( GetStructureOpenSound( pStructure, FALSE ), RATE_11025, SoundVolume( HIGHVOLUME, sGridNo ), 1, SoundDir( sGridNo ) );
  191. }
  192. else
  193. {
  194. // Play Opening sound...
  195. PlayJA2Sample( ( GetStructureOpenSound( pStructure, TRUE ) ), RATE_11025, SoundVolume( HIGHVOLUME, sGridNo ), 1, SoundDir( sGridNo ) );
  196. }
  197. // ATE: Don't handle switches!
  198. if ( !( pStructure->fFlags & STRUCTURE_SWITCH ) )
  199. {
  200. if ( pSoldier->bTeam == gbPlayerNum )
  201. {
  202. if ( sGridNo == BOBBYR_SHIPPING_DEST_GRIDNO && gWorldSectorX == BOBBYR_SHIPPING_DEST_SECTOR_X && gWorldSectorY == BOBBYR_SHIPPING_DEST_SECTOR_Y && gbWorldSectorZ == BOBBYR_SHIPPING_DEST_SECTOR_Z && CheckFact( FACT_PABLOS_STOLE_FROM_LATEST_SHIPMENT, 0 ) && !(CheckFact( FACT_PLAYER_FOUND_ITEMS_MISSING, 0) ) )
  203. {
  204. SayQuoteFromNearbyMercInSector( BOBBYR_SHIPPING_DEST_GRIDNO, 3, QUOTE_STUFF_MISSING_DRASSEN );
  205. fDidMissingQuote = TRUE;
  206. }
  207. }
  208. else if ( pSoldier->bTeam == CIV_TEAM )
  209. {
  210. if ( pSoldier->ubProfile != NO_PROFILE )
  211. {
  212. TriggerNPCWithGivenApproach( pSoldier->ubProfile, APPROACH_DONE_OPEN_STRUCTURE, FALSE );
  213. }
  214. }
  215. // LOOK for item pool here...
  216. if ( GetItemPool( (INT16)sGridNo, &pItemPool, pSoldier->bLevel ) )
  217. {
  218. // Update visiblity....
  219. if ( !( pStructure->fFlags & STRUCTURE_OPEN ) )
  220. {
  221. BOOLEAN fDoHumm = TRUE;
  222. BOOLEAN fDoLocators = TRUE;
  223. if ( pSoldier->bTeam != gbPlayerNum )
  224. {
  225. fDoHumm = FALSE;
  226. fDoLocators = FALSE;
  227. }
  228. // Look for ownership here....
  229. if ( gWorldItems[ pItemPool->iItemIndex ].o.usItem == OWNERSHIP )
  230. {
  231. fDoHumm = FALSE;
  232. TacticalCharacterDialogueWithSpecialEvent( pSoldier, 0, DIALOGUE_SPECIAL_EVENT_DO_BATTLE_SND, BATTLE_SOUND_NOTHING , 500 );
  233. }
  234. // If now open, set visible...
  235. SetItemPoolVisibilityOn( pItemPool, ANY_VISIBILITY_VALUE, fDoLocators );
  236. // Display quote!
  237. //TacticalCharacterDialogue( pSoldier, (UINT16)( QUOTE_SPOTTED_SOMETHING_ONE + Random( 2 ) ) );
  238. // ATE: Check now many things in pool.....
  239. if ( !fDidMissingQuote )
  240. {
  241. if ( pItemPool->pNext != NULL )
  242. {
  243. if ( pItemPool->pNext->pNext != NULL )
  244. {
  245. fDoHumm = FALSE;
  246. TacticalCharacterDialogueWithSpecialEvent( pSoldier, 0, DIALOGUE_SPECIAL_EVENT_DO_BATTLE_SND, BATTLE_SOUND_COOL1 , 500 );
  247. }
  248. }
  249. if ( fDoHumm )
  250. {
  251. TacticalCharacterDialogueWithSpecialEvent( pSoldier, 0, DIALOGUE_SPECIAL_EVENT_DO_BATTLE_SND, BATTLE_SOUND_HUMM , 500 );
  252. }
  253. }
  254. }
  255. else
  256. {
  257. SetItemPoolVisibilityHidden( pItemPool );
  258. }
  259. }
  260. else
  261. {
  262. if ( !( pStructure->fFlags & STRUCTURE_OPEN ) )
  263. {
  264. TacticalCharacterDialogueWithSpecialEvent( pSoldier, 0, DIALOGUE_SPECIAL_EVENT_DO_BATTLE_SND, BATTLE_SOUND_NOTHING , 500 );
  265. }
  266. }
  267. }
  268. // Deduct points!
  269. // CalcInteractiveObjectAPs( sGridNo, pStructure, &sAPCost, &sBPCost );
  270. // DeductPoints( pSoldier, sAPCost, sBPCost );
  271. pNewStructure = SwapStructureForPartner( sGridNo, pStructure );
  272. if ( pNewStructure != NULL)
  273. {
  274. RecompileLocalMovementCosts( sGridNo );
  275. SetRenderFlags( RENDER_FLAG_FULL );
  276. if ( pNewStructure->fFlags & STRUCTURE_SWITCH )
  277. {
  278. // just turned a switch on!
  279. ActivateSwitchInGridNo( pSoldier->ubID, sGridNo );
  280. }
  281. }
  282. }
  283. UINT32 GetInteractiveTileCursor( UINT32 uiOldCursor, BOOLEAN fConfirm )
  284. {
  285. LEVELNODE *pIntNode;
  286. STRUCTURE *pStructure;
  287. INT16 sGridNo;
  288. // OK, first see if we have an in tile...
  289. pIntNode = GetCurInteractiveTileGridNoAndStructure( &sGridNo, &pStructure );
  290. if ( pIntNode != NULL && pStructure != NULL )
  291. {
  292. if( pStructure->fFlags & STRUCTURE_ANYDOOR )
  293. {
  294. SetDoorString( sGridNo );
  295. if ( fConfirm )
  296. {
  297. return( OKHANDCURSOR_UICURSOR );
  298. }
  299. else
  300. {
  301. return( NORMALHANDCURSOR_UICURSOR );
  302. }
  303. }
  304. else
  305. {
  306. if( pStructure->fFlags & STRUCTURE_SWITCH )
  307. {
  308. wcscpy( gzIntTileLocation, gzLateLocalizedString[ 25 ] );
  309. gfUIIntTileLocation = TRUE;
  310. }
  311. if ( fConfirm )
  312. {
  313. return( OKHANDCURSOR_UICURSOR );
  314. }
  315. else
  316. {
  317. return( NORMALHANDCURSOR_UICURSOR );
  318. }
  319. }
  320. }
  321. return( uiOldCursor );
  322. }
  323. void SetActionModeDoorCursorText( )
  324. {
  325. LEVELNODE *pIntNode;
  326. STRUCTURE *pStructure;
  327. INT16 sGridNo;
  328. // If we are over a merc, don't
  329. if ( gfUIFullTargetFound )
  330. {
  331. return;
  332. }
  333. // OK, first see if we have an in tile...
  334. pIntNode = GetCurInteractiveTileGridNoAndStructure( &sGridNo, &pStructure );
  335. if ( pIntNode != NULL && pStructure != NULL )
  336. {
  337. if( pStructure->fFlags & STRUCTURE_ANYDOOR )
  338. {
  339. SetDoorString( sGridNo );
  340. }
  341. }
  342. }
  343. void GetLevelNodeScreenRect( LEVELNODE *pNode, SGPRect *pRect, INT16 sXPos, INT16 sYPos, INT16 sGridNo )
  344. {
  345. INT16 sScreenX, sScreenY;
  346. INT16 sOffsetX, sOffsetY;
  347. INT16 sTempX_S, sTempY_S;
  348. ETRLEObject *pTrav;
  349. UINT32 usHeight, usWidth;
  350. TILE_ELEMENT *TileElem;
  351. // Get 'TRUE' merc position
  352. sOffsetX = sXPos - gsRenderCenterX;
  353. sOffsetY = sYPos - gsRenderCenterY;
  354. FromCellToScreenCoordinates( sOffsetX, sOffsetY, &sTempX_S, &sTempY_S );
  355. if ( pNode->uiFlags & LEVELNODE_CACHEDANITILE )
  356. {
  357. pTrav = &(gpTileCache[ pNode->pAniTile->sCachedTileID ].pImagery->vo->pETRLEObject[ pNode->pAniTile->sCurrentFrame ] );
  358. }
  359. else
  360. {
  361. TileElem = &(gTileDatabase[pNode->usIndex]);
  362. //Adjust for current frames and animations....
  363. if ( TileElem->uiFlags & ANIMATED_TILE)
  364. {
  365. Assert( TileElem->pAnimData != NULL );
  366. TileElem = &gTileDatabase[TileElem->pAnimData->pusFrames[TileElem->pAnimData->bCurrentFrame]];
  367. }
  368. else if( ( pNode->uiFlags & LEVELNODE_ANIMATION ) )
  369. {
  370. if ( pNode->sCurrentFrame != -1 )
  371. {
  372. Assert( TileElem->pAnimData != NULL );
  373. TileElem = &gTileDatabase[TileElem->pAnimData->pusFrames[pNode->sCurrentFrame]];
  374. }
  375. }
  376. pTrav = &(TileElem->hTileSurface->pETRLEObject[ TileElem->usRegionIndex ] );
  377. }
  378. sScreenX = ( ( gsVIEWPORT_END_X - gsVIEWPORT_START_X ) /2 ) + (INT16)sTempX_S;
  379. sScreenY = ( ( gsVIEWPORT_END_Y - gsVIEWPORT_START_Y ) /2 ) + (INT16)sTempY_S;
  380. // Adjust for offset position on screen
  381. sScreenX -= gsRenderWorldOffsetX;
  382. sScreenY -= gsRenderWorldOffsetY;
  383. sScreenY -= gpWorldLevelData[ sGridNo ].sHeight;
  384. // Adjust based on interface level
  385. if ( gsInterfaceLevel > 0 )
  386. {
  387. sScreenY += ROOF_LEVEL_HEIGHT;
  388. }
  389. // Adjust for render height
  390. sScreenY += gsRenderHeight;
  391. usHeight = (UINT32)pTrav->usHeight;
  392. usWidth = (UINT32)pTrav->usWidth;
  393. // Add to start position of dest buffer
  394. sScreenX += ( pTrav->sOffsetX - ( WORLD_TILE_X/2 ) );
  395. sScreenY += ( pTrav->sOffsetY - ( WORLD_TILE_Y/2 ) );
  396. // Adjust y offset!
  397. sScreenY += ( WORLD_TILE_Y/2);
  398. pRect->iLeft = sScreenX;
  399. pRect->iTop = sScreenY;
  400. pRect->iBottom = sScreenY + usHeight;
  401. pRect->iRight = sScreenX + usWidth;
  402. }
  403. void CompileInteractiveTiles( )
  404. {
  405. }
  406. void LogMouseOverInteractiveTile( INT16 sGridNo )
  407. {
  408. SGPRect aRect;
  409. INT16 sXMapPos, sYMapPos, sScreenX, sScreenY;
  410. LEVELNODE *pNode;
  411. // OK, for now, don't allow any interactive tiles on higher interface level!
  412. if ( gsInterfaceLevel > 0 )
  413. {
  414. return;
  415. }
  416. // Also, don't allow for mercs who are on upper level...
  417. if ( gusSelectedSoldier != NOBODY && MercPtrs[ gusSelectedSoldier ]->bLevel == 1 )
  418. {
  419. return;
  420. }
  421. // Get World XY From gridno
  422. ConvertGridNoToCellXY( sGridNo, &sXMapPos, &sYMapPos );
  423. // Set mouse stuff
  424. sScreenX = gusMouseXPos;
  425. sScreenY = gusMouseYPos;
  426. pNode = gpWorldLevelData[ sGridNo ].pStructHead;
  427. while( pNode != NULL )
  428. {
  429. {
  430. GetLevelNodeScreenRect( pNode, &aRect, sXMapPos, sYMapPos , sGridNo );
  431. // Make sure we are always on guy if we are on same gridno
  432. if ( IsPointInScreenRect( sScreenX, sScreenY, &aRect ) )
  433. {
  434. // OK refine it!
  435. if ( RefinePointCollisionOnStruct( sGridNo, sScreenX, sScreenY, (INT16)aRect.iLeft, (INT16)aRect.iBottom, pNode ) )
  436. {
  437. // Do some additional checks here!
  438. if ( RefineLogicOnStruct( sGridNo, pNode ) )
  439. {
  440. gCurIntTile.fFound = TRUE;
  441. // Only if we are not currently cycling....
  442. if ( !gfCycleIntTile )
  443. {
  444. // Accumulate them!
  445. gCurIntTileStack.bTiles[ gCurIntTileStack.bNum ].pFoundNode = pNode;
  446. gCurIntTileStack.bTiles[ gCurIntTileStack.bNum ].sFoundGridNo = sGridNo;
  447. gCurIntTileStack.bNum++;
  448. // Determine if it's the best one
  449. if ( aRect.iBottom > gCurIntTile.sHeighestScreenY )
  450. {
  451. gCurIntTile.sMaxScreenY = (UINT16)aRect.iBottom;
  452. gCurIntTile.sHeighestScreenY = gCurIntTile.sMaxScreenY;
  453. // Set it!
  454. gCurIntTile.pFoundNode = pNode;
  455. gCurIntTile.sFoundGridNo = sGridNo;
  456. // Set stack current one...
  457. gCurIntTileStack.bCur = gCurIntTileStack.bNum-1;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. pNode = pNode->pNext;
  464. }
  465. }
  466. }
  467. LEVELNODE *InternalGetCurInteractiveTile( BOOLEAN fRejectItemsOnTop )
  468. {
  469. LEVELNODE *pNode = NULL;
  470. STRUCTURE *pStructure = NULL;
  471. // OK, Look for our tile!
  472. // Check for shift down!
  473. if ( _KeyDown( SHIFT ) )
  474. {
  475. return( NULL );
  476. }
  477. if ( gfOverIntTile )
  478. {
  479. pNode = gpWorldLevelData[ gCurIntTile.sGridNo ].pStructHead;
  480. while( pNode != NULL )
  481. {
  482. if ( pNode->usIndex == gCurIntTile.sTileIndex )
  483. {
  484. if ( fRejectItemsOnTop )
  485. {
  486. // get strucuture here...
  487. if ( gCurIntTile.fStructure )
  488. {
  489. pStructure = FindStructureByID( gCurIntTile.sGridNo, gCurIntTile.usStructureID );
  490. if (pStructure != NULL)
  491. {
  492. if ( pStructure->fFlags & STRUCTURE_HASITEMONTOP )
  493. {
  494. return( NULL );
  495. }
  496. }
  497. else
  498. {
  499. return( NULL );
  500. }
  501. }
  502. }
  503. return( pNode );
  504. }
  505. pNode = pNode->pNext;
  506. }
  507. }
  508. return( NULL );
  509. }
  510. LEVELNODE *GetCurInteractiveTile( )
  511. {
  512. return( InternalGetCurInteractiveTile( TRUE ) );
  513. }
  514. LEVELNODE *GetCurInteractiveTileGridNo( INT16 *psGridNo )
  515. {
  516. LEVELNODE *pNode;
  517. pNode = GetCurInteractiveTile( );
  518. if ( pNode != NULL )
  519. {
  520. *psGridNo = gCurIntTile.sGridNo;
  521. }
  522. else
  523. {
  524. *psGridNo = NOWHERE;
  525. }
  526. return( pNode );
  527. }
  528. LEVELNODE *ConditionalGetCurInteractiveTileGridNoAndStructure( INT16 *psGridNo, STRUCTURE **ppStructure, BOOLEAN fRejectOnTopItems )
  529. {
  530. LEVELNODE *pNode;
  531. STRUCTURE *pStructure;
  532. *ppStructure = NULL;
  533. pNode = InternalGetCurInteractiveTile( fRejectOnTopItems );
  534. if ( pNode != NULL )
  535. {
  536. *psGridNo = gCurIntTile.sGridNo;
  537. }
  538. else
  539. {
  540. *psGridNo = NOWHERE;
  541. }
  542. if ( pNode != NULL )
  543. {
  544. if ( gCurIntTile.fStructure )
  545. {
  546. pStructure = FindStructureByID( gCurIntTile.sGridNo, gCurIntTile.usStructureID );
  547. if (pStructure == NULL)
  548. {
  549. *ppStructure = NULL;
  550. return( NULL );
  551. }
  552. else
  553. {
  554. *ppStructure = pStructure;
  555. }
  556. }
  557. }
  558. return( pNode );
  559. }
  560. LEVELNODE *GetCurInteractiveTileGridNoAndStructure( INT16 *psGridNo, STRUCTURE **ppStructure )
  561. {
  562. return( ConditionalGetCurInteractiveTileGridNoAndStructure( psGridNo, ppStructure, TRUE ) );
  563. }
  564. void BeginCurInteractiveTileCheck( UINT8 bCheckFlags )
  565. {
  566. gfOverIntTile = FALSE;
  567. // OK, release our stack, stuff could be different!
  568. gfCycleIntTile = FALSE;
  569. // Reset some highest values
  570. gCurIntTile.sHeighestScreenY = 0;
  571. gCurIntTile.fFound = FALSE;
  572. gCurIntTile.ubFlags = bCheckFlags;
  573. // Reset stack values
  574. gCurIntTileStack.bNum = 0;
  575. }
  576. void EndCurInteractiveTileCheck( )
  577. {
  578. CUR_INTERACTIVE_TILE *pCurIntTile;
  579. if ( gCurIntTile.fFound )
  580. {
  581. // Set our currently cycled guy.....
  582. if ( gfCycleIntTile )
  583. {
  584. // OK, we're over this cycled node
  585. pCurIntTile = &( gCurIntTileStack.bTiles[ gCurIntTileStack.bCur ] );
  586. }
  587. else
  588. {
  589. // OK, we're over this levelnode,
  590. pCurIntTile = &gCurIntTile;
  591. }
  592. gCurIntTile.sGridNo = pCurIntTile->sFoundGridNo;
  593. gCurIntTile.sTileIndex = pCurIntTile->pFoundNode->usIndex;
  594. if ( pCurIntTile->pFoundNode->pStructureData != NULL )
  595. {
  596. gCurIntTile.usStructureID = pCurIntTile->pFoundNode->pStructureData->usStructureID;
  597. gCurIntTile.fStructure = TRUE;
  598. }
  599. else
  600. {
  601. gCurIntTile.fStructure = FALSE;
  602. }
  603. gfOverIntTile = TRUE;
  604. }
  605. else
  606. {
  607. // If we are in cycle mode, end it
  608. if ( gfCycleIntTile )
  609. {
  610. gfCycleIntTile = FALSE;
  611. }
  612. }
  613. }
  614. BOOLEAN RefineLogicOnStruct( INT16 sGridNo, LEVELNODE *pNode )
  615. {
  616. TILE_ELEMENT *TileElem;
  617. STRUCTURE *pStructure;
  618. if ( pNode->uiFlags & LEVELNODE_CACHEDANITILE )
  619. {
  620. return ( FALSE );
  621. }
  622. TileElem = &(gTileDatabase[pNode->usIndex]);
  623. if ( gCurIntTile.ubFlags == INTILE_CHECK_SELECTIVE )
  624. {
  625. // See if we are on an interactable tile!
  626. // Try and get struct data from levelnode pointer
  627. pStructure = pNode->pStructureData;
  628. // If no data, quit
  629. if ( pStructure == NULL )
  630. {
  631. return( FALSE );
  632. }
  633. if ( !( pStructure->fFlags & ( STRUCTURE_OPENABLE | STRUCTURE_HASITEMONTOP ) ) )
  634. {
  635. return( FALSE );
  636. }
  637. if ( gusSelectedSoldier != NOBODY && MercPtrs[ gusSelectedSoldier ]->ubBodyType == ROBOTNOWEAPON )
  638. {
  639. return( FALSE );
  640. }
  641. // If we are a door, we need a different definition of being visible than other structs
  642. if ( pStructure->fFlags & STRUCTURE_ANYDOOR )
  643. {
  644. if ( !IsDoorVisibleAtGridNo( sGridNo ) )
  645. {
  646. return( FALSE );
  647. }
  648. // OK, For a OPENED door, addition requirements are: need to be in 'HAND CURSOR' mode...
  649. if ( pStructure->fFlags & STRUCTURE_OPEN )
  650. {
  651. //Are we in hand cursor mode?
  652. if ( gCurrentUIMode != HANDCURSOR_MODE && gCurrentUIMode != ACTION_MODE )
  653. {
  654. return( FALSE );
  655. }
  656. }
  657. // If this option is on...
  658. if ( !gGameSettings.fOptions[ TOPTION_SNAP_CURSOR_TO_DOOR ] )
  659. {
  660. if ( gCurrentUIMode != HANDCURSOR_MODE )
  661. {
  662. return( FALSE );
  663. }
  664. }
  665. }
  666. else
  667. {
  668. // IF we are a switch, reject in another direction...
  669. if ( pStructure->fFlags & STRUCTURE_SWITCH )
  670. {
  671. // Find a new gridno based on switch's orientation...
  672. INT16 sNewGridNo = NOWHERE;
  673. switch( pStructure->pDBStructureRef->pDBStructure->ubWallOrientation )
  674. {
  675. case OUTSIDE_TOP_LEFT:
  676. case INSIDE_TOP_LEFT:
  677. // Move south...
  678. sNewGridNo = NewGridNo( sGridNo, DirectionInc( SOUTH ) );
  679. break;
  680. case OUTSIDE_TOP_RIGHT:
  681. case INSIDE_TOP_RIGHT:
  682. // Move east...
  683. sNewGridNo = NewGridNo( sGridNo, DirectionInc( EAST ) );
  684. break;
  685. }
  686. if ( sNewGridNo != NOWHERE )
  687. {
  688. // If we are hidden by a roof, reject it!
  689. if ( !gfBasement && IsRoofVisible2( sNewGridNo ) && !( gTacticalStatus.uiFlags&SHOW_ALL_ITEMS ) )
  690. {
  691. return( FALSE );
  692. }
  693. }
  694. }
  695. else
  696. {
  697. // If we are hidden by a roof, reject it!
  698. if ( !gfBasement && IsRoofVisible( sGridNo ) && !( gTacticalStatus.uiFlags&SHOW_ALL_ITEMS ) )
  699. {
  700. return( FALSE );
  701. }
  702. }
  703. }
  704. // Check if it's a hidden struct and we have not revealed anything!
  705. if ( TileElem->uiFlags & HIDDEN_TILE )
  706. {
  707. if ( !IsHiddenStructureVisible( sGridNo, pNode->usIndex ) )
  708. {
  709. // Return false
  710. return( FALSE );
  711. }
  712. }
  713. }
  714. return( TRUE );
  715. }
  716. BOOLEAN RefinePointCollisionOnStruct( INT16 sGridNo, INT16 sTestX, INT16 sTestY, INT16 sSrcX, INT16 sSrcY, LEVELNODE *pNode )
  717. {
  718. TILE_ELEMENT *TileElem;
  719. if ( pNode->uiFlags & LEVELNODE_CACHEDANITILE )
  720. {
  721. //Check it!
  722. return ( CheckVideoObjectScreenCoordinateInData( gpTileCache[ pNode->pAniTile->sCachedTileID ].pImagery->vo, pNode->pAniTile->sCurrentFrame, (INT32)( sTestX - sSrcX ), (INT32)( -1 * ( sTestY - sSrcY ) ) ) );
  723. }
  724. else
  725. {
  726. TileElem = &( gTileDatabase[pNode->usIndex] );
  727. //Adjust for current frames and animations....
  728. if ( TileElem->uiFlags & ANIMATED_TILE)
  729. {
  730. Assert( TileElem->pAnimData != NULL );
  731. TileElem = &gTileDatabase[TileElem->pAnimData->pusFrames[TileElem->pAnimData->bCurrentFrame]];
  732. }
  733. else if( ( pNode->uiFlags & LEVELNODE_ANIMATION ) )
  734. {
  735. if ( pNode->sCurrentFrame != -1 )
  736. {
  737. Assert( TileElem->pAnimData != NULL );
  738. TileElem = &gTileDatabase[TileElem->pAnimData->pusFrames[pNode->sCurrentFrame]];
  739. }
  740. }
  741. //Check it!
  742. return ( CheckVideoObjectScreenCoordinateInData( TileElem->hTileSurface, TileElem->usRegionIndex, (INT32)( sTestX - sSrcX ), (INT32)( -1 * ( sTestY - sSrcY ) ) ) );
  743. }
  744. }
  745. // This function will check the video object at SrcX and SrcY for the lack of transparency
  746. // will return true if data found, else false
  747. BOOLEAN CheckVideoObjectScreenCoordinateInData( HVOBJECT hSrcVObject, UINT16 usIndex, INT32 iTestX, INT32 iTestY )
  748. {
  749. UINT32 uiOffset;
  750. UINT32 usHeight, usWidth;
  751. UINT8 *SrcPtr;
  752. UINT32 LineSkip;
  753. ETRLEObject *pTrav;
  754. BOOLEAN fDataFound = FALSE;
  755. INT32 iTestPos, iStartPos;
  756. // Assertions
  757. Assert( hSrcVObject != NULL );
  758. // Get Offsets from Index into structure
  759. pTrav = &(hSrcVObject->pETRLEObject[ usIndex ] );
  760. usHeight = (UINT32)pTrav->usHeight;
  761. usWidth = (UINT32)pTrav->usWidth;
  762. uiOffset = pTrav->uiDataOffset;
  763. // Calculate test position we are looking for!
  764. // Calculate from 0, 0 at top left!
  765. iTestPos = ( ( usHeight - iTestY ) * usWidth ) + iTestX;
  766. iStartPos = 0;
  767. LineSkip = usWidth;
  768. SrcPtr= (UINT8 *)hSrcVObject->pPixData + uiOffset;
  769. __asm {
  770. mov esi, SrcPtr
  771. mov edi, iStartPos
  772. xor eax, eax
  773. xor ebx, ebx
  774. xor ecx, ecx
  775. BlitDispatch:
  776. mov cl, [esi]
  777. inc esi
  778. or cl, cl
  779. js BlitTransparent
  780. jz BlitDoneLine
  781. //BlitNonTransLoop:
  782. clc
  783. rcr cl, 1
  784. jnc BlitNTL2
  785. inc esi
  786. // Check
  787. cmp edi, iTestPos
  788. je BlitFound
  789. add edi, 1
  790. BlitNTL2:
  791. clc
  792. rcr cl, 1
  793. jnc BlitNTL3
  794. add esi, 2
  795. // Check
  796. cmp edi, iTestPos
  797. je BlitFound
  798. add edi, 1
  799. // Check
  800. cmp edi, iTestPos
  801. je BlitFound
  802. add edi, 1
  803. BlitNTL3:
  804. or cl, cl
  805. jz BlitDispatch
  806. xor ebx, ebx
  807. BlitNTL4:
  808. add esi, 4
  809. // Check
  810. cmp edi, iTestPos
  811. je BlitFound
  812. add edi, 1
  813. // Check
  814. cmp edi, iTestPos
  815. je BlitFound
  816. add edi, 1
  817. // Check
  818. cmp edi, iTestPos
  819. je BlitFound
  820. add edi, 1
  821. // Check
  822. cmp edi, iTestPos
  823. je BlitFound
  824. add edi, 1
  825. dec cl
  826. jnz BlitNTL4
  827. jmp BlitDispatch
  828. BlitTransparent:
  829. and ecx, 07fH
  830. // shl ecx, 1
  831. add edi, ecx
  832. jmp BlitDispatch
  833. BlitDoneLine:
  834. // Here check if we have passed!
  835. cmp edi, iTestPos
  836. jge BlitDone
  837. dec usHeight
  838. jz BlitDone
  839. // add edi, LineSkip
  840. jmp BlitDispatch
  841. BlitFound:
  842. mov fDataFound, 1
  843. BlitDone:
  844. }
  845. return(fDataFound);
  846. }
  847. BOOLEAN ShouldCheckForMouseDetections( )
  848. {
  849. BOOLEAN fOK = FALSE;
  850. if ( gsINTOldRenderCenterX != gsRenderCenterX || gsINTOldRenderCenterY != gsRenderCenterY ||
  851. gusINTOldMousePosX != gusMouseXPos || gusINTOldMousePosY != gusMouseYPos )
  852. {
  853. fOK = TRUE;
  854. }
  855. // Set old values
  856. gsINTOldRenderCenterX = gsRenderCenterX;
  857. gsINTOldRenderCenterY = gsRenderCenterY;
  858. gusINTOldMousePosX = gusMouseXPos;
  859. gusINTOldMousePosY = gusMouseYPos;
  860. return( fOK );
  861. }
  862. void CycleIntTileFindStack( UINT16 usMapPos )
  863. {
  864. gfCycleIntTile = TRUE;
  865. // Cycle around!
  866. gCurIntTileStack.bCur++;
  867. //PLot new movement
  868. gfPlotNewMovement = TRUE;
  869. if ( gCurIntTileStack.bCur == gCurIntTileStack.bNum )
  870. {
  871. gCurIntTileStack.bCur = 0;
  872. }
  873. }