Skip to content

Commit 9e4a660

Browse files
committed
Ao remover uma unidade, devemos limpar as referencias para ela em outras taticas.
1 parent ec60893 commit 9e4a660

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

source/src/Army.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ Unit* Army::removeUnit(unsigned int i)
389389
units[i]->setID(i);
390390
}
391391

392+
// Remover referencias para a unidade removida
393+
for (int i = 0; i < units.size(); ++i)
394+
{
395+
for (int j = 0; j < units[i]->getTacticSize(); ++j)
396+
{
397+
Tactic* t = units[i]->getTacticAt(j);
398+
if ( t->getInfo().allyUnit == removed ){
399+
t->setInfo(TacticInfo(nullptr));
400+
}
401+
}
402+
}
403+
392404
return removed;
393405
}
394406

source/src/GuiElements.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,11 @@ void ComboBox::draw()
582582
}
583583
}
584584
else{
585-
SDL_Rect rect;
586-
rect.x = x;
587-
rect.y = y;
588-
rect.w = lenght*font->getPtSize();
589-
rect.h = cell_height * (int)(list.size()+1) + 1;
585+
// SDL_Rect rect;
586+
// rect.x = x;
587+
// rect.y = y;
588+
// rect.w = lenght*font->getPtSize();
589+
// rect.h = cell_height * (int)(list.size()+1) + 1;
590590
// SDL_RenderFillRect(renderer, &rect);
591591
}
592592

@@ -607,11 +607,11 @@ void ComboBox::draw()
607607
// Seta
608608
border->DrawImage(renderer, x + (border->getFrameWidth()*(i+1)), y, 2);
609609
}else{
610-
SDL_Rect rect;
611-
rect.x = x;
612-
rect.y = y;
613-
rect.w = lenght*font->getPtSize();
614-
rect.h = cell_height;
610+
// SDL_Rect rect;
611+
// rect.x = x;
612+
// rect.y = y;
613+
// rect.w = lenght*font->getPtSize();
614+
// rect.h = cell_height;
615615
// SDL_RenderFillRect(renderer, &rect);
616616
}
617617
}

source/src/GuiTactics.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ void TacticSet::setTactic(Tactic *tactic, int id)
126126

127127
delete guiTactic;
128128

129+
int allyid = 0;
130+
if (tactic->getInfo().allyUnit)
131+
allyid = tactic->getInfo().allyUnit->getID();
132+
129133
switch (tactic->getType())
130134
{
131135
case TACTIC_ATTACK_NEAREST_ENEMY:
@@ -137,19 +141,19 @@ void TacticSet::setTactic(Tactic *tactic, int id)
137141
break;
138142

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

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

147151
case TACTIC_KAMIKASE:
148152
guiTactic = new TacticKM(x,y, GID);
149153
break;
150154

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

155159
case TACTIC_MOVE_RANDOM:

source/src/Unit_Setup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ void Unit_Setup::onInputEvent(GuiElement* element, INPUT_EVENT action, SDL_Keysy
180180
squad_number.erase(squad_number.begin() + squad_focus->getID());
181181

182182
Game::getGlobalGame()->getEditingArmy()->removeUnit(squad_focus->getID());
183+
183184
squad_focus = nullptr;
184185
}
185186
return;

0 commit comments

Comments
 (0)