2013-12-10 09:57:05 +01:00
|
|
|
#include "AttatchmentMassDriver.h"
|
2013-12-12 12:16:13 +01:00
|
|
|
#include "PhysicsAPI.h"
|
2014-01-31 14:05:52 +01:00
|
|
|
#include "GameLogicStates.h"
|
2013-12-10 09:57:05 +01:00
|
|
|
|
|
|
|
using namespace GameLogic;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AttatchmentMassDriver::AttatchmentMassDriver(void)
|
|
|
|
{
|
2013-12-12 12:16:13 +01:00
|
|
|
this->owner = 0;
|
2014-02-03 15:32:46 +01:00
|
|
|
this->heldObject = NULL;
|
|
|
|
this->hasObject = false;
|
2013-12-12 12:16:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AttatchmentMassDriver::AttatchmentMassDriver(Player &owner)
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
|
2013-12-12 12:16:13 +01:00
|
|
|
this->owner = &owner;
|
2014-02-03 15:32:46 +01:00
|
|
|
this->heldObject = NULL;
|
|
|
|
this->hasObject = false;
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AttatchmentMassDriver::~AttatchmentMassDriver(void)
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
2013-12-10 11:17:25 +01:00
|
|
|
/********************************************************
|
|
|
|
* Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used
|
|
|
|
********************************************************/
|
2014-01-21 15:46:54 +01:00
|
|
|
void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, float dt)
|
2013-12-10 11:17:25 +01:00
|
|
|
{
|
2013-12-12 12:16:13 +01:00
|
|
|
//switch case to determin what functionallity to use in the attatchment
|
2014-01-16 11:17:19 +01:00
|
|
|
switch (usage)
|
2013-12-12 12:16:13 +01:00
|
|
|
{
|
|
|
|
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
|
2014-01-21 15:46:54 +01:00
|
|
|
ForcePush(usage,dt);
|
2013-12-12 12:16:13 +01:00
|
|
|
break;
|
2014-02-13 09:58:14 +01:00
|
|
|
|
2013-12-12 12:16:13 +01:00
|
|
|
case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS:
|
2014-01-21 15:46:54 +01:00
|
|
|
ForcePull(usage,dt);
|
2014-02-13 09:58:14 +01:00
|
|
|
break;
|
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS:
|
|
|
|
ForceZip(usage,dt);
|
2014-02-13 09:58:14 +01:00
|
|
|
break;
|
2013-12-12 12:16:13 +01:00
|
|
|
}
|
2014-01-22 14:26:45 +01:00
|
|
|
|
2013-12-10 11:17:25 +01:00
|
|
|
}
|
2013-12-10 09:57:05 +01:00
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
void AttatchmentMassDriver::Update(float dt)
|
|
|
|
{
|
|
|
|
|
|
|
|
//update position of heldObject if there is an object being held
|
|
|
|
if(hasObject)
|
|
|
|
{
|
2014-02-12 14:00:53 +01:00
|
|
|
//Oyster::Physics::ICustomBody::State state;
|
|
|
|
//state = heldObject->GetState();
|
2014-02-03 16:19:24 +01:00
|
|
|
Oyster::Math::Float3 ownerPos = owner->GetPosition();
|
2014-02-05 15:54:48 +01:00
|
|
|
Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState();
|
2014-02-09 21:24:09 +01:00
|
|
|
Oyster::Math::Float3 up = -ownerState.GetOrientation().v[2];
|
2014-02-14 10:09:03 +01:00
|
|
|
up *= -0.3f;
|
2014-02-12 14:00:53 +01:00
|
|
|
Oyster::Math::Float3 pos = ownerPos + (owner->GetLookDir().GetNormalized()*5);
|
2014-02-03 15:32:46 +01:00
|
|
|
|
2014-02-12 14:00:53 +01:00
|
|
|
//state.centerPos = pos;
|
|
|
|
heldObject->SetPosition(pos);
|
2014-02-03 15:32:46 +01:00
|
|
|
|
2014-02-12 14:00:53 +01:00
|
|
|
//heldObject->SetState(state);
|
2014-02-03 15:32:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 11:17:25 +01:00
|
|
|
/********************************************************
|
2013-12-12 12:21:19 +01:00
|
|
|
* Pushes objects in a cone in front of the weapon when fired
|
2014-02-03 15:32:46 +01:00
|
|
|
*alternativly it puts a large force on the currently held object
|
2013-12-10 11:17:25 +01:00
|
|
|
********************************************************/
|
2014-01-21 15:46:54 +01:00
|
|
|
void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt)
|
2013-12-10 09:57:05 +01:00
|
|
|
{
|
2014-02-03 15:32:46 +01:00
|
|
|
//if the weapon has an object then it is only the object that will be shot away
|
|
|
|
Oyster::Math::Float4 pushForce;
|
|
|
|
|
|
|
|
if(hasObject)
|
|
|
|
{
|
2014-02-03 16:19:24 +01:00
|
|
|
Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject);
|
2014-02-12 14:45:10 +01:00
|
|
|
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400);
|
2014-02-12 14:00:53 +01:00
|
|
|
heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce);
|
2014-02-03 16:19:24 +01:00
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
hasObject = false;
|
|
|
|
heldObject = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2014-02-12 11:32:30 +01:00
|
|
|
|
2014-02-12 13:12:51 +01:00
|
|
|
Oyster::Math::Float radius = 4;
|
2014-02-12 11:32:30 +01:00
|
|
|
Oyster::Math::Float3 look = owner->GetLookDir().GetNormalized();
|
2014-02-12 13:12:51 +01:00
|
|
|
Oyster::Math::Float lenght = 10;
|
2014-02-12 11:32:30 +01:00
|
|
|
Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos;
|
2014-02-03 15:32:46 +01:00
|
|
|
|
2014-02-12 14:45:10 +01:00
|
|
|
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400);
|
2014-01-31 16:42:25 +01:00
|
|
|
|
2014-02-12 13:12:51 +01:00
|
|
|
Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius);
|
2014-02-12 10:43:41 +01:00
|
|
|
|
2014-02-12 11:32:30 +01:00
|
|
|
|
2014-02-12 10:43:41 +01:00
|
|
|
|
2014-01-31 14:05:52 +01:00
|
|
|
forcePushData args;
|
|
|
|
args.pushForce = pushForce;
|
2013-12-12 12:16:13 +01:00
|
|
|
|
2014-02-12 11:32:30 +01:00
|
|
|
Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction);
|
2014-02-20 16:02:53 +01:00
|
|
|
|
|
|
|
if(hitCone) delete hitCone;
|
2014-01-22 13:02:13 +01:00
|
|
|
}
|
|
|
|
|
2013-12-12 12:21:19 +01:00
|
|
|
/********************************************************
|
|
|
|
* Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack)
|
|
|
|
********************************************************/
|
2014-02-03 15:32:46 +01:00
|
|
|
void AttatchmentMassDriver::ForceZip(const WEAPON_FIRE &usage, float dt)
|
2013-12-12 12:16:13 +01:00
|
|
|
{
|
2014-02-13 09:58:14 +01:00
|
|
|
Oyster::Math::Float3 force = Oyster::Math::Float4(this->owner->GetLookDir()) * (1000);
|
2014-01-21 15:46:54 +01:00
|
|
|
|
2014-02-13 09:58:14 +01:00
|
|
|
this->owner->GetRigidBody()->ApplyImpulse(force);
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt)
|
|
|
|
{
|
2014-02-12 13:12:51 +01:00
|
|
|
if(hasObject) return; //this test checks if the weapon already has something picked up, if so then it cant use this function
|
2014-02-03 15:32:46 +01:00
|
|
|
|
|
|
|
PickUpObject(usage,dt); //first test if there is a nearby object to pickup
|
|
|
|
|
|
|
|
if(hasObject) return; //this test checks if the weapon has now picked up an object, if so then it shall not apply a force to suck in objects
|
|
|
|
|
|
|
|
|
|
|
|
//if no object has been picked up then suck objects towards you
|
2014-02-12 13:12:51 +01:00
|
|
|
Oyster::Math::Float radius = 4;
|
|
|
|
Oyster::Math::Float3 look = owner->GetLookDir().GetNormalized();
|
|
|
|
Oyster::Math::Float lenght = 10;
|
|
|
|
Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos;
|
2014-02-03 15:32:46 +01:00
|
|
|
|
2014-02-12 13:12:51 +01:00
|
|
|
Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (100);
|
|
|
|
|
|
|
|
Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius);
|
2014-02-03 15:32:46 +01:00
|
|
|
forcePushData args;
|
|
|
|
args.pushForce = -pushForce;
|
|
|
|
|
2014-02-12 13:12:51 +01:00
|
|
|
Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction);
|
2014-02-20 16:02:53 +01:00
|
|
|
|
|
|
|
if(hitCone) delete hitCone;
|
2014-02-03 15:32:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt)
|
|
|
|
{
|
2014-02-04 13:58:37 +01:00
|
|
|
Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized()*5;
|
2014-02-12 13:12:51 +01:00
|
|
|
Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,10);
|
2014-02-03 15:32:46 +01:00
|
|
|
|
2014-02-04 13:58:37 +01:00
|
|
|
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp);
|
2014-02-12 10:43:41 +01:00
|
|
|
|
2014-02-20 16:02:53 +01:00
|
|
|
if(hitSphere) delete hitSphere;
|
2014-02-03 15:32:46 +01:00
|
|
|
}
|