From 3cd82d9229a7f2d3dd2094ea613077daed709b2d Mon Sep 17 00:00:00 2001 From: Johxz Date: Tue, 31 Jan 2017 18:38:09 -0600 Subject: [PATCH 1/2] add strikeObject functionality feature --- Engine/source/T3D/fx/lightning.cpp | 40 ++++++++++++++++++++++++++++-- Engine/source/T3D/fx/lightning.h | 2 +- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Engine/source/T3D/fx/lightning.cpp b/Engine/source/T3D/fx/lightning.cpp index 080bbed820..385068ddfd 100644 --- a/Engine/source/T3D/fx/lightning.cpp +++ b/Engine/source/T3D/fx/lightning.cpp @@ -863,11 +863,47 @@ void Lightning::strikeRandomPoint() } //-------------------------------------------------------------------------- -void Lightning::strikeObject(ShapeBase*) +void Lightning::strikeObject(ShapeBase* targetObj) { AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!"); - AssertFatal(false, "Lightning::strikeObject is not implemented."); + Point3F strikePoint = targetObj->getPosition(); + Point3F objectCenter; + + targetObj->getObjBox().getCenter(&objectCenter); + objectCenter.convolve(targetObj->getScale()); + targetObj->getTransform().mulP(objectCenter); + + bool playerInWarmup = false; + Player *playerObj = dynamic_cast< Player * >(targetObj); + if (playerObj) + { + if (!playerObj->getControllingClient()) + { + playerInWarmup = true; + } + } + + if (!playerInWarmup) + { + applyDamage_callback(objectCenter, VectorF(0.0, 0.0, 1.0), targetObj); + } + + SimGroup* pClientGroup = Sim::getClientGroup(); + for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++) { + NetConnection* nc = static_cast(*itr); + if (nc != NULL) + { + LightningStrikeEvent* pEvent = new LightningStrikeEvent; + pEvent->mLightning = this; + + pEvent->mStart.x = strikePoint.x; + pEvent->mStart.y = strikePoint.y; + pEvent->mTarget = targetObj; + + nc->postNetEvent(pEvent); + } + } } diff --git a/Engine/source/T3D/fx/lightning.h b/Engine/source/T3D/fx/lightning.h index 340d4e067f..ed08bbd82d 100644 --- a/Engine/source/T3D/fx/lightning.h +++ b/Engine/source/T3D/fx/lightning.h @@ -229,7 +229,7 @@ class Lightning : public GameBase void warningFlashes(); void strikeRandomPoint(); - void strikeObject(ShapeBase*); + void strikeObject(ShapeBase* targetObj); void processEvent(LightningStrikeEvent*); DECLARE_CONOBJECT(Lightning); From 84f610f2f23373179ed895be7cd5ca1d500129ea Mon Sep 17 00:00:00 2001 From: Johxz Date: Fri, 3 Feb 2017 18:23:34 -0600 Subject: [PATCH 2/2] fix tabs vs space, fix net strikepoints --- Engine/source/T3D/fx/lightning.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Engine/source/T3D/fx/lightning.cpp b/Engine/source/T3D/fx/lightning.cpp index 385068ddfd..e6c315796c 100644 --- a/Engine/source/T3D/fx/lightning.cpp +++ b/Engine/source/T3D/fx/lightning.cpp @@ -870,25 +870,30 @@ void Lightning::strikeObject(ShapeBase* targetObj) Point3F strikePoint = targetObj->getPosition(); Point3F objectCenter; - targetObj->getObjBox().getCenter(&objectCenter); - objectCenter.convolve(targetObj->getScale()); - targetObj->getTransform().mulP(objectCenter); + Box3F wb = getWorldBox(); + if (!wb.isContained(strikePoint)) + return; + + Point3F targetRel = strikePoint - getPosition(); + Point3F length(wb.len_x() / 2.0f, wb.len_y() / 2.0f, wb.len_z() / 2.0f); + + Point3F strikePos = targetRel / length; bool playerInWarmup = false; Player *playerObj = dynamic_cast< Player * >(targetObj); if (playerObj) { - if (!playerObj->getControllingClient()) - { - playerInWarmup = true; - } + if (!playerObj->getControllingClient()) + { + playerInWarmup = true; + } } if (!playerInWarmup) { - applyDamage_callback(objectCenter, VectorF(0.0, 0.0, 1.0), targetObj); + applyDamage_callback(targetObj->getWorldSphere().center, VectorF(0.0, 0.0, 1.0), targetObj); } - + SimGroup* pClientGroup = Sim::getClientGroup(); for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++) { NetConnection* nc = static_cast(*itr); @@ -897,16 +902,15 @@ void Lightning::strikeObject(ShapeBase* targetObj) LightningStrikeEvent* pEvent = new LightningStrikeEvent; pEvent->mLightning = this; - pEvent->mStart.x = strikePoint.x; - pEvent->mStart.y = strikePoint.y; - pEvent->mTarget = targetObj; + pEvent->mStart.x = strikePoint.x; + pEvent->mStart.y = strikePoint.y; + pEvent->mTarget = targetObj; nc->postNetEvent(pEvent); } } } - //-------------------------------------------------------------------------- U32 Lightning::packUpdate(NetConnection* con, U32 mask, BitStream* stream) {