-
Notifications
You must be signed in to change notification settings - Fork 1
/
Goal_Regroup.cpp
112 lines (84 loc) · 2.73 KB
/
Goal_Regroup.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Goal_Regroup.h"
#include "Raven_Teammate.h"
#include "Raven_Bot.h"
#include "navigation/Raven_PathPlanner.h"
#include "Raven_Game.h"
#include "Raven_Map.h"
#include "Messaging/Telegram.h"
#include "Raven_Messages.h"
#include "goals/Goal_SeekToPosition.h"
#include "goals/Goal_FollowPath.h"
Goal_Regroup::Goal_Regroup(Raven_Teammate * pOwner):
Goal_Composite<Raven_Teammate>(pOwner, goal_regroup),
m_bDestinationIsSet(false)
{
}
Goal_Regroup::~Goal_Regroup()
{
}
//------------------------------ Activate -------------------------------------
//-----------------------------------------------------------------------------
void Goal_Regroup::Activate()
{
m_iStatus = active;
//if this goal is reactivated then there may be some existing subgoals that
//must be removed
RemoveAllSubgoals();
if (m_pOwner->TeamSize() > 1) {
//if (!m_bDestinationIsSet)
//{
// //grab the regroup location
// m_CurrentDestination = m_pOwner->GetRegroupLocation();
// m_bDestinationIsSet = true;
//}
if (!m_bDestinationIsSet && m_pOwner->HasPartner())
{
m_CurrentDestination = m_pOwner->GetPartner()->Pos();
m_bDestinationIsSet = true;
}
if (m_bDestinationIsSet) {
//and request a path to that position
m_pOwner->GetPathPlanner()->RequestPathToPosition(m_CurrentDestination);
//the bot may have to wait a few update cycles before a path is calculated
//so for appearances sake it simple ARRIVES at the destination until a path
//has been found
AddSubgoal(reinterpret_cast<Goal<Raven_Teammate> *>(new Goal_SeekToPosition(m_pOwner, m_CurrentDestination)));
}
}
}
//------------------------------ Process -------------------------------------
//-----------------------------------------------------------------------------
int Goal_Regroup::Process()
{
//if status is inactive, call Activate()
ActivateIfInactive();
//process the subgoals
m_iStatus = ProcessSubgoals();
return m_iStatus;
}
//---------------------------- HandleMessage ----------------------------------
//-----------------------------------------------------------------------------
bool Goal_Regroup::HandleMessage(const Telegram& msg)
{
//first, pass the message down the goal hierarchy
bool bHandled = ForwardMessageToFrontMostSubgoal(msg);
//if the msg was not handled, test to see if this goal can handle it
if (bHandled == false)
{
switch (msg.Msg)
{
case Msg_PathReady:
//clear any existing goals
RemoveAllSubgoals();
AddSubgoal(reinterpret_cast<Goal<Raven_Teammate> *>(new Goal_FollowPath(m_pOwner,
m_pOwner->GetPathPlanner()->GetPath())));
return true; //msg handled
case Msg_NoPathAvailable:
m_iStatus = failed;
return true; //msg handled
default: return false;
}
}
//handled by subgoals
return true;
}