-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategie.cpp
152 lines (140 loc) · 5.47 KB
/
strategie.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "strategie.h"
#include "pathfinder.h"
#include "warrior.h"
#include "MersenneTwister.h"
#include "clan.h"
void StrategieExploration::executeStrategie(Clan *clan)
{
Pathfinder* tmpFind;
foreach(ClanMember* m, clan->getMembers())
{
tmpFind=(Pathfinder*)m;
if(tmpFind->getVector().x == 0)
{
Position tmp((genrand_int32()%10)-5,(genrand_int32()%10)-5);
if(tmp.x >= 0) tmp.x+=1;
if(tmp.y >= 0) tmp.y+=1;
tmpFind->setVector(tmp);
}
}
}
void StrategieDefence::executeStrategie(Clan *clan)
{
Pathfinder* mPath;
if(!clan->isPromotedPhase())//cas ou défense normale
{
foreach(ClanMember* m, clan->getMembers())
{
switch(m->getType())
{
case pathfinder:
mPath=(Pathfinder*)m;
if(!mPath->isPromoted() || !mPath->isGoingToMerge())
{
// Pour les pathfinders restants il couvre la map de manière aléatoire
if(mPath->getVector() == Position(0,0))
{
Position tmp((genrand_int32()%10)-5,(genrand_int32()%10)-5);
if(tmp.x >= 0) tmp.x+=1;
if(tmp.y >= 0) tmp.y+=1;
mPath->setVector(tmp);
}
}
else
{
if(mPath->isGoingToMerge() && mPath->getObjectif() == mPath->getCurrent() && mPath->getTargetToMerged()->getCurrent() == mPath->getObjectif())
{
//alors delete 2 eclaireur a cette position et creer un warrior
// L'objectif du guerrier est de rejoindre le camp (ressource du clan) le plus proche
clan->addMember(mPath->getCurrent(),clan->plusProcheRessource(mPath->getCurrent())->getPosition(),warrior,Alliance(clan->getAlliance()));
cout <<"MERGED IN : {"<< mPath->getCurrent().x<<","<< mPath->getCurrent().y<<"}"<< endl;
// Suppression des deux pathfinders
clan->removeMember(mPath->getTargetToMerged()->getId());
mPath->getTargetToMerged()->setPromoted(false);
clan->removeMember(mPath->getId());
}
}
break;
case warrior://STRATEGIE DEFENCE WARRIOR
break;
case robot://STRATEGIE DEFENCE ROBOT
break;
}
}
}
else//cas juste après la "course aux ressources"
{//80% des eclaireurs vont entamer une procedure de mutation en warrior en rejoignant un autre eclaireur
foreach(ClanMember* m, clan->getMembers())
{
if(clan->getNbWarrior()==0 && !((Pathfinder*)m)->isPromoted()&& (genrand_int32()%100)<PROBA_PROMOTED)
{
((Pathfinder*)m)->setPromoted(true);
m->setVector(Position(1,1));
}
else
{
if(!((Pathfinder*)m)->isPromoted())
{
m->setObjectif(m->getCurrent());
}
}
}
clan->setPromotedPhase(false);
}
}
void StrategieAttaque::executeStrategie(Clan *clan)
{
Resource* resourceTarget;
foreach(ClanMember* m, clan->getMembers())
{
switch(m->getType())
{
case warrior:
{
Warrior * ww = (Warrior*)m;
ww->setVector(Position(0,0));
if(ww->getFollowing() == NULL)
{
ww->getNearestVise(1);
if(ww->getVise() == NULL)
{
Resource * tmp;
if(clan->getAlliance() == JEDI)
tmp=clan->getPlanet()->getClan(SITH)->plusProcheRessource(ww->getCurrent());
else
tmp=clan->getPlanet()->getClan(JEDI)->plusProcheRessource(ww->getCurrent());
ww->setObjectif(tmp->getPosition());
}
else //on suit l'ennemi
{
ww->setObjectif(ww->getVise()->getCurrent());
}
}
break;
}
case pathfinder://recherche la plus proche ressource enemie pour la capturer
Pathfinder * mm=(Pathfinder*)m;
if(m->getCurrent()!= m->getObjectif() || mm->getResourceTargeted() == NULL)
{
if(m->getAlliance()== JEDI)
resourceTarget=clan->getPlanet()->plusProcheRessourceClan(m->getCurrent(),SITH);
else
resourceTarget=clan->getPlanet()->plusProcheRessourceClan(m->getCurrent(),JEDI);
m->setObjectif(resourceTarget->getPosition());
mm->setResourceTargeted(resourceTarget);
Warrior* w=(Warrior*)m->getFollowerWarrior();
if(w != NULL && mm->getFollowers().count()/(float)clan->getMembers().count() <= 0.15 )//5% du clan max
mm->addFollower(w);
}
else
{
if(m->getCurrent()==m->getObjectif())
{
m->setVector(Position(0,0));
mm->catchingRessource();
}
}
break;
}
}
}