Skip to content

Commit c670f75

Browse files
author
tvo
committed
* Apply fixed patch by colorblind, doesn't desync the game anymore after choosing resign.
* Reapply part of my fix for com dies game ends exploit. (I assume it was wrongly merged out in r1354?) git-svn-id: https://spring.clan-sy.com/svn/spring/trunk@1434 37977431-3df6-0310-b722-df95706aa16b
1 parent 92e87d6 commit c670f75

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

rts/Game/Team.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ void CTeam::Update()
173173
lastStatSave+=480;
174174
statHistory.push_back(currentStats);
175175
}
176+
177+
/* Kill the player on 'com dies = game ends' games. This can't be done in
178+
CTeam::CommanderDied anymore, because that function is called in
179+
CUnit::ChangeTeam(), hence it'd cause a random amount of the shared units
180+
to be killed if the commander is among them. Also, ".take" would kill all
181+
units once it transfered the commander. */
182+
if(gs->gameMode==1 && numCommanders<=0){
183+
for(list<CUnit*>::iterator ui=uh->activeUnits.begin();ui!=uh->activeUnits.end();++ui){
184+
if((*ui)->team==teamNum && !(*ui)->unitDef->isCommander)
185+
(*ui)->KillUnit(true,false,0);
186+
}
187+
// Set to 1 to prevent above loop from being done every update.
188+
numCommanders = 1;
189+
}
176190
}
177191

178192
void CTeam::AddUnit(CUnit* unit,AddType type)
@@ -226,10 +240,4 @@ void CTeam::CommanderDied(CUnit* commander)
226240
{
227241
assert(commander->unitDef->isCommander);
228242
--numCommanders;
229-
if(gs->gameMode==1 && numCommanders<=0){
230-
for(list<CUnit*>::iterator ui=uh->activeUnits.begin();ui!=uh->activeUnits.end();++ui){
231-
if((*ui)->team==teamNum)
232-
(*ui)->KillUnit(true,false,0);
233-
}
234-
}
235243
}

rts/Game/UI/QuitBox.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ void CQuitBox::MouseRelease(int x,int y,int button)
194194

195195
if(InBox(mx,my,box+resignQuitBox) || InBox(mx,my,box+resignBox) || InBox(mx,my,box+giveAwayBox) && !gs->Team(shareTeam)->isDead && !gs->Team(gu->myTeam)->isDead){
196196
set<CUnit*>* tu=&gs->Team(gu->myTeam)->units;
197+
//select all units
198+
selectedUnits.ClearSelected();
199+
for(set<CUnit*>::iterator ui=tu->begin();ui!=tu->end();++ui){
200+
selectedUnits.AddUnit(*ui);
201+
}
202+
Command c;
197203
// give away all units (and resources)
198204
if(InBox(mx,my,box+giveAwayBox)){
199-
//select all units
200-
selectedUnits.ClearSelected();
201-
for(set<CUnit*>::iterator ui=tu->begin();ui!=tu->end();++ui){
202-
selectedUnits.AddUnit(*ui);
203-
}
204205
//make sure the units are stopped and that the selection is transmitted
205-
Command c;
206206
c.id=CMD_STOP;
207207
selectedUnits.GiveCommand(c,false);
208208
net->SendData<unsigned char, unsigned char, unsigned char, float, float>(
@@ -218,10 +218,10 @@ void CQuitBox::MouseRelease(int x,int y,int button)
218218
net->SendSTLData<unsigned char, std::string>(NETMSG_CHAT, gu->myPlayerNum, givenAwayMsg);
219219
}
220220
// resign, so self-d all units
221-
if(InBox(mx,my,box+resignQuitBox) || InBox(mx,my,box+resignBox))
222-
for(set<CUnit*>::iterator ui=tu->begin();ui!=tu->end();++ui){
223-
(*ui)->KillUnit(true,false,0);
224-
}
221+
if(InBox(mx,my,box+resignQuitBox) || InBox(mx,my,box+resignBox)) {
222+
c.id=CMD_SELFD;
223+
selectedUnits.GiveCommand(c,false);
224+
}
225225
// (resign and) quit, so leave the game
226226
if(InBox(mx,my,box+resignQuitBox)){
227227
info->AddLine("User exited");

0 commit comments

Comments
 (0)