Skip to content

Commit 5c8a821

Browse files
authored
Merge pull request #1938 from John3/add_strikeObject
added strikeObject lightning feature
2 parents b6cbac0 + 84f610f commit 5c8a821

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

Engine/source/T3D/fx/lightning.cpp

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,13 +867,53 @@ void Lightning::strikeRandomPoint()
867867
}
868868

869869
//--------------------------------------------------------------------------
870-
void Lightning::strikeObject(ShapeBase*)
870+
void Lightning::strikeObject(ShapeBase* targetObj)
871871
{
872872
AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!");
873873

874-
AssertFatal(false, "Lightning::strikeObject is not implemented.");
875-
}
874+
Point3F strikePoint = targetObj->getPosition();
875+
Point3F objectCenter;
876+
877+
Box3F wb = getWorldBox();
878+
if (!wb.isContained(strikePoint))
879+
return;
880+
881+
Point3F targetRel = strikePoint - getPosition();
882+
Point3F length(wb.len_x() / 2.0f, wb.len_y() / 2.0f, wb.len_z() / 2.0f);
883+
884+
Point3F strikePos = targetRel / length;
885+
886+
bool playerInWarmup = false;
887+
Player *playerObj = dynamic_cast< Player * >(targetObj);
888+
if (playerObj)
889+
{
890+
if (!playerObj->getControllingClient())
891+
{
892+
playerInWarmup = true;
893+
}
894+
}
895+
896+
if (!playerInWarmup)
897+
{
898+
applyDamage_callback(targetObj->getWorldSphere().center, VectorF(0.0, 0.0, 1.0), targetObj);
899+
}
900+
901+
SimGroup* pClientGroup = Sim::getClientGroup();
902+
for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++) {
903+
NetConnection* nc = static_cast<NetConnection*>(*itr);
904+
if (nc != NULL)
905+
{
906+
LightningStrikeEvent* pEvent = new LightningStrikeEvent;
907+
pEvent->mLightning = this;
908+
909+
pEvent->mStart.x = strikePoint.x;
910+
pEvent->mStart.y = strikePoint.y;
911+
pEvent->mTarget = targetObj;
876912

913+
nc->postNetEvent(pEvent);
914+
}
915+
}
916+
}
877917

878918
//--------------------------------------------------------------------------
879919
U32 Lightning::packUpdate(NetConnection* con, U32 mask, BitStream* stream)

Engine/source/T3D/fx/lightning.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class Lightning : public GameBase
229229

230230
void warningFlashes();
231231
void strikeRandomPoint();
232-
void strikeObject(ShapeBase*);
232+
void strikeObject(ShapeBase* targetObj);
233233
void processEvent(LightningStrikeEvent*);
234234

235235
DECLARE_CONOBJECT(Lightning);

0 commit comments

Comments
 (0)