Skip to content

Commit

Permalink
Ao remover uma unidade, devemos limpar as referencias para ela em out…
Browse files Browse the repository at this point in the history
…ras taticas.
  • Loading branch information
MateusMP committed Oct 15, 2014
1 parent ec60893 commit 9e4a660
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
12 changes: 12 additions & 0 deletions source/src/Army.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,18 @@ Unit* Army::removeUnit(unsigned int i)
units[i]->setID(i);
}

// Remover referencias para a unidade removida
for (int i = 0; i < units.size(); ++i)
{
for (int j = 0; j < units[i]->getTacticSize(); ++j)
{
Tactic* t = units[i]->getTacticAt(j);
if ( t->getInfo().allyUnit == removed ){
t->setInfo(TacticInfo(nullptr));
}
}
}

return removed;
}

Expand Down
20 changes: 10 additions & 10 deletions source/src/GuiElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ void ComboBox::draw()
}
}
else{
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = lenght*font->getPtSize();
rect.h = cell_height * (int)(list.size()+1) + 1;
// SDL_Rect rect;
// rect.x = x;
// rect.y = y;
// rect.w = lenght*font->getPtSize();
// rect.h = cell_height * (int)(list.size()+1) + 1;
// SDL_RenderFillRect(renderer, &rect);
}

Expand All @@ -607,11 +607,11 @@ void ComboBox::draw()
// Seta
border->DrawImage(renderer, x + (border->getFrameWidth()*(i+1)), y, 2);
}else{
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = lenght*font->getPtSize();
rect.h = cell_height;
// SDL_Rect rect;
// rect.x = x;
// rect.y = y;
// rect.w = lenght*font->getPtSize();
// rect.h = cell_height;
// SDL_RenderFillRect(renderer, &rect);
}
}
Expand Down
10 changes: 7 additions & 3 deletions source/src/GuiTactics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ void TacticSet::setTactic(Tactic *tactic, int id)

delete guiTactic;

int allyid = 0;
if (tactic->getInfo().allyUnit)
allyid = tactic->getInfo().allyUnit->getID();

switch (tactic->getType())
{
case TACTIC_ATTACK_NEAREST_ENEMY:
Expand All @@ -137,19 +141,19 @@ void TacticSet::setTactic(Tactic *tactic, int id)
break;

case TACTIC_ATTACK_COLLAB:
guiTactic = new TacticCA(x,y, id, tactic->getInfo().allyUnit->getID(), GID);
guiTactic = new TacticCA(x,y, id, allyid, GID);
break;

case TACTIC_DEFENSE_COLLAB:
guiTactic = new TacticCD(x,y, id, tactic->getInfo().allyUnit->getID(), GID);
guiTactic = new TacticCD(x,y, id, allyid, GID);
break;

case TACTIC_KAMIKASE:
guiTactic = new TacticKM(x,y, GID);
break;

case TACTIC_RETREAT:
guiTactic = new TacticRT(x,y, id, tactic->getInfo().allyUnit->getID(), GID);
guiTactic = new TacticRT(x,y, id, allyid, GID);
break;

case TACTIC_MOVE_RANDOM:
Expand Down
1 change: 1 addition & 0 deletions source/src/Unit_Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void Unit_Setup::onInputEvent(GuiElement* element, INPUT_EVENT action, SDL_Keysy
squad_number.erase(squad_number.begin() + squad_focus->getID());

Game::getGlobalGame()->getEditingArmy()->removeUnit(squad_focus->getID());

squad_focus = nullptr;
}
return;
Expand Down

0 comments on commit 9e4a660

Please sign in to comment.