-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquad.cpp
More file actions
105 lines (95 loc) · 1.92 KB
/
squad.cpp
File metadata and controls
105 lines (95 loc) · 1.92 KB
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
#include "squad.h"
// Squad Class
Squad::Squad(int posx, int posy, int size, int team, Pathfinder* pathfinder)
{
m_pPathfinder = pathfinder;
m_iPosX = posx;
m_iPosY = posy;
m_iTeam = team;
m_iInterval = 2;
int i = 0;
// while(i < size)
// {
// m_lActorList.push_back(new Actor(m_iPosX + i,m_iPosY,'@',m_iTeam));
// i++;
// }
}
Squad::~Squad()
{
for(std::list<Actor*>::iterator it = m_lActorList.begin(); it != m_lActorList.end();++it)
{
delete (*it);
}
m_lActorList.clear();
}
void Squad::Update(ActorAI* ai)
{
for(std::list<Actor*>::iterator it = m_lActorList.begin(); it != m_lActorList.end();++it)
{
if((*it)->isDead())
{
it = m_lActorList.erase(it);
}
ai->UpdateActor((*it));
}
}
int Squad::getTeam()
{
return m_iTeam;
}
void Squad::setMoveTarget(int x, int y)
{
for(std::list<Actor*>::iterator it = m_lActorList.begin(); it != m_lActorList.end();++it)
{
std::list<Point> *f_pPath = m_pPathfinder->FindPath((*it)->getPosX(),(*it)->getPosY(),x,y);
if(f_pPath)
(*it)->setPath(f_pPath);
}
}
void Squad::setTargetPos(int x, int y)
{
for(std::list<Actor*>::iterator it = m_lActorList.begin(); it != m_lActorList.end();++it)
{
(*it)->setTargetPos(x, y);
}
}
int Squad::getTargetPosX()
{
return (*m_lActorList.begin())->getTargetPosX();
}
int Squad::getTargetPosY()
{
return (*m_lActorList.begin())->getTargetPosY();
}
void Squad::clearTargetPos()
{
for(std::list<Actor*>::iterator it = m_lActorList.begin(); it != m_lActorList.end();++it)
{
(*it)->clearTargetPos();
}
}
void Squad::addToSquad(Actor *actor)
{
if(m_iTeam == actor->getTeam())
{
actor->setSquad(this);
m_lActorList.push_back(actor);
}
else
std::cout << "Wrong team!" << std::endl;
}
int Squad::getPosX()
{
return m_iPosX;
}
int Squad::getPosY()
{
return m_iPosY;
}
void Squad::setFacing(int x, int y)
{
for(std::list<Actor*>::iterator it = m_lActorList.begin(); it != m_lActorList.end();++it)
{
(*it)->setFacing(x,y);
}
}