/** * @brief Set the used team for the given player * @param[out] player The player the team should be set for * @param[in] team The team to set for the given player * @return <code>true</code> if the team was set successfully, <code>false</code> otherwise. */ bool G_SetTeamForPlayer (player_t* player, const int team) { assert(player); assert(team >= TEAM_NO_ACTIVE && team < MAX_TEAMS); if (G_IsAIPlayer(player)) { if (team != TEAM_ALIEN && team != TEAM_CIVILIAN) return false; } else { if (!sv_teamplay->integer) { player_t *p = NULL; while ((p = G_PlayerGetNextHuman(p)) != NULL) { if (p->pers.team == team) return false; } } } player->pers.team = team; /* if we started in dev mode, we maybe don't have a * starting position in this map */ if (!g_nospawn->integer) { if (team >= 0 && team < MAX_TEAMS) { if (!level.num_spawnpoints[team]) gi.Error("No spawnpoints for team %i", team); } } if (!G_IsAIPlayer(player)) Info_SetValueForKeyAsInteger(player->pers.userinfo, sizeof(player->pers.userinfo), "cl_team", team); return true; }
TEST_F(GameTest, SpawnAndConnect) { char userinfo[MAX_INFO_STRING]; player_t* player; const char* name = "name"; bool day = true; byte* buf; /* this entity string may not contain any inline models, we don't have the bsp tree loaded here */ const int size = FS_LoadFile("game/entity.txt", &buf); Edict* e = nullptr; int cnt = 0; ASSERT_NE(size, -1) << "could not load game/entity.txt."; ASSERT_TRUE(size > 0) << "game/entity.txt is empty."; SV_InitGameProgs(); /* otherwise we can't link the entities */ SV_ClearWorld(); player = G_PlayerGetNextHuman(0); svs.ge->SpawnEntities(name, day, (const char*)buf); ASSERT_TRUE(svs.ge->ClientConnect(player, userinfo, sizeof(userinfo))) << "Failed to connect the client"; ASSERT_FALSE(svs.ge->RunFrame()) << "Failed to run the server logic frame tick"; while ((e = G_EdictsGetNextInUse(e))) { Com_Printf("entity %i: %s\n", cnt, e->classname); cnt++; } ASSERT_EQ(cnt, 43); FS_FreeFile(buf); }
static void testSpawnAndConnect (void) { char userinfo[MAX_INFO_STRING]; player_t *player; const char *name = "name"; bool day = true; byte *buf; /* this entity string may not contain any inline models, we don't have the bsp tree loaded here */ const int size = FS_LoadFile("game/entity.txt", &buf); edict_t *e = NULL; int cnt = 0; CU_ASSERT_NOT_EQUAL_FATAL(size, -1); CU_ASSERT_FATAL(size > 0); SV_InitGameProgs(); /* otherwise we can't link the entities */ SV_ClearWorld(); player = G_PlayerGetNextHuman(0); svs.ge->SpawnEntities(name, day, (const char *)buf); CU_ASSERT_TRUE(svs.ge->ClientConnect(player, userinfo, sizeof(userinfo))); CU_ASSERT_FALSE(svs.ge->RunFrame()); while ((e = G_EdictsGetNextInUse(e))) { Com_Printf("entity %i: %s\n", cnt, e->classname); cnt++; } CU_ASSERT_EQUAL(cnt, 45); SV_ShutdownGameProgs(); FS_FreeFile(buf); }
/** * @brief Iterate through the list of players * @param lastPlayer The player found in the previous iteration; if NULL, we start at the beginning */ player_t* G_PlayerGetNextActiveHuman (player_t* lastPlayer) { player_t* player = lastPlayer; while ((player = G_PlayerGetNextHuman(player))) { if (player->inuse) return player; } return NULL; }
/** * @brief Generates the player bit mask for a given team * @param[in] team The team to create the player bit mask for * @note E.g. multiplayer team play can have more than one human player on the * same team. */ playermask_t G_TeamToPM (int team) { player_t *p; playermask_t playerMask; playerMask = 0; /* don't handle the ai players, here */ p = NULL; while ((p = G_PlayerGetNextHuman(p))) { if (p->inuse && team == p->pers.team) playerMask |= G_PlayerToPM(p); } return playerMask; }