Esempio n. 1
0
void World::updateWorldScore()
{
	float prevWorldScore = worldScore;
	worldScore = 0;
	for(unsigned int i = 0; i < getPlayers()->size(); i++)
	{
		worldScore += dynamic_cast<Player*>(getPlayers()->at(i))->getScore();
	}
	if(worldScore == 0)
	{
		worldScore = prevWorldScore;
	}
}
Esempio n. 2
0
void CatanRoom::requestStartGame()
{
    CatanPlayer *player = qobject_cast<CatanPlayer*>(sender());
    Q_ASSERT(player);

    if( !player ) return;
    if( player != host ) return; //only the host can begin the game
    if( startTimer.isActive() ) return; //the game is already being started
    if( GetNumPlayers() < CATAN_MIN_PLAYERS ) return; //cannot start with less than 4 players
    //check to make sure everyone is ready.
    for( int i = 0; i < GetMaxPlayers(); i++ )
    {
        CatanPlayer *occupant = players[i];
        if( !occupant ) continue;

        if( !readyPlayers[occupant->GetID()] )
            return; //cannot start the game unless all players are ready.
    }

    startTimer.setSingleShot(true);
    startTimer.start( CATAN_ROOM_START_TIME * 1000 );

    net::Begin(NETWORK_COMMAND::SERVER_ROOM_STARTING);
    net::Send(getPlayers());
}
Esempio n. 3
0
void PlayerRelationsManager::clear()
{
    StringVect *const names = getPlayers();
    FOR_EACHP (StringVectCIter, it, names)
        removePlayer(*it);
    delete names;
}
Esempio n. 4
0
void World::Update(sf::RenderWindow& window)
{
	if(getPlayers()->empty())
	{
		playerLoseClock.resume();
	}
	else
	{
		hud.Update();
		worldScore = hud.getDisplayScore();
	}

	enemySpawnManager.Update(*getPlayers());
	entityManager.Update(window);
	particleEmitterManager.Update();
}
Esempio n. 5
0
int GameState::getTotalScorePlayerSum() const {
	int total = 0;
	for (PlayerData const & pd : getPlayers()) {
		total += pd.TotalScore;
	}

	return total;
}
void SingleEliminationWorld::checkpointReachedExtended(Boxx *box, int pos)
{
	if (hud == NULL) hud = ((SingleElimHud*)Director::getInstance()->getRunningScene()->getChildByTag(LAYER_HUD));
	bool shouldplaySound = false;
	if (player && box == player) shouldplaySound = true;
	if (box == orderedOpponents.at(remainingGates))
	{
		//deactivate
		pozycje.pushBack(orderedOpponents.at(remainingGates + 1));
		orderedOpponents.at(remainingGates+1)->deactivate();
		hud->boxEliminated(orderedOpponents.at(remainingGates + 1));
		//game over
        if(remainingGates == 0) pozycje.pushBack(box);
        if(multiplayerEnabled)
        {
            bool koniecplayerow = true;
            for(auto pl : *getPlayers())
            {
                if(!pl->isDeactivated())
                {
                    koniecplayerow=false;
                    break;
                }
            }
            if(koniecplayerow)
            {
                for (auto bx : orderedOpponents)
                {
                    if (!bx->isDeactivated() && !pozycje.contains(bx)) pozycje.pushBack(bx);
                }
                this->gameIsOver(false);
                return;
            }
        }
		else if (player && remainingGates == 0 && box == player)
		{
			this->gameIsOver(true);
			return;
		}
		else if (player && orderedOpponents.at(remainingGates + 1) == player)
		{
			for (auto bx : orderedOpponents)
			{
				if (!bx->isDeactivated() && !pozycje.contains(bx)) pozycje.pushBack(bx);
			}
			this->gameIsOver(false);
			return;
		}
		if (remainingGates == 0)
		{
			shouldplaySound = true;
			this->gameIsOver(true);
		}
		if (!player) shouldplaySound = true;
	}
	if (shouldplaySound) SoundManager::getInstance()->playEffect(R_MP3_punch);
}
Esempio n. 7
0
void CatanRoom::RemovePlayer( CatanPlayer *player )
{
    disconnect( player, SIGNAL(requestLeaveRoom()),
                this, SLOT(onPlayerLeave()));
    disconnect( player, SIGNAL(destroyed()),
                this, SLOT(onPlayerDestroying()));

    if( players[player->GetID()] != player ) return;

    LOG_DEBUG("[Lobby " << GetID() << "] Removing player: " << player->GetName() << endl);

    //remove the player
    players[player->GetID()] = 0;
    readyPlayers[player->GetID()] = false;
    playerCount--;

    cancelStartup(player);
    emit removedPlayer(player);

    //remove this room if it is empty
    if( GetNumPlayers() == 0 )
    {
        player->deleteLater();
        this->deleteLater();
        return;
    }

    //get a list of all the players to send the message to
    QVector<CatanPlayer*> playerList = getPlayers();

    if( player == host ) //if this was the host
    {

        //remove the previous host
        disconnect( player, SIGNAL(requestStartGame()),
                    this,     SLOT(requestStartGame()));
        disconnect( player, SIGNAL(requestChangeConfig(QDataStream&)),
                    this,    SLOT(receivedChangeConfig(QDataStream&)));
        host = 0;

        //set the host to the next player in the list
        LOG_INFO("The host disconnected from lobby [" << (quint16)GetID() << "]" << endl);
        for( int i = 0; i < GetMaxPlayers(); i++ )
        {
            if( players[i] )
            {
                setHost(players[i]);
                break;
            }
        }
        if( host ) {
            LOG_DEBUG("New lobby host: " << host->GetName() << endl);
            net::Begin(NETWORK_COMMAND::SERVER_ROOM_NEW_HOST);
                net::AddByte(host->GetID());
            net::Send(playerList);
        }
    }
Esempio n. 8
0
void Map::update (uint32_t deltaTime)
{
	_pointCount = 0;

	if (_pause)
		return;

	_timeManager.update(deltaTime);

	if (_restartDue > 0 && _restartDue <= _time) {
		const std::string currentName = getName();
		info(LOG_MAP, "restarting map " + currentName);
		if (isFailed()) {
			const Map::PlayerList& players = getPlayers();
			for (Map::PlayerListConstIter i = players.begin(); i != players.end(); ++i) {
				const Player* p = *i;
				GameEvent.failedMap(p->getClientId(), currentName, getFailReason(p), getTheme());
			}
			System.track("mapstate", "failed:" + currentName);
		} else {
			load(currentName);
		}
		return;
	}

	if (_world) {
		_time += deltaTime;
		while (_time - _physicsTime >= Constant::DELTA_PHYSICS_MILLIS) {
			_physicsTime += Constant::DELTA_PHYSICS_MILLIS;
			{
				ExecutionTime visitTime("VisitTime", 2000L);
				visitEntities(this);
			}

			handleFlyingNPC();
			handleFishNPC();

			if (_time >= _warmupPhase) {
				_entityRemovalAllowed = false;
				ExecutionTime stepTime("StepTime", 2000L);
				_world->Step(Constant::DELTA_PHYSICS_SECONDS, 8, 3);
				_entityRemovalAllowed = true;
			}
		}

		const int t = _referenceTime - _time / 1000;
		if (t < 0)
			return;

		static int lastT = 0;
		if (lastT != t) {
			GameEvent.sendTimeRemaining(t);
			lastT = t;
		}
	}
}
Esempio n. 9
0
void Map::killPlayers ()
{
#ifdef DEBUG
	const Map::PlayerList& players = getPlayers();
	for (Map::PlayerListConstIter i = players.begin(); i != players.end(); ++i) {
		Player* player = *i;
		player->setCrashed(CRASH_DAMAGE);
	}
#endif
}
Esempio n. 10
0
void CatanRoom::cancelStartup(CatanPlayer *player)
{
    //if we changed to un-ready and the game was starting, halt the game start timer
    if( startTimer.isActive() )
    {
        startTimer.stop();
        net::Begin(NETWORK_COMMAND::SERVER_ROOM_START_INTERRUPT);
            net::AddByte(player->GetID());
        net::Send(getPlayers());
    }
}
Esempio n. 11
0
void giveSockets (int currentSockets [MAX_PLAYERS])
{
	clientTyp clients[MAX_PLAYERS];
	getPlayers(clients);
    pthread_mutex_lock (&datamut);
	for (int i=0;i<currentPlayersCount;i++)
	{
		currentSockets[i] = clients[i].socket;
	}
    pthread_mutex_unlock (&datamut);
}
Esempio n. 12
0
void		RoomPanel::updatePlayers(std::vector<std::string> &vector, int from)
{
  (void)from;
  RenderWindow *window = RenderWindow::getInstance();
  unsigned int i = 0;

  while (i < vector.size() - 2)
    {
      getPlayers().at(i)->setUsername(vector.at(i));
      _backgrounds.at(i + 1).setTexture(*_spaceShipsTextures.at(i + 1));


      getLabels().at(i + 2).setString(vector.at(i));
      getLabels().at(i + 2).setOrigin(_labels.at(i + 2).getText().getGlobalBounds().width / 2, _labels.at(i + 2).getText().getGlobalBounds().height / 2);
      _nbPlayers++;
      i++;
    }
  i--;
  _players.at(i)->setCurrentClient(true);
  _currentPlayer = i + 1;

  switch (i)
    {
    case 0:
      getLabels().at(i + 2).setColor(Color::BLUE);
      break;
    case 1:
      getLabels().at(i + 2).setColor(Color::RED);
      break;
    case 2:
      getLabels().at(i + 2).setColor(Color::GREEN);
      break;
    case 3:
      getLabels().at(i + 2).setColor(Color::YELLOW);
      break;
    default:
      getLabels().at(i + 2).setColor(Color::WHITE);
      break;
    }

  _idRoom = vector.at(vector.size() - 2);
  _labels.at(6).setString(_idRoom);
  _labels.at(6).setOrigin(_labels.at(6).getText().getGlobalBounds().width / 2, _labels.at(6).getText().getGlobalBounds().height / 2);
  _labels.at(6).setPosition(Vector2(0.5 * window->getSize()._x, 0.95 * window->getSize()._y));
}
Esempio n. 13
0
Player * Environment::getRandomConnectedPlayer()
{
	core::list<Player*> connected_players = getPlayers(true);
	u32 chosen_one = myrand() % connected_players.size();
	u32 j = 0;
	for(core::list<Player*>::Iterator
			i = connected_players.begin();
			i != connected_players.end(); i++)
	{
		if(j == chosen_one)
		{
			Player *player = *i;
			return player;
		}
		j++;
	}
	return NULL;
}
Esempio n. 14
0
Player * Environment::getNearestConnectedPlayer(v3f pos)
{
	core::list<Player*> connected_players = getPlayers(true);
	f32 nearest_d = 0;
	Player *nearest_player = NULL;
	for(core::list<Player*>::Iterator
			i = connected_players.begin();
			i != connected_players.end(); i++)
	{
		Player *player = *i;
		f32 d = player->getPosition().getDistanceFrom(pos);
		if(d < nearest_d || nearest_player == NULL)
		{
			nearest_d = d;
			nearest_player = player;
		}
	}
	return nearest_player;
}
Esempio n. 15
0
void Rcon::loginResponse()
{
	if (rcon_socket.recv_buffer[8] == 0x01)
	{
		*(rcon_socket.rcon_login_flag) = true;

		logger->info("Rcon: Login Success");
		timerKeepAlive(30);
		unsigned int unique_id = 1;
		getPlayers(unique_id);
		startReceive();
	}
	else
	{
		*(rcon_socket.rcon_login_flag) = false;
		logger->info("Rcon: Login Failed");
		disconnect();
	}
}
Esempio n. 16
0
void CatanRoom::readyUp(bool ready)
{
    CatanPlayer *player = qobject_cast<CatanPlayer*>(sender());
    Q_ASSERT(player);

    //make sure this player is still in the room.
    if( players[player->GetID()] != player ) return;

    //if the ready status has changed, network it to the other players
    if( ready == readyPlayers[player->GetID()] ) return;

    //send the message
    net::Begin(NETWORK_COMMAND::SERVER_ROOM_PLAYER_READY);
        net::AddByte(player->GetID());
        net::AddBool(ready);
    net::Send(getPlayers());

    readyPlayers[player->GetID()] = ready;
    if( !ready ) cancelStartup(player);
}