bool PlayerSelection(void) { PlayerSelectionData data; memset(&data, 0, sizeof data); data.IsOK = true; GetDataFilePath(data.prefixes, "data/prefixes.txt"); GetDataFilePath(data.suffixes, "data/suffixes.txt"); GetDataFilePath(data.suffixnames, "data/suffixnames.txt"); NameGenInit(&data.g, data.prefixes, data.suffixes, data.suffixnames); // Create selection menus for each local player for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } PlayerSelectMenusCreate( &data.menus[idx], GetNumPlayers(false, false, true), idx, i, &gEventHandlers, &gGraphicsDevice, &data.g); } if (!gCampaign.IsClient) { NetServerOpen(&gNetServer); } GameLoopData gData = GameLoopDataNew( &data, PlayerSelectionUpdate, &data, PlayerSelectionDraw); GameLoop(&gData); if (data.IsOK) { for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } // For any player slots not picked, turn them into AIs if (p->inputDevice == INPUT_DEVICE_UNSET) { PlayerSetInputDevice(p, INPUT_DEVICE_AI, 0); } } } for (int i = 0; i < GetNumPlayers(false, false, true); i++) { MenuSystemTerminate(&data.menus[i].ms); } NameGenTerminate(&data.g); return data.IsOK; }
void APuzzlePresetGameMode::PostLogin(APlayerController* NewPlayer) { if (GetNumPlayers() >= 2) { bStartPlayersAsSpectators = true; NewPlayer->StartSpectatingOnly(); } Super::PostLogin(NewPlayer); UE_LOG(LogTemp, Warning, TEXT("Totally connected: %d"), GetNumPlayers()); UE_LOG(LogTemp, Warning, TEXT("Connected PC is spectating: %d"), NewPlayer->PlayerState->bIsSpectator); }
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()); }
static void PrintStats(FILE *stream, wbstartstruct_t *stats) { int leveltime, partime; int i; PrintLevelName(stream, stats->epsd, stats->last); fprintf(stream, "\n"); leveltime = stats->plyr[0].stime / TICRATE; partime = stats->partime / TICRATE; fprintf(stream, "Time: %i:%02i", leveltime / 60, leveltime % 60); fprintf(stream, " (par: %i:%02i)\n", partime / 60, partime % 60); fprintf(stream, "\n"); for (i=0; i<MAXPLAYERS; ++i) { if (stats->plyr[i].in) { PrintPlayerStats(stream, stats, i); } } if (GetNumPlayers(stats) >= 2) { PrintFragsTable(stream, stats); } fprintf(stream, "\n"); }
Visibility GameWorldBase::CalcVisiblityWithAllies(const MapPoint pt, const unsigned char player) const { const MapNode& node = GetNode(pt); Visibility best_visibility = node.fow[player].visibility; if(best_visibility == VIS_VISIBLE) return best_visibility; /// Teamsicht aktiviert? if(GetGGS().teamView) { const GamePlayer& curPlayer = GetPlayer(player); // Dann prüfen, ob Teammitglieder evtl. eine bessere Sicht auf diesen Punkt haben for(unsigned i = 0; i < GetNumPlayers(); ++i) { if(i != player && curPlayer.IsAlly(i)) { if(node.fow[i].visibility > best_visibility) best_visibility = node.fow[i].visibility; } } } return best_visibility; }
void Channel::LeaveNotify(ObjectGuid guid) { WorldPacket data(SMSG_USERLIST_REMOVE, 8 + 1 + 4 + GetName().size() + 1); data << ObjectGuid(guid); data << uint8(GetFlags()); data << uint32(GetNumPlayers()); data << GetName(); SendToAll(&data); }
static void PlayerEquipDraw(void *data) { const PlayerEquipData *pData = data; GraphicsBlitBkg(&gGraphicsDevice); for (int i = 0; i < GetNumPlayers(false, false, true); i++) { MenuDisplay(&pData->menus[i].ms); } }
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); } }
// TODO: reimplement in camera Vec2i GetPlayerCenter( GraphicsDevice *device, const Camera *camera, const PlayerData *pData, const int playerIdx) { if (pData->ActorUID < 0) { // Player is dead return Vec2iZero(); } Vec2i center = Vec2iZero(); int w = device->cachedConfig.Res.x; int h = device->cachedConfig.Res.y; if (GetNumPlayers(PLAYER_ALIVE_OR_DYING, true, true) == 1 || GetNumPlayers(PLAYER_ALIVE_OR_DYING, false , true) == 1 || CameraIsSingleScreen()) { const Vec2i pCenter = camera->lastPosition; const Vec2i screenCenter = Vec2iNew(w / 2, device->cachedConfig.Res.y / 2); const TActor *actor = ActorGetByUID(pData->ActorUID); const Vec2i p = Vec2iNew(actor->tileItem.x, actor->tileItem.y); center = Vec2iAdd(Vec2iMinus(p, pCenter), screenCenter); } else { const int numLocalPlayers = GetNumPlayers(PLAYER_ANY, false, true); if (numLocalPlayers == 2) { center.x = playerIdx == 0 ? w / 4 : w * 3 / 4; center.y = h / 2; } else if (numLocalPlayers >= 3 && numLocalPlayers <= 4) { center.x = (playerIdx & 1) ? w * 3 / 4 : w / 4; center.y = (playerIdx >= 2) ? h * 3 / 4 : h / 4; } else { CASSERT(false, "invalid number of players"); } } return center; }
void CameraInput(Camera *camera, const int cmd, const int lastCmd) { // Control the camera if (camera->spectateMode == SPECTATE_NONE) { return; } // Arrows: pan camera // CMD1/2: choose next player to follow if (CMD_HAS_DIRECTION(cmd)) { camera->spectateMode = SPECTATE_FREE; const int pan = PAN_SPEED; if (cmd & CMD_LEFT) camera->lastPosition.x -= pan; else if (cmd & CMD_RIGHT) camera->lastPosition.x += pan; if (cmd & CMD_UP) camera->lastPosition.y -= pan; else if (cmd & CMD_DOWN) camera->lastPosition.y += pan; } else if ((AnyButton(cmd) && !AnyButton(lastCmd)) || camera->FollowNextPlayer) { // Can't follow if there are no players if (GetNumPlayers(PLAYER_ALIVE_OR_DYING, false, false) == 0) { return; } camera->spectateMode = SPECTATE_FOLLOW; // Find index of player int playerIndex = -1; CA_FOREACH(const PlayerData, p, gPlayerDatas) if (p->UID == camera->FollowPlayerUID) { playerIndex = _ca_index; break; } CA_FOREACH_END() // Get the next player by index that has an actor in the game const int d = (cmd & CMD_BUTTON1) ? 1 : -1; for (int i = playerIndex + d;; i += d) { i = CLAMP_OPPOSITE(i, 0, (int)gPlayerDatas.size - 1); // Check if clamping made us hit the termination condition if (i == playerIndex) break; const PlayerData *p = CArrayGet(&gPlayerDatas, i); if (IsPlayerAliveOrDying(p)) { // Follow this player camera->FollowPlayerUID = p->UID; camera->FollowNextPlayer = false; break; } } } }
static GameLoopResult PlayerEquipUpdate(void *data) { PlayerEquipData *pData = data; // Check if anyone pressed escape int cmds[MAX_LOCAL_PLAYERS]; memset(cmds, 0, sizeof cmds); GetPlayerCmds(&gEventHandlers, &cmds); if (EventIsEscape(&gEventHandlers, cmds, GetMenuCmd(&gEventHandlers))) { pData->IsOK = false; return UPDATE_RESULT_EXIT; } // Update menus int idx = 0; for (int i = 0; i < (int)gPlayerDatas.size; i++, idx++) { const PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } if (!MenuIsExit(&pData->menus[idx].ms)) { MenuProcessCmd(&pData->menus[idx].ms, cmds[idx]); } else if (p->weaponCount == 0) { // Check exit condition; must have selected at least one weapon // Otherwise reset the current menu pData->menus[idx].ms.current = pData->menus[idx].ms.root; } } bool isDone = true; for (int i = 0; i < GetNumPlayers(false, false, true); i++) { if (strcmp(pData->menus[i].ms.current->name, "(End)") != 0) { isDone = false; } } if (isDone) { pData->IsOK = true; return UPDATE_RESULT_EXIT; } return UPDATE_RESULT_DRAW; }
void Channel::LeaveNotify(uint64 guid) { WorldPacket data(SMSG_USERLIST_REMOVE, 8+1+4+GetName().size()+1); data << uint64(guid); data << uint8(GetFlags()); data << uint32(GetNumPlayers()); data << GetName(); if (IsConstant()) SendToAllButOne(&data, guid); else SendToAll(&data); }
bool IBattle::IsEveryoneReady() const { for ( unsigned int i = 0; i < GetNumPlayers(); i++ ) { User& usr = GetUser( i ); UserBattleStatus& status = usr.BattleStatus(); if ( status.IsBot() ) continue; if ( status.spectator ) continue; if ( &usr == &GetMe() ) continue; if ( !status.ready ) return false; if ( !status.sync ) return false; } return true; }
void Channel::JoinNotify(uint64 guid) { WorldPacket data(IsConstant() ? SMSG_USERLIST_ADD : SMSG_USERLIST_UPDATE, 8 + 1 + 1 + 4 + GetName().size()); data << uint64(guid); data << uint8(GetPlayerFlags(guid)); data << uint8(GetFlags()); data << uint32(GetNumPlayers()); data << GetName(); if (IsConstant()) SendToAllButOne(&data, guid); else SendToAll(&data); }
static void PlayerSelectionDraw(void *data) { const PlayerSelectionData *pData = data; GraphicsBlitBkg(&gGraphicsDevice); const int w = gGraphicsDevice.cachedConfig.Res.x; const int h = gGraphicsDevice.cachedConfig.Res.y; int idx = 0; for (int i = 0; i < (int)gPlayerDatas.size; i++, idx++) { const PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } if (p->inputDevice != INPUT_DEVICE_UNSET) { MenuDisplay(&pData->menus[idx].ms); } else { Vec2i center = Vec2iZero(); const char *prompt = "Press Fire to join..."; const Vec2i offset = Vec2iScaleDiv(FontStrSize(prompt), -2); switch (GetNumPlayers(false, false, true)) { case 1: // Center of screen center = Vec2iNew(w / 2, h / 2); break; case 2: // Side by side center = Vec2iNew(idx * w / 2 + w / 4, h / 2); break; case 3: case 4: // Four corners center = Vec2iNew( (idx & 1) * w / 2 + w / 4, (idx / 2) * h / 2 + h / 4); break; default: CASSERT(false, "not implemented"); break; } FontStr(prompt, Vec2iAdd(center, offset)); } } }
void Channel::LeaveNotify(Player* p) { if (_channelRights.flags & CHANNEL_RIGHT_CANT_SPEAK) return; if (!AccountMgr::IsPlayerAccount(p->GetSession()->GetSecurity())) return; WorldPacket data(SMSG_USERLIST_REMOVE, 8 + 1 + 4 + GetName().size()); data << uint64(p->GetGUID()); data << uint8(GetFlags()); data << uint32(GetNumPlayers()); data << GetName(); SendToAllWatching(&data); }
void Channel::JoinNotify(ObjectGuid guid) { WorldPacket data; if (IsConstant()) data.Initialize(SMSG_USERLIST_ADD, 8 + 1 + 1 + 4 + GetName().size() + 1); else data.Initialize(SMSG_USERLIST_UPDATE, 8 + 1 + 1 + 4 + GetName().size() + 1); data << ObjectGuid(guid); data << uint8(GetPlayerFlags(guid)); data << uint8(GetFlags()); data << uint32(GetNumPlayers()); data << GetName(); SendToAll(&data); }
int CTeam::GetAliveMembers( void ) { int iAlive = 0; int iNumPlayers = GetNumPlayers(); for ( int i=0;i<iNumPlayers;i++ ) { if ( GetPlayer(i) && GetPlayer(i)->IsAlive() ) { iAlive++; } } return iAlive; }
GameLoopData *ScreenVictory(CampaignOptions *c) { SoundPlay(&gSoundDevice, StrSound("victory")); VictoryData *data; CMALLOC(data, sizeof *data); data->Campaign = c; const char *finalWordsSingle[] = { "Ha, next time I'll use my good hand", "Over already? I was just warming up...", "There's just no good opposition to be found these days!", "Well, maybe I'll just do my monthly reload then", "Woof woof", "I'll just bury the bones in the back yard, he-he", "I just wish they'd let me try bare-handed", "Rambo? Who's Rambo?", "<in Austrian accent:> I'll be back", "Gee, my trigger finger is sore", "I need more practice. I think I missed a few shots at times" }; const char *finalWordsMulti[] = { "United we stand, divided we conquer", "Nothing like good teamwork, is there?", "Which way is the camera?", "We eat bullets for breakfast and have grenades as dessert", "We're so cool we have to wear mittens", }; if (GetNumPlayers(PLAYER_ANY, false, true) == 1) { const int numWords = sizeof finalWordsSingle / sizeof(char *); data->FinalWords = finalWordsSingle[rand() % numWords]; } else { const int numWords = sizeof finalWordsMulti / sizeof(char *); data->FinalWords = finalWordsMulti[rand() % numWords]; } PlayerList *pl = PlayerListNew( PlayerListUpdate, VictoryDraw, data, true, false); pl->pos.y = 75; pl->size.y -= pl->pos.y; return PlayerListLoop(pl); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTeam::AwardAchievement( int iAchievement ) { Assert( iAchievement >= 0 && iAchievement < 255 ); // must fit in short CRecipientFilter filter; int iNumPlayers = GetNumPlayers(); for ( int i=0;i<iNumPlayers;i++ ) { if ( GetPlayer(i) ) { filter.AddRecipient( GetPlayer(i) ); } } UserMessageBegin( filter, "AchievementEvent" ); WRITE_SHORT( iAchievement ); MessageEnd(); }
unsigned int IBattle::GetNumActivePlayers() const { return GetNumPlayers() - m_opts.spectators; }
bool CatanRoom::AddUser( CatanUser *user ) { if( GetNumPlayers() >= config->GetMaxPlayers() ) return false; if( user->InGame() || user->InLobby() ) return false; int id = getNextPID( players ); CatanPlayer* player = new CatanPlayer(id, user, this); //set the host if( !host ) setHost( player ); players[id] = player; playerCount++; LOG_DEBUG( "Lobby player count: " << GetNumPlayers() << endl ); player->SetState(PLAYER_STATE::IN_LOBBY); //tell the current players in the room that this user has joined for( int i = 0; i < GetMaxPlayers(); i++ ) { CatanPlayer *occupant = players[i]; if( !occupant ) continue; net::Begin(NETWORK_COMMAND::SERVER_ROOM_USER_JOINED); net::AddShort(this->GetID()); net::AddByte(player->GetID()); net::AddString(player->GetName()); net::Send(occupant->GetUser()); } //tell this user about the current players in the room net::Begin(NETWORK_COMMAND::SERVER_ROOM_PLAYERS); net::AddByte(GetNumPlayers()-1); //don't include the new player //send the host first. net::AddByte(host->GetID()); net::AddString(host->GetName()); net::AddBool(readyPlayers[host->GetID()]); for( int i = 0; i < GetMaxPlayers(); i++ ) { CatanPlayer *occupant = players[i]; if( !occupant ) continue; if( occupant != host && occupant != player ) { net::AddByte(occupant->GetID()); net::AddString(occupant->GetName()); net::AddBool(readyPlayers[occupant->GetID()]); } } net::Send(user); //send the game configuration transmitConfigFull(user); //if the user gets destroyed, remove him from the room connect( player, SIGNAL(destroying()), this, SLOT(onPlayerDestroying())); connect( player, SIGNAL(requestLeaveRoom()), this, SLOT(onPlayerLeave())); connect( player, SIGNAL(readyUp(bool)), this, SLOT(readyUp(bool))); emit addedPlayer(player); return true; }
void CameraDraw( Camera *camera, const input_device_e pausingDevice, const bool controllerUnplugged) { Vec2i centerOffset = Vec2iZero(); const int numLocalPlayersAlive = GetNumPlayers(PLAYER_ALIVE_OR_DYING, false, true); const int numLocalPlayers = GetNumPlayers(PLAYER_ANY, false, true); const int w = gGraphicsDevice.cachedConfig.Res.x; const int h = gGraphicsDevice.cachedConfig.Res.y; for (int i = 0; i < GraphicsGetScreenSize(&gGraphicsDevice.cachedConfig); i++) { gGraphicsDevice.buf[i] = COLOR2PIXEL(colorBlack); } const Vec2i noise = ScreenShakeGetDelta(camera->shake); GraphicsResetBlitClip(&gGraphicsDevice); if (numLocalPlayersAlive == 0) { // Count the number of local players with lives left // If there are none, then try to spectate if there are remote players int firstRemotePlayerUID = -1; bool hasLocalPlayerLives = false; CA_FOREACH(const PlayerData, p, gPlayerDatas) if (p->Lives > 0) { if (p->IsLocal) { hasLocalPlayerLives = true; break; } else { firstRemotePlayerUID = p->UID; } } CA_FOREACH_END() if (!hasLocalPlayerLives) { if (camera->spectateMode == SPECTATE_NONE) { // Enter spectator mode // If there are remote players, follow them if (firstRemotePlayerUID != -1) { camera->spectateMode = SPECTATE_FOLLOW; camera->FollowPlayerUID = firstRemotePlayerUID; } else { // Free-look mode camera->spectateMode = SPECTATE_FREE; } } } else { // Don't spectate camera->spectateMode = SPECTATE_NONE; } if (camera->spectateMode == SPECTATE_FOLLOW) { FollowPlayer(&camera->lastPosition, camera->FollowPlayerUID); } DoBuffer( &camera->Buffer, camera->lastPosition, X_TILES, noise, centerOffset); SoundSetEars(camera->lastPosition); }
void CTeam::SortPlayers(int nSortKey, int nDir) { // Sanity checks... if (nSortKey == TM_KEY_SCORE) return; if (GetNumPlayers() <= 1) return; // Remove each player from our list, and insert it, sorted, into a temp list... CTeamPlayerList lsTemp; CTeamPlayer* pCurPlr = GetFirstPlayer(); while (pCurPlr) { CTeamPlayer* pNextPlr = GetNextPlayer(pCurPlr); m_lsPlayers.Delete(pCurPlr); // Insert the player from our main list, sorted, into our temp list... CTeamPlayer* pTmpPlr = lsTemp.GetFirst(); if (!pTmpPlr) { lsTemp.Insert(pCurPlr); } else { while (pTmpPlr) { if (nDir == TM_SORT_DESCENDING && IsGreater(pCurPlr, pTmpPlr, nSortKey)) { lsTemp.InsertBefore(pTmpPlr, pCurPlr); pTmpPlr = NULL; } else if (nDir == TM_SORT_ASCENDING && IsLess(pCurPlr, pTmpPlr, nSortKey)) { lsTemp.InsertBefore(pTmpPlr, pCurPlr); pTmpPlr = NULL; } else { pTmpPlr = pTmpPlr->GetNext(); if (!pTmpPlr) { lsTemp.InsertLast(pCurPlr); } } } } pCurPlr = pNextPlr; } // Re-insert all items into our main list... CTeamPlayer* pPlr = lsTemp.GetFirst(); while (pPlr) { CTeamPlayer* pNextPlr = pPlr->GetNext(); m_lsPlayers.InsertLast(pPlr); pPlr = pNextPlr; } }
void CTO2GameServerShell::Update(LTFLOAT timeElapsed) { // Update the main server first CGameServerShell::Update(timeElapsed); m_VersionMgr.Update(); if (!GetServerDir()) return; //if we're hosting LANOnly game, don't publish the server if( m_ServerGameOptions.m_bLANOnly ) return; // Are we still waiting? static std::string status; switch (GetServerDir()->GetCurStatus()) { case IServerDirectory::eStatus_Processing : status =""; break; case IServerDirectory::eStatus_Waiting : if (status.empty()) status = GetServerDir()->GetLastRequestResultString(); break; case IServerDirectory::eStatus_Error : { IServerDirectory::ERequest eErrorRequest = GetServerDir()->GetLastErrorRequest(); status = GetServerDir()->GetLastRequestResultString(); GetServerDir()->ProcessRequestList(); } break; }; // Publish the server if we've waited long enough since the last directory update uint32 nCurTime = (uint32)GetTickCount(); if ((m_nLastPublishTime == 0) || ((nCurTime - m_nLastPublishTime) > k_nRepublishDelay)) { status = ""; m_nLastPublishTime = nCurTime; uint32 nMax = 0; g_pLTServer->GetMaxConnections(nMax); // If not run by a dedicated server, we need to add one connection // for the local host. if( !m_ServerGameOptions.m_bDedicated ) nMax++; GetServerDir()->SetActivePeer(0); CAutoMessage cMsg; // Update the summary info cMsg.WriteString(GetHostName()); GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Name, *cMsg.Read()); char fname[_MAX_FNAME] = ""; _splitpath( GetCurLevel(), NULL, NULL, fname, NULL ); // Update the summary info cMsg.WriteString(g_pVersionMgr->GetBuild()); cMsg.WriteString( fname ); cMsg.Writeuint8(GetNumPlayers()); cMsg.Writeuint8(nMax); cMsg.Writebool(m_ServerGameOptions.m_bUsePassword); cMsg.Writeuint8((uint8)GetGameType()); cMsg.WriteString( m_ServerGameOptions.m_sModName.c_str() ); GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Summary, *cMsg.Read()); // Update the details ServerMissionSettings sms = g_pServerMissionMgr->GetServerSettings(); cMsg.Writebool(sms.m_bUseSkills); cMsg.Writebool(sms.m_bFriendlyFire); cMsg.Writeuint8(sms.m_nMPDifficulty); cMsg.Writefloat(sms.m_fPlayerDiffFactor); CPlayerObj* pPlayer = GetFirstNetPlayer(); while (pPlayer) { //has player info cMsg.Writebool(true); cMsg.WriteString(pPlayer->GetNetUniqueName()); cMsg.Writeuint16( Min( GetPlayerPing(pPlayer), ( uint32 )65535 )); pPlayer = GetNextNetPlayer(); }; //end of player info cMsg.Writebool(false); cMsg.Writeuint8(sms.m_nRunSpeed); cMsg.Writeuint8(sms.m_nScoreLimit); cMsg.Writeuint8(sms.m_nTimeLimit); GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Details, *cMsg.Read()); // Update the port char aHostAddr[16]; uint16 nHostPort; g_pLTServer->GetTcpIpAddress(aHostAddr, sizeof(aHostAddr), nHostPort); cMsg.Writeuint16(nHostPort); GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Port, *cMsg.Read()); // Tell serverdir again about info, but in service specific manner. PeerInfo_Service_Titan peerInfo; peerInfo.m_sHostName = GetHostName( ); peerInfo.m_sCurWorld = fname; peerInfo.m_nCurNumPlayers = GetNumPlayers( ); peerInfo.m_nMaxNumPlayers = nMax; peerInfo.m_bUsePassword = m_ServerGameOptions.m_bUsePassword; peerInfo.m_sGameType = GameTypeToString( GetGameType( )); peerInfo.m_nScoreLimit = sms.m_nScoreLimit; peerInfo.m_nTimeLimit = sms.m_nTimeLimit; PeerInfo_Service_Titan::Player player; CPlayerObj::PlayerObjList::const_iterator iter = CPlayerObj::GetPlayerObjList( ).begin( ); while( iter != CPlayerObj::GetPlayerObjList( ).end( )) { CPlayerObj* pPlayerObj = *iter; player.m_sName = pPlayerObj->GetNetUniqueName( ); player.m_nScore = pPlayerObj->GetPlayerScore()->GetScore( ); float fPing; g_pLTServer->GetClientPing( pPlayerObj->GetClient( ), fPing ); player.m_nPing = ( uint16 )( fPing + 0.5f ); peerInfo.m_PlayerList.push_back( player ); iter++; } cMsg.Writeuint32(( uint32 )&peerInfo ); GetServerDir()->SetActivePeerInfo(IServerDirectory::ePeerInfo_Service, *cMsg.Read()); // Tell the world about me... GetServerDir()->QueueRequest(IServerDirectory::eRequest_Publish_Server); } }
static void Campaign(GraphicsDevice *graphics, CampaignOptions *co) { if (IsPasswordAllowed(co->Entry.Mode)) { MissionSave m; AutosaveLoadMission( &gAutosave, &m, co->Entry.Path, co->Entry.BuiltinIndex); co->MissionIndex = EnterPassword(graphics, &m); } else { co->MissionIndex = 0; } bool run = false; bool gameOver = true; do { CampaignAndMissionSetup(1, co, &gMission); if (IsGameOptionsNeeded(gCampaign.Entry.Mode)) { debug(D_NORMAL, ">> Game options\n"); if (!GameOptions(gCampaign.Entry.Mode)) { run = false; goto bail; } gCampaign.OptionsSet = true; } // Mission briefing if (IsMissionBriefingNeeded(co->Entry.Mode)) { if (!ScreenMissionBriefing(&gMission)) { run = false; goto bail; } } // Equip guns if (!PlayerEquip()) { run = false; goto bail; } // Initialise before waiting for game start; // server will send us messages GameEventsInit(&gGameEvents); if (gCampaign.IsClient) { if (!ScreenWaitForGameStart()) { run = false; goto bail; } } MapLoad(&gMap, &gMission, co); // Seed random if PVP mode (otherwise players will always spawn in same // position) if (IsPVP(co->Entry.Mode)) { srand((unsigned int)time(NULL)); } if (!gCampaign.IsClient) { MapLoadDynamic(&gMap, &gMission, &co->Setting.characters); // Note: place players first, // as bad guys are placed away from players StartPlayers(ModeMaxHealth(co->Entry.Mode), co->MissionIndex); AddAndPlacePlayers(); if (!IsPVP(co->Entry.Mode)) { InitializeBadGuys(); CreateEnemies(); } } MusicPlayGame( &gSoundDevice, gCampaign.Entry.Path, gMission.missionData->Song); run = RunGame(&gMission, &gMap); // Don't quit if all players died, that's normal for PVP modes if (IsPVP(co->Entry.Mode) && GetNumPlayers(true, false, false) == 0) { run = true; } GameEventsTerminate(&gGameEvents); const int survivingPlayers = GetNumPlayers(true, false, false); // In co-op (non-PVP) modes, at least one player must survive if (!IsPVP(co->Entry.Mode)) { gameOver = survivingPlayers == 0 || co->MissionIndex == (int)gCampaign.Setting.Missions.size - 1; } int maxScore = 0; for (int i = 0; i < (int)gPlayerDatas.size; i++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); p->survived = IsPlayerAlive(p); if (IsPlayerAlive(p)) { TActor *player = CArrayGet(&gActors, p->Id); p->hp = player->health; p->RoundsWon++; maxScore = MAX(maxScore, p->RoundsWon); } } if (IsPVP(co->Entry.Mode)) { gameOver = maxScore == ModeMaxRoundsWon(co->Entry.Mode); CASSERT(maxScore <= ModeMaxRoundsWon(co->Entry.Mode), "score exceeds max rounds won"); } MissionEnd(); MusicPlayMenu(&gSoundDevice); if (run) { switch (co->Entry.Mode) { case GAME_MODE_DOGFIGHT: ScreenDogfightScores(); break; case GAME_MODE_DEATHMATCH: ScreenDeathmatchFinalScores(); break; default: ScreenMissionSummary(&gCampaign, &gMission); // Note: must use cached value because players get cleaned up // in CleanupMission() if (gameOver && survivingPlayers > 0) { ScreenVictory(&gCampaign); } break; } } // Check if any scores exceeded high scores, if we're not a PVP mode if (!IsPVP(co->Entry.Mode)) { bool allTime = false; bool todays = false; for (int i = 0; i < (int)gPlayerDatas.size; i++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); if (((run && !p->survived) || gameOver) && p->IsLocal) { EnterHighScore(p); allTime |= p->allTime >= 0; todays |= p->today >= 0; } if (!p->survived) { p->totalScore = 0; p->missions = 0; } else { p->missions++; } p->lastMission = co->MissionIndex; } if (allTime) { DisplayAllTimeHighScores(graphics); } if (todays) { DisplayTodaysHighScores(graphics); } } if (!HasRounds(co->Entry.Mode)) { co->MissionIndex++; } bail: // Need to terminate the mission later as it is used in calculating scores MissionOptionsTerminate(&gMission); } while (run && !gameOver); // Final screen if (run) { switch (co->Entry.Mode) { case GAME_MODE_DOGFIGHT: ScreenDogfightFinalScores(); break; default: // no end screen break; } } }
void HUDDraw(HUD *hud, const input_device_e pausingDevice) { char s[50]; int flags = 0; const int numPlayersAlive = GetNumPlayers(PLAYER_ALIVE_OR_DYING, false, false); const int numLocalPlayers = GetNumPlayers(PLAYER_ANY, false, true); const int numLocalPlayersAlive = GetNumPlayers(PLAYER_ALIVE_OR_DYING, false, true); Rect2i r; r.Size = Vec2iNew( hud->device->cachedConfig.Res.x, hud->device->cachedConfig.Res.y); if (numLocalPlayersAlive <= 1) { flags = 0; } else if ( ConfigGetEnum(&gConfig, "Interface.Splitscreen") == SPLITSCREEN_NEVER) { flags |= HUDFLAGS_SHARE_SCREEN; } else if (numLocalPlayers == 2) { r.Size.x /= 2; flags |= HUDFLAGS_HALF_SCREEN; } else if (numLocalPlayers == 3 || numLocalPlayers == 4) { r.Size.x /= 2; r.Size.y /= 2; flags |= HUDFLAGS_QUARTER_SCREEN; } else { assert(0 && "not implemented"); } int idx = 0; for (int i = 0; i < (int)gPlayerDatas.size; i++, idx++) { const PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } int drawFlags = flags; r.Pos = Vec2iZero(); if (idx & 1) { r.Pos.x = r.Size.x; drawFlags |= HUDFLAGS_PLACE_RIGHT; } if (idx >= 2) { r.Pos.y = r.Size.y; drawFlags |= HUDFLAGS_PLACE_BOTTOM; } TActor *player = NULL; if (IsPlayerAlive(p)) { player = ActorGetByUID(p->ActorUID); } DrawPlayerStatus(hud, p, player, drawFlags, r); DrawScoreUpdate(&hud->scoreUpdates[idx], drawFlags); DrawHealthUpdate(&hud->healthUpdates[idx], drawFlags); DrawAmmoUpdate(&hud->ammoUpdates[idx], drawFlags); } // Only draw radar once if shared if (ConfigGetBool(&gConfig, "Interface.ShowHUDMap") && (flags & HUDFLAGS_SHARE_SCREEN) && IsAutoMapEnabled(gCampaign.Entry.Mode)) { DrawSharedRadar(hud->device, RADAR_SCALE, hud->showExit); } if (numPlayersAlive == 0) { if (AreAllPlayersDeadAndNoLives()) { if (!IsPVP(gCampaign.Entry.Mode)) { FontStrCenter("Game Over!"); } else { FontStrCenter("All Kill!"); } } } else if (hud->mission->state == MISSION_STATE_PICKUP) { int timeLeft = gMission.pickupTime + PICKUP_LIMIT - gMission.time; sprintf(s, "Pickup in %d seconds\n", (timeLeft + (FPS_FRAMELIMIT - 1)) / FPS_FRAMELIMIT); FontStrCenter(s); } if (pausingDevice != INPUT_DEVICE_UNSET) { Vec2i pos = Vec2iScaleDiv(Vec2iMinus( gGraphicsDevice.cachedConfig.Res, FontStrSize("Foo\nPress foo or bar to unpause\nBaz")), 2); const int x = pos.x; FontStr("<Paused>", pos); pos.y += FontH(); pos = FontStr("Press ", pos); color_t c = colorWhite; const char *buttonName = InputGetButtonNameColor(pausingDevice, 0, CMD_ESC, &c); pos = FontStrMask(buttonName, pos, c); FontStr(" again to quit", pos); pos.x = x; pos.y += FontH(); pos = FontStr("Press ", pos); buttonName = InputGetButtonNameColor( pausingDevice, 0, CMD_BUTTON1, &c); pos = FontStrMask(buttonName, pos, c); pos = FontStr(" or ", pos); buttonName = InputGetButtonNameColor( pausingDevice, 0, CMD_BUTTON2, &c); pos = FontStrMask(buttonName, pos, c); FontStr(" to unpause", pos); } if (hud->messageTicks > 0 || hud->messageTicks == -1) { // Draw the message centered, and just below the automap Vec2i pos = Vec2iNew( (hud->device->cachedConfig.Res.x - FontStrW(hud->message)) / 2, AUTOMAP_SIZE + AUTOMAP_PADDING + AUTOMAP_PADDING); FontStrMask(hud->message, pos, colorCyan); } if (ConfigGetBool(&gConfig, "Interface.ShowFPS")) { FPSCounterDraw(&hud->fpsCounter); } if (ConfigGetBool(&gConfig, "Interface.ShowTime")) { WallClockDraw(&hud->clock); } DrawKeycards(hud); // Draw elapsed mission time as MM:SS int missionTimeSeconds = gMission.time / FPS_FRAMELIMIT; sprintf(s, "%d:%02d", missionTimeSeconds / 60, missionTimeSeconds % 60); FontOpts opts = FontOptsNew(); opts.HAlign = ALIGN_CENTER; opts.Area = hud->device->cachedConfig.Res; opts.Pad.y = 5; FontStrOpt(s, Vec2iZero(), opts); if (HasObjectives(gCampaign.Entry.Mode)) { DrawObjectiveCounts(hud); } }
bool PlayerEquip(void) { PlayerEquipData data; memset(&data, 0, sizeof data); data.IsOK = true; for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } // Remove unavailable weapons from players inventories RemoveUnavailableWeapons(p, &gMission.Weapons); WeaponMenuCreate( &data.menus[idx], GetNumPlayers(false, false, true), idx, i, &gEventHandlers, &gGraphicsDevice); // For AI players, pre-pick their weapons and go straight to menu end if (p->inputDevice == INPUT_DEVICE_AI) { const int lastMenuIndex = (int)data.menus[idx].ms.root->u.normal.subMenus.size - 1; data.menus[idx].ms.current = CArrayGet( &data.menus[idx].ms.root->u.normal.subMenus, lastMenuIndex); AICoopSelectWeapons(p, idx, &gMission.Weapons); } } GameLoopData gData = GameLoopDataNew( &data, PlayerEquipUpdate, &data, PlayerEquipDraw); GameLoop(&gData); for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } const NetMsgPlayerData d = NetMsgMakePlayerData(p); // Ready player definitions p->IsUsed = true; if (gCampaign.IsClient) { NetClientSendMsg(&gNetClient, MSG_PLAYER_DATA, &d); } else { NetServerBroadcastMsg(&gNetServer, MSG_PLAYER_DATA, &d); } } for (int i = 0; i < GetNumPlayers(false, false, true); i++) { MenuSystemTerminate(&data.menus[i].ms); } return data.IsOK; }
const GamePlayer& GameWorldBase::GetPlayer(const unsigned id) const { RTTR_Assert(id < GetNumPlayers()); return players[id]; }
static void Campaign(GraphicsDevice *graphics, CampaignOptions *co) { if (co->IsClient) { // If connecting to a server, we've already received the mission index // Do nothing } else if (IsPasswordAllowed(co->Entry.Mode)) { MissionSave m; AutosaveLoadMission(&gAutosave, &m, co->Entry.Path); co->MissionIndex = EnterPassword(graphics, &m); } else { co->MissionIndex = 0; } bool run = false; bool gameOver = true; do { // Unready all the players for (int i = 0; i < (int)gPlayerDatas.size; i++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); p->Ready = false; } CampaignAndMissionSetup(1, co, &gMission); if (IsGameOptionsNeeded(co->Entry.Mode)) { debug(D_NORMAL, ">> Game options\n"); if (!GameOptions(co->Entry.Mode)) { run = false; goto bail; } co->OptionsSet = true; // If enabled, start net server if (!co->IsClient && ConfigGetBool(&gConfig, "StartServer")) { NetServerOpen(&gNetServer); } } // Mission briefing if (IsMissionBriefingNeeded(co->Entry.Mode)) { if (!ScreenMissionBriefing(&gMission)) { run = false; goto bail; } } // Equip guns if (!PlayerEquip()) { run = false; goto bail; } if (co->IsClient) { if (!ScreenWaitForGameStart()) { run = false; goto bail; } } run = RunGame(co, &gMission, &gMap); // Don't quit if all players died, that's normal for PVP modes if (IsPVP(co->Entry.Mode) && GetNumPlayers(PLAYER_ALIVE_OR_DYING, false, false) == 0) { run = true; } const int survivingPlayers = GetNumPlayers(PLAYER_ALIVE, false, false); // In co-op (non-PVP) modes, at least one player must survive if (!IsPVP(co->Entry.Mode)) { gameOver = survivingPlayers == 0 || co->MissionIndex == (int)gCampaign.Setting.Missions.size - 1; } int maxScore = 0; for (int i = 0; i < (int)gPlayerDatas.size; i++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); p->survived = IsPlayerAlive(p); if (IsPlayerAlive(p)) { TActor *player = ActorGetByUID(p->ActorUID); p->hp = player->health; p->RoundsWon++; maxScore = MAX(maxScore, p->RoundsWon); } } if (IsPVP(co->Entry.Mode)) { gameOver = maxScore == ModeMaxRoundsWon(co->Entry.Mode); CASSERT(maxScore <= ModeMaxRoundsWon(co->Entry.Mode), "score exceeds max rounds won"); } MissionEnd(); MusicPlayMenu(&gSoundDevice); if (run) { switch (co->Entry.Mode) { case GAME_MODE_DOGFIGHT: ScreenDogfightScores(); break; case GAME_MODE_DEATHMATCH: ScreenDeathmatchFinalScores(); break; default: ScreenMissionSummary(&gCampaign, &gMission); // Note: must use cached value because players get cleaned up // in CleanupMission() if (gameOver && survivingPlayers > 0) { ScreenVictory(&gCampaign); } break; } } // Check if any scores exceeded high scores, if we're not a PVP mode if (!IsPVP(co->Entry.Mode)) { bool allTime = false; bool todays = false; for (int i = 0; i < (int)gPlayerDatas.size; i++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); if (((run && !p->survived) || gameOver) && p->IsLocal) { EnterHighScore(p); allTime |= p->allTime >= 0; todays |= p->today >= 0; } if (!p->survived) { p->totalScore = 0; p->missions = 0; } else { p->missions++; } p->lastMission = co->MissionIndex; } if (allTime) { DisplayAllTimeHighScores(graphics); } if (todays) { DisplayTodaysHighScores(graphics); } } if (!HasRounds(co->Entry.Mode)) { co->MissionIndex++; } bail: // Need to terminate the mission later as it is used in calculating scores MissionOptionsTerminate(&gMission); } while (run && !gameOver); // Final screen if (run) { switch (co->Entry.Mode) { case GAME_MODE_DOGFIGHT: ScreenDogfightFinalScores(); break; default: // no end screen break; } } NetServerClose(&gNetServer); }