Merged revision(s) 6836 from branches/ja2_source_official_2014:

Fix: incorrect gridno calculation

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6837 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Flugente
2014-01-26 22:07:28 +00:00
parent 0c4f5c5df5
commit 461cfc405e
+61 -69
View File
@@ -5042,47 +5042,46 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect
*psAdjustedGridNo = sGridNo; *psAdjustedGridNo = sGridNo;
} }
// Flugente: change condition order // CHECK IF IT'S THE SAME ONE AS WE'RE ON, IF SO, RETURN THAT!
// OK, if we are looking for a door, it may be in the same tile as us, so find the direction we if ( pSoldier->sGridNo == sGridNo && !FindStructure( sGridNo, ( STRUCTURE_SWITCH ) ) )
// have to face to get to the door, not just our initial direction... {
// If we are in the same tile as a switch, we can NEVER pull it.... // OK, if we are looking for a door, it may be in the same tile as us, so find the direction we
if (pubDirection && fDoor ) // have to face to get to the door, not just our initial direction...
{ // If we are in the same tile as a switch, we can NEVER pull it....
// CHECK IF IT'S THE SAME ONE AS WE'RE ON, IF SO, RETURN THAT! if( fDoor && pubDirection )
if ( pSoldier->sGridNo == sGridNo && !FindStructure( sGridNo, ( STRUCTURE_SWITCH ) ) ) {
{ // This can only happen if a door was to the south to east of us!
// This can only happen if a door was to the south to east of us!
// Do south! // Do south!
//sSpot = NewGridNo( sGridNo, DirectionInc( SOUTH ) ); //sSpot = NewGridNo( sGridNo, DirectionInc( SOUTH ) );
// ATE: Added: Switch behave EXACTLY like doors // ATE: Added: Switch behave EXACTLY like doors
pDoor = FindStructure( sGridNo, ( STRUCTURE_ANYDOOR ) ); pDoor = FindStructure( sGridNo, ( STRUCTURE_ANYDOOR ) );
if ( pDoor != NULL ) if ( pDoor != NULL )
{ {
// Get orinetation // Get orinetation
ubWallOrientation = pDoor->ubWallOrientation; ubWallOrientation = pDoor->ubWallOrientation;
if ( ubWallOrientation == OUTSIDE_TOP_LEFT || ubWallOrientation == INSIDE_TOP_LEFT ) if ( ubWallOrientation == OUTSIDE_TOP_LEFT || ubWallOrientation == INSIDE_TOP_LEFT )
{ {
// To the south! // To the south!
sSpot = NewGridNo( sGridNo, DirectionInc( SOUTH ) ); sSpot = NewGridNo( sGridNo, DirectionInc( SOUTH ) );
(*pubDirection) = (UINT8)GetDirectionFromGridNo( sSpot, pSoldier ); (*pubDirection) = (UINT8)GetDirectionFromGridNo( sSpot, pSoldier );
} }
if ( ubWallOrientation == OUTSIDE_TOP_RIGHT || ubWallOrientation == INSIDE_TOP_RIGHT ) if ( ubWallOrientation == OUTSIDE_TOP_RIGHT || ubWallOrientation == INSIDE_TOP_RIGHT )
{ {
// TO the east! // TO the east!
sSpot = NewGridNo( sGridNo, DirectionInc( EAST ) ); sSpot = NewGridNo( sGridNo, DirectionInc( EAST ) );
(*pubDirection) = (UINT8)GetDirectionFromGridNo( sSpot, pSoldier ); (*pubDirection) = (UINT8)GetDirectionFromGridNo( sSpot, pSoldier );
} }
} }
}
// Use soldier's direction // Use soldier's direction
return( sGridNo ); return( sGridNo );
} }
}
// Look for a door! // Look for a door!
if (fDoor) if (fDoor)
@@ -5096,23 +5095,22 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect
if ( fForceToPerson ) if ( fForceToPerson )
{ {
if ( psAdjustedGridNo != NULL ) if ( FindSoldier( sGridNo, &usSoldierIndex, &uiMercFlags, FIND_SOLDIER_GRIDNO ) )
{ {
if ( FindSoldier( sGridNo, &usSoldierIndex, &uiMercFlags, FIND_SOLDIER_GRIDNO ) ) sGridNo = MercPtrs[ usSoldierIndex ]->sGridNo;
{ if ( psAdjustedGridNo != NULL )
sGridNo = MercPtrs[ usSoldierIndex ]->sGridNo; {
*psAdjustedGridNo = sGridNo; *psAdjustedGridNo = sGridNo;
// Use direction to this guy! // Use direction to this guy!
if (pubDirection) if (pubDirection)
{ {
(*pubDirection) = (UINT8)GetDirectionFromGridNo( sGridNo, pSoldier ); (*pubDirection) = (UINT8)GetDirectionFromGridNo( sGridNo, pSoldier );
} }
} }
} }
} }
if ( ( sOkTest = NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->pathing.bLevel ) ) > 0) // no problem going there! nobody on it! if ( ( sOkTest = NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->pathing.bLevel ) ) > 0) // no problem going there! nobody on it!
{ {
// OK, if we are looking to goto a switch, ignore this.... // OK, if we are looking to goto a switch, ignore this....
@@ -5140,13 +5138,13 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect
{ {
if ( sDistance < sClosest ) if ( sDistance < sClosest )
{ {
sClosest = sDistance; sClosest = sDistance;
sCloseGridNo = sGridNo; sCloseGridNo = sGridNo;
} }
} }
} }
} }
for (INT8 cnt = 0; cnt < 4; ++cnt) for (INT8 cnt = 0; cnt < 4; ++cnt)
{ {
// MOVE OUT TWO DIRECTIONS // MOVE OUT TWO DIRECTIONS
@@ -5206,14 +5204,10 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect
// OK, at least get direction to face...... // OK, at least get direction to face......
// Defaults to soldier's facing dir unless we change it! // Defaults to soldier's facing dir unless we change it!
//if ( pDoor != NULL ) // Use direction to the door!
{ if (pubDirection)
// Use direction to the door! (*pubDirection) = (UINT8)GetDirectionFromGridNo( sGridNo, pSoldier );
if (pubDirection)
{
(*pubDirection) = (UINT8)GetDirectionFromGridNo( sGridNo, pSoldier );
}
}
return( sSpot ); return( sSpot );
} }
@@ -5281,7 +5275,7 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect
return( sCloseGridNo ); return( sCloseGridNo );
} }
return( NOWHERE ); return( NOWHERE );
} }
@@ -5333,16 +5327,18 @@ INT32 FindNextToAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pub
pDoor = NULL; pDoor = NULL;
} }
if ( fForceToPerson && psAdjustedGridNo != NULL ) if ( fForceToPerson )
{ {
if ( FindSoldier( sGridNo, &usSoldierIndex, &uiMercFlags, FIND_SOLDIER_GRIDNO ) ) if ( FindSoldier( sGridNo, &usSoldierIndex, &uiMercFlags, FIND_SOLDIER_GRIDNO ) )
{ {
sGridNo = MercPtrs[ usSoldierIndex ]->sGridNo; sGridNo = MercPtrs[ usSoldierIndex ]->sGridNo;
*psAdjustedGridNo = sGridNo; if ( psAdjustedGridNo != NULL )
{
*psAdjustedGridNo = sGridNo;
}
} }
} }
if ( ( sOkTest = NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->pathing.bLevel ) ) > 0) // no problem going there! nobody on it! if ( ( sOkTest = NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->pathing.bLevel ) ) > 0) // no problem going there! nobody on it!
{ {
// OK, if we are looking to goto a switch, ignore this.... // OK, if we are looking to goto a switch, ignore this....
@@ -5370,8 +5366,7 @@ INT32 FindNextToAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pub
} }
} }
for (INT8 cnt = 0; cnt < 4; ++cnt)
for (INT8 cnt = 0; cnt < 4; cnt++)
{ {
// MOVE OUT TWO DIRECTIONS // MOVE OUT TWO DIRECTIONS
sFourGrids[cnt] = sSpot = NewGridNo( sGridNo, DirectionInc( sDirs[ cnt ] ) ); sFourGrids[cnt] = sSpot = NewGridNo( sGridNo, DirectionInc( sDirs[ cnt ] ) );
@@ -5439,9 +5434,8 @@ INT32 FindNextToAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pub
if ( sSpot == pSoldier->sGridNo ) if ( sSpot == pSoldier->sGridNo )
{ {
if (pubDirection) if (pubDirection)
{
(*pubDirection) = (UINT8)GetDirectionFromGridNo( sGridNo, pSoldier ); (*pubDirection) = (UINT8)GetDirectionFromGridNo( sGridNo, pSoldier );
}
//*pubDirection = pSoldier->ubDirection; //*pubDirection = pSoldier->ubDirection;
return( sSpot ); return( sSpot );
} }
@@ -5504,14 +5498,12 @@ INT32 FindNextToAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pub
{ {
return( NOWHERE ); return( NOWHERE );
} }
return( sCloseGridNo ); return( sCloseGridNo );
} }
return( NOWHERE ); return( NOWHERE );
/* /*
if ( !TileIsOutOfBounds(sCloseGridNo)) if ( !TileIsOutOfBounds(sCloseGridNo))
{ {