Skip to content

Commit

Permalink
Spawn shield hit effect exactly where projectile hit the droid
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Oct 28, 2024
1 parent 8dfde00 commit b1b3930
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
15 changes: 8 additions & 7 deletions src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,13 @@ int objArmour(const BASE_OBJECT *psObj, WEAPON_CLASS weaponClass)

/* Deals damage to an object
* \param psObj object to deal damage to
* \param psProjectile projectile which hit the object (may be nullptr)
* \param damage amount of damage to deal
* \param weaponClass the class of the weapon that deals the damage
* \param weaponSubClass the subclass of the weapon that deals the damage
* \return < 0 when the dealt damage destroys the object, > 0 when the object survives
*/
int32_t objDamage(BASE_OBJECT *psObj, unsigned damage, unsigned originalhp, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, bool isDamagePerSecond, int minDamage, bool empRadiusHit)
int32_t objDamage(BASE_OBJECT *psObj, PROJECTILE *psProjectile, unsigned damage, unsigned originalhp, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, bool isDamagePerSecond, int minDamage, bool empRadiusHit)
{
int level = 0;
int armour = objArmour(psObj, weaponClass);
Expand Down Expand Up @@ -527,22 +528,22 @@ int32_t objDamage(BASE_OBJECT *psObj, unsigned damage, unsigned originalhp, WEAP
psDroid->shieldInterruptRegenTime = psDroid->time;
}

if (weaponSubClass != WSC_FLAME &&
if (psProjectile != nullptr &&
weaponSubClass != WSC_FLAME &&
weaponSubClass != WSC_COMMAND &&
PERCENT(psDroid->shieldPoints, droidGetMaxShieldPoints(psDroid)) > 25)
{
Vector3i dv;
dv.y = psDroid->pos.z;
dv.y += (psDroid->sDisplay.imd->max.y * 2);
dv.y = psProjectile->pos.z;

for (uint32_t i = 0; i < DROID_SHIELD_PARTICLES; i++)
{
dv.x = psDroid->pos.x + DROID_SHIELD_DAMAGE_SPREAD;
dv.z = psDroid->pos.y + DROID_SHIELD_DAMAGE_SPREAD;
dv.x = psProjectile->pos.x + DROID_SHIELD_DAMAGE_SPREAD;
dv.z = psProjectile->pos.y + DROID_SHIELD_DAMAGE_SPREAD;
addEffect(&dv, EFFECT_FIREWORK, FIREWORK_TYPE_STARBURST, false, nullptr, 0, gameTime - deltaGameTime + 1);
}

audio_PlayStaticTrack(psDroid->pos.x, psDroid->pos.y, ID_SOUND_SHIELD_HIT);
audio_PlayStaticTrack(psProjectile->pos.x, psProjectile->pos.y, ID_SOUND_SHIELD_HIT);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define __INCLUDED_SRC_COMBAT_H__

#include "weapondef.h"
#include "objectdef.h"

/* Fire a weapon at something added int weapon_slot*/
bool combFire(WEAPON *psWeap, BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, int weapon_slot);
Expand All @@ -33,7 +34,7 @@ bool combFire(WEAPON *psWeap, BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, in
if any support a counter battery sensor*/
void counterBatteryFire(BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget);

int32_t objDamage(BASE_OBJECT *psObj, unsigned damage, unsigned originalhp, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, bool isDamagePerSecond, int minDamage, bool empRadiusHit);
int32_t objDamage(BASE_OBJECT *psObj, PROJECTILE *psProjectile, unsigned damage, unsigned originalhp, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, bool isDamagePerSecond, int minDamage, bool empRadiusHit);

unsigned int objGuessFutureDamage(WEAPON_STATS *psStats, unsigned int player, BASE_OBJECT *psTarget);

Expand Down
7 changes: 4 additions & 3 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,15 @@ void addDroidDeathAnimationEffect(DROID *psDroid)
#define UNIT_LOST_DELAY (5*GAME_TICKS_PER_SEC)
/* Deals damage to a droid
* \param psDroid droid to deal damage to
* \param psProjectile projectile which hit the object (may be nullptr)
* \param damage amount of damage to deal
* \param weaponClass the class of the weapon that deals the damage
* \param weaponSubClass the subclass of the weapon that deals the damage
* \param angle angle of impact (from the damage dealing projectile in relation to this droid)
* \return > 0 when the dealt damage destroys the droid, < 0 when the droid survives
*
*/
int32_t droidDamage(DROID *psDroid, unsigned damage, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, unsigned impactTime, bool isDamagePerSecond, int minDamage, bool empRadiusHit)
int32_t droidDamage(DROID *psDroid, PROJECTILE *psProjectile, unsigned damage, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, unsigned impactTime, bool isDamagePerSecond, int minDamage, bool empRadiusHit)
{
int32_t relativeDamage;

Expand All @@ -299,7 +300,7 @@ int32_t droidDamage(DROID *psDroid, unsigned damage, WEAPON_CLASS weaponClass, W
damage *= 3;
}

relativeDamage = objDamage(psDroid, damage, psDroid->originalBody, weaponClass, weaponSubClass, isDamagePerSecond, minDamage, empRadiusHit);
relativeDamage = objDamage(psDroid, psProjectile, damage, psDroid->originalBody, weaponClass, weaponSubClass, isDamagePerSecond, minDamage, empRadiusHit);

if (relativeDamage != 0 && psDroid->player == selectedPlayer && psDroid->timeLastHit == gameTime)
{
Expand Down Expand Up @@ -929,7 +930,7 @@ void droidUpdate(DROID *psDroid)
else
{
// do hardcoded burn damage (this damage automatically applied after periodical damage finished)
droidDamage(psDroid, BURN_DAMAGE, WC_HEAT, WSC_FLAME, gameTime - deltaGameTime / 2 + 1, true, BURN_MIN_DAMAGE, false);
droidDamage(psDroid, nullptr, BURN_DAMAGE, WC_HEAT, WSC_FLAME, gameTime - deltaGameTime / 2 + 1, true, BURN_MIN_DAMAGE, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/droid.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ UDWORD calcTemplateBuild(const DROID_TEMPLATE *psTemplate);
UDWORD calcTemplatePower(const DROID_TEMPLATE *psTemplate);

/* Do damage to a droid */
int32_t droidDamage(DROID *psDroid, unsigned damage, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, unsigned impactTime, bool isDamagePerSecond, int minDamage, bool empRadiusHit);
int32_t droidDamage(DROID *psDroid, PROJECTILE *psProjectile, unsigned damage, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, unsigned impactTime, bool isDamagePerSecond, int minDamage, bool empRadiusHit);

/* The main update routine for all droids */
void droidUpdate(DROID *psDroid);
Expand Down
2 changes: 1 addition & 1 deletion src/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int32_t featureDamage(FEATURE *psFeature, unsigned damage, WEAPON_CLASS weaponCl
debug(LOG_ATTACK, "feature (id %d): body %d armour %d damage: %d",
psFeature->id, psFeature->body, psFeature->psStats->armourValue, damage);

relativeDamage = objDamage(psFeature, damage, psFeature->psStats->body, weaponClass, weaponSubClass, isDamagePerSecond, minDamage, empRadiusHit);
relativeDamage = objDamage(psFeature, nullptr, damage, psFeature->psStats->body, weaponClass, weaponSubClass, isDamagePerSecond, minDamage, empRadiusHit);

// If the shell did sufficient damage to destroy the feature
if (relativeDamage < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ static int32_t objectDamageDispatch(DAMAGE *psDamage)
switch (psDamage->psDest->type)
{
case OBJ_DROID:
return droidDamage((DROID *)psDamage->psDest, psDamage->damage, psDamage->weaponClass, psDamage->weaponSubClass, psDamage->impactTime, psDamage->isDamagePerSecond, psDamage->minDamage, psDamage->empRadiusHit);
return droidDamage((DROID *)psDamage->psDest, psDamage->psProjectile, psDamage->damage, psDamage->weaponClass, psDamage->weaponSubClass, psDamage->impactTime, psDamage->isDamagePerSecond, psDamage->minDamage, psDamage->empRadiusHit);
break;

case OBJ_STRUCTURE:
Expand Down
2 changes: 1 addition & 1 deletion src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ int32_t structureDamage(STRUCTURE *psStructure, unsigned damage, WEAPON_CLASS we
debug(LOG_ATTACK, "structure id %d, body %d, armour %d, damage: %d",
psStructure->id, psStructure->body, objArmour(psStructure, weaponClass), damage);

relativeDamage = objDamage(psStructure, damage, psStructure->structureBody(), weaponClass, weaponSubClass, isDamagePerSecond, minDamage, empRadiusHit);
relativeDamage = objDamage(psStructure, nullptr, damage, psStructure->structureBody(), weaponClass, weaponSubClass, isDamagePerSecond, minDamage, empRadiusHit);

// If the shell did sufficient damage to destroy the structure
if (relativeDamage < 0)
Expand Down

0 comments on commit b1b3930

Please sign in to comment.