End network game early if there is no red or blue team player

This commit is contained in:
Benau 2018-08-10 15:08:19 +08:00
parent 00c0fecb27
commit 95f3dfc01a
7 changed files with 34 additions and 4 deletions

View File

@ -25,6 +25,7 @@
#include "guiengine/modaldialog.hpp"
#include "guiengine/widget.hpp"
#include "modes/world.hpp"
#include "network/network_config.hpp"
#include "states_screens/state_manager.hpp"
#include <irrlicht.h>
@ -90,7 +91,8 @@ Screen::~Screen()
*/
void Screen::init()
{
if(m_pause_race && World::getWorld())
if (m_pause_race && World::getWorld() &&
!NetworkConfig::get()->isNetworking())
World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE);
} // init
@ -111,7 +113,8 @@ void Screen::push()
*/
void Screen::tearDown()
{
if(m_pause_race && World::getWorld())
if (m_pause_race && World::getWorld() &&
!NetworkConfig::get()->isNetworking())
World::getWorld()->scheduleUnpause();
} // tearDown

View File

@ -457,6 +457,9 @@ void SoccerWorld::setBallHitter(unsigned int kart_id)
*/
bool SoccerWorld::isRaceOver()
{
if (m_unfair_team)
return true;
if (race_manager->hasTimeTarget())
{
return m_count_down_reached_zero;

View File

@ -409,6 +409,9 @@ public:
void handlePlayerGoalFromServer(const NetworkString& ns);
// ------------------------------------------------------------------------
void handleResetBallFromServer(const NetworkString& ns);
// ------------------------------------------------------------------------
virtual bool hasTeam() const OVERRIDE { return true; }
// ------------------------------------------------------------------------
}; // SoccerWorld

View File

@ -312,6 +312,7 @@ void World::reset()
// Reset all data structures that depend on number of karts.
irr_driver->reset();
m_unfair_team = false;
} // reset
//-----------------------------------------------------------------------------

View File

@ -108,6 +108,8 @@ protected:
bool m_stop_music_when_dialog_open;
bool m_unfair_team;
/** Whether highscores should be used for this kind of race.
* True by default, change to false in a child class to disable.
*/
@ -327,7 +329,11 @@ public:
virtual void loadCustomModels() {}
// ------------------------------------------------------------------------
void eliminateKart(int kart_number, bool notify_of_elimination = true);
// ------------------------------------------------------------------------
void setUnfairTeam(bool val) { m_unfair_team = val; }
// ------------------------------------------------------------------------
virtual bool hasTeam() const { return false; }
// ------------------------------------------------------------------------
/** Set the network mode (true if networked) */
void setNetworkWorld(bool is_networked) { m_is_network_world = is_networked; }

View File

@ -54,9 +54,19 @@ void GameSetup::update(bool remove_disconnected_players)
if (!World::getWorld() ||
World::getWorld()->getPhase() < WorldStatus::MUSIC_PHASE)
return;
int red_count = 0;
int blue_count = 0;
for (uint8_t i = 0; i < (uint8_t)m_players.size(); i++)
{
if (!m_players[i].expired())
bool disconnected = m_players[i].expired();
if (race_manager->getKartInfo(i).getSoccerTeam() == SOCCER_TEAM_RED &&
!disconnected)
red_count++;
else if (race_manager->getKartInfo(i).getSoccerTeam() ==
SOCCER_TEAM_BLUE && !disconnected)
blue_count++;
if (!disconnected)
continue;
AbstractKart* k = World::getWorld()->getKart(i);
if (!k->isEliminated())
@ -72,6 +82,9 @@ void GameSetup::update(bool remove_disconnected_players)
STKHost::get()->sendPacketToAllPeers(&p, true);
}
}
if (m_players.size() != 1 && World::getWorld()->hasTeam() &&
(red_count == 0 || blue_count == 0))
World::getWorld()->setUnfairTeam(true);
} // removePlayer
//-----------------------------------------------------------------------------

View File

@ -337,6 +337,7 @@ void ClientLobby::update(int ticks)
GUIEngine::ModalDialog::dismiss();
if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU)
StateManager::get()->enterGameState();
World::getWorld()->enterRaceOverState();
}
break;
case DONE: