Permalink
Browse files

Lua: add projectileID argument to UnitPreDamaged

  • Loading branch information...
rt
rt committed Mar 21, 2013
1 parent d189f3f commit 68342c40a18abf0263a1de17abb2608ca751f944
@@ -392,8 +392,14 @@ void CEngineOutHandler::UnitDestroyed(const CUnit& destroyed, const CUnit* attac
}
-void CEngineOutHandler::UnitDamaged(const CUnit& damaged, const CUnit* attacker,
- float damage, int weaponDefId, bool paralyzer) {
+void CEngineOutHandler::UnitDamaged(
+ const CUnit& damaged,
+ const CUnit* attacker,
+ float damage,
+ int weaponDefID,
+ int projectileID,
+ bool paralyzer
+) {
AI_EVT_MTH();
const int damagedUnitId = damaged.id;
@@ -417,7 +423,7 @@ void CEngineOutHandler::UnitDamaged(const CUnit& damaged, const CUnit* attacker,
visibleAttackerUnitId = attackerUnitId;
}
try {
- id_skirmishAI[*ai]->UnitDamaged(damagedUnitId, visibleAttackerUnitId, damage, attackDir_damagedsView, weaponDefId, paralyzer);
+ id_skirmishAI[*ai]->UnitDamaged(damagedUnitId, visibleAttackerUnitId, damage, attackDir_damagedsView, weaponDefID, paralyzer);
} CATCH_AI_EXCEPTION;
}
}
@@ -439,7 +445,7 @@ void CEngineOutHandler::UnitDamaged(const CUnit& damaged, const CUnit* attacker,
{
try {
saw->EnemyDamaged(damagedUnitId, attackerUnitId, damage,
- attackDir, weaponDefId, paralyzer);
+ attackDir, weaponDefID, paralyzer);
} CATCH_AI_EXCEPTION;
}
}
@@ -49,7 +49,7 @@ class CEngineOutHandler : public CObject {
void UnitCreated(const CUnit& unit, const CUnit* builder);
void UnitFinished(const CUnit& unit);
void UnitDestroyed(const CUnit& destroyed, const CUnit* attacker);
- void UnitDamaged(const CUnit& damaged, const CUnit* attacker, float damage, int weaponId, bool paralyzer);
+ void UnitDamaged(const CUnit& damaged, const CUnit* attacker, float damage, int weaponDefID, int projectileID, bool paralyzer);
void UnitMoveFailed(const CUnit& unit);
void UnitCaptured(const CUnit& unit, int oldTeam, int newTeam);
void UnitGiven(const CUnit& unit, int oldTeam, int newTeam);
View
@@ -83,7 +83,8 @@ void CGameHelper::DoExplosionDamage(
const float expEdgeEffect,
const bool ignoreOwner,
const DamageArray& damages,
- const int weaponDefID
+ const int weaponDefID,
+ const int projectileID
) {
if (ignoreOwner && (unit == owner)) {
return;
@@ -139,10 +140,10 @@ void CGameHelper::DoExplosionDamage(
if (expDist < (expSpeed * DIRECT_EXPLOSION_DAMAGE_SPEED_SCALE)) {
// damage directly
- unit->DoDamage(expDamages, expImpulse, owner, weaponDefID);
+ unit->DoDamage(expDamages, expImpulse, owner, weaponDefID, projectileID);
} else {
// damage later
- WaitingDamage* wd = new WaitingDamage((owner? owner->id: -1), unit->id, expDamages, expImpulse, weaponDefID);
+ WaitingDamage* wd = new WaitingDamage((owner? owner->id: -1), unit->id, expDamages, expImpulse, weaponDefID, projectileID);
waitingDamages[(gs->frameNum + int(expDist / expSpeed) - 3) & 127].push_front(wd);
}
}
@@ -153,7 +154,8 @@ void CGameHelper::DoExplosionDamage(
const float expRadius,
const float expEdgeEffect,
const DamageArray& damages,
- const int weaponDefID
+ const int weaponDefID,
+ const int projectileID
) {
const CollisionVolume* vol = CollisionVolume::GetVolume(feature, NULL);
const float3& volPos = vol->GetWorldSpacePos(feature, ZeroVector);
@@ -175,7 +177,7 @@ void CGameHelper::DoExplosionDamage(
const float3 impulseDir = (volPos - expPos).SafeNormalize();
const float3 expImpulse = impulseDir * modImpulseScale;
- feature->DoDamage(damages * expMod, expImpulse, NULL, weaponDefID);
+ feature->DoDamage(damages * expMod, expImpulse, NULL, weaponDefID, projectileID);
}
@@ -206,7 +208,7 @@ void CGameHelper::Explosion(const ExplosionParams& params) {
const bool impactOnly = params.impactOnly;
const bool ignoreOwner = params.ignoreOwner;
const bool damageGround = params.damageGround;
- const bool noGfx = eventHandler.Explosion(weaponDefID, expPos, owner);
+ const bool noGfx = eventHandler.Explosion(weaponDefID, params.projectileID, expPos, owner);
if (luaUI) {
if (weaponDef != NULL && weaponDef->cameraShake > 0.0f) {
@@ -216,9 +218,9 @@ void CGameHelper::Explosion(const ExplosionParams& params) {
if (impactOnly) {
if (hitUnit) {
- DoExplosionDamage(hitUnit, owner, expPos, damageAOE, expSpeed, expEdgeEffect, ignoreOwner, damages, weaponDefID);
+ DoExplosionDamage(hitUnit, owner, expPos, damageAOE, expSpeed, expEdgeEffect, ignoreOwner, damages, weaponDefID, params.projectileID);
} else if (hitFeature) {
- DoExplosionDamage(hitFeature, expPos, damageAOE, expEdgeEffect, damages, weaponDefID);
+ DoExplosionDamage(hitFeature, expPos, damageAOE, expEdgeEffect, damages, weaponDefID, params.projectileID);
}
} else {
{
@@ -233,14 +235,14 @@ void CGameHelper::Explosion(const ExplosionParams& params) {
hitUnitDamaged = true;
}
- DoExplosionDamage(unit, owner, expPos, damageAOE, expSpeed, expEdgeEffect, ignoreOwner, damages, weaponDefID);
+ DoExplosionDamage(unit, owner, expPos, damageAOE, expSpeed, expEdgeEffect, ignoreOwner, damages, weaponDefID, params.projectileID);
}
// HACK: for a unit with an offset coldet volume, the explosion
// (from an impacting projectile) position might not correspond
// to its quadfield position so we need to damage it separately
if (hitUnit != NULL && !hitUnitDamaged) {
- DoExplosionDamage(hitUnit, owner, expPos, damageAOE, expSpeed, expEdgeEffect, ignoreOwner, damages, weaponDefID);
+ DoExplosionDamage(hitUnit, owner, expPos, damageAOE, expSpeed, expEdgeEffect, ignoreOwner, damages, weaponDefID, params.projectileID);
}
}
@@ -256,11 +258,11 @@ void CGameHelper::Explosion(const ExplosionParams& params) {
hitFeatureDamaged = true;
}
- DoExplosionDamage(feature, expPos, damageAOE, expEdgeEffect, damages, weaponDefID);
+ DoExplosionDamage(feature, expPos, damageAOE, expEdgeEffect, damages, weaponDefID, params.projectileID);
}
if (hitFeature != NULL && !hitFeatureDamaged) {
- DoExplosionDamage(hitFeature, expPos, damageAOE, expEdgeEffect, damages, weaponDefID);
+ DoExplosionDamage(hitFeature, expPos, damageAOE, expEdgeEffect, damages, weaponDefID, params.projectileID);
}
}
@@ -1288,7 +1290,7 @@ void CGameHelper::Update()
CUnit* attacker = (w->attacker == -1)? NULL: unitHandler->units[w->attacker];
if (attackee != NULL)
- attackee->DoDamage(w->damage, w->impulse, attacker, w->weaponId);
+ attackee->DoDamage(w->damage, w->impulse, attacker, w->weaponID, w->projectileID);
delete w;
}
View
@@ -55,9 +55,12 @@ class CGameHelper
float edgeEffectiveness;
float explosionSpeed;
float gfxMod;
+
bool impactOnly;
bool ignoreOwner;
bool damageGround;
+
+ unsigned int projectileID;
};
CGameHelper();
@@ -120,23 +123,25 @@ class CGameHelper
const float expEdgeEffect,
const bool ignoreOwner,
const DamageArray& damages,
- const int weaponDefID
+ const int weaponDefID,
+ const int projectileID
);
void DoExplosionDamage(
CFeature* feature,
const float3& expPos,
const float expRadius,
const float expEdgeEffect,
const DamageArray& damages,
- const int weaponDefID
+ const int weaponDefID,
+ const int projectileID
);
void Explosion(const ExplosionParams& params);
private:
CStdExplosionGenerator* stdExplosionGenerator;
- struct WaitingDamage{
+ struct WaitingDamage {
#if !defined(SYNCIFY)
inline void* operator new(size_t size) {
return mempool.Alloc(size);
@@ -145,17 +150,20 @@ class CGameHelper
mempool.Free(p, size);
};
#endif
- WaitingDamage(int attacker, int target, const DamageArray& damage, const float3& impulse, const int weaponId)
- : target(target),
- attacker(attacker),
- weaponId(weaponId),
- damage(damage),
- impulse(impulse)
+ WaitingDamage(int attacker, int target, const DamageArray& damage, const float3& impulse, const int _weaponID, const int _projectileID)
+ : target(target)
+ , attacker(attacker)
+ , weaponID(_weaponID)
+ , projectileID(_projectileID)
+ , damage(damage)
+ , impulse(impulse)
{}
int target;
int attacker;
- int weaponId;
+ int weaponID;
+ int projectileID;
+
DamageArray damage;
float3 impulse;
};
@@ -176,7 +176,7 @@ class DestroyActionExecutor : public ISyncedActionExecutor {
CUnit* unit = unitHandler->GetUnit(unitId);
if (unit != NULL) {
- unit->KillUnit(false, false, 0);
+ unit->KillUnit(NULL, false, false);
} else {
LOG("Wrong unitID: %i", unitId);
}
View
@@ -989,10 +989,15 @@ void CLuaHandle::UnitCmdDone(const CUnit* unit, int cmdID, int cmdTag)
}
-void CLuaHandle::UnitDamaged(const CUnit* unit, const CUnit* attacker,
- float damage, int weaponID, bool paralyzer)
-{
- LUA_UNIT_BATCH_PUSH(,UNIT_DAMAGED, unit, attacker, damage, weaponID, paralyzer);
+void CLuaHandle::UnitDamaged(
+ const CUnit* unit,
+ const CUnit* attacker,
+ float damage,
+ int weaponDefID,
+ int projectileID,
+ bool paralyzer)
+{
+ LUA_UNIT_BATCH_PUSH(,UNIT_DAMAGED, unit, attacker, damage, weaponDefID, paralyzer);
LUA_CALL_IN_CHECK(L);
lua_checkstack(L, 11);
@@ -1012,8 +1017,13 @@ void CLuaHandle::UnitDamaged(const CUnit* unit, const CUnit* attacker,
lua_pushnumber(L, damage);
lua_pushboolean(L, paralyzer);
if (GetHandleFullRead(L)) {
- lua_pushnumber(L, weaponID);
+ lua_pushnumber(L, weaponDefID);
argCount += 1;
+
+ // TODO: add to batch
+ // lua_pushnumber(L, projectileID);
+ // argCount += 1;
+
if (attacker != NULL) {
lua_pushnumber(L, attacker->id);
lua_pushnumber(L, attacker->unitDef->id);
@@ -1429,7 +1439,7 @@ void CLuaHandle::ProjectileDestroyed(const CProjectile* p)
/******************************************************************************/
-bool CLuaHandle::Explosion(int weaponDefID, const float3& pos, const CUnit* owner)
+bool CLuaHandle::Explosion(int weaponDefID, int projectileID, const float3& pos, const CUnit* owner)
{
// piece-projectile collision (*ALL* other
// explosion events pass valid weaponDefIDs)
@@ -1548,7 +1558,7 @@ void CLuaHandle::ExecuteUnitEventBatch() {
UnitCmdDone(e.unit1, e.int1, e.int2);
break;
case UNIT_DAMAGED:
- UnitDamaged(e.unit1, e.unit2, e.float1, e.int1, e.bool1);
+ UnitDamaged(e.unit1, e.unit2, e.float1, e.int1, -1, e.bool1);
break;
case UNIT_EXPERIENCE:
UnitExperience(e.unit1, e.float1);
@@ -1596,7 +1606,7 @@ void CLuaHandle::ExecuteUnitEventBatch() {
UnitMoveFailed(e.unit1);
break;
case UNIT_EXPLOSION:
- Explosion(e.int1, e.cmd1->GetPos(0), e.unit1);
+ Explosion(e.int1, -1, e.cmd1->GetPos(0), e.unit1);
break;
case UNIT_UNIT_COLLISION:
UnitUnitCollision(e.unit1, e.unit2);
View
@@ -157,8 +157,13 @@ class CLuaHandle : public CEventClient
void UnitIdle(const CUnit* unit);
void UnitCommand(const CUnit* unit, const Command& command);
void UnitCmdDone(const CUnit* unit, int cmdID, int cmdTag);
- void UnitDamaged(const CUnit* unit, const CUnit* attacker,
- float damage, int weaponID, bool paralyzer);
+ void UnitDamaged(
+ const CUnit* unit,
+ const CUnit* attacker,
+ float damage,
+ int weaponDefID,
+ int projectileID,
+ bool paralyzer);
void UnitExperience(const CUnit* unit, float oldExperience);
void UnitSeismicPing(const CUnit* unit, int allyTeam,
@@ -189,7 +194,7 @@ class CLuaHandle : public CEventClient
void ProjectileCreated(const CProjectile* p);
void ProjectileDestroyed(const CProjectile* p);
- bool Explosion(int weaponID, const float3& pos, const CUnit* owner);
+ bool Explosion(int weaponID, int projectileID, const float3& pos, const CUnit* owner);
void StockpileChanged(const CUnit* owner,
const CWeapon* weapon, int oldCount);
View
@@ -717,9 +717,15 @@ bool CLuaRules::TerraformComplete(const CUnit* unit, const CUnit* build)
* 1st is stored under *newDamage if newDamage != NULL
* 2nd is stored under *impulseMult if impulseMult != NULL
*/
-bool CLuaRules::UnitPreDamaged(const CUnit* unit, const CUnit* attacker,
- float damage, int weaponID, bool paralyzer,
- float* newDamage, float* impulseMult)
+bool CLuaRules::UnitPreDamaged(
+ const CUnit* unit,
+ const CUnit* attacker,
+ float damage,
+ int weaponDefID,
+ int projectileID,
+ bool paralyzer,
+ float* newDamage,
+ float* impulseMult)
{
if (!haveUnitPreDamaged)
return false;
@@ -743,8 +749,12 @@ bool CLuaRules::UnitPreDamaged(const CUnit* unit, const CUnit* attacker,
lua_pushnumber(L, damage);
lua_pushboolean(L, paralyzer);
if (GetHandleFullRead(L)) {
- lua_pushnumber(L, weaponID);
+ lua_pushnumber(L, weaponDefID);
argCount += 1;
+
+ lua_pushnumber(L, projectileID);
+ argCount += 1;
+
if (attacker != NULL) {
lua_pushnumber(L, attacker->id);
lua_pushnumber(L, attacker->unitDef->id);
View
@@ -70,9 +70,15 @@ class CLuaRules : public CLuaHandleSynced
unsigned int attackerWeaponDefID,
float* targetPriority);
- bool UnitPreDamaged(const CUnit* unit, const CUnit* attacker,
- float damage, int weaponID, bool paralyzer,
- float* newDamage, float* impulseMult);
+ bool UnitPreDamaged(
+ const CUnit* unit,
+ const CUnit* attacker,
+ float damage,
+ int weaponDefID,
+ int projectileID,
+ bool paralyzer,
+ float* newDamage,
+ float* impulseMult);
bool ShieldPreDamaged(const CProjectile*, const CWeapon*, const CUnit*, bool);
@@ -1034,7 +1034,7 @@ int LuaSyncedCtrl::DestroyUnit(lua_State* L)
}
inDestroyUnit = true;
ASSERT_SYNCED(unit->id);
- unit->KillUnit(selfd, reclaimed, attacker);
+ unit->KillUnit(attacker, selfd, reclaimed);
inDestroyUnit = false;
return 0;
@@ -2222,7 +2222,7 @@ int LuaSyncedCtrl::AddUnitDamage(lua_State* L)
damages.paralyzeDamageTime = paralyze;
}
- unit->DoDamage(damages, impulse, attacker, weaponDefID);
+ unit->DoDamage(damages, impulse, attacker, weaponDefID, -1);
return 0;
}
@@ -347,7 +347,7 @@ bool CFeature::AddBuildPower(float amount, CUnit* builder)
}
-void CFeature::DoDamage(const DamageArray& damages, const float3& impulse, CUnit*, int)
+void CFeature::DoDamage(const DamageArray& damages, const float3& impulse, CUnit*, int, int)
{
if (damages.paralyzeDamageTime) {
return; // paralyzers do not damage features
Oops, something went wrong.

0 comments on commit 68342c4

Please sign in to comment.