当前位置: 首页>>代码示例>>C++>>正文


C++ game_state::number_of_team方法代码示例

本文整理汇总了C++中game_state::number_of_team方法的典型用法代码示例。如果您正苦于以下问题:C++ game_state::number_of_team方法的具体用法?C++ game_state::number_of_team怎么用?C++ game_state::number_of_team使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在game_state的用法示例。


在下文中一共展示了game_state::number_of_team方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
        }
    }
}
开发者ID:20k,项目名称:sword_gameserver,代码行数:46,代码来源:game_state.cpp

示例2: 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++;
        }
    }
}
开发者ID:20k,项目名称:sword_gameserver,代码行数:45,代码来源:game_state.cpp


注:本文中的game_state::number_of_team方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。