Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Tactical/Soldier Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10700,6 +10700,22 @@ UINT8 SOLDIERTYPE::SoldierTakeDamage( INT8 bHeight, INT16 sLifeDeduct, INT16 sBr
return(ubCombinedLoss);
}

void SOLDIERTYPE::SoldierTakeDelayedDamage(INT8 bHeight, INT16 sLifeDeduct, INT16 sBreathLoss, UINT8 ubReason, UINT8 ubAttacker, INT32 sSourceGrid, INT16 sSubsequent, BOOLEAN fShowDamage)
{
delayedDamageFunction = [this, bHeight, sLifeDeduct, sBreathLoss, ubReason, ubAttacker, sSourceGrid, sSubsequent, fShowDamage]()
{
this->SoldierTakeDamage(bHeight, sLifeDeduct, sBreathLoss, ubReason, ubAttacker, sSourceGrid, sSubsequent, fShowDamage);
};
}

void SOLDIERTYPE::ResolveDelayedDamage()
{
if (delayedDamageFunction)
{
delayedDamageFunction();
delayedDamageFunction = nullptr;
}
}

extern BOOLEAN IsMercSayingDialogue( UINT8 ubProfileID );

Expand Down Expand Up @@ -11499,6 +11515,8 @@ void SOLDIERTYPE::MoveMerc( FLOAT dMovementChange, FLOAT dAngle, BOOLEAN fCheckR
// OK, set new position
this->EVENT_InternalSetSoldierPosition( dXPos, dYPos, FALSE, FALSE, FALSE );

this->ResolveDelayedDamage();

// Flugente: drag people
if ( currentlydragging )
{
Expand Down Expand Up @@ -26234,4 +26252,6 @@ void SOLDIERTYPE::InitializeExtraData(void)
this->ubQuickItemSlot = 0;

this->usGrenadeItem = 0;

this->delayedDamageFunction = nullptr;
}
8 changes: 8 additions & 0 deletions Tactical/Soldier Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <iterator>
#include "GameSettings.h" // added by Flugente
#include "Disease.h" // added by Flugente
#include <functional>

#define PTR_CIVILIAN (pSoldier->bTeam == CIV_TEAM)
#define PTR_CROUCHED (gAnimControl[ pSoldier->usAnimState ].ubHeight == ANIM_CROUCH)
Expand Down Expand Up @@ -1656,6 +1657,10 @@ class SOLDIERTYPE//last edited at version 102
UINT8 ubQuickItemSlot;

UINT16 usGrenadeItem;

// anv: resolve damage with delay, e.g. damage applied mid movement that would cause issues with world data if applied immediately
std::function<void()> delayedDamageFunction;

public:
// CREATION FUNCTIONS
BOOLEAN DeleteSoldier( void );
Expand Down Expand Up @@ -1719,6 +1724,9 @@ class SOLDIERTYPE//last edited at version 102
void ReviveSoldier( void );
UINT8 SoldierTakeDamage( INT8 bHeight, INT16 sLifeDeduct, INT16 sBreathDeduct, UINT8 ubReason, UINT8 ubAttacker, INT32 sSourceGrid, INT16 sSubsequent, BOOLEAN fShowDamage );

// anv: resolve damage with delay, e.g. damage applied mid movement that would cause issues with world data if applied immediately
void SoldierTakeDelayedDamage(INT8 bHeight, INT16 sLifeDeduct, INT16 sBreathDeduct, UINT8 ubReason, UINT8 ubAttacker, INT32 sSourceGrid, INT16 sSubsequent, BOOLEAN fShowDamage);
void ResolveDelayedDamage();

// Palette functions for soldiers
BOOLEAN CreateSoldierPalettes( void );
Expand Down
4 changes: 2 additions & 2 deletions TileEngine/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,10 +1914,10 @@ INT8 DamageStructure( STRUCTURE * pStructure, UINT8 ubDamage, UINT8 ubReason, IN
//Since the structure is being damaged, set the map element that a structure is damaged
gpWorldLevelData[ tmpgridno ].uiFlags |= MAPELEMENT_STRUCTURE_DAMAGED;

// handle structure revenge - damage to vehicle
// handle structure revenge - damage to vehicle - to be resolved after movement
if ( ubOwner != NOBODY && MercPtrs[ubOwner] && !ARMED_VEHICLE( MercPtrs[ubOwner] ) )
{
MercPtrs[ ubOwner ]->SoldierTakeDamage( 0, Random(max(0,(ubBaseArmour-10)/5))+max(0,(ubBaseArmour-10)/5), 0, TAKE_DAMAGE_STRUCTURE_EXPLOSION, NOBODY, MercPtrs[ ubOwner ]->sGridNo, 0, TRUE );
MercPtrs[ubOwner]->SoldierTakeDelayedDamage(0, Random(max(0,(ubBaseArmour-10)/5)) + max(0,(ubBaseArmour-10)/5), 0, TAKE_DAMAGE_STRUCTURE_EXPLOSION, NOBODY, MercPtrs[ ubOwner ]->sGridNo, 0, TRUE);
}

// recompile = TRUE means that we destroyed something
Expand Down