mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
Fix for 1% chance to hit target when distance is > 52
Camo and other effects are taken into account when aiming at a body part Max Distance Visible is more consistent in being calculated based on the soldier and direction rather than a fixed number git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1239 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+57
-50
@@ -1077,12 +1077,24 @@ INT16 DistanceSmellable( SOLDIERTYPE *pSoldier, SOLDIERTYPE * pSubject )
|
||||
return( sDistVisible );
|
||||
}
|
||||
|
||||
INT16 MaxDistanceVisible( void )
|
||||
INT16 MaxNormalDistanceVisible( void )
|
||||
{
|
||||
return( STRAIGHT * 2 );
|
||||
}
|
||||
|
||||
INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, INT16 sSubjectGridNo, INT8 bLevel, SOLDIERTYPE *pOther )
|
||||
INT16 SOLDIERTYPE::GetMaxDistanceVisible(INT16 sGridNo, INT8 bLevel)
|
||||
{
|
||||
if (sGridNo == -1) {
|
||||
return MaxNormalDistanceVisible();
|
||||
}
|
||||
if (bLevel == -1) {
|
||||
bLevel = this->bLevel;
|
||||
}
|
||||
|
||||
return DistanceVisible( this, (SoldierHasLimitedVision(this) ? this->bDesiredDirection : DIRECTION_IRRELEVANT), DIRECTION_IRRELEVANT, sGridNo, bLevel );
|
||||
}
|
||||
|
||||
INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, INT16 sSubjectGridNo, INT8 bLevel )
|
||||
{
|
||||
INT16 sDistVisible;
|
||||
INT8 bLightLevel;
|
||||
@@ -1116,7 +1128,7 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir,
|
||||
|
||||
if ( !TANK( pSoldier ) && ( bFacingDir == DIRECTION_IRRELEVANT || (pSoldier->uiStatusFlags & SOLDIER_ROBOT) || (pSubject && pSubject->fMuzzleFlash) ) )
|
||||
{
|
||||
sDistVisible = MaxDistanceVisible();
|
||||
sDistVisible = MaxNormalDistanceVisible();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1124,7 +1136,7 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir,
|
||||
if (pSoldier->sGridNo == sSubjectGridNo)
|
||||
{
|
||||
// looking up or down or two people accidentally in same tile... don't want it to be 0!
|
||||
sDistVisible = MaxDistanceVisible();
|
||||
sDistVisible = MaxNormalDistanceVisible();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1133,6 +1145,9 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir,
|
||||
{
|
||||
bSubjectDir = (INT8) GetDirectionToGridNoFromGridNo( pSoldier->sGridNo, sSubjectGridNo );
|
||||
}
|
||||
if (bFacingDir == DIRECTION_IRRELEVANT) {
|
||||
bFacingDir = pSoldier->bDirection;
|
||||
}
|
||||
|
||||
sDistVisible = gbLookDistance[bFacingDir][bSubjectDir];
|
||||
|
||||
@@ -1165,8 +1180,7 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir,
|
||||
if ( gbLookDistance[bFacingDir][bSubjectDir] != STRAIGHT )
|
||||
{
|
||||
// reduce sight when we're not looking in that direction...
|
||||
// (20%?)
|
||||
sDistVisible = (sDistVisible * 8) / 10;
|
||||
sDistVisible = (INT16) (sDistVisible * ANGLE_RATIO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1186,16 +1200,8 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir,
|
||||
// valid map references then use the ambient light level instead.
|
||||
if(0 > sSubjectGridNo || sSubjectGridNo > WORLD_MAX)
|
||||
{
|
||||
if(pSoldier != pOther)
|
||||
{
|
||||
DebugMsg(TOPIC_JA2,DBG_LEVEL_3,String("113/UC Warning! Tried to detect the light level when character %ls[%d] at gridno %d tries to look for character %ls[%d] who outside of the valid map (gridno %d). Assigning default %d",
|
||||
pSoldier->name, pSoldier->ubID, pSoldier->sGridNo, pOther->name, pOther->ubID, pOther->sGridNo, ubAmbientLightLevel));
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("113/UC Warning! Tried to detect the light level when character %ls[%d] looks at a location outside of the valid map (gridno %d). Assigning default %d",
|
||||
pSoldier->name, pSoldier->ubID, pSoldier->sGridNo, ubAmbientLightLevel));
|
||||
}
|
||||
DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("113/UC Warning! Tried to detect the light level when character %ls[%d] looks at a location outside of the valid map (gridno %d). Assigning default %d",
|
||||
pSoldier->name, pSoldier->ubID, pSoldier->sGridNo, ubAmbientLightLevel));
|
||||
|
||||
bLightLevel = ubAmbientLightLevel;
|
||||
}
|
||||
@@ -1242,7 +1248,13 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir,
|
||||
// let tanks see and be seen further (at night)
|
||||
if ( (TANK( pSoldier ) && sDistVisible > 0) || (pSubject && TANK( pSubject ) ) )
|
||||
{
|
||||
sDistVisible = __max( sDistVisible + 5, MaxDistanceVisible() );
|
||||
if ( TANK(pSoldier) && sDistVisible > 0 && pSubject)
|
||||
{
|
||||
sDistVisible = __max( sDistVisible + 5, pSubject->GetMaxDistanceVisible(pSoldier->sGridNo, pSoldier->bLevel) );
|
||||
}
|
||||
else {
|
||||
sDistVisible = __max( sDistVisible + 5, pSoldier->GetMaxDistanceVisible() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( gpWorldLevelData[ pSoldier->sGridNo ].ubExtFlags[ bLevel ] & (MAPELEMENT_EXT_TEARGAS | MAPELEMENT_EXT_MUSTARDGAS) )
|
||||
@@ -1293,7 +1305,7 @@ void EndMuzzleFlash( SOLDIERTYPE * pSoldier )
|
||||
{
|
||||
if ( pOtherSoldier->sGridNo != NOWHERE )
|
||||
{
|
||||
if ( PythSpacesAway( pOtherSoldier->sGridNo, pSoldier->sGridNo ) > DistanceVisible( pOtherSoldier, (SoldierHasLimitedVision(pSoldier) ? pOtherSoldier->bDesiredDirection : DIRECTION_IRRELEVANT), DIRECTION_IRRELEVANT, pSoldier->sGridNo, pSoldier->bLevel, pSoldier ) )
|
||||
if ( PythSpacesAway( pOtherSoldier->sGridNo, pSoldier->sGridNo ) > DistanceVisible( pOtherSoldier, (SoldierHasLimitedVision(pSoldier) ? pOtherSoldier->bDesiredDirection : DIRECTION_IRRELEVANT), DIRECTION_IRRELEVANT, pSoldier->sGridNo, pSoldier->bLevel ) )
|
||||
{
|
||||
// if this guy can no longer see us, change to seen this turn
|
||||
HandleManNoLongerSeen( pOtherSoldier, pSoldier, &(pOtherSoldier->bOppList[ pSoldier->ubID ]), &(gbPublicOpplist[ pOtherSoldier->bTeam ][ pSoldier->ubID ] ) );
|
||||
@@ -1832,7 +1844,7 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall
|
||||
bAware = TRUE;
|
||||
|
||||
// then we look for him full viewing distance in EVERY direction
|
||||
sDistVisible = DistanceVisible(pSoldier, (SoldierHasLimitedVision(pSoldier) ? pSoldier->bDesiredDirection : DIRECTION_IRRELEVANT), 0, pOpponent->sGridNo, pOpponent->bLevel, pOpponent );
|
||||
sDistVisible = pSoldier->GetMaxDistanceVisible( pOpponent->sGridNo, pOpponent->bLevel );
|
||||
//if (pSoldier->ubID == 0)
|
||||
//sprintf(gDebugStr,"ALREADY KNOW: ME %d him %d val %d",pSoldier->ubID,pOpponent->ubID,pSoldier->bOppList[pOpponent->ubID]);
|
||||
}
|
||||
@@ -1843,7 +1855,7 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall
|
||||
// BIG NOTE: must use desdir instead of direction, since in a projected
|
||||
// situation, the direction may still be changing if it's one of the first
|
||||
// few animation steps when this guy's turn to do his stepped look comes up
|
||||
sDistVisible = DistanceVisible(pSoldier,pSoldier->bDesiredDirection,bDir, pOpponent->sGridNo, pOpponent->bLevel, pOpponent );
|
||||
sDistVisible = DistanceVisible(pSoldier,pSoldier->bDesiredDirection,bDir, pOpponent->sGridNo, pOpponent->bLevel );
|
||||
//if (pSoldier->ubID == 0)
|
||||
//sprintf(gDebugStr,"dist visible %d: my dir %d to him %d",sDistVisible,pSoldier->bDesiredDirection,bDir);
|
||||
}
|
||||
@@ -1860,7 +1872,7 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall
|
||||
{
|
||||
// and we can trace a line of sight to his x,y coordinates
|
||||
// must use the REAL opplist value here since we may or may not know of him
|
||||
if (SoldierToSoldierLineOfSightTest(pSoldier,pOpponent,(UINT8)sDistVisible,bAware))
|
||||
if (SoldierToSoldierLineOfSightTest(pSoldier,pOpponent,bAware,(UINT8)sDistVisible))
|
||||
{
|
||||
ManSeesMan(pSoldier,pOpponent,pOpponent->sGridNo,pOpponent->bLevel,MANLOOKSFORMAN,ubCaller);
|
||||
bSuccess = TRUE;
|
||||
@@ -5676,15 +5688,15 @@ void HearNoise(SOLDIERTYPE *pSoldier, UINT8 ubNoiseMaker, UINT16 sGridNo, INT8 b
|
||||
fMuzzleFlash = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
sDistVisible = DistanceVisible( pSoldier, (SoldierHasLimitedVision(pSoldier) ? pSoldier->bDesiredDirection : DIRECTION_IRRELEVANT), DIRECTION_IRRELEVANT, sGridNo, bLevel, pSoldier );
|
||||
|
||||
sDistVisible = pSoldier->GetMaxDistanceVisible( sGridNo, bLevel );
|
||||
|
||||
if ( fMuzzleFlash )
|
||||
{
|
||||
// turn flash on again
|
||||
MercPtrs[ ubNoiseMaker ]->fMuzzleFlash = TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (PythSpacesAway(pSoldier->sGridNo,sGridNo) <= sDistVisible )
|
||||
{
|
||||
// just use the XXadjustedXX center of the gridno
|
||||
@@ -5706,7 +5718,7 @@ void HearNoise(SOLDIERTYPE *pSoldier, UINT8 ubNoiseMaker, UINT16 sGridNo, INT8 b
|
||||
// skip LOS check if we had to turn and we're a tank. sorry Mr Tank, no looking out of the sides for you!
|
||||
if ( !( bHadToTurn && TANK( pSoldier ) ) )
|
||||
{
|
||||
if ( SoldierTo3DLocationLineOfSightTest( pSoldier, sGridNo, bLevel, 0, (UINT8) sDistVisible, TRUE ) )
|
||||
if ( SoldierTo3DLocationLineOfSightTest( pSoldier, sGridNo, bLevel, 0, TRUE, sDistVisible ) )
|
||||
{
|
||||
// he can actually see the spot where the noise came from!
|
||||
bSourceSeen = TRUE;
|
||||
@@ -6485,7 +6497,6 @@ void RecalculateOppCntsDueToBecomingNeutral( SOLDIERTYPE * pSoldier )
|
||||
void NoticeUnseenAttacker( SOLDIERTYPE * pAttacker, SOLDIERTYPE * pDefender, INT8 bReason )
|
||||
{
|
||||
INT8 bOldOppList;
|
||||
UINT8 ubTileSightLimit;
|
||||
BOOLEAN fSeesAttacker = FALSE;
|
||||
INT8 bDirection;
|
||||
BOOLEAN fMuzzleFlash = FALSE;
|
||||
@@ -6512,30 +6523,26 @@ void NoticeUnseenAttacker( SOLDIERTYPE * pAttacker, SOLDIERTYPE * pDefender, INT
|
||||
}
|
||||
|
||||
bOldOppList = pDefender->bOppList[ pAttacker->ubID ];
|
||||
if ( PythSpacesAway( pAttacker->sGridNo, pDefender->sGridNo ) <= MaxDistanceVisible() )
|
||||
// check LOS, considering we are now aware of the attacker
|
||||
// ignore muzzle flashes when must turning head
|
||||
if ( pAttacker->fMuzzleFlash )
|
||||
{
|
||||
// check LOS, considering we are now aware of the attacker
|
||||
// ignore muzzle flashes when must turning head
|
||||
if ( pAttacker->fMuzzleFlash )
|
||||
bDirection = atan8( pDefender->sX,pDefender->sY, pAttacker->sX, pAttacker->sY );
|
||||
if ( pDefender->bDirection != bDirection && pDefender->bDirection != gOneCDirection[ bDirection ] && pDefender->bDirection != gOneCCDirection[ bDirection ] )
|
||||
{
|
||||
bDirection = atan8( pDefender->sX,pDefender->sY, pAttacker->sX, pAttacker->sY );
|
||||
if ( pDefender->bDirection != bDirection && pDefender->bDirection != gOneCDirection[ bDirection ] && pDefender->bDirection != gOneCCDirection[ bDirection ] )
|
||||
{
|
||||
// temporarily turn off muzzle flash so DistanceVisible can be calculated without it
|
||||
pAttacker->fMuzzleFlash = FALSE;
|
||||
fMuzzleFlash = TRUE;
|
||||
}
|
||||
// temporarily turn off muzzle flash so DistanceVisible can be calculated without it
|
||||
pAttacker->fMuzzleFlash = FALSE;
|
||||
fMuzzleFlash = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
ubTileSightLimit = (UINT8) DistanceVisible( pDefender, (SoldierHasLimitedVision(pDefender) ? pDefender->bDesiredDirection : DIRECTION_IRRELEVANT), 0, pAttacker->sGridNo, pAttacker->bLevel, pAttacker );
|
||||
if (SoldierToSoldierLineOfSightTest( pDefender, pAttacker, ubTileSightLimit, TRUE ) != 0)
|
||||
{
|
||||
fSeesAttacker = TRUE;
|
||||
}
|
||||
if ( fMuzzleFlash )
|
||||
{
|
||||
pAttacker->fMuzzleFlash = TRUE;
|
||||
}
|
||||
if (SoldierToSoldierLineOfSightTest( pDefender, pAttacker, TRUE ) != 0)
|
||||
{
|
||||
fSeesAttacker = TRUE;
|
||||
}
|
||||
if ( fMuzzleFlash )
|
||||
{
|
||||
pAttacker->fMuzzleFlash = TRUE;
|
||||
}
|
||||
|
||||
if (fSeesAttacker)
|
||||
@@ -6646,7 +6653,7 @@ void CheckForAlertWhenEnemyDies( SOLDIERTYPE * pDyingSoldier )
|
||||
|
||||
// distance we "see" then depends on the direction he is located from us
|
||||
bDir = atan8(pSoldier->sX,pSoldier->sY,pDyingSoldier->sX,pDyingSoldier->sY);
|
||||
sDistVisible = DistanceVisible( pSoldier, pSoldier->bDesiredDirection, bDir, pDyingSoldier->sGridNo, pDyingSoldier->bLevel, pDyingSoldier );
|
||||
sDistVisible = DistanceVisible( pSoldier, pSoldier->bDesiredDirection, bDir, pDyingSoldier->sGridNo, pDyingSoldier->bLevel );
|
||||
sDistAway = PythSpacesAway( pSoldier->sGridNo, pDyingSoldier->sGridNo );
|
||||
|
||||
// if we see close enough to see the soldier
|
||||
@@ -6654,7 +6661,7 @@ void CheckForAlertWhenEnemyDies( SOLDIERTYPE * pDyingSoldier )
|
||||
{
|
||||
// and we can trace a line of sight to his x,y coordinates
|
||||
// assume enemies are always aware of their buddies...
|
||||
if ( SoldierTo3DLocationLineOfSightTest( pSoldier, pDyingSoldier->sGridNo, pDyingSoldier->bLevel, 0, (UINT8) sDistVisible, TRUE ) )
|
||||
if ( SoldierTo3DLocationLineOfSightTest( pSoldier, pDyingSoldier->sGridNo, pDyingSoldier->bLevel, 0, TRUE, sDistVisible ) )
|
||||
{
|
||||
pSoldier->bAlertStatus = STATUS_RED;
|
||||
CheckForChangingOrders( pSoldier );
|
||||
@@ -6787,9 +6794,9 @@ INT8 GetHighestVisibleWatchedLoc( UINT8 ubID )
|
||||
{
|
||||
if ( gsWatchedLoc[ ubID ][ bLoop ] != NOWHERE && gubWatchedLocPoints[ ubID ][ bLoop ] > bHighestPoints )
|
||||
{
|
||||
sDistVisible = DistanceVisible( MercPtrs[ ubID ], (SoldierHasLimitedVision(MercPtrs[ ubID ]) ? MercPtrs[ ubID ]->bDesiredDirection : DIRECTION_IRRELEVANT), DIRECTION_IRRELEVANT, gsWatchedLoc[ ubID ][ bLoop ], gbWatchedLocLevel[ ubID ][ bLoop ], MercPtrs[ubID] );
|
||||
sDistVisible = DistanceVisible( MercPtrs[ ubID ], (SoldierHasLimitedVision(MercPtrs[ ubID ]) ? MercPtrs[ ubID ]->bDesiredDirection : DIRECTION_IRRELEVANT), DIRECTION_IRRELEVANT, gsWatchedLoc[ ubID ][ bLoop ], gbWatchedLocLevel[ ubID ][ bLoop ] );
|
||||
// look at standing height
|
||||
if ( SoldierTo3DLocationLineOfSightTest( MercPtrs[ ubID ], gsWatchedLoc[ ubID ][ bLoop ], gbWatchedLocLevel[ ubID ][ bLoop ], 3, (UINT8) sDistVisible, TRUE ) )
|
||||
if ( SoldierTo3DLocationLineOfSightTest( MercPtrs[ ubID ], gsWatchedLoc[ ubID ][ bLoop ], gbWatchedLocLevel[ ubID ][ bLoop ], 3, TRUE, sDistVisible ) )
|
||||
{
|
||||
bHighestLoc = bLoop;
|
||||
bHighestPoints = gubWatchedLocPoints[ ubID ][ bLoop ];
|
||||
|
||||
Reference in New Issue
Block a user