Render debug info in tactical

Functionality for rendering pathfinding and cover values in tactical was behind defunct #ifdefs.
It's now compiled always, but only enabled if cheat level is BEDUG_CHEAT_LEVEL.
Unified rendering the debug info into one function, instead of several nearly identical ones.
Ctrl + Shift + Z cycles through the different debug modes.

Now it should be fairly easy to add more info modes like these two in the future.
This commit is contained in:
Asdow
2024-02-21 23:24:14 +02:00
parent ab2c5fc10d
commit de91c7a9fd
9 changed files with 301 additions and 322 deletions
+51 -2
View File
@@ -87,7 +87,7 @@
#include "SaveLoadScreen.h"
#include "Map Screen Interface.h" // added by Flugente for SquadNames
#include "Keys.h" // added by silversurfer for door handling from the side
#include "Cheats.h"
#include "AIInternals.h"
extern BOOLEAN gubWorldTileInLight[MAX_ALLOWED_WORLD_MAX];
extern BOOLEAN gubIsCorpseThere[MAX_ALLOWED_WORLD_MAX];
@@ -386,7 +386,7 @@ BOOLEAN gfDisplayTimerCursor = FALSE;
UINT32 guiTimerCursorID = 0;
UINT32 guiTimerLastUpdate = 0;
UINT32 guiTimerCursorDelay = 0;
UINT8 gRenderDebugInfoMode = DEBUG_OFF;
CHAR16 gzLocation[ 20 ];
BOOLEAN gfLocation = FALSE;
@@ -518,6 +518,54 @@ void GetMercOknoDirection( UINT8 ubSoldierID, BOOLEAN *pfGoDown, BOOLEAN *pfGoUp
}
//----------------------------------------------------------------------------------
void HandleRenderDebugInfoModes()
{
if (DEBUG_CHEAT_LEVEL())
{
switch (gRenderDebugInfoMode)
{
case DEBUG_PATHFINDING:
// Nothing to do here, pathfinding info is filled in the pathing functions.
break;
case DEBUG_THREATVALUE:
break;
case DEBUG_COVERVALUE:
// Calculate cover values for pSoldier under cursor, or for currently selected merc, if nobody is under the cursor.
if (gTacticalStatus.Team[OUR_TEAM].bTeamActive)
{
static SOLDIERTYPE* previousSoldier = nullptr;
static INT32 previousLocation = NOWHERE;
static UINT8 previousStance = 0;
UINT16 usSoldierIndex = NOBODY;
UINT32 uiMercFlags;
FindSoldierFromMouse(&usSoldierIndex, &uiMercFlags);
if (usSoldierIndex == NOBODY)
{
usSoldierIndex = gusSelectedSoldier;
}
if (usSoldierIndex != NOBODY)
{
// Get Soldier
INT32 iPercentBetter;
SOLDIERTYPE* pSoldier;
GetSoldier(&pSoldier, usSoldierIndex);
if (previousSoldier != pSoldier || previousLocation != pSoldier->sGridNo || previousStance != gAnimControl[pSoldier->usAnimState].ubEndHeight)
{
FindBestNearbyCover(pSoldier, pSoldier->aiData.bAIMorale, &iPercentBetter);
previousSoldier = pSoldier;
previousLocation = pSoldier->sGridNo;
previousStance = gAnimControl[pSoldier->usAnimState].ubEndHeight;
}
}
}
break;
default: // off
break;
}
}
}
void PreventFromTheFreezingBug(SOLDIERTYPE* pSoldier)
{
@@ -691,6 +739,7 @@ UINT32 HandleTacticalUI( void )
}
}
HandleRenderDebugInfoModes();
// Check if current event has changed and clear event if so, to prepare it for execution
// Clearing it does things like set first time flag, param variables, etc
if ( uiNewEvent != guiOldEvent )
+3 -1
View File
@@ -296,6 +296,8 @@ extern BOOLEAN gfUIForceReExamineCursorData;
extern INT16 guiCreateGuyIndex;
extern INT16 guiCreateBadGuyIndex;
extern UINT8 gRenderDebugInfoMode;
// WANNE: Calculate the APs to turn around
INT16 APsToTurnAround(SOLDIERTYPE *pSoldier, INT32 sAdjustedGridNo);
@@ -382,4 +384,4 @@ void GetGridNoScreenXY( INT32 sGridNo, INT16 *pScreenX, INT16 *pScreenY );
//Legion by Jazz
void GetMercOknoDirection( UINT8 ubSoldierID, BOOLEAN *pfGoDown, BOOLEAN *pfGoUp );
#endif
#endif
+34 -101
View File
@@ -25,7 +25,7 @@
#include "english.h"
#include "worlddef.h"
#include "worldman.h"
// #include "renderworld.h"
#include "renderworld.h"
#include "pathai.h"
#include "Points.h"
#include "ai.h"
@@ -41,7 +41,7 @@
#include "Rotting Corpses.h"
#include "Meanwhile.h"
#include "connect.h"
#include <Cheats.h>
#include "LOS.h" //ddd
//forward declarations of common classes to eliminate includes
@@ -66,19 +66,8 @@ extern BOOLEAN InGasSpot(SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel);
// skiplist has extra level of pointers every 4 elements, so a level 5is optimized for
// 4 to the power of 5 elements, or 2 to the power of 10, 1024
//#define PATHAI_VISIBLE_DEBUG
//#define PATHAI_SKIPLIST_DEBUG
#ifdef PATHAI_VISIBLE_DEBUG
#include "video.h"
//extern INT16 gsCoverValue[WORLD_MAX];
extern INT16 * gsCoverValue;
BOOLEAN gfDisplayCoverValues = TRUE;
BOOLEAN gfDrawPathPoints = TRUE;
#endif
BOOLEAN gfPlotPathToExitGrid = FALSE;
BOOLEAN gfRecalculatingExistingPathCost = FALSE;
UINT8 gubGlobalPathFlags = 0;
@@ -623,15 +612,12 @@ int AStarPathfinder::GetPath(SOLDIERTYPE *s ,
}
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
memset( gsCoverValue, 0x7F, sizeof( INT16 ) * WORLD_MAX );
ResetDebugInfoValues();
gRenderDebugInfoValues[ StartNode ] = 0;
PATHAI_VISIBLE_DEBUG_Counter = 1;
}
gsCoverValue[ StartNode ] = 0;
PATHAI_VISIBLE_DEBUG_Counter = 1;
#endif
//init other private data, mostly flags
endDir = lastDir = direction = startDir = 0;
@@ -796,12 +782,10 @@ int AStarPathfinder::GetPath(SOLDIERTYPE *s ,
return 0;
}
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
SetRenderFlags( RENDER_FLAG_FULL );
}
#endif
// Count the number of steps, but keep it less than the max path length.
// Adjust the parent until it begins at the tail end of the max path length (or the dest if reachable)
@@ -884,12 +868,10 @@ int AStarPathfinder::GetPath(SOLDIERTYPE *s ,
sizePath = giPathDataSize;
}
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
SetRenderFlags( RENDER_FLAG_FULL );
}
#endif
#ifdef COUNT_PATHS
guiSuccessfulPathChecks++;
@@ -1001,15 +983,13 @@ void AStarPathfinder::ExecuteAStarLogic()
SetAStarStatus(ParentNode, AStar_Closed);
//ClosedList.push_back(ParentNode);
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
if (gsCoverValue[ ParentNode ] > 0)
if (gRenderDebugInfoValues[ParentNode] > 0)
{
gsCoverValue[ ParentNode ] *= -1;
gRenderDebugInfoValues[ParentNode] *= -1;
}
}
#endif
// Shouldn't G and AP be the same thing?
INT16 baseGCost = GetAStarG(ParentNode);
@@ -1092,7 +1072,7 @@ void AStarPathfinder::ExecuteAStarLogic()
gpWorldLevelData[ CurrentNode ].ubExtFlags[0] |= MAPELEMENT_EXT_CLIMBPOINT;
gpWorldLevelData[ ParentNode ].ubExtFlags[1] |= MAPELEMENT_EXT_CLIMBPOINT;
#ifdef ROOF_DEBUG
gsCoverValue[CurrentNode] = 1;
gRenderDebugInfoValues[CurrentNode] = 1;
#endif
}
@@ -1190,26 +1170,13 @@ void AStarPathfinder::ExecuteAStarLogic()
int AStarH = CalcH();
int AStarF = (AStarG + extraGCoverCost) + AStarH;
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
if (gsCoverValue[CurrentNode] == 0x7F7F)
if (gRenderDebugInfoValues[CurrentNode] == 0x7FFFFFFF)
{
//gsCoverValue[CurrentNode] = PATHAI_VISIBLE_DEBUG_Counter++;
gsCoverValue[CurrentNode] = (INT16) AStarF;
gRenderDebugInfoValues[CurrentNode] = (INT16) AStarF;
}
/*
else if (gsCoverValue[CurrentNodeIndex] >= 0)
{
gsCoverValue[CurrentNodeIndex]++;
}
else
{
gsCoverValue[CurrentNodeIndex]--;
}
*/
}
#endif
//insert this node onto the heap
if (GetAStarStatus(CurrentNode) == AStar_Init)
@@ -2260,9 +2227,7 @@ INT32 FindBestPath(SOLDIERTYPE *s , INT32 sDestination, INT8 bLevel, INT16 usMov
CHAR8 zTempString[1000], zTS[50];
#endif
#ifdef PATHAI_VISIBLE_DEBUG
UINT16 usCounter = 0;
#endif
fVehicle = FALSE;
iOriginationX = iOriginationY = 0;
@@ -2512,12 +2477,10 @@ if(!GridNoOnVisibleWorldTile(iDestination))
memset( pathQ, 0, iMaxPathQ * sizeof( path_t ) );
memset( trailTree, 0, iMaxTrailTree * sizeof( trail_t ) );
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
memset( gsCoverValue, 0x7F, sizeof( INT16 ) * WORLD_MAX );
ResetDebugInfoValues();
}
#endif
bSkipListLevel = 1;
iSkipListSize = 0;
@@ -2629,15 +2592,13 @@ if(!GridNoOnVisibleWorldTile(iDestination))
// remember the cost used to get here...
prevCost = gubWorldMovementCosts[ trailTree[ sCurPathNdx ].sGridNo ][ trailTree[ sCurPathNdx ].stepDir ][ bLevel ];
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
if (gsCoverValue[ curLoc ] > 0)
if (gRenderDebugInfoValues[ curLoc ] > 0)
{
gsCoverValue[ curLoc ] *= -1;
gRenderDebugInfoValues[ curLoc ] *= -1;
}
}
#endif
/*
if (fTurnSlow)
@@ -3563,27 +3524,13 @@ if(!GridNoOnVisibleWorldTile(iDestination))
// costs less than the best so far to the same location?
if (trailCostUsed[newLoc] != gubGlobalPathCount || newTotCost < trailCost[newLoc])
{
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
{
if (gsCoverValue[newLoc] == 0x7F7F)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
if (gRenderDebugInfoValues[newLoc] == 0x7FFFFFFF)
{
gsCoverValue[newLoc] = usCounter++;
gRenderDebugInfoValues[newLoc] = usCounter++;
}
/*
else if (gsCoverValue[newLoc] >= 0)
{
gsCoverValue[newLoc]++;
}
else
{
gsCoverValue[newLoc]--;
}
*/
}
#endif
}
//NEWQUENODE;
{
@@ -3826,20 +3773,13 @@ ENDOFLOOP:
while (pathQNotEmpty && pathNotYetFound);
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
if ( guiCurrentScreen == GAME_SCREEN )
{
SetRenderFlags( RENDER_FLAG_FULL );
if ( guiCurrentScreen == GAME_SCREEN )
{
RenderWorld();
RenderCoverDebug( );
InvalidateScreen( );
EndFrameBufferRender();
RefreshScreen( NULL );
}
InvalidateRegion(gsVIEWPORT_START_X, gsVIEWPORT_START_Y, gsVIEWPORT_END_X, gsVIEWPORT_WINDOW_END_Y);
}
#endif
}
// work finished. Did we find a path?
@@ -3894,17 +3834,10 @@ ENDOFLOOP:
}
#if defined( PATHAI_VISIBLE_DEBUG )
if (gfDisplayCoverValues && gfDrawPathPoints)
{
SetRenderFlags( RENDER_FLAG_FULL );
RenderWorld();
RenderCoverDebug( );
InvalidateScreen( );
EndFrameBufferRender();
RefreshScreen( NULL );
}
#endif
if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL())
{
InvalidateRegion(gsVIEWPORT_START_X, gsVIEWPORT_START_Y, gsVIEWPORT_END_X, gsVIEWPORT_WINDOW_END_Y);
}
// return path length : serves as a "successful" flag and a path length counter
+25
View File
@@ -1700,6 +1700,24 @@ void ItemCreationCallBack( UINT8 ubResult )
memset(gszMsgBoxInputString,0,sizeof(gszMsgBoxInputString));
}
static void CycleThroughTileDebugInfo()
{
const STR16 modeStrings[] =
{
L"Pathfinding",
L"Threat values",
L"Cover values",
L"Off",
};
gRenderDebugInfoMode += 1;
if (gRenderDebugInfoMode > DEBUG_OFF)
{
gRenderDebugInfoMode = 0;
}
ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, modeStrings[gRenderDebugInfoMode]);
}
extern BOOLEAN gfDisableRegionActive;
extern BOOLEAN gfUserTurnRegionActive;
@@ -4763,6 +4781,13 @@ void GetKeyboardInput( UINT32 *puiNewEvent )
break;
case 'Z':
if (fCtrl)
{
if (DEBUG_CHEAT_LEVEL())
{
CycleThroughTileDebugInfo();
}
}
break;
}