2013-11-20 14:18:31 +01:00
|
|
|
#include "Weapon.h"
|
2013-12-10 09:57:05 +01:00
|
|
|
#include "AttatchmentSocket.h"
|
|
|
|
#include "AttatchmentMassDriver.h"
|
2014-01-14 10:28:12 +01:00
|
|
|
#include "DynamicArray.h"
|
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
|
|
|
struct Weapon::PrivateData
|
2013-11-20 14:18:31 +01:00
|
|
|
{
|
2013-12-05 11:50:39 +01:00
|
|
|
PrivateData()
|
|
|
|
{
|
2013-12-10 09:57:05 +01:00
|
|
|
weaponState = WEAPON_STATE_IDLE;
|
2013-12-13 11:06:03 +01:00
|
|
|
selectedAttatchment = 0;
|
2013-12-12 09:36:14 +01:00
|
|
|
currentNrOfAttatchments = 0;
|
|
|
|
selectedSocketID = 0;
|
2013-12-19 12:32:23 +01:00
|
|
|
attatchmentSockets = 0;
|
2013-12-05 11:50:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~PrivateData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-10 09:57:05 +01:00
|
|
|
WEAPON_STATE weaponState;
|
|
|
|
|
2014-01-14 10:28:12 +01:00
|
|
|
DynamicArray<SmartPointer<AttatchmentSocket>> attatchmentSockets;
|
2013-12-12 09:36:14 +01:00
|
|
|
int currentNrOfAttatchments;
|
2014-01-14 10:28:12 +01:00
|
|
|
SmartPointer<IAttatchment> selectedAttatchment;
|
2013-12-12 09:36:14 +01:00
|
|
|
int selectedSocketID;
|
2013-12-10 09:57:05 +01:00
|
|
|
|
2013-12-05 11:50:39 +01:00
|
|
|
}myData;
|
|
|
|
|
|
|
|
Weapon::Weapon()
|
|
|
|
{
|
|
|
|
myData = new PrivateData();
|
2013-11-20 14:18:31 +01:00
|
|
|
}
|
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
Weapon::Weapon(int MaxNrOfSockets)
|
|
|
|
{
|
|
|
|
myData = new PrivateData();
|
2014-01-14 10:28:12 +01:00
|
|
|
myData->attatchmentSockets.Resize(MaxNrOfSockets);
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
|
|
|
|
2013-11-20 14:18:31 +01:00
|
|
|
|
|
|
|
Weapon::~Weapon(void)
|
|
|
|
{
|
2013-12-05 11:50:39 +01:00
|
|
|
delete myData;
|
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-16 11:17:19 +01:00
|
|
|
void Weapon::Use(const WEAPON_FIRE &usage)
|
2013-12-10 09:57:05 +01:00
|
|
|
{
|
2013-12-18 08:30:58 +01:00
|
|
|
if (myData->selectedAttatchment)
|
|
|
|
{
|
2014-01-16 11:17:19 +01:00
|
|
|
myData->selectedAttatchment->UseAttatchment(usage);
|
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-15 11:03:25 +01:00
|
|
|
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIRING);
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Weapon::IsIdle()
|
|
|
|
{
|
|
|
|
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_IDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Weapon::IsReloading()
|
|
|
|
{
|
|
|
|
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING);
|
|
|
|
}
|
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
bool Weapon::IsValidSocket(int socketID)
|
|
|
|
{
|
2014-01-14 10:28:12 +01:00
|
|
|
if(socketID < myData->attatchmentSockets.Size() && socketID >= 0)
|
2013-12-12 09:36:14 +01:00
|
|
|
{
|
|
|
|
if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Weapon::GetCurrentSocketID()
|
|
|
|
{
|
|
|
|
return myData->selectedSocketID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-14 10:28:12 +01:00
|
|
|
if(myData->currentNrOfAttatchments < myData->attatchmentSockets.Size())
|
2013-12-12 09:36:14 +01:00
|
|
|
{
|
|
|
|
myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment);
|
|
|
|
myData->currentNrOfAttatchments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
myData->attatchmentSockets[socketID]->SetAttatchment(attatchment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Weapon::RemoveAttatchment(int socketID)
|
|
|
|
{
|
|
|
|
if (IsValidSocket(socketID))
|
|
|
|
{
|
|
|
|
myData->attatchmentSockets[socketID]->RemoveAttatchment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Weapon::SelectAttatchment(int socketID)
|
|
|
|
{
|
|
|
|
if (IsValidSocket(socketID))
|
|
|
|
{
|
2013-12-13 11:06:03 +01:00
|
|
|
myData->selectedAttatchment = myData->attatchmentSockets[socketID]->GetAttatchment();
|
2013-12-12 09:36:14 +01:00
|
|
|
myData->selectedSocketID = socketID;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|