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"
|
2013-11-20 14:18:31 +01:00
|
|
|
|
|
|
|
using namespace GameLogic;
|
|
|
|
|
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-13 11:06:03 +01:00
|
|
|
maxNrOfSockets = 0;
|
2013-12-05 11:50:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~PrivateData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-10 09:57:05 +01:00
|
|
|
WEAPON_STATE weaponState;
|
|
|
|
|
|
|
|
AttatchmentSocket **attatchmentSockets;
|
2013-12-13 11:06:03 +01:00
|
|
|
int maxNrOfSockets;
|
2013-12-12 09:36:14 +01:00
|
|
|
int currentNrOfAttatchments;
|
2013-12-10 09:57:05 +01:00
|
|
|
|
2013-12-13 11:06:03 +01:00
|
|
|
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();
|
2013-12-13 11:06:03 +01:00
|
|
|
myData->maxNrOfSockets = MaxNrOfSockets;
|
2013-12-12 09:36:14 +01:00
|
|
|
myData->attatchmentSockets = new AttatchmentSocket*[MaxNrOfSockets];
|
|
|
|
for (int i = 0; i < MaxNrOfSockets; i++)
|
|
|
|
{
|
|
|
|
myData->attatchmentSockets[i] = new AttatchmentSocket();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
********************************************************/
|
2013-12-12 09:36:14 +01:00
|
|
|
void Weapon::Use(const WEAPON_FIRE &fireInput)
|
2013-12-10 09:57:05 +01:00
|
|
|
{
|
2013-12-13 11:06:03 +01:00
|
|
|
myData->selectedAttatchment->UseAttatchment(fireInput);
|
2013-12-10 09:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* Specific weapon usage implementation
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* Get functions for states
|
|
|
|
********************************************************/
|
|
|
|
bool Weapon::IsFireing()
|
|
|
|
{
|
|
|
|
return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIREING);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-12-13 11:06:03 +01:00
|
|
|
if(socketID < myData->maxNrOfSockets && 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
|
|
|
{
|
2013-12-13 11:06:03 +01:00
|
|
|
if(myData->currentNrOfAttatchments < myData->maxNrOfSockets)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|