From 8d49e74df457e52771a5f553212a7db3e80659a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Fa=C5=82kowski?= Date: Tue, 3 Oct 2023 14:20:36 +0200 Subject: [PATCH 01/16] Face gear render fixes (#232) * Face gear is shaded the same as a face * Render continue button above icons and facegear * Face gear rendered below "hatch" (inactivity overlay) * Consistent naming --- Tactical/Faces.cpp | 586 +++++++++++++++++++++++---------------------- 1 file changed, 305 insertions(+), 281 deletions(-) diff --git a/Tactical/Faces.cpp b/Tactical/Faces.cpp index 059ba8271..a16473532 100644 --- a/Tactical/Faces.cpp +++ b/Tactical/Faces.cpp @@ -62,7 +62,8 @@ void NewEye( FACETYPE *pFace ); void NewMouth( FACETYPE *pFace ); INT32 GetFreeFace(void); void RecountFaces(void); -void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLEAN fUseExternBuffer, UINT32 uiBuffer, INT16 sFaceX, INT16 sFaceY, UINT16 usEyesX, UINT16 usEyesY ); +UINT32 GetFaceShade(SOLDIERTYPE *pSoldier, FACETYPE *pFace, BOOLEAN fExternBlit); +void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLEAN fUseExternBuffer, UINT32 uiBuffer, INT16 sFaceX, INT16 sFaceY, UINT16 usEyesX, UINT16 usEyesY, UINT32 uiFaceShade); extern BOOLEAN gfInItemPickupMenu; @@ -157,6 +158,32 @@ INT32 InitFace( UINT8 usMercProfileID, UINT8 ubSoldierID, UINT32 uiInitFlags ) } +void SetPalettes(HVOBJECT *hVObject, UINT32 uiIndex) +{ + SGPPaletteEntry Pal[256]; + + // Build a grayscale palette! ( for testing different looks ) + for (UINT32 uiCount = 0; uiCount < 256; uiCount++) + { + Pal[uiCount].peRed = 255; + Pal[uiCount].peGreen = 255; + Pal[uiCount].peBlue = 255; + } + + (*hVObject)->pShades[FLASH_PORTRAIT_NOSHADE] = Create16BPPPaletteShaded((*hVObject)->pPaletteEntry, 255, 255, 255, FALSE); + (*hVObject)->pShades[FLASH_PORTRAIT_STARTSHADE] = Create16BPPPaletteShaded(Pal, 255, 255, 255, FALSE); + (*hVObject)->pShades[FLASH_PORTRAIT_ENDSHADE] = Create16BPPPaletteShaded((*hVObject)->pPaletteEntry, 250, 25, 25, TRUE); + (*hVObject)->pShades[FLASH_PORTRAIT_DARKSHADE] = Create16BPPPaletteShaded((*hVObject)->pPaletteEntry, 100, 100, 100, TRUE); + (*hVObject)->pShades[FLASH_PORTRAIT_LITESHADE] = Create16BPPPaletteShaded((*hVObject)->pPaletteEntry, 100, 100, 100, FALSE); + + for (UINT32 uiCount = 0; uiCount < 256; uiCount++) + { + Pal[uiCount].peRed = (UINT8)(uiCount % 128) + 128; + Pal[uiCount].peGreen = (UINT8)(uiCount % 128) + 128; + Pal[uiCount].peBlue = (UINT8)(uiCount % 128) + 128; + } + (*hVObject)->pShades[FLASH_PORTRAIT_GRAYSHADE] = Create16BPPPaletteShaded(Pal, 255, 255, 255, FALSE); +} INT32 InternalInitFace( UINT8 usMercProfileID, UINT8 ubSoldierID, UINT32 uiInitFlags, INT32 iFaceFileID, UINT32 uiBlinkFrequency, UINT32 uiExpressionFrequency ) { @@ -167,7 +194,6 @@ INT32 InternalInitFace( UINT8 usMercProfileID, UINT8 ubSoldierID, UINT32 uiInitF ETRLEObject ETRLEObject; HVOBJECT hVObject; UINT32 uiCount; - SGPPaletteEntry Pal[256]; if( ( iFaceIndex = GetFreeFace() )==(-1) ) return(-1); @@ -436,33 +462,11 @@ INT32 InternalInitFace( UINT8 usMercProfileID, UINT8 ubSoldierID, UINT32 uiInitF // Set palette - if( GetVideoObject( &hVObject, uiVideoObject ) ) + if (GetVideoObject(&hVObject, uiVideoObject)) { - // Build a grayscale palette! ( for testing different looks ) - for(uiCount=0; uiCount < 256; uiCount++) - { - Pal[uiCount].peRed=255; - Pal[uiCount].peGreen=255; - Pal[uiCount].peBlue=255; - } - - hVObject->pShades[ FLASH_PORTRAIT_NOSHADE ] = Create16BPPPaletteShaded( hVObject->pPaletteEntry, 255, 255, 255, FALSE ); - hVObject->pShades[ FLASH_PORTRAIT_STARTSHADE ] = Create16BPPPaletteShaded( Pal, 255, 255, 255, FALSE ); - hVObject->pShades[ FLASH_PORTRAIT_ENDSHADE ] = Create16BPPPaletteShaded( hVObject->pPaletteEntry, 250, 25, 25, TRUE ); - hVObject->pShades[ FLASH_PORTRAIT_DARKSHADE ] = Create16BPPPaletteShaded( hVObject->pPaletteEntry, 100, 100, 100, TRUE ); - hVObject->pShades[ FLASH_PORTRAIT_LITESHADE ] = Create16BPPPaletteShaded( hVObject->pPaletteEntry, 100, 100, 100, FALSE ); - - for(uiCount=0; uiCount < 256; uiCount++) - { - Pal[uiCount].peRed=(UINT8)(uiCount%128)+128; - Pal[uiCount].peGreen=(UINT8)(uiCount%128)+128; - Pal[uiCount].peBlue=(UINT8)(uiCount%128)+128; - } - hVObject->pShades[ FLASH_PORTRAIT_GRAYSHADE ] = Create16BPPPaletteShaded( Pal, 255, 255, 255, FALSE ); - + SetPalettes(&hVObject, uiVideoObject); } - // Get FACE height, width if( GetVideoObjectETRLEPropertiesFromIndex( uiVideoObject, &ETRLEObject, 0 ) == FALSE ) { @@ -942,9 +946,13 @@ void BlinkAutoFace( INT32 iFaceIndex ) { pFace = &gFacesData[ iFaceIndex ]; + UINT32 uiFaceShade = FLASH_PORTRAIT_NOSHADE; + // CHECK IF BUDDY IS DEAD, UNCONSCIOUS, ASLEEP, OR POW! if ( pFace->ubSoldierID != NOBODY ) { + uiFaceShade = GetFaceShade(MercPtrs[pFace->ubSoldierID], pFace, FALSE); + if ( ( MercPtrs[ pFace->ubSoldierID ]->stats.bLife < OKLIFE ) || ( MercPtrs[ pFace->ubSoldierID ]->flags.fMercAsleep == TRUE ) || ( MercPtrs[ pFace->ubSoldierID ]->bAssignment == ASSIGNMENT_POW ) ) @@ -1043,8 +1051,7 @@ void BlinkAutoFace( INT32 iFaceIndex ) } - HandleRenderFaceAdjustments( pFace, TRUE, FALSE, 0, pFace->usFaceX, pFace->usFaceY, pFace->usEyesX, pFace->usEyesY ); - + HandleRenderFaceAdjustments(pFace, TRUE, FALSE, 0, pFace->usFaceX, pFace->usFaceY, pFace->usEyesX, pFace->usEyesY, uiFaceShade); } } @@ -1228,7 +1235,15 @@ void MouthAutoFace( INT32 iFaceIndex ) } - HandleRenderFaceAdjustments( pFace, TRUE, FALSE, 0, pFace->usFaceX, pFace->usFaceY, pFace->usEyesX, pFace->usEyesY ); + UINT32 uiFaceShade = FLASH_PORTRAIT_NOSHADE; + + // Set shade + if (pFace->ubSoldierID != NOBODY) + { + uiFaceShade = GetFaceShade(MercPtrs[pFace->ubSoldierID], pFace, FALSE); + } + + HandleRenderFaceAdjustments( pFace, TRUE, FALSE, 0, pFace->usFaceX, pFace->usFaceY, pFace->usEyesX, pFace->usEyesY, uiFaceShade); } } @@ -1317,32 +1332,38 @@ void HandleTalkingAutoFace( INT32 iFaceIndex ) // Local function - uses these variables because they have already been validated -void SetFaceShade( SOLDIERTYPE *pSoldier, FACETYPE *pFace, BOOLEAN fExternBlit ) +void SetFaceShade(FACETYPE *pFace, UINT32 uiFaceShade) { // Set to default - SetObjectHandleShade( pFace->uiVideoObject, FLASH_PORTRAIT_NOSHADE ); + SetObjectHandleShade(pFace->uiVideoObject, uiFaceShade); +} - if ( pFace->iVideoOverlay == -1 && !fExternBlit ) +UINT32 GetFaceShade(SOLDIERTYPE *pSoldier, FACETYPE *pFace, BOOLEAN fExternBlit) +{ + if (pFace->iVideoOverlay == -1 && !fExternBlit) { - if ( ( pSoldier->bActionPoints == 0 ) && !( gTacticalStatus.uiFlags & REALTIME ) && (gTacticalStatus.uiFlags & INCOMBAT ) ) + if ((pSoldier->bActionPoints == 0) && !(gTacticalStatus.uiFlags & REALTIME) && (gTacticalStatus.uiFlags & INCOMBAT)) { - SetObjectHandleShade( pFace->uiVideoObject, FLASH_PORTRAIT_LITESHADE ); + return FLASH_PORTRAIT_LITESHADE; } } - if ( pSoldier->stats.bLife < OKLIFE ) + if (pSoldier->stats.bLife < OKLIFE) { - SetObjectHandleShade( pFace->uiVideoObject, FLASH_PORTRAIT_DARKSHADE ); + return FLASH_PORTRAIT_DARKSHADE; } // ATE: Don't shade for damage if blitting extern face... - if ( !fExternBlit ) + if (!fExternBlit) { - if ( pSoldier->flags.fFlashPortrait == FLASH_PORTRAIT_START ) + if (pSoldier->flags.fFlashPortrait == FLASH_PORTRAIT_START) { - SetObjectHandleShade( pFace->uiVideoObject, pSoldier->bFlashPortraitFrame ); + return pSoldier->bFlashPortraitFrame; } } + + // Set to default + return FLASH_PORTRAIT_NOSHADE; } BOOLEAN RenderAutoFaceFromSoldier( UINT8 ubSoldierID ) @@ -1450,45 +1471,46 @@ void DoRightIcon_legion_GAS_MASK( UINT32 uiRenderBuffer, FACETYPE *pFace, INT16 } */ -void GetXYForRightIconPlacement_FaceGera( FACETYPE *pFace, UINT16 ubIndex, INT16 sFaceX, INT16 sFaceY, INT16 *psX, INT16 *psY, INT8 bNumIcons , UINT32 uIDFaceGear, BOOLEAN isIMP) +void GetXYForRightIconPlacement_FaceGear(FACETYPE *pFace, UINT16 ubIndex, INT16 sFaceX, INT16 sFaceY, INT16 *psX, INT16 *psY, INT8 bNumIcons, UINT32 uiFaceGearIndex, UINT32 uiFaceShade) { INT16 sX, sY; UINT16 usWidth, usHeight; - ETRLEObject *pTrav; - HVOBJECT hVObject; + ETRLEObject *pTrav; + HVOBJECT hVObject = nullptr; // Get height, width of icon... - if (isIMP) - GetVideoObject( &hVObject, zNewFaceGearIMP[uIDFaceGear].uiIndex ); - else - GetVideoObject( &hVObject, zNewFaceGear[uIDFaceGear].uiIndex ); - - pTrav = &(hVObject->pETRLEObject[ ubIndex ] ); - usHeight = pTrav->usHeight; - usWidth = pTrav->usWidth; + if (GetVideoObject(&hVObject, uiFaceGearIndex)) + { + SetPalettes(&hVObject, uiFaceGearIndex); + } - sX = sFaceX + ( usWidth * bNumIcons ); + SetObjectShade(hVObject, uiFaceShade); + + pTrav = &(hVObject->pETRLEObject[ubIndex]); + usHeight = pTrav->usHeight; + usWidth = pTrav->usWidth; + + sX = sFaceX + (usWidth * bNumIcons); sY = sFaceY + pFace->usFaceHeight - usHeight; *psX = sX; *psY = sY; } -void DoRightIcon_FaceGear( UINT32 uiRenderBuffer, FACETYPE *pFace, INT16 sFaceX, INT16 sFaceY, INT8 bNumIcons, UINT8 sIconIndex , UINT32 uIDFaceGear, BOOLEAN isIMP) +void DoRightIcon_FaceGear(UINT32 uiRenderBuffer, FACETYPE *pFace, INT16 sFaceX, INT16 sFaceY, INT8 bNumIcons, UINT8 sIconIndex, UINT32 uIDFaceGear, BOOLEAN isIMP, UINT32 uiFaceShade) { - INT16 sIconX, sIconY; + INT16 sIconX, sIconY; // Find X, y for placement - if (isIMP) { - GetXYForRightIconPlacement_FaceGera( pFace, sIconIndex, sFaceX, sFaceY, &sIconX, &sIconY, bNumIcons , uIDFaceGear,isIMP); - BltVideoObjectFromIndex( uiRenderBuffer, zNewFaceGearIMP[uIDFaceGear].uiIndex, sIconIndex, sIconX, sIconY, VO_BLT_SRCTRANSPARENCY, NULL ); + GetXYForRightIconPlacement_FaceGear(pFace, sIconIndex, sFaceX, sFaceY, &sIconX, &sIconY, bNumIcons, zNewFaceGearIMP[uIDFaceGear].uiIndex, uiFaceShade); + BltVideoObjectFromIndex(uiRenderBuffer, zNewFaceGearIMP[uIDFaceGear].uiIndex, sIconIndex, sIconX, sIconY, VO_BLT_SRCTRANSPARENCY, NULL); } else { - GetXYForRightIconPlacement_FaceGera( pFace, sIconIndex, sFaceX, sFaceY, &sIconX, &sIconY, bNumIcons , uIDFaceGear,isIMP); - BltVideoObjectFromIndex( uiRenderBuffer, zNewFaceGear[uIDFaceGear].uiIndex, sIconIndex, sIconX, sIconY, VO_BLT_SRCTRANSPARENCY, NULL ); + GetXYForRightIconPlacement_FaceGear(pFace, sIconIndex, sFaceX, sFaceY, &sIconX, &sIconY, bNumIcons, zNewFaceGear[uIDFaceGear].uiIndex, uiFaceShade); + BltVideoObjectFromIndex(uiRenderBuffer, zNewFaceGear[uIDFaceGear].uiIndex, sIconIndex, sIconX, sIconY, VO_BLT_SRCTRANSPARENCY, NULL); } } //---------------------------------------------------------------- @@ -1548,7 +1570,7 @@ void DoRightIcon( UINT32 uiRenderBuffer, FACETYPE *pFace, INT16 sFaceX, INT16 sF } -void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLEAN fUseExternBuffer, UINT32 uiBuffer, INT16 sFaceX, INT16 sFaceY, UINT16 usEyesX, UINT16 usEyesY ) +void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLEAN fUseExternBuffer, UINT32 uiBuffer, INT16 sFaceX, INT16 sFaceY, UINT16 usEyesX, UINT16 usEyesY, UINT32 uiFaceShade) { INT16 sIconX, sIconY; INT16 sIconIndex = -1; @@ -1612,6 +1634,190 @@ void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLE { pSoldier = MercPtrs[ pFace->ubSoldierID ]; + UINT8 faceProfileId = gMercProfiles[pSoldier->ubProfile].ubFaceIndex; + BOOLEAN isIMP = gMercProfiles[pSoldier->ubProfile].Type == PROFILETYPE_IMP; + + if (gGameSettings.fOptions[TOPTION_SHOW_TACTICAL_FACE_GEAR] && MercPtrs[pFace->ubSoldierID]->stats.bLife > 0 && !(pFace->uiFlags & FACE_BIGFACE)) + { + if (MercPtrs[pFace->ubSoldierID]->inv[HELMETPOS].usItem > 0) + { + uiFaceItemOne = MercPtrs[pFace->ubSoldierID]->inv[HELMETPOS].usItem; + + if (uiFaceItemOne != NONE && zNewFaceGear[uiFaceItemOne].Type == 1) //back + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceItemOne, isIMP, uiFaceShade); + } + } + + // this section chooses the pictures for gas mask and NV goggles if the ini setting "SHOW_TACTICAL_FACE_GEAR" is TRUE + // and the merc actually wears something to be shown + if (MercPtrs[pFace->ubSoldierID]->inv[HEAD1POS].usItem + MercPtrs[pFace->ubSoldierID]->inv[HEAD2POS].usItem > 0) + { + // WANNE: Removed the limitation + // silversurfer: don't overwrite icons if they shall be shown! + //if ( !gGameSettings.fOptions[ SHOW_TACTICAL_FACE_ICONS ] ) + { + uiFaceItemOne = MercPtrs[pFace->ubSoldierID]->inv[HEAD1POS].usItem; + uiFaceItemTwo = MercPtrs[pFace->ubSoldierID]->inv[HEAD2POS].usItem; + + uiFaceOne = MercPtrs[pFace->ubSoldierID]->inv[HEAD1POS].usItem; + uiFaceTwo = MercPtrs[pFace->ubSoldierID]->inv[HEAD2POS].usItem; + + // check first face slot + if (uiFaceItemOne != NONE) + { + if (zNewFaceGear[uiFaceOne].Type == 3) + { + uiFaceItemOne = 1; + } + else if (zNewFaceGear[uiFaceOne].Type == 4) + { + uiFaceItemOne = 2; + } + else uiFaceItemOne = 0; + } + + // check second face slot + if (uiFaceItemTwo != NONE) + { + if (zNewFaceGear[uiFaceTwo].Type == 3) + { + uiFaceItemTwo = 21; + } + else if (zNewFaceGear[uiFaceTwo].Type == 4) + { + uiFaceItemTwo = 42; + } + else uiFaceItemTwo = 0; + } + + + // Now select the correct picture. This uses a matrix from uiFaceOneItem and uiFaceTwoItem (simple addition) + // the numbers on the outer border are used if that is the only item worn in that slot + // + // 21 42 63 84 + // face slot 1 \ slot 2 gas mask | NV goggles | sun goggles | extended ear + // 1 gas mask -- 43 64 85 + // 2 NV goggles 23 -- -- 86 + // 3 sun goggles 24 -- -- 87 + // 4 extended ear 25 46 67 -- + // + // this matrix leaves room for expansion + // we only need a few of the matrix' values this time because we only show gas mask or NV goggles pictures + ubFaceItemsCombined = uiFaceItemOne + uiFaceItemTwo; + } + + // WANNE: Removed silversurfers limitation, because it is too complex for the players :) + // silversurfer: we don't want to display icons for gas mask or NV goggles because you can actually see the merc wearing the gear + // in case of gas mask together with NV we display the picture of the item in face slot 1 and the icon of the item + // in face slot 2 (if icons are allowed) + + //Type : 3 - gas mask ; 4 - NV googles + // gas mask only + + if (ubFaceItemsCombined == 1 || ubFaceItemsCombined == 21) + { + if (zNewFaceGear[uiFaceOne].Type == 3) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP, uiFaceShade); + } + else if (zNewFaceGear[uiFaceTwo].Type == 3) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP, uiFaceShade); + } + } + + // NV goggles only + if (ubFaceItemsCombined == 2 || ubFaceItemsCombined == 42) + { + if (zNewFaceGear[uiFaceOne].Type == 4) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP, uiFaceShade); + } + else if (zNewFaceGear[uiFaceTwo].Type == 4) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP, uiFaceShade); + } + } + + // NV goggles + gas mask + if (ubFaceItemsCombined == 23) + { + if (zNewFaceGear[uiFaceOne].Type == 4 && zNewFaceGear[uiFaceTwo].Type == 3) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP, uiFaceShade); + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP, uiFaceShade); + } + } + + // gas mask + NV goggles + if (ubFaceItemsCombined == 43) + { + if (zNewFaceGear[uiFaceOne].Type == 3 && zNewFaceGear[uiFaceTwo].Type == 4) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP, uiFaceShade); + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP, uiFaceShade); + } + } + + // gas mask + extended ear + if (ubFaceItemsCombined == 24 || ubFaceItemsCombined == 64) + { + if (zNewFaceGear[uiFaceOne].Type == 3) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP, uiFaceShade); + } + else if (zNewFaceGear[uiFaceTwo].Type == 3) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP, uiFaceShade); + } + } + + // gas mask + extended ear + if (ubFaceItemsCombined == 25 || ubFaceItemsCombined == 85) + { + if (zNewFaceGear[uiFaceOne].Type == 3) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP, uiFaceShade); + } + else if (zNewFaceGear[uiFaceTwo].Type == 3) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP, uiFaceShade); + } + } + + // NV goggles + extended ear + if (ubFaceItemsCombined == 46 || ubFaceItemsCombined == 86) + { + if (zNewFaceGear[uiFaceOne].Type == 4) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP, uiFaceShade); + } + else if (zNewFaceGear[uiFaceTwo].Type == 4) + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP, uiFaceShade); + } + } + } + + if (MercPtrs[pFace->ubSoldierID]->inv[HELMETPOS].usItem > 0) + // dirty hack for IMPs because they don't have pictures for face gear + // && ( MercPtrs[ pFace->ubSoldierID ]->ubProfile < 51 || MercPtrs[ pFace->ubSoldierID ]->ubProfile > 56 ) + { + uiFaceItemOne = MercPtrs[pFace->ubSoldierID]->inv[HELMETPOS].usItem; + + if (uiFaceItemOne != NONE) + { + if (uiFaceItemOne != NONE && zNewFaceGear[uiFaceItemOne].Type == 2) //front + { + DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceItemOne, isIMP, uiFaceShade); + } + } + } + + //------------------------------------end of tactical face gear----------------------------- + } + if ( (MercPtrs[pFace->ubSoldierID]->stats.bLife < CONSCIOUSNESS || MercPtrs[pFace->ubSoldierID]->flags.fDeadPanel ) ) { // Blit Closed eyes here! @@ -1707,34 +1913,6 @@ void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLE // Blit hatch! BltVideoObjectFromIndex( uiRenderBuffer, guiHATCH, 0, sFaceX, sFaceY, VO_BLT_SRCTRANSPARENCY, NULL ); } - - if ( !pFace->fDisabled && !pFace->fInvalidAnim ) - { - // Render text above here if that's what was asked for - if ( pFace->fDisplayTextOver != FACE_NO_TEXT_OVER ) - { - SetFont( TINYFONT1 ); - SetFontBackground( FONT_MCOLOR_BLACK ); - SetFontForeground( FONT_MCOLOR_WHITE ); - - SetFontDestBuffer( uiRenderBuffer, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE ); - - VarFindFontCenterCoordinates( sFaceX, sFaceY, pFace->usFaceWidth, pFace->usFaceHeight, TINYFONT1, &sFontX, &sFontY, pFace->zDisplayText ); - - if ( pFace->fDisplayTextOver == FACE_DRAW_TEXT_OVER ) - { - gprintfinvalidate( sFontX, sFontY, pFace->zDisplayText ); - mprintf( sFontX, sFontY, pFace->zDisplayText ); - } - else if ( pFace->fDisplayTextOver == FACE_ERASE_TEXT_OVER ) - { - gprintfRestore( sFontX, sFontY, pFace->zDisplayText ); - pFace->fDisplayTextOver = FACE_NO_TEXT_OVER; - } - - SetFontDestBuffer( FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE ); - } - } } // sevenfm: only show for alive soldiers, no face icons for big faces @@ -1760,15 +1938,6 @@ void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLE //------------------------------------Legion 2 by jazz-------------------------------- - UINT8 faceProfileId = gMercProfiles[MercPtrs[pFace->ubSoldierID]->ubProfile].ubFaceIndex; - BOOLEAN isIMP = FALSE; - - //IMP - if (gMercProfiles[MercPtrs[pFace->ubSoldierID]->ubProfile].Type == PROFILETYPE_IMP) - { - isIMP = TRUE; - } - // rewritten by silversurfer // this section chooses the icons for face gear if the ini setting "SHOW_TACTICAL_FACE_ICONS" is TRUE // and the merc actually wears something to be shown @@ -1883,187 +2052,6 @@ void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLE } } - if (gGameSettings.fOptions[TOPTION_SHOW_TACTICAL_FACE_GEAR]) - { - if (MercPtrs[pFace->ubSoldierID]->inv[HELMETPOS].usItem > 0) - { - uiFaceItemOne = MercPtrs[pFace->ubSoldierID]->inv[HELMETPOS].usItem; - - if (uiFaceItemOne != NONE && zNewFaceGear[uiFaceItemOne].Type == 1) //back - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceItemOne, isIMP); - } - } - - // this section chooses the pictures for gas mask and NV goggles if the ini setting "SHOW_TACTICAL_FACE_GEAR" is TRUE - // and the merc actually wears something to be shown - if (MercPtrs[pFace->ubSoldierID]->inv[HEAD1POS].usItem + MercPtrs[pFace->ubSoldierID]->inv[HEAD2POS].usItem > 0) - { - // WANNE: Removed the limitation - // silversurfer: don't overwrite icons if they shall be shown! - //if ( !gGameSettings.fOptions[ SHOW_TACTICAL_FACE_ICONS ] ) - { - uiFaceItemOne = MercPtrs[pFace->ubSoldierID]->inv[HEAD1POS].usItem; - uiFaceItemTwo = MercPtrs[pFace->ubSoldierID]->inv[HEAD2POS].usItem; - - uiFaceOne = MercPtrs[pFace->ubSoldierID]->inv[HEAD1POS].usItem; - uiFaceTwo = MercPtrs[pFace->ubSoldierID]->inv[HEAD2POS].usItem; - - // check first face slot - if (uiFaceItemOne != NONE) - { - if (zNewFaceGear[uiFaceOne].Type == 3) - { - uiFaceItemOne = 1; - } - else if (zNewFaceGear[uiFaceOne].Type == 4) - { - uiFaceItemOne = 2; - } - else uiFaceItemOne = 0; - } - - // check second face slot - if (uiFaceItemTwo != NONE) - { - if (zNewFaceGear[uiFaceTwo].Type == 3) - { - uiFaceItemTwo = 21; - } - else if (zNewFaceGear[uiFaceTwo].Type == 4) - { - uiFaceItemTwo = 42; - } - else uiFaceItemTwo = 0; - } - - - // Now select the correct picture. This uses a matrix from uiFaceOneItem and uiFaceTwoItem (simple addition) - // the numbers on the outer border are used if that is the only item worn in that slot - // - // 21 42 63 84 - // face slot 1 \ slot 2 gas mask | NV goggles | sun goggles | extended ear - // 1 gas mask -- 43 64 85 - // 2 NV goggles 23 -- -- 86 - // 3 sun goggles 24 -- -- 87 - // 4 extended ear 25 46 67 -- - // - // this matrix leaves room for expansion - // we only need a few of the matrix' values this time because we only show gas mask or NV goggles pictures - ubFaceItemsCombined = uiFaceItemOne + uiFaceItemTwo; - } - - // WANNE: Removed silversurfers limitation, because it is too complex for the players :) - // silversurfer: we don't want to display icons for gas mask or NV goggles because you can actually see the merc wearing the gear - // in case of gas mask together with NV we display the picture of the item in face slot 1 and the icon of the item - // in face slot 2 (if icons are allowed) - - //Type : 3 - gas mask ; 4 - NV googles - // gas mask only - - if (ubFaceItemsCombined == 1 || ubFaceItemsCombined == 21) - { - if (zNewFaceGear[uiFaceOne].Type == 3) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP); - } - else if (zNewFaceGear[uiFaceTwo].Type == 3) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP); - } - } - - // NV goggles only - if (ubFaceItemsCombined == 2 || ubFaceItemsCombined == 42) - { - if (zNewFaceGear[uiFaceOne].Type == 4) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP); - } - else if (zNewFaceGear[uiFaceTwo].Type == 4) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP); - } - } - - // NV goggles + gas mask - if (ubFaceItemsCombined == 23) - { - if (zNewFaceGear[uiFaceOne].Type == 4 && zNewFaceGear[uiFaceTwo].Type == 3) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP); - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP); - } - } - - // gas mask + NV goggles - if (ubFaceItemsCombined == 43) - { - if (zNewFaceGear[uiFaceOne].Type == 3 && zNewFaceGear[uiFaceTwo].Type == 4) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP); - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP); - } - } - - // gas mask + extended ear - if (ubFaceItemsCombined == 24 || ubFaceItemsCombined == 64) - { - if (zNewFaceGear[uiFaceOne].Type == 3) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP); - } - else if (zNewFaceGear[uiFaceTwo].Type == 3) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP); - } - } - - // gas mask + extended ear - if (ubFaceItemsCombined == 25 || ubFaceItemsCombined == 85) - { - if (zNewFaceGear[uiFaceOne].Type == 3) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP); - } - else if (zNewFaceGear[uiFaceTwo].Type == 3) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP); - } - } - - // NV goggles + extended ear - if (ubFaceItemsCombined == 46 || ubFaceItemsCombined == 86) - { - if (zNewFaceGear[uiFaceOne].Type == 4) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceOne, isIMP); - } - else if (zNewFaceGear[uiFaceTwo].Type == 4) - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceTwo, isIMP); - } - } - } - - if (MercPtrs[pFace->ubSoldierID]->inv[HELMETPOS].usItem > 0) - // dirty hack for IMPs because they don't have pictures for face gear - // && ( MercPtrs[ pFace->ubSoldierID ]->ubProfile < 51 || MercPtrs[ pFace->ubSoldierID ]->ubProfile > 56 ) - { - uiFaceItemOne = MercPtrs[pFace->ubSoldierID]->inv[HELMETPOS].usItem; - - if (uiFaceItemOne != NONE) - { - if (uiFaceItemOne != NONE && zNewFaceGear[uiFaceItemOne].Type == 2) //front - { - DoRightIcon_FaceGear(uiRenderBuffer, pFace, sFaceX, sFaceY, bNumRightIcons_legion, faceProfileId, uiFaceItemOne, isIMP); - } - } - } - - //------------------------------------end of tactical face gear----------------------------- - } - // If blind... if (MercPtrs[pFace->ubSoldierID]->bBlindedCounter > 0) { @@ -2542,6 +2530,37 @@ void HandleRenderFaceAdjustments( FACETYPE *pFace, BOOLEAN fDisplayBuffer, BOOLE } } } + + if (!(pFace->uiFlags & FACE_INACTIVE_HANDLED_ELSEWHERE) || fUseExternBuffer) + { + if (!pFace->fDisabled && !pFace->fInvalidAnim) + { + // Render text above here if that's what was asked for + if (pFace->fDisplayTextOver != FACE_NO_TEXT_OVER) + { + SetFont(TINYFONT1); + SetFontBackground(FONT_MCOLOR_BLACK); + SetFontForeground(FONT_MCOLOR_WHITE); + + SetFontDestBuffer(uiRenderBuffer, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE); + + VarFindFontCenterCoordinates(sFaceX, sFaceY, pFace->usFaceWidth, pFace->usFaceHeight, TINYFONT1, &sFontX, &sFontY, pFace->zDisplayText); + + if (pFace->fDisplayTextOver == FACE_DRAW_TEXT_OVER) + { + gprintfinvalidate(sFontX, sFontY, pFace->zDisplayText); + mprintf(sFontX, sFontY, pFace->zDisplayText); + } + else if (pFace->fDisplayTextOver == FACE_ERASE_TEXT_OVER) + { + gprintfRestore(sFontX, sFontY, pFace->zDisplayText); + pFace->fDisplayTextOver = FACE_NO_TEXT_OVER; + } + + SetFontDestBuffer(FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE); + } + } + } } else { @@ -2601,10 +2620,13 @@ BOOLEAN RenderAutoFace( INT32 iFaceIndex ) // Check for disabled guy! CHECKF( pFace->fDisabled != TRUE ); + UINT32 uiFaceShade = FLASH_PORTRAIT_NOSHADE; + // Set shade if ( pFace->ubSoldierID != NOBODY ) { - SetFaceShade( MercPtrs[ pFace->ubSoldierID ], pFace, FALSE ); + uiFaceShade = GetFaceShade(MercPtrs[pFace->ubSoldierID], pFace, FALSE); + SetFaceShade(pFace, uiFaceShade); } // Blit face to save buffer! @@ -2620,7 +2642,7 @@ BOOLEAN RenderAutoFace( INT32 iFaceIndex ) } } - HandleRenderFaceAdjustments( pFace, FALSE, FALSE, 0, pFace->usFaceX, pFace->usFaceY, pFace->usEyesX, pFace->usEyesY ); + HandleRenderFaceAdjustments(pFace, FALSE, FALSE, 0, pFace->usFaceX, pFace->usFaceY, pFace->usEyesX, pFace->usEyesY, uiFaceShade); // Restore extern rect if ( pFace->uiAutoRestoreBuffer == guiSAVEBUFFER ) @@ -2664,9 +2686,11 @@ BOOLEAN ExternRenderFace( UINT32 uiBuffer, INT32 iFaceIndex, INT16 sX, INT16 sY // Here, any face can be rendered, even if disabled // Set shade + UINT32 uiFaceShade = FLASH_PORTRAIT_NOSHADE; if ( pFace->ubSoldierID != NOBODY ) { - SetFaceShade( MercPtrs[ pFace->ubSoldierID ], pFace , TRUE ); + uiFaceShade = GetFaceShade(MercPtrs[pFace->ubSoldierID], pFace, TRUE); + SetFaceShade(pFace, uiFaceShade); } // Blit face to save buffer! @@ -2674,7 +2698,7 @@ BOOLEAN ExternRenderFace( UINT32 uiBuffer, INT32 iFaceIndex, INT16 sX, INT16 sY GetFaceRelativeCoordinates( pFace, &usEyesX, &usEyesY, &usMouthX, &usMouthY ); - HandleRenderFaceAdjustments( pFace, FALSE, TRUE, uiBuffer, sX, sY, ( UINT16)( sX + usEyesX ), ( UINT16)( sY + usEyesY ) ); + HandleRenderFaceAdjustments(pFace, FALSE, TRUE, uiBuffer, sX, sY, (UINT16)(sX + usEyesX), ( UINT16)(sY + usEyesY), uiFaceShade); // Restore extern rect if ( uiBuffer == guiSAVEBUFFER ) From b68f206969e14c03a9c7deac2a45d84375a6fafa Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Sat, 7 Oct 2023 08:29:59 -0300 Subject: [PATCH 02/16] remove annoying warning on MSVC 19.37.32822 `register` keyword does exactly nothing: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5033?view=msvc-170 --- Tactical/BinaryHeap.hpp | 6 +++--- Tactical/DisplayCover.cpp | 16 ++++++++-------- Tactical/Items.cpp | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Tactical/BinaryHeap.hpp b/Tactical/BinaryHeap.hpp index 8d1697fe8..c4b5df1ba 100644 --- a/Tactical/BinaryHeap.hpp +++ b/Tactical/BinaryHeap.hpp @@ -102,7 +102,7 @@ public: return (returnHeap); } - int moveUp(register int index, KEY newKey) + int moveUp(int index, KEY newKey) { while (index > 1) { int current2 = index>>1;//divided by 2 @@ -120,7 +120,7 @@ public: int moveDown(int index, KEY currentKey) { - register int current2 = index+index; + int current2 = index+index; while (current2 < heapCount) { if (current2+1 < heapCount) { //choose child to possibly move @@ -314,7 +314,7 @@ insert: int findData(const T data) const { - register int current; + int current; for (current = heapCount-1; current > 0; --current) { if (BinaryHeap[current].data == data) { break; diff --git a/Tactical/DisplayCover.cpp b/Tactical/DisplayCover.cpp index 3d35841d9..7d1a36764 100644 --- a/Tactical/DisplayCover.cpp +++ b/Tactical/DisplayCover.cpp @@ -373,7 +373,7 @@ BOOLEAN HasAdjTile( const INT32& ubX, const INT32& ubY, const INT32& ubZ ) void AddCoverObjectsToViewArea() { - register INT32 ubX, ubY, ubZ; + INT32 ubX, ubY, ubZ; BOOLEAN fChanged = FALSE; BOOLEAN fNightTime = NightTime( ); @@ -406,7 +406,7 @@ void RemoveCoverObjectsFromViewArea() return; // Go through the whole gCoverViewArea when removing cover objects. Otherwise we don't clean up tiles that are not in the viewport which results in an annoying visual bug. - register INT32 ubX, ubY, ubZ; + INT32 ubX, ubY, ubZ; BOOLEAN fChanged = FALSE; for ( ubX = 0; ubX < COVER_X_CELLS; ++ubX ) @@ -669,8 +669,8 @@ static void CalculateCoverFromEnemies() void CalculateCover() { - register INT32 ubX, ubY; - register INT8 ubZ; + INT32 ubX, ubY; + INT8 ubZ; SOLDIERTYPE* pSoldier; if (gusSelectedSoldier == NOBODY) @@ -1144,7 +1144,7 @@ void AddMinesObjectsToViewArea() if ( gsMaxCellY < 0 ) return; - register INT32 ubX, ubY, ubZ; + INT32 ubX, ubY, ubZ; BOOLEAN fChanged = FALSE; BOOLEAN fNightTime = NightTime( ); @@ -1503,7 +1503,7 @@ void AddTraitObjectsToViewArea() if ( gsMaxCellY < 0 ) return; - register INT32 ubX, ubY, ubZ; + INT32 ubX, ubY, ubZ; BOOLEAN fChanged = FALSE; BOOLEAN fNightTime = NightTime( ); @@ -1657,7 +1657,7 @@ void AddTrackerObjectsToViewArea( ) if ( gsMaxCellY < 0 ) return; - register INT32 ubX, ubY, ubZ; + INT32 ubX, ubY, ubZ; BOOLEAN fChanged = FALSE; BOOLEAN fNightTime = NightTime(); @@ -1731,7 +1731,7 @@ void CalculateFortify( ) if ( gsMaxCellY < 0 ) return; - register INT32 ubX, ubY, ubZ; + INT32 ubX, ubY, ubZ; BOOLEAN fChanged = FALSE; BOOLEAN fNightTime = NightTime( ); diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 8212c736d..e61c326cb 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -15271,7 +15271,7 @@ BOOLEAN HasItemFlag( UINT16 usItem, UINT64 aFlag ) // Flugente: get first item number that has this flag. Use with caution, as we search in all items BOOLEAN GetFirstItemWithFlag( UINT16* pusItem, UINT64 aFlag ) { - register UINT16 i; + UINT16 i; for ( i = 1; i < gMAXITEMS_READ; ++i ) { if ( HasItemFlag(i, aFlag) ) @@ -15537,7 +15537,7 @@ BOOLEAN GetFirstClothesItemWithSpecificData( UINT16* pusItem, PaletteRepID aPalV UINT32 bestclothestype = 999999; UINT16 bestitem = 0; - register UINT16 i; + UINT16 i; for ( i = 1; i < gMAXITEMS_READ; ++i ) { if ( Item[i].clothestype > 0 ) From b8a870df02183b89ce8e5ead39e1248f24ac20f4 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 7 Oct 2023 15:14:15 +0300 Subject: [PATCH 03/16] Reduce code duplication (#233) * Use ConvertGridNoToCenterCellXY instead of CenterX & CenterY * Add direction utility function We have a lot of places in the code that calculate direction based on center cell coordinates, but lack a utility function for it similar to other direction methods. * Use utility function for calculating direction * Use ConvertGridNoToCenterCellXY * Use utility function for direction * Use ConvertGridNoToCenterCellXY instead of CenterX & CenterY * Use ConvertGridNoToCenterCellXY instead of CenterX & CenterY * Remove CenterX & CenterY functions Use ConvertGridNoToCenterCellXY instead * Remove CenterX & CenterY calls from UB configuration * Address review feedback * Remove duplicate function ConvertGridNoToCenterCellXY and ConvertMapPosToWorldTileCenter do the exact same thing * Use PythSpacesAway instead of GetRangeFromGridNoDiff Both functions calculate the same thing * Remove GetRangeFromGridNoDiff * Remove calls to abs() The values end up being squared anyways making these unnecessary --- Multiplayer/client.cpp | 11 +- Strategic/Strategic Movement.cpp | 24 ++--- Strategic/strategicmap.cpp | 4 +- Tactical/Air Raid.cpp | 22 ++-- Tactical/Handle Items.cpp | 5 +- Tactical/Handle UI.cpp | 4 +- Tactical/Interface Dialogue.cpp | 14 ++- Tactical/Interface Items.cpp | 2 +- Tactical/Interface.cpp | 14 +-- Tactical/Items.cpp | 11 +- Tactical/Keys.cpp | 7 +- Tactical/LOS.cpp | 151 ++++++++++++++++------------ Tactical/Rotting Corpses.cpp | 14 +-- Tactical/ShopKeeper Interface.cpp | 4 +- Tactical/Soldier Add.cpp | 33 ++---- Tactical/Soldier Ani.cpp | 5 +- Tactical/Soldier Control.cpp | 55 ++++++---- Tactical/Soldier Control.h | 3 +- Tactical/Soldier Find.cpp | 28 +++--- Tactical/Soldier Tile.cpp | 3 +- Tactical/Tactical Save.cpp | 21 ++-- Tactical/UI Cursors.cpp | 24 +++-- Tactical/Vehicles.cpp | 8 +- Tactical/Weapons.cpp | 77 +++++++++----- Tactical/opplist.cpp | 10 +- TacticalAI/AIUtils.cpp | 12 +-- TacticalAI/Attacks.cpp | 9 +- TacticalAI/CreatureDecideAction.cpp | 6 +- TacticalAI/DecideAction.cpp | 54 +++++----- TileEngine/Explosion Control.cpp | 35 +++++-- TileEngine/Isometric Utils.cpp | 67 +----------- TileEngine/Isometric Utils.h | 13 +-- TileEngine/LightEffects.cpp | 5 +- TileEngine/SmokeEffects.cpp | 8 +- TileEngine/environment.cpp | 4 +- TileEngine/physics.cpp | 2 +- TileEngine/renderworld.cpp | 2 +- 37 files changed, 389 insertions(+), 382 deletions(-) diff --git a/Multiplayer/client.cpp b/Multiplayer/client.cpp index d66e0f8b8..05803259d 100644 --- a/Multiplayer/client.cpp +++ b/Multiplayer/client.cpp @@ -815,10 +815,8 @@ void recievePATH(RPCParameters *rpcParameters) SendGetNewSoldierPathEvent( pSoldier, SNetPath->sDestGridNo, SNetPath->ubNewState ); INT16 sCellX, sCellY; - - sCellX = CenterX( SNetPath->sAtGridNo ); - sCellY = CenterY( SNetPath->sAtGridNo ); - + ConvertGridNoToCenterCellXY(SNetPath->sAtGridNo, &sCellX, &sCellY); + if (( gAnimControl[ pSoldier->usAnimState ].uiFlags & ( ANIM_MOVING | ANIM_SPECIALMOVE ) ) && !(pSoldier->flags.fNoAPToFinishMove ) ) { } @@ -4251,8 +4249,7 @@ void UpdateSoldierFromNetwork (RPCParameters *rpcParameters) pSoldier->stats.bLife=SUpdateNetworkSoldier->bLife; INT16 sCellX, sCellY; - sCellX = CenterX( SUpdateNetworkSoldier->sAtGridNo ); - sCellY = CenterY( SUpdateNetworkSoldier->sAtGridNo ); + ConvertGridNoToCenterCellXY(SUpdateNetworkSoldier->sAtGridNo, &sCellX, &sCellY); if( pSoldier->sGridNo != SUpdateNetworkSoldier->sAtGridNo) { @@ -5281,4 +5278,4 @@ void ChatCallback( UINT8 ubResult ) void OpenChatMsgBox( void ) { DoChatBox((guiCurrentScreen == GAME_SCREEN? true : false),gzMPChatboxText[1],guiCurrentScreen,ChatCallback,NULL); -} \ No newline at end of file +} diff --git a/Strategic/Strategic Movement.cpp b/Strategic/Strategic Movement.cpp index cbabfed6e..e8969d4f0 100644 --- a/Strategic/Strategic Movement.cpp +++ b/Strategic/Strategic Movement.cpp @@ -1757,30 +1757,30 @@ void AddCorpsesToBloodcatLair( INT16 sSectorX, INT16 sSectorY ) Corpse.usFlags = ROTTING_CORPSE_FIND_SWEETSPOT_FROM_GRIDNO; // 1st gridno - Corpse.sGridNo = 14319; //dnl!!! - ConvertGridNoToXY( Corpse.sGridNo, &sXPos, &sYPos ); - Corpse.dXPos = (FLOAT)( CenterX( sXPos ) ); - Corpse.dYPos = (FLOAT)( CenterY( sYPos ) ); + Corpse.sGridNo = 14319; //dnl!!! + ConvertGridNoToCenterCellXY(Corpse.sGridNo, &sXPos, &sYPos); + Corpse.dXPos = (FLOAT)( sXPos ); + Corpse.dYPos = (FLOAT)( sYPos ); //Add the rotting corpse info to the sectors unloaded rotting corpse file AddRottingCorpseToUnloadedSectorsRottingCorpseFile( sSectorX, sSectorY, 0, &Corpse); // 2nd gridno - Corpse.sGridNo = 9835; //dnl!!! - ConvertGridNoToXY( Corpse.sGridNo, &sXPos, &sYPos ); - Corpse.dXPos = (FLOAT)( CenterX( sXPos ) ); - Corpse.dYPos = (FLOAT)( CenterY( sYPos ) ); + Corpse.sGridNo = 9835; //dnl!!! + ConvertGridNoToCenterCellXY(Corpse.sGridNo, &sXPos, &sYPos); + Corpse.dXPos = (FLOAT)(sXPos); + Corpse.dYPos = (FLOAT)(sYPos); //Add the rotting corpse info to the sectors unloaded rotting corpse file AddRottingCorpseToUnloadedSectorsRottingCorpseFile( sSectorX, sSectorY, 0, &Corpse); // 3rd gridno - Corpse.sGridNo = 11262; //dnl!!! - ConvertGridNoToXY( Corpse.sGridNo, &sXPos, &sYPos ); - Corpse.dXPos = (FLOAT)( CenterX( sXPos ) ); - Corpse.dYPos = (FLOAT)( CenterY( sYPos ) ); + Corpse.sGridNo = 11262; //dnl!!! + ConvertGridNoToCenterCellXY(Corpse.sGridNo, &sXPos, &sYPos); + Corpse.dXPos = (FLOAT)(sXPos); + Corpse.dYPos = (FLOAT)(sYPos); //Add the rotting corpse info to the sectors unloaded rotting corpse file AddRottingCorpseToUnloadedSectorsRottingCorpseFile( sSectorX, sSectorY, 0, &Corpse); diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index e1dd54c47..9fa2cff67 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -4773,8 +4773,8 @@ void DoneFadeOutAdjacentSector( ) curr->pSoldier->ubWaitActionToDo = 1; // OK, here we have been given a position, a gridno has been given to use as well.... sOldGridNo = curr->pSoldier->sGridNo; - sWorldX = CenterX( sGridNo ); - sWorldY = CenterY( sGridNo ); + ConvertGridNoToCenterCellXY(sGridNo, &sWorldX, &sWorldY); + curr->pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY ); if ( sGridNo != sOldGridNo ) { diff --git a/Tactical/Air Raid.cpp b/Tactical/Air Raid.cpp index 20ede367c..120ad3d79 100644 --- a/Tactical/Air Raid.cpp +++ b/Tactical/Air Raid.cpp @@ -352,9 +352,8 @@ INT32 PickRandomLocationAtMinSpacesAway( INT32 sGridNo, INT16 sMinValue, INT16 s DebugMsg(TOPIC_JA2,DBG_LEVEL_3,"PickRandomLocationAtMinSpacesAway"); - sX = CenterX( sGridNo ); - sY = CenterY( sGridNo ); - + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + while(TileIsOutOfBounds(sNewGridNo)) { sNewX = sX + sMinValue + (INT16)Random( sRandomVar ); @@ -596,8 +595,7 @@ void BeginBombing( ) sGridNo = PickRandomLocationAtMinSpacesAway( gsDiveTargetLocation , 300, 200 ); // Save X, y: - gsDiveX = CenterX( sGridNo ); - gsDiveY = CenterY( sGridNo ); + ConvertGridNoToCenterCellXY(sGridNo, &gsDiveX, &gsDiveY); RESETTIMECOUNTER( giTimerAirRaidUpdate, RAID_DELAY ); @@ -657,8 +655,7 @@ void BeginDive( ) sGridNo = PickRandomLocationAtMinSpacesAway( gsDiveTargetLocation, 300, 200 ); // Save X, y: - gsDiveX = CenterX( sGridNo ); - gsDiveY = CenterY( sGridNo ); + ConvertGridNoToCenterCellXY(sGridNo, &gsDiveX, &gsDiveY); RESETTIMECOUNTER( giTimerAirRaidUpdate, RAID_DELAY ); giNumTurnsSinceDiveStarted = 0; @@ -760,8 +757,7 @@ void DoDive( ) DebugMsg(TOPIC_JA2,DBG_LEVEL_3,"DoDive: move towards target"); // Move Towards target.... - sTargetX = CenterX( gsDiveTargetLocation ); - sTargetY = CenterY( gsDiveTargetLocation ); + ConvertGridNoToCenterCellXY(gsDiveTargetLocation, &sTargetX, &sTargetY); // Determine deltas dDeltaX = (FLOAT)( sTargetX - gsDiveX ); @@ -886,7 +882,7 @@ void DoBombing( ) INT16 sRange; INT32 sGridNo, sOldGridNo, sBombGridNo; - INT16 sTargetX, sTargetY; + INT16 sTargetX, sTargetY, sBombX, sBombY; UINT16 usItem; INT16 sStrafeX, sStrafeY; FLOAT dDeltaX, dDeltaY, dAngle, dDeltaXPos, dDeltaYPos; @@ -933,8 +929,7 @@ void DoBombing( ) RESETTIMECOUNTER( giTimerAirRaidUpdate, RAID_DELAY ); // Move Towards target.... - sTargetX = CenterX( gsDiveTargetLocation ); - sTargetY = CenterY( gsDiveTargetLocation ); + ConvertGridNoToCenterCellXY(gsDiveTargetLocation, &sTargetX, &sTargetY); // Determine deltas dDeltaX = (FLOAT)( sTargetX - gsDiveX ); @@ -1002,7 +997,8 @@ void DoBombing( ) } // Drop bombs... - InternalIgniteExplosion( NOBODY, CenterX( sBombGridNo ), CenterY( sBombGridNo ), 0, sBombGridNo, usItem, fLocate , (UINT8)IsRoofPresentAtGridNo( sBombGridNo ) ); + ConvertGridNoToCenterCellXY(sBombGridNo, &sBombX, &sBombY); + InternalIgniteExplosion( NOBODY, sBombX, sBombY, 0, sBombGridNo, usItem, fLocate , (UINT8)IsRoofPresentAtGridNo( sBombGridNo ) ); } diff --git a/Tactical/Handle Items.cpp b/Tactical/Handle Items.cpp index a865d7031..6eb448ad8 100644 --- a/Tactical/Handle Items.cpp +++ b/Tactical/Handle Items.cpp @@ -2187,7 +2187,7 @@ void HandleSoldierThrowItem( SOLDIERTYPE *pSoldier, INT32 sGridNo ) pSoldier->usPendingAnimation = LOB_ITEM; } // Draw item depending on distance from buddy - else if ( GetRangeFromGridNoDiff( sGridNo, pSoldier->sGridNo ) < MIN_LOB_RANGE ) + else if (PythSpacesAway( sGridNo, pSoldier->sGridNo ) < MIN_LOB_RANGE ) { //ddd maybe need to add check for throwing item class - grenade if( (pSoldier->pThrowParams->ubActionCode == THROW_ARM_ITEM) && @@ -5919,8 +5919,7 @@ void SetOffBoobyTrap( ITEM_POOL * pItemPool ) if ( pItemPool ) { INT16 sX, sY; - sX = CenterX( pItemPool->sGridNo ); - sY = CenterY( pItemPool->sGridNo ); + ConvertGridNoToCenterCellXY(pItemPool->sGridNo, &sX, &sY); IgniteExplosion( NOBODY, sX, sY, (INT16) (gpWorldLevelData[pItemPool->sGridNo].sHeight + pItemPool->bRenderZHeightAboveLevel), pItemPool->sGridNo, MINI_GRENADE, 0 ); RemoveItemFromPool( pItemPool->sGridNo, pItemPool->iItemIndex, pItemPool->ubLevel ); } diff --git a/Tactical/Handle UI.cpp b/Tactical/Handle UI.cpp index 86a50e133..e42433812 100644 --- a/Tactical/Handle UI.cpp +++ b/Tactical/Handle UI.cpp @@ -5619,7 +5619,7 @@ UINT32 UIHandleTOnTerrain( UI_EVENT *pUIEvent ) sTargetGridNo = MercPtrs[ ubTargID ]->sGridNo; } - uiRange = GetRangeFromGridNoDiff( pSoldier->sGridNo, sTargetGridNo ); + uiRange = PythSpacesAway( pSoldier->sGridNo, sTargetGridNo ); if ( uiRange <= NPC_TALK_RADIUS ) @@ -6610,7 +6610,7 @@ BOOLEAN HandleTalkInit( ) } // Check distance - uiRange = GetRangeFromGridNoDiff( pSoldier->sGridNo, usMapPos ); + uiRange = PythSpacesAway( pSoldier->sGridNo, usMapPos ); // Double check path if ( GetCivType( pTSoldier ) != CIV_TYPE_NA ) diff --git a/Tactical/Interface Dialogue.cpp b/Tactical/Interface Dialogue.cpp index 00e4334aa..d805af376 100644 --- a/Tactical/Interface Dialogue.cpp +++ b/Tactical/Interface Dialogue.cpp @@ -1827,7 +1827,7 @@ void HandleNPCDoAction( UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum EXITGRID ExitGrid; INT32 iRandom = 0; UINT8 ubMineIndex; - + INT16 sX, sY, sX2, sY2; pSoldier2 = NULL; //ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Handling %s, action %d at %ld", gMercProfiles[ ubTargetNPC ].zNickname, usActionCode, GetJA2Clock() ); @@ -1840,7 +1840,9 @@ void HandleNPCDoAction( UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum if (pSoldier && pSoldier2) { // see if we are facing this person - ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(pSoldier2->sGridNo),CenterY(pSoldier2->sGridNo)); + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(pSoldier2->sGridNo, &sX2, &sY2); + ubDesiredMercDir = atan8(sX, sY, sX2, sY2); // if not already facing in that direction, if (pSoldier->ubDirection != ubDesiredMercDir) { @@ -2317,7 +2319,9 @@ void HandleNPCDoAction( UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum if (!TileIsOutOfBounds(sGridNo)) { // see if we are facing this person - ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sGridNo),CenterY(sGridNo)); + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(sGridNo, &sX2, &sY2); + ubDesiredMercDir = atan8(sX, sY, sX2, sY2); // if not already facing in that direction, if (pSoldier->ubDirection != ubDesiredMercDir) { @@ -5632,7 +5636,9 @@ void HandleRaulBlowingHimselfUp() //blow himself up with, hmmm, lets say TNT. :) usItem = HAND_GRENADE; - IgniteExplosion( RAUL_UB, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, usItem, pSoldier->pathing.bLevel ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + IgniteExplosion( RAUL_UB, sX, sY, 0, pSoldier->sGridNo, usItem, pSoldier->pathing.bLevel ); SetJa25GeneralFlag( JA_GF__RAUL_BLOW_HIMSELF_UP ); } diff --git a/Tactical/Interface Items.cpp b/Tactical/Interface Items.cpp index 9b7832044..b021c47a8 100644 --- a/Tactical/Interface Items.cpp +++ b/Tactical/Interface Items.cpp @@ -9570,7 +9570,7 @@ BOOLEAN HandleItemPointerClick( INT32 usMapPos ) BOOLEAN ItemCursorInLobRange( INT32 usMapPos ) { // Draw item depending on distance from buddy - if ( GetRangeFromGridNoDiff( usMapPos, gpItemPointerSoldier->sGridNo ) > MIN_LOB_RANGE ) + if (PythSpacesAway( usMapPos, gpItemPointerSoldier->sGridNo ) > MIN_LOB_RANGE ) { return( FALSE ); } diff --git a/Tactical/Interface.cpp b/Tactical/Interface.cpp index 8ac354710..5ab367503 100644 --- a/Tactical/Interface.cpp +++ b/Tactical/Interface.cpp @@ -2478,14 +2478,16 @@ BOOLEAN DrawCTHIndicator() ////////////////////////////////// // Calculate Aperture - + INT16 sX, sY; // Calculate the center point of the shooter, in world coordinates. - FLOAT dStartX = (FLOAT) CenterX( gCTHDisplay.iShooterGridNo ); - FLOAT dStartY = (FLOAT) CenterY( gCTHDisplay.iShooterGridNo ); + ConvertGridNoToCenterCellXY(gCTHDisplay.iShooterGridNo, &sX, &sY); + FLOAT dStartX = (FLOAT) sX; + FLOAT dStartY = (FLOAT) sY; // Calculate the center point of the target, in world coordinates. - FLOAT dEndX = (FLOAT) CenterX( gCTHDisplay.iTargetGridNo ); - FLOAT dEndY = (FLOAT) CenterY( gCTHDisplay.iTargetGridNo ); + ConvertGridNoToCenterCellXY(gCTHDisplay.iTargetGridNo, &sX, &sY); + FLOAT dEndX = (FLOAT) sX; + FLOAT dEndY = (FLOAT) sY; // Calculate a delta: the difference between the shooter and target. FLOAT dDeltaX = dEndX - dStartX; @@ -6647,4 +6649,4 @@ INT16 GetBackgroundValue( UINT8 usProfile, UINT16 aNr ) } return 0; -} \ No newline at end of file +} diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index e61c326cb..6e3535525 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -9262,13 +9262,16 @@ void CheckEquipmentForDamage( SOLDIERTYPE *pSoldier, INT32 iDamage ) if (fBlowsUp) { // blow it up! + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + if ( gTacticalStatus.ubAttackBusyCount ) { - IgniteExplosion( pSoldier->ubAttackerID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, pSoldier->inv[ bSlot ].usItem, pSoldier->pathing.bLevel, pSoldier->ubDirection, &pSoldier->inv[ bSlot ] ); + IgniteExplosion( pSoldier->ubAttackerID, sX, sY, 0, pSoldier->sGridNo, pSoldier->inv[ bSlot ].usItem, pSoldier->pathing.bLevel, pSoldier->ubDirection, &pSoldier->inv[ bSlot ] ); } else { - IgniteExplosion( pSoldier->ubID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, pSoldier->inv[ bSlot ].usItem, pSoldier->pathing.bLevel, pSoldier->ubDirection, &pSoldier->inv[ bSlot ] ); + IgniteExplosion( pSoldier->ubID, sX, sY, 0, pSoldier->sGridNo, pSoldier->inv[ bSlot ].usItem, pSoldier->pathing.bLevel, pSoldier->ubDirection, &pSoldier->inv[ bSlot ] ); } //ADB when something in a stack blows up the whole stack goes, so no need to worry about number of items @@ -9333,7 +9336,9 @@ BOOLEAN DamageItemOnGround( OBJECTTYPE * pObject, INT32 sGridNo, INT8 bLevel, IN if ( fBlowsUp ) { // OK, Ignite this explosion! - IgniteExplosion( ubOwner, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, pObject->usItem, bLevel, DIRECTION_IRRELEVANT, pObject ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + IgniteExplosion( ubOwner, sX, sY, 0, sGridNo, pObject->usItem, bLevel, DIRECTION_IRRELEVANT, pObject ); // SANDRO - merc records if ( (pObject->fFlags & OBJECT_ARMED_BOMB) && ((*pObject)[0]->data.misc.ubBombOwner > 1) ) diff --git a/Tactical/Keys.cpp b/Tactical/Keys.cpp index b5e9c0c30..b8dc66e4f 100644 --- a/Tactical/Keys.cpp +++ b/Tactical/Keys.cpp @@ -669,7 +669,9 @@ void HandleDoorTrap( SOLDIERTYPE * pSoldier, DOOR * pDoor ) { case EXPLOSION: // cause damage as a regular hand grenade - IgniteExplosion( NOBODY, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 25, pSoldier->sGridNo, HAND_GRENADE, 0 ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + IgniteExplosion( NOBODY, sX, sY, 25, pSoldier->sGridNo, HAND_GRENADE, 0 ); break; case SIREN: @@ -760,8 +762,7 @@ BOOLEAN AttemptToBlowUpLock(SOLDIERTYPE * pSoldier, DOOR * pDoor) sGridNo = pDoor->sGridNo; // Get sX, sy; - sX = CenterX(sGridNo); - sY = CenterY(sGridNo); + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); // Get Z position, based on orientation.... sZ = 20; diff --git a/Tactical/LOS.cpp b/Tactical/LOS.cpp index 1911493ea..ac2605a37 100644 --- a/Tactical/LOS.cpp +++ b/Tactical/LOS.cpp @@ -2380,12 +2380,15 @@ INT32 SoldierToSoldierLineOfSightTest( SOLDIERTYPE * pStartSoldier, SOLDIERTYPE UINT8 ubNumberOfTiles = pBase->pDBStructureRef->pDBStructure->ubNumberOfTiles; INT32 sStructGridNo; + INT16 sX, sY, sX2, sY2; + ConvertGridNoToCenterCellXY(pStartSoldier->sGridNo, &sX, &sY); // loop through all tiles for (UINT8 ubLoop = BASE_TILE; ubLoop < ubNumberOfTiles; ubLoop++) { sStructGridNo = AddPosRelToBase(pBase->sGridNo, ppTile[ubLoop]); - if( LineOfSightTest( (FLOAT) CenterX( pStartSoldier->sGridNo ), (FLOAT) CenterY( pStartSoldier->sGridNo ), dStartZPos, (FLOAT) CenterX( sStructGridNo ), (FLOAT) CenterY( sStructGridNo ), dEndZPos, iTileSightLimit, bAware, fSmell, NULL, adjustForSight, cthCalc ) ) + ConvertGridNoToCenterCellXY(sStructGridNo, &sX2, &sY2); + if( LineOfSightTest( (FLOAT) sX, (FLOAT) sY, dStartZPos, (FLOAT) sX2, (FLOAT) sY2, dEndZPos, iTileSightLimit, bAware, fSmell, NULL, adjustForSight, cthCalc ) ) { return( TRUE ); } @@ -2393,14 +2396,18 @@ INT32 SoldierToSoldierLineOfSightTest( SOLDIERTYPE * pStartSoldier, SOLDIERTYPE return( FALSE ); } - return( LineOfSightTest( (FLOAT) CenterX( pStartSoldier->sGridNo ), (FLOAT) CenterY( pStartSoldier->sGridNo ), dStartZPos, (FLOAT) CenterX( pEndSoldier->sGridNo ), (FLOAT) CenterY( pEndSoldier->sGridNo ), dEndZPos, iTileSightLimit, bAware, fSmell, NULL, adjustForSight, cthCalc ) ); + INT16 sX, sY, sX2, sY2; + ConvertGridNoToCenterCellXY(pStartSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(pEndSoldier->sGridNo, &sX2, &sY2); + + return( LineOfSightTest( (FLOAT) sX, (FLOAT) sY, dStartZPos, (FLOAT) sX2, (FLOAT) sY2, dEndZPos, iTileSightLimit, bAware, fSmell, NULL, adjustForSight, cthCalc ) ); } INT32 SoldierToLocationWindowTest( SOLDIERTYPE * pStartSoldier, INT32 sEndGridNo ) { // figure out if there is a SINGLE window between the looker and target FLOAT dStartZPos, dEndZPos; - INT16 sXPos, sYPos; + INT16 sX, sY, sX2, sY2; INT32 sWindowGridNo = NOWHERE; INT32 iRet; @@ -2413,24 +2420,23 @@ INT32 SoldierToLocationWindowTest( SOLDIERTYPE * pStartSoldier, INT32 sEndGridNo dStartZPos += CONVERT_PIXELS_TO_HEIGHTUNITS( gpWorldLevelData[pStartSoldier->sGridNo].sHeight ); dEndZPos = dStartZPos; - ConvertGridNoToXY( sEndGridNo, &sXPos, &sYPos ); - sXPos = sXPos * CELL_X_SIZE + (CELL_X_SIZE / 2); - sYPos = sYPos * CELL_Y_SIZE + (CELL_Y_SIZE / 2); + ConvertGridNoToCenterCellXY(pStartSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(sEndGridNo, &sX2, &sY2); //ADB changed from 255 to 511 to handle new LOS test // We don't want to consider distance limits here so pass in tile sight limit of 255( + 256) // and consider trees as little as possible - iRet = LineOfSightTest( (FLOAT) CenterX( pStartSoldier->sGridNo ), (FLOAT) CenterY( pStartSoldier->sGridNo ), dStartZPos, (FLOAT) sXPos, (FLOAT) sYPos, dEndZPos, 511, TRUE, FALSE, &sWindowGridNo ); + iRet = LineOfSightTest( (FLOAT) sX, (FLOAT) sY, dStartZPos, (FLOAT) sX2, (FLOAT) sY2, dEndZPos, 511, TRUE, FALSE, &sWindowGridNo ); return( sWindowGridNo ); } INT32 SoldierTo3DLocationLineOfSightTest( SOLDIERTYPE * pStartSoldier, INT32 sGridNo, INT8 bLevel, INT8 bCubeLevel, INT8 bAware, int iTileSightLimit, bool adjustForSight ) { - FLOAT dStartZPos, dEndZPos; - INT16 sXPos, sYPos; - UINT8 ubTargetID; - BOOLEAN fOk; + FLOAT dStartZPos, dEndZPos; + INT16 sX, sY, sX2, sY2; + UINT8 ubTargetID; + BOOLEAN fOk; CHECKF( pStartSoldier ); @@ -2457,9 +2463,6 @@ INT32 SoldierTo3DLocationLineOfSightTest( SOLDIERTYPE * pStartSoldier, INT32 sGr dEndZPos += CONVERT_PIXELS_TO_HEIGHTUNITS( gpWorldLevelData[ sGridNo ].sHeight ); } - ConvertGridNoToXY( sGridNo, &sXPos, &sYPos ); - sXPos = sXPos * CELL_X_SIZE + (CELL_X_SIZE / 2); - sYPos = sYPos * CELL_Y_SIZE + (CELL_Y_SIZE / 2); if (iTileSightLimit == CALC_FROM_ALL_DIRS || iTileSightLimit == CALC_FROM_WANTED_DIR) { iTileSightLimit = pStartSoldier->GetMaxDistanceVisible( sGridNo, bLevel, iTileSightLimit ); @@ -2468,14 +2471,17 @@ INT32 SoldierTo3DLocationLineOfSightTest( SOLDIERTYPE * pStartSoldier, INT32 sGr iTileSightLimit = 255 + pStartSoldier->GetMaxDistanceVisible( sGridNo, bLevel, CALC_FROM_ALL_DIRS ); } - return( LineOfSightTest( (FLOAT) CenterX( pStartSoldier->sGridNo ), (FLOAT) CenterY( pStartSoldier->sGridNo ), dStartZPos, (FLOAT) sXPos, (FLOAT) sYPos, dEndZPos, iTileSightLimit, bAware, HasThermalOptics( pStartSoldier), NULL, adjustForSight ) ); + ConvertGridNoToCenterCellXY(pStartSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(sGridNo, &sX2, &sY2); + + return( LineOfSightTest( (FLOAT) sX, (FLOAT) sY, dStartZPos, (FLOAT) sX2, (FLOAT) sY2, dEndZPos, iTileSightLimit, bAware, HasThermalOptics( pStartSoldier), NULL, adjustForSight ) ); } INT32 SoldierToVirtualSoldierLineOfSightTest( SOLDIERTYPE * pStartSoldier, INT32 sGridNo, INT8 bLevel, INT8 bStance, INT8 bAware, int iTileSightLimit ) { - FLOAT dStartZPos, dEndZPos; - INT16 sXPos, sYPos; - BOOLEAN fOk; + FLOAT dStartZPos, dEndZPos; + INT16 endXPos, endYPos, startXPos, startYPos; + BOOLEAN fOk; CHECKF( pStartSoldier ); @@ -2504,10 +2510,6 @@ INT32 SoldierToVirtualSoldierLineOfSightTest( SOLDIERTYPE * pStartSoldier, INT32 } - ConvertGridNoToXY( sGridNo, &sXPos, &sYPos ); - sXPos = sXPos * CELL_X_SIZE + (CELL_X_SIZE / 2); - sYPos = sYPos * CELL_Y_SIZE + (CELL_Y_SIZE / 2); - if (iTileSightLimit == CALC_FROM_ALL_DIRS || iTileSightLimit == CALC_FROM_WANTED_DIR) { iTileSightLimit = pStartSoldier->GetMaxDistanceVisible( sGridNo, bLevel, iTileSightLimit ); } @@ -2515,13 +2517,15 @@ INT32 SoldierToVirtualSoldierLineOfSightTest( SOLDIERTYPE * pStartSoldier, INT32 iTileSightLimit = 255 + pStartSoldier->GetMaxDistanceVisible( sGridNo, bLevel, CALC_FROM_ALL_DIRS ); } - return( LineOfSightTest( (FLOAT) CenterX( pStartSoldier->sGridNo ), (FLOAT) CenterY( pStartSoldier->sGridNo ), dStartZPos, (FLOAT) sXPos, (FLOAT) sYPos, dEndZPos, iTileSightLimit, bAware, HasThermalOptics( pStartSoldier), NULL, false ) ); + ConvertGridNoToCenterCellXY(pStartSoldier->sGridNo, &startXPos, &startYPos); + ConvertGridNoToCenterCellXY(sGridNo, &endXPos, &endYPos); + return(LineOfSightTest((FLOAT)startXPos, (FLOAT)startYPos, dStartZPos, (FLOAT)endXPos, (FLOAT)endYPos, dEndZPos, iTileSightLimit, bAware, HasThermalOptics(pStartSoldier), NULL, false)); } INT32 LocationToLocationLineOfSightTest( INT32 sStartGridNo, INT8 bStartLevel, INT32 sEndGridNo, INT8 bEndLevel, INT8 bAware, int iTileSightLimit, FLOAT dStartPos, FLOAT dEndPos ) { - FLOAT dStartZPos, dEndZPos; - INT16 sStartXPos, sStartYPos, sEndXPos, sEndYPos; + FLOAT dStartZPos, dEndZPos; + INT16 sStartXPos, sStartYPos, sEndXPos, sEndYPos; // Bob: prevent access violation if (sStartGridNo < 0) { @@ -2544,19 +2548,11 @@ INT32 LocationToLocationLineOfSightTest( INT32 sStartGridNo, INT8 bStartLevel, I // add in ground height dStartZPos += CONVERT_PIXELS_TO_HEIGHTUNITS( gpWorldLevelData[ sStartGridNo ].sHeight ); - ConvertGridNoToXY( sStartGridNo, &sStartXPos, &sStartYPos ); - sStartXPos = sStartXPos * CELL_X_SIZE + (CELL_X_SIZE / 2); - sStartYPos = sStartYPos * CELL_Y_SIZE + (CELL_Y_SIZE / 2); - // sevenfm: use height argument dEndZPos = dEndPos + bEndLevel * HEIGHT_UNITS; // add in ground height dEndZPos += CONVERT_PIXELS_TO_HEIGHTUNITS( gpWorldLevelData[ sEndGridNo ].sHeight ); - ConvertGridNoToXY( sEndGridNo, &sEndXPos, &sEndYPos ); - sEndXPos = sEndXPos * CELL_X_SIZE + (CELL_X_SIZE / 2); - sEndYPos = sEndYPos * CELL_Y_SIZE + (CELL_Y_SIZE / 2); - if (iTileSightLimit == CALC_FROM_ALL_DIRS || iTileSightLimit == CALC_FROM_WANTED_DIR) { iTileSightLimit = MaxNormalDistanceVisible(); @@ -2565,6 +2561,10 @@ INT32 LocationToLocationLineOfSightTest( INT32 sStartGridNo, INT8 bStartLevel, I { iTileSightLimit = 255 + MaxNormalDistanceVisible(); } + + ConvertGridNoToCenterCellXY(sStartGridNo, &sStartXPos, &sStartYPos); + ConvertGridNoToCenterCellXY(sEndGridNo, &sEndXPos, &sEndYPos); + return( LineOfSightTest( (FLOAT)sStartXPos, (FLOAT)sStartYPos, dStartZPos, (FLOAT) sEndXPos, (FLOAT) sEndYPos, dEndZPos, iTileSightLimit, bAware, FALSE, NULL ) ); } @@ -2931,20 +2931,24 @@ BOOLEAN BulletHitMerc( BULLET * pBullet, STRUCTURE * pStructure, BOOLEAN fIntend // Flugente: we measure the distance of the bullet's location to the location of the soldier, and to the 2 gridnos his head and leg occupy // From this we can decide what body part was hit - FLOAT bodycenterX = (FLOAT)CenterX( pTarget->sGridNo ); - FLOAT bodycenterY = (FLOAT)CenterY( pTarget->sGridNo ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pTarget->sGridNo, &sX, &sY); + FLOAT bodycenterX = (FLOAT) sX; + FLOAT bodycenterY = (FLOAT) sY; FLOAT difftobodycenter = sqrt( (bodycenterX - x) * (bodycenterX - x) + (bodycenterY - y) * (bodycenterY - y) ); INT32 viewdirectiongridno = NewGridNo( pTarget->sGridNo, DirectionInc( pTarget->ubDirection ) ); - FLOAT nextgridnocenterX = (FLOAT)CenterX( viewdirectiongridno ); - FLOAT nextgridnocenterY = (FLOAT)CenterY( viewdirectiongridno ); + ConvertGridNoToCenterCellXY(viewdirectiongridno, &sX, &sY); + FLOAT nextgridnocenterX = (FLOAT) sX; + FLOAT nextgridnocenterY = (FLOAT) sY; FLOAT difftonextgridno = sqrt( (nextgridnocenterX - x) * (nextgridnocenterX - x) + (nextgridnocenterY - y) * (nextgridnocenterY - y) ); INT32 oppositeviewdirectiongridno = NewGridNo( pTarget->sGridNo, DirectionInc( gOppositeDirection[pTarget->ubDirection] ) ); - FLOAT oppositenextgridnocenterX = (FLOAT)CenterX( oppositeviewdirectiongridno ); - FLOAT oppositenextgridnocenterY = (FLOAT)CenterY( oppositeviewdirectiongridno ); + ConvertGridNoToCenterCellXY(oppositeviewdirectiongridno, &sX, &sY); + FLOAT oppositenextgridnocenterX = (FLOAT) sX; + FLOAT oppositenextgridnocenterY = (FLOAT) sY; FLOAT difftooppositenextgridno = sqrt( (oppositenextgridnocenterX - x) * (oppositenextgridnocenterX - x) + (oppositenextgridnocenterY - y) * (oppositenextgridnocenterY - y) ); @@ -4319,8 +4323,9 @@ UINT8 CalcChanceToGetThrough( BULLET * pBullet ) UINT8 SoldierToSoldierChanceToGetThrough( SOLDIERTYPE * pStartSoldier, SOLDIERTYPE * pEndSoldier ) { - FLOAT dEndZPos; - BOOLEAN fOk; + INT16 sX, sY; + FLOAT dEndZPos; + BOOLEAN fOk; if (pStartSoldier == pEndSoldier) { @@ -4337,15 +4342,18 @@ UINT8 SoldierToSoldierChanceToGetThrough( SOLDIERTYPE * pStartSoldier, SOLDIERTY // set startsoldier's target ID ... need an ID stored in case this // is the AI calculating cover to a location where he might not be any more pStartSoldier->ubCTGTTargetID = pEndSoldier->ubID; - return( ChanceToGetThrough( pStartSoldier, (FLOAT) CenterX( pEndSoldier->sGridNo ), (FLOAT) CenterY( pEndSoldier->sGridNo ), dEndZPos ) ); + + ConvertGridNoToCenterCellXY(pEndSoldier->sGridNo, &sX, &sY); + return( ChanceToGetThrough( pStartSoldier, (FLOAT) sX, (FLOAT) sY, dEndZPos ) ); } UINT8 SoldierToSoldierBodyPartChanceToGetThrough( SOLDIERTYPE * pStartSoldier, SOLDIERTYPE * pEndSoldier, UINT8 ubAimLocation ) { // does like StS-CTGT but with a particular body part in mind - FLOAT dEndZPos; - BOOLEAN fOk; - UINT8 ubPosType; + INT16 sX, sY; + FLOAT dEndZPos; + BOOLEAN fOk; + UINT8 ubPosType; if (pStartSoldier == pEndSoldier) { @@ -4378,7 +4386,8 @@ UINT8 SoldierToSoldierBodyPartChanceToGetThrough( SOLDIERTYPE * pStartSoldier, S // set startsoldier's target ID ... need an ID stored in case this // is the AI calculating cover to a location where he might not be any more pStartSoldier->ubCTGTTargetID = pEndSoldier->ubID; - return( ChanceToGetThrough( pStartSoldier, (FLOAT) CenterX( pEndSoldier->sGridNo ), (FLOAT) CenterY( pEndSoldier->sGridNo ), dEndZPos ) ); + ConvertGridNoToCenterCellXY(pEndSoldier->sGridNo, &sX, &sY); + return( ChanceToGetThrough( pStartSoldier, (FLOAT) sX, (FLOAT) sY, dEndZPos ) ); } UINT8 SoldierToLocationChanceToGetThrough( SOLDIERTYPE * pStartSoldier, INT32 sGridNo, INT8 bLevel, INT8 bCubeLevel, UINT8 ubTargetID ) @@ -4423,9 +4432,7 @@ UINT8 SoldierToLocationChanceToGetThrough( SOLDIERTYPE * pStartSoldier, INT32 sG } dEndZPos += CONVERT_PIXELS_TO_HEIGHTUNITS( gpWorldLevelData[sGridNo].sHeight ); - ConvertGridNoToXY( sGridNo, &sXPos, &sYPos ); - sXPos = sXPos * CELL_X_SIZE + (CELL_X_SIZE / 2); - sYPos = sYPos * CELL_Y_SIZE + (CELL_Y_SIZE / 2); + ConvertGridNoToCenterCellXY(sGridNo, &sXPos, &sYPos); // set startsoldier's target ID ... need an ID stored in case this // is the AI calculating cover to a location where he might not be any more @@ -4437,6 +4444,7 @@ UINT8 SoldierToLocationChanceToGetThrough( SOLDIERTYPE * pStartSoldier, INT32 sG UINT8 AISoldierToSoldierChanceToGetThrough( SOLDIERTYPE * pStartSoldier, SOLDIERTYPE * pEndSoldier ) { // Like a standard CTGT algorithm BUT fakes the start soldier at standing height + INT16 sX, sY; FLOAT dEndZPos; BOOLEAN fOk; UINT8 ubChance; @@ -4460,7 +4468,8 @@ UINT8 AISoldierToSoldierChanceToGetThrough( SOLDIERTYPE * pStartSoldier, SOLDIER // is the AI calculating cover to a location where he might not be any more pStartSoldier->ubCTGTTargetID = NOBODY; - ubChance = ChanceToGetThrough( pStartSoldier, (FLOAT) CenterX( pEndSoldier->sGridNo ), (FLOAT) CenterY( pEndSoldier->sGridNo ), dEndZPos ); + ConvertGridNoToCenterCellXY(pEndSoldier->sGridNo, &sX, &sY); + ubChance = ChanceToGetThrough( pStartSoldier, (FLOAT) sX, (FLOAT) sY, dEndZPos ); pStartSoldier->usAnimState = usTrueState; return( ubChance ); } @@ -4510,9 +4519,7 @@ UINT8 AISoldierToLocationChanceToGetThrough( SOLDIERTYPE * pStartSoldier, INT32 } dEndZPos += CONVERT_PIXELS_TO_HEIGHTUNITS( gpWorldLevelData[sGridNo].sHeight ); - ConvertGridNoToXY( sGridNo, &sXPos, &sYPos ); - sXPos = sXPos * CELL_X_SIZE + (CELL_X_SIZE / 2); - sYPos = sYPos * CELL_Y_SIZE + (CELL_Y_SIZE / 2); + ConvertGridNoToCenterCellXY(sGridNo, &sXPos, &sYPos); // set startsoldier's target ID ... need an ID stored in case this // is the AI calculating cover to a location where he might not be any more @@ -4788,6 +4795,7 @@ INT8 FireBulletGivenTargetNCTH( SOLDIERTYPE * pFirer, FLOAT dEndX, FLOAT dEndY, UINT8 ubSpreadIndex = 0; UINT16 usBulletFlags = 0; int n=0; + INT16 sXPos, sYPos; OBJECTTYPE* pObjAttHand = pFirer->GetUsedWeapon( &(pFirer->inv[pFirer->ubAttackingHand]) ); @@ -4799,8 +4807,9 @@ INT8 FireBulletGivenTargetNCTH( SOLDIERTYPE * pFirer, FLOAT dEndX, FLOAT dEndY, CalculateSoldierZPos( pFirer, FIRING_POS, &dStartZ ); - dStartX = (FLOAT) CenterX( pFirer->sGridNo ); - dStartY = (FLOAT) CenterY( pFirer->sGridNo ); + ConvertGridNoToCenterCellXY(pFirer->sGridNo, &sXPos, &sYPos); + dStartX = (FLOAT) sXPos; + dStartY = (FLOAT) sYPos; dDeltaX = dEndX - dStartX; dDeltaY = dEndY - dStartY; @@ -5279,6 +5288,7 @@ INT8 FireBulletGivenTarget( SOLDIERTYPE * pFirer, FLOAT dEndX, FLOAT dEndY, FLOA UINT8 ubSpreadIndex = 0; UINT16 usBulletFlags = 0; int n=0; + INT16 sXPos, sYPos; OBJECTTYPE* pObjAttHand = pFirer->GetUsedWeapon( &(pFirer->inv[pFirer->ubAttackingHand]) ); @@ -5290,8 +5300,9 @@ INT8 FireBulletGivenTarget( SOLDIERTYPE * pFirer, FLOAT dEndX, FLOAT dEndY, FLOA CalculateSoldierZPos( pFirer, FIRING_POS, &dStartZ ); - dStartX = (FLOAT) CenterX( pFirer->sGridNo ); - dStartY = (FLOAT) CenterY( pFirer->sGridNo ); + ConvertGridNoToCenterCellXY(pFirer->sGridNo, &sXPos, &sYPos); + dStartX = (FLOAT) sXPos; + dStartY = (FLOAT) sYPos; dDeltaX = dEndX - dStartX; dDeltaY = dEndY - dStartY; @@ -5954,6 +5965,7 @@ INT8 FireBulletGivenTargetTrapOnly( SOLDIERTYPE* pThrower, OBJECTTYPE* pObj, INT UINT8 ubSpreadIndex = 0; UINT16 usBulletFlags = 0; int n=0; + INT16 sXPos, sYPos; UINT16 usItem = pObj->usItem; UINT8 ammotype = ( *pObj )[0]->data.gun.ubGunAmmoType; @@ -5962,8 +5974,9 @@ INT8 FireBulletGivenTargetTrapOnly( SOLDIERTYPE* pThrower, OBJECTTYPE* pObj, INT if ( AmmoTypes[ammotype].numberOfBullets > 1 ) fBuckshot = TRUE; - dStartX = (FLOAT) CenterX( gridno ); - dStartY = (FLOAT) CenterY( gridno ); + ConvertGridNoToCenterCellXY(gridno, &sXPos, &sYPos); + dStartX = (FLOAT) sXPos; + dStartY = (FLOAT) sYPos; dDeltaX = dEndX - dStartX; dDeltaY = dEndY - dStartY; @@ -6541,13 +6554,15 @@ INT8 FireBulletGivenTarget_NoObjectNoSoldier( UINT16 usItem, UINT8 ammotype, UIN UINT8 ubSpreadIndex = 0; UINT16 usBulletFlags = 0; int n = 0; - + INT16 sXPos, sYPos; + BOOLEAN fBuckshot = FALSE; if ( AmmoTypes[ammotype].numberOfBullets > 1 ) fBuckshot = TRUE; - dStartX = (FLOAT)CenterX( gridno ); - dStartY = (FLOAT)CenterY( gridno ); + ConvertGridNoToCenterCellXY(gridno, &sXPos, &sYPos); + dStartX = (FLOAT)sXPos; + dStartY = (FLOAT)sYPos; dDeltaX = dEndX - dStartX; dDeltaY = dEndY - dStartY; @@ -8537,8 +8552,10 @@ void AdjustTargetCenterPoint( SOLDIERTYPE *pShooter, INT32 iTargetGridNo, FLOAT CalculateSoldierZPos( pShooter, FIRING_POS, &dStartZ ); // Locate absolute center X,Y of the shooter - dStartX = (FLOAT) CenterX( pShooter->sGridNo ); - dStartY = (FLOAT) CenterY( pShooter->sGridNo ); + INT16 sXPos, sYPos; + ConvertGridNoToCenterCellXY(pShooter->sGridNo, &sXPos, &sYPos); + dStartX = (FLOAT) sXPos; + dStartY = (FLOAT) sYPos; //////////////////////////////////////////////////////////////////////////// // Calculate difference (Delta) between start and end point of bullet flight @@ -9157,8 +9174,10 @@ void CalcTargetMovementOffset( SOLDIERTYPE *pShooter, SOLDIERTYPE *pTarget, OBJE { // HEADROCK HAM 4: Hopefully the right spot for this: This soldier has no "old" coordinates, so just set them // to wherever he/she is currently standing. - pTarget->sOldXPos = CenterX( pTarget->sGridNo ); - pTarget->sOldYPos = CenterY( pTarget->sGridNo ); + INT16 sXPos, sYPos; + ConvertGridNoToCenterCellXY(pTarget->sGridNo, &sXPos, &sYPos); + pTarget->sOldXPos = sXPos; + pTarget->sOldYPos = sYPos; // Since movement is now nonexistent, break the formula here without adjusting coordinates. return; } diff --git a/Tactical/Rotting Corpses.cpp b/Tactical/Rotting Corpses.cpp index 35c4101ba..2293bfa69 100644 --- a/Tactical/Rotting Corpses.cpp +++ b/Tactical/Rotting Corpses.cpp @@ -561,8 +561,7 @@ INT32 AddRottingCorpse( ROTTING_CORPSE_DEFINITION *pCorpseDef ) } else { - AniParams.sX = CenterX(pCorpse->def.sGridNo); - AniParams.sY = CenterY(pCorpse->def.sGridNo); + ConvertGridNoToCenterCellXY(pCorpse->def.sGridNo, &AniParams.sX, &AniParams.sY); } AniParams.sZ = (INT16)pCorpse->def.sHeightAdjustment; @@ -1588,8 +1587,7 @@ void VaporizeCorpse( INT32 sGridNo, INT8 asLevel, UINT16 usStructureID ) AniParams.sDelay = (INT16)( 80 ); AniParams.sStartFrame = 0; AniParams.uiFlags = ANITILE_CACHEDTILE | ANITILE_FORWARD; - AniParams.sX = CenterX( sBaseGridNo ); - AniParams.sY = CenterY( sBaseGridNo ); + ConvertGridNoToCenterCellXY(sBaseGridNo, &AniParams.sX, &AniParams.sY); AniParams.sZ = (INT16)pCorpse->def.sHeightAdjustment; strcpy( AniParams.zCachedFile, "TILECACHE\\GEN_BLOW.STI" ); @@ -2284,10 +2282,12 @@ BOOLEAN AddCorpseFromObject(OBJECTTYPE* pObj, INT32 sGridNo, INT8 bLevel ) Corpse.ubBodyType = REGMALE; } + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + Corpse.sGridNo = sGridNo; - - Corpse.dXPos = CenterX(Corpse.sGridNo); - Corpse.dYPos = CenterY(Corpse.sGridNo); + Corpse.dXPos = sX; + Corpse.dYPos = sY; Corpse.sHeightAdjustment = 0; diff --git a/Tactical/ShopKeeper Interface.cpp b/Tactical/ShopKeeper Interface.cpp index 32af6e28b..427a0fc59 100644 --- a/Tactical/ShopKeeper Interface.cpp +++ b/Tactical/ShopKeeper Interface.cpp @@ -776,7 +776,7 @@ BOOLEAN EnterShopKeeperInterface() else pShopkeeper = FindSoldierByProfileID( armsDealerInfo[gbSelectedArmsDealerID].ubShopKeeperID, FALSE ); - if ( GetRangeFromGridNoDiff( pSoldier->sGridNo, pShopkeeper->sGridNo ) > NPC_TALK_RADIUS ) + if (PythSpacesAway( pSoldier->sGridNo, pShopkeeper->sGridNo ) > NPC_TALK_RADIUS ) { //so now we know we are too far away to trade, so instead of just quitting, //either post a message or run to the guy like HandleTalkInit does @@ -6668,7 +6668,7 @@ BOOLEAN CanMercInteractWithSelectedShopkeeper( SOLDIERTYPE *pSoldier ) if ( SoldierTo3DLocationLineOfSightTest( pSoldier, sDestGridNo, bDestLevel, 3, TRUE, CALC_FROM_ALL_DIRS ) ) { // Get range to shopkeeper - uiRange = GetRangeFromGridNoDiff( pSoldier->sGridNo, sDestGridNo ); + uiRange = PythSpacesAway( pSoldier->sGridNo, sDestGridNo ); // and is close enough to talk to the shopkeeper (use this define INSTEAD of PASSING_ITEM_DISTANCE_OKLIFE!) if ( uiRange <= NPC_TALK_RADIUS ) diff --git a/Tactical/Soldier Add.cpp b/Tactical/Soldier Add.cpp index 40c31c81f..64a83a0c0 100644 --- a/Tactical/Soldier Add.cpp +++ b/Tactical/Soldier Add.cpp @@ -1367,11 +1367,9 @@ void InternalSoldierInSectorSleep( SOLDIERTYPE *pSoldier, INT32 sGridNo, BOOLEAN usAnim = STANDING; } - // OK, look for sutable placement.... + // OK, look for suitable placement.... sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, usAnim, sGridNo, 5, &ubNewDirection, FALSE ); - - sWorldX = CenterX( sGoodGridNo ); - sWorldY = CenterY( sGoodGridNo ); + ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY); pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY ); @@ -1408,11 +1406,9 @@ void SoldierInSectorIncompaciated( SOLDIERTYPE *pSoldier, INT32 sGridNo ) return; } - // OK, look for sutable placement.... + // OK, look for suitable placement.... sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, STAND_FALLFORWARD_STOP, sGridNo, 5, &ubNewDirection, FALSE ); - - sWorldX = CenterX( sGoodGridNo ); - sWorldY = CenterY( sGoodGridNo ); + ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY); pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY ); @@ -1444,11 +1440,9 @@ void SoldierInSectorPatient( SOLDIERTYPE *pSoldier, INT32 sGridNo ) return; } - // OK, look for sutable placement.... + // OK, look for suitable placement.... sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_PATIENT, sGridNo, 5, &ubNewDirection, FALSE ); - - sWorldX = CenterX( sGoodGridNo ); - sWorldY = CenterY( sGoodGridNo ); + ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY); pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY ); @@ -1479,11 +1473,9 @@ void SoldierInSectorDoctor( SOLDIERTYPE *pSoldier, INT32 sGridNo ) return; } - // OK, look for sutable placement.... + // OK, look for suitable placement.... sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_DOCTOR, sGridNo, 5, &ubNewDirection, FALSE ); - - sWorldX = CenterX( sGoodGridNo ); - sWorldY = CenterY( sGoodGridNo ); + ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY); pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY ); @@ -1514,11 +1506,9 @@ void SoldierInSectorRepair( SOLDIERTYPE *pSoldier, INT32 sGridNo ) return; } - // OK, look for sutable placement.... + // OK, look for suitable placement.... sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_REPAIRMAN, sGridNo, 5, &ubNewDirection, FALSE ); - - sWorldX = CenterX( sGoodGridNo ); - sWorldY = CenterY( sGoodGridNo ); + ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY); pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY ); @@ -1550,8 +1540,7 @@ void AddSoldierToSectorGridNo( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubDir DebugMsg(TOPIC_JA2,DBG_LEVEL_3,String("AddSoldierToSectorGridNo")); // Add merc to gridno - sWorldX = CenterX( sGridNo ); - sWorldY = CenterY( sGridNo ); + ConvertGridNoToCenterCellXY(sGridNo, &sWorldX, &sWorldY); // Set reserved location! pSoldier->sReservedMovementGridNo = NOWHERE; diff --git a/Tactical/Soldier Ani.cpp b/Tactical/Soldier Ani.cpp index e60f7bec2..eda237d26 100644 --- a/Tactical/Soldier Ani.cpp +++ b/Tactical/Soldier Ani.cpp @@ -280,7 +280,7 @@ BOOLEAN AdjustToNextAnimationFrame( SOLDIERTYPE *pSoldier ) INT16 sXPos, sYPos; //sNewGridNo = NewGridNo( pSoldier->sGridNo, (UINT16)DirectionInc( pSoldier->ubDirection ) ); - ConvertMapPosToWorldTileCenter( pSoldier->sTempNewGridNo, &sXPos, &sYPos ); + ConvertGridNoToCenterCellXY( pSoldier->sTempNewGridNo, &sXPos, &sYPos ); pSoldier->EVENT_SetSoldierPosition( (FLOAT)sXPos, (FLOAT)sYPos ); } @@ -717,8 +717,7 @@ BOOLEAN AdjustToNextAnimationFrame( SOLDIERTYPE *pSoldier ) // CODE: End Hop Fence // MOVE TO FORCASTED GRIDNO - sX = CenterX( pSoldier->sForcastGridno ); - sY = CenterY( pSoldier->sForcastGridno ); + ConvertGridNoToCenterCellXY(pSoldier->sForcastGridno, &sX, &sY); pSoldier->EVENT_InternalSetSoldierPosition( (FLOAT) sX, (FLOAT) sY, FALSE, FALSE, FALSE ); pSoldier->EVENT_SetSoldierDirection( gTwoCDirection[ pSoldier->ubDirection ] ); diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index d41c63a4f..d99e31bd5 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -5041,8 +5041,10 @@ void SOLDIERTYPE::EVENT_FireSoldierWeapon( INT32 sTargetGridNo ) } else if (!TileIsOutOfBounds(sTargetGridNo) && !GridNoOnScreen(sTargetGridNo)) { - INT16 sNewCenterWorldX = CenterX(sTargetGridNo); - INT16 sNewCenterWorldY = CenterY(sTargetGridNo); + INT16 sNewCenterWorldX; + INT16 sNewCenterWorldY; + ConvertGridNoToCenterCellXY(sTargetGridNo, &sNewCenterWorldX, &sNewCenterWorldY); + SetRenderCenter(sNewCenterWorldX, sNewCenterWorldY); // Plot new path! @@ -7359,7 +7361,7 @@ void SOLDIERTYPE::EVENT_InternalSetSoldierDestination( UINT16 usNewDirection, BO // Get dest gridno, convert to center coords sNewGridNo = NewGridNo( this->sGridNo, DirectionInc( (UINT8)usNewDirection ) ); - ConvertMapPosToWorldTileCenter( sNewGridNo, &sXPos, &sYPos ); + ConvertGridNoToCenterCellXY( sNewGridNo, &sXPos, &sYPos ); // Save new dest gridno, x, y this->pathing.sDestination = sNewGridNo; @@ -11544,7 +11546,7 @@ void SOLDIERTYPE::MoveMerc( FLOAT dMovementChange, FLOAT dAngle, BOOLEAN fCheckR { INT16 this_base_x = 0; INT16 this_base_y = 0; - ConvertMapPosToWorldTileCenter( this->sGridNo, &this_base_x, &this_base_y ); + ConvertGridNoToCenterCellXY( this->sGridNo, &this_base_x, &this_base_y ); dx = this->dXPos - this_base_x; dy = this->dYPos - this_base_y; @@ -11552,7 +11554,7 @@ void SOLDIERTYPE::MoveMerc( FLOAT dMovementChange, FLOAT dAngle, BOOLEAN fCheckR INT16 base_x = 0; INT16 base_y = 0; - ConvertMapPosToWorldTileCenter( gridnotouse, &base_x, &base_y ); + ConvertGridNoToCenterCellXY( gridnotouse, &base_x, &base_y ); pSoldier->EVENT_InternalSetSoldierPosition( base_x + dx, base_y + dy, FALSE, FALSE, FALSE ); } @@ -11586,27 +11588,33 @@ void SOLDIERTYPE::MoveMerc( FLOAT dMovementChange, FLOAT dAngle, BOOLEAN fCheckR // adjust both gridno and x,y coordinates if (sOldGridNo != this->sGridNo) { - CorpseDef.sGridNo = sOldGridNo; - CorpseDef.dXPos = CenterX(CorpseDef.sGridNo); - CorpseDef.dYPos = CenterY(CorpseDef.sGridNo); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sOldGridNo, &sX, &sY); + + CorpseDef.sGridNo = sOldGridNo; + CorpseDef.dXPos = sX; + CorpseDef.dYPos = sY; } else { // move corpse a bit INT16 this_base_x = 0; INT16 this_base_y = 0; - ConvertMapPosToWorldTileCenter(this->sGridNo, &this_base_x, &this_base_y); + ConvertGridNoToCenterCellXY(this->sGridNo, &this_base_x, &this_base_y); FLOAT dx = this->dXPos - this_base_x; FLOAT dy = this->dYPos - this_base_y; INT16 base_x = 0; INT16 base_y = 0; - ConvertMapPosToWorldTileCenter(pCorpse->def.sGridNo, &base_x, &base_y); + ConvertGridNoToCenterCellXY(pCorpse->def.sGridNo, &base_x, &base_y); + + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pCorpse->def.sGridNo, &sX, &sY); CorpseDef.sGridNo = pCorpse->def.sGridNo; - CorpseDef.dXPos = CenterX(CorpseDef.sGridNo) + dx; - CorpseDef.dYPos = CenterY(CorpseDef.sGridNo) + dy; + CorpseDef.dXPos = sX + dx; + CorpseDef.dYPos = sY + dy; } CorpseDef.usFlags |= ROTTING_CORPSE_USE_XY_PROVIDED; @@ -11768,6 +11776,17 @@ UINT8 GetDirectionFromXY( INT16 sXPos, INT16 sYPos, SOLDIERTYPE *pSoldier ) return(atan8( sXPos2, sYPos2, sXPos, sYPos )); } +INT16 GetDirectionFromCenterCellXYGridNo(INT32 EndGridNo, INT32 StartGridNo) +{ + INT16 sXPos2, sYPos2; + INT16 sXPos, sYPos; + + ConvertGridNoToCenterCellXY(StartGridNo, &sXPos, &sYPos); + ConvertGridNoToCenterCellXY(EndGridNo, &sXPos2, &sYPos2); + + return(atan8(sXPos2, sYPos2, sXPos, sYPos)); +} + //#if 0 UINT8 atan8( INT16 sXPos, INT16 sYPos, INT16 sXPos2, INT16 sYPos2 ) @@ -12261,8 +12280,7 @@ void SOLDIERTYPE::ReviveSoldier( void ) this->BeginSoldierGetup( ); // Makesure center of tile - sX = CenterX( this->sGridNo ); - sY = CenterY( this->sGridNo ); + ConvertGridNoToCenterCellXY(this->sGridNo, &sX, &sY); this->EVENT_SetSoldierPosition( (FLOAT)sX, (FLOAT)sY ); @@ -13962,8 +13980,7 @@ void SOLDIERTYPE::EVENT_StopMerc( INT32 sGridNo, INT8 bDirection ) // MOVE GUY TO GRIDNO--- SHOULD BE THE SAME UNLESS IN MULTIPLAYER // Makesure center of tile - sX = CenterX( sGridNo ); - sY = CenterY( sGridNo ); + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); //Cancel pending events if ( !this->flags.fDelayedMovement ) @@ -15862,7 +15879,7 @@ BOOLEAN SOLDIERTYPE::SeemsLegit( UINT8 ubObserverID ) } UINT8 covertlevel = NUM_SKILL_TRAITS( this, COVERT_NT ); // our level in covert operations - INT32 distance = GetRangeFromGridNoDiff( this->sGridNo, pSoldier->sGridNo ); + INT32 distance = PythSpacesAway( this->sGridNo, pSoldier->sGridNo ); // if we are closer than this, our cover will always break if we do not have the skill // if we have the skill, our cover will blow if we dress up as a soldier, but not if we are dressed like a civilian @@ -20865,7 +20882,7 @@ void SOLDIERTYPE::CancelDrag() { INT16 base_x = 0; INT16 base_y = 0; - ConvertMapPosToWorldTileCenter(pSoldier->sGridNo, &base_x, &base_y); + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &base_x, &base_y); pSoldier->EVENT_InternalSetSoldierPosition(base_x, base_y, FALSE, FALSE, FALSE); } @@ -23199,7 +23216,7 @@ BOOLEAN SOLDIERTYPE::PlayerSoldierStartTalking( UINT8 ubTargetID, BOOLEAN fValid return(FALSE); } - uiRange = GetRangeFromGridNoDiff( this->sGridNo, pTSoldier->sGridNo ); + uiRange = PythSpacesAway( this->sGridNo, pTSoldier->sGridNo ); if ( uiRange > (NPC_TALK_RADIUS * 2) ) { diff --git a/Tactical/Soldier Control.h b/Tactical/Soldier Control.h index 5873618d4..f461f30dc 100644 --- a/Tactical/Soldier Control.h +++ b/Tactical/Soldier Control.h @@ -2204,7 +2204,8 @@ BOOLEAN GetDirectionChangeAmount( INT32 sGridNo, SOLDIERTYPE *pSoldier, UINT8 ui UINT8 GetDirectionFromGridNo( INT32 sGridNo, SOLDIERTYPE *pSoldier ); UINT8 atan8( INT16 sXPos, INT16 sYPos, INT16 sXPos2, INT16 sYPos2 ); UINT8 atan8FromAngle( DOUBLE dAngle ); -INT16 GetDirectionToGridNoFromGridNo( INT32 sGridNoDest, INT32 sGridNoSrc ); +INT16 GetDirectionToGridNoFromGridNo(INT32 sGridNoDest, INT32 sGridNoSrc); +INT16 GetDirectionFromCenterCellXYGridNo(INT32 EndGridNo, INT32 StartGridNo); // This function is now obsolete. Call ReduceAttackBusyCount instead. // void ReleaseSoldiersAttacker( SOLDIERTYPE *pSoldier ); diff --git a/Tactical/Soldier Find.cpp b/Tactical/Soldier Find.cpp index 6b9ada5f9..c45b35c00 100644 --- a/Tactical/Soldier Find.cpp +++ b/Tactical/Soldier Find.cpp @@ -814,8 +814,7 @@ BOOLEAN SoldierLocationRelativeToScreen( INT32 sGridNo, UINT16 usReasonID, INT8 *puiScrollFlags = 0; - sX = CenterX( sGridNo ); - sY = CenterY( sGridNo ); + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); // Get screen coordinates for current position of soldier GetWorldXYAbsoluteScreenXY( (INT16)(sX/CELL_X_SIZE), (INT16)(sY/CELL_Y_SIZE), &sWorldX, &sWorldY); @@ -954,25 +953,28 @@ BOOLEAN FindRelativeSoldierPosition( SOLDIERTYPE *pSoldier, UINT16 *usFlags, INT // Then, depending on whether this is the gridno we are looking at, this will be head or legs if ( gGameExternalOptions.fAllowTargetHeadAndLegIfProne ) { - INT16 sWorldX, sWorldY; + INT16 sWorldX, sWorldY, sX, sY; GetMouseWorldCoords( &sWorldX, &sWorldY ); // Flugente: we measure the distance of the bullet's location to the location of the soldier, and to the 2 gridnos his head and leg occupy // From this we can decide what body part was hit - FLOAT bodycenterX = (FLOAT)CenterX( pSoldier->sGridNo ); - FLOAT bodycenterY = (FLOAT)CenterY( pSoldier->sGridNo ); + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + FLOAT bodycenterX = (FLOAT) sX; + FLOAT bodycenterY = (FLOAT) sY; FLOAT difftobodycenter = sqrt( (bodycenterX - sWorldX) * (bodycenterX - sWorldX) + (bodycenterY - sWorldY) * (bodycenterY - sWorldY) ); INT32 viewdirectiongridno = NewGridNo( pSoldier->sGridNo, DirectionInc( pSoldier->ubDirection ) ); - FLOAT nextgridnocenterX = (FLOAT)CenterX( viewdirectiongridno ); - FLOAT nextgridnocenterY = (FLOAT)CenterY( viewdirectiongridno ); + ConvertGridNoToCenterCellXY(viewdirectiongridno, &sX, &sY); + FLOAT nextgridnocenterX = (FLOAT) sX; + FLOAT nextgridnocenterY = (FLOAT) sY; FLOAT difftonextgridno = sqrt( (nextgridnocenterX - sWorldX) * (nextgridnocenterX - sWorldX) + (nextgridnocenterY - sWorldY) * (nextgridnocenterY - sWorldY) ); INT32 oppositeviewdirectiongridno = NewGridNo( pSoldier->sGridNo, DirectionInc( gOppositeDirection[pSoldier->ubDirection] ) ); - FLOAT oppositenextgridnocenterX = (FLOAT)CenterX( oppositeviewdirectiongridno ); - FLOAT oppositenextgridnocenterY = (FLOAT)CenterY( oppositeviewdirectiongridno ); + ConvertGridNoToCenterCellXY(oppositeviewdirectiongridno, &sX, &sY); + FLOAT oppositenextgridnocenterX = (FLOAT) sX; + FLOAT oppositenextgridnocenterY = (FLOAT) sY; FLOAT difftooppositenextgridno = sqrt( (oppositenextgridnocenterX - sWorldX) * (oppositenextgridnocenterX - sWorldX) + (oppositenextgridnocenterY - sWorldY) * (oppositenextgridnocenterY - sWorldY) ); @@ -1030,13 +1032,15 @@ UINT8 QuickFindSoldier( INT32 sGridNo ) void GetGridNoScreenPos( INT32 sGridNo, UINT8 ubLevel, INT16 *psScreenX, INT16 *psScreenY ) { - INT16 sScreenX, sScreenY; + INT16 sScreenX, sScreenY, sX, sY; FLOAT dOffsetX, dOffsetY; FLOAT dTempX_S, dTempY_S; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + // Get 'TRUE' merc position - dOffsetX = (FLOAT)( CenterX( sGridNo ) - gsRenderCenterX ); - dOffsetY = (FLOAT)( CenterY( sGridNo ) - gsRenderCenterY ); + dOffsetX = (FLOAT)( sX - gsRenderCenterX ); + dOffsetY = (FLOAT)( sY - gsRenderCenterY ); // OK, DONT'T ASK... CONVERSION TO PROPER Y NEEDS THIS... dOffsetX -= CELL_Y_SIZE; diff --git a/Tactical/Soldier Tile.cpp b/Tactical/Soldier Tile.cpp index b43c0e471..4a3d7037c 100644 --- a/Tactical/Soldier Tile.cpp +++ b/Tactical/Soldier Tile.cpp @@ -738,8 +738,7 @@ BOOLEAN TeleportSoldier( SOLDIERTYPE *pSoldier, INT32 sGridNo, BOOLEAN fForce ) if ( NewOKDestination( pSoldier, sGridNo, TRUE, 0 ) || fForce ) { // TELEPORT TO THIS LOCATION! - sX = CenterX( sGridNo ); - sY = CenterY( sGridNo ); + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); pSoldier->EVENT_SetSoldierPosition( (FLOAT) sX, (FLOAT) sY ); pSoldier->pathing.sFinalDestination = sGridNo; diff --git a/Tactical/Tactical Save.cpp b/Tactical/Tactical Save.cpp index c58a3459c..7a5036705 100644 --- a/Tactical/Tactical Save.cpp +++ b/Tactical/Tactical Save.cpp @@ -1878,8 +1878,10 @@ BOOLEAN LoadRottingCorpsesFromTempCorpseFile( INT16 sMapX, INT16 sMapY, INT8 bMa def.sGridNo = gMapInformation.sWestGridNo; } //Recalculate the dx,dy info - def.dXPos = CenterX( def.sGridNo ); - def.dYPos = CenterY( def.sGridNo ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(def.sGridNo, &sX, &sY); + def.dXPos = sX; + def.dYPos = sY; // If not from loading a save.... if( !(gTacticalStatus.uiFlags & LOADING_SAVED_GAME ) ) { @@ -2737,15 +2739,14 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S memset( &Corpse, 0, sizeof( ROTTING_CORPSE_DEFINITION ) ); // Setup some values! - Corpse.ubBodyType = pSoldier->ubBodyType; - Corpse.sGridNo = sGridNo; + ConvertGridNoToCenterCellXY(sGridNo, &sXPos, &sYPos); - ConvertGridNoToXY( sGridNo, &sXPos, &sYPos ); - - Corpse.dXPos = (FLOAT)( CenterX( sXPos ) ); - Corpse.dYPos = (FLOAT)( CenterY( sYPos ) ); - Corpse.sHeightAdjustment = pSoldier->sHeightAdjustment; - Corpse.bVisible = TRUE; + Corpse.ubBodyType = pSoldier->ubBodyType; + Corpse.sGridNo = sGridNo; + Corpse.dXPos = (FLOAT)( sXPos ); + Corpse.dYPos = (FLOAT)( sYPos ); + Corpse.sHeightAdjustment = pSoldier->sHeightAdjustment; + Corpse.bVisible = TRUE; SET_PALETTEREP_ID ( Corpse.HeadPal, pSoldier->HeadPal ); SET_PALETTEREP_ID ( Corpse.VestPal, pSoldier->VestPal ); diff --git a/Tactical/UI Cursors.cpp b/Tactical/UI Cursors.cpp index b51cd4ff6..241eb810a 100644 --- a/Tactical/UI Cursors.cpp +++ b/Tactical/UI Cursors.cpp @@ -676,8 +676,12 @@ UINT8 HandleActivatedTargetCursor( SOLDIERTYPE *pSoldier, INT32 usMapPos, BOOLEA gCTHDisplay.iTargetGridNo = usMapPos; // Calculate distance to target - FLOAT dDeltaX = (FLOAT)(CenterX( pSoldier->sGridNo ) - CenterX( usMapPos )); - FLOAT dDeltaY = (FLOAT)(CenterY( pSoldier->sGridNo ) - CenterY( usMapPos )); + INT16 sX, sY, sXMap, sYMap; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(usMapPos, &sXMap, &sYMap); + + FLOAT dDeltaX = (FLOAT)( sX - sXMap ); + FLOAT dDeltaY = (FLOAT)( sY - sYMap ); FLOAT d2DDistance = sqrt((dDeltaX*dDeltaX)+(dDeltaY*dDeltaY)); CalcMagFactorSimple( pSoldier, d2DDistance, pSoldier->aiData.bShownAimTime, usMapPos ); @@ -782,8 +786,12 @@ UINT8 HandleActivatedTargetCursor( SOLDIERTYPE *pSoldier, INT32 usMapPos, BOOLEA gbCtHBurstCount = 0; // Calculate distance to target - FLOAT dDeltaX = (FLOAT)(CenterX( pSoldier->sGridNo ) - CenterX( usMapPos )); - FLOAT dDeltaY = (FLOAT)(CenterY( pSoldier->sGridNo ) - CenterY( usMapPos )); + INT16 sX, sY, sXMap, sYMap; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(usMapPos, &sXMap, &sYMap); + + FLOAT dDeltaX = (FLOAT)(sX - sXMap); + FLOAT dDeltaY = (FLOAT)(sY - sYMap); FLOAT d2DDistance = sqrt((dDeltaX*dDeltaX)+(dDeltaY*dDeltaY)); CalcMagFactorSimple( pSoldier, d2DDistance, pSoldier->aiData.bShownAimTime, usMapPos ); @@ -884,8 +892,12 @@ UINT8 HandleActivatedTargetCursor( SOLDIERTYPE *pSoldier, INT32 usMapPos, BOOLEA gCTHDisplay.iTargetGridNo = usMapPos; // Calculate distance to target - FLOAT dDeltaX = (FLOAT)(CenterX( pSoldier->sGridNo ) - CenterX( usMapPos )); - FLOAT dDeltaY = (FLOAT)(CenterY( pSoldier->sGridNo ) - CenterY( usMapPos )); + INT16 sX, sY, sXMap, sYMap; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(usMapPos, &sXMap, &sYMap); + + FLOAT dDeltaX = (FLOAT)(sX - sXMap); + FLOAT dDeltaY = (FLOAT)(sY - sYMap); FLOAT d2DDistance = sqrt((dDeltaX*dDeltaX)+(dDeltaY*dDeltaY)); CalcMagFactorSimple( pSoldier, d2DDistance, pSoldier->aiData.bShownAimTime, usMapPos ); diff --git a/Tactical/Vehicles.cpp b/Tactical/Vehicles.cpp index d67d18ae9..d954d75aa 100644 --- a/Tactical/Vehicles.cpp +++ b/Tactical/Vehicles.cpp @@ -1787,7 +1787,9 @@ BOOLEAN ExitVehicle( SOLDIERTYPE *pSoldier ) pSoldier->aiData.bOppList[ pVehicle->ubID ] = 1; // Add to sector.... - pSoldier->EVENT_SetSoldierPosition( CenterX( sGridNo ), CenterY( sGridNo ) ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + pSoldier->EVENT_SetSoldierPosition( sX, sY ); // anv: since now they can shoot it's important to set passenger to proper stance // namely, back to standing, because we set them to crouching when entering @@ -2064,7 +2066,9 @@ void HandleCriticalHitForVehicleInLocation( UINT8 ubID, INT16 sDmg, INT32 sGridN pVehicleList[ ubID ].fDestroyed = TRUE; // Explode vehicle... - IgniteExplosion( ubAttackerID, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, GREAT_BIG_EXPLOSION, 0 ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + IgniteExplosion( ubAttackerID, sX, sY, 0, sGridNo, GREAT_BIG_EXPLOSION, 0 ); if ( pSoldier != NULL ) { diff --git a/Tactical/Weapons.cpp b/Tactical/Weapons.cpp index 667f9be46..cdc60e02a 100644 --- a/Tactical/Weapons.cpp +++ b/Tactical/Weapons.cpp @@ -1714,7 +1714,7 @@ void GetTargetWorldPositions( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo, FLOAT FLOAT dTargetZ; SOLDIERTYPE* pTargetSoldier = NULL; INT8 bStructHeight; - INT16 sXMapPos, sYMapPos; + INT16 sXMapPos, sYMapPos, sX, sY; UINT32 uiRoll; INT8 bTargetCubeLevel = 0; INT8 bTargetLevel = 0; @@ -1731,8 +1731,9 @@ void GetTargetWorldPositions( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo, FLOAT { // SAVE OPP ID pSoldier->ubOppNum = pTargetSoldier->ubID; - dTargetX = (FLOAT) CenterX( pTargetSoldier->sGridNo ); - dTargetY = (FLOAT) CenterY( pTargetSoldier->sGridNo ); + ConvertGridNoToCenterCellXY(pTargetSoldier->sGridNo, &sX, &sY); + dTargetX = (FLOAT) sX; + dTargetY = (FLOAT) sY; if (pSoldier->bAimShotLocation == AIM_SHOT_RANDOM) { uiRoll = PreRandom( 100 ); @@ -1773,9 +1774,11 @@ void GetTargetWorldPositions( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo, FLOAT if ( gGameExternalOptions.fAllowTargetHeadAndLegIfProne && gAnimControl[pTargetSoldier->usAnimState].ubHeight == ANIM_PRONE ) { INT32 viewdirectiongridno = NewGridNo( pTargetSoldier->sGridNo, DirectionInc( pTargetSoldier->ubDirection ) ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(viewdirectiongridno, &sX, &sY); - dTargetX = (0.3f * dTargetX + 0.7f * (FLOAT)CenterX( viewdirectiongridno )) / 1.0f; - dTargetY = (0.3f * dTargetY + 0.7f * (FLOAT)CenterY( viewdirectiongridno )) / 1.0f; + dTargetX = (0.3f * dTargetX + 0.7f * (FLOAT)sX) / 1.0f; + dTargetY = (0.3f * dTargetY + 0.7f * (FLOAT)sY) / 1.0f; } } break; @@ -1789,9 +1792,11 @@ void GetTargetWorldPositions( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo, FLOAT if ( gGameExternalOptions.fAllowTargetHeadAndLegIfProne && gAnimControl[pTargetSoldier->usAnimState].ubHeight == ANIM_PRONE ) { INT32 viewdirectiongridno = NewGridNo( pTargetSoldier->sGridNo, DirectionInc( gOppositeDirection[pTargetSoldier->ubDirection] ) ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(viewdirectiongridno, &sX, &sY); - dTargetX = (0.3f * dTargetX + 0.7f * (FLOAT)CenterX( viewdirectiongridno )) / 1.0f; - dTargetY = (0.3f * dTargetY + 0.7f * (FLOAT)CenterY( viewdirectiongridno )) / 1.0f; + dTargetX = (0.3f * dTargetX + 0.7f * (FLOAT)sX) / 1.0f; + dTargetY = (0.3f * dTargetY + 0.7f * (FLOAT)sY) / 1.0f; } } break; @@ -2718,11 +2723,14 @@ BOOLEAN UseGunNCTH( SOLDIERTYPE *pSoldier , INT32 sTargetGridNo ) { if ( WillExplosiveWeaponFail( pSoldier, pObjHand ) ) { + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + if ( Item[usUBItem].singleshotrocketlauncher ) { CreateItem( Item[usItemNum].discardedlauncheritem , (*pObjHand)[0]->data.objectStatus, pObjHand ); - // Flugente: why would we keep a piece of scrap in our ahnds in the first place? just drop it to the ground + // Flugente: why would we keep a piece of scrap in our hands in the first place? just drop it to the ground AddItemToPool( pSoldier->sGridNo, pObjHand, 1, pSoldier->pathing.bLevel, 0, -1 ); // Delete object @@ -2730,20 +2738,21 @@ BOOLEAN UseGunNCTH( SOLDIERTYPE *pSoldier , INT32 sTargetGridNo ) DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 ); + if ( Item[usUBItem].usBuddyItem != 0 && Item[Item[usUBItem].usBuddyItem].usItemClass & IC_EXPLOSV ) { - IgniteExplosion( pSoldier->ubID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, Item[usUBItem].usBuddyItem, pSoldier->pathing.bLevel ); + IgniteExplosion( pSoldier->ubID, sX, sY, 0, pSoldier->sGridNo, Item[usUBItem].usBuddyItem, pSoldier->pathing.bLevel ); } else { - IgniteExplosion( pSoldier->ubID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, C1, pSoldier->pathing.bLevel ); + IgniteExplosion( pSoldier->ubID, sX, sY, 0, pSoldier->sGridNo, C1, pSoldier->pathing.bLevel ); } } else { DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("StructureHit: RPG7 item: %d, Ammo: %d", usUBItem , (*pObjHand)[0]->data.gun.usGunAmmoItem ) ); - IgniteExplosion( pSoldier->ubID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, (*pObjHand)[0]->data.gun.usGunAmmoItem, pSoldier->pathing.bLevel ); + IgniteExplosion( pSoldier->ubID, sX, sY, 0, pSoldier->sGridNo, (*pObjHand)[0]->data.gun.usGunAmmoItem, pSoldier->pathing.bLevel ); pSoldier->inv[pSoldier->ubAttackingHand ][0]->data.gun.usGunAmmoItem = NONE; } // Reduce again for attack end 'cause it has been incremented for a normal attack @@ -2893,8 +2902,8 @@ BOOLEAN UseGunNCTH( SOLDIERTYPE *pSoldier , INT32 sTargetGridNo ) { sTempGridNo = NewGridNo(sTempGridNo, DirectionInc(pSoldier->ubDirection)); } - INT16 sX = CenterX(sTempGridNo); - INT16 sY = CenterY(sTempGridNo); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sTempGridNo, &sX, &sY); AniParams.sGridNo = pSoldier->sGridNo; AniParams.ubLevelID = ANI_TOPMOST_LEVEL; @@ -3643,6 +3652,9 @@ BOOLEAN UseGun( SOLDIERTYPE *pSoldier , INT32 sTargetGridNo ) { if ( WillExplosiveWeaponFail( pSoldier, pObjUsed ) ) { + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + if ( Item[usUBItem].singleshotrocketlauncher ) { CreateItem( Item[usUBItem].discardedlauncheritem , (*pObjUsed)[0]->data.objectStatus, pObjUsed ); @@ -3655,20 +3667,21 @@ BOOLEAN UseGun( SOLDIERTYPE *pSoldier , INT32 sTargetGridNo ) DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 ); + if ( Item[usUBItem].usBuddyItem != 0 && Item[Item[usUBItem].usBuddyItem].usItemClass & IC_EXPLOSV ) { - IgniteExplosion( pSoldier->ubID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, C1, pSoldier->pathing.bLevel ); + IgniteExplosion( pSoldier->ubID, sX, sY, 0, pSoldier->sGridNo, C1, pSoldier->pathing.bLevel ); } else { - IgniteExplosion( pSoldier->ubID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, C1, pSoldier->pathing.bLevel ); + IgniteExplosion( pSoldier->ubID, sX, sY, 0, pSoldier->sGridNo, C1, pSoldier->pathing.bLevel ); } } else { DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("StructureHit: RPG7 item: %d, Ammo: %d", usUBItem , (*pObjUsed)[0]->data.gun.usGunAmmoItem ) ); - IgniteExplosion( pSoldier->ubID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, (*pObjUsed)[0]->data.gun.usGunAmmoItem, pSoldier->pathing.bLevel ); + IgniteExplosion( pSoldier->ubID, sX, sY, 0, pSoldier->sGridNo, (*pObjUsed)[0]->data.gun.usGunAmmoItem, pSoldier->pathing.bLevel ); OBJECTTYPE * pLaunchable = FindLaunchableAttachment( pObjUsed, usUBItem ); if(pLaunchable) @@ -3708,8 +3721,8 @@ BOOLEAN UseGun( SOLDIERTYPE *pSoldier , INT32 sTargetGridNo ) { sTempGridNo = NewGridNo(sTempGridNo, DirectionInc(pSoldier->ubDirection)); } - INT16 sX = CenterX(sTempGridNo); - INT16 sY = CenterY(sTempGridNo); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sTempGridNo, &sX, &sY); AniParams.sGridNo = pSoldier->sGridNo; AniParams.ubLevelID = ANI_TOPMOST_LEVEL; @@ -5167,7 +5180,9 @@ BOOLEAN UseLauncher( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo ) // So we still should have ABC > 0 // Begin explosion due to failure... - IgniteExplosion( pSoldier->ubID, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, Launchable.usItem, pSoldier->pathing.bLevel ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + IgniteExplosion( pSoldier->ubID, sX, sY, 0, pSoldier->sGridNo, Launchable.usItem, pSoldier->pathing.bLevel ); // Reduce again for attack end 'cause it has been incremented for a normal attack // Nope, not anymore. @@ -5676,15 +5691,18 @@ void StructureHit( INT32 iBullet, UINT16 usWeaponIndex, INT16 bWeaponStatus, UIN // HEADROCK HAM 5: Fragments fired by such weapons should not explode. if ( pBullet->fFragment == false) { + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + if ( Item[usWeaponIndex].singleshotrocketlauncher ) { if ( Item[usWeaponIndex].usBuddyItem != 0 && Item[Item[usWeaponIndex].usBuddyItem].usItemClass & IC_EXPLOSV ) { - IgniteExplosion( ubAttackerID, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, Item[usWeaponIndex].usBuddyItem, bLevel, usDirection ); + IgniteExplosion( ubAttackerID, sX, sY, 0, sGridNo, Item[usWeaponIndex].usBuddyItem, bLevel, usDirection ); } else { - IgniteExplosion( ubAttackerID, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, C1, bLevel, usDirection ); + IgniteExplosion( ubAttackerID, sX, sY, 0, sGridNo, C1, bLevel, usDirection ); } } // changed too to use 2 flag to determine @@ -5692,7 +5710,7 @@ void StructureHit( INT32 iBullet, UINT16 usWeaponIndex, INT16 bWeaponStatus, UIN //there shouldn't be a way to enter here with an UnderBarrel weapon, so retaining original code :JMich { DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("StructureHit: RPG7 item: %d, Ammo: %d",pAttacker->inv[HANDPOS].usItem , pAttacker->inv[HANDPOS][0]->data.gun.usGunAmmoItem ) ); - IgniteExplosion( ubAttackerID, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, pAttacker->inv[pAttacker->ubAttackingHand][0]->data.gun.usGunAmmoItem, bLevel, usDirection ); + IgniteExplosion( ubAttackerID, sX, sY, 0, sGridNo, pAttacker->inv[pAttacker->ubAttackingHand][0]->data.gun.usGunAmmoItem, bLevel, usDirection ); //This is just to make multishot launchers work in semi auto. It's not really a permanent solution because it still doesn't allow autofire, but it will do for now. OBJECTTYPE * pLaunchable = FindLaunchableAttachment( &(pAttacker->inv[pAttacker->ubAttackingHand ]), pAttacker->inv[pAttacker->ubAttackingHand ].usItem ); @@ -5708,7 +5726,7 @@ void StructureHit( INT32 iBullet, UINT16 usWeaponIndex, INT16 bWeaponStatus, UIN else if ( AmmoTypes[(*pObj)[0]->data.gun.ubGunAmmoType].explosionSize > 1) { // re-routed the Highexplosive value to define exposion type - IgniteExplosion( ubAttackerID, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, AmmoTypes[(*pObj)[0]->data.gun.ubGunAmmoType].highExplosive, bLevel, usDirection ); + IgniteExplosion( ubAttackerID, sX, sY, 0, sGridNo, AmmoTypes[(*pObj)[0]->data.gun.ubGunAmmoType].highExplosive, bLevel, usDirection ); // pSoldier->inv[pSoldier->ubAttackingHand ][0]->data.gun.usGunAmmoItem = NONE; } } @@ -5726,7 +5744,9 @@ void StructureHit( INT32 iBullet, UINT16 usWeaponIndex, INT16 bWeaponStatus, UIN //FreeUpAttacker( ubAttackerID ); // HEADROCK HAM 5 TODO: Tank shell!! - IgniteExplosion( ubAttackerID, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, TANK_SHELL, bLevel, usDirection ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + IgniteExplosion( ubAttackerID, sX, sY, 0, sGridNo, TANK_SHELL, bLevel, usDirection ); //FreeUpAttacker( (UINT8) ubAttackerID ); // Moved here to keep ABC >0 as long as possible @@ -6250,7 +6270,7 @@ UINT32 CalcNewChanceToHitGun(SOLDIERTYPE *pSoldier, INT32 sGridNo, INT16 ubAimTi // Basic defines SOLDIERTYPE * pTarget; INT32 iRange, iSightRange; //, minRange; - + INT16 sX, sY, sX2, sY2; UINT16 usInHand; OBJECTTYPE * pInHand; INT16 sDistVis, sDistVisNoScope; @@ -6270,8 +6290,11 @@ UINT32 CalcNewChanceToHitGun(SOLDIERTYPE *pSoldier, INT32 sGridNo, INT16 ubAimTi // calculate actual range (in units, 10 units = 1 tile) iRange = GetRangeInCellCoordsFromGridNoDiff( pSoldier->sGridNo, sGridNo ); - FLOAT dDeltaX = (FLOAT)(CenterX( pSoldier->sGridNo ) - CenterX( sGridNo )); - FLOAT dDeltaY = (FLOAT)(CenterY( pSoldier->sGridNo ) - CenterY( sGridNo )); + + ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY); + ConvertGridNoToCenterCellXY(sGridNo, &sX2, &sY2); + FLOAT dDeltaX = (FLOAT)( sX - sX2 ); + FLOAT dDeltaY = (FLOAT)( sY - sY2 ); FLOAT d2DDistance = sqrt((dDeltaX*dDeltaX)+(dDeltaY*dDeltaY)); // Find a target in the tile diff --git a/Tactical/opplist.cpp b/Tactical/opplist.cpp index 274413f91..2b8c8cc01 100644 --- a/Tactical/opplist.cpp +++ b/Tactical/opplist.cpp @@ -6130,10 +6130,8 @@ void ProcessNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrTy { // ALL RIGHT! Passed all the tests, this listener hears this noise!!! HearNoise(pSoldier,ubSource,sGridNo,bLevel,ubEffVolume,ubNoiseType, (UINT8 *)&bSeen); - bHeard = TRUE; - - ubNoiseDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sGridNo),CenterY(sGridNo)); + ubNoiseDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sGridNo); // check the 'noise heard & reported' bit for that soldier & direction if ( ubNoiseType != NOISE_MOVEMENT || bTeam != OUR_TEAM || (pSoldier->aiData.bInterruptDuelPts != NO_INTERRUPT) || !(pSoldier->ubMovementNoiseHeard & (1 << ubNoiseDir) ) ) @@ -6441,8 +6439,7 @@ void HearNoise(SOLDIERTYPE *pSoldier, UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bL // ignore muzzle flashes when turning head to see noise if ( ubNoiseType == NOISE_GUNFIRE && ubNoiseMaker != NOBODY && MercPtrs[ ubNoiseMaker ]->flags.fMuzzleFlash ) { - sNoiseX = CenterX(sGridNo); - sNoiseY = CenterY(sGridNo); + ConvertGridNoToCenterCellXY(sGridNo, &sNoiseX, &sNoiseY); bDirection = atan8(pSoldier->sX,pSoldier->sY,sNoiseX,sNoiseY); if ( pSoldier->ubDirection != bDirection && pSoldier->ubDirection != gOneCDirection[ bDirection ] && pSoldier->ubDirection != gOneCCDirection[ bDirection ] ) { @@ -6463,8 +6460,7 @@ void HearNoise(SOLDIERTYPE *pSoldier, UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bL if (PythSpacesAway(pSoldier->sGridNo,sGridNo) <= sDistVisible ) { // just use the XXadjustedXX center of the gridno - sNoiseX = CenterX(sGridNo); - sNoiseY = CenterY(sGridNo); + ConvertGridNoToCenterCellXY(sGridNo, &sNoiseX, &sNoiseY); if (pSoldier->ubDirection != atan8(pSoldier->sX,pSoldier->sY,sNoiseX,sNoiseY)) { diff --git a/TacticalAI/AIUtils.cpp b/TacticalAI/AIUtils.cpp index 2f947a9fe..8b42fb29b 100644 --- a/TacticalAI/AIUtils.cpp +++ b/TacticalAI/AIUtils.cpp @@ -144,7 +144,7 @@ BOOLEAN ConsiderProne( SOLDIERTYPE * pSoldier ) } // We don't want to go prone if there is a nearby enemy ClosestKnownOpponent( pSoldier, &sOpponentGridNo, &bOpponentLevel ); - iRange = GetRangeFromGridNoDiff( pSoldier->sGridNo, sOpponentGridNo ); + iRange = PythSpacesAway( pSoldier->sGridNo, sOpponentGridNo ); if (iRange > 10) { return( TRUE ); @@ -2724,7 +2724,7 @@ INT32 CalcManThreatValue( SOLDIERTYPE *pEnemy, INT32 sMyGrid, UINT8 ubReduceForC else { // ADD 5% if man's already facing me - if (pEnemy->ubDirection == atan8(CenterX(pEnemy->sGridNo),CenterY(pEnemy->sGridNo),CenterX(sMyGrid),CenterY(sMyGrid))) + if (pEnemy->ubDirection == GetDirectionFromCenterCellXYGridNo(pEnemy->sGridNo, sMyGrid)) { iThreatValue += (iThreatValue / 20); } @@ -3619,13 +3619,13 @@ UINT8 CountFriendsInDirection( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo ) CHECKF(pSoldier); - ubMyDir = atan8(CenterX(sTargetGridNo),CenterY(sTargetGridNo),CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo)); + ubMyDir = GetDirectionFromCenterCellXYGridNo(sTargetGridNo, pSoldier->sGridNo); // Run through each friendly. for ( UINT8 iCounter = gTacticalStatus.Team[ pSoldier->bTeam ].bFirstID ; iCounter <= gTacticalStatus.Team[ pSoldier->bTeam ].bLastID ; iCounter ++ ) { pFriend = MercPtrs[ iCounter ]; - ubFriendDir = atan8(CenterX(sTargetGridNo),CenterY(sTargetGridNo),CenterX(pFriend->sGridNo),CenterY(pFriend->sGridNo)); + ubFriendDir = GetDirectionFromCenterCellXYGridNo(sTargetGridNo, pFriend->sGridNo); if (pFriend != pSoldier && pFriend->bActive && @@ -4811,7 +4811,7 @@ BOOLEAN AnyCoverFromSpot( INT32 sSpot, INT8 bLevel, INT32 sThreatLoc, INT8 bThre return FALSE; } - ubDirection = atan8(CenterX(sSpot), CenterY(sSpot), CenterX(sThreatLoc), CenterY(sThreatLoc)); + ubDirection = GetDirectionFromCenterCellXYGridNo(sSpot, sThreatLoc); sCoverSpot = NewGridNo( sSpot, DirectionInc( ubDirection ) ); if ( TileIsOutOfBounds( sCoverSpot ) ) @@ -5001,7 +5001,7 @@ UINT8 AIDirection(INT32 sSpot1, INT32 sSpot2) return DIRECTION_IRRELEVANT; } - return atan8(CenterX(sSpot1), CenterY(sSpot1), CenterX(sSpot2), CenterY(sSpot2)); + return GetDirectionFromCenterCellXYGridNo(sSpot1, sSpot2); } BOOLEAN AICheckIsSniper(SOLDIERTYPE *pSoldier) diff --git a/TacticalAI/Attacks.cpp b/TacticalAI/Attacks.cpp index c2dc03cd0..b3e9f1837 100644 --- a/TacticalAI/Attacks.cpp +++ b/TacticalAI/Attacks.cpp @@ -783,7 +783,6 @@ BOOLEAN CloseEnoughForGrenadeToss( INT32 sGridNo, INT32 sGridNo2 ) { INT32 sTempGridNo; UINT8 ubDirection; - INT16 sXPos, sYPos, sXPos2, sYPos2; UINT8 ubMovementCost; if (sGridNo == sGridNo2 ) @@ -815,13 +814,7 @@ BOOLEAN CloseEnoughForGrenadeToss( INT32 sGridNo, INT32 sGridNo2 ) // so we can now do a loop safely sTempGridNo = sGridNo; - - sXPos = CenterX( sGridNo ); - sYPos = CenterY( sGridNo ); - sXPos2 = CenterX( sGridNo2 ); - sYPos2 = CenterY( sGridNo2 ); - ubDirection = atan8( sXPos, sYPos, sXPos2, sYPos2 ); - + ubDirection = GetDirectionFromCenterCellXYGridNo(sGridNo, sGridNo2); // For each step of the loop, we are checking for door or obstacle movement costs. If we // find we're blocked, then this is no good for grenade tossing! do diff --git a/TacticalAI/CreatureDecideAction.cpp b/TacticalAI/CreatureDecideAction.cpp index bb74c226e..94fa1e186 100644 --- a/TacticalAI/CreatureDecideAction.cpp +++ b/TacticalAI/CreatureDecideAction.cpp @@ -481,7 +481,7 @@ INT8 CreatureDecideActionYellow( SOLDIERTYPE * pSoldier ) if (pSoldier->aiData.bMobility != CREATURE_IMMOBILE) { // determine direction from this soldier in which the noise lies - ubNoiseDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sNoiseGridNo),CenterY(sNoiseGridNo)); + ubNoiseDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sNoiseGridNo); // if soldier is not already facing in that direction, // and the noise source is close enough that it could possibly be seen @@ -849,7 +849,7 @@ INT8 CreatureDecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK) if (!TileIsOutOfBounds(sClosestOpponent)) { // determine direction from this soldier to the closest opponent - ubOpponentDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent)); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestOpponent); // if soldier is not already facing in that direction, // and the opponent is close enough that he could possibly be seen @@ -1410,7 +1410,7 @@ INT8 CreatureDecideActionBlack( SOLDIERTYPE * pSoldier ) } else if (GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints) // turn to face enemy { - bDirection = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent)); + bDirection = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestOpponent); // if we're not facing towards him if (pSoldier->ubDirection != bDirection && ValidCreatureTurn( pSoldier, bDirection ) ) diff --git a/TacticalAI/DecideAction.cpp b/TacticalAI/DecideAction.cpp index eb421ce88..e4a1e0ad7 100644 --- a/TacticalAI/DecideAction.cpp +++ b/TacticalAI/DecideAction.cpp @@ -473,8 +473,7 @@ INT8 DecideActionSchedule( SOLDIERTYPE * pSoldier ) switch( pSoldier->bAIScheduleProgress ) { case 0: - sX = CenterX( pSoldier->sOffWorldGridNo ); - sY = CenterY( pSoldier->sOffWorldGridNo ); + ConvertGridNoToCenterCellXY(pSoldier->sOffWorldGridNo, &sX, &sY); pSoldier->EVENT_SetSoldierPosition( sX, sY ); pSoldier->bInSector = TRUE; MoveSoldierFromAwayToMercSlot( pSoldier ); @@ -565,7 +564,7 @@ INT8 DecideActionBoxerEnteringRing(SOLDIERTYPE *pSoldier) if (!TileIsOutOfBounds(sDesiredMercLoc)) { // see if we are facing this person - ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sDesiredMercLoc),CenterY(sDesiredMercLoc)); + ubDesiredMercDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sDesiredMercLoc); // if not already facing in that direction, if ( pSoldier->ubDirection != ubDesiredMercDir && pSoldier->InternalIsValidStance( ubDesiredMercDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) ) @@ -626,7 +625,7 @@ INT8 DecideActionNamedNPC( SOLDIERTYPE * pSoldier ) } // see if we are facing this person - ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sDesiredMercLoc),CenterY(sDesiredMercLoc)); + ubDesiredMercDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sDesiredMercLoc); // if not already facing in that direction, if (pSoldier->ubDirection != ubDesiredMercDir && pSoldier->InternalIsValidStance( ubDesiredMercDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) ) @@ -782,7 +781,7 @@ INT8 DecideActionGreen(SOLDIERTYPE *pSoldier) UINT8 ubRingDir; // face ring! - ubRingDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(CENTER_OF_RING),CenterY(CENTER_OF_RING)); + ubRingDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, CENTER_OF_RING); if ( gfTurnBasedAI || GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints ) { if ( pSoldier->ubDirection != ubRingDir ) @@ -966,7 +965,7 @@ INT8 DecideActionGreen(SOLDIERTYPE *pSoldier) if ( PythSpacesAway(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo) < 2 ) { // see if we are facing this person - UINT8 ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(MercPtrs[ubPerson]->sGridNo),CenterY(MercPtrs[ubPerson]->sGridNo)); + UINT8 ubDesiredMercDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo); // if not already facing in that direction, if ( pSoldier->ubDirection != ubDesiredMercDir ) @@ -1495,8 +1494,7 @@ INT8 DecideActionGreen(SOLDIERTYPE *pSoldier) UINT8 ubNoiseDir; if (TileIsOutOfBounds(sNoiseGridNo) || - (ubNoiseDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sNoiseGridNo),CenterY(sNoiseGridNo)) - ) == pSoldier->ubDirection ) + ( ubNoiseDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sNoiseGridNo) ) == pSoldier->ubDirection ) { pSoldier->aiData.usActionData = PreRandom(8); @@ -1668,7 +1666,7 @@ INT8 DecideActionYellow(SOLDIERTYPE *pSoldier) if ( PythSpacesAway(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo) < 2 ) { // see if we are facing this person - UINT8 ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(MercPtrs[ubPerson]->sGridNo),CenterY(MercPtrs[ubPerson]->sGridNo)); + UINT8 ubDesiredMercDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo); // if not already facing in that direction, if ( pSoldier->ubDirection != ubDesiredMercDir ) @@ -1721,7 +1719,7 @@ INT8 DecideActionYellow(SOLDIERTYPE *pSoldier) if ( PythSpacesAway(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo) < 2 ) { // see if we are facing this person - UINT8 ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(MercPtrs[ubPerson]->sGridNo),CenterY(MercPtrs[ubPerson]->sGridNo)); + UINT8 ubDesiredMercDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo); // if not already facing in that direction, if ( pSoldier->ubDirection != ubDesiredMercDir ) @@ -1798,7 +1796,7 @@ INT8 DecideActionYellow(SOLDIERTYPE *pSoldier) //////////////////////////////////////////////////////////////////////////// // determine direction from this soldier in which the noise lies - ubNoiseDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sNoiseGridNo),CenterY(sNoiseGridNo)); + ubNoiseDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sNoiseGridNo); // if soldier is not already facing in that direction, // and the noise source is close enough that it could possibly be seen @@ -3293,7 +3291,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier) if ( PythSpacesAway(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo) < 2 ) { // see if we are facing this person - UINT8 ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(MercPtrs[ubPerson]->sGridNo),CenterY(MercPtrs[ubPerson]->sGridNo)); + UINT8 ubDesiredMercDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo); // if not already facing in that direction, if ( pSoldier->ubDirection != ubDesiredMercDir ) @@ -3341,7 +3339,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier) if ( PythSpacesAway(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo) < 2 ) { // see if we are facing this person - UINT8 ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(MercPtrs[ubPerson]->sGridNo),CenterY(MercPtrs[ubPerson]->sGridNo)); + UINT8 ubDesiredMercDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, MercPtrs[ubPerson]->sGridNo); // if not already facing in that direction, if ( pSoldier->ubDirection != ubDesiredMercDir ) @@ -4521,7 +4519,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier) if (!TileIsOutOfBounds(sClosestOpponent)) { // determine direction from this soldier to the closest opponent - ubOpponentDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent)); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestOpponent); // if soldier is not already facing in that direction, // and the opponent is close enough that he could possibly be seen @@ -4625,7 +4623,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier) if (!TileIsOutOfBounds(sClosestDisturbance)) { - ubOpponentDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sClosestDisturbance ), CenterY( sClosestDisturbance ) ); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestDisturbance); if ( pSoldier->ubDirection == ubOpponentDir ) { ubOpponentDir = (UINT8) PreRandom( NUM_WORLD_DIRECTIONS ); @@ -4768,7 +4766,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier) if (!gfTurnBasedAI || (GetAPsToReadyWeapon( pSoldier, READY_RIFLE_CROUCH ) + GetAPsToChangeStance( pSoldier, ANIM_CROUCH )) <= pSoldier->bActionPoints) { // determine direction from this soldier to the closest opponent - ubOpponentDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent)); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestOpponent); if (!WeaponReady(pSoldier) && pSoldier->ubDirection == ubOpponentDir && @@ -4802,7 +4800,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier) if (!TileIsOutOfBounds(sClosestDisturbance)) { - ubOpponentDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sClosestDisturbance ), CenterY( sClosestDisturbance ) ); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestDisturbance); if ( pSoldier->ubDirection != ubOpponentDir ) { if ( !gfTurnBasedAI || GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints ) @@ -6994,7 +6992,7 @@ L_NEWAIM: if(!TileIsOutOfBounds(pSoldier->sLastTarget)) sClosestOpponent = pSoldier->sLastTarget; pSoldier->aiData.bNextAction = AI_ACTION_CHANGE_FACING; - pSoldier->aiData.usNextActionData = atan8(CenterX(sBestCover),CenterY(sBestCover),CenterX(sClosestOpponent),CenterY(sClosestOpponent)); + pSoldier->aiData.usNextActionData = GetDirectionFromCenterCellXYGridNo(sBestCover, sClosestOpponent); } return(AI_ACTION_TAKE_COVER); } @@ -7088,7 +7086,7 @@ L_NEWAIM: // if we have a closest seen opponent if (!TileIsOutOfBounds(sClosestOpponent)) { - bDirection = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent)); + bDirection = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestOpponent); // if we're not facing towards him if (pSoldier->ubDirection != bDirection) @@ -7149,7 +7147,7 @@ L_NEWAIM: { if(!TileIsOutOfBounds(pSoldier->sLastTarget))//dnl ch58 150913 sClosestOpponent = pSoldier->sLastTarget; - bDirection = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent)); + bDirection = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestOpponent); // if we're not facing towards him if ( pSoldier->ubDirection != bDirection && pSoldier->InternalIsValidStance( bDirection, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) ) @@ -7801,7 +7799,7 @@ INT8 ArmedVehicleDecideActionGreen( SOLDIERTYPE *pSoldier ) UINT8 ubNoiseDir; if ( TileIsOutOfBounds( sNoiseGridNo ) || - (ubNoiseDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sNoiseGridNo ), CenterY( sNoiseGridNo ) ) + (ubNoiseDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sNoiseGridNo) ) == pSoldier->ubDirection ) { @@ -7904,7 +7902,7 @@ INT8 ArmedVehicleDecideActionYellow( SOLDIERTYPE *pSoldier ) //////////////////////////////////////////////////////////////////////////// // determine direction from this soldier in which the noise lies - ubNoiseDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sNoiseGridNo ), CenterY( sNoiseGridNo ) ); + ubNoiseDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sNoiseGridNo); // if soldier is not already facing in that direction, // and the noise source is close enough that it could possibly be seen @@ -9153,7 +9151,7 @@ INT8 ArmedVehicleDecideActionRed( SOLDIERTYPE *pSoldier) if ( bHighestWatchLoc != -1 ) { // see if we need turn to face that location - ubOpponentDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( gsWatchedLoc[pSoldier->ubID][bHighestWatchLoc] ), CenterY( gsWatchedLoc[pSoldier->ubID][bHighestWatchLoc] ) ); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, gsWatchedLoc[pSoldier->ubID][bHighestWatchLoc]); // if soldier is not already facing in that direction, // and the opponent is close enough that he could possibly be seen @@ -9339,7 +9337,7 @@ INT8 ArmedVehicleDecideActionRed( SOLDIERTYPE *pSoldier) if ( !TileIsOutOfBounds( sClosestOpponent ) ) { // determine direction from this soldier to the closest opponent - ubOpponentDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sClosestOpponent ), CenterY( sClosestOpponent ) ); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestOpponent); // if soldier is not already facing in that direction, // and the opponent is close enough that he could possibly be seen @@ -9384,7 +9382,7 @@ INT8 ArmedVehicleDecideActionRed( SOLDIERTYPE *pSoldier) if ( !TileIsOutOfBounds( sClosestDisturbance ) ) { - ubOpponentDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sClosestDisturbance ), CenterY( sClosestDisturbance ) ); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestDisturbance); if ( pSoldier->ubDirection == ubOpponentDir ) { ubOpponentDir = (UINT8)PreRandom( NUM_WORLD_DIRECTIONS ); @@ -9435,7 +9433,7 @@ INT8 ArmedVehicleDecideActionRed( SOLDIERTYPE *pSoldier) if ( !TileIsOutOfBounds( sClosestDisturbance ) ) { - ubOpponentDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sClosestDisturbance ), CenterY( sClosestDisturbance ) ); + ubOpponentDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestDisturbance); if ( pSoldier->ubDirection != ubOpponentDir ) { if ( !gfTurnBasedAI || GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints ) @@ -10019,7 +10017,7 @@ INT8 ArmedVehicleDecideActionBlack( SOLDIERTYPE *pSoldier ) if ( gGameExternalOptions.fEnemyTanksCanMoveInTactical ) { // first get the direction, as we will need to pass that in to ShootingStanceChange - bDirection = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( BestAttack.sTarget ), CenterY( BestAttack.sTarget ) ); + bDirection = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, BestAttack.sTarget); // Change facing if ( pSoldier->ubDirection != bDirection && pSoldier->InternalIsValidStance( bDirection, gAnimControl[pSoldier->usAnimState].ubEndHeight ) ) @@ -10306,7 +10304,7 @@ INT8 ArmedVehicleDecideActionBlack( SOLDIERTYPE *pSoldier ) { if ( !TileIsOutOfBounds( pSoldier->sLastTarget ) )//dnl ch58 150913 sClosestOpponent = pSoldier->sLastTarget; - bDirection = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sClosestOpponent ), CenterY( sClosestOpponent ) ); + bDirection = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sClosestOpponent); // if we're not facing towards him if ( pSoldier->ubDirection != bDirection && pSoldier->InternalIsValidStance( bDirection, gAnimControl[pSoldier->usAnimState].ubEndHeight ) ) diff --git a/TileEngine/Explosion Control.cpp b/TileEngine/Explosion Control.cpp index 85df4d393..fac8bc3e5 100644 --- a/TileEngine/Explosion Control.cpp +++ b/TileEngine/Explosion Control.cpp @@ -698,8 +698,7 @@ INT8 ExplosiveDamageStructureAtGridNo( STRUCTURE * pCurrent, STRUCTURE **ppNextC #endif // Get xy - sX = CenterX( sGridNo ); - sY = CenterY( sGridNo ); + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); // ATE: Continue if we are only looking for walls if ( fOnlyWalls && !( pCurrent->fFlags & STRUCTURE_WALLSTUFF ) ) @@ -1305,7 +1304,9 @@ INT8 ExplosiveDamageStructureAtGridNo( STRUCTURE * pCurrent, STRUCTURE **ppNextC // Make secondary explosion if eplosive.... if ( fExplosive ) { - InternalIgniteExplosion( ubOwner, CenterX( sBaseGridNo ), CenterY( sBaseGridNo ), 0, sBaseGridNo, STRUCTURE_EXPLOSION, FALSE, bLevel ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sBaseGridNo, &sX, &sY); + InternalIgniteExplosion( ubOwner, sX, sY, 0, sBaseGridNo, STRUCTURE_EXPLOSION, FALSE, bLevel ); } } @@ -1477,7 +1478,9 @@ void ExplosiveDamageGridNo( INT32 sGridNo, INT16 sWoundAmt, UINT32 uiDist, BOOLE } { - InternalIgniteExplosion( ubOwner, CenterX( sNewGridNo2 ), CenterY( sNewGridNo2 ), 0, sNewGridNo2, RDX, FALSE, bLevel ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sNewGridNo2, &sX, &sY); + InternalIgniteExplosion( ubOwner, sX, sY, 0, sNewGridNo2, RDX, FALSE, bLevel ); } fToBreak = TRUE; @@ -4163,7 +4166,10 @@ void HandleExplosionQueue( void ) // no preplaced (owner=NOBODY) tripwire with explosive attachments allowed if ( gGameExternalOptions.bAllowExplosiveAttachments && (*pObj)[0]->data.misc.ubBombOwner > 1 ) { - fAttFound=HandleAttachedExplosions( (UINT8) ((*pObj)[0]->data.misc.ubBombOwner - 2), CenterX( sGridNo ), CenterY( sGridNo ), 0, + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + + fAttFound=HandleAttachedExplosions( (UINT8) ((*pObj)[0]->data.misc.ubBombOwner - 2), sX, sY, 0, sGridNo, (*pObj)[0]->data.misc.usBombItem, FALSE, ubLevel, (*pObj)[0]->data.ubDirection, pObj); } } @@ -4236,15 +4242,18 @@ void HandleExplosionQueue( void ) CheckForBuriedBombsAndRemoveFlags( sGridNo, ubLevel); // BOOM! + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + // bomb objects only store the SIDE who placed the bomb! :-( if ( (*pObj)[0]->data.misc.ubBombOwner > 1 ) { - IgniteExplosion( (UINT8) ((*pObj)[0]->data.misc.ubBombOwner - 2), CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, (*pObj)[0]->data.misc.usBombItem, ubLevel, (*pObj)[0]->data.ubDirection, pObj); + IgniteExplosion( (UINT8) ((*pObj)[0]->data.misc.ubBombOwner - 2), sX, sY, 0, sGridNo, (*pObj)[0]->data.misc.usBombItem, ubLevel, (*pObj)[0]->data.ubDirection, pObj); } else { // pre-placed - IgniteExplosion( NOBODY, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, (*pObj)[0]->data.misc.usBombItem, ubLevel, (*pObj)[0]->data.ubDirection ); + IgniteExplosion( NOBODY, sX, sY, 0, sGridNo, (*pObj)[0]->data.misc.usBombItem, ubLevel, (*pObj)[0]->data.ubDirection ); } } /* if ( FindWorldItemForBuriedBombInGridNo(sGridNo, ubLevel) != -1 ) @@ -5530,8 +5539,8 @@ void FireFragmentsTrapGun( SOLDIERTYPE* pThrower, INT32 gridno, INT16 sZ, OBJECT INT16 horizontalarc = 5; INT16 verticalarc = 0; - INT16 sX = CenterX(gridno); - INT16 sY = CenterY(gridno); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(gridno, &sX, &sY); AssertMsg( ubFragRange > 0 , "Fragmentation data lacks range property!" ); @@ -6331,7 +6340,9 @@ void RoofDestruction( INT32 sGridNo, BOOLEAN fWithExplosion ) static UINT16 usRoofCollapseExplosionIndex = 1727; if ( HasItemFlag( usRoofCollapseExplosionIndex, ROOF_COLLAPSE_ITEM ) || GetFirstItemWithFlag( &usRoofCollapseExplosionIndex, ROOF_COLLAPSE_ITEM ) ) { - InternalIgniteExplosion( NOBODY, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, usRoofCollapseExplosionIndex, FALSE, 0 ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + InternalIgniteExplosion( NOBODY, sX, sY, 0, sGridNo, usRoofCollapseExplosionIndex, FALSE, 0 ); } if ( Chance( 15 ) ) @@ -6340,7 +6351,9 @@ void RoofDestruction( INT32 sGridNo, BOOLEAN fWithExplosion ) if ( debrissmokeitem ) { - InternalIgniteExplosion( NOBODY, CenterX( sGridNo ), CenterY( sGridNo ), 0, sGridNo, debrissmokeitem, FALSE, 0 ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + InternalIgniteExplosion( NOBODY, sX, sY, 0, sGridNo, debrissmokeitem, FALSE, 0 ); } } } diff --git a/TileEngine/Isometric Utils.cpp b/TileEngine/Isometric Utils.cpp index 5f68cf493..51d8a986f 100644 --- a/TileEngine/Isometric Utils.cpp +++ b/TileEngine/Isometric Utils.cpp @@ -708,27 +708,6 @@ BOOLEAN GetMouseMapPos( INT32 *psMapPos ) } - -BOOLEAN ConvertMapPosToWorldTileCenter( INT32 usMapPos, INT16 *psXPos, INT16 *psYPos ) -{ - INT16 sWorldX, sWorldY; - INT16 sCellX, sCellY; - - // Get X, Y world GRID Coordinates - sWorldY = ( usMapPos / WORLD_COLS ); - sWorldX = usMapPos - ( sWorldY * WORLD_COLS ); - - // Convert into cell coords - sCellY = sWorldY * CELL_Y_SIZE; - sCellX = sWorldX * CELL_X_SIZE; - - // Add center tile positions - *psXPos = sCellX + ( CELL_X_SIZE / 2 ); - *psYPos = sCellY + ( CELL_Y_SIZE / 2 ); - - return( TRUE ); -} - void GetScreenXYWorldCoords( INT16 sScreenX, INT16 sScreenY, INT16 *psWorldX, INT16 *psWorldY ) { INT16 sOffsetX, sOffsetY; @@ -931,7 +910,7 @@ void ConvertGridNoToCellXY( INT32 sGridNo, INT16 *sXPos, INT16 *sYPos ) *sXPos = ( *sXPos * CELL_X_SIZE ); } -void ConvertGridNoToCenterCellXY( INT32 sGridNo, INT16 *sXPos, INT16 *sYPos ) +void ConvertGridNoToCenterCellXY( const INT32 sGridNo, INT16 *sXPos, INT16 *sYPos ) { *sYPos = ( sGridNo / WORLD_COLS ); *sXPos = ( sGridNo - ( *sYPos * WORLD_COLS ) ); @@ -940,22 +919,6 @@ void ConvertGridNoToCenterCellXY( INT32 sGridNo, INT16 *sXPos, INT16 *sYPos ) *sXPos = ( *sXPos * CELL_X_SIZE ) + ( CELL_X_SIZE / 2 ); } -INT32 GetRangeFromGridNoDiff( INT32 sGridNo1, INT32 sGridNo2 ) -{ - INT32 uiDist; - INT16 sXPos, sYPos, sXPos2, sYPos2; - - // Convert our grid-not into an XY - ConvertGridNoToXY( sGridNo1, &sXPos, &sYPos ); - - // Convert our grid-not into an XY - ConvertGridNoToXY( sGridNo2, &sXPos2, &sYPos2 ); - - uiDist = (INT32)(sqrt((double) ( sXPos2 - sXPos )*( sXPos2 - sXPos ) + ( sYPos2 - sYPos ) * ( sYPos2 - sYPos ) )); - - return( uiDist ); -} - INT32 GetRangeInCellCoordsFromGridNoDiff( INT32 sGridNo1, INT32 sGridNo2 ) { INT16 sXPos, sYPos, sXPos2, sYPos2; @@ -1002,8 +965,8 @@ INT16 PythSpacesAway(INT32 sOrigin, INT32 sDest) { INT16 sRows,sCols,sResult; - sRows = abs((sOrigin / MAXCOL) - (sDest / MAXCOL)); - sCols = abs((sOrigin % MAXROW) - (sDest % MAXROW)); + sRows = (sOrigin / MAXCOL) - (sDest / MAXCOL); + sCols = (sOrigin % MAXROW) - (sDest % MAXROW); // apply Pythagoras's theorem for right-handed triangle: @@ -1234,30 +1197,6 @@ INT16 ExtQuickestDirection(INT16 origin, INT16 dest) } -// Returns the (center ) cell coordinates in X -INT16 CenterX( INT32 sGridNo ) -{ - INT32 sYPos, sXPos; - - sYPos = sGridNo / WORLD_COLS; - sXPos = ( sGridNo - ( sYPos * WORLD_COLS ) ); - - return( ( sXPos * CELL_X_SIZE ) + ( CELL_X_SIZE / 2 ) ); -} - - -// Returns the (center ) cell coordinates in Y -INT16 CenterY( INT32 sGridNo ) -{ - INT32 sYPos, sXPos; - - sYPos = sGridNo / WORLD_COLS; - sXPos = ( sGridNo - ( sYPos * WORLD_COLS ) ); - - return( ( sYPos * CELL_Y_SIZE ) + ( CELL_Y_SIZE / 2 ) ); -} - - INT16 MapX( INT32 sGridNo ) { INT32 sYPos, sXPos; diff --git a/TileEngine/Isometric Utils.h b/TileEngine/Isometric Utils.h index 7da2f67e4..ad74b6e33 100644 --- a/TileEngine/Isometric Utils.h +++ b/TileEngine/Isometric Utils.h @@ -45,7 +45,7 @@ extern UINT8 gPurpendicularDirection[ NUM_WORLD_DIRECTIONS ][ NUM_WORLD_DIRECTIO void ConvertDirectionToVectorInXY(UINT8 ubDirection, INT16* sXDir, INT16* sYDir); void ConvertGridNoToXY( INT32 sGridNo, INT16 *sXPos, INT16 *sYPos ); void ConvertGridNoToCellXY( INT32 sGridNo, INT16 *sXPos, INT16 *sYPos ); -void ConvertGridNoToCenterCellXY( INT32 sGridNo, INT16 *sXPos, INT16 *sYPos ); +void ConvertGridNoToCenterCellXY( const INT32 sGridNo, INT16 *sXPos, INT16 *sYPos ); // GRID NO MANIPULATION FUNCTIONS @@ -88,11 +88,8 @@ BOOLEAN GridNoOnVisibleWorldTile( INT32 sGridNo ); BOOLEAN GridNoOnVisibleWorldTileGivenYLimits( INT32 sGridNo ); BOOLEAN GridNoOnEdgeOfMap( INT32 sGridNo, INT8 * pbDirection ); -BOOLEAN ConvertMapPosToWorldTileCenter( INT32 usMapPos, INT16 *psXPos, INT16 *psYPos ); - BOOLEAN CellXYToScreenXY(INT16 sCellX, INT16 sCellY, INT16 *sScreenX, INT16 *sScreenY); -INT32 GetRangeFromGridNoDiff( INT32 sGridNo1, INT32 sGridNo2 ); INT32 GetRangeInCellCoordsFromGridNoDiff( INT32 sGridNo1, INT32 sGridNo2 ); BOOLEAN IsPointInScreenRect( INT16 sXPos, INT16 sYPos, SGPRect *pRect ); @@ -110,12 +107,6 @@ INT16 QuickestDirection(INT16 origin, INT16 dest); INT16 ExtQuickestDirection(INT16 origin, INT16 dest); -// Returns the (center ) cell coordinates in X -INT16 CenterX( INT32 sGridNo ); - -// Returns the (center ) cell coordinates in Y -INT16 CenterY( INT32 sGridNo ); - INT16 MapX( INT32 sGridNo ); INT16 MapY( INT32 sGridNo ); BOOLEAN FindFenceJumpDirection( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bStartingDir, INT8 *pbDirection ); @@ -157,4 +148,4 @@ BOOLEAN FindWindowJumpDirection( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bSta // Flugente: is this gridno near a player merc? BOOLEAN GridNoNearPlayerMercs( INT32 sGridNo, INT16 sRadius ); -#endif \ No newline at end of file +#endif diff --git a/TileEngine/LightEffects.cpp b/TileEngine/LightEffects.cpp index a229f4a63..dcbb15748 100644 --- a/TileEngine/LightEffects.cpp +++ b/TileEngine/LightEffects.cpp @@ -84,7 +84,10 @@ void UpdateLightingSprite( LIGHTEFFECT *pLight ) LightSpritePower( pLight->iLight, TRUE ); // LightSpriteFake( pLight->iLight ); - LightSpritePosition( pLight->iLight, (INT16)( CenterX( pLight->sGridNo ) / CELL_X_SIZE ), (INT16)( CenterY( pLight->sGridNo ) / CELL_Y_SIZE ) ); + INT16 sX, sY; + ConvertGridNoToCenterCellXY(pLight->sGridNo, &sX, &sY); + + LightSpritePosition( pLight->iLight, (INT16)( sX / CELL_X_SIZE ), (INT16)( sY / CELL_Y_SIZE ) ); } // Flugente: create a pure light, worry about updating sight in other functions diff --git a/TileEngine/SmokeEffects.cpp b/TileEngine/SmokeEffects.cpp index 8d6bce9c2..4e202318a 100644 --- a/TileEngine/SmokeEffects.cpp +++ b/TileEngine/SmokeEffects.cpp @@ -534,9 +534,11 @@ void AddSmokeEffectToTile( INT32 iSmokeEffectID, INT8 bType, INT32 sGridNo, INT8 AniParams.uiFlags = ANITILE_CACHEDTILE | ANITILE_FORWARD | ANITILE_SMOKE_EFFECT | ANITILE_LOOPING | ANITILE_ALWAYS_TRANSLUCENT; } - AniParams.sX = CenterX( sGridNo ); - AniParams.sY = CenterY( sGridNo ); - AniParams.sZ = (INT16)0; + INT16 sX, sY; + ConvertGridNoToCenterCellXY(sGridNo, &sX, &sY); + AniParams.sX = sX; + AniParams.sY = sY; + AniParams.sZ = (INT16)0; // Use the right graphic based on type.. switch( bType ) diff --git a/TileEngine/environment.cpp b/TileEngine/environment.cpp index 54aff33df..ad04fdc9e 100644 --- a/TileEngine/environment.cpp +++ b/TileEngine/environment.cpp @@ -1093,7 +1093,6 @@ void AddSnakeAmim( INT32 sGridno, UINT8 usDirection ) if ( !TileIsOutOfBounds( sGridno ) ) { ANITILE_PARAMS AniParams; - memset( &AniParams, 0, sizeof(ANITILE_PARAMS) ); AniParams.sGridNo = sGridno; @@ -1101,8 +1100,7 @@ void AddSnakeAmim( INT32 sGridno, UINT8 usDirection ) AniParams.sDelay = 100; AniParams.sStartFrame = 0; AniParams.uiFlags = ANITILE_CACHEDTILE | ANITILE_FORWARD | ANITILE_USE_DIRECTION_FOR_START_FRAME;//| ANITILE_LOOPING; - AniParams.sX = CenterX( sGridno ); - AniParams.sY = CenterY( sGridno ); + ConvertGridNoToCenterCellXY(sGridno, &AniParams.sX, &AniParams.sY); AniParams.sZ = 0; strcpy( AniParams.zCachedFile, "TILECACHE\\WATERSNAKE_MOVE.sti" ); diff --git a/TileEngine/physics.cpp b/TileEngine/physics.cpp index a08b72365..68c55586c 100644 --- a/TileEngine/physics.cpp +++ b/TileEngine/physics.cpp @@ -1995,7 +1995,7 @@ void CalculateLaunchItemBasicParams( SOLDIERTYPE *pSoldier, OBJECTTYPE *pItem, I { // bad news - i can't throw item at myself // so use dir incrementer - UINT8 ubDir = atan8( CenterX(pSoldier->sGridNo), CenterY(pSoldier->sGridNo), CenterX(sGridNo), CenterY(sGridNo) ); + UINT8 ubDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sGridNo); sInterGridNo += DirIncrementer[ubDir]; } } diff --git a/TileEngine/renderworld.cpp b/TileEngine/renderworld.cpp index 5258b73a0..85eb7bd9d 100644 --- a/TileEngine/renderworld.cpp +++ b/TileEngine/renderworld.cpp @@ -614,7 +614,7 @@ void ShowRiotShield( SOLDIERTYPE* pSoldier, UINT16 *pBuffer, UINT32 uiDestPitchB // try to keep the shield 'moving' alongside the soldier. This won't work perfectly, but it's better than nothing INT16 base_x = 0; INT16 base_y = 0; - ConvertMapPosToWorldTileCenter( pSoldier->sGridNo, &base_x, &base_y ); + ConvertGridNoToCenterCellXY( pSoldier->sGridNo, &base_x, &base_y ); INT16 dx = pSoldier->sX - base_x; INT16 dy = pSoldier->sY - base_y; From eca4086d303f48121f504a7b1c6b2f2d489f8b0c Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Sat, 7 Oct 2023 08:53:23 -0300 Subject: [PATCH 04/16] inherit minimum cmake version from ja2 all this does is silence the warning that cmake 2.6 is deprecated, we're never building bfVFS standalone anyway --- ext/VFS/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/VFS/CMakeLists.txt b/ext/VFS/CMakeLists.txt index 23806e848..21f5d1ecf 100644 --- a/ext/VFS/CMakeLists.txt +++ b/ext/VFS/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 2.6) - project(bfVFS) set(BFVFS_VERSION_MAJOR 1) From 56a55f1bc49ce119f6709829ea76934f65803b57 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 7 Oct 2023 18:53:39 +0300 Subject: [PATCH 05/16] Use std::queue instead of old custom queue implemented in container.cpp --- Tactical/Dialogue Control.cpp | 563 +++++++++++++++------------------- 1 file changed, 245 insertions(+), 318 deletions(-) diff --git a/Tactical/Dialogue Control.cpp b/Tactical/Dialogue Control.cpp index 16653ffa9..b8d9a9a72 100644 --- a/Tactical/Dialogue Control.cpp +++ b/Tactical/Dialogue Control.cpp @@ -52,6 +52,7 @@ #include "qarray.h" #include "Soldier Profile.h" #include +#include #include "Auto Resolve.h" #include "connect.h" @@ -168,8 +169,8 @@ UINT8 gubNumStopTimeQuotes = 2; // QUEUE UP DIALOG! -#define INITIAL_Q_SIZE 10 -HQUEUE ghDialogueQ = NULL; +std::queue ghDialogueQ; + FACETYPE *gpCurrentTalkingFace = NULL; UINT8 gubCurrentTalkingID = NO_PROFILE; INT8 gbUIHandlerID; @@ -283,40 +284,18 @@ BOOLEAN DialogueActive( ) BOOLEAN InitalizeDialogueControl() { - ghDialogueQ = CreateQueue( INITIAL_Q_SIZE, sizeof( DIALOGUE_Q_STRUCT_PTR ) ); - - // Initalize subtitle popup box - // - + EmptyDialogueQueue(); giNPCReferenceCount = 0; - - if ( ghDialogueQ == NULL ) - { - return( FALSE ); - } - else - { - return( TRUE ); - } + return( TRUE ); } void ShutdownDialogueControl() { - if( ghDialogueQ != NULL ) - { - // Empty - EmptyDialogueQueue( ); - - // Delete - DeleteQueue( ghDialogueQ ); - ghDialogueQ=NULL; - } - // shutdown external static NPC faces ShutdownStaticExternalNPCFaces( ); - // gte rid of portraits for cars + // get rid of portraits for cars UnLoadCarPortraits( ); // } @@ -373,49 +352,31 @@ void ShutdownStaticExternalNPCFaces( void ) void EmptyDialogueQueue( ) { // If we have anything left in the queue, remove! - if( ghDialogueQ != NULL ) + while( !ghDialogueQ.empty() ) { -/* -DEF: commented out because the Queue system ?? uses a contiguous memory block ??? for the queue - so you cant delete a single node. The DeleteQueue, below, will free the entire memory block - - numDialogueItems = QueueSize( ghDialogueQ ); - - for ( cnt = numDialogueItems-1; cnt >= 0; cnt-- ) - { - if ( PeekQueue( ghDialogueQ, &QItem ) ) - { - MemFree( QItem ); - } - } -*/ - - // Delete list - DeleteQueue( ghDialogueQ ); - ghDialogueQ=NULL; - - // Recreate list - ghDialogueQ = CreateQueue( INITIAL_Q_SIZE, sizeof( DIALOGUE_Q_STRUCT_PTR ) ); - + ghDialogueQ.pop(); } gfWaitingForTriggerTimer = FALSE; } -BOOLEAN DialogueQueueIsEmpty( ) +inline BOOLEAN DialogueQueueIsEmpty( ) { - if( ghDialogueQ != NULL ) - { - INT32 numDialogueItems = QueueSize( ghDialogueQ ); + return( ghDialogueQ.empty() ); +} - if ( numDialogueItems == 0 ) - { - return( TRUE ); - } + +static bool PopFromDialogueQueue(DIALOGUE_Q_STRUCT_PTR pDialogue) +{ + if (!ghDialogueQ.empty()) + { + *pDialogue = ghDialogueQ.front(); + ghDialogueQ.pop(); + return (true); } - return( FALSE ); + return false; } @@ -434,6 +395,7 @@ BOOLEAN DialogueQueueIsEmptyOrSomebodyTalkingNow( ) return( TRUE ); } + void DialogueAdvanceSpeech( ) { // Shut them up! @@ -507,7 +469,6 @@ void HandleDialogueUIAdjustments( ) void HandleDialogue( ) { INT32 iQSize; - DIALOGUE_Q_STRUCT *QItem; static BOOLEAN fOldEngagedInConvFlagOn = FALSE; BOOLEAN fDoneTalking = FALSE; SOLDIERTYPE *pSoldier = NULL; @@ -520,7 +481,7 @@ void HandleDialogue( ) return; } - iQSize = QueueSize( ghDialogueQ ); + iQSize = ghDialogueQ.size(); if ( iQSize == 0 && gpCurrentTalkingFace == NULL ) { @@ -787,19 +748,18 @@ void HandleDialogue( ) // If here, pick current one from queue and play // Get new one - RemfromQueue( ghDialogueQ, &QItem ); - + DIALOGUE_Q_STRUCT QItem; + PopFromDialogueQueue(&QItem); + // If we are in auto bandage, ignore any quotes! if ( gTacticalStatus.fAutoBandageMode ) { - if( QItem->fPauseTime ) + if( QItem.fPauseTime ) { UnLockPauseState(); UnPauseGame(); } - // Delete memory - MemFree( QItem ); return; } @@ -807,30 +767,27 @@ void HandleDialogue( ) // Alrighty, check if this one is to be delayed until we gain control. // If so, place it back in! - if ( QItem->fDelayed ) + if ( QItem.fDelayed ) { // Are we not in our turn and not interrupted if ( gTacticalStatus.ubCurrentTeam != gbPlayerNum ) { //Place back in! - // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); - + ghDialogueQ.push(QItem); return; } } // ATE: OK: If a battle sound, and delay value was given, set time stamp // now... - if ( QItem->uiSpecialEventFlag == DIALOGUE_SPECIAL_EVENT_DO_BATTLE_SND ) + if ( QItem.uiSpecialEventFlag == DIALOGUE_SPECIAL_EVENT_DO_BATTLE_SND ) { - if ( QItem->uiSpecialEventData2 != 0 ) + if ( QItem.uiSpecialEventData2 != 0 ) { - if ( ( GetJA2Clock( ) - QItem->iTimeStamp ) < QItem->uiSpecialEventData2 ) + if ( ( GetJA2Clock( ) - QItem.iTimeStamp ) < QItem.uiSpecialEventData2 ) { //Place back in! - // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); + ghDialogueQ.push(QItem); return; } @@ -838,26 +795,25 @@ void HandleDialogue( ) } // Try to find soldier... - pSoldier = FindSoldierByProfileID( QItem->ubCharacterNum, TRUE ); + pSoldier = FindSoldierByProfileID( QItem.ubCharacterNum, TRUE ); if ( pSoldier != NULL ) { if ( SoundIsPlaying( pSoldier->uiBattleSoundID ) ) { //Place back in! - // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); + ghDialogueQ.push(QItem); return; } } - if ( (guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN ) && ( QItem->uiSpecialEventFlag == 0 ) ) + if ( (guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN ) && ( QItem.uiSpecialEventFlag == 0 ) ) { - QItem->fPauseTime = TRUE; + QItem.fPauseTime = TRUE; } - if( QItem->fPauseTime ) + if( QItem.fPauseTime ) { if( GamePaused( ) == FALSE ) { @@ -869,7 +825,7 @@ void HandleDialogue( ) // Now play first item in queue // If it's not a 'special' dialogue event, continue - if ( QItem->uiSpecialEventFlag == 0 ) + if ( QItem.uiSpecialEventFlag == 0 ) { if( pSoldier ) { @@ -883,43 +839,43 @@ void HandleDialogue( ) fTeamPanelDirty = TRUE; // allow them to go back to sleep - TacticalCharacterDialogueWithSpecialEvent( pSoldier, QItem->usQuoteNum, DIALOGUE_SPECIAL_EVENT_SLEEP, 1,0 ); + TacticalCharacterDialogueWithSpecialEvent( pSoldier, QItem.usQuoteNum, DIALOGUE_SPECIAL_EVENT_SLEEP, 1,0 ); } } - gTacticalStatus.ubLastQuoteSaid = (UINT8)QItem->usQuoteNum; - gTacticalStatus.ubLastQuoteProfileNUm = (UINT8)QItem->ubCharacterNum; + gTacticalStatus.ubLastQuoteSaid = (UINT8)QItem.usQuoteNum; + gTacticalStatus.ubLastQuoteProfileNUm = (UINT8)QItem.ubCharacterNum; // Flugente: only set up face if we can access correctly - if ( QItem->iFaceIndex >= 0 ) + if ( QItem.iFaceIndex >= 0 ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[ QItem->iFaceIndex ]; + gpCurrentTalkingFace = &gFacesData[ QItem.iFaceIndex ]; } - gubCurrentTalkingID = QItem->ubCharacterNum; + gubCurrentTalkingID = QItem.ubCharacterNum; #ifdef JA2UB //Ja25: test - if( QItem->ubCharacterNum == MORRIS_UB ) //MORRIS + if( QItem.ubCharacterNum == MORRIS_UB ) //MORRIS { - if( QItem->usQuoteNum == 0 ) + if( QItem.usQuoteNum == 0 ) { } } #endif - ExecuteCharacterDialogue( QItem->ubCharacterNum, QItem->usQuoteNum, QItem->iFaceIndex, QItem->bUIHandlerID, QItem->fFromSoldier ); + ExecuteCharacterDialogue( QItem.ubCharacterNum, QItem.usQuoteNum, QItem.iFaceIndex, QItem.bUIHandlerID, QItem.fFromSoldier ); } - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SKIP_A_FRAME ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SKIP_A_FRAME ) { } - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_LOCK_INTERFACE ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_LOCK_INTERFACE ) { // locking or unlocking? - if( QItem->uiSpecialEventData ) + if( QItem.uiSpecialEventData ) { - switch( QItem->uiSpecialEventData2 ) + switch( QItem.uiSpecialEventData2 ) { case( MAP_SCREEN ): fLockOutMapScreenInterface = TRUE; @@ -928,7 +884,7 @@ void HandleDialogue( ) } else { - switch( QItem->uiSpecialEventData2 ) + switch( QItem.uiSpecialEventData2 ) { case( MAP_SCREEN ): fLockOutMapScreenInterface = FALSE; @@ -936,61 +892,61 @@ void HandleDialogue( ) } } } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_REMOVE_EPC ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_REMOVE_EPC ) { - gMercProfiles[ (UINT8) QItem->uiSpecialEventData ].ubMiscFlags &= ~PROFILE_MISC_FLAG_FORCENPCQUOTE; - UnRecruitEPC( (UINT8) QItem->uiSpecialEventData ); + gMercProfiles[ (UINT8) QItem.uiSpecialEventData ].ubMiscFlags &= ~PROFILE_MISC_FLAG_FORCENPCQUOTE; + UnRecruitEPC( (UINT8) QItem.uiSpecialEventData ); ReBuildCharactersList(); } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTRACT_WANTS_TO_RENEW ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTRACT_WANTS_TO_RENEW ) { - HandleMercIsWillingToRenew( (UINT8)QItem->uiSpecialEventData ); + HandleMercIsWillingToRenew( (UINT8)QItem.uiSpecialEventData ); } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTRACT_NOGO_TO_RENEW ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTRACT_NOGO_TO_RENEW ) { - HandleMercIsNotWillingToRenew( (UINT8)QItem->uiSpecialEventData ); + HandleMercIsNotWillingToRenew( (UINT8)QItem.uiSpecialEventData ); } else { - if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_USE_ALTERNATE_FILES ) + if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_USE_ALTERNATE_FILES ) { gfUseAlternateDialogueFile = TRUE; // Flugente: only set up face if we can access correctly - if ( QItem->iFaceIndex >= 0 ) + if ( QItem.iFaceIndex >= 0 ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[ QItem->iFaceIndex ]; + gpCurrentTalkingFace = &gFacesData[ QItem.iFaceIndex ]; } - gubCurrentTalkingID = QItem->ubCharacterNum; + gubCurrentTalkingID = QItem.ubCharacterNum; - ExecuteCharacterDialogue( QItem->ubCharacterNum, QItem->usQuoteNum, QItem->iFaceIndex, QItem->bUIHandlerID, QItem->fFromSoldier ); + ExecuteCharacterDialogue( QItem.ubCharacterNum, QItem.usQuoteNum, QItem.iFaceIndex, QItem.bUIHandlerID, QItem.fFromSoldier ); gfUseAlternateDialogueFile = FALSE; } // We could have a special flag, but dialogue as well - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_PCTRIGGERNPC ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_PCTRIGGERNPC ) { // Flugente: only set up face if we can access correctly - if ( QItem->iFaceIndex >= 0 ) + if ( QItem.iFaceIndex >= 0 ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[ QItem->iFaceIndex ]; + gpCurrentTalkingFace = &gFacesData[ QItem.iFaceIndex ]; } - gubCurrentTalkingID = QItem->ubCharacterNum; + gubCurrentTalkingID = QItem.ubCharacterNum; - ExecuteCharacterDialogue( QItem->ubCharacterNum, QItem->usQuoteNum, QItem->iFaceIndex, QItem->bUIHandlerID, QItem->fFromSoldier ); + ExecuteCharacterDialogue( QItem.ubCharacterNum, QItem.usQuoteNum, QItem.iFaceIndex, QItem.bUIHandlerID, QItem.fFromSoldier ); // Setup face with data! gpCurrentTalkingFace->uiFlags |= FACE_PCTRIGGER_NPC; - gpCurrentTalkingFace->uiUserData1 = QItem->uiSpecialEventData; - gpCurrentTalkingFace->uiUserData2 = QItem->uiSpecialEventData2; + gpCurrentTalkingFace->uiUserData1 = QItem.uiSpecialEventData; + gpCurrentTalkingFace->uiUserData2 = QItem.uiSpecialEventData2; } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SHOW_CONTRACT_MENU ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SHOW_CONTRACT_MENU ) { // Setup face pointer // ATE: THis is working with MARK'S STUFF :( @@ -1003,116 +959,116 @@ void HandleDialogue( ) pProcessingSoldier = pSoldier; fProcessingAMerc = TRUE; } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_DO_BATTLE_SND ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_DO_BATTLE_SND ) { // grab soldier ptr from profile ID - pSoldier = FindSoldierByProfileID( QItem->ubCharacterNum, FALSE ); + pSoldier = FindSoldierByProfileID( QItem.ubCharacterNum, FALSE ); // Do battle snounds...... if ( pSoldier ) { - pSoldier->InternalDoMercBattleSound( (UINT8)QItem->uiSpecialEventData, 0 ); + pSoldier->InternalDoMercBattleSound( (UINT8)QItem.uiSpecialEventData, 0 ); } } - if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SIGNAL_ITEM_LOCATOR_START ) + if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SIGNAL_ITEM_LOCATOR_START ) { // Turn off item lock for locators... gTacticalStatus.fLockItemLocators = FALSE; // Slide to location! - SlideToLocation( 0, QItem->uiSpecialEventData ); + SlideToLocation( 0, QItem.uiSpecialEventData ); // Flugente: only set up face if we can access correctly - if ( QItem->iFaceIndex >= 0 ) + if ( QItem.iFaceIndex >= 0 ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[ QItem->iFaceIndex ]; + gpCurrentTalkingFace = &gFacesData[ QItem.iFaceIndex ]; } - gubCurrentTalkingID = QItem->ubCharacterNum; + gubCurrentTalkingID = QItem.ubCharacterNum; - ExecuteCharacterDialogue( QItem->ubCharacterNum, QItem->usQuoteNum, QItem->iFaceIndex, QItem->bUIHandlerID, QItem->fFromSoldier ); + ExecuteCharacterDialogue( QItem.ubCharacterNum, QItem.usQuoteNum, QItem.iFaceIndex, QItem.bUIHandlerID, QItem.fFromSoldier ); } - if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_ENABLE_AI ) + if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_ENABLE_AI ) { //OK, allow AI to work now.... UnPauseAI(); } - if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_TRIGGERPREBATTLEINTERFACE ) + if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_TRIGGERPREBATTLEINTERFACE ) { UnLockPauseState(); // Flugente: what hideous idiocy is this? We cast a UINT32 as GROUP*? This is likely to return garbage. // Why the hell not use the id instead? - InitPreBattleInterface( (GROUP*)QItem->uiSpecialEventData, TRUE ); + InitPreBattleInterface( (GROUP*)QItem.uiSpecialEventData, TRUE ); - /*GROUP* pGroup = GetGroup( (UINT8)QItem->uiSpecialEventData ); + /*GROUP* pGroup = GetGroup( (UINT8)QItem.uiSpecialEventData ); if ( pGroup ) InitPreBattleInterface( pGroup, TRUE );*/ } - if( QItem->uiSpecialEventFlag & DIALOGUE_ADD_EVENT_FOR_SOLDIER_UPDATE_BOX ) + if( QItem.uiSpecialEventFlag & DIALOGUE_ADD_EVENT_FOR_SOLDIER_UPDATE_BOX ) { INT32 iReason = 0; SOLDIERTYPE *pUpdateSoldier = NULL; - iReason = QItem->uiSpecialEventData; + iReason = QItem.uiSpecialEventData; switch( iReason ) { case( UPDATE_BOX_REASON_ADDSOLDIER ): - pUpdateSoldier = &Menptr[ QItem->uiSpecialEventData2 ]; + pUpdateSoldier = &Menptr[ QItem.uiSpecialEventData2 ]; if( pUpdateSoldier->bActive == TRUE ) { AddSoldierToUpdateBox( pUpdateSoldier ); } break; case( UPDATE_BOX_REASON_SET_REASON ): - SetSoldierUpdateBoxReason( QItem->uiSpecialEventData2 ); + SetSoldierUpdateBoxReason( QItem.uiSpecialEventData2 ); break; case( UPDATE_BOX_REASON_SHOW_BOX ): ShowUpdateBox( ); break; } } - if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_BEGINPREBATTLEINTERFACE ) + if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_BEGINPREBATTLEINTERFACE ) { // Flugente: only set up face if we can access correctly - if ( QItem->iFaceIndex >= 0 ) + if ( QItem.iFaceIndex >= 0 ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[ QItem->iFaceIndex ]; + gpCurrentTalkingFace = &gFacesData[ QItem.iFaceIndex ]; } - gubCurrentTalkingID = QItem->ubCharacterNum; + gubCurrentTalkingID = QItem.ubCharacterNum; - ExecuteCharacterDialogue( QItem->ubCharacterNum, QItem->usQuoteNum, QItem->iFaceIndex, QItem->bUIHandlerID, QItem->fFromSoldier ); + ExecuteCharacterDialogue( QItem.ubCharacterNum, QItem.usQuoteNum, QItem.iFaceIndex, QItem.bUIHandlerID, QItem.fFromSoldier ); // Setup face with data! gpCurrentTalkingFace->uiFlags |= FACE_TRIGGER_PREBATTLE_INT; - gpCurrentTalkingFace->uiUserData1 = QItem->uiSpecialEventData; - gpCurrentTalkingFace->uiUserData2 = QItem->uiSpecialEventData2; + gpCurrentTalkingFace->uiUserData1 = QItem.uiSpecialEventData; + gpCurrentTalkingFace->uiUserData2 = QItem.uiSpecialEventData2; } - if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SHOPKEEPER ) + if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SHOPKEEPER ) { - if( QItem->uiSpecialEventData < 3 ) + if( QItem.uiSpecialEventData < 3 ) { // post a notice if the player wants to withdraw money from thier account to cover the difference? - swprintf( zMoney, L"%d", QItem->uiSpecialEventData2 ); + swprintf( zMoney, L"%d", QItem.uiSpecialEventData2 ); InsertCommasForDollarFigure( zMoney ); InsertDollarSignInToString( zMoney ); } - else if ( QItem->uiSpecialEventData > 7 ) + else if ( QItem.uiSpecialEventData > 7 ) { // post a notice if the player wants to withdraw money from thier account to cover the difference? - swprintf( zMoney, L"%d", QItem->uiSpecialEventData2 ); + swprintf( zMoney, L"%d", QItem.uiSpecialEventData2 ); InsertCommasForDollarFigure( zMoney ); } - switch( QItem->uiSpecialEventData ) + switch( QItem.uiSpecialEventData ) { case( 0 ): swprintf( zText, SkiMessageBoxText[ SKI_SHORT_FUNDS_TEXT ], zMoney ); @@ -1136,7 +1092,7 @@ void HandleDialogue( ) break; case( 3 ): // this means a dialogue event is in progress - giShopKeepDialogueEventinProgress = QItem->uiSpecialEventData2; + giShopKeepDialogueEventinProgress = QItem.uiSpecialEventData2; break; case( 4 ): // this means a dialogue event has ended @@ -1179,107 +1135,107 @@ void HandleDialogue( ) } - if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_EXIT_MAP_SCREEN ) + if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_EXIT_MAP_SCREEN ) { // select sector - ChangeSelectedMapSector( ( INT16 )QItem->uiSpecialEventData, ( INT16 )QItem->uiSpecialEventData2, ( INT8 )QItem->uiSpecialEventData3 ); + ChangeSelectedMapSector( ( INT16 )QItem.uiSpecialEventData, ( INT16 )QItem.uiSpecialEventData2, ( INT8 )QItem.uiSpecialEventData3 ); RequestTriggerExitFromMapscreen( MAP_EXIT_TO_TACTICAL ); } - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_DISPLAY_STAT_CHANGE ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_DISPLAY_STAT_CHANGE ) { // grab soldier ptr from profile ID - pSoldier = FindSoldierByProfileID( QItem->ubCharacterNum, FALSE ); + pSoldier = FindSoldierByProfileID( QItem.ubCharacterNum, FALSE ); if ( pSoldier ) { CHAR16 wTempString[ 128 ]; // tell player about stat increase - BuildStatChangeString( wTempString, pSoldier->name, ( BOOLEAN ) QItem->uiSpecialEventData, ( INT16 ) QItem->uiSpecialEventData2, ( UINT8 ) QItem->uiSpecialEventData3 ); + BuildStatChangeString( wTempString, pSoldier->name, ( BOOLEAN ) QItem.uiSpecialEventData, ( INT16 ) QItem.uiSpecialEventData2, ( UINT8 ) QItem.uiSpecialEventData3 ); ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, wTempString ); } } - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_UNSET_ARRIVES_FLAG ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_UNSET_ARRIVES_FLAG ) { gTacticalStatus.bMercArrivingQuoteBeingUsed = FALSE; } /* - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_DISPLAY_INVASION_MESSAGE ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_DISPLAY_INVASION_MESSAGE ) { - HandlePlayerNotifyInvasionByEnemyForces( (INT16)(QItem->uiSpecialEventData % MAP_WORLD_X), (INT16)(QItem->uiSpecialEventData / MAP_WORLD_X), 0, NULL ); + HandlePlayerNotifyInvasionByEnemyForces( (INT16)(QItem.uiSpecialEventData % MAP_WORLD_X), (INT16)(QItem.uiSpecialEventData / MAP_WORLD_X), 0, NULL ); } */ - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SKYRIDERMAPSCREENEVENT ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SKYRIDERMAPSCREENEVENT ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[ QItem->iFaceIndex ]; - gubCurrentTalkingID = QItem->ubCharacterNum; + gpCurrentTalkingFace = &gFacesData[ QItem.iFaceIndex ]; + gubCurrentTalkingID = QItem.ubCharacterNum; // handle the monologue event - HandleSkyRiderMonologueEvent( QItem->uiSpecialEventData, QItem->uiSpecialEventData2 ); + HandleSkyRiderMonologueEvent( QItem.uiSpecialEventData, QItem.uiSpecialEventData2 ); } - if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_MINESECTOREVENT ) + if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_MINESECTOREVENT ) { // Flugente: only set up face if we can access correctly - if ( QItem->iFaceIndex >= 0 ) + if ( QItem.iFaceIndex >= 0 ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[ QItem->iFaceIndex ]; + gpCurrentTalkingFace = &gFacesData[ QItem.iFaceIndex ]; } - gubCurrentTalkingID = QItem->ubCharacterNum; + gubCurrentTalkingID = QItem.ubCharacterNum; // set up the mine highlgith events - SetUpAnimationOfMineSectors( QItem->uiSpecialEventData ); + SetUpAnimationOfMineSectors( QItem.uiSpecialEventData ); } //Switch on our special events - if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_GIVE_ITEM ) + if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_GIVE_ITEM ) { - if ( QItem->bUIHandlerID == DIALOGUE_NPC_UI ) + if ( QItem.bUIHandlerID == DIALOGUE_NPC_UI ) { - HandleNPCItemGiven( (UINT8)QItem->uiSpecialEventData, (OBJECTTYPE*)QItem->uiSpecialEventData2, (INT8)QItem->uiSpecialEventData3 ); + HandleNPCItemGiven( (UINT8)QItem.uiSpecialEventData, (OBJECTTYPE*)QItem.uiSpecialEventData2, (INT8)QItem.uiSpecialEventData3 ); } } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_TRIGGER_NPC ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_TRIGGER_NPC ) { - if ( QItem->bUIHandlerID == DIALOGUE_NPC_UI ) + if ( QItem.bUIHandlerID == DIALOGUE_NPC_UI ) { - HandleNPCTriggerNPC( (UINT8)QItem->uiSpecialEventData, (UINT8)QItem->uiSpecialEventData2, (BOOLEAN)QItem->uiSpecialEventData3, (UINT8)QItem->uiSpecialEventData4 ); + HandleNPCTriggerNPC( (UINT8)QItem.uiSpecialEventData, (UINT8)QItem.uiSpecialEventData2, (BOOLEAN)QItem.uiSpecialEventData3, (UINT8)QItem.uiSpecialEventData4 ); } } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_GOTO_GRIDNO ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_GOTO_GRIDNO ) { - if ( QItem->bUIHandlerID == DIALOGUE_NPC_UI ) + if ( QItem.bUIHandlerID == DIALOGUE_NPC_UI ) { - HandleNPCGotoGridNo( (UINT8)QItem->uiSpecialEventData, (UINT16)QItem->uiSpecialEventData2, (UINT8)QItem->uiSpecialEventData3 );//dnl!!! + HandleNPCGotoGridNo( (UINT8)QItem.uiSpecialEventData, (UINT16)QItem.uiSpecialEventData2, (UINT8)QItem.uiSpecialEventData3 );//dnl!!! } } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_DO_ACTION ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_DO_ACTION ) { - if ( QItem->bUIHandlerID == DIALOGUE_NPC_UI ) + if ( QItem.bUIHandlerID == DIALOGUE_NPC_UI ) { - HandleNPCDoAction( (UINT8)QItem->uiSpecialEventData, (UINT16)QItem->uiSpecialEventData2, (UINT8)QItem->uiSpecialEventData3 ); + HandleNPCDoAction( (UINT8)QItem.uiSpecialEventData, (UINT16)QItem.uiSpecialEventData2, (UINT8)QItem.uiSpecialEventData3 ); } } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CLOSE_PANEL ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CLOSE_PANEL ) { - if ( QItem->bUIHandlerID == DIALOGUE_NPC_UI ) + if ( QItem.bUIHandlerID == DIALOGUE_NPC_UI ) { HandleNPCClosePanel( ); } } - else if ( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SHOW_UPDATE_MENU ) + else if ( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SHOW_UPDATE_MENU ) { SetUpdateBoxFlag( TRUE ); } #ifdef JA2UB - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_JERRY_MILO ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_JERRY_MILO ) { //switch on the quote that is being spoken - switch( QItem->uiSpecialEventData ) + switch( QItem.uiSpecialEventData ) { case JM_SE__SHOW_RADIO_LOCATOR: HandleShowingRadioLocatorsInMorrisArea(); @@ -1301,10 +1257,10 @@ void HandleDialogue( ) } } #else //Ja25: removed the flag, no militia - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTINUE_TRAINING_MILITIA ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTINUE_TRAINING_MILITIA ) { // grab soldier ptr from profile ID - pSoldier = FindSoldierByProfileID( ( UINT8 )( QItem->uiSpecialEventData ), FALSE ); + pSoldier = FindSoldierByProfileID( ( UINT8 )( QItem.uiSpecialEventData ), FALSE ); // if soldier valid... if( pSoldier != NULL ) @@ -1313,7 +1269,7 @@ void HandleDialogue( ) } } #endif - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_ENTER_MAPSCREEN ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_ENTER_MAPSCREEN ) { if( !(guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN ) ) { @@ -1321,22 +1277,22 @@ void HandleDialogue( ) fEnterMapDueToContract = TRUE; } } - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTRACT_ENDING ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTRACT_ENDING ) { // grab soldier ptr from profile ID - pSoldier = FindSoldierByProfileID( QItem->ubCharacterNum, FALSE ); + pSoldier = FindSoldierByProfileID( QItem.ubCharacterNum, FALSE ); // if soldier valid... if( pSoldier != NULL ) { // .. remove the fired soldier again - BeginStrategicRemoveMerc( pSoldier, (UINT8)QItem->uiSpecialEventData ); + BeginStrategicRemoveMerc( pSoldier, (UINT8)QItem.uiSpecialEventData ); } } - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTRACT_ENDING_NO_ASK_EQUIP ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_CONTRACT_ENDING_NO_ASK_EQUIP ) { // grab soldier ptr from profile ID - pSoldier = FindSoldierByProfileID( QItem->ubCharacterNum, FALSE ); + pSoldier = FindSoldierByProfileID( QItem.ubCharacterNum, FALSE ); // if soldier valid... if( pSoldier != NULL ) @@ -1345,53 +1301,53 @@ void HandleDialogue( ) StrategicRemoveMerc( pSoldier ); } } - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_MULTIPURPOSE ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_MULTIPURPOSE ) { // anv: handle snitch event - if( QItem->uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_SNITCH_DIALOGUE ) + if( QItem.uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_SNITCH_DIALOGUE ) { - gTacticalStatus.ubLastQuoteSaid = (UINT8)QItem->usQuoteNum; - gTacticalStatus.ubLastQuoteProfileNUm = (UINT8)QItem->ubCharacterNum; + gTacticalStatus.ubLastQuoteSaid = (UINT8)QItem.usQuoteNum; + gTacticalStatus.ubLastQuoteProfileNUm = (UINT8)QItem.ubCharacterNum; // Flugente: only set up face if we can access correctly - if ( QItem->iFaceIndex >= 0 ) + if ( QItem.iFaceIndex >= 0 ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[ QItem->iFaceIndex ]; + gpCurrentTalkingFace = &gFacesData[ QItem.iFaceIndex ]; } - gubCurrentTalkingID = QItem->iFaceIndex; + gubCurrentTalkingID = QItem.iFaceIndex; - //ExecuteCharacterDialogue( QItem->ubCharacterNum, QItem->usQuoteNum, QItem->iFaceIndex, DIALOGUE_TACTICAL_UI, TRUE ); - ExecuteSnitchCharacterDialogue( QItem->ubCharacterNum, QItem->usQuoteNum, QItem->iFaceIndex, QItem->bUIHandlerID, QItem->uiSpecialEventData2, QItem->uiSpecialEventData3, QItem->uiSpecialEventData4 ); + //ExecuteCharacterDialogue( QItem.ubCharacterNum, QItem.usQuoteNum, QItem.iFaceIndex, DIALOGUE_TACTICAL_UI, TRUE ); + ExecuteSnitchCharacterDialogue( QItem.ubCharacterNum, QItem.usQuoteNum, QItem.iFaceIndex, QItem.bUIHandlerID, QItem.uiSpecialEventData2, QItem.uiSpecialEventData3, QItem.uiSpecialEventData4 ); } // Flugente: additional dialogue - else if ( QItem->uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_ADDITIONAL_DIALOGUE ) + else if ( QItem.uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_ADDITIONAL_DIALOGUE ) { // Flugente: only set up face if we can access correctly - if ( QItem->iFaceIndex >= 0 ) + if ( QItem.iFaceIndex >= 0 ) { // Setup face pointer - gpCurrentTalkingFace = &gFacesData[QItem->iFaceIndex]; + gpCurrentTalkingFace = &gFacesData[QItem.iFaceIndex]; } - gubCurrentTalkingID = QItem->iFaceIndex; + gubCurrentTalkingID = QItem.iFaceIndex; extern BOOLEAN ExecuteAdditionalCharacterDialogue( UINT8 ubProfile, INT32 iFaceIndex, UINT16 usEventNr, UINT32 aData1, UINT32 aData2, UINT32 aData3 ); - ExecuteAdditionalCharacterDialogue( QItem->ubCharacterNum, QItem->iFaceIndex, QItem->usQuoteNum, QItem->uiSpecialEventData2, QItem->uiSpecialEventData3, QItem->uiSpecialEventData4 ); + ExecuteAdditionalCharacterDialogue( QItem.ubCharacterNum, QItem.iFaceIndex, QItem.usQuoteNum, QItem.uiSpecialEventData2, QItem.uiSpecialEventData3, QItem.uiSpecialEventData4 ); } #ifdef JA2UB //JA25 UB - if ( QItem->uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_TEAM_MEMBERS_DONE_TALKING ) + if ( QItem.uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_TEAM_MEMBERS_DONE_TALKING ) { HandleEveryoneDoneTheirEndGameQuotes(); } else { // grab soldier ptr from profile ID - pSoldier = FindSoldierByProfileID( (UINT8)QItem->uiSpecialEventData, FALSE ); + pSoldier = FindSoldierByProfileID( (UINT8)QItem.uiSpecialEventData, FALSE ); // FindSoldier was returning a lot of nullptrs which would crash the game very quickly after Jerry gets up. This check is here to circumvent that. if (pSoldier != nullptr) @@ -1429,17 +1385,17 @@ void HandleDialogue( ) } } #else //Ja25 No queen - if ( QItem->uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_DONE_KILLING_DEIDRANNA ) + if ( QItem.uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_DONE_KILLING_DEIDRANNA ) { HandleDoneLastKilledQueenQuote( ); } - else if ( QItem->uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_TEAM_MEMBERS_DONE_TALKING ) + else if ( QItem.uiSpecialEventData & MULTIPURPOSE_SPECIAL_EVENT_TEAM_MEMBERS_DONE_TALKING ) { HandleDoneLastEndGameQuote( ); } } #endif - else if( QItem->uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SLEEP ) + else if( QItem.uiSpecialEventFlag & DIALOGUE_SPECIAL_EVENT_SLEEP ) { // no soldier, leave now if( pSoldier == NULL ) @@ -1448,7 +1404,7 @@ void HandleDialogue( ) } // wake merc up or put them back down? - if( QItem->uiSpecialEventData == 1 ) + if( QItem.uiSpecialEventData == 1 ) { pSoldier->flags.fMercAsleep = TRUE; } @@ -1464,20 +1420,17 @@ void HandleDialogue( ) } // grab soldier ptr from profile ID - pSoldier = FindSoldierByProfileID( QItem->ubCharacterNum, FALSE ); + pSoldier = FindSoldierByProfileID( QItem.ubCharacterNum, FALSE ); if ( pSoldier && pSoldier->bTeam == gbPlayerNum ) { - CheckForStopTimeQuotes( QItem->usQuoteNum ); + CheckForStopTimeQuotes( QItem.usQuoteNum ); } - if( QItem->fPauseTime ) + if( QItem.fPauseTime ) { fWasPausedDuringDialogue = TRUE; } - - // Delete memory - MemFree( QItem ); } BOOLEAN GetDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, UINT32 iDataSize, STR16 zDialogueText, UINT32 *puiSoundID, CHAR8 *zSoundString ); @@ -1845,27 +1798,23 @@ void AdditionalTacticalCharacterDialogue_AllInSectorRadiusCall( UINT8 ausIgnoreP BOOLEAN CharacterDialogueWithSpecialEvent( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 iFaceIndex, UINT8 bUIHandlerID, BOOLEAN fFromSoldier, BOOLEAN fDelayed, UINT32 uiFlag, UINT32 uiData1, UINT32 uiData2 ) { - DIALOGUE_Q_STRUCT *QItem; - - // Allocate new item - QItem = (DIALOGUE_Q_STRUCT *) MemAlloc( sizeof( DIALOGUE_Q_STRUCT ) ); - memset( QItem, 0, sizeof( DIALOGUE_Q_STRUCT ) ); - - QItem->ubCharacterNum = ubCharacterNum; - QItem->usQuoteNum = usQuoteNum; - QItem->iFaceIndex = iFaceIndex; - QItem->bUIHandlerID = bUIHandlerID; - QItem->iTimeStamp = GetJA2Clock( ); - QItem->fFromSoldier = fFromSoldier; - QItem->fDelayed = fDelayed; + DIALOGUE_Q_STRUCT QItem; + memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + QItem.ubCharacterNum = ubCharacterNum; + QItem.usQuoteNum = usQuoteNum; + QItem.iFaceIndex = iFaceIndex; + QItem.bUIHandlerID = bUIHandlerID; + QItem.iTimeStamp = GetJA2Clock( ); + QItem.fFromSoldier = fFromSoldier; + QItem.fDelayed = fDelayed; // Set flag for special event - QItem->uiSpecialEventFlag = uiFlag; - QItem->uiSpecialEventData = uiData1; - QItem->uiSpecialEventData2 = uiData2; + QItem.uiSpecialEventFlag = uiFlag; + QItem.uiSpecialEventData = uiData1; + QItem.uiSpecialEventData2 = uiData2; // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); + ghDialogueQ.push(QItem); // sevenfm: disable FF for dialogues if (IsFastForwardMode()) @@ -1884,28 +1833,24 @@ BOOLEAN CharacterDialogueWithSpecialEvent( UINT8 ubCharacterNum, UINT16 usQuoteN BOOLEAN CharacterDialogueWithSpecialEventEx( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 iFaceIndex, UINT8 bUIHandlerID, BOOLEAN fFromSoldier, BOOLEAN fDelayed, UINT32 uiFlag, UINT32 uiData1, UINT32 uiData2, UINT32 uiData3 ) { - DIALOGUE_Q_STRUCT *QItem; - - // Allocate new item - QItem = (DIALOGUE_Q_STRUCT *) MemAlloc( sizeof( DIALOGUE_Q_STRUCT ) ); - memset( QItem, 0, sizeof( DIALOGUE_Q_STRUCT ) ); - - QItem->ubCharacterNum = ubCharacterNum; - QItem->usQuoteNum = usQuoteNum; - QItem->iFaceIndex = iFaceIndex; - QItem->bUIHandlerID = bUIHandlerID; - QItem->iTimeStamp = GetJA2Clock( ); - QItem->fFromSoldier = fFromSoldier; - QItem->fDelayed = fDelayed; + DIALOGUE_Q_STRUCT QItem; + memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + QItem.ubCharacterNum = ubCharacterNum; + QItem.usQuoteNum = usQuoteNum; + QItem.iFaceIndex = iFaceIndex; + QItem.bUIHandlerID = bUIHandlerID; + QItem.iTimeStamp = GetJA2Clock( ); + QItem.fFromSoldier = fFromSoldier; + QItem.fDelayed = fDelayed; // Set flag for special event - QItem->uiSpecialEventFlag = uiFlag; - QItem->uiSpecialEventData = uiData1; - QItem->uiSpecialEventData2 = uiData2; - QItem->uiSpecialEventData3 = uiData3; + QItem.uiSpecialEventFlag = uiFlag; + QItem.uiSpecialEventData = uiData1; + QItem.uiSpecialEventData2 = uiData2; + QItem.uiSpecialEventData3 = uiData3; // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); + ghDialogueQ.push(QItem); if ( uiFlag & DIALOGUE_SPECIAL_EVENT_PCTRIGGERNPC ) { @@ -1918,30 +1863,26 @@ BOOLEAN CharacterDialogueWithSpecialEventEx( UINT8 ubCharacterNum, UINT16 usQuot BOOLEAN CharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 iFaceIndex, UINT8 bUIHandlerID, BOOLEAN fFromSoldier, BOOLEAN fDelayed ) { - DIALOGUE_Q_STRUCT *QItem; - - // Allocate new item - QItem = (DIALOGUE_Q_STRUCT *) MemAlloc( sizeof( DIALOGUE_Q_STRUCT ) ); - memset( QItem, 0, sizeof( DIALOGUE_Q_STRUCT ) ); - - QItem->ubCharacterNum = ubCharacterNum; - QItem->usQuoteNum = usQuoteNum; - QItem->iFaceIndex = iFaceIndex; - QItem->bUIHandlerID = bUIHandlerID; - QItem->iTimeStamp = GetJA2Clock( ); - QItem->fFromSoldier = fFromSoldier; - QItem->fDelayed = fDelayed; + DIALOGUE_Q_STRUCT QItem; + memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + QItem.ubCharacterNum = ubCharacterNum; + QItem.usQuoteNum = usQuoteNum; + QItem.iFaceIndex = iFaceIndex; + QItem.bUIHandlerID = bUIHandlerID; + QItem.iTimeStamp = GetJA2Clock( ); + QItem.fFromSoldier = fFromSoldier; + QItem.fDelayed = fDelayed; // check if pause already locked, if so, then don't mess with it if( gfLockPauseState == FALSE ) { - QItem->fPauseTime = fPausedTimeDuringQuote; + QItem.fPauseTime = fPausedTimeDuringQuote; } fPausedTimeDuringQuote = FALSE; // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); + ghDialogueQ.push(QItem); // Flugente: additional dialogue // in the dialogue screen, only the merc doing the talking may answer @@ -1973,35 +1914,31 @@ BOOLEAN SnitchCharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 UINT32 uiSpecialEventData3, UINT32 uiSpecialEventData4, UINT8 bUIHandlerID, BOOLEAN fFromSoldier, BOOLEAN fDelayed ) { - DIALOGUE_Q_STRUCT *QItem; - - // Allocate new item - QItem = (DIALOGUE_Q_STRUCT *) MemAlloc( sizeof( DIALOGUE_Q_STRUCT ) ); - memset( QItem, 0, sizeof( DIALOGUE_Q_STRUCT ) ); - - QItem->ubCharacterNum = ubCharacterNum; - QItem->usQuoteNum = usQuoteNum; - QItem->uiSpecialEventFlag = uiSpecialEventFlag; - QItem->uiSpecialEventData = uiSpecialEventData1; - QItem->uiSpecialEventData2 = uiSpecialEventData2; - QItem->uiSpecialEventData3 = uiSpecialEventData3; - QItem->uiSpecialEventData4 = uiSpecialEventData4; - QItem->iFaceIndex = iFaceIndex; - QItem->bUIHandlerID = bUIHandlerID; - QItem->iTimeStamp = GetJA2Clock( ); - QItem->fFromSoldier = fFromSoldier; - QItem->fDelayed = fDelayed; + DIALOGUE_Q_STRUCT QItem; + memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + QItem.ubCharacterNum = ubCharacterNum; + QItem.usQuoteNum = usQuoteNum; + QItem.uiSpecialEventFlag = uiSpecialEventFlag; + QItem.uiSpecialEventData = uiSpecialEventData1; + QItem.uiSpecialEventData2 = uiSpecialEventData2; + QItem.uiSpecialEventData3 = uiSpecialEventData3; + QItem.uiSpecialEventData4 = uiSpecialEventData4; + QItem.iFaceIndex = iFaceIndex; + QItem.bUIHandlerID = bUIHandlerID; + QItem.iTimeStamp = GetJA2Clock( ); + QItem.fFromSoldier = fFromSoldier; + QItem.fDelayed = fDelayed; // check if pause already locked, if so, then don't mess with it if( gfLockPauseState == FALSE ) { - QItem->fPauseTime = fPausedTimeDuringQuote; + QItem.fPauseTime = fPausedTimeDuringQuote; } fPausedTimeDuringQuote = FALSE; // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); + ghDialogueQ.push(QItem); return( TRUE ); } @@ -2009,63 +1946,53 @@ BOOLEAN SnitchCharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 BOOLEAN SpecialCharacterDialogueEvent( UINT32 uiSpecialEventFlag, UINT32 uiSpecialEventData1, UINT32 uiSpecialEventData2, UINT32 uiSpecialEventData3, INT32 iFaceIndex, UINT8 bUIHandlerID ) { - DIALOGUE_Q_STRUCT *QItem; - - // Allocate new item - QItem = (DIALOGUE_Q_STRUCT *) MemAlloc( sizeof( DIALOGUE_Q_STRUCT ) ); - memset( QItem, 0, sizeof( DIALOGUE_Q_STRUCT ) ); - - QItem->uiSpecialEventFlag = uiSpecialEventFlag; - QItem->uiSpecialEventData = uiSpecialEventData1; - QItem->uiSpecialEventData2 = uiSpecialEventData2; - QItem->uiSpecialEventData3 = uiSpecialEventData3; - QItem->iFaceIndex = iFaceIndex; - QItem->bUIHandlerID = bUIHandlerID; - QItem->iTimeStamp = GetJA2Clock( ); + DIALOGUE_Q_STRUCT QItem; + memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + QItem.uiSpecialEventFlag = uiSpecialEventFlag; + QItem.uiSpecialEventData = uiSpecialEventData1; + QItem.uiSpecialEventData2 = uiSpecialEventData2; + QItem.uiSpecialEventData3 = uiSpecialEventData3; + QItem.iFaceIndex = iFaceIndex; + QItem.bUIHandlerID = bUIHandlerID; + QItem.iTimeStamp = GetJA2Clock( ); // if paused state not already locked if( gfLockPauseState == FALSE ) { - QItem->fPauseTime = fPausedTimeDuringQuote; + QItem.fPauseTime = fPausedTimeDuringQuote; } fPausedTimeDuringQuote = FALSE; // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); - + ghDialogueQ.push(QItem); return( TRUE ); } BOOLEAN SpecialCharacterDialogueEventWithExtraParam( UINT32 uiSpecialEventFlag, UINT32 uiSpecialEventData1, UINT32 uiSpecialEventData2, UINT32 uiSpecialEventData3, UINT32 uiSpecialEventData4, INT32 iFaceIndex, UINT8 bUIHandlerID ) { - DIALOGUE_Q_STRUCT *QItem; - - // Allocate new item - QItem = (DIALOGUE_Q_STRUCT *) MemAlloc( sizeof( DIALOGUE_Q_STRUCT ) ); - memset( QItem, 0, sizeof( DIALOGUE_Q_STRUCT ) ); - - QItem->uiSpecialEventFlag = uiSpecialEventFlag; - QItem->uiSpecialEventData = uiSpecialEventData1; - QItem->uiSpecialEventData2 = uiSpecialEventData2; - QItem->uiSpecialEventData3 = uiSpecialEventData3; - QItem->uiSpecialEventData4 = uiSpecialEventData4; - QItem->iFaceIndex = iFaceIndex; - QItem->bUIHandlerID = bUIHandlerID; - QItem->iTimeStamp = GetJA2Clock( ); + DIALOGUE_Q_STRUCT QItem; + memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + QItem.uiSpecialEventFlag = uiSpecialEventFlag; + QItem.uiSpecialEventData = uiSpecialEventData1; + QItem.uiSpecialEventData2 = uiSpecialEventData2; + QItem.uiSpecialEventData3 = uiSpecialEventData3; + QItem.uiSpecialEventData4 = uiSpecialEventData4; + QItem.iFaceIndex = iFaceIndex; + QItem.bUIHandlerID = bUIHandlerID; + QItem.iTimeStamp = GetJA2Clock( ); // if paused state not already locked if( gfLockPauseState == FALSE ) { - QItem->fPauseTime = fPausedTimeDuringQuote; + QItem.fPauseTime = fPausedTimeDuringQuote; } fPausedTimeDuringQuote = FALSE; // Add to queue - ghDialogueQ = AddtoQueue( ghDialogueQ, &QItem ); - + ghDialogueQ.push(QItem); return( TRUE ); } From 4b1de56b016ce375675218ef0ee1fe719ee4e48f Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:45:06 +0300 Subject: [PATCH 06/16] Remove #ifdefs for USE_VFS --- CMakeLists.txt | 2 +- Editor/LoadScreen.cpp | 43 +- Editor/LoadScreen.h | 2 - Editor/Sector Summary.cpp | 176 ----- Laptop/IMP Confirm.cpp | 11 - MainMenuScreen.cpp | 2 - SaveLoadGame.cpp | 28 - SaveLoadScreen.cpp | 2 - Standard Gaming Platform/DEBUG.H | 2 - Standard Gaming Platform/DEBUG.cpp | 2 - Standard Gaming Platform/FileMan.cpp | 902 ------------------------ Standard Gaming Platform/MemMan.cpp | 18 - Standard Gaming Platform/Types.h | 22 +- Standard Gaming Platform/WinFont.cpp | 16 - Standard Gaming Platform/sgp.cpp | 122 ---- Standard Gaming Platform/sgp_logger.cpp | 34 - Standard Gaming Platform/sgp_logger.h | 34 +- Standard Gaming Platform/soundman.cpp | 14 - Standard Gaming Platform/video.cpp | 79 --- Strategic/Campaign Init.cpp | 21 - Strategic/Strategic AI.cpp | 41 -- Strategic/strategicmap.cpp | 75 -- Tactical/Tactical Save.cpp | 26 - TileEngine/SaveLoadMap.cpp | 6 - TileEngine/Shade Table Util.cpp | 31 - TileEngine/WorldDat.cpp | 2 - TileEngine/worlddef.cpp | 8 - Utils/Cinematics Bink.cpp | 16 - Utils/Cinematics.cpp | 18 - Utils/Debug Control.cpp | 20 - Utils/INIReader.cpp | 111 +-- Utils/INIReader.h | 6 +- Utils/message.cpp | 14 - jascreens.cpp | 19 - 34 files changed, 9 insertions(+), 1916 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b196f87e6..5a36e8481 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ set(usingMsBuild $) # TODO: build our own Lua 5.1.2 from source so we can use whichever set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -add_compile_definitions(CINTERFACE XML_STATIC VFS_STATIC VFS_WITH_SLF VFS_WITH_7ZIP USE_VFS _CRT_SECURE_NO_DEPRECATE) +add_compile_definitions(CINTERFACE XML_STATIC VFS_STATIC VFS_WITH_SLF VFS_WITH_7ZIP _CRT_SECURE_NO_DEPRECATE) include_directories(${CMAKE_SOURCE_DIR} "ext/VFS/include" Utils TileEngine TacticalAI ModularizedTacticalAI Tactical Strategic "Standard Gaming Platform" Res Lua Laptop Multiplayer "Multiplayer/raknet" Editor Console) # external libraries diff --git a/Editor/LoadScreen.cpp b/Editor/LoadScreen.cpp index 81a9e0248..7c7d70b4e 100644 --- a/Editor/LoadScreen.cpp +++ b/Editor/LoadScreen.cpp @@ -83,9 +83,7 @@ INT32 iCurrFileShown; INT32 iLastFileClicked; INT32 iLastClickTime; -#ifdef USE_VFS CHAR8 gzProfileName[FILENAME_BUFLEN];//dnl ch81 021213 -#endif CHAR16 gzFilename[FILENAME_BUFLEN];//dnl ch39 190909 extern INT16 gsSelSectorX; extern INT16 gsSelSectorY; @@ -165,7 +163,6 @@ void LoadSaveScreenEntry() } iTopFileShown = iTotalFiles = 0; -#ifdef USE_VFS//dnl ch37 300909 gzProfileName[0] = 0;//dnl ch81 021213 FDLG_LIST* TempFileList = NULL; vfs::CProfileStack* st = getVFS()->getProfileStack(); @@ -220,25 +217,6 @@ void LoadSaveScreenEntry() } while(FileList->pPrev) FileList = FileList->pPrev; -#else - if(GetFileFirst("MAPS\\*.dat", &FileInfo)) - { - if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) - { - FileList = AddToFDlgList(FileList, &FileInfo); - iTotalFiles++; - } - while(GetFileNext(&FileInfo)) - { - if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) - { - FileList = AddToFDlgList(FileList, &FileInfo); - iTotalFiles++; - } - } - GetFileClose(&FileInfo); - } -#endif swprintf( zOrigName, L"%s Map (*.dat)", iCurrentAction == ACTION_SAVE_MAP ? L"Save" : L"Load" ); swprintf( gzFilename, L"%S", gubFilename ); @@ -283,7 +261,8 @@ UINT32 ProcessLoadSaveScreenMessageBoxResult() { if( gfReadOnly ) { - FileClearAttributes( gszCurrFilename ); + // Other call sites have replaced this with FileDelete(); for VFS, should we do the same here? + //FileClearAttributes( gszCurrFilename ); gfReadOnly = FALSE; } FileDelete( gszCurrFilename ); @@ -468,19 +447,6 @@ UINT32 LoadSaveScreenHandle(void) } sprintf(gszCurrFilename, "MAPS\\%S", gzFilename); gfFileExists = FALSE; -#ifndef USE_VFS - gfReadOnly = FALSE; - if(FileExists(gszCurrFilename)) - { - gfFileExists = TRUE; - if(GetFileFirst(gszCurrFilename, &FileInfo)) - { - if(FileInfo.uiFileAttribs & (FILE_IS_READONLY|FILE_IS_DIRECTORY|FILE_IS_HIDDEN|FILE_IS_SYSTEM|FILE_IS_OFFLINE|FILE_IS_TEMPORARY)) - gfReadOnly = TRUE; - GetFileClose(&FileInfo); - } - } -#else gfReadOnly = TRUE; vfs::CProfileStack* st = getVFS()->getProfileStack(); vfs::CProfileStack::Iterator it = st->begin(); @@ -502,7 +468,6 @@ UINT32 LoadSaveScreenHandle(void) } it.next(); } -#endif if(gfReadOnly) { CreateMessageBox(L" File is read only! Choose a different name? "); @@ -726,7 +691,6 @@ void SelectFileDialogYPos( UINT16 usRelativeYPos ) iLastClickTime = iCurrClickTime; iLastFileClicked = x; //dnl ch81 021213 -#ifdef USE_VFS gzProfileName[0] = 0; while(FListNode = FListNode->pPrev) { @@ -737,7 +701,6 @@ void SelectFileDialogYPos( UINT16 usRelativeYPos ) break; } } -#endif break; } FListNode = FListNode->pNext; @@ -950,7 +913,6 @@ void HandleMainKeyEvents( InputAtom *pEvent ) SetInputFieldStringWith16BitString(0, L""); wcscpy(gzFilename, L""); } -#ifdef USE_VFS gzProfileName[0] = 0; while(curr = curr->pPrev) { @@ -961,7 +923,6 @@ void HandleMainKeyEvents( InputAtom *pEvent ) break; } } -#endif } } } diff --git a/Editor/LoadScreen.h b/Editor/LoadScreen.h index 07b08c743..c8adac4cf 100644 --- a/Editor/LoadScreen.h +++ b/Editor/LoadScreen.h @@ -51,9 +51,7 @@ extern CHAR16 gzErrorCatchString[ 256 ]; //dnl ch81 031213 extern CHAR16 gzFilename[FILENAME_BUFLEN]; -#ifdef USE_VFS extern CHAR8 gzProfileName[FILENAME_BUFLEN]; -#endif #endif #endif diff --git a/Editor/Sector Summary.cpp b/Editor/Sector Summary.cpp index aa4865524..b71742472 100644 --- a/Editor/Sector Summary.cpp +++ b/Editor/Sector Summary.cpp @@ -1923,40 +1923,14 @@ BOOLEAN HandleSummaryInput( InputAtom *pEvent ) void CreateGlobalSummary() { -#ifndef USE_VFS - FILE *fp; - STRING512 Dir; - STRING512 ExecDir; -#endif OutputDebugString( "Generating GlobalSummary Information...\n" ); gfGlobalSummaryExists = FALSE; //Set current directory to JA2\DevInfo which contains all of the summary data -#ifndef USE_VFS - GetExecutableDirectory( ExecDir ); - sprintf( Dir, "%s\\DevInfo", ExecDir ); - - // Snap: save current directory - //GetFileManCurrentDirectory( DataDir ); - - //Directory doesn't exist, so create it, and continue. - if( !MakeFileManDirectory( Dir ) ) - AssertMsg( 0, "Can't create new directory, JA2\\DevInfo for summary information." ); - if( !SetFileManCurrentDirectory( Dir ) ) - AssertMsg( 0, "Can't set to new directory, JA2\\DevInfo for summary information." ); - - //Generate a simple readme file. - fp = fopen( "readme.txt", "w" ); - Assert( fp ); - fprintf( fp, "%s\n%s\n", "This information is used in conjunction with the editor.", - "This directory or it's contents shouldn't be included with final release." ); - fclose( fp ); -#else vfs::COpenWriteFile wfile(L"DevInfo\\readme.txt",true,true); std::string str = "This information is used in conjunction with the editor.\n"; str += "This directory or it's contents shouldn't be included with final release.\n"; SGP_TRYCATCH_RETHROW( wfile->write(str.c_str(), str.length()), L"" ); -#endif // Snap: Restore the data directory once we are finished. //SetFileManCurrentDirectory( DataDir ); @@ -2281,12 +2255,6 @@ void CalculateOverrideStatus() void LoadGlobalSummary() { HWFILE hfile; -#ifndef USE_VFS - STRING512 DataDir; - STRING512 ExecDir; - STRING512 DevInfoDir; - STRING512 MapsDir; -#endif UINT32 uiNumBytesRead; FLOAT dMajorVersion; INT32 x,y; @@ -2295,34 +2263,16 @@ void LoadGlobalSummary() OutputDebugString( "Executing LoadGlobalSummary()...\n" ); // Snap: save current directory -#ifndef USE_VFS - GetFileManCurrentDirectory( DataDir ); -#endif gfMustForceUpdateAllMaps = FALSE; gusNumberOfMapsToBeForceUpdated = 0; gfGlobalSummaryExists = FALSE; //Set current directory to JA2\DevInfo which contains all of the summary data -#ifndef USE_VFS - GetExecutableDirectory( ExecDir ); - sprintf( DevInfoDir, "%s\\DevInfo", ExecDir ); - sprintf( MapsDir, "%s\\Maps", DataDir ); - //Check to make sure we have a DevInfo directory. If we don't create one! - if( !SetFileManCurrentDirectory( DevInfoDir ) ) - { - OutputDebugString( "LoadGlobalSummary() aborted -- doesn't exist on this local computer.\n"); - return; - } -#endif //TEMP -#ifndef USE_VFS - FileDelete( "_global.sum" ); -#else if(FileExists("DevInfo\\_global.sum")) { FileDelete( "DevInfo\\_global.sum" ); } -#endif gfGlobalSummaryExists = TRUE; //Analyse all sectors to see if matching maps exist. For any maps found, the information @@ -2337,19 +2287,12 @@ void LoadGlobalSummary() sprintf( szSector, "%c%d", 'A' + y, x + 1 ); //main ground level -#ifndef USE_VFS - sprintf( szFilename, "%c%d.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= GROUND_LEVEL_MASK; @@ -2359,27 +2302,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s.sum", szSector ); -#endif FileDelete( szFilename ); } //main B1 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b1.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b1.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= BASEMENT1_LEVEL_MASK; @@ -2389,27 +2321,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b1.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b1.sum", szSector ); -#endif FileDelete( szFilename ); } //main B2 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b2.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b2.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= BASEMENT2_LEVEL_MASK; @@ -2419,27 +2340,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b2.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b2.sum", szSector ); -#endif FileDelete( szFilename ); } //main B3 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b3.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b3.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= BASEMENT3_LEVEL_MASK; @@ -2449,27 +2359,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b3.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b3.sum", szSector ); -#endif FileDelete( szFilename ); } //alternate ground level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_a.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_a.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= ALTERNATE_GROUND_MASK; @@ -2479,27 +2378,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_a.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_a.sum", szSector ); -#endif FileDelete( szFilename ); } //alternate B1 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b1_a.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b1_a.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= ALTERNATE_B1_MASK; @@ -2509,27 +2397,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b1_a.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b1_a.sum", szSector ); -#endif FileDelete( szFilename ); } //alternate B2 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b2_a.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b2_a.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= ALTERNATE_B2_MASK; @@ -2539,27 +2416,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b2_a.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b2_a.sum", szSector ); -#endif FileDelete( szFilename ); } //alternate B3 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b3_a.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b3_a.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= ALTERNATE_B1_MASK;; @@ -2569,20 +2435,12 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b3_a.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b3_a.sum", szSector ); -#endif FileDelete( szFilename ); } } OutputDebugString( (LPCSTR)String("Sector Row %c complete... \n", y + 'A') ); } -#ifndef USE_VFS - // Snap: Restore the data directory once we are finished. - SetFileManCurrentDirectory( DataDir ); -#endif //sprintf( MapsDir, "%s\\Data", ExecDir ); //SetFileManCurrentDirectory( MapsDir ); @@ -2599,39 +2457,6 @@ void LoadGlobalSummary() void GenerateSummaryList() { -#ifndef USE_VFS - FILE *fp; - STRING512 DataDir; - STRING512 ExecDir; - STRING512 Dir; - - // Snap: save current directory - GetFileManCurrentDirectory( DataDir ); - - //Set current directory to JA2\DevInfo which contains all of the summary data - GetExecutableDirectory( ExecDir ); - sprintf( Dir, "%s\\DevInfo", ExecDir ); - if( !SetFileManCurrentDirectory( Dir ) ) - { - //Directory doesn't exist, so create it, and continue. - if( !MakeFileManDirectory( Dir ) ) - AssertMsg( 0, "Can't create new directory, JA2\\DevInfo for summary information." ); - if( !SetFileManCurrentDirectory( Dir ) ) - AssertMsg( 0, "Can't set to new directory, JA2\\DevInfo for summary information." ); - //Generate a simple readme file. - fp = fopen( "readme.txt", "w" ); - Assert( fp ); - fprintf( fp, "%s\n%s\n", "This information is used in conjunction with the editor.", - "This directory or it's contents shouldn't be included with final release." ); - fclose( fp ); - } - - // Snap: Restore the data directory once we are finished. - SetFileManCurrentDirectory( DataDir ); - //Set current directory back to data directory! - //sprintf( Dir, "%s\\Data", ExecDir ); - //SetFileManCurrentDirectory( Dir ); -#else try { vfs::COpenWriteFile wfile(L"DevInfo/readme.txt",true,true); @@ -2643,7 +2468,6 @@ void GenerateSummaryList() { SGP_RETHROW(L"Could not create readme.txt", ex); } -#endif } //dnl ch28 260909 diff --git a/Laptop/IMP Confirm.cpp b/Laptop/IMP Confirm.cpp index 817804620..fd74d9f2d 100644 --- a/Laptop/IMP Confirm.cpp +++ b/Laptop/IMP Confirm.cpp @@ -1336,16 +1336,6 @@ void WriteOutCurrentImpCharacter( INT32 iProfileId ) DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("WriteOutCurrentImpCharacter: Nickname.dat")); -#ifndef USE_VFS - char zFileName[13]; - char temp; - - for(int i=0;i < 9;i++) // Madd: I couldn't get strcpy or anything to work here... weird... if s/o wants to fix it, go ahead - { - temp = (char) gMercProfiles[iProfileId].zNickname[i]; - zFileName[i] = temp; - } -#else char zFileName[32]; if(vfs::Settings::getUseUnicode()) { @@ -1355,7 +1345,6 @@ void WriteOutCurrentImpCharacter( INT32 iProfileId ) { vfs::String::narrow(gMercProfiles[iProfileId].zNickname, 10, zFileName, 32); } -#endif // Changed by ADB, rev 1513 //strcat(zFileName,IMP_FILENAME_SUFFIX); diff --git a/MainMenuScreen.cpp b/MainMenuScreen.cpp index bebe6193c..22d2a2663 100644 --- a/MainMenuScreen.cpp +++ b/MainMenuScreen.cpp @@ -248,7 +248,6 @@ BOOLEAN InitMainMenu( ) { is_networked = FALSE; -#ifdef USE_VFS // remove Multiplayer profile if it exists vfs::CProfileStack *PS = getVFS()->getProfileStack(); vfs::CVirtualProfile *pProf = PS->getProfile("_MULTIPLAYER"); @@ -256,7 +255,6 @@ BOOLEAN InitMainMenu( ) { SGP_THROW_IFFALSE(PS->popProfile(), "Leaving Multiplayer mode : Could not remove \"_MULTIPLAYER\" profile"); } -#endif // Snap: UN-Init MP save game directory if ( !InitSaveDir() ) diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index 3d90f27e3..a013b4558 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -3553,33 +3553,6 @@ BOOLEAN Inventory::Save( HWFILE hFile, bool fSavingMap ) // The save directory now resides in the data directory (default or custom) BOOLEAN InitSaveDir() { -#ifndef USE_VFS - // Look for a custom data dir first - std::string dataDir = gCustomDataCat.GetRootDir(); - if( dataDir.empty() || FileGetAttributes( (STR) dataDir.c_str() ) == 0xFFFFFFFF ) { - dataDir = gDefaultDataCat.GetRootDir(); - } - - // The locale-specific save dir location is of the form L"..\\SavedGames" - // This has not changed; instead, we strip the ".." at the beginning - if(is_networked) - { - sprintf( gSaveDir, "%s%S", dataDir.c_str(), pMessageStrings[ MSG_MPSAVEDIRECTORY ] + 2 ); - } - else - sprintf( gSaveDir, "%s%S", dataDir.c_str(), pMessageStrings[ MSG_SAVEDIRECTORY ] + 2 ); - - // This was moved here from SaveGame - //Check to see if the save directory exists - if( FileGetAttributes( (STR) gSaveDir ) == 0xFFFFFFFF ) - { - //ok the direcotry doesnt exist, create it - if( !MakeFileManDirectory( (CHAR8 *)gSaveDir ) ) - { - return FALSE; - } - } -#else if(is_networked) { sprintf( gSaveDir, "%s", vfs::String::as_utf8(pMessageStrings[ MSG_MPSAVEDIRECTORY ] + 3).c_str() ); @@ -3588,7 +3561,6 @@ BOOLEAN InitSaveDir() { sprintf( gSaveDir, "%s", vfs::String::as_utf8(pMessageStrings[ MSG_SAVEDIRECTORY ] + 3).c_str() ); } -#endif return TRUE; } diff --git a/SaveLoadScreen.cpp b/SaveLoadScreen.cpp index 5fe319ff9..e5442659f 100644 --- a/SaveLoadScreen.cpp +++ b/SaveLoadScreen.cpp @@ -1350,7 +1350,6 @@ BOOLEAN InitSaveGameArray() gbSaveGameArray[VAL_SLOT_START + cnt] = TRUE; // anv: read last modified date property of save file -#ifdef USE_VFS // get full path to save file vfs::Path vfsPath; vfs::COpenReadFile rfile(zSaveGameName); @@ -1369,7 +1368,6 @@ BOOLEAN InitSaveGameArray() // close CloseHandle( hFile ); rfile->close(); -#endif } } else diff --git a/Standard Gaming Platform/DEBUG.H b/Standard Gaming Platform/DEBUG.H index 2b2e3169f..1d0d0c3ed 100644 --- a/Standard Gaming Platform/DEBUG.H +++ b/Standard Gaming Platform/DEBUG.H @@ -252,10 +252,8 @@ namespace sgp // compatibility with std::exception Exception(WString const& msg, std::exception& ex SGP_CALLER_LOCATION); -#if defined(USE_VFS) // compatibility with vfs::Exception Exception(WString const& msg, vfs::Exception& ex SGP_CALLER_LOCATION); -#endif virtual const char* what() const throw(); diff --git a/Standard Gaming Platform/DEBUG.cpp b/Standard Gaming Platform/DEBUG.cpp index 8463e9fb4..2aad673b1 100644 --- a/Standard Gaming Platform/DEBUG.cpp +++ b/Standard Gaming Platform/DEBUG.cpp @@ -562,7 +562,6 @@ sgp::Exception::Exception(sgp::WString const& msg, Exception& ex SGP_CALLER_LOCA _msg.push_back(excp); } -#if defined(USE_VFS) sgp::Exception::Exception(sgp::WString const& msg, vfs::Exception& ex SGP_CALLER_LOCATION_IMPL) { vfs::Exception::CALLSTACK::iterator it = ex.m_CallStack.begin(); @@ -584,7 +583,6 @@ sgp::Exception::Exception(sgp::WString const& msg, vfs::Exception& ex SGP_CALLER _msg.push_back(excp); } -#endif sgp::Exception::Exception(WString const& msg, std::exception& ex SGP_CALLER_LOCATION_IMPL) { diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index 0de5e3d80..e7f2a1d0d 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -47,7 +47,6 @@ using namespace std; #include #include -#ifdef USE_VFS #include #include @@ -66,7 +65,6 @@ struct SOperation typedef std::map tFILEMAP; static tFILEMAP s_mapFiles; -#endif //************************************************************************** // // Defines @@ -250,26 +248,7 @@ void FileDebug( BOOLEAN f ) //************************************************************************** BOOLEAN FileExists( STR strFilename ) { -#ifdef USE_VFS return getVFS()->fileExists(vfs::Path(strFilename)); -#else - // First check to see if it's in a library (most files should be there) - if ( gFileDataBase.fInitialized && - CheckIfFileExistInLibrary( strFilename ) ) return TRUE; - - // ... then check if it's in the custom Data directory - if ( gCustomDataCat.FindFile(strFilename) ) return TRUE; - - // ... then check if it's in the default Data directory - if ( gDefaultDataCat.FindFile(strFilename) ) return TRUE; - - // ... lastly, try to locate it in the file system - DWORD attribs = GetFileAttributes(strFilename); - if ( attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY) ) - return TRUE; - - return FALSE; -#endif } //************************************************************************** @@ -296,22 +275,7 @@ BOOLEAN FileExists( STR strFilename ) //************************************************************************** extern BOOLEAN FileExistsNoDB( STR strFilename ) { -#ifdef USE_VFS return getVFS()->fileExists(vfs::Path(strFilename)); -#else - // First check if it's in the custom Data directory - if ( gCustomDataCat.FindFile(strFilename) ) return TRUE; - - // ... then check if it's in the default Data directory - if ( gDefaultDataCat.FindFile(strFilename) ) return TRUE; - - // ... lastly, try to locate it in the file system - DWORD attribs = GetFileAttributes(strFilename); - if ( attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY) ) - return TRUE; - - return FALSE; -#endif } //************************************************************************** @@ -336,16 +300,7 @@ extern BOOLEAN FileExistsNoDB( STR strFilename ) //************************************************************************** BOOLEAN FileDelete( STR strFilename ) { -#ifdef USE_VFS return getVFS()->removeFileFromFS(vfs::Path(strFilename)); -#else - // Snap: delete the file from the default Data catalogue (if it is there) - // Since the path can be either relative or absolute, try both methods - gDefaultDataCat.RemoveFile(strFilename, true); - gDefaultDataCat.RemoveFile(strFilename, false); - - return( DeleteFile( (LPCSTR) strFilename ) ); -#endif } //************************************************************************** @@ -375,7 +330,6 @@ BOOLEAN FileDelete( STR strFilename ) //************************************************************************** HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose, STR strProfilename )//dnl ch81 021213 { -#ifdef USE_VFS vfs::Path path(strFilename); vfs::IBaseFile *pFile = NULL; try @@ -418,148 +372,6 @@ HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose, STR SGP_ERROR( "Caught undefined exception" ); } return 0; -#else - HWFILE hFile; - HANDLE hRealFile; - DWORD dwAccess; - DWORD dwFlagsAndAttributes; - BOOLEAN fExists; - HDBFILE hDBFile; - DWORD dwCreationFlags; - HWFILE hLibFile; - - hFile = 0; - hDBFile = 0; - dwCreationFlags = 0; - - dwAccess = 0; - if ( uiOptions & FILE_ACCESS_READ ) - dwAccess |= GENERIC_READ; - if ( uiOptions & FILE_ACCESS_WRITE ) - dwAccess |= GENERIC_WRITE; - - dwFlagsAndAttributes = FILE_FLAG_RANDOM_ACCESS; - if ( fDeleteOnClose ) - dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; - - // Snap: This seems like an unnecessary check, but I don't feel like - // rewriting the function to eliminate it... - - // check if the file exists - note that we use the function FileExistsNoDB - // because it doesn't check the databases, and we don't want to do that here - fExists = FileExistsNoDB( strFilename ); - - // Snap: First see if the file is in the custom Data catalogue: - std::string filePath; - if ( gCustomDataCat.FindFile(strFilename) ) { - filePath = gCustomDataCat.GetRootDir() + '\\'; - } - filePath += strFilename; - // Bad cast! strFilename should have been const. Oh well... - strFilename = const_cast( filePath.c_str() ); - // Now strFilename points either to the original file name, - // or to the full file path in the custom Data directory. - // Except for this substitution, the rest of the function is unchanged. - - //if the file is on the disk - if ( fExists ) - { - hRealFile = CreateFile( (LPCSTR) strFilename, dwAccess, 0, NULL, OPEN_ALWAYS, - dwFlagsAndAttributes, NULL ); - - if ( hRealFile == INVALID_HANDLE_VALUE ) - { - return(0); - } - - //create a file handle for the 'real file' - hFile = CreateRealFileHandle( hRealFile ); - } - - // if the file did not exist, try to open it from the database - else if ( gFileDataBase.fInitialized ) - { - //if the file is to be opened for writing, return an error cause you cant write a file that is in the database library - if( fDeleteOnClose ) - { - return( 0 ); - } - - //if the file doesnt exist on the harddrive, but it is to be created, dont try to load it from the file database - if( uiOptions & FILE_ACCESS_WRITE ) - { - //if the files is to be written to - if( ( uiOptions & FILE_CREATE_NEW ) || ( uiOptions & FILE_OPEN_ALWAYS ) || ( uiOptions & FILE_CREATE_ALWAYS ) || ( uiOptions & FILE_TRUNCATE_EXISTING ) ) - { - hFile = 0; - } - } - //else if the file is to be opened using FILE_OPEN_EXISTING, and the file doesnt exists, fail out of the function) -// else if( uiOptions & FILE_OPEN_EXISTING ) -// { - //fail out of the function -// return( 0 ); -// } - else - { - //If the file is in the library, get a handle to it. - hLibFile = OpenFileFromLibrary( strFilename ); - - //tried to open a file that wasnt in the database - if( !hLibFile ) - return( 0 ); - else - return( hLibFile ); //return the file handle - } - } - - if ( !hFile ) - { - if ( uiOptions & FILE_CREATE_NEW ) - { - dwCreationFlags = CREATE_NEW; - } - else if ( uiOptions & FILE_CREATE_ALWAYS ) - { - dwCreationFlags = CREATE_ALWAYS; - } - else if ( uiOptions & FILE_OPEN_EXISTING || uiOptions & FILE_ACCESS_READ ) - { - dwCreationFlags = OPEN_EXISTING; - } - else if ( uiOptions & FILE_OPEN_ALWAYS ) - { - dwCreationFlags = OPEN_ALWAYS; - } - else if ( uiOptions & FILE_TRUNCATE_EXISTING ) - { - dwCreationFlags = TRUNCATE_EXISTING; - } - else - { - dwCreationFlags = OPEN_ALWAYS; - } - - - hRealFile = CreateFile( (LPCSTR) strFilename, dwAccess, 0, NULL, dwCreationFlags, - dwFlagsAndAttributes, NULL ); - if ( hRealFile == INVALID_HANDLE_VALUE ) - { - UINT32 uiLastError = GetLastError(); - char zString[1024]; - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, uiLastError, 0, zString, 1024, NULL); - - return(0); - } - - hFile = CreateRealFileHandle( hRealFile ); - } - - if ( !hFile ) - return(0); - - return(hFile); -#endif } //************************************************************************** @@ -581,43 +393,12 @@ HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose, STR //************************************************************************** void FileClose( HWFILE hFile ) { -#ifdef USE_VFS vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; if(pFile) { pFile->close(); s_mapFiles.erase(pFile); } -#else - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its the 'real file' library - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //if its not already closed - if( gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].uiFileID != 0 ) - { - CloseHandle( gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle ); - gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].uiFileID = 0; - gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle= 0; - gFileDataBase.RealFiles.iNumFilesOpen--; - if( gFileDataBase.RealFiles.iNumFilesOpen < 0 ) - { - //if for some reason we are below 0, report an error ( should never be ) - Assert( 0 ); - } - } - } - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - CloseLibraryFile( sLibraryID, uiFileNum ); - } -#endif } //************************************************************************** @@ -669,7 +450,6 @@ private: BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead ) { -#ifdef USE_VFS #ifdef JA2TESTVERSION TimeCounter timer; #endif @@ -702,80 +482,10 @@ BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiByte } } return FALSE; -#else - HANDLE hRealFile; - DWORD dwNumBytesToRead, dwNumBytesRead; - BOOLEAN fRet = FALSE; - INT16 sLibraryID; - UINT32 uiFileNum; - -#ifdef JA2TESTVERSION - UINT32 uiStartTime = GetJA2Clock(); -#endif - - //init the variables - dwNumBytesToRead = dwNumBytesRead = 0; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - dwNumBytesToRead = (DWORD)uiBytesToRead; - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //if the file is opened - if( uiFileNum != 0 ) - { - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - fRet = ReadFile( hRealFile, pDest, dwNumBytesToRead, &dwNumBytesRead, NULL ); - if ( dwNumBytesToRead != dwNumBytesRead ) - { - UINT32 uiLastError = GetLastError(); - char zString[1024]; - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, uiLastError, 0, zString, 1024, NULL); - - fRet = FALSE; - } - - if ( puiBytesRead ) - *puiBytesRead = (UINT32)dwNumBytesRead; - } - } - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - { - //if the file is opened - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - //read the data from the library - fRet = LoadDataFromLibrary( sLibraryID, uiFileNum, pDest, dwNumBytesToRead, (UINT32 *) &dwNumBytesRead ); - if ( puiBytesRead ) - { - *puiBytesRead = (UINT32)dwNumBytesRead; - } - } - } - } - } - #ifdef JA2TESTVERSION - //Add the time that we spent in this function to the total. - uiTotalFileReadTime += GetJA2Clock() - uiStartTime; - uiTotalFileReadCalls++; - #endif - - return(fRet); -#endif } BOOLEAN FileReadLine( HWFILE hFile, std::string* pDest ) { -#ifdef USE_VFS vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; if ( pFile && FileCheckEndOfFile( hFile ) == FALSE && (s_mapFiles[pFile].op == SOperation::READ) ) { @@ -787,7 +497,6 @@ BOOLEAN FileReadLine( HWFILE hFile, std::string* pDest ) return TRUE; } } -#endif // ifdef USE_VFS return FALSE; } @@ -836,7 +545,6 @@ BOOLEAN FileReadLine( HWFILE hFile, STR8 pDest, UINT32 uiDestSize, UINT32 *puiBy BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBytesWritten ) { -#ifdef USE_VFS if(uiBytesToWrite == 0)//dnl ch38 110909 { *puiBytesWritten = 0; @@ -871,42 +579,6 @@ BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBy } } return FALSE; -#else - HANDLE hRealFile; - DWORD dwNumBytesToWrite, dwNumBytesWritten; - BOOLEAN fRet; - INT16 sLibraryID; - UINT32 uiFileNum; - - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - dwNumBytesToWrite = (DWORD)uiBytesToWrite; - - //get the real file handle to the file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - fRet = WriteFile( hRealFile, pDest, dwNumBytesToWrite, &dwNumBytesWritten, NULL ); - - if (dwNumBytesToWrite != dwNumBytesWritten) - fRet = FALSE; - - if ( puiBytesWritten ) - *puiBytesWritten = (UINT32)dwNumBytesWritten; - } - else - { - //we cannot write to a library file - if ( puiBytesWritten ) - *puiBytesWritten = 0; - return(FALSE); - } - - return(fRet); -#endif } //************************************************************************** @@ -932,7 +604,6 @@ BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBy BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead ) { -#ifdef USE_VFS vfs::tReadableFile *pFile = getVFS()->getReadFile(vfs::Path(strFilename)); vfs::COpenReadFile rfile(pFile); if(pFile) @@ -952,30 +623,6 @@ BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiB return TRUE; } return FALSE; -#else - HWFILE hFile; - UINT32 uiNumBytesRead; - BOOLEAN fRet; - - hFile = FileOpen( strFilename, FILE_ACCESS_READ, FALSE ); - if ( hFile ) - { - fRet = FileRead( hFile, pDest, uiBytesToRead, &uiNumBytesRead ); - FileClose( hFile ); - - if (uiBytesToRead != uiNumBytesRead) - fRet = FALSE; - - if ( puiBytesRead ) - *puiBytesRead = uiNumBytesRead; - - CHECKF( uiNumBytesRead == uiBytesToRead ); - } - else - fRet = FALSE; - - return(fRet); -#endif } //************************************************************************** @@ -1008,7 +655,6 @@ BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiB BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... ) { -#ifdef USE_VFS CHAR8 strToSend[160]; /* itemdescription of item 0 will NOT fit if only 80 Chars per Line!, Sergeant_Kolja, 2007-06-10 */ va_list argptr; BOOLEAN fRetVal = FALSE; @@ -1020,34 +666,6 @@ BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... ) fRetVal = FileWrite( hFile, strToSend, strlen(strToSend), NULL ); return( fRetVal ); -#else - CHAR8 strToSend[160]; /* itemdescription of item 0 will NOT fit if only 80 Chars per Line!, Sergeant_Kolja, 2007-06-10 */ - va_list argptr; - BOOLEAN fRetVal = FALSE; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - va_start(argptr, strFormatted); - _vsnprintf( strToSend, DIM(strToSend), strFormatted, argptr ); /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */ - strToSend[ DIM(strToSend)-1 ] = 0; - va_end(argptr); - - fRetVal = FileWrite( hFile, strToSend, strlen(strToSend), NULL ); - } - else - { - //its a library file, cant write to it so return an error - fRetVal = FALSE; - } - - return( fRetVal ); -#endif } //************************************************************************** @@ -1077,7 +695,6 @@ BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... ) BOOLEAN FileSeek( HWFILE hFile, UINT32 uiDistance, UINT8 uiHow ) { -#ifdef USE_VFS INT32 iDistance = (INT32)uiDistance; vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; @@ -1125,50 +742,6 @@ BOOLEAN FileSeek( HWFILE hFile, UINT32 uiDistance, UINT8 uiHow ) } } return FALSE; -#else - HANDLE hRealFile; - LONG lDistanceToMove; - DWORD dwMoveMethod; - INT32 iDistance=0; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to the real file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - iDistance = (INT32) uiDistance; - - if ( uiHow == FILE_SEEK_FROM_START ) - dwMoveMethod = FILE_BEGIN; - else if ( uiHow == FILE_SEEK_FROM_END ) - { - dwMoveMethod = FILE_END; - if( iDistance > 0 ) - iDistance = -(iDistance); - } - else - dwMoveMethod = FILE_CURRENT; - - lDistanceToMove = (LONG)uiDistance; - - if ( SetFilePointer( hRealFile, iDistance, NULL, dwMoveMethod ) == 0xFFFFFFFF ) - return(FALSE); - } - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - LibraryFileSeek( sLibraryID, uiFileNum, uiDistance, uiHow ); - } - - return(TRUE); -#endif } //************************************************************************** @@ -1196,7 +769,6 @@ BOOLEAN FileSeek( HWFILE hFile, UINT32 uiDistance, UINT8 uiHow ) INT32 FileGetPos( HWFILE hFile ) { -#ifdef USE_VFS vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; if(pFile && (s_mapFiles[pFile].op == SOperation::WRITE)) { @@ -1216,44 +788,6 @@ INT32 FileGetPos( HWFILE hFile ) } return BAD_INDEX; -#else - HANDLE hRealFile; - UINT32 uiPositionInFile=0; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to the real file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - uiPositionInFile = SetFilePointer( hRealFile, 0, NULL, FILE_CURRENT); - if( uiPositionInFile == 0xFFFFFFFF ) - { - uiPositionInFile = 0; - } - return( uiPositionInFile ); - } - else - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - { - //check if the file is open - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - uiPositionInFile = gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFilePosInFile; - return( uiPositionInFile ); - } - } - } - - return(BAD_INDEX); -#endif } //************************************************************************** @@ -1281,43 +815,12 @@ INT32 FileGetPos( HWFILE hFile ) UINT32 FileGetSize( HWFILE hFile ) { -#ifdef USE_VFS vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; if(pFile) { return pFile->getSize(); } return 0; -#else - HANDLE hRealHandle; - UINT32 uiFileSize = 0xFFFFFFFF; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to a real file - hRealHandle = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - uiFileSize = GetFileSize( hRealHandle, NULL ); - } - else - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - uiFileSize = gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].pFileHeader->uiFileLength; - } - - - if ( uiFileSize == 0xFFFFFFFF ) - return(0); - else - return( uiFileSize ); -#endif } //************************************************************************** @@ -1632,9 +1135,6 @@ INT32 GetFilesInDirectory( HCONTAINER hStack, CHAR *pcDir, HANDLE hFile, WIN32_F BOOLEAN SetFileManCurrentDirectory( STR pcDirectory ) { -#ifndef USE_VFS - return( SetCurrentDirectory( pcDirectory ) ); -#else try { vfs::OS::setCurrectDirectory(pcDirectory); @@ -1645,19 +1145,11 @@ BOOLEAN SetFileManCurrentDirectory( STR pcDirectory ) return FALSE; } return TRUE; -#endif } BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory ) { -#ifndef USE_VFS - if (GetCurrentDirectory( 512, pcDirectory ) == 0) - { - return( FALSE ); - } - return( TRUE ); -#else try { vfs::Path sDir; @@ -1670,7 +1162,6 @@ BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory ) return FALSE; } return TRUE; -#endif } @@ -1707,11 +1198,7 @@ BOOLEAN DirectoryExists( STRING512 pcDirectory ) BOOLEAN MakeFileManDirectory( STRING512 pcDirectory ) { -#ifndef USE_VFS - return CreateDirectory( pcDirectory, NULL ); -#else return FALSE; -#endif } @@ -1721,87 +1208,8 @@ BOOLEAN MakeFileManDirectory( STRING512 pcDirectory ) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive ) { -#ifdef USE_VFS // ignore 'recursive' flag, just delete every file in that subtree (but leave the directories) return getVFS()->removeDirectoryFromFS(pcDirectory); -#else - WIN32_FIND_DATA sFindData; - HANDLE SearchHandle; - const CHAR8 *pFileSpec = "*.*"; - BOOLEAN fDone = FALSE; - BOOLEAN fRetval=FALSE; - CHAR8 zOldDir[512]; - CHAR8 zSubdirectory[512]; - - GetFileManCurrentDirectory( zOldDir ); - - if( !SetFileManCurrentDirectory( pcDirectory ) ) - { - FastDebugMsg(String("RemoveFileManDirectory: ERROR - SetFileManCurrentDirectory on %s failed, error %d", pcDirectory, GetLastError())); - return( FALSE ); //Error going into directory - } - - //If there are files in the directory, DELETE THEM - SearchHandle = FindFirstFile( pFileSpec, &sFindData); - if( SearchHandle != INVALID_HANDLE_VALUE ) - { - - fDone = FALSE; - do - { - // if the object is a directory - if( GetFileAttributes( sFindData.cFileName ) == FILE_ATTRIBUTE_DIRECTORY ) - { - // only go in if the fRecursive flag is TRUE (like Deltree) - if (fRecursive) - { - sprintf(zSubdirectory, "%s\\%s", pcDirectory, sFindData.cFileName); - - if ((strcmp(sFindData.cFileName, ".") != 0) && (strcmp(sFindData.cFileName, "..") != 0)) - { - if (!RemoveFileManDirectory(zSubdirectory, TRUE)) - { - FastDebugMsg(String("RemoveFileManDirectory: ERROR - Recursive call on %s failed", zSubdirectory)); - break; - } - } - } - // otherwise, all the individual files will be deleted, but the subdirectories remain, causing - // RemoveDirectory() at the end to fail, thus this function will return FALSE in that event (failure) - } - else - { - FileDelete( sFindData.cFileName ); - } - - //find the next file in the directory - fRetval = FindNextFile( SearchHandle, &sFindData ); - if( fRetval == 0 ) - { - fDone = TRUE; - } - } while(!fDone); - - // very important: close the find handle, or subsequent RemoveDirectory() calls will fail - FindClose( SearchHandle ); - } - - if( !SetFileManCurrentDirectory( zOldDir ) ) - { - FastDebugMsg(String("RemoveFileManDirectory: ERROR - SetFileManCurrentDirectory on %s failed, error %d", zOldDir, GetLastError())); - return( FALSE ); //Error returning from subdirectory - } - - - // The directory MUST be empty - fRetval = RemoveDirectory( pcDirectory ); - if (!fRetval) - { - FastDebugMsg(String("RemoveFileManDirectory: ERROR - RemoveDirectory on %s failed, error %d", pcDirectory, GetLastError())); - } - - return fRetval; -#endif } @@ -1811,102 +1219,22 @@ BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive ) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN EraseDirectory( STRING512 pcDirectory) { -#ifdef USE_VFS // ignore 'recursive' flag, just delete every file in that subtree (but leave the directories) return getVFS()->removeDirectoryFromFS(pcDirectory); -#else - WIN32_FIND_DATA sFindData; - HANDLE SearchHandle; - const CHAR8 *pFileSpec = "*.*"; - BOOLEAN fDone = FALSE; - CHAR8 zOldDir[512]; - - GetFileManCurrentDirectory( zOldDir ); - - if( !SetFileManCurrentDirectory( pcDirectory ) ) - { - FastDebugMsg(String("EraseDirectory: ERROR - SetFileManCurrentDirectory on %s failed, error %d", pcDirectory, GetLastError())); - return( FALSE ); //Error going into directory - } - - //If there are files in the directory, DELETE THEM - SearchHandle = FindFirstFile( pFileSpec, &sFindData); - if( SearchHandle != INVALID_HANDLE_VALUE ) - { - - fDone = FALSE; - do - { - // if it's a file, not a directory - if( GetFileAttributes( sFindData.cFileName ) != FILE_ATTRIBUTES_DIRECTORY ) - { - FileDelete( sFindData.cFileName ); - } - - //find the next file in the directory - if ( !FindNextFile( SearchHandle, &sFindData )) - { - fDone = TRUE; - } - } while(!fDone); - - // very important: close the find handle, or subsequent RemoveDirectory() calls will fail - FindClose( SearchHandle ); - } - - // Snap: Delete the directory from the default Data catalogue (if it is there) - // Since the path can be either relative or absolute, try both methods - gDefaultDataCat.RemoveDir(pcDirectory, true); - gDefaultDataCat.RemoveDir(pcDirectory, false); - - if( !SetFileManCurrentDirectory( zOldDir ) ) - { - FastDebugMsg(String("EraseDirectory: ERROR - SetFileManCurrentDirectory on %s failed, error %d", zOldDir, GetLastError())); - return( FALSE ); //Error returning from directory - } - - return( TRUE ); -#endif } BOOLEAN GetExecutableDirectory( STRING512 pcDirectory ) { -#ifdef USE_VFS vfs::Path exe_dir, exe_file; vfs::OS::getExecutablePath(exe_dir, exe_file); strncpy(pcDirectory, exe_dir.to_string().c_str(), 512); return true; -#else - SGPFILENAME ModuleFilename; - UINT32 cnt; - - if ( GetModuleFileName( NULL, ModuleFilename, sizeof( ModuleFilename ) ) == 0 ) - { - return( FALSE ); - } - - // Now get directory - strcpy( pcDirectory, ModuleFilename ); - - for ( cnt = strlen( pcDirectory ) - 1; cnt >= 0; cnt -- ) - { - if ( pcDirectory[ cnt ] == '\\' ) - { - pcDirectory[ cnt ] = '\0'; - break; - } - } -#endif - return( TRUE ); } -#ifdef USE_VFS static vfs::CVirtualFileSystem::Iterator file_iter; -#endif BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct ) { -#ifdef USE_VFS CHECKF( pSpec != NULL ); CHECKF( pGFStruct != NULL ); @@ -1927,43 +1255,10 @@ BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct ) return TRUE; } return FALSE; -#else - INT32 x,iWhich=0; - BOOLEAN fFound; - - CHECKF( pSpec != NULL ); - CHECKF( pGFStruct != NULL ); - - fFound = FALSE; - for( x = 0; x < 20 && !fFound; x++) - { - if( !fFindInfoInUse[x] ) - { - iWhich = x; - fFound = TRUE; - } - } - - if ( !fFound ) - return(FALSE); - - pGFStruct->iFindHandle = iWhich; - - hFindInfoHandle[iWhich] = FindFirstFile( pSpec, &Win32FindInfo[iWhich] ); - - if ( hFindInfoHandle[iWhich] == INVALID_HANDLE_VALUE ) - return(FALSE); - fFindInfoInUse[iWhich] = TRUE; - - W32toSGPFileFind( pGFStruct, &Win32FindInfo[iWhich] ); - - return(TRUE); -#endif } BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct ) { -#ifdef USE_VFS if(!file_iter.end()) { file_iter.next(); @@ -1984,32 +1279,11 @@ BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct ) return TRUE; } return FALSE; -#else - CHECKF( pGFStruct != NULL ); - - if ( FindNextFile(hFindInfoHandle[pGFStruct->iFindHandle], &Win32FindInfo[pGFStruct->iFindHandle]) ) - { - W32toSGPFileFind( pGFStruct, &Win32FindInfo[pGFStruct->iFindHandle] ); - return(TRUE); - } - return(FALSE); -#endif } void GetFileClose( GETFILESTRUCT *pGFStruct ) { -#ifdef USE_VFS file_iter = vfs::CVirtualFileSystem::Iterator(); -#else - if ( pGFStruct == NULL ) - return; - - FindClose( hFindInfoHandle[pGFStruct->iFindHandle] ); - hFindInfoHandle[pGFStruct->iFindHandle] = INVALID_HANDLE_VALUE; - fFindInfoInUse[pGFStruct->iFindHandle] = FALSE; - - return; -#endif } void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct ) @@ -2226,18 +1500,13 @@ UINT32 FileGetAttributes( STR strFilename ) BOOLEAN FileClearAttributes( STR strFilename ) { -#ifndef USE_VFS - return SetFileAttributes( (LPCSTR) strFilename, FILE_ATTRIBUTE_NORMAL ); -#else return TRUE; -#endif } //returns true if at end of file, else false BOOLEAN FileCheckEndOfFile( HWFILE hFile ) { -#ifdef USE_VFS vfs::size_t current_position, max_position; vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; @@ -2262,139 +1531,13 @@ BOOLEAN FileCheckEndOfFile( HWFILE hFile ) } } return FALSE; -#else - INT16 sLibraryID; - UINT32 uiFileNum; - HANDLE hRealFile; -// UINT8 Data; - UINT32 uiOldFilePtrLoc=0; - UINT32 uiEndOfFilePtrLoc=0; - UINT32 temp=0; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to the real file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - //Get the current position of the file pointer - uiOldFilePtrLoc = SetFilePointer( hRealFile, 0, NULL, FILE_CURRENT ); - - //Get the end of file ptr location - uiEndOfFilePtrLoc = SetFilePointer( hRealFile, 0, NULL, FILE_END ); - - //reset back to the original location - temp = SetFilePointer( hRealFile, -( (INT32)( uiEndOfFilePtrLoc - uiOldFilePtrLoc ) ), NULL, FILE_END ); - - //if the 2 pointers are the same, we are at the end of a file - if( uiEndOfFilePtrLoc <= uiOldFilePtrLoc ) - { - return( 1 ); - } - } - - //else it is a library file - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - { - //if the file is opened - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - UINT32 uiLength; //uiOffsetInLibrary -// HANDLE hLibraryFile; -// UINT32 uiNumBytesRead; - UINT32 uiCurPos; - - uiLength = gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].pFileHeader->uiFileLength; - uiCurPos = gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFilePosInFile; - - //if we are trying to read more data then the size of the file, return an error - if( uiCurPos >= uiLength ) - { - return( TRUE ); - } - } - } - } - } - - //we are not and the end of a file - return( 0 ); -#endif } BOOLEAN GetFileManFileTime( HWFILE hFile, SGP_FILETIME *pCreationTime, SGP_FILETIME *pLastAccessedTime, SGP_FILETIME *pLastWriteTime ) { -#ifndef USE_VFS - HANDLE hRealFile; - INT16 sLibraryID; - UINT32 uiFileNum; - - FILETIME sCreationUtcFileTime; - FILETIME sLastAccessedUtcFileTime; - FILETIME sLastWriteUtcFileTime; - - //Initialize the passed in variables - if (pCreationTime) memset( pCreationTime, 0, sizeof( SGP_FILETIME ) ); - if (pLastAccessedTime) memset( pLastAccessedTime, 0, sizeof( SGP_FILETIME ) ); - if (pLastWriteTime) memset( pLastWriteTime, 0, sizeof( SGP_FILETIME ) ); - - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //get the real file handle to the file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - //Gets the UTC file time for the 'real' file - GetFileTime( hRealFile, &sCreationUtcFileTime, &sLastAccessedUtcFileTime, &sLastWriteUtcFileTime ); - - //converts the creation UTC file time to the current time used for the file - if(pCreationTime) - FileTimeToLocalFileTime( &sCreationUtcFileTime, pCreationTime ); - - //converts the accessed UTC file time to the current time used for the file - if (pLastAccessedTime) - FileTimeToLocalFileTime( &sLastAccessedUtcFileTime, pLastAccessedTime ); - - //converts the write UTC file time to the current time used for the file - if (pLastWriteTime) - FileTimeToLocalFileTime( &sLastWriteUtcFileTime, pLastWriteTime ); - } - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - { - //if the file is opened - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - if( !GetLibraryFileTime( sLibraryID, uiFileNum, pLastWriteTime ) ) - { - return( FALSE ); - } - } - } - } - } - return( TRUE ); -#else return( FALSE ); -#endif } @@ -2405,60 +1548,15 @@ INT32 CompareSGPFileTimes( SGP_FILETIME *pFirstFileTime, SGP_FILETIME *pSecondFi UINT32 FileSize(STR strFilename) { -#ifdef USE_VFS vfs::IBaseFile *pFile = getVFS()->getFile(vfs::Path(strFilename)); if(pFile) { return pFile->getSize(); } return 0; -#else -HWFILE hFile; -UINT32 uiSize; - - if((hFile=FileOpen(strFilename, FILE_OPEN_EXISTING | FILE_ACCESS_READ, FALSE))==0) - return(0); - - uiSize=FileGetSize(hFile); - FileClose(hFile); - - return(uiSize); -#endif } - -HANDLE GetRealFileHandleFromFileManFileHandle( HWFILE hFile ) -{ -#ifndef USE_VFS - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its the 'real file' library - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //if its not already closed - if( gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].uiFileID != 0 ) - { - return( gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle ); - } - } - else - { - //if the file is not opened, dont close it - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - return( gFileDataBase.pLibraries[ sLibraryID ].hLibraryHandle ); - } - } -#endif - return( 0 ); -} - - - //************************************************************************** // // AddSubdirectoryToPath diff --git a/Standard Gaming Platform/MemMan.cpp b/Standard Gaming Platform/MemMan.cpp index 8db377900..caa545e8c 100644 --- a/Standard Gaming Platform/MemMan.cpp +++ b/Standard Gaming Platform/MemMan.cpp @@ -204,23 +204,6 @@ void ShutdownMemoryManager( void ) #ifndef EXTREME_MEMORY_DEBUGGING #ifdef JA2BETAVERSION { -#ifndef USE_VFS - FILE *fp; - fp = fopen( "MemLeakInfo.txt", "a" ); - if( fp ) - { - fprintf( fp, "\n\n" ); - fprintf( fp, ">>>>> MEMORY LEAK DETECTED!!! <<<<<\n" ); - fprintf( fp, " %d bytes memory total was allocated\n", guiMemAlloced ); - fprintf( fp, "- %d bytes memory total was freed\n", guiMemFreed ); - fprintf( fp, "_______________________________________________\n" ); - fprintf( fp, "%d bytes memory total STILL allocated\n", guiMemTotal ); - fprintf( fp, "%d memory blocks still allocated\n", MemDebugCounter ); - fprintf( fp, "guiScreenExitedFrom = %S\n", gzJA2ScreenNames[ gMsgBox.uiExitScreen ] ); - fprintf( fp, "\n\n" ); - } - fclose( fp ); -#else sgp::Logger_ID log_id = sgp::Logger::instance().createLogger(); sgp::Logger::LogInstance memLeak = SGP_LOG(log_id); memLeak << sgp::endl << sgp::endl; @@ -232,7 +215,6 @@ void ShutdownMemoryManager( void ) memLeak << MemDebugCounter << " memory blocks still allocated" << sgp::endl; memLeak << "guiScreenExitedFrom = " << gzJA2ScreenNames[ gMsgBox.uiExitScreen ] << sgp::endl; memLeak << sgp::endl << sgp::endl; -#endif } #endif #endif diff --git a/Standard Gaming Platform/Types.h b/Standard Gaming Platform/Types.h index 0fc57bef2..6c304ad39 100644 --- a/Standard Gaming Platform/Types.h +++ b/Standard Gaming Platform/Types.h @@ -141,15 +141,6 @@ typedef VECTOR4 COLOR; // rgba color array inline void convert_string(std::wstring const& str_in, std::string &str_out) { -#if !defined(USE_VFS) - const wchar_t* src = str_in.c_str(); - size_t len = wcstombs(NULL, src, str_in.length()); - if(len > 0) - { - str_out.resize(len); - wcstombs(&str_out[0], src, len); - } -#else if(vfs::Settings::getUseUnicode()) { str_out = vfs::String::as_utf8(str_in); @@ -158,20 +149,10 @@ inline void convert_string(std::wstring const& str_in, std::string &str_out) { vfs::String::narrow(str_in, str_out); } -#endif } inline void convert_string(std::string const& str_in, std::wstring &str_out) { -#if !defined(USE_VFS) - const char* src = str_in.c_str(); - size_t len = mbstowcs(NULL, src, str_in.length()); - if(len > 0) - { - str_out.resize(len); - mbstowcs(&str_out[0], src, len); - } -#else if(vfs::Settings::getUseUnicode()) { vfs::String::as_utf16(str_in, str_out); @@ -180,8 +161,7 @@ inline void convert_string(std::string const& str_in, std::wstring &str_out) { vfs::String::widen(str_in, str_out); } -#endif } -#endif \ No newline at end of file +#endif diff --git a/Standard Gaming Platform/WinFont.cpp b/Standard Gaming Platform/WinFont.cpp index bfed0c1be..223e634fb 100644 --- a/Standard Gaming Platform/WinFont.cpp +++ b/Standard Gaming Platform/WinFont.cpp @@ -189,21 +189,6 @@ Name=Tahoma Height=-20 Weight=400 */ -#ifndef USE_VFS - char INIFile[MAX_PATH]; - GetExecutableDirectory( INIFile ); - strcat(INIFile, "\\"); - strcat(INIFile, GAME_INI_FILE); - - - gWinFontAdjust = GetPrivateProfileInt("Ja2 Settings", "WIN_FONT_ADJUST", 0, INIFile); - for (UINT16 i=0; i @@ -841,9 +799,7 @@ int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pC -#ifdef USE_VFS vfs::Log::setSharedString( getGameID() ); -#endif //if(!vfs::Aspects::getMutexFactory()) //{ // vfs::Aspects::setMutexFactory( new VfsMutexFactory() ); @@ -914,15 +870,6 @@ int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pC // ShowCursor(FALSE); -#ifdef USE_VFS - //vfs::Path exe_dir, exe_file; - //os::getExecutablePath(exe_dir, exe_file); - //os::setCurrectDirectory(exe_dir); -#else - STRING512 sExecutableDir; - GetExecutableDirectory( sExecutableDir ); - SetCurrentDirectory(sExecutableDir); -#endif try { // Inititialize the SGP @@ -934,9 +881,7 @@ int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pC } HANDLE_FATAL_ERROR; -#ifdef USE_VFS vfs::Log::flushReleaseAll(); -#endif #ifdef LUACONSOLE if (1==iScreenMode) @@ -1051,39 +996,10 @@ void GetRuntimeSettings( ) /* Detect cnc-ddraw and disable windowed mode */ BOOL bCncDdraw = GetProcAddress(GetModuleHandleW(L"ddraw.dll"), "GameHandlesClose") != NULL; -#ifndef USE_VFS - CHAR8 zMaximize[ 50 ]; - CHAR8 zWindowedMode[ 50 ]; - - // Runtime settings - for now use INI file - later use registry - STRING512 INIFile; // Path to the ini file - CHAR8 zScreenResolution[ 50 ]; - - // Get Executable Directory - GetExecutableDirectory( INIFile ); - - strcat(INIFile, "\\"); - strcat(INIFile, GAME_INI_FILE); -#else vfs::PropertyContainer oProps; oProps.initFromIniFile(GAME_INI_FILE); PopulateSectionFromCommandLine(oProps, "Ja2 Settings"); -#endif -#ifndef USE_VFS - if (GetPrivateProfileString( "Ja2 Settings","SCREEN_RESOLUTION", "", zScreenResolution, 50, INIFile )) - { - iResolution = atoi(zScreenResolution); - } - if (GetPrivateProfileString( "Ja2 Settings","SCREEN_MODE_WINDOWED_MAXIMIZE", "", zMaximize, 50, INIFile )) - { - iMaximize = atoi(zMaximize); - } - if (GetPrivateProfileString( "Ja2 Settings","SCREEN_MODE_WINDOWED", "", zWindowedMode, 50, INIFile )) - { - iWindowedMode = bCncDdraw ? 0 : atoi(zWindowedMode); - } -#else vfs::String loc = oProps.getStringProperty("Ja2 Settings", L"LOCALE"); if(!loc.empty()) { @@ -1142,9 +1058,7 @@ void GetRuntimeSettings( ) CIniReader::RegisterFileForMerging(*it); } } -#endif -#ifdef USE_VFS extern bool g_bUsePngItemImages; g_bUsePngItemImages = oProps.getBoolProperty(L"Ja2 Settings", L"USE_PNG_ITEM_IMAGES", false); g_bUseXML_Structures = oProps.getBoolProperty(L"Ja2 Settings", L"USE_XML_STRUCTURES", false); @@ -1164,17 +1078,9 @@ void GetRuntimeSettings( ) s_bExportStrings = oProps.getBoolProperty(L"Ja2 Settings", L"EXPORT_STRINGS", false); sp_force_load_jsd_xml_file = oProps.getStringProperty(L"Ja2 Settings", L"FORCE_LOAD_JSD_XML_FILE", L""); -#endif #ifdef JA2EDITOR -#ifndef USE_VFS - if (GetPrivateProfileString( "Ja2 Settings","EDITOR_SCREEN_RESOLUTION", "", zScreenResolution, 50, INIFile )) - { - iResolution = atoi(zScreenResolution); - } -#else iResolution = (int)oProps.getIntProperty("Ja2 Settings","EDITOR_SCREEN_RESOLUTION", -1); -#endif #endif int iResX; @@ -1311,30 +1217,6 @@ void GetRuntimeSettings( ) } // Adjust again - -#ifndef USE_VFS - gbPixelDepth = GetPrivateProfileInt( "SGP", "PIXEL_DEPTH", PIXEL_DEPTH, INIFile ); - - SCREEN_WIDTH = GetPrivateProfileInt( "SGP", "WIDTH", iResX, INIFile ); - SCREEN_HEIGHT = GetPrivateProfileInt( "SGP", "HEIGHT", iResY, INIFile ); - - iScreenWidthOffset = (SCREEN_WIDTH - 640) / 2; - iScreenHeightOffset = (SCREEN_HEIGHT - 480) / 2; - - /* Sergeant_Kolja. 2007-02-20: runtime Windowed mode instead of compile-time */ - /* 1 for Windowed, 0 for Fullscreen */ - if( !bScreenModeCmdLine ) - iScreenMode = bCncDdraw ? 0 : (int) GetPrivateProfileInt( "Ja2 Settings","SCREEN_MODE_WINDOWED", iScreenMode, INIFile ); - - // WANNE: Should we play the intro? - iPlayIntro = (int) GetPrivateProfileInt( "Ja2 Settings","PLAY_INTRO", iPlayIntro, INIFile ); - iUseWinFonts = (int) GetPrivateProfileInt( "Ja2 Settings","USE_WINFONTS", iUseWinFonts, INIFile,); - fTooltipScaleFactor = ((int)GetPrivateProfileInt("Ja2 Settings", "TOOLTIP_SCALE_FACTOR", 100, INIFile, )) / 100; - if (fTooltipScaleFactor < 1) fTooltipScaleFactor = 1; - - // haydent: mouse scrolling - iDisableMouseScrolling = (int) GetPrivateProfileInt( "Ja2 Settings","DISABLE_MOUSE_SCROLLING", iDisableMouseScrolling, INIFile ); -#else gbPixelDepth = PIXEL_DEPTH; SCREEN_WIDTH = iResX; @@ -1388,8 +1270,6 @@ void GetRuntimeSettings( ) // get timer/clock initialization state //SetHiSpeedClockMode( oProps.getBoolProperty("Ja2 Settings", "HIGHSPEED_TIMER", false) ? TRUE : FALSE ); SetHiSpeedClockMode( TRUE ); - -#endif } @@ -1464,7 +1344,6 @@ void ProcessJa2CommandLineBeforeInitialization(CHAR8 *pCommandLine) MemFree(pCopy); } -#ifdef USE_VFS static void PopulateSectionFromCommandLine(vfs::PropertyContainer &oProps, vfs::String const& sSection) { const wchar_t* lpCommandLine = GetCommandLineW(); @@ -1496,7 +1375,6 @@ static void PopulateSectionFromCommandLine(vfs::PropertyContainer &oProps, vfs:: } } } -#endif static LONG __stdcall SGPExceptionFilter(int exceptionCount, EXCEPTION_POINTERS* pExceptInfo) { diff --git a/Standard Gaming Platform/sgp_logger.cpp b/Standard Gaming Platform/sgp_logger.cpp index 54772ebaa..dc82bbdec 100644 --- a/Standard Gaming Platform/sgp_logger.cpp +++ b/Standard Gaming Platform/sgp_logger.cpp @@ -16,16 +16,12 @@ static inline void flush_screen(std::wstringstream& stream) int sgp::Logger::_next_log_id = -1; -#if defined(USE_VFS) //std::vector sgp::Logger::_logs; std::vector sgp::Logger::_logs; -#endif sgp::Logger::Logger() { -#if defined(USE_VFS) connectFile(this->createLogger(), L"game_log.log", false, sgp::Logger::FLUSH_ON_ENDL); -#endif } sgp::Logger::~Logger() @@ -47,9 +43,7 @@ bool sgp::Logger::shutdown() { for(::size_t i=0; i < _logs.size(); ++i) { -#if defined(USE_VFS) disconnectFile(i); -#endif disconnectStream(i); disconnectScreen(i); } @@ -102,7 +96,6 @@ void sgp::Logger::flushMode(sgp::Logger_ID id, sgp::Logger::FlushMode fmode) } -#if defined(USE_VFS) void sgp::Logger::connectFile(sgp::Logger_ID id, vfs::Path const& log_file, bool append, FlushMode fmode) { if(id >= 0 && id < _logs.size()) @@ -128,7 +121,6 @@ void sgp::Logger::disconnectFile(sgp::Logger_ID id) } } } -#endif void sgp::Logger::connectStream(sgp::Logger_ID id, std::ostream& stream) { @@ -170,29 +162,10 @@ void sgp::Logger::disconnectScreen(sgp::Logger_ID id) } -//#if defined(USE_VFS) -//int sgp::Logger::createLogger(vfs::Path const& log_file, bool append, FlushMode fp) -//{ -// vfs::Log::EFlushMode fm; -// if(fp == sgp::Logger::FLUSH_ON_DELETE) fm = vfs::Log::FLUSH_ON_DELETE; -// else if(fp == sgp::Logger::FLUSH_IMMIDIATELY) fm = vfs::Log::FLUSH_IMMEDIATELY; -// else if(fp == sgp::Logger::FLUSH_FULL_BUFFER) fm = vfs::Log::FLUSH_BUFFER; -// else if(fp == sgp::Logger::FLUSH_ON_ENDL) fm = vfs::Log::FLUSH_ON_ENDL; -// else fm = vfs::Log::FLUSH_IMMEDIATELY; -// -// _logs.push_back(STimeLog()); -// _next_log_id++; -// _logs[_next_log_id]._log = vfs::Log::create(log_file,append,fm); -// _logs[_next_log_id]._timer.startTimer(); -// return _next_log_id; -//} -//#endif - sgp::Logger::LogInstance sgp::Logger::logger(sgp::Logger_ID id) { if(id < _logs.size()) { -#if defined(USE_VFS) std::wstringstream tmp; tmp << L"[" << _logs[id].timer.running() << L"] : "; std::wstring str(tmp.str()); @@ -208,7 +181,6 @@ sgp::Logger::LogInstance sgp::Logger::logger(sgp::Logger_ID id) if(ld.screen) { (*ld.screen) << str; } -#endif return sgp::Logger::LogInstance(&ld); } SGP_THROW(L"Unknown log id"); @@ -219,10 +191,8 @@ sgp::Logger::LogInstance& sgp::Logger::LogInstance::operator<< (sgp { if(_log.file) { -#if defined(USE_VFS) (*_log.file).flush(); (*_log.file).unlock(); -#endif } if(_log.stream) { @@ -240,14 +210,12 @@ sgp::Logger::LogInstance& sgp::Logger::LogInstance::operator<< (sgp: { if(_log.file) { -#if defined(USE_VFS) (*_log.file) << vfs::Log::endl; if(_log.file->flushMode() == vfs::Log::FLUSH_ON_ENDL) { (*_log.file).flush(); } (*_log.file).unlock(); -#endif } if(_log.stream) { @@ -263,8 +231,6 @@ sgp::Logger::LogInstance& sgp::Logger::LogInstance::operator<< (sgp: template <> sgp::Logger::LogInstance& sgp::Logger::LogInstance::operator<< (sgp::_lock const& l) { -#if defined(USE_VFS) _log.file->lock(); -#endif return *this; } diff --git a/Standard Gaming Platform/sgp_logger.h b/Standard Gaming Platform/sgp_logger.h index d93c7cd69..db457eb50 100644 --- a/Standard Gaming Platform/sgp_logger.h +++ b/Standard Gaming Platform/sgp_logger.h @@ -2,13 +2,9 @@ #define SGP_LOGGER_H #include -#if defined(USE_VFS) -# include -# include -# include -#else -# include -#endif +#include +#include +#include namespace sgp { @@ -22,13 +18,9 @@ namespace sgp { struct LogData { -#if defined(USE_VFS) LogData() : file(NULL), stream(NULL), screen(NULL) {}; vfs::HPTimer timer; vfs::Log* file; -#else - LogData() : stream(NULL), screen(NULL) {}; -#endif std::wostream* stream; std::wstringstream* screen; }; @@ -53,9 +45,7 @@ namespace sgp LogInstance& operator<<(T const& t){ if(_log.stream) (*_log.stream) << t; if(_log.screen) (*_log.screen) << t; -#if defined(USE_VFS) if(_log.file ) (*_log.file) << t; -#endif return *this; } private: @@ -72,10 +62,8 @@ namespace sgp Logger_ID createLogger(); -#if defined(USE_VFS) void connectFile(Logger_ID id, vfs::Path const& log_file, bool append, FlushMode fp); void disconnectFile(Logger_ID id); -#endif void connectStream(Logger_ID id, std::ostream& stream); void disconnectStream(Logger_ID id); @@ -102,44 +90,28 @@ namespace sgp Logger::LogInstance& Logger::LogInstance::operator<< <_flush>(_flush const& f); } -#if defined(USE_VFS) inline sgp::Logger::LogInstance SGP_LOG(sgp::Logger_ID id, vfs::String const& str){ -#else -inline sgp::Logger::LogInstance SGP_LOG(int id, const char* str){ -#endif return sgp::Logger::instance().logger(id) << (str) << sgp::endl; } inline sgp::Logger::LogInstance SGP_LOG(sgp::Logger_ID id){ return sgp::Logger::instance().logger(id); } -#if defined(USE_VFS) inline sgp::Logger::LogInstance SGP_INFO(vfs::String const& str){ -#else -inline sgp::Logger::LogInstance SGP_INFO(const char* str){ -#endif return sgp::Logger::instance().logger(0) << str << sgp::endl; } inline sgp::Logger::LogInstance SGP_INFO(){ return sgp::Logger::instance().logger(0); } -#if defined(USE_VFS) inline sgp::Logger::LogInstance SGP_WARNING(vfs::String const& str){ -#else -inline sgp::Logger::LogInstance SGP_WARNING(const char* str){ -#endif return sgp::Logger::instance().logger(0) << "WARNING : " << str << sgp::endl; } inline sgp::Logger::LogInstance SGP_WARNING(){ return sgp::Logger::instance().logger(0) << "WARNING : "; } -#if defined(USE_VFS) inline sgp::Logger::LogInstance SGP_ERROR(vfs::String const& str){ -#else -inline sgp::Logger::LogInstance SGP_ERROR(const char* str){ -#endif return sgp::Logger::instance().logger(0) << "ERROR : " << str << sgp::endl; } inline sgp::Logger::LogInstance SGP_ERROR(){ diff --git a/Standard Gaming Platform/soundman.cpp b/Standard Gaming Platform/soundman.cpp index 22077f741..a2f5869eb 100644 --- a/Standard Gaming Platform/soundman.cpp +++ b/Standard Gaming Platform/soundman.cpp @@ -1869,15 +1869,7 @@ void SoundLog(CHAR8 *strMessage) sgp::Logger::instance().connectFile(id, SndDebugFileName, true, sgp::Logger::FLUSH_ON_DELETE); } } s_SoundLog; -#ifndef USE_VFS - if ((SndDebug = fopen(SndDebugFileName, "a+t")) != NULL) - { - fprintf(SndDebug, "%s\n", strMessage); - fclose(SndDebug); - } -#else SGP_LOG(s_SoundLog.id, vfs::String::widen(strMessage,strlen(strMessage))); -#endif } //***************************************************************************************** @@ -1890,10 +1882,4 @@ void SoundLog(CHAR8 *strMessage) //***************************************************************************************** void InitLogging() { -#ifndef USE_VFS - if ((SndDebug = fopen(SndDebugFileName, "wt")) != NULL) - { - fclose(SndDebug); - } -#endif } diff --git a/Standard Gaming Platform/video.cpp b/Standard Gaming Platform/video.cpp index 0432e5121..bd1bcca26 100644 --- a/Standard Gaming Platform/video.cpp +++ b/Standard Gaming Platform/video.cpp @@ -1888,22 +1888,10 @@ void RefreshScreen(void *DummyVariable) LPDIRECTDRAWSURFACE _pTmpBuffer; LPDIRECTDRAWSURFACE2 pTmpBuffer; DDSURFACEDESC SurfaceDescription; -#ifndef USE_VFS - FILE *OutputFile; -#endif CHAR8 FileName[64]; INT32 iIndex; UINT16 *p16BPPData; - // Snap: save current directory -#ifndef USE_VFS - STRING512 DataDir; - STRING512 ExecDir; - - GetFileManCurrentDirectory( DataDir ); - GetExecutableDirectory( ExecDir ); - SetFileManCurrentDirectory( ExecDir ); -#endif // // Create temporary system memory surface. This is used to correct problems with the backbuffer // surface which can be interlaced or have a funky pitch @@ -1953,23 +1941,13 @@ void RefreshScreen(void *DummyVariable) { sprintf( FileName, "SCREEN%03d.TGA", guiPrintFrameBufferIndex++); } -#ifndef USE_VFS - while( (_access( FileName, 0 )) != -1 ); -#else while(FileExists(FileName)); -#endif -#ifndef USE_VFS - if ((OutputFile = fopen( FileName, "wb")) != NULL) - { - fprintf(OutputFile, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, LOBYTE(SCREEN_WIDTH), HIBYTE(SCREEN_WIDTH), LOBYTE(SCREEN_HEIGHT), HIBYTE(SCREEN_HEIGHT), 0x10, 0); -#else try { vfs::COpenWriteFile wfile(FileName,true,true); char head[] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, LOBYTE(SCREEN_WIDTH), HIBYTE(SCREEN_WIDTH), LOBYTE(SCREEN_HEIGHT), HIBYTE(SCREEN_HEIGHT), 0x10, 0}; SGP_TRYCATCH_RETHROW(wfile->write(head,18), L""); -#endif // // Lock temp surface @@ -2006,19 +1984,11 @@ void RefreshScreen(void *DummyVariable) ConvertRGBDistribution565To555( p16BPPData, SCREEN_WIDTH ); // Write -#ifndef USE_VFS - fwrite( p16BPPData, SCREEN_WIDTH * 2, 1, OutputFile); -#else SGP_TRYCATCH_RETHROW(wfile->write((vfs::Byte*)p16BPPData, SCREEN_WIDTH * 2), L""); -#endif } else { -#ifndef USE_VFS - fwrite((void *)(((UINT8 *)SurfaceDescription.lpSurface) + (iIndex * SCREEN_WIDTH * 2)), SCREEN_WIDTH * 2, 1, OutputFile); -#else SGP_TRYCATCH_RETHROW(wfile->write((vfs::Byte*)(((UINT8 *)SurfaceDescription.lpSurface) + (iIndex * SCREEN_WIDTH * 2)), SCREEN_WIDTH * 2), L""); -#endif } } @@ -2027,9 +1997,6 @@ void RefreshScreen(void *DummyVariable) { MemFree( p16BPPData ); } -#ifndef USE_VFS - fclose(OutputFile); -#endif // // Unlock temp surface // @@ -2043,12 +2010,10 @@ void RefreshScreen(void *DummyVariable) } } -#ifdef USE_VFS catch(std::exception& ex) { SGP_RETHROW(L"", ex); } -#endif // // Release temp surface @@ -2056,12 +2021,6 @@ void RefreshScreen(void *DummyVariable) gfPrintFrameBuffer = FALSE; IDirectDrawSurface2_Release(pTmpBuffer); -#ifndef USE_VFS - // Snap: Restore the data directory once we are finished. - SetFileManCurrentDirectory( DataDir ); - //strcat( ExecDir, "\\Data" ); - //SetFileManCurrentDirectory( ExecDir ); -#endif } // @@ -3322,80 +3281,42 @@ void RefreshMovieCache( ) { TARGA_HEADER Header; INT32 iCountX, iCountY; -#ifndef USE_VFS - FILE *disk; -#endif CHAR8 cFilename[_MAX_PATH]; static UINT32 uiPicNum=0; UINT16 *pDest; INT32 cnt; -#ifndef USE_VFS - STRING512 DataDir; - STRING512 ExecDir; -#endif PauseTime( TRUE ); -#ifndef USE_VFS - // Snap: save current directory - GetFileManCurrentDirectory( DataDir ); - - GetExecutableDirectory( ExecDir ); - SetFileManCurrentDirectory( ExecDir ); -#else try { -#endif for ( cnt = 0; cnt < giNumFrames; cnt++ ) { sprintf( cFilename, "JA%5.5d.TGA", uiPicNum++ ); -#ifndef USE_VFS - if( ( disk = fopen(cFilename, "wb"))==NULL ) - return; -#else vfs::COpenWriteFile wfile(cFilename, true, true); -#endif memset(&Header, 0, sizeof(TARGA_HEADER)); Header.ubTargaType=2; // Uncompressed 16/24/32 bit Header.usImageWidth=SCREEN_WIDTH; Header.usImageHeight=SCREEN_HEIGHT; Header.ubBitsPerPixel=16; -#ifndef USE_VFS - fwrite(&Header, sizeof(TARGA_HEADER), 1, disk); -#else SGP_TRYCATCH_RETHROW(wfile->write((vfs::Byte*)&Header, sizeof(TARGA_HEADER)), L""); -#endif pDest = gpFrameData[ cnt ]; for(iCountY=SCREEN_HEIGHT-1; iCountY >=0 ; iCountY-=1) { for(iCountX=0; iCountX < SCREEN_WIDTH; iCountX ++ ) { -#ifndef USE_VFS - fwrite( ( pDest + ( iCountY * SCREEN_WIDTH ) + iCountX ), sizeof(UINT16), 1, disk); -#else SGP_TRYCATCH_RETHROW(wfile->write( (vfs::Byte*)( pDest + ( iCountY * SCREEN_WIDTH ) + iCountX ), sizeof(UINT16)), L""); -#endif } } -#ifndef USE_VFS - fclose(disk); -#endif } PauseTime( FALSE ); giNumFrames = 0; -#ifndef USE_VFS - // Snap: Restore the data directory once we are finished. - SetFileManCurrentDirectory( DataDir ); - //strcat( ExecDir, "\\Data" ); - //SetFileManCurrentDirectory( ExecDir ); -#else } catch(std::exception& ex) { SGP_ERROR(ex.what()); } -#endif } diff --git a/Strategic/Campaign Init.cpp b/Strategic/Campaign Init.cpp index c3faaa385..0da5809b6 100644 --- a/Strategic/Campaign Init.cpp +++ b/Strategic/Campaign Init.cpp @@ -206,26 +206,6 @@ BOOLEAN ReadInAltSectors(STR fileName) BOOLEAN WriteInAltSectors(STR fileName) { -#ifndef USE_VFS - // Lets output the current Strategic map format using the XML structure I've devised. - FILE *outfile = fopen(fileName, "wt"); - - UINT32 x, y; - - fprintf (outfile, "\n"); - for(y = 1;y <= 16;y++) - { - fprintf (outfile, "\t",(y+0x40)); - for(x = 1;x <= 16; x++) - { - fprintf (outfile, " %d",RandomSector[ ((y - 1) * 16) + (x - 1) ] ); - } - fprintf (outfile, " \n"); - } - fprintf (outfile, "\n"); - - fclose(outfile); -#else XMLWriter xmlw; xmlw.openNode(L"ALT_SECTORS_LIST"); UINT32 x, y; @@ -241,7 +221,6 @@ BOOLEAN WriteInAltSectors(STR fileName) } xmlw.closeNode(); xmlw.writeToFile(fileName); -#endif return (TRUE); } diff --git a/Strategic/Strategic AI.cpp b/Strategic/Strategic AI.cpp index c64d85ed1..bf1d52b59 100644 --- a/Strategic/Strategic AI.cpp +++ b/Strategic/Strategic AI.cpp @@ -5430,22 +5430,11 @@ void LogStrategicMsg( STR8 str, ... ) { va_list argptr; CHAR8 string[512]; -#ifndef USE_VFS - FILE *fp; - - fp = fopen( "Strategic Decisions.txt", "a" ); - if( !fp ) - return; -#endif va_start(argptr, str ); vsprintf( string, str, argptr); va_end(argptr); -#ifndef USE_VFS - fprintf( fp, "%s\n", string ); -#else SGP_LOG(s_stratD.id, string); -#endif if( gfDisplayStrategicAILogs ) { @@ -5455,33 +5444,17 @@ void LogStrategicMsg( STR8 str, ... ) { OutputDebugString( (LPCSTR)String( "%s\n", string ) ); } - -#ifndef USE_VFS - fclose( fp ); -#endif } void LogStrategicEvent( STR8 str, ... ) { va_list argptr; CHAR8 string[512]; -#ifndef USE_VFS - FILE *fp; - - fp = fopen( "Strategic Decisions.txt", "a" ); - if( !fp ) - return; -#endif va_start(argptr, str ); vsprintf( string, str, argptr); va_end(argptr); -#ifndef USE_VFS - fprintf( fp, "\n%S:\n", WORLDTIMESTR ); - fprintf( fp, "%s\n", string ); -#else SGP_LOG(s_stratD.id) << sgp::endl << WORLDTIMESTR << ":" << sgp::endl << string << sgp::endl; -#endif if( gfDisplayStrategicAILogs ) { ScreenMsg( FONT_LTKHAKI, MSG_DIALOG, L"%S", string ); @@ -5490,25 +5463,11 @@ void LogStrategicEvent( STR8 str, ... ) { OutputDebugString( (LPCSTR)String( "%s\n", string ) ); } -#ifndef USE_VFS - fclose( fp ); -#endif } void ClearStrategicLog() { -#ifndef USE_VFS - FILE *fp; - fp = fopen( "Strategic Decisions.txt", "w" ); - if( !fp ) - return; - - fprintf( fp, "STRATEGIC LOG\n" ); - - fclose( fp ); -#else SGP_LOG(s_stratD.id) << sgp::flush; -#endif } #endif diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index 9fa2cff67..f194853a9 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -1659,80 +1659,6 @@ void EndLoadScreen( ) 'A' + gWorldSectorY - 1, gWorldSectorX, gbWorldSectorZ, uiSeconds, uiHundreths ); } ScreenMsg( FONT_YELLOW, MSG_TESTVERSION, str ); -#ifndef USE_VFS - FILE *fp; - - if ( fStartNewFile ) - { //start new file - fp = fopen( "TimeResults.txt", "w" ); - ScreenMsg( FONT_YELLOW, MSG_TESTVERSION, L"See JA2\\Data\\TimeResults.txt for more detailed timings." ); - fStartNewFile = FALSE; - } - else - { //append to end of file - fp = fopen( "TimeResults.txt", "a" ); - - if ( fp ) - { - fprintf( fp, "\n\n--------------------------------------------------------------------\n\n" ); - } - } - if ( fp ) - { - //Record all of the timings. - fprintf( fp, "%S\n", str ); - fprintf( fp, "EnterSector() supersets LoadWorld(). This includes other external sections.\n" ); - //FileRead() - fprintf( fp, "\n\nVARIOUS FUNCTION TIMINGS (exclusive of actual function timings in second heading)\n" ); - uiSeconds = uiTotalFileReadTime / 1000; - uiHundreths = (uiTotalFileReadTime / 10) % 100; - fprintf( fp, "FileRead: %d.%02d (called %d times)\n", uiSeconds, uiHundreths, uiTotalFileReadCalls ); - - fprintf( fp, "\n\nSECTIONS OF LOADWORLD (all parts should add up to 100%)\n" ); - //TrashWorld() - uiSeconds = uiTrashWorldTime / 1000; - uiHundreths = (uiTrashWorldTime / 10) % 100; - fprintf( fp, "TrashWorld: %d.%02d\n", uiSeconds, uiHundreths ); - //LoadMapTilesets() - uiSeconds = uiLoadMapTilesetTime / 1000; - uiHundreths = (uiLoadMapTilesetTime / 10) % 100; - fprintf( fp, "LoadMapTileset: %d.%02d\n", uiSeconds, uiHundreths ); - //LoadMapLights() - uiSeconds = uiLoadMapLightsTime / 1000; - uiHundreths = (uiLoadMapLightsTime / 10) % 100; - fprintf( fp, "LoadMapLights: %d.%02d\n", uiSeconds, uiHundreths ); - uiSeconds = uiBuildShadeTableTime / 1000; - uiHundreths = (uiBuildShadeTableTime / 10) % 100; - fprintf( fp, " 1) BuildShadeTables: %d.%02d\n", uiSeconds, uiHundreths ); - - uiPercentage = uiNumImagesReloaded * 100 / giNumberOfTileTypes; - fprintf( fp, " 2) %d%% of the tileset images were actually reloaded.\n", uiPercentage ); - if ( (uiNumTablesSaved + uiNumTablesLoaded) != 0 ) - { - uiPercentage = uiNumTablesSaved * 100 / (uiNumTablesSaved + uiNumTablesLoaded); - } - else - { - uiPercentage = 0; - } - fprintf( fp, " 3) Of that, %d%% of the shade tables were generated (not loaded).\n", uiPercentage ); - if ( gfForceBuildShadeTables ) - fprintf( fp, " NOTE: Force building of shadetables enabled on this local computer.\n" ); - - - //Unaccounted - uiUnaccounted = uiLoadWorldTime - uiTrashWorldTime - uiLoadMapTilesetTime - uiLoadMapLightsTime; - uiSeconds = uiUnaccounted / 1000; - uiHundreths = (uiUnaccounted / 10) % 100; - fprintf( fp, "Unaccounted: %d.%02d\n", uiSeconds, uiHundreths ); - //LoadWorld() - uiSeconds = uiLoadWorldTime / 1000; - uiHundreths = (uiLoadWorldTime / 10) % 100; - fprintf( fp, "\nTotal: %d.%02d\n", uiSeconds, uiHundreths ); - - fclose( fp ); - } -#else sgp::Logger_ID time_log_id = sgp::Logger::instance( ).createLogger( ); sgp::Logger::instance( ).connectFile( time_log_id, L"TimeResults.txt", true, sgp::Logger::FLUSH_ON_ENDL ); sgp::Logger::LogInstance timeResults = SGP_LOG( time_log_id ); @@ -1793,7 +1719,6 @@ void EndLoadScreen( ) uiSeconds = uiLoadWorldTime / 1000; uiHundreths = (uiLoadWorldTime / 10) % 100; timeResults << vfs::Log::endl << "Total: " << uiSeconds << "." << uiHundreths << sgp::endl; -#endif // USE_VFS #endif } diff --git a/Tactical/Tactical Save.cpp b/Tactical/Tactical Save.cpp index 7a5036705..6f84aa342 100644 --- a/Tactical/Tactical Save.cpp +++ b/Tactical/Tactical Save.cpp @@ -1678,33 +1678,7 @@ BOOLEAN RetrieveTempFileFromSavedGame( HWFILE hFile, UINT32 uiType, INT16 sMapX, //Deletes the Temp map Directory BOOLEAN InitTacticalSave( BOOLEAN fCreateTempDir ) { -#ifndef USE_VFS - UINT32 uiRetVal; - - //If the Map Temp directory exists, removes the temp files - uiRetVal = FileGetAttributes( MAPS_DIR ); - if( uiRetVal != 0xFFFFFFFF ) - { - if( uiRetVal & FILE_ATTRIBUTES_DIRECTORY ) - { - //Erase the directory - if( !EraseDirectory( MAPS_DIR ) ) - { - //error erasing the temporary maps directory - } - } - } - else - { - if( !MakeFileManDirectory( MAPS_DIR ) ) - { - //Erro creating the temp map directory - AssertMsg( 0, "Error creating the Temp Directory."); - } - } -#else EraseDirectory( MAPS_DIR ); -#endif if( fCreateTempDir ) { //Create the initial temp file for the Npc Quote Info diff --git a/TileEngine/SaveLoadMap.cpp b/TileEngine/SaveLoadMap.cpp index 0931fe915..3ca80d74c 100644 --- a/TileEngine/SaveLoadMap.cpp +++ b/TileEngine/SaveLoadMap.cpp @@ -557,12 +557,6 @@ BOOLEAN LoadAllMapChangesFromMapTempFileAndApplyThem( ) { ReSetSectorFlag( gWorldSectorX, gWorldSectorY, gbWorldSectorZ, SF_MAP_MODIFICATIONS_TEMP_FILE_EXISTS ); } -#ifndef USE_VFS - FileClose( hFile ); -#else - // FileClose( hFile ); - // file already deleted. can't close it anymore (handle is invalid) -#endif //Free the memory used for the temp array MemFree( pTempArrayOfMaps ); diff --git a/TileEngine/Shade Table Util.cpp b/TileEngine/Shade Table Util.cpp index f802fa443..b2345f4f6 100644 --- a/TileEngine/Shade Table Util.cpp +++ b/TileEngine/Shade Table Util.cpp @@ -24,10 +24,6 @@ BOOLEAN gfForceBuildShadeTables = FALSE; void DetermineRGBDistributionSettings() { -#ifndef USE_VFS - STRING512 DataDir; - STRING512 ExecDir; -#endif STRING512 ShadeTableDir; UINT32 uiRBitMask, uiGBitMask, uiBBitMask; UINT32 uiPrevRBitMask, uiPrevGBitMask, uiPrevBBitMask; @@ -37,36 +33,9 @@ void DetermineRGBDistributionSettings() BOOLEAN fCleanShadeTable = FALSE; BOOLEAN fLoadedPrevRGBDist = FALSE; -#ifndef USE_VFS - // Snap: save current directory - GetFileManCurrentDirectory( DataDir ); - - //First, determine if we have a file saved. If not, then this is the first time, and - //all shade tables will have to be built and saved to disk. This can be time consuming, adding up to - //3-4 seconds to the time of a map load. - GetExecutableDirectory( ExecDir ); - sprintf( ShadeTableDir, "%s\\%s", DataDir, SHADE_TABLE_DIR ); - - //Check to make sure we have a ShadeTable directory. If we don't create one! - if( !SetFileManCurrentDirectory( ShadeTableDir ) ) - { - if( !MakeFileManDirectory( ShadeTableDir ) ) - { - AssertMsg( 0, "ShadeTable directory doesn't exist, and couldn't create one!" ); - } - if( !SetFileManCurrentDirectory( ShadeTableDir ) ) - { - AssertMsg( 0, "Couldn't access the newly created ShadeTable directory." ); - } - fSaveRGBDist = TRUE; - } - // directory existed or was created. - SetFileManCurrentDirectory( DataDir ); -#else // changing the current directory can screw up the VFS; don't do it // the creation of the SHADE_TABLE_DIR directory is done by the VFS sprintf( ShadeTableDir, "%s", SHADE_TABLE_DIR ); -#endif CHAR8 sRGBDist[50]; sprintf( sRGBDist, "%s\\%s", SHADE_TABLE_DIR, "RGBDist.dat"); diff --git a/TileEngine/WorldDat.cpp b/TileEngine/WorldDat.cpp index 5e9a15805..92b1b2041 100644 --- a/TileEngine/WorldDat.cpp +++ b/TileEngine/WorldDat.cpp @@ -138,7 +138,6 @@ void InitEngineTilesets( ) #endif } -#ifdef USE_VFS void ExportTilesets(vfs::Path const& filename) { UINT32 uiNumBytesRead = 0; @@ -217,7 +216,6 @@ void ExportTilesets(vfs::Path const& filename) xmlw.closeNode(); xmlw.writeToFile(filename); } -#endif void SetTilesetOneTerrainValues( ) { diff --git a/TileEngine/worlddef.cpp b/TileEngine/worlddef.cpp index bf616f584..628a35e3d 100644 --- a/TileEngine/worlddef.cpp +++ b/TileEngine/worlddef.cpp @@ -2437,14 +2437,10 @@ BOOLEAN EvaluateWorld(STR8 pSector, UINT8 ubLevel) if(ValidMapFileName(szFileName)) strcpy(szFilename, pSector); sprintf(szDirFilename, "MAPS\\%s", szFilename); -#ifdef USE_VFS//dnl ch81 021213 if(guiCurrentScreen == LOADSAVE_SCREEN) hfile = FileOpen(szDirFilename, FILE_ACCESS_READ, FALSE, gzProfileName); else hfile = FileOpen(szDirFilename, FILE_ACCESS_READ); -#else - hfile = FileOpen(szDirFilename, FILE_ACCESS_READ, FALSE); -#endif if(!hfile) return(FALSE); uiFileSize = FileGetSize(hfile); @@ -2851,7 +2847,6 @@ BOOLEAN LoadWorld(const STR8 puiFilename, FLOAT* pMajorMapVersion, UINT8* pMinor else sprintf(aFilename, "MAPS\\%s", puiFilename); // Open file -#ifdef USE_VFS//dnl ch81 021213 #ifdef JA2EDITOR if(guiCurrentScreen == LOADSAVE_SCREEN) hfile = FileOpen(aFilename, FILE_ACCESS_READ, FALSE, gzProfileName); @@ -2859,9 +2854,6 @@ BOOLEAN LoadWorld(const STR8 puiFilename, FLOAT* pMajorMapVersion, UINT8* pMinor hfile = FileOpen(aFilename, FILE_ACCESS_READ); #else hfile = FileOpen(aFilename, FILE_ACCESS_READ); -#endif -#else - hfile = FileOpen(aFilename, FILE_ACCESS_READ, FALSE); #endif if(!hfile) { diff --git a/Utils/Cinematics Bink.cpp b/Utils/Cinematics Bink.cpp index 2e17d1a2d..4393c13be 100644 --- a/Utils/Cinematics Bink.cpp +++ b/Utils/Cinematics Bink.cpp @@ -171,17 +171,6 @@ BINKFLIC *BinkOpenFlic( const CHAR8 *cFilename ) ErrorMsg("BINK ERROR: Out of flic slots, cannot open another"); return(NULL); } -#ifndef USE_VFS - // Attempt opening the filename - if(!(pBink->hFileHandle = FileOpen( const_cast(cFilename), FILE_OPEN_EXISTING | FILE_ACCESS_READ, FALSE ) ) ) - { - ErrorMsg("BINK ERROR: Can't open the BINK file"); - return(NULL); - } - - //Get the real file handle for the file man handle for the smacker file - HANDLE hFile = GetRealFileHandleFromFileManFileHandle( pBink->hFileHandle ); -#else vfs::Path introname(cFilename); vfs::Path dir,filename; introname.splitLast(dir,filename); @@ -207,11 +196,7 @@ BINKFLIC *BinkOpenFlic( const CHAR8 *cFilename ) SGP_RETHROW(_BS(L"Intro file \"") << filename << L"\" could not be extracted" << _BS::wget, ex); } } -#endif -#ifndef USE_VFS - if( !( pBink->BinkHandle = BinkOpen((CHAR8 *)hFile, BINKFILEHANDLE ) ) ) //| SMACKTRACKS -#else vfs::Path tempfilename; try { @@ -226,7 +211,6 @@ BINKFLIC *BinkOpenFlic( const CHAR8 *cFilename ) SGP_RETHROW(L"Temporary intro file could not be read", ex); } if( !( pBink->BinkHandle = BinkOpen(tempfilename.to_string().c_str(), BINKNOTHREADEDIO /*BINKFILEHANDLE*/ ) ) ) //| SMACKTRACKS -#endif { ErrorMsg("BINK ERROR: Bink won't open the BINK file"); return(NULL); diff --git a/Utils/Cinematics.cpp b/Utils/Cinematics.cpp index 8dc056048..5e810cbd2 100644 --- a/Utils/Cinematics.cpp +++ b/Utils/Cinematics.cpp @@ -194,19 +194,6 @@ SMKFLIC *SmkOpenFlic(const CHAR8 *cFilename) return(NULL); } -#ifndef USE_VFS - // Attempt opening the filename - if(!(pSmack->hFileHandle=FileOpen(cFilename, FILE_OPEN_EXISTING | FILE_ACCESS_READ, FALSE))) - { - ErrorMsg("SMK ERROR: Can't open the SMK file"); - return(NULL); - } - - HANDLE hFile; - - //Get the real file handle for the file man handle for the smacker file - hFile = GetRealFileHandleFromFileManFileHandle( pSmack->hFileHandle ); -#else vfs::Path introname(cFilename); vfs::Path dir,filename; introname.splitLast(dir,filename); @@ -232,7 +219,6 @@ SMKFLIC *SmkOpenFlic(const CHAR8 *cFilename) SGP_RETHROW(_BS(L"Intro file \"") << filename << L"\" could not be extracted" << _BS::wget, ex); } } -#endif // Allocate a Smacker buffer for video decompression if(!(pSmack->SmackBuffer=SmackBufferOpen(hDisplayWindow,SMACKAUTOBLIT,SCREEN_WIDTH,SCREEN_HEIGHT,0,0))) @@ -240,9 +226,6 @@ SMKFLIC *SmkOpenFlic(const CHAR8 *cFilename) ErrorMsg("SMK ERROR: Can't allocate a Smacker decompression buffer"); return(NULL); } -#ifndef USE_VFS - if(!(pSmack->SmackHandle=SmackOpen((CHAR8 *)hFile, SMACKFILEHANDLE | SMACKTRACKS, SMACKAUTOEXTRA))) -#else // if(!(pSmack->SmackHandle=SmackOpen(cFilename, SMACKTRACKS, SMACKAUTOEXTRA))) vfs::Path tempfilename; try @@ -258,7 +241,6 @@ SMKFLIC *SmkOpenFlic(const CHAR8 *cFilename) SGP_RETHROW(L"Temporary intro file could not be read", ex); } if(!(pSmack->SmackHandle=SmackOpen(tempfilename.to_string().c_str(), SMACKTRACKS, SMACKAUTOEXTRA))) -#endif { ErrorMsg("SMK ERROR: Smacker won't open the SMK file"); return(NULL); diff --git a/Utils/Debug Control.cpp b/Utils/Debug Control.cpp index b1fa6fa75..21ca49e0c 100644 --- a/Utils/Debug Control.cpp +++ b/Utils/Debug Control.cpp @@ -62,30 +62,10 @@ static struct LiveLog { void LiveMessage( CHAR8 *strMessage) { -#ifndef USE_VFS - FILE *OutFile; - - if ((OutFile = fopen("Log.txt", "a+t")) != NULL) - { - fprintf(OutFile, "%s\n", strMessage); - fclose(OutFile); - } -#else SGP_LOG(s_LiveLog.id, strMessage); -#endif } void MPDebugMsg( CHAR8 *strMessage) { -#ifndef USE_VFS - FILE *OutFile; - - if ((OutFile = fopen("MPDebug.txt", "a+t")) != NULL) - { - fprintf(OutFile, "%s\n", strMessage); - fclose(OutFile); - } -#else static vfs::Log& mpMsg = *vfs::Log::create(L"MPDebug.txt", true); mpMsg << strMessage << vfs::Log::endl; -#endif } diff --git a/Utils/INIReader.cpp b/Utils/INIReader.cpp index f9649c86d..d238ddb07 100644 --- a/Utils/INIReader.cpp +++ b/Utils/INIReader.cpp @@ -12,9 +12,7 @@ #include -#ifdef USE_VFS std::set CIniReader::m_merge_files; -#endif std::stack iniErrorMessages; template @@ -32,26 +30,14 @@ void PushErrorMessage(std::string const& filename, iniErrorMessages.push(errMessage.str()); } -#ifdef USE_VFS void CIniReader::RegisterFileForMerging(vfs::Path const& filename) { m_merge_files.insert(filename); } -#endif CIniReader::CIniReader(const STR8 szFileName) { memset(m_szFileName,0,sizeof(m_szFileName)); -#ifndef USE_VFS - // Snap: Look for the INI file in the custom Data directory. - // If not there, leave at default location. - if ( gCustomDataCat.FindFile(szFileName) ) { - sprintf(m_szFileName, "%s\\%s", gCustomDataCat.GetRootDir().c_str(), szFileName); - } - else { - sprintf(m_szFileName, "%s\\%s", gDefaultDataCat.GetRootDir().c_str(), szFileName); - } -#else strncpy(m_szFileName,szFileName, std::min(strlen(szFileName), sizeof(m_szFileName)-1)); if(m_merge_files.find(szFileName) == m_merge_files.end()) { @@ -81,7 +67,6 @@ CIniReader::CIniReader(const STR8 szFileName) if(getVFS()->fileExists(OvrFileName)) m_oProps.initFromIniFile(vfs::Path(OvrFileName)); } -#endif } CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path) @@ -89,32 +74,6 @@ CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path) memset(m_szFileName,0,sizeof(m_szFileName)); // ary-05/05/2009 : force custom data path for potential non existing file -or- force default data path // : Also, flag file detection to allow functions to determine course of action for case of file [not found/is found]. -#ifndef USE_VFS - if ( Force_Custom_Data_Path ) - { - if ( gCustomDataCat.FindFile(szFileName) ) - { - CIniReader_File_Found = TRUE; - } - else - { - CIniReader_File_Found = FALSE; - } - sprintf(m_szFileName, "%s\\%s", gCustomDataCat.GetRootDir().c_str(), szFileName); - } - else - { - if ( gDefaultDataCat.FindFile(szFileName) ) - { - CIniReader_File_Found = TRUE; - } - else - { - CIniReader_File_Found = FALSE; - } - sprintf(m_szFileName, "%s\\%s", gDefaultDataCat.GetRootDir().c_str(), szFileName); - } -#else strncpy(m_szFileName,szFileName, std::min(strlen(szFileName), sizeof(m_szFileName)-1)); if(m_merge_files.find(szFileName) == m_merge_files.end()) { @@ -137,38 +96,24 @@ CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path) rev_order.pop(); } } - -#endif } void CIniReader::Clear() { -#ifndef USE_VFS - memset(m_szFileName, 0, MAX_PATH); -#else memset(m_szFileName, 0, MAX_PATH); m_oProps.clearContainer(); -#endif } int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int iDefaultValue) { -#ifndef USE_VFS - return GetPrivateProfileInt(szSection, szKey, iDefaultValue, m_szFileName); -#else return (int)(m_oProps.getIntProperty(szSection, szKey, iDefaultValue)); -#endif } int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultValue, int minValue, int maxValue) { -#ifndef USE_VFS - int iniValueReadFromFile = (int)(GetPrivateProfileInt(szSection, szKey, defaultValue, m_szFileName)); -#else int iniValueReadFromFile = (int)(m_oProps.getIntProperty(szSection, szKey, defaultValue)); -#endif //AssertGE(iniValueReadFromFile, minValue); //AssertLE(iniValueReadFromFile, maxValue); if (iniValueReadFromFile < minValue) @@ -200,15 +145,7 @@ int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultV double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double defaultValue, double minValue, double maxValue) { double iniValueReadFromFile; -#ifndef USE_VFS - char szResult[255]; - char szDefault[255]; - sprintf(szDefault, "%f", defaultValue); - GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName); - iniValueReadFromFile = (float) atof(szResult); -#else iniValueReadFromFile = m_oProps.getFloatProperty(szSection, szKey, defaultValue); -#endif //AssertGE(iniValueReadFromFile, minValue); //AssertLE(iniValueReadFromFile, maxValue); if (iniValueReadFromFile < minValue) @@ -227,15 +164,7 @@ double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double def FLOAT CIniReader::ReadFloat(const STR8 szSection, const STR8 szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue) { FLOAT iniValueReadFromFile; -#ifndef USE_VFS - char szResult[255]; - char szDefault[255]; - sprintf(szDefault, "%f", defaultValue); - GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName); - iniValueReadFromFile = (FLOAT) atof(szResult); -#else iniValueReadFromFile = (FLOAT) m_oProps.getFloatProperty(szSection, szKey, (float)defaultValue); -#endif //AssertGE(iniValueReadFromFile, minValue); //AssertLE(iniValueReadFromFile, maxValue); @@ -329,18 +258,6 @@ void CIniReader::ReadINT32Array(const STR8 szSection, const STR8 szKey, std::vec BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool defaultValue, bool bolDisplayError) { -#ifndef USE_VFS - char szResult[255]; - char szDefault[255]; - sprintf(szDefault, "%s", defaultValue? "TRUE" : "FALSE"); - GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName); - for (int idx=0; (szResult[idx] != 0) && (idx < 255); ++idx) - szResult[idx] = toupper(szResult[idx]); - if (strcmp(szResult, "TRUE") == 0) - return TRUE; - else if (strcmp(szResult, "FALSE") == 0) - return FALSE; -#else vfs::String str = m_oProps.getStringProperty(szSection, szKey, L""); if( vfs::StrCmp::Equal(str, L"true") ) { @@ -353,7 +270,7 @@ BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool def std::string szResult = str.utf8(); char szDefault[255]; sprintf(szDefault, "%s", defaultValue? "TRUE" : "FALSE"); -#endif + if(bolDisplayError){ std::stringstream errMessage; errMessage << "The value [" << szSection << "][" << szKey << "] = \"" << szResult << "\" " @@ -370,14 +287,10 @@ BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool def void CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue, STR8 input_buffer, size_t buffer_size) { -#ifndef USE_VFS - GetPrivateProfileString(szSection, szKey, szDefaultValue, input_buffer, buffer_size, m_szFileName); -#else std::string s = m_oProps.getStringProperty(szSection, szKey, szDefaultValue).utf8(); int len = std::min(s.length(),buffer_size-1); strncpy(input_buffer, s.c_str(), len); input_buffer[len] = 0; -#endif } // WANNE - MP: Old version, currently used by Multiplayer @@ -386,12 +299,8 @@ STR8 CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 s // >>>>> Memory Leak <<<<< STR8 szResult = new char[255]; memset(szResult, 0x00, 255); -#ifndef USE_VFS - GetPrivateProfileString(szSection, szKey, szDefaultValue, szResult, 255, m_szFileName); -#else std::string s = m_oProps.getStringProperty(szSection, szKey, szDefaultValue).utf8(); strncpy(szResult, s.c_str(), std::min(s.length(),254)); -#endif return szResult; } @@ -429,20 +338,7 @@ UINT32 CIniReader::ReadUINT32(const STR8 szSection, const STR8 szKey, UINT32 def UINT32 CIniReader::ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue ) { UINT32 iniValueReadFromFile; -#ifndef USE_VFS - STR8 szResult = new char[255]; - STR8 szDefault = new char[255]; - - memset(szResult, 0x00, 255); - memset(szDefault, 0x00, 255); - - sprintf(szDefault, "%u", defaultValue); - - this->ReadString (szSection , szKey , szDefault, szResult, (size_t) 255 ); - iniValueReadFromFile = (UINT32) strtoul(szResult,NULL,0); -#else iniValueReadFromFile = (UINT32) m_oProps.getUIntProperty(szSection, szKey, defaultValue); -#endif //AssertGE(iniValueReadFromFile, minValue); //AssertLE(iniValueReadFromFile, maxValue); @@ -457,10 +353,5 @@ UINT32 CIniReader::ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defau iniValueReadFromFile = maxValue; } -#ifndef USE_VFS - delete [] szResult ; - delete [] szDefault ; -#endif return iniValueReadFromFile; - } diff --git a/Utils/INIReader.h b/Utils/INIReader.h index 947cdeff5..11595a1e9 100644 --- a/Utils/INIReader.h +++ b/Utils/INIReader.h @@ -56,18 +56,14 @@ public: BOOLEAN Is_CIniReader_File_Found(void) {return (CIniReader_File_Found);} void Clear(); -#ifdef USE_VFS static void RegisterFileForMerging(vfs::Path const& filename); -#endif private: vfs::PropertyContainer m_oProps; char m_szFileName[MAX_PATH]; BOOLEAN CIniReader_File_Found; UINT32 ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue); -#ifdef USE_VFS static std::set m_merge_files; -#endif }; -#endif//INIREADER_H \ No newline at end of file +#endif//INIREADER_H diff --git a/Utils/message.cpp b/Utils/message.cpp index 4c6163c48..2befaa263 100644 --- a/Utils/message.cpp +++ b/Utils/message.cpp @@ -1522,22 +1522,8 @@ static struct DebugMessageLog { void WriteMessageToFile( const STR16 pString ) { #ifdef JA2BETAVERSION -#ifndef USE_VFS - FILE *fp; - - fp = fopen( "DebugMessage.txt", "a" ); - - if( fp == NULL ) - { - return; - } - - fprintf( fp, "%S\n", pString ); - fclose( fp ); -#else SGP_LOG(s_DebugMessageLog.id, pString); #endif -#endif } diff --git a/jascreens.cpp b/jascreens.cpp index 4409a0b45..b431dd2e8 100644 --- a/jascreens.cpp +++ b/jascreens.cpp @@ -396,44 +396,25 @@ UINT32 InitScreenHandle(void) // Handle queued .ini file error messages int y = 40; -#ifdef USE_VFS sgp::Logger_ID ini_id = sgp::Logger::instance().createLogger(); sgp::Logger::instance().connectFile(ini_id, L"iniErrorReport.txt", false, sgp::Logger::FLUSH_ON_DELETE); sgp::Logger::LogInstance logger = sgp::Logger::instance().logger(ini_id); -#endif while (! iniErrorMessages.empty()) { -#ifndef USE_VFS - FILE *file_pointer; -#endif static BOOL iniErrorMessage_create_out_file = TRUE; std::string iniErrorMessage = iniErrorMessages.top(); CHAR16 str[256]; if (iniErrorMessage_create_out_file) { -#ifndef USE_VFS - fopen_s( &file_pointer, "..\\iniErrorReport.txt", "w" ); -#endif y += 25; swprintf( str, L"%S", "Warning: found the following ini errors. iniErrorReport.txt has been created." ); DisplayWrappedString( 10, y, 560, 2, FONT12ARIAL, FONT_ORANGE, str, FONT_BLACK, TRUE, LEFT_JUSTIFIED ); iniErrorMessage_create_out_file = FALSE; } - else - { -#ifndef USE_VFS - fopen_s( &file_pointer, "..\\iniErrorReport.txt", "a+" ); -#endif - } y += 25; swprintf( str, L"%S", iniErrorMessage.c_str() ); -#ifndef USE_VFS - fprintf_s (file_pointer , "%S\n" , str ); - fclose( file_pointer ); -#else logger << iniErrorMessage << sgp::endl; -#endif DisplayWrappedString( 10, y, 560, 2, FONT12ARIAL, FONT_ORANGE, str, FONT_BLACK, TRUE, LEFT_JUSTIFIED ); iniErrorMessages.pop(); From 0b5f14a3ad3dd4a220706206d77e338c4f7b651c Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:45:40 +0300 Subject: [PATCH 07/16] Remove empty function --- Standard Gaming Platform/FileMan.cpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index e7f2a1d0d..c11c12823 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -78,8 +78,6 @@ static tFILEMAP s_mapFiles; #define CHECKN(exp) if (!(exp)) { return(NULL); } #define CHECKBI(exp) if (!(exp)) { return(-1); } -#define PRINT_DEBUG_INFO FileDebugPrint(); - //************************************************************************** // // Typedefs @@ -148,7 +146,6 @@ TFileCat gCustomDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct ); -void FileDebugPrint( void ); HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ); HWFILE CreateFileHandle( HANDLE hRealFile, BOOLEAN fDatabaseFile ); void DestroyFileHandle( HWFILE hFile ); @@ -823,23 +820,6 @@ UINT32 FileGetSize( HWFILE hFile ) return 0; } -//************************************************************************** -// -// FileDebugPrint -// -// To print the state of memory to output. -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -//************************************************************************** - -void FileDebugPrint( void ) -{ -} //************************************************************************** // From 74a25a20698f4c8cb64c6a361b8970251da9d348 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:46:36 +0300 Subject: [PATCH 08/16] Remove empty function --- Standard Gaming Platform/soundman.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Standard Gaming Platform/soundman.cpp b/Standard Gaming Platform/soundman.cpp index a2f5869eb..743dd0877 100644 --- a/Standard Gaming Platform/soundman.cpp +++ b/Standard Gaming Platform/soundman.cpp @@ -61,7 +61,6 @@ FILE *SndDebug; // Debug logging void SoundLog(CHAR8 *strMessage); -void InitLogging(); // Cache system BOOLEAN SoundInitCache(void); @@ -213,7 +212,6 @@ BOOLEAN InitializeSoundManager(void) { UINT32 uiCount; - InitLogging(); if(fSoundSystemInit) { @@ -1871,15 +1869,3 @@ void SoundLog(CHAR8 *strMessage) } s_SoundLog; SGP_LOG(s_SoundLog.id, vfs::String::widen(strMessage,strlen(strMessage))); } - -//***************************************************************************************** -// InitLogging -// Creates empty log file -// -// Returns nothing -// -// Created: 10.12.2005 Lesh -//***************************************************************************************** -void InitLogging() -{ -} From f5e0d0bbd8611f08e54300ab170e401121f7a35c Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:47:13 +0300 Subject: [PATCH 09/16] Remove useless function --- Standard Gaming Platform/FileMan.cpp | 6 ------ Standard Gaming Platform/FileMan.h | 1 - 2 files changed, 7 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index c11c12823..3b57cd692 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -1176,12 +1176,6 @@ BOOLEAN DirectoryExists( STRING512 pcDirectory ) } -BOOLEAN MakeFileManDirectory( STRING512 pcDirectory ) -{ - return FALSE; -} - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Removes ALL FILES in the specified directory (and all subdirectories with their files if fRecursive is TRUE) // Use EraseDirectory() to simply delete directory contents without deleting the directory itself diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index b35f06fef..0ef827c10 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -132,7 +132,6 @@ BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory ); BOOLEAN GetExecutableDirectory( STRING512 pcDirectory ); BOOLEAN DirectoryExists( STRING512 pcDirectory ); -BOOLEAN MakeFileManDirectory( STRING512 pcDirectory ); // WARNING: THESE DELETE ALL FILES IN THE DIRECTORY ( and all subdirectories if fRecursive is TRUE!! ) BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive); From f11534e792e64e6aa4957c3e495abadf38574a6a Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:47:38 +0300 Subject: [PATCH 10/16] Remove orphan function declaration --- Standard Gaming Platform/FileMan.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index 0ef827c10..a1350eaa4 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -179,10 +179,6 @@ INT32 CompareSGPFileTimes( SGP_FILETIME *pFirstFileTime, SGP_FILETIME *pSecondFi // files times may be slightly different due to SourceSafe of copying BOOLEAN FileIsOlderThanFile(CHAR8 *pcFileName1, CHAR8 *pcFileName2, UINT32 ulNumSeconds); -// Pass in the Fileman file handle of an OPEN file and it will return.. -// if its a Real File, the return will be the handle of the REAL file -// if its a LIBRARY file, the return will be the handle of the LIBRARY -HANDLE GetRealFileHandleFromFileManFileHandle( HWFILE hFile ); BOOLEAN AddSubdirectoryToPath(CHAR8 *pDirectory); From 5a922e3a42c1400e118538ec8e990c59fed7b1d3 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:48:18 +0300 Subject: [PATCH 11/16] Remove useless function --- Editor/Sector Summary.cpp | 3 ++- Laptop/files.cpp | 1 - Laptop/finances.cpp | 1 - Laptop/history.cpp | 1 - Laptop/laptop.cpp | 4 ---- Standard Gaming Platform/FileMan.cpp | 5 ----- Standard Gaming Platform/FileMan.h | 2 -- 7 files changed, 2 insertions(+), 15 deletions(-) diff --git a/Editor/Sector Summary.cpp b/Editor/Sector Summary.cpp index b71742472..9c328cfaa 100644 --- a/Editor/Sector Summary.cpp +++ b/Editor/Sector Summary.cpp @@ -2177,7 +2177,8 @@ void SummarySaveMapCallback( GUI_BUTTON *btn, INT32 reason ) { CHAR8 filename[40]; sprintf( filename, "MAPS\\%S", gszDisplayName ); - FileClearAttributes( filename ); + // Other call sites have replaced this with FileDelete(); for VFS, should we do the same here? + //FileClearAttributes( filename ); } if( ExternalSaveMap( gszDisplayName ) ) { diff --git a/Laptop/files.cpp b/Laptop/files.cpp index feb802715..3de647b97 100644 --- a/Laptop/files.cpp +++ b/Laptop/files.cpp @@ -476,7 +476,6 @@ void GameInitFiles( ) { if ( FileExists( FILES_DAT_FILE ) == TRUE ) { - FileClearAttributes( FILES_DAT_FILE ); FileDelete( FILES_DAT_FILE ); } diff --git a/Laptop/finances.cpp b/Laptop/finances.cpp index 57c8acbaa..ac542863f 100644 --- a/Laptop/finances.cpp +++ b/Laptop/finances.cpp @@ -460,7 +460,6 @@ void GameInitFinances() // unlink Finances data file if( (FileExists( FINANCES_DATA_FILE ) ) ) { - FileClearAttributes( FINANCES_DATA_FILE ); FileDelete( FINANCES_DATA_FILE ); } GetBalanceFromDisk( ); diff --git a/Laptop/history.cpp b/Laptop/history.cpp index 6067098da..3ca4a8c47 100644 --- a/Laptop/history.cpp +++ b/Laptop/history.cpp @@ -227,7 +227,6 @@ void GameInitHistory() if( ( FileExists( HISTORY_DATA_FILE ) ) ) { // unlink history file - FileClearAttributes( HISTORY_DATA_FILE ); FileDelete( HISTORY_DATA_FILE ); } diff --git a/Laptop/laptop.cpp b/Laptop/laptop.cpp index 33e95d76d..00c2f1615 100644 --- a/Laptop/laptop.cpp +++ b/Laptop/laptop.cpp @@ -7136,28 +7136,24 @@ void ClearOutTempLaptopFiles( void ) // file file if ( (FileExists( "files.dat" ) == TRUE ) ) { - FileClearAttributes( "files.dat" ); FileDelete( "files.dat" ); } // finances if ( (FileExists( "finances.dat" ) == TRUE ) ) { - FileClearAttributes( "finances.dat" ); FileDelete( "finances.dat" ); } // email if ( (FileExists( "email.dat" ) == TRUE ) ) { - FileClearAttributes( "email.dat" ); FileDelete( "email.dat" ); } // history if ( (FileExists( "history.dat" ) == TRUE ) ) { - FileClearAttributes( "history.dat" ); FileDelete( "history.dat" ); } } diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index 3b57cd692..9e4c3804a 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -1472,11 +1472,6 @@ UINT32 FileGetAttributes( STR strFilename ) return( uiFileAttrib ); } -BOOLEAN FileClearAttributes( STR strFilename ) -{ - return TRUE; -} - //returns true if at end of file, else false BOOLEAN FileCheckEndOfFile( HWFILE hFile ) diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index a1350eaa4..e5ba08544 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -156,8 +156,6 @@ BOOLEAN FileMove(STR strOldName, STR strNewName); BOOLEAN FileSetAttributes( STR filename, UINT32 uiNewAttribs ); UINT32 FileGetAttributes( STR filename ); -BOOLEAN FileClearAttributes( STR strFilename ); - //returns true if at end of file, else false BOOLEAN FileCheckEndOfFile( HWFILE hFile ); From 8525d3f86967bb8a5877a42af1421ab88a52e8da Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 7 Oct 2023 22:40:45 +0300 Subject: [PATCH 12/16] Use std::vector for HVSURFACE->RegionList Replaces the use of old custom list implementation in container.cpp --- Standard Gaming Platform/vsurface.cpp | 75 ++++++++------------------- Standard Gaming Platform/vsurface.h | 6 +-- 2 files changed, 26 insertions(+), 55 deletions(-) diff --git a/Standard Gaming Platform/vsurface.cpp b/Standard Gaming Platform/vsurface.cpp index 8636b2c0e..d9d0b064f 100644 --- a/Standard Gaming Platform/vsurface.cpp +++ b/Standard Gaming Platform/vsurface.cpp @@ -110,6 +110,7 @@ HVSURFACE ghFrameBuffer = NULL; HVSURFACE ghMouseBuffer = NULL; #include +#include extern std::map g_SurfaceRectangle; @@ -1161,11 +1162,7 @@ HVSURFACE CreateVideoSurface( VSURFACE_DESC *VSurfaceDesc ) // // Allocate memory for Video Surface data and initialize // - - hVSurface = (HVSURFACE) MemAlloc( sizeof( SGPVSurface ) ); - memset( hVSurface, 0, sizeof( SGPVSurface ) ); - CHECKF( hVSurface != NULL ); - + hVSurface = new SGPVSurface{}; hVSurface->usHeight = usHeight; hVSurface->usWidth = usWidth; // BF : since we use a 16bpp framebuffer and images are converted to that format, @@ -1178,7 +1175,6 @@ HVSURFACE CreateVideoSurface( VSURFACE_DESC *VSurfaceDesc ) hVSurface->pPalette = NULL; hVSurface->p16BPPPalette = NULL; hVSurface->TransparentColor = FROMRGB( 0, 0, 0 ); - hVSurface->RegionList = CreateList( DEFAULT_NUM_REGIONS, sizeof( VSURFACE_REGION ) ); hVSurface->fFlags = 0; hVSurface->pClipper = NULL; @@ -1647,12 +1643,6 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface ) hVSurface->pPalette = NULL; } - //if ( hVSurface->pClipper != NULL ) - //{ - // Release Clipper - // DDReleaseClipper( (LPDIRECTDRAWCLIPPER)hVSurface->pClipper ); - //} - // Get surface pointer lpDDSurface = (LPDIRECTDRAWSURFACE2)hVSurface->pSurfaceData; @@ -1670,7 +1660,7 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface ) } // Release region data - DeleteList( hVSurface->RegionList ); + hVSurface->RegionList.clear(); //If there is a 16bpp palette, free it if( hVSurface->p16BPPPalette != NULL ) @@ -1682,8 +1672,7 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface ) giMemUsedInSurfaces -= ( hVSurface->usHeight * hVSurface->usWidth * ( hVSurface->ubBitDepth / 8 ) ); // Release object - MemFree( hVSurface ); - + delete hVSurface; return( TRUE ); } @@ -1768,7 +1757,7 @@ BOOLEAN GetNumRegions( HVSURFACE hVSurface , UINT32 *puiNumRegions ) { Assert( hVSurface ); - *puiNumRegions = ListSize( hVSurface->RegionList ); + *puiNumRegions = hVSurface->RegionList.size(); return( TRUE ); @@ -1780,7 +1769,7 @@ BOOLEAN AddVSurfaceRegion( HVSURFACE hVSurface, VSURFACE_REGION *pNewRegion ) Assert( pNewRegion != NULL ); // Add new region to list - hVSurface->RegionList = AddtoList( hVSurface->RegionList, pNewRegion, ListSize( hVSurface->RegionList ) ); + hVSurface->RegionList.push_back(*pNewRegion); return( TRUE ); } @@ -1801,29 +1790,10 @@ BOOLEAN AddVSurfaceRegions( HVSURFACE hVSurface, VSURFACE_REGION **ppNewRegions, return( TRUE ); } -BOOLEAN RemoveVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex ) -{ - VSURFACE_REGION aRegion; - - Assert( hVSurface != NULL ); - - return( RemfromList( hVSurface->RegionList, &aRegion, usIndex ) ); - -} - BOOLEAN ClearAllVSurfaceRegions( HVSURFACE hVSurface ) { - UINT32 uiListSize; - Assert( hVSurface != NULL ); - - uiListSize = ListSize( hVSurface->RegionList ); - - for ( INT32 cnt = uiListSize - 1; cnt >= 0; cnt-- ) - { - RemoveVSurfaceRegion( hVSurface, (UINT16)cnt ); - } - + hVSurface->RegionList.clear(); return( TRUE ); } @@ -1831,12 +1801,13 @@ BOOLEAN GetVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION { Assert( hVSurface != NULL ); - if ( !PeekList( hVSurface->RegionList, aRegion, usIndex ) ) + if (usIndex < hVSurface->RegionList.size()) { - return( FALSE ); + *aRegion = hVSurface->RegionList[usIndex]; + return( TRUE ); } - return( TRUE ); + return( FALSE ); } BOOLEAN GetVSurfaceRect( HVSURFACE hVSurface, RECT *pRect) @@ -1858,16 +1829,13 @@ BOOLEAN ReplaceVSurfaceRegion( HVSURFACE hVSurface , UINT16 usIndex, VSURFACE_RE Assert( hVSurface != NULL ); - // Validate index given - if ( !PeekList( hVSurface->RegionList, &OldRegion, usIndex ) ) + if (usIndex < hVSurface->RegionList.size()) { - return( FALSE ); + hVSurface->RegionList[usIndex] = *aRegion; + return( TRUE ); } - // Replace information - hVSurface->RegionList = AddtoList( hVSurface->RegionList, aRegion, usIndex ); - - return( TRUE ); + return( FALSE ); } BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *pNewRegion ) @@ -1876,10 +1844,14 @@ BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_ Assert( pNewRegion != NULL ); // Add new region to list - hVSurface->RegionList = AddtoList( hVSurface->RegionList, pNewRegion, usIndex ); - - return( TRUE ); + if (usIndex < hVSurface->RegionList.size()) + { + auto pos = hVSurface->RegionList.begin() + usIndex; + hVSurface->RegionList.insert(pos, *pNewRegion); + return(TRUE); + } + return(FALSE); } // ******************************************************************* @@ -2161,7 +2133,7 @@ HVSURFACE CreateVideoSurfaceFromDDSurface( LPDIRECTDRAWSURFACE2 lpDDSurface ) // Allocate Video Surface struct - hVSurface = (HVSURFACE) MemAlloc( sizeof( SGPVSurface ) ); + hVSurface = new SGPVSurface{}; // Set values based on DD Surface given DDGetSurfaceDescription ( lpDDSurface, &DDSurfaceDesc ); @@ -2173,7 +2145,6 @@ HVSURFACE CreateVideoSurfaceFromDDSurface( LPDIRECTDRAWSURFACE2 lpDDSurface ) hVSurface->pSurfaceData = (PTR)lpDDSurface; hVSurface->pSurfaceData1 = NULL; hVSurface->pSavedSurfaceData = NULL; - hVSurface->RegionList = CreateList( DEFAULT_NUM_REGIONS, sizeof( VSURFACE_REGION ) ); hVSurface->fFlags = 0; // Get and Set palette, if attached, allow to fail diff --git a/Standard Gaming Platform/vsurface.h b/Standard Gaming Platform/vsurface.h index 579574235..8564aab5f 100644 --- a/Standard Gaming Platform/vsurface.h +++ b/Standard Gaming Platform/vsurface.h @@ -5,6 +5,7 @@ #include "container.h" #include "himage.h" #include "vobject.h" +#include /////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -105,7 +106,7 @@ typedef struct UINT16 *p16BPPPalette; // A 16BPP palette used for 8->16 blits COLORVAL TransparentColor; // Defaults to 0,0,0 PTR pClipper; // A void pointer encapsolated as a clipper Surface - HLIST RegionList; // A List of regions within the video Surface + std::vector RegionList; // A List of regions within the video Surface } SGPVSurface, *HVSURFACE; @@ -240,7 +241,6 @@ BOOLEAN DeleteVideoSurfaceFromIndex( UINT32 uiIndex ); BOOLEAN AddVSurfaceRegion( HVSURFACE hVSurface, VSURFACE_REGION *pNewRegion ); BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *pNewRegion ); BOOLEAN AddVSurfaceRegions( HVSURFACE hVSurface, VSURFACE_REGION **ppNewRegions, UINT16 uiNumRegions ); -BOOLEAN RemoveVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex ); BOOLEAN ClearAllVSurfaceRegions( HVSURFACE hVSurface ); BOOLEAN GetVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *aRegion ); BOOLEAN GetNumRegions( HVSURFACE hVSurface , UINT32 *puiNumRegions ); @@ -286,4 +286,4 @@ BOOLEAN ShadowVideoSurfaceRectUsingLowPercentTable( UINT32 uiDestVSurface, INT32 #endif */ -#endif \ No newline at end of file +#endif From d3b4874af0cd4c4eac737ef79afc802318b4ad02 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 7 Oct 2023 22:43:26 +0300 Subject: [PATCH 13/16] Remove unused global --- Standard Gaming Platform/vobject.cpp | 1 - Standard Gaming Platform/vobject.h | 1 - 2 files changed, 2 deletions(-) diff --git a/Standard Gaming Platform/vobject.cpp b/Standard Gaming Platform/vobject.cpp index d8ade50c9..c784a3833 100644 --- a/Standard Gaming Platform/vobject.cpp +++ b/Standard Gaming Platform/vobject.cpp @@ -51,7 +51,6 @@ -HLIST ghVideoObjects = NULL; BOOLEAN gfVideoObjectsInit=FALSE; #ifndef SGP_VIDEO_DEBUGGING diff --git a/Standard Gaming Platform/vobject.h b/Standard Gaming Platform/vobject.h index 0cdd55533..c49648990 100644 --- a/Standard Gaming Platform/vobject.h +++ b/Standard Gaming Platform/vobject.h @@ -225,7 +225,6 @@ BOOLEAN GetETRLEPixelValue( UINT8 * pDest, HVOBJECT hVObject, UINT16 usETLREInde // Globals // // **************************************************************************** -extern HLIST ghVideoObjects; // **************************************************************************** // From 029af63eb8d84afbd6c188543d95aaffba1ef155 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 7 Oct 2023 22:54:00 +0300 Subject: [PATCH 14/16] Remove unused global --- Standard Gaming Platform/vsurface.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Standard Gaming Platform/vsurface.cpp b/Standard Gaming Platform/vsurface.cpp index d9d0b064f..bf103bbc7 100644 --- a/Standard Gaming Platform/vsurface.cpp +++ b/Standard Gaming Platform/vsurface.cpp @@ -98,12 +98,6 @@ void CheckValidVSurfaceIndex( UINT32 uiIndex ); INT32 giMemUsedInSurfaces; - -//OBSOLETE!!!!!!!!! -HLIST ghVideoSurfaces = NULL; -//OBSOLETE!!!!!!!!! - - HVSURFACE ghPrimary = NULL; HVSURFACE ghBackBuffer = NULL; HVSURFACE ghFrameBuffer = NULL; From f00214d00dd73d5e8bb59d3e9b5f36803dc2be3e Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:55:22 +0300 Subject: [PATCH 15/16] Use std::queue and std::vector in event system instead of old custom code from container.cpp * Removed initialize and shutdown event manager calls from Init.cpp as they were only used to create and destroy the old HLIST globals * Moved code from Event Manager.cpp to Event Pump.cpp as the event queue system is only used in said file. * Removed now useless event manager.cpp and .h files --- Init.cpp | 8 - Utils/CMakeLists.txt | 1 - Utils/Event Manager.cpp | 234 ------------------------ Utils/Event Manager.h | 33 ---- Utils/Event Pump.cpp | 383 ++++++++++++++++++++++++++++------------ Utils/Event Pump.h | 7 +- 6 files changed, 269 insertions(+), 397 deletions(-) delete mode 100644 Utils/Event Manager.cpp delete mode 100644 Utils/Event Manager.h diff --git a/Init.cpp b/Init.cpp index 207884248..605a13a7b 100644 --- a/Init.cpp +++ b/Init.cpp @@ -1514,12 +1514,6 @@ UINT32 InitializeJA2(void) // INit intensity tables BuildIntensityTable( ); - // Init Event Manager - if ( !InitializeEventManager( ) ) - { - return( ERROR_SCREEN ); - } - // Initailize World if ( !InitializeWorld( ) ) { @@ -1698,8 +1692,6 @@ void ShutdownJA2(void) ShutdownJA2Sound( ); - ShutdownEventManager( ); - ShutdownBaseDirtyRectQueue( ); // Unload any text box images! diff --git a/Utils/CMakeLists.txt b/Utils/CMakeLists.txt index 0a11b8bb2..688f95559 100644 --- a/Utils/CMakeLists.txt +++ b/Utils/CMakeLists.txt @@ -6,7 +6,6 @@ set(UtilsSrc "${CMAKE_CURRENT_SOURCE_DIR}/Debug Control.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/dsutil.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Encrypted File.cpp" -"${CMAKE_CURRENT_SOURCE_DIR}/Event Manager.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Event Pump.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/ExportStrings.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Font Control.cpp" diff --git a/Utils/Event Manager.cpp b/Utils/Event Manager.cpp deleted file mode 100644 index edd39c59c..000000000 --- a/Utils/Event Manager.cpp +++ /dev/null @@ -1,234 +0,0 @@ - #include - #include - #include "sgp.h" - #include "container.h" - #include "wcheck.h" - #include "Event Manager.h" - #include "Timer Control.h" - -HLIST hEventQueue = NULL; -HLIST hDelayEventQueue = NULL; -HLIST hDemandEventQueue = NULL; - -#define QUEUE_RESIZE 20 - -// LOCAL FUNCTIONS -HLIST GetQueue( UINT8 ubQueueID ); -void SetQueue( UINT8 ubQueueID, HLIST hQueue ); - - -BOOLEAN InitializeEventManager( ) -{ - // Create Queue - hEventQueue = CreateList( QUEUE_RESIZE, sizeof( PTR ) ); - - if ( hEventQueue == NULL ) - { - return( FALSE ); - } - - // Create Delay Queue - hDelayEventQueue = CreateList( QUEUE_RESIZE, sizeof( PTR ) ); - - if ( hDelayEventQueue == NULL ) - { - return( FALSE ); - } - - // Create Demand Queue (events on this queue are only processed when specifically - // called for by code) - hDemandEventQueue = CreateList( QUEUE_RESIZE, sizeof( PTR ) ); - - if ( hDemandEventQueue == NULL ) - { - return( FALSE ); - } - - return( TRUE ); -} - -BOOLEAN ShutdownEventManager( ) -{ - if ( hEventQueue != NULL ) - { - DeleteList( hEventQueue ); - } - - if ( hDelayEventQueue != NULL ) - { - DeleteList( hDelayEventQueue ); - } - - if ( hDemandEventQueue != NULL ) - { - DeleteList( hDemandEventQueue ); - } - - return( TRUE ); -} - - - -BOOLEAN AddEvent( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT32 uiDataSize, UINT8 ubQueueID ) -{ - EVENT *pEvent; - UINT32 uiEventSize = sizeof( EVENT ); - HLIST hQueue; - - // Allocate new event - pEvent = (EVENT *) MemAlloc( uiEventSize + uiDataSize ); - - CHECKF( pEvent != NULL ); - - // Set values - pEvent->TimeStamp = GetJA2Clock( ); - pEvent->usDelay = usDelay; - pEvent->uiEvent = uiEvent; - pEvent->uiFlags = 0; - pEvent->uiDataSize = uiDataSize; - pEvent->pData = (BYTE*)pEvent; - pEvent->pData = pEvent->pData + uiEventSize; - - memcpy( pEvent->pData, pEventData, uiDataSize ); - - // Add event to queue - hQueue = GetQueue( ubQueueID ); - hQueue = AddtoList( hQueue, &pEvent, ListSize( hQueue ) ); - SetQueue( ubQueueID, hQueue ); - - return( TRUE ); - -} - - - -BOOLEAN RemoveEvent( EVENT **ppEvent, UINT32 uiIndex, UINT8 ubQueueID ) -{ - UINT32 uiQueueSize; - HLIST hQueue; - - // Get an event from queue, if one exists - // - - hQueue = GetQueue( ubQueueID ); - - - // Get Size - uiQueueSize = ListSize( hQueue ); - - if ( uiQueueSize > 0 ) - { - // Get - CHECKF( RemfromList( hQueue , ppEvent, uiIndex ) != FALSE ); - } - else - { - return( FALSE ); - } - - return( TRUE ); -} - - -BOOLEAN PeekEvent( EVENT **ppEvent, UINT32 uiIndex , UINT8 ubQueueID ) -{ - UINT32 uiQueueSize; - HLIST hQueue; - - // Get an event from queue, if one exists - // - - hQueue = GetQueue( ubQueueID ); - - - // Get Size - uiQueueSize = ListSize( hQueue ); - - if ( uiQueueSize > 0 ) - { - // Get - CHECKF( PeekList( hQueue, ppEvent, uiIndex ) != FALSE ); - } - else - { - return( FALSE ); - } - - return( TRUE ); -} - - - -BOOLEAN FreeEvent( EVENT *pEvent ) -{ - CHECKF( pEvent != NULL ); - - // Delete event - MemFree( pEvent ); - - return( TRUE ); -} - - -UINT32 EventQueueSize( UINT8 ubQueueID ) -{ - UINT32 uiQueueSize; - HLIST hQueue; - - // Get an event from queue, if one exists - // - - hQueue = GetQueue( ubQueueID ); - - // Get Size - uiQueueSize = ListSize( hQueue ); - - return( uiQueueSize ); -} - - -HLIST GetQueue( UINT8 ubQueueID ) -{ - switch( ubQueueID ) - { - case PRIMARY_EVENT_QUEUE: - return( hEventQueue ); - break; - - case SECONDARY_EVENT_QUEUE: - return( hDelayEventQueue ); - break; - - case DEMAND_EVENT_QUEUE: - return( hDemandEventQueue ); - break; - - default: - Assert( FALSE ); - return( 0 ); - break; - } - -} - -void SetQueue( UINT8 ubQueueID, HQUEUE hQueue ) -{ - switch( ubQueueID ) - { - case PRIMARY_EVENT_QUEUE: - hEventQueue = hQueue; - break; - - case SECONDARY_EVENT_QUEUE: - hDelayEventQueue = hQueue; - break; - - case DEMAND_EVENT_QUEUE: - hDemandEventQueue = hQueue; - break; - - default: - Assert( FALSE ); - break; - } -} diff --git a/Utils/Event Manager.h b/Utils/Event Manager.h deleted file mode 100644 index 1e24941ff..000000000 --- a/Utils/Event Manager.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __EVENT_MANAGER_H -#define __EVENT_MANAGER_H - -typedef struct -{ - TIMER TimeStamp; - UINT32 uiFlags; - UINT16 usDelay; - UINT32 uiEvent; - UINT32 uiDataSize; - BYTE *pData; - -} EVENT; - -#define PRIMARY_EVENT_QUEUE 0 -#define SECONDARY_EVENT_QUEUE 1 -#define DEMAND_EVENT_QUEUE 2 - -#define EVENT_EXPIRED 0x00000002 - -// Management fucntions -BOOLEAN InitializeEventManager( ); -BOOLEAN ShutdownEventManager( ); - -BOOLEAN AddEvent( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT32 uiDataSize, UINT8 ubQueueID ); -BOOLEAN RemoveEvent( EVENT **ppEvent, UINT32 uiIndex , UINT8 ubQueueID ); -BOOLEAN PeekEvent( EVENT **ppEvent, UINT32 uiIndex , UINT8 ubQueueID ); -BOOLEAN FreeEvent( EVENT *pEvent ); -UINT32 EventQueueSize( UINT8 ubQueueID ); - - -#endif - diff --git a/Utils/Event Pump.cpp b/Utils/Event Pump.cpp index da01372d4..4c5f2a702 100644 --- a/Utils/Event Pump.cpp +++ b/Utils/Event Pump.cpp @@ -1,21 +1,26 @@ - #include - #include - #include "sgp.h" - #include "container.h" - #include "wcheck.h" - #include "Event Pump.h" - #include "Timer.h" - #include "Sound Control.h" - #include "Overhead.h" - #include "weapons.h" - #include "Animation Control.h" - #include "opplist.h" - #include "Tactical Save.h" +#include +#include +#include "sgp.h" +#include "container.h" +#include "wcheck.h" +#include "Event Pump.h" +#include "Timer.h" +#include "Sound Control.h" +#include "Overhead.h" +#include "weapons.h" +#include "Animation Control.h" +#include "opplist.h" +#include "Tactical Save.h" +#include +#include #ifdef NETWORKED #include "Networking.h" #include "NetworkEvent.h" #endif +#include "MemMan.h" +#include "Timer Control.h" +#include "DEBUG.H" UINT8 gubEncryptionArray4[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_ARRAY_SIZE ] = { @@ -590,6 +595,26 @@ UINT8 gubEncryptionArray4[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_AR }, }; +typedef struct +{ + TIMER TimeStamp; + UINT32 uiFlags; + UINT16 usDelay; + UINT32 uiEvent; + UINT32 uiDataSize; + BYTE* pData; + +} EVENT; + +#define PRIMARY_EVENT_QUEUE 0 +#define SECONDARY_EVENT_QUEUE 1 +#define DEMAND_EVENT_QUEUE 2 +#define EVENT_EXPIRED 0x00000002 + +std::queue hEventQueue; +std::vector hDelayEventQueue; +std::queue hDemandEventQueue; + // GLobals used here, for each event structure used, // Used as globals for stack reasons EV_E_PLAYSOUND EPlaySound; @@ -601,67 +626,172 @@ EV_S_GETNEWPATH SGetNewPath; EV_S_BEGINTURN SBeginTurn; EV_S_CHANGESTANCE SChangeStance; EV_S_SETDIRECTION SSetDirection; -EV_S_SETDESIREDDIRECTION SSetDesiredDirection; -EV_S_BEGINFIREWEAPON SBeginFireWeapon; +EV_S_SETDESIREDDIRECTION SSetDesiredDirection; +EV_S_BEGINFIREWEAPON SBeginFireWeapon; EV_S_FIREWEAPON SFireWeapon; EV_S_WEAPONHIT SWeaponHit; EV_S_STRUCTUREHIT SStructureHit; EV_S_WINDOWHIT SWindowHit; -EV_S_MISS SMiss; -EV_S_NOISE SNoise; +EV_S_MISS SMiss; +EV_S_NOISE SNoise; EV_S_STOP_MERC SStopMerc; -EV_S_SENDPATHTONETWORK SUpdateNetworkSoldier; +EV_S_SENDPATHTONETWORK SUpdateNetworkSoldier; extern BOOLEAN gfAmINetworked; -BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID ); + BOOLEAN ExecuteGameEvent( EVENT *pEvent ); -BOOLEAN AddGameEvent( UINT32 uiEvent, UINT16 usDelay, PTR pEventData ) +BOOLEAN AddEvent(UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT32 uiDataSize, UINT8 ubQueueID) { - if (usDelay == DEMAND_EVENT_DELAY) + BYTE* pData = (BYTE*)MemAlloc(uiDataSize); + Assert(pData); + memcpy(pData, pEventData, uiDataSize); + + // Add event to queue + switch (ubQueueID) { - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local and network #%d", uiEvent)); - #ifdef NETWORKED - if(gfAmINetworked) - SendEventToNetwork(uiEvent, usDelay, pEventData); - #endif - return( AddGameEventToQueue( uiEvent, 0, pEventData, DEMAND_EVENT_QUEUE ) ); + case PRIMARY_EVENT_QUEUE: + //hEventQueue.push(*pEvent); + hEventQueue.emplace( + EVENT{ + GetJA2Clock(), + 0, + usDelay, + uiEvent, + uiDataSize, + pData + } + ); + break; + + case SECONDARY_EVENT_QUEUE: + hDelayEventQueue.emplace_back( + EVENT{ + GetJA2Clock(), + 0, + usDelay, + uiEvent, + uiDataSize, + pData + } + ); + break; + + case DEMAND_EVENT_QUEUE: + hDemandEventQueue.emplace( + EVENT{ + GetJA2Clock(), + 0, + usDelay, + uiEvent, + uiDataSize, + pData + } + ); + break; + + default: + Assert(FALSE); + break; } - else if( uiEvent < EVENTS_LOCAL_AND_NETWORK) - { - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local and network #%d", uiEvent)); - #ifdef NETWORKED - if(gfAmINetworked) - SendEventToNetwork(uiEvent, usDelay, pEventData); - #endif - return( AddGameEventToQueue( uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE ) ); - } - else if( uiEvent < EVENTS_ONLY_USED_LOCALLY) - { - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local #%d", uiEvent)); - return( AddGameEventToQueue( uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE ) ); - } - else if( uiEvent < EVENTS_ONLY_SENT_OVER_NETWORK) - { - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending network #%d", uiEvent)); - #ifdef NETWORKED - if(gfAmINetworked) - SendEventToNetwork(uiEvent, usDelay, pEventData); - #endif - return(TRUE); - } - // There is an error with the event - else - return(FALSE); + + return(TRUE); } -BOOLEAN AddGameEventFromNetwork( UINT32 uiEvent, UINT16 usDelay, PTR pEventData ) + +static BOOLEAN RemoveEventFromSecondaryEventQueue(EVENT* ppEvent, UINT32 uiIndex) { - return( AddGameEventToQueue( uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE ) ); + if (uiIndex < hDelayEventQueue.size()) + { + *ppEvent = hDelayEventQueue[uiIndex]; + hDelayEventQueue.erase(hDelayEventQueue.begin() + uiIndex); + return(TRUE); + } + + return(FALSE); } + +BOOLEAN PopEvent(EVENT* ppEvent, UINT8 ubQueueID) +{ + // Get an event from queue, if one exists + // + switch (ubQueueID) + { + case PRIMARY_EVENT_QUEUE: + if (!hEventQueue.empty()) + { + *ppEvent = hEventQueue.front(); + hEventQueue.pop(); + return(TRUE); + } + break; + + case SECONDARY_EVENT_QUEUE: + if (!hDelayEventQueue.empty()) + { + *ppEvent = hDelayEventQueue.front(); + hDelayEventQueue.erase(hDelayEventQueue.begin()); + return(TRUE); + } + break; + + case DEMAND_EVENT_QUEUE: + if (!hDemandEventQueue.empty()) + { + *ppEvent = hDemandEventQueue.front(); + hDemandEventQueue.pop(); + return(TRUE); + } + break; + + default: + Assert(FALSE); + break; + } + + return(FALSE); +} + + +BOOLEAN FreeEvent(EVENT* pEvent) +{ + CHECKF(pEvent != NULL); + + // Delete event + MemFree(pEvent->pData); + //MemFree(pEvent); + + return(TRUE); +} + + +UINT32 EventQueueSize(UINT8 ubQueueID) +{ + switch (ubQueueID) + { + case PRIMARY_EVENT_QUEUE: + return(hEventQueue.size()); + break; + + case SECONDARY_EVENT_QUEUE: + return(hDelayEventQueue.size()); + break; + + case DEMAND_EVENT_QUEUE: + return(hDemandEventQueue.size()); + break; + + default: + Assert(FALSE); + return(-1); + break; + } +} + + BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID ) { UINT32 uiDataSize; @@ -783,18 +913,65 @@ BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UIN return( TRUE ); } + +BOOLEAN AddGameEvent(UINT32 uiEvent, UINT16 usDelay, PTR pEventData) +{ + if (usDelay == DEMAND_EVENT_DELAY) + { + //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local and network #%d", uiEvent)); +#ifdef NETWORKED + if (gfAmINetworked) + SendEventToNetwork(uiEvent, usDelay, pEventData); +#endif + return(AddGameEventToQueue(uiEvent, 0, pEventData, DEMAND_EVENT_QUEUE)); + } + else if (uiEvent < EVENTS_LOCAL_AND_NETWORK) + { + //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local and network #%d", uiEvent)); +#ifdef NETWORKED + if (gfAmINetworked) + SendEventToNetwork(uiEvent, usDelay, pEventData); +#endif + return(AddGameEventToQueue(uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE)); + } + else if (uiEvent < EVENTS_ONLY_USED_LOCALLY) + { + //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local #%d", uiEvent)); + return(AddGameEventToQueue(uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE)); + } + else if (uiEvent < EVENTS_ONLY_SENT_OVER_NETWORK) + { + //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending network #%d", uiEvent)); +#ifdef NETWORKED + if (gfAmINetworked) + SendEventToNetwork(uiEvent, usDelay, pEventData); +#endif + return(TRUE); + } + // There is an error with the event + else + return(FALSE); +} + + +BOOLEAN AddGameEventFromNetwork(UINT32 uiEvent, UINT16 usDelay, PTR pEventData) +{ + return(AddGameEventToQueue(uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE)); +} + + BOOLEAN DequeAllGameEvents( BOOLEAN fExecute ) { - EVENT *pEvent; - UINT32 uiQueueSize, cnt; - BOOLEAN fCompleteLoop = FALSE; + EVENT pEvent; + UINT32 uiQueueSize, i; + BOOLEAN fCompleteLoop = FALSE; + + // First dequeue all primary events - - while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 ) { // Get Event - if ( RemoveEvent( &pEvent, 0, PRIMARY_EVENT_QUEUE) == FALSE ) + if (PopEvent( &pEvent, PRIMARY_EVENT_QUEUE) == FALSE ) { return( FALSE ); } @@ -802,90 +979,66 @@ BOOLEAN DequeAllGameEvents( BOOLEAN fExecute ) if ( fExecute ) { // Check if event has a delay and add to secondary queue if so - if ( pEvent->usDelay > 0 ) + if ( pEvent.usDelay > 0 ) { - AddGameEventToQueue( pEvent->uiEvent, pEvent->usDelay, pEvent->pData, SECONDARY_EVENT_QUEUE ); + AddGameEventToQueue( pEvent.uiEvent, pEvent.usDelay, pEvent.pData, SECONDARY_EVENT_QUEUE ); } else { - ExecuteGameEvent( pEvent ); + ExecuteGameEvent( &pEvent ); } } // Delete event - FreeEvent( pEvent ); - + FreeEvent( &pEvent ); }; - // NOW CHECK SECONDARY QUEUE FOR ANY EXPRIED EVENTS - // Get size of queue + + // NOW CHECK SECONDARY QUEUE FOR EVENTS uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE ); - for ( cnt = 0; cnt < uiQueueSize; cnt++ ) + for ( i = 0; i < uiQueueSize; i++ ) { - if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE ) - { - return( FALSE ); - } - + EVENT& pEventRef = hDelayEventQueue[i]; // Check time - if ( ( GetJA2Clock() - pEvent->TimeStamp ) > pEvent->usDelay ) + if ( ( GetJA2Clock() - pEventRef.TimeStamp ) > pEventRef.usDelay ) { if ( fExecute ) { - ExecuteGameEvent( pEvent ); + ExecuteGameEvent( &pEventRef ); } // FLag as expired - pEvent->uiFlags = EVENT_EXPIRED; - + pEventRef.uiFlags = EVENT_EXPIRED; } - } - do + // Remove expired events from secondary event queue + uiQueueSize = EventQueueSize(SECONDARY_EVENT_QUEUE); + for (INT32 i = uiQueueSize-1; i >= 0; i--) { - uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE ); - - for ( cnt = 0; cnt < uiQueueSize; cnt++ ) + EVENT& pEventRef = hDelayEventQueue[i]; + if (pEventRef.uiFlags & EVENT_EXPIRED) { - if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE ) - { - return( FALSE ); - } - - // Check time - if ( pEvent->uiFlags & EVENT_EXPIRED ) - { - RemoveEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE ); - FreeEvent( pEvent ); - // Restart loop - break; - - } - + RemoveEventFromSecondaryEventQueue(&pEventRef, i); + FreeEvent(&pEventRef); } - - if ( cnt == uiQueueSize ) - { - fCompleteLoop = TRUE; - } - - } while( fCompleteLoop == FALSE ); + } return( TRUE ); } + BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute ) { - EVENT *pEvent; + EVENT pEvent; // Dequeue all events on the demand queue (only) while( EventQueueSize( DEMAND_EVENT_QUEUE ) > 0 ) { // Get Event - if ( RemoveEvent( &pEvent, 0, DEMAND_EVENT_QUEUE) == FALSE ) + if ( PopEvent( &pEvent, DEMAND_EVENT_QUEUE) == FALSE ) { return( FALSE ); } @@ -893,18 +1046,18 @@ BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute ) if ( fExecute ) { // Check if event has a delay and add to secondary queue if so - if ( pEvent->usDelay > 0 ) + if ( pEvent.usDelay > 0 ) { - AddGameEventToQueue( pEvent->uiEvent, pEvent->usDelay, pEvent->pData, SECONDARY_EVENT_QUEUE ); + AddGameEventToQueue( pEvent.uiEvent, pEvent.usDelay, pEvent.pData, SECONDARY_EVENT_QUEUE ); } else { - ExecuteGameEvent( pEvent ); + ExecuteGameEvent( &pEvent ); } } // Delete event - FreeEvent( pEvent ); + FreeEvent( &pEvent ); }; @@ -912,7 +1065,6 @@ BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute ) } - BOOLEAN ExecuteGameEvent( EVENT *pEvent ) { SOLDIERTYPE *pSoldier; @@ -1237,17 +1389,16 @@ BOOLEAN ExecuteGameEvent( EVENT *pEvent ) BOOLEAN ClearEventQueue( void ) { // clear out the event queue - EVENT *pEvent; + EVENT pEvent; while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 ) { // Get Event - if ( RemoveEvent( &pEvent, 0, PRIMARY_EVENT_QUEUE) == FALSE ) + if (PopEvent( &pEvent, PRIMARY_EVENT_QUEUE) == FALSE ) { return( FALSE ); } + FreeEvent(&pEvent); } return( TRUE ); } - - diff --git a/Utils/Event Pump.h b/Utils/Event Pump.h index 536d0ab52..b171bca7a 100644 --- a/Utils/Event Pump.h +++ b/Utils/Event Pump.h @@ -1,7 +1,6 @@ #ifndef EVENT_PROCESSOR_H #define EVENT_PROCESSOR_H -#include "Event Manager.h" #include "Overhead Types.h" @@ -271,8 +270,6 @@ BOOLEAN AddGameEventFromNetwork( UINT32 uiEvent, UINT16 usDelay, PTR pEventData BOOLEAN DequeAllGameEvents( BOOLEAN fExecute ); BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute ); -// clean out the evetn queue +// clean out the event queue BOOLEAN ClearEventQueue( void ); - - -#endif \ No newline at end of file +#endif From d6a3a27b58eb7cd7a00bbccc72db1065726f2172 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Tue, 10 Oct 2023 00:47:02 +0300 Subject: [PATCH 16/16] Address review feedback * Dialogue control.cpp * vsurface.cpp * Event pump.cpp --- Standard Gaming Platform/vsurface.cpp | 27 ++++----- Tactical/Dialogue Control.cpp | 20 +++---- Utils/Event Pump.cpp | 85 ++++++++++++--------------- 3 files changed, 57 insertions(+), 75 deletions(-) diff --git a/Standard Gaming Platform/vsurface.cpp b/Standard Gaming Platform/vsurface.cpp index bf103bbc7..0df8bab77 100644 --- a/Standard Gaming Platform/vsurface.cpp +++ b/Standard Gaming Platform/vsurface.cpp @@ -1795,13 +1795,13 @@ BOOLEAN GetVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION { Assert( hVSurface != NULL ); - if (usIndex < hVSurface->RegionList.size()) + if (usIndex >= hVSurface->RegionList.size()) { - *aRegion = hVSurface->RegionList[usIndex]; - return( TRUE ); + return( FALSE ); } - return( FALSE ); + *aRegion = hVSurface->RegionList[usIndex]; + return( TRUE ); } BOOLEAN GetVSurfaceRect( HVSURFACE hVSurface, RECT *pRect) @@ -1823,13 +1823,13 @@ BOOLEAN ReplaceVSurfaceRegion( HVSURFACE hVSurface , UINT16 usIndex, VSURFACE_RE Assert( hVSurface != NULL ); - if (usIndex < hVSurface->RegionList.size()) + if (usIndex >= hVSurface->RegionList.size()) { - hVSurface->RegionList[usIndex] = *aRegion; - return( TRUE ); + return( FALSE ); } - return( FALSE ); + hVSurface->RegionList[usIndex] = *aRegion; + return( TRUE ); } BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *pNewRegion ) @@ -1837,15 +1837,14 @@ BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_ Assert( hVSurface != NULL ); Assert( pNewRegion != NULL ); - // Add new region to list - if (usIndex < hVSurface->RegionList.size()) + if (usIndex >= hVSurface->RegionList.size()) { - auto pos = hVSurface->RegionList.begin() + usIndex; - hVSurface->RegionList.insert(pos, *pNewRegion); - return(TRUE); + return(FALSE); } - return(FALSE); + auto pos = hVSurface->RegionList.begin() + usIndex; + hVSurface->RegionList.insert(pos, *pNewRegion); + return(TRUE); } // ******************************************************************* diff --git a/Tactical/Dialogue Control.cpp b/Tactical/Dialogue Control.cpp index b8d9a9a72..cb646341e 100644 --- a/Tactical/Dialogue Control.cpp +++ b/Tactical/Dialogue Control.cpp @@ -361,7 +361,7 @@ void EmptyDialogueQueue( ) } -inline BOOLEAN DialogueQueueIsEmpty( ) +BOOLEAN DialogueQueueIsEmpty( ) { return( ghDialogueQ.empty() ); } @@ -1798,8 +1798,7 @@ void AdditionalTacticalCharacterDialogue_AllInSectorRadiusCall( UINT8 ausIgnoreP BOOLEAN CharacterDialogueWithSpecialEvent( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 iFaceIndex, UINT8 bUIHandlerID, BOOLEAN fFromSoldier, BOOLEAN fDelayed, UINT32 uiFlag, UINT32 uiData1, UINT32 uiData2 ) { - DIALOGUE_Q_STRUCT QItem; - memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + DIALOGUE_Q_STRUCT QItem{}; QItem.ubCharacterNum = ubCharacterNum; QItem.usQuoteNum = usQuoteNum; QItem.iFaceIndex = iFaceIndex; @@ -1833,8 +1832,7 @@ BOOLEAN CharacterDialogueWithSpecialEvent( UINT8 ubCharacterNum, UINT16 usQuoteN BOOLEAN CharacterDialogueWithSpecialEventEx( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 iFaceIndex, UINT8 bUIHandlerID, BOOLEAN fFromSoldier, BOOLEAN fDelayed, UINT32 uiFlag, UINT32 uiData1, UINT32 uiData2, UINT32 uiData3 ) { - DIALOGUE_Q_STRUCT QItem; - memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + DIALOGUE_Q_STRUCT QItem{}; QItem.ubCharacterNum = ubCharacterNum; QItem.usQuoteNum = usQuoteNum; QItem.iFaceIndex = iFaceIndex; @@ -1863,8 +1861,7 @@ BOOLEAN CharacterDialogueWithSpecialEventEx( UINT8 ubCharacterNum, UINT16 usQuot BOOLEAN CharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 iFaceIndex, UINT8 bUIHandlerID, BOOLEAN fFromSoldier, BOOLEAN fDelayed ) { - DIALOGUE_Q_STRUCT QItem; - memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + DIALOGUE_Q_STRUCT QItem{}; QItem.ubCharacterNum = ubCharacterNum; QItem.usQuoteNum = usQuoteNum; QItem.iFaceIndex = iFaceIndex; @@ -1914,8 +1911,7 @@ BOOLEAN SnitchCharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 UINT32 uiSpecialEventData3, UINT32 uiSpecialEventData4, UINT8 bUIHandlerID, BOOLEAN fFromSoldier, BOOLEAN fDelayed ) { - DIALOGUE_Q_STRUCT QItem; - memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + DIALOGUE_Q_STRUCT QItem{}; QItem.ubCharacterNum = ubCharacterNum; QItem.usQuoteNum = usQuoteNum; QItem.uiSpecialEventFlag = uiSpecialEventFlag; @@ -1946,8 +1942,7 @@ BOOLEAN SnitchCharacterDialogue( UINT8 ubCharacterNum, UINT16 usQuoteNum, INT32 BOOLEAN SpecialCharacterDialogueEvent( UINT32 uiSpecialEventFlag, UINT32 uiSpecialEventData1, UINT32 uiSpecialEventData2, UINT32 uiSpecialEventData3, INT32 iFaceIndex, UINT8 bUIHandlerID ) { - DIALOGUE_Q_STRUCT QItem; - memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + DIALOGUE_Q_STRUCT QItem{}; QItem.uiSpecialEventFlag = uiSpecialEventFlag; QItem.uiSpecialEventData = uiSpecialEventData1; QItem.uiSpecialEventData2 = uiSpecialEventData2; @@ -1972,8 +1967,7 @@ BOOLEAN SpecialCharacterDialogueEvent( UINT32 uiSpecialEventFlag, UINT32 uiSpeci BOOLEAN SpecialCharacterDialogueEventWithExtraParam( UINT32 uiSpecialEventFlag, UINT32 uiSpecialEventData1, UINT32 uiSpecialEventData2, UINT32 uiSpecialEventData3, UINT32 uiSpecialEventData4, INT32 iFaceIndex, UINT8 bUIHandlerID ) { - DIALOGUE_Q_STRUCT QItem; - memset(&QItem, 0, sizeof(DIALOGUE_Q_STRUCT)); + DIALOGUE_Q_STRUCT QItem{}; QItem.uiSpecialEventFlag = uiSpecialEventFlag; QItem.uiSpecialEventData = uiSpecialEventData1; QItem.uiSpecialEventData2 = uiSpecialEventData2; diff --git a/Utils/Event Pump.cpp b/Utils/Event Pump.cpp index 4c5f2a702..c05677775 100644 --- a/Utils/Event Pump.cpp +++ b/Utils/Event Pump.cpp @@ -11,8 +11,8 @@ #include "Animation Control.h" #include "opplist.h" #include "Tactical Save.h" -#include -#include +#include +#include #ifdef NETWORKED #include "Networking.h" @@ -595,7 +595,7 @@ UINT8 gubEncryptionArray4[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_AR }, }; -typedef struct +struct EVENT { TIMER TimeStamp; UINT32 uiFlags; @@ -604,7 +604,25 @@ typedef struct UINT32 uiDataSize; BYTE* pData; -} EVENT; + EVENT(UINT16 delay, UINT32 event, UINT32 dataSize, BYTE* eventData) : + TimeStamp(GetJA2Clock()), + uiFlags(0), + usDelay(delay), + uiEvent(event), + uiDataSize(dataSize), + pData{ eventData } + { + } + + EVENT() : + TimeStamp(GetJA2Clock()), + uiFlags(0), + usDelay(0), + uiEvent(0), + uiDataSize(0), + pData{ nullptr } + {} +}; #define PRIMARY_EVENT_QUEUE 0 #define SECONDARY_EVENT_QUEUE 1 @@ -653,43 +671,15 @@ BOOLEAN AddEvent(UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT32 uiDataSi switch (ubQueueID) { case PRIMARY_EVENT_QUEUE: - //hEventQueue.push(*pEvent); - hEventQueue.emplace( - EVENT{ - GetJA2Clock(), - 0, - usDelay, - uiEvent, - uiDataSize, - pData - } - ); + hEventQueue.emplace(usDelay, uiEvent, uiDataSize, pData); break; case SECONDARY_EVENT_QUEUE: - hDelayEventQueue.emplace_back( - EVENT{ - GetJA2Clock(), - 0, - usDelay, - uiEvent, - uiDataSize, - pData - } - ); + hDelayEventQueue.emplace_back(usDelay, uiEvent, uiDataSize, pData); break; case DEMAND_EVENT_QUEUE: - hDemandEventQueue.emplace( - EVENT{ - GetJA2Clock(), - 0, - usDelay, - uiEvent, - uiDataSize, - pData - } - ); + hDemandEventQueue.emplace(usDelay, uiEvent, uiDataSize, pData); break; default: @@ -703,18 +693,18 @@ BOOLEAN AddEvent(UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT32 uiDataSi static BOOLEAN RemoveEventFromSecondaryEventQueue(EVENT* ppEvent, UINT32 uiIndex) { - if (uiIndex < hDelayEventQueue.size()) + if (uiIndex >= hDelayEventQueue.size()) { - *ppEvent = hDelayEventQueue[uiIndex]; - hDelayEventQueue.erase(hDelayEventQueue.begin() + uiIndex); - return(TRUE); + return(FALSE); } - return(FALSE); + *ppEvent = hDelayEventQueue[uiIndex]; + hDelayEventQueue.erase(hDelayEventQueue.begin() + uiIndex); + return(TRUE); } -BOOLEAN PopEvent(EVENT* ppEvent, UINT8 ubQueueID) +static BOOLEAN PopEvent(EVENT* ppEvent, UINT8 ubQueueID) { // Get an event from queue, if one exists // @@ -756,11 +746,10 @@ BOOLEAN PopEvent(EVENT* ppEvent, UINT8 ubQueueID) } -BOOLEAN FreeEvent(EVENT* pEvent) +static BOOLEAN FreeEventData(EVENT* pEvent) { CHECKF(pEvent != NULL); - // Delete event MemFree(pEvent->pData); //MemFree(pEvent); @@ -792,7 +781,7 @@ UINT32 EventQueueSize(UINT8 ubQueueID) } -BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID ) +static BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID ) { UINT32 uiDataSize; @@ -990,7 +979,7 @@ BOOLEAN DequeAllGameEvents( BOOLEAN fExecute ) } // Delete event - FreeEvent( &pEvent ); + FreeEventData( &pEvent ); }; @@ -1021,7 +1010,7 @@ BOOLEAN DequeAllGameEvents( BOOLEAN fExecute ) if (pEventRef.uiFlags & EVENT_EXPIRED) { RemoveEventFromSecondaryEventQueue(&pEventRef, i); - FreeEvent(&pEventRef); + FreeEventData(&pEventRef); } } @@ -1057,7 +1046,7 @@ BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute ) } // Delete event - FreeEvent( &pEvent ); + FreeEventData( &pEvent ); }; @@ -1397,7 +1386,7 @@ BOOLEAN ClearEventQueue( void ) { return( FALSE ); } - FreeEvent(&pEvent); + FreeEventData(&pEvent); } return( TRUE );