-
Notifications
You must be signed in to change notification settings - Fork 1
/
Raven_Leader.cpp
65 lines (57 loc) · 1.84 KB
/
Raven_Leader.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
#include "Raven_Leader.h"
#include "lua/Raven_Scriptor.h"
#include "Raven_SensoryMemory.h"
#include "time/Regulator.h"
#include "Raven_Messages.h"
#include "Messaging/MessageDispatcher.h"
#include "Debug\DebugConsole.h"
Raven_Leader::Raven_Leader(Raven_Game * world, Vector2D pos, Raven_TeamManager * teammanager):
Raven_Leader(world, pos, teammanager, new Goal_Think(this))
{
}
Raven_Leader::Raven_Leader(Raven_Game * world, Vector2D pos, Raven_TeamManager * teammanager, Goal_Think * goal):
Raven_Teammate(world, pos, teammanager, goal),
m_savedTarget(NULL)
{
m_pLocationSendingRegulator = new Regulator(script->GetDouble("Leader_LocationSendingFreq"));
m_pLocationTargetRegulator = new Regulator(script->GetDouble("Leader_LocationTargetFreq"));
}
Raven_Leader::~Raven_Leader()
{
}
void Raven_Leader::Update()
{
if (isPossessed())
{
m_savedTarget = NULL;
}
else
{
bool targetChanged = false;
Raven_Bot* target = GetTargetBot();
if (target && target != m_savedTarget && !target->isDead() && TeamSize() > 1) {
m_savedTarget = target;
targetChanged = true;
}
else if (!target) {
m_savedTarget = NULL;
}
if (m_pLocationSendingRegulator->isReady() && TeamSize() > 1) {
//send location to teammates
m_savedPosition = Pos();
m_pTeamManager->SendMessageToAllTeammates(this, SEND_MSG_IMMEDIATELY, Msg_LeaderLocation, static_cast<void*>(&m_savedPosition));
}
if (target && (m_pLocationTargetRegulator->isReady() || targetChanged) && TeamSize() > 1) {
//send target location to teammates
//prepare order
m_order.target = target;
m_order.order = order_attack;
m_pTeamManager->SendMessageToAllTeammates(this, SEND_MSG_IMMEDIATELY, Msg_LeaderTargetLocation, static_cast<void*>(&m_order));
}
}
Raven_Bot::Update();
}
bool Raven_Leader::HasTag(int tag) const
{
return Raven_Teammate::HasTag(tag) || tag == leader_bot;
}