GL - only 1 player can manipulate a object at a time

This commit is contained in:
Erik Persson 2014-02-25 11:20:46 +01:00
parent 5ba57c1a72
commit 8a359bd1ba
5 changed files with 39 additions and 4 deletions

View File

@ -80,7 +80,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
{ {
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (800); pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (800);
heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce);
((DynamicObject*)(heldObject->GetCustomTag()))->RemoveManipulation();
hasObject = false; hasObject = false;
heldObject = NULL; heldObject = NULL;
return; return;

View File

@ -310,6 +310,7 @@ using namespace GameLogic;
obj->ApplyImpulse(((forcePushData*)(args))->pushForce); obj->ApplyImpulse(((forcePushData*)(args))->pushForce);
DynamicObject *dynamicObj = dynamic_cast<DynamicObject*>(realObj); DynamicObject *dynamicObj = dynamic_cast<DynamicObject*>(realObj);
if(dynamicObj) if(dynamicObj)
@ -333,12 +334,21 @@ using namespace GameLogic;
Object* realObj = (Object*)(obj->GetCustomTag()); Object* realObj = (Object*)(obj->GetCustomTag());
//check so that it is an object that you can pickup //check so that it is an object that you can pickup
switch(realObj->GetObjectType()) DynamicObject *dynamicObj = dynamic_cast<DynamicObject*>(realObj);
if(!dynamicObj) return;
if(dynamicObj->getManipulatingPlayer() != NULL)
{
return;
}
switch(dynamicObj->GetObjectType())
{ {
case ObjectSpecialType::ObjectSpecialType_StandardBox: case ObjectSpecialType::ObjectSpecialType_StandardBox:
weapon->heldObject = obj; //weapon now holds the object weapon->heldObject = obj; //weapon now holds the object
weapon->hasObject = true; 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; break;
} }

View File

@ -12,6 +12,7 @@ DynamicObject::DynamicObject()
this->isReleased = false; this->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL; 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) 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->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL; 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) 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) :Object(rigidBody, EventOnCollision, type, objectID)
@ -27,6 +29,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P
this->isReleased = false; this->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL; 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) 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->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL; 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) 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->isReleased = false;
this->isActive = true; this->isActive = true;
this->affectedBy = NULL; this->affectedBy = NULL;
this->manipulatedBy = NULL;
} }
DynamicObject::~DynamicObject(void) DynamicObject::~DynamicObject(void)
{ {
@ -101,3 +106,18 @@ void DynamicObject::RemoveAffectedBy()
{ {
this->affectedBy = NULL; 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;
}

View File

@ -30,8 +30,11 @@ namespace GameLogic
void Activate(); void Activate();
void SetAffectedBy(GameLogic::Player &player); void SetAffectedBy(GameLogic::Player &player);
void SetManipulatingPlayer(GameLogic::Player &player);
void RemoveAffectedBy(); void RemoveAffectedBy();
void RemoveManipulation();
GameLogic::Player* getAffectingPlayer(); GameLogic::Player* getAffectingPlayer();
GameLogic::Player* getManipulatingPlayer();
static void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); static void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
@ -40,6 +43,8 @@ namespace GameLogic
bool isReleased; bool isReleased;
protected: protected:
GameLogic::Player *affectedBy; GameLogic::Player *affectedBy;
GameLogic::Player *manipulatedBy;
}; };

View File

@ -221,7 +221,7 @@ void Player::EndFrame()
//check if there are any objects that can be removed from the AffectedObjects list //check if there are any objects that can be removed from the AffectedObjects list
for(int i = 0; i < this->AffectedObjects.Size(); i++) 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[i]->RemoveAffectedBy();
this->AffectedObjects.Remove(i); this->AffectedObjects.Remove(i);