2013-11-20 14:18:31 +01:00
|
|
|
#include "Weapon.h"
|
2013-12-10 09:57:05 +01:00
|
|
|
#include "AttatchmentMassDriver.h"
|
2014-01-27 13:54:57 +01:00
|
|
|
#include "Player.h"
|
2014-01-21 15:46:54 +01:00
|
|
|
|
2013-11-20 14:18:31 +01:00
|
|
|
|
|
|
|
using namespace GameLogic;
|
2014-01-14 10:28:12 +01:00
|
|
|
using namespace Utility::DynamicMemory;
|
2013-11-20 14:18:31 +01:00
|
|
|
|
2013-12-05 11:50:39 +01:00
|
|
|
|
|
|
|
Weapon::Weapon()
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
weaponState = WEAPON_STATE_IDLE;
|
|
|
|
selectedAttatchment = 0;
|
|
|
|
currentNrOfAttatchments = 0;
|
|
|
|
selectedSocketID = 0;
|
|
|
|
attatchmentSockets = 0;
|
2013-11-20 14:18:31 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 13:54:57 +01:00
|
|
|
Weapon::Weapon(int MaxNrOfSockets,Player *owner)
|
2013-12-12 09:36:14 +01:00
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
attatchmentSockets.Resize(MaxNrOfSockets);
|
2014-01-27 13:54:57 +01:00
|
|
|
attatchmentSockets[0] = new AttatchmentSocket();
|
|
|
|
|
|
|
|
weaponState = WEAPON_STATE_IDLE;
|
|
|
|
currentNrOfAttatchments = 0;
|
|
|
|
selectedAttatchment = 0;
|
|
|
|
|
|
|
|
//give the weapon a massdriver on socket 0
|
|
|
|
IAttatchment *mD = new AttatchmentMassDriver(*owner);
|
|
|
|
attatchmentSockets[0]->SetAttatchment(mD);
|
|
|
|
this->currentNrOfAttatchments = 1;
|
|
|
|
SelectAttatchment(0);
|
|
|
|
//give the weapon a massdriver on socket 0
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
|
|
|
|
2013-11-20 14:18:31 +01:00
|
|
|
|
|
|
|
Weapon::~Weapon(void)
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
for (unsigned int i = 0; i < this->attatchmentSockets.Size(); i++)
|
|
|
|
{
|
|
|
|
delete this->attatchmentSockets[i];
|
|
|
|
this->attatchmentSockets[i] = 0;
|
|
|
|
}
|
2013-11-20 14:18:31 +01:00
|
|
|
}
|
2013-12-10 09:57:05 +01:00
|
|
|
|
|
|
|
/********************************************************
|
2013-12-10 11:17:25 +01:00
|
|
|
* Uses the weapon based on the input given and the current chosen attatchment
|
2013-12-10 09:57:05 +01:00
|
|
|
********************************************************/
|
2014-01-21 15:46:54 +01:00
|
|
|
void Weapon::Use(const WEAPON_FIRE &usage, float dt)
|
2013-12-10 09:57:05 +01:00
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
if (selectedAttatchment)
|
2013-12-18 08:30:58 +01:00
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
selectedAttatchment->UseAttatchment(usage, dt);
|
2013-12-18 08:30:58 +01:00
|
|
|
}
|
|
|
|
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* Specific weapon usage implementation
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* Get functions for states
|
|
|
|
********************************************************/
|
|
|
|
bool Weapon::IsFireing()
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
return (weaponState == WEAPON_STATE::WEAPON_STATE_FIRING);
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Weapon::IsIdle()
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
return (weaponState == WEAPON_STATE::WEAPON_STATE_IDLE);
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Weapon::IsReloading()
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
return (weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING);
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
bool Weapon::IsValidSocket(int socketID)
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
if(socketID < (int)attatchmentSockets.Size() && socketID >= 0)
|
2013-12-12 09:36:14 +01:00
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
if (attatchmentSockets[socketID]->GetAttatchment() != 0)
|
2013-12-12 09:36:14 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Weapon::GetCurrentSocketID()
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
return selectedSocketID;
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-13 11:06:03 +01:00
|
|
|
void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner)
|
2013-12-12 09:36:14 +01:00
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
if(currentNrOfAttatchments < (int)attatchmentSockets.Size())
|
2013-12-12 09:36:14 +01:00
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
attatchmentSockets[currentNrOfAttatchments]->SetAttatchment(attatchment);
|
|
|
|
currentNrOfAttatchments++;
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 11:06:03 +01:00
|
|
|
void Weapon::SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner)
|
2013-12-12 09:36:14 +01:00
|
|
|
{
|
|
|
|
if (IsValidSocket(socketID))
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
attatchmentSockets[socketID]->SetAttatchment(attatchment);
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Weapon::RemoveAttatchment(int socketID)
|
|
|
|
{
|
|
|
|
if (IsValidSocket(socketID))
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
attatchmentSockets[socketID]->RemoveAttatchment();
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Weapon::SelectAttatchment(int socketID)
|
|
|
|
{
|
|
|
|
if (IsValidSocket(socketID))
|
|
|
|
{
|
2014-01-21 15:46:54 +01:00
|
|
|
selectedAttatchment = attatchmentSockets[socketID]->GetAttatchment();
|
|
|
|
selectedSocketID = socketID;
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Weapon::Update(float dt)
|
|
|
|
{
|
2014-02-04 22:33:39 +01:00
|
|
|
if(!selectedAttatchment) return;
|
|
|
|
|
2014-02-03 15:32:46 +01:00
|
|
|
selectedAttatchment->Update(dt);
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|