From a92379ec96c2816bec0bfa19fb1584a8d84ee81a Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Sun, 25 Apr 2021 04:05:45 +0000 Subject: [PATCH] Vision update fixes (by Shadooow): Small fix in TurnSoldier code. I am not sure if this caused anything or not, but unless I missed something, the deleted code will never trigger. So I moved the check for jump up/down animations above if they are even used. Fix for vision not being updated in many situations. This fixes the vision issue captured at above images. The reason it happened was that the code uses hacky approach to change direction when making certain actions like stabbing, punching, giving first aid etc. to make it smoother which then causes code later in the events to not update vision. I only playtested punching, stabbing and knife throwing, but it is obvious that the same issue happens with other activities I altered. I also made the code more efficient - changing direction will only happen when needed. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8972 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Soldier Control.cpp | 125 +++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 51 deletions(-) diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index b531ab80..bfee34df 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -8357,7 +8357,7 @@ void SOLDIERTYPE::TurnSoldier( void ) // We handle sight now.... if ( this->flags.uiStatusFlags & SOLDIER_LOOK_NEXT_TURNSOLDIER ) { - if ( (gAnimControl[this->usAnimState].uiFlags & ANIM_STATIONARY && this->usAnimState != CLIMBUPROOF && this->usAnimState != CLIMBDOWNROOF) ) + if ( (gAnimControl[this->usAnimState].uiFlags & ANIM_STATIONARY && this->usAnimState != CLIMBUPROOF && this->usAnimState != CLIMBDOWNROOF && this->usAnimState != JUMPUPWALL && this->usAnimState != JUMPDOWNWALL) ) { // HANDLE SIGHT! HandleSight( this, SIGHT_LOOK | SIGHT_RADIO ); @@ -8368,20 +8368,6 @@ void SOLDIERTYPE::TurnSoldier( void ) HandleSystemNewAISituation( this, FALSE ); } - if ( this->flags.uiStatusFlags & SOLDIER_LOOK_NEXT_TURNSOLDIER ) - { - if ( (gAnimControl[this->usAnimState].uiFlags & ANIM_STATIONARY && this->usAnimState != JUMPUPWALL && this->usAnimState != JUMPDOWNWALL) ) - { - // HANDLE SIGHT! - HandleSight( this, SIGHT_LOOK | SIGHT_RADIO ); - } - // Turn off! - this->flags.uiStatusFlags &= (~SOLDIER_LOOK_NEXT_TURNSOLDIER); - - HandleSystemNewAISituation( this, FALSE ); - } - - if ( this->flags.fTurningToShoot ) { if ( this->ubDirection == this->pathing.bDesiredDirection ) @@ -12742,13 +12728,17 @@ void SOLDIERTYPE::EVENT_SoldierBeginBladeAttack( INT32 sGridNo, UINT8 ubDirectio // CHANGE DIRECTION AND GOTO ANIMATION NOW //dnl ch73 290913 - if ( this->usAnimState != CRAWLING && gAnimControl[this->usAnimState].ubEndHeight == ANIM_PRONE ) - usForceAnimState = CROUCHING; - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); - if ( this->flags.bTurningFromPronePosition ) - this->flags.bTurningFromPronePosition = TURNING_FROM_PRONE_FOR_PUNCH_OR_STAB; - usForceAnimState = INVALID_ANIMATION; + if (this->ubDirection != ubDirection) + { + if (this->usAnimState != CRAWLING && gAnimControl[this->usAnimState].ubEndHeight == ANIM_PRONE) + usForceAnimState = CROUCHING; + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + if (this->flags.bTurningFromPronePosition) + this->flags.bTurningFromPronePosition = TURNING_FROM_PRONE_FOR_PUNCH_OR_STAB; + usForceAnimState = INVALID_ANIMATION; + } // CHANGE TO ANIMATION // sevenfm: initialize attack data @@ -12949,7 +12939,6 @@ void SOLDIERTYPE::EVENT_SoldierBeginPunchAttack( INT32 sGridNo, UINT8 ubDirectio //UINT32 uiMercFlags; UINT16 usSoldierIndex; UINT8 ubTDirection; - BOOLEAN fChangeDirection = FALSE; UINT16 usItem; // Get item in hand... @@ -12969,16 +12958,12 @@ void SOLDIERTYPE::EVENT_SoldierBeginPunchAttack( INT32 sGridNo, UINT8 ubDirectio //usSoldierIndex = WhoIsThere2( this->sTargetGridNo, this->pathing.bLevel ); usSoldierIndex = WhoIsThere2(sGridNo, this->pathing.bLevel); - if ( usSoldierIndex != NOBODY ) - { - GetSoldier( &pTSoldier, usSoldierIndex ); - - fChangeDirection = TRUE; - } - else + if (usSoldierIndex == NOBODY) { return; } + + GetSoldier( &pTSoldier, usSoldierIndex ); // sevenfm: set flag indicating back attack and sneak attack if (pTSoldier) @@ -13002,14 +12987,15 @@ void SOLDIERTYPE::EVENT_SoldierBeginPunchAttack( INT32 sGridNo, UINT8 ubDirectio } } - if ( fChangeDirection ) + if (this->ubDirection != ubDirection) { // CHANGE DIRECTION AND GOTO ANIMATION NOW //dnl ch73 290913 if ( this->usAnimState != CRAWLING && gAnimControl[this->usAnimState].ubEndHeight == ANIM_PRONE ) usForceAnimState = CROUCHING; - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); if ( this->flags.bTurningFromPronePosition ) this->flags.bTurningFromPronePosition = TURNING_FROM_PRONE_FOR_PUNCH_OR_STAB; usForceAnimState = INVALID_ANIMATION; @@ -13311,8 +13297,13 @@ void SOLDIERTYPE::EVENT_SoldierBeginKnifeThrowAttack( INT32 sGridNo, UINT8 ubDir usForceAnimState = INVALID_ANIMATION; this->flags.fDontUnsetLastTargetFromTurn = TRUE; // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } + usForceAnimState = INVALID_ANIMATION; // SET TARGET GRIDNO @@ -13463,8 +13454,12 @@ void SOLDIERTYPE::EVENT_SoldierBeginFirstAid( INT32 sGridNo, UINT8 ubDirection ) fInProne = TRUE; } // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } // CHANGE TO ANIMATION if ( fInProne ) @@ -22262,8 +22257,12 @@ void SOLDIERTYPE::EVENT_SoldierBeginCutFence( INT32 sGridNo, UINT8 ubDirection ) if ( IsCuttableWireFenceAtGridNo( sGridNo ) ) { // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } //BOOLEAN CutWireFence( INT16 sGridNo ) @@ -22290,8 +22289,12 @@ void SOLDIERTYPE::EVENT_SoldierBeginRepair( INT32 sGridNo, UINT8 ubDirection ) if ( bRepairItem ) { // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } //BOOLEAN CutWireFence( INT16 sGridNo ) @@ -22326,8 +22329,12 @@ void SOLDIERTYPE::EVENT_SoldierBeginRefuel( INT32 sGridNo, UINT8 ubDirection ) if ( bRefuelItem ) { // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } //BOOLEAN CutWireFence( INT16 sGridNo ) @@ -22354,8 +22361,12 @@ void SOLDIERTYPE::EVENT_SoldierBeginTakeBlood( INT32 sGridNo, UINT8 ubDirection this->aiData.uiPendingActionData4 = pCorpse->iID; // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } this->EVENT_InitNewSoldierAnim( TAKE_BLOOD_FROM_CORPSE, 0, FALSE ); } @@ -22439,8 +22450,12 @@ void SOLDIERTYPE::EVENT_SoldierBuildStructure( INT32 sGridNo, UINT8 ubDirection } // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } // do checks here... OBJECTTYPE* pObj = &(this->inv[HANDPOS]); @@ -22571,8 +22586,12 @@ void SOLDIERTYPE::EVENT_SoldierHandcuffPerson( INT32 sGridNo, UINT8 ubDirection } // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } // CHANGE TO ANIMATION this->EVENT_InitNewSoldierAnim( RELOAD_ROBOT, 0, FALSE ); @@ -22908,8 +22927,12 @@ void SOLDIERTYPE::EVENT_SoldierBeginReloadRobot( INT32 sGridNo, UINT8 ubDirectio if ( ubPerson != NOBODY && MercPtrs[ubPerson]->flags.uiStatusFlags & SOLDIER_ROBOT ) { // CHANGE DIRECTION AND GOTO ANIMATION NOW - this->EVENT_SetSoldierDesiredDirection( ubDirection ); - this->EVENT_SetSoldierDirection( ubDirection ); + if (this->ubDirection != ubDirection) + { + this->flags.uiStatusFlags |= SOLDIER_LOOK_NEXT_TURNSOLDIER;//shadooow: fix for vision not updating + this->EVENT_SetSoldierDesiredDirection(ubDirection); + this->EVENT_SetSoldierDirection(ubDirection); + } // CHANGE TO ANIMATION this->EVENT_InitNewSoldierAnim( RELOAD_ROBOT, 0, FALSE );