Fix for replays and players that quit

This commit is contained in:
jsalmon3 2003-02-17 18:09:44 +00:00
parent 9411cef56a
commit 269016cb01
4 changed files with 35 additions and 19 deletions

View file

@ -130,6 +130,35 @@ local void ClearSavedAction(Unit* unit)
-- Commands
----------------------------------------------------------------------------*/
/**
** Player quit.
**
** @param player Player number that quit.
*/
global void CommandQuit(int player)
{
int i;
if (Players[player].TotalNumUnits != 0) {
// Set player to neutral, remove allied/enemy/shared vision status
Players[player].Type = PlayerNeutral;
for (i = 0; i < NumPlayers; ++i) {
if (i == player) {
continue;
}
Players[i].Allied &= ~(1 << player);
Players[i].Enemy &= ~(1 << player);
Players[i].SharedVision &= ~(1 << player);
Players[player].Allied &= ~(1 << i);
Players[player].Enemy &= ~(1 << i);
Players[player].SharedVision &= ~(1 << i);
}
SetMessage("Player \"%s\" has left the game", Players[player].Name);
} else {
SetMessage("Player \"%s\" has been killed", Players[player].Name);
}
}
/**
** Stop unit.
**

View file

@ -69,6 +69,8 @@ extern int BurnBuildingDamageRate; /// HP per second to damage buildings
** by the user the function with Send prefix should be used.
*/
/// Prepare command quit
extern void CommandQuit(int player);
/// Prepare command stop
extern void CommandStopUnit(Unit* unit);
/// Prepare command stand ground

View file

@ -598,6 +598,8 @@ local void DoNextReplay(void)
} else {
HandleCheats(val);
}
} else if( !strcmp(name,"quit") ) {
CommandQuit(posx);
} else {
DebugLevel0Fn("Invalid name: %s" _C_ name);
}

View file

@ -620,25 +620,6 @@ local void NetworkRemovePlayer(int player)
{
int i;
if (Players[player].TotalNumUnits != 0) {
// Set player to neutral, remove allied/enemy/shared vision status
Players[player].Type = PlayerNeutral;
for (i = 0; i < NumPlayers; ++i) {
if (i == player) {
continue;
}
Players[i].Allied &= ~(1 << player);
Players[i].Enemy &= ~(1 << player);
Players[i].SharedVision &= ~(1 << player);
Players[player].Allied &= ~(1 << i);
Players[player].Enemy &= ~(1 << i);
Players[player].SharedVision &= ~(1 << i);
}
SetMessage("Player \"%s\" has left the game", Players[player].Name);
} else {
SetMessage("Player \"%s\" has been killed", Players[player].Name);
}
// Remove player from Hosts and clear NetworkIn
for (i = 0; i < HostsCount; ++i) {
if (Hosts[i].PlyNr == player) {
@ -942,6 +923,8 @@ local void ParseNetworkCommand(const NetworkCommandQueue *ncq)
break;
case MessageQuit:
NetworkRemovePlayer(ncq->Data.X);
CommandLog("quit",NoUnitP,FlushCommands,ncq->Data.X,-1,NoUnitP,NULL,-1);
CommandQuit(ncq->Data.X);
break;
case MessageExtendedCommand: {
const NetworkExtendedCommand *nec;