本文整理汇总了C++中game_state::broadcast方法的典型用法代码示例。如果您正苦于以下问题:C++ game_state::broadcast方法的具体用法?C++ game_state::broadcast怎么用?C++ game_state::broadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game_state
的用法示例。
在下文中一共展示了game_state::broadcast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: balance_first_to_x
void balance_first_to_x(game_state& state)
{
if(state.number_of_team(0) == state.number_of_team(1))
return;
///odd number of players, rest in peace
if(abs(state.number_of_team(1) - state.number_of_team(0)) == 1)
return;
int t0 = state.number_of_team(0);
int t1 = state.number_of_team(1);
int team_to_swap = t1 > t0 ? 1 : 0;
int team_to_swap_to = t1 < t0 ? 1 : 0;
int extra = abs(state.number_of_team(1) - state.number_of_team(0));
int num_to_swap = extra / 2;
int num_swapped = 0;
for(auto& i : state.player_list)
{
if(i.team == team_to_swap && num_swapped < num_to_swap)
{
i.team = team_to_swap_to;
///network
byte_vector vec;
vec.push_back(canary_start);
vec.push_back(message::TEAMASSIGNMENT);
vec.push_back<int32_t>(i.id);
vec.push_back<int32_t>(i.team);
vec.push_back(canary_end);
//udp_send_to(i.sock, vec.ptr, (const sockaddr*)&i.store);
int no_player = -1;
state.broadcast(vec.ptr, no_player);
num_swapped++;
}
}
}
示例2: balance_ffa
///well, more of an iterative balance. Should probably make it properly fully balance
///team data isn't reliable. Am I an idiot?
///this is not a good balance, we want to distribute players evenly between teams
void balance_ffa(game_state& state)
{
int number_of_players = state.player_list.size();
int max_players_per_team = (number_of_players / TEAM_NUMS) + 1;
//printf("Max num of players per team %i\ncurrentplayernum %i\n", max_players_per_team, number_of_players);;
std::vector<int32_t> too_big_teams;
too_big_teams.resize(TEAM_NUMS);
for(int i=0; i<TEAM_NUMS; i++)
{
if(state.number_of_team(i) > max_players_per_team)
{
too_big_teams[i] = 1;
}
}
for(auto& i : state.player_list)
{
if(i.team < 0 || i.team >= too_big_teams.size() || too_big_teams[i.team] == 1)
{
int old_team = i.team;
i.team = (i.team + 1) % TEAM_NUMS;
byte_vector vec;
vec.push_back(canary_start);
vec.push_back(message::TEAMASSIGNMENT);
vec.push_back<int32_t>(i.id);
vec.push_back<int32_t>(i.team);
vec.push_back(canary_end);
int no_player = -1;
state.broadcast(vec.ptr, no_player);
if(old_team >= 0 && old_team < too_big_teams.size())
too_big_teams[old_team] = 0;
}
}
}