From ba618387036debf2fd722acb8cb18139a7fc40f3 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 25 Feb 2014 11:20:46 +0100 Subject: [PATCH] GL - only 1 player can manipulate a object at a time --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 2 +- Code/Game/GameLogic/CollisionManager.cpp | 14 +++++++++++-- Code/Game/GameLogic/DynamicObject.cpp | 20 +++++++++++++++++++ Code/Game/GameLogic/DynamicObject.h | 5 +++++ Code/Game/GameLogic/Player.cpp | 2 +- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index c6b0df0a..1f86bf60 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -80,7 +80,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float { pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (800); heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); - + ((DynamicObject*)(heldObject->GetCustomTag()))->RemoveManipulation(); hasObject = false; heldObject = NULL; return; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 8a360059..d60d16ce 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -309,6 +309,7 @@ using namespace GameLogic; obj->ApplyImpulse(((forcePushData*)(args))->pushForce); + DynamicObject *dynamicObj = dynamic_cast(realObj); @@ -333,12 +334,21 @@ using namespace GameLogic; Object* realObj = (Object*)(obj->GetCustomTag()); //check so that it is an object that you can pickup - switch(realObj->GetObjectType()) + DynamicObject *dynamicObj = dynamic_cast(realObj); + + if(!dynamicObj) return; + + if(dynamicObj->getManipulatingPlayer() != NULL) + { + return; + } + + switch(dynamicObj->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_StandardBox: weapon->heldObject = obj; //weapon now holds the object weapon->hasObject = true; - + dynamicObj->SetManipulatingPlayer(*weapon->owner); //TODO: add if this is to be a struggle of who has the most power in its weapon, the player that is already manipulating the object or you. if you then you take the object from the other player, if not then you do not take the object break; } diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 961d29fc..844deaf2 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -12,6 +12,7 @@ DynamicObject::DynamicObject() this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) @@ -20,6 +21,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) :Object(rigidBody, EventOnCollision, type, objectID) @@ -27,6 +29,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) @@ -36,6 +39,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) @@ -45,6 +49,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::~DynamicObject(void) { @@ -100,4 +105,19 @@ Player* DynamicObject::getAffectingPlayer() void DynamicObject::RemoveAffectedBy() { this->affectedBy = NULL; +} + +GameLogic::Player* DynamicObject::getManipulatingPlayer() +{ + return this->manipulatedBy; +} + +void DynamicObject::SetManipulatingPlayer(GameLogic::Player &player) +{ + this->manipulatedBy = &player; +} + +void DynamicObject::RemoveManipulation() +{ + this->manipulatedBy = NULL; } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index d1bb63bc..03a03ad6 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -30,8 +30,11 @@ namespace GameLogic void Activate(); void SetAffectedBy(GameLogic::Player &player); + void SetManipulatingPlayer(GameLogic::Player &player); void RemoveAffectedBy(); + void RemoveManipulation(); GameLogic::Player* getAffectingPlayer(); + GameLogic::Player* getManipulatingPlayer(); static void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); @@ -40,6 +43,8 @@ namespace GameLogic bool isReleased; protected: GameLogic::Player *affectedBy; + GameLogic::Player *manipulatedBy; + }; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 4dcdacaa..d8ba38ba 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -221,7 +221,7 @@ void Player::EndFrame() //check if there are any objects that can be removed from the AffectedObjects list for(int i = 0; i < this->AffectedObjects.Size(); i++) { - if((this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) + if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) { this->AffectedObjects[i]->RemoveAffectedBy(); this->AffectedObjects.Remove(i);