Fixed crash when the cheat command to teleport on mapscreen assigned previous sector into sector from which the destination cannot be entered.

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9272 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Shadooow
2022-01-22 20:08:37 +00:00
parent 9668618b68
commit 24775ee398
+46 -28
View File
@@ -8234,13 +8234,29 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent )
if ( ( GetSelectedDestChar() != -1) && !fPlotForHelicopter && !fPlotForMilitia && (iCurrentMapSectorZ == 0) && (GetMouseMapXY( &sMapX, &sMapY )) ) if ( ( GetSelectedDestChar() != -1) && !fPlotForHelicopter && !fPlotForMilitia && (iCurrentMapSectorZ == 0) && (GetMouseMapXY( &sMapX, &sMapY )) )
{ {
INT16 sDeltaX, sDeltaY; INT16 sDeltaX, sDeltaY;
INT16 sPrevX, sPrevY; INT16 sPrevX = 0, sPrevY = 0;
SOLDIERTYPE *pSoldier = MercPtrs[ gCharactersList[GetSelectedDestChar()].usSolID ]; SOLDIERTYPE *pSoldier = MercPtrs[ gCharactersList[GetSelectedDestChar()].usSolID ];
// can't teleport to where we already are // can't teleport to where we already are
if ( ( sMapX == pSoldier->sSectorX ) && ( sMapY == pSoldier->sSectorY ) ) if ( ( sMapX == pSoldier->sSectorX ) && ( sMapY == pSoldier->sSectorY ) )
break; break;
// figure out where they would've come from
if (pTempCharacterPath)
{
pTempCharacterPath = MoveToEndOfPathList(pTempCharacterPath);
UINT32 sSectorId = pTempCharacterPath->pPrev->uiSectorId;
sPrevX = GET_X_FROM_STRATEGIC_INDEX(sSectorId);
sPrevY = GET_Y_FROM_STRATEGIC_INDEX(sSectorId);
}
else if (pTempHelicopterPath)
{
pTempHelicopterPath = MoveToEndOfPathList(pTempHelicopterPath);
UINT32 sSectorId = pTempHelicopterPath->pPrev->uiSectorId;
sPrevX = GET_X_FROM_STRATEGIC_INDEX(sSectorId);
sPrevY = GET_Y_FROM_STRATEGIC_INDEX(sSectorId);
}
// cancel movement plotting // cancel movement plotting
AbortMovementPlottingMode( ); AbortMovementPlottingMode( );
@@ -8261,40 +8277,42 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent )
AddPlayerToGroup( ubGroupId, pSoldier ); AddPlayerToGroup( ubGroupId, pSoldier );
} }
// figure out where they would've come from //shadooow: this should now only happen when teleporting into inaccessible sectors
sDeltaX = sMapX - pSoldier->sSectorX; if (!sPrevX || !sPrevY)
sDeltaY = sMapY - pSoldier->sSectorY; {
// figure out where they would've come from
sDeltaX = sMapX - pSoldier->sSectorX;
sDeltaY = sMapY - pSoldier->sSectorY;
if ( abs( sDeltaX ) >= abs( sDeltaY ) ) if ( abs( sDeltaX ) >= abs( sDeltaY ) )
{
// use East or West
if( sDeltaX > 0 )
{ {
// came in from the West // use East or West
sPrevX = sMapX - 1; if( sDeltaX > 0 )
{
// came in from the West
sPrevX = sMapX - 1;
}
else
{
// came in from the East
sPrevX = sMapX + 1;
}
sPrevY = sMapY; sPrevY = sMapY;
} }
else else
{ {
// came in from the East // use North or South
sPrevX = sMapX + 1; if( sDeltaY > 0 )
sPrevY = sMapY; {
} // came in from the North
} sPrevY = sMapY - 1;
else }
{ else
// use North or South {
if( sDeltaY > 0 ) // came in from the South
{ sPrevY = sMapY + 1;
// came in from the North }
sPrevX = sMapX; sPrevX = sMapX;
sPrevY = sMapY - 1;
}
else
{
// came in from the South
sPrevX = sMapX;
sPrevY = sMapY + 1;
} }
} }