-
Notifications
You must be signed in to change notification settings - Fork 0
/
AimedFiringTask.cpp
80 lines (68 loc) · 1.88 KB
/
AimedFiringTask.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "AimedFiringTask.h"
#include "Node.h"
#include "PhysicalObject.h"
#include "PosQuat.h"
#include <iostream>
using namespace std;
AimedFiringTask::AimedFiringTask()
{
Init();
}
AimedFiringTask::~AimedFiringTask()
{
SetTarget(0);
}
void AimedFiringTask::ApplyTask(PhysicalObject *pObject, float fDeltaTime)
{
if (pObject && m_pTarget && m_pTarget->IsAlive())
{ //fire the ship's weapons if they aren't on cooldown
if ((pObject->GetWeaponOne()) && (pObject->GetWeaponOne()->IsReady()))
{ //fire weapon one!
//calculate aim
VECTOR3 vAim;
vAim.x = m_pTarget->GetNode()->m_PosQuat.pos.x - pObject->GetNode()->m_PosQuat.pos.x;
vAim.y = m_pTarget->GetNode()->m_PosQuat.pos.y - pObject->GetNode()->m_PosQuat.pos.y;
vAim.z = m_pTarget->GetNode()->m_PosQuat.pos.z - pObject->GetNode()->m_PosQuat.pos.z;
pObject->GetWeaponOne()->SetAim(vAim);
pObject->GetWeaponOne()->SetOwner(pObject);
//then fire
pObject->GetWeaponOne()->Fire();
}
if ((pObject->GetWeaponTwo()) && (pObject->GetWeaponTwo()->IsReady()))
{ //fire weapon two!
//calculate aim
VECTOR3 vAim;
vAim.x = m_pTarget->GetNode()->m_PosQuat.pos.x - pObject->GetNode()->m_PosQuat.pos.x;
vAim.y = m_pTarget->GetNode()->m_PosQuat.pos.y - pObject->GetNode()->m_PosQuat.pos.y;
vAim.z = m_pTarget->GetNode()->m_PosQuat.pos.z - pObject->GetNode()->m_PosQuat.pos.z;
pObject->GetWeaponTwo()->SetAim(vAim);
pObject->GetWeaponTwo()->SetOwner(pObject);
//then fire!!!!
pObject->GetWeaponTwo()->Fire();
}
}
}
void AimedFiringTask::Init()
{
m_pTarget = 0;
}
void AimedFiringTask::Print(int indent) const
{
printf("%*sAimedFiringTask 0x%p (%s)\n", indent, "", this);
}
void AimedFiringTask::SetTarget(PhysicalObject *pTarget)
{
if (m_pTarget != pTarget)
{
if (m_pTarget)
{
m_pTarget->Release();
m_pTarget = 0;
}
if (pTarget)
{
m_pTarget = pTarget;
m_pTarget->AddRef();
}
}
}