src/game/Tactical/Soldier_Control.cc
static INT8 MultiTiledTurnDirection(SOLDIERTYPE* pSoldier, INT8 bStartDirection, INT8 bDesiredDirection)
{
	INT8 bTurningIncrement;
	INT8 bCurrentDirection;
	INT8 bLoop;
	UINT16 usStructureID, usAnimSurface;
	BOOLEAN fOk = FALSE;

	// start by trying to turn in quickest direction
	bTurningIncrement = (INT8) QuickestDirection( bStartDirection, bDesiredDirection );

	usAnimSurface = DetermineSoldierAnimationSurface( pSoldier, pSoldier->usUIMovementMode );

	const STRUCTURE_FILE_REF* const pStructureFileRef = GetAnimationStructureRef(pSoldier, usAnimSurface, pSoldier->usUIMovementMode);
	if ( !pStructureFileRef )
	{
		// without structure data, well, assume quickest direction
		return( bTurningIncrement );
	}

	// ATE: Only if we have a levelnode...
	if ( pSoldier->pLevelNode != NULL && pSoldier->pLevelNode->pStructureData != NULL )
	{
		usStructureID = pSoldier->pLevelNode->pStructureData->usStructureID;
	}
	else
	{
		usStructureID = INVALID_STRUCTURE_ID;
	}

	bLoop = 0;
	bCurrentDirection = bStartDirection;

	while( bLoop < 2 )
	{
		while( bCurrentDirection != bDesiredDirection )
		{
			bCurrentDirection += bTurningIncrement;

			// did we wrap directions?
			if ( bCurrentDirection < 0 )
			{
				bCurrentDirection = (MAXDIR - 1);
			}
			else if ( bCurrentDirection >= MAXDIR )
			{
				bCurrentDirection = 0;
			}

			// check to see if we can add creature in that direction
			fOk = OkayToAddStructureToWorld(pSoldier->sGridNo, pSoldier->bLevel, &pStructureFileRef->pDBStructureRef[OneCDirection(bCurrentDirection)], usStructureID);
			if (!fOk)
			{
				break;
			}
		}

		if ( (bCurrentDirection == bDesiredDirection) && fOk )
		{
			// success!!
			return( bTurningIncrement );
		}

		bLoop++;
		if ( bLoop < 2 )
		{
			// change direction of loop etc
			bCurrentDirection = bStartDirection;
			bTurningIncrement *= -1;
		}
	}
	// nothing found... doesn't matter much what we return
	return( bTurningIncrement );
}
// function to determine which direction a creature can turn in
function to determine which direction a creature can turn in
function to determine which direction a creature can turn in
static INT8 MultiTiledTurnDirection(SOLDIERTYPE* pSoldier, INT8 bStartDirection, INT8 bDesiredDirection)
{
	INT8 bTurningIncrement;
	INT8 bCurrentDirection;
	INT8 bLoop;
	UINT16 usStructureID, usAnimSurface;
	BOOLEAN fOk = FALSE;
	bTurningIncrement = (INT8) QuickestDirection( bStartDirection, bDesiredDirection );
	usAnimSurface = DetermineSoldierAnimationSurface( pSoldier, pSoldier->usUIMovementMode );
	const STRUCTURE_FILE_REF* const pStructureFileRef = GetAnimationStructureRef(pSoldier, usAnimSurface, pSoldier->usUIMovementMode);
	if ( !pStructureFileRef )
	{
		return( bTurningIncrement );
	}
	if ( pSoldier->pLevelNode != NULL && pSoldier->pLevelNode->pStructureData != NULL )
	{
		usStructureID = pSoldier->pLevelNode->pStructureData->usStructureID;
	}
	else
	{
		usStructureID = INVALID_STRUCTURE_ID;
	}
	bLoop = 0;
	bCurrentDirection = bStartDirection;
	while( bLoop < 2 )
	{
		while( bCurrentDirection != bDesiredDirection )
		{
			bCurrentDirection += bTurningIncrement;
			if ( bCurrentDirection < 0 )
			{
				bCurrentDirection = (MAXDIR - 1);
			}
			else if ( bCurrentDirection >= MAXDIR )
			{
				bCurrentDirection = 0;
			}
			fOk = OkayToAddStructureToWorld(pSoldier->sGridNo, pSoldier->bLevel, &pStructureFileRef->pDBStructureRef[OneCDirection(bCurrentDirection)], usStructureID);
			if (!fOk)
			{
				break;
			}
		}
		if ( (bCurrentDirection == bDesiredDirection) && fOk )
		{
			return( bTurningIncrement );
		}
		bLoop++;
		if ( bLoop < 2 )
		{
			bCurrentDirection = bStartDirection;
			bTurningIncrement *= -1;
		}
	}
	return( bTurningIncrement );
}
static INT8 MultiTiledTurnDirection ( SOLDIERTYPE * pSoldier , INT8 bStartDirection , INT8 bDesiredDirection ) { INT8 bTurningIncrement ; INT8 bCurrentDirection ; INT8 bLoop ; UINT16 usStructureID , usAnimSurface ; BOOLEAN fOk = FALSE ; bTurningIncrement = ( INT8 ) QuickestDirection ( bStartDirection , bDesiredDirection ) ; usAnimSurface = DetermineSoldierAnimationSurface ( pSoldier , pSoldier -> usUIMovementMode ) ; const STRUCTURE_FILE_REF * const pStructureFileRef = GetAnimationStructureRef ( pSoldier , usAnimSurface , pSoldier -> usUIMovementMode ) ; if ( ! pStructureFileRef ) { return ( bTurningIncrement ) ; } if ( pSoldier -> pLevelNode != NULL && pSoldier -> pLevelNode -> pStructureData != NULL ) { usStructureID = pSoldier -> pLevelNode -> pStructureData -> usStructureID ; } else { usStructureID = INVALID_STRUCTURE_ID ; } bLoop = 0 ; bCurrentDirection = bStartDirection ; while ( bLoop < 2 ) { while ( bCurrentDirection != bDesiredDirection ) { bCurrentDirection += bTurningIncrement ; if ( bCurrentDirection < 0 ) { bCurrentDirection = ( MAXDIR - 1 ) ; } else if ( bCurrentDirection >= MAXDIR ) { bCurrentDirection = 0 ; } fOk = OkayToAddStructureToWorld ( pSoldier -> sGridNo , pSoldier -> bLevel , & pStructureFileRef -> pDBStructureRef [ OneCDirection ( bCurrentDirection ) ] , usStructureID ) ; if ( ! fOk ) { break ; } } if ( ( bCurrentDirection == bDesiredDirection ) && fOk ) { return ( bTurningIncrement ) ; } bLoop ++ ; if ( bLoop < 2 ) { bCurrentDirection = bStartDirection ; bTurningIncrement *= -1 ; } } return ( bTurningIncrement ) ; }
function to determine which direction a creature can turn in
function to determine which direction a creature can turn in
// start by trying to turn in quickest direction // without structure data, well, assume quickest direction // ATE: Only if we have a levelnode... // did we wrap directions? // check to see if we can add creature in that direction // success!! // change direction of loop etc // nothing found... doesn't matter much what we return