Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ntut-Tu committed May 31, 2024
1 parent 432f6de commit f66ad26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
21 changes: 10 additions & 11 deletions include/AI/AIGroupCommander.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,18 @@ class AIGroupCommander {
updateOffensiveTroopAttackTarget();
}
void updateDefensiveGroup(){
int t=0;
for(auto i : m_defensiveGroup){
if(i->getHealth()->ifDead()){
m_defensiveGroup.erase(m_defensiveGroup.begin()+t);
for(int i = static_cast<int>(m_defensiveGroup.size());i>0;--i ){
if(m_defensiveGroup[i-1]->getHealth()->ifDead()){
m_defensiveGroup.erase(m_defensiveGroup.begin()+i-1);
}else{
autoAttack(i,AUTO_ATTACK_METHOD);
autoAttack(m_defensiveGroup[i-1],AUTO_ATTACK_METHOD);
};
t++;
}
std::vector<std::shared_ptr<Avatar>> temp = m_AIAvatarManager->getAvatarArray();
for(int i=static_cast<int>(temp.size())-1;i>=0;i--){
if(temp[i]->getAIType()==AI_Type::NONE){
temp[i]->setAIType(AI_Type::DEFENCE);
m_defensiveGroup.push_back(temp[i]);
}else{
break;
}
}
}
Expand Down Expand Up @@ -140,10 +136,13 @@ class AIGroupCommander {
return;
}
// attack
for (auto j : i) {
m_AIAvatarManager->assignMoveOrderToAvatar(j,targetCell);
for (int j=static_cast<int>(i.size());j>0;--j) {
if(i[j-1]->getHealth()->ifDead()){
i.erase(i.begin()+j-1);
}
m_AIAvatarManager->assignMoveOrderToAvatar(i[j-1],targetCell);
m_AIAvatarManager->assignAttackOrderToAvatar(
j, targetCell,HouseType::ENEMY);
i[j-1], targetCell,HouseType::ENEMY);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/AI/EnemyScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void EnemyScripts::modeUpdate() {
buildADV();
spawnUnit();
}else if(enemyAvatarCount<MAX_TROOPS_SIZE){

spawnUnit();
}else{

Expand Down

0 comments on commit f66ad26

Please sign in to comment.