本文整理汇总了C++中GetNumPlayers函数的典型用法代码示例。如果您正苦于以下问题:C++ GetNumPlayers函数的具体用法?C++ GetNumPlayers怎么用?C++ GetNumPlayers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetNumPlayers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PlayerSelection
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;
}
示例2: UE_LOG
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);
}
示例3: Q_ASSERT
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());
}
示例4: PrintStats
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");
}
示例5: GetNode
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;
}
示例6: data
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);
}
示例7: PlayerEquipDraw
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);
}
}
示例8: disconnect
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);
}
}
示例9: GetPlayerCenter
// 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;
}
示例10: CameraInput
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;
}
}
}
}
示例11: PlayerEquipUpdate
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;
}
示例12: data
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);
}
示例13: IsEveryoneReady
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;
}
示例14: data
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);
}
示例15: PlayerSelectionDraw
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));
}
}
}