#include <TeamBalancer.h>
Public Types | |
enum | DefaultAssigmentAlgorithm { SMALLEST_TEAM, FILL_IN_ORDER } |
Public Member Functions | |
void | SetTeamSizeLimit (TeamId team, unsigned short limit) |
Set the limit to the number of players on the specified team. | |
void | SetDefaultAssignmentAlgorithm (DefaultAssigmentAlgorithm daa) |
Determine how players' teams will be set when they call RequestAnyTeam(). | |
void | SetForceEvenTeams (bool force) |
By default, teams can be unbalanced up to the team size limit defined by SetTeamSizeLimits(). | |
void | SetLockTeams (bool lock) |
If set, calls to RequestSpecificTeam() and RequestAnyTeam() will return the team you are currently on. | |
void | RequestSpecificTeam (NetworkID memberId, TeamId desiredTeam) |
void | CancelRequestSpecificTeam (NetworkID memberId) |
void | RequestAnyTeam (NetworkID memberId) |
TeamId | GetMyTeam (NetworkID memberId) const |
void | SetAllowHostMigration (bool allow) |
Protected Member Functions | |
virtual PluginReceiveResult | OnReceive (Packet *packet) |
virtual void | OnClosedConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason) |
void | OnAttach (void) |
Called when the interface is attached. |
Automatically handles transmission and resolution of team selection, including team switching and balancing.
Usage: TODO
void RakNet::TeamBalancer::CancelRequestSpecificTeam | ( | NetworkID | memberId | ) |
If ID_TEAM_BALANCER_REQUESTED_TEAM_CHANGE_PENDING is returned after a call to RequestSpecificTeam(), the request will stay in memory on the host and execute when available, or until the teams become locked. You can cancel the request by calling CancelRequestSpecificTeam(), in which case you will stay on your existing team.
[in] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSINGED_NETWORK_ID if there is only one player. |
TeamId RakNet::TeamBalancer::GetMyTeam | ( | NetworkID | memberId | ) | const |
Returns your team. As your team changes, you are notified through the ID_TEAM_BALANCER_TEAM_ASSIGNED packet in byte 1. Returns UNASSIGNED_TEAM_ID initially
[in] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSINGED_NETWORK_ID if there is only one player. |
virtual void RakNet::TeamBalancer::OnClosedConnection | ( | const SystemAddress & | systemAddress, | |
RakNetGUID | rakNetGUID, | |||
PI2_LostConnectionReason | lostConnectionReason | |||
) | [protected, virtual] |
Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system
[in] | systemAddress | The system whose connection was closed |
[in] | rakNetGuid | The guid of the specified system |
[in] | lostConnectionReason | How the connection was closed: manually, connection lost, or notification of disconnection |
Reimplemented from RakNet::PluginInterface2.
virtual PluginReceiveResult RakNet::TeamBalancer::OnReceive | ( | Packet * | packet | ) | [protected, virtual] |
OnReceive is called for every packet.
[in] | packet | the packet that is being returned to the user |
Reimplemented from RakNet::PluginInterface2.
void RakNet::TeamBalancer::RequestAnyTeam | ( | NetworkID | memberId | ) |
Allow host to pick your team, based on whatever algorithm it uses for default team assignments. This only has an effect if you are not currently on a team (GetMyTeam() returns UNASSIGNED_TEAM_ID)
[in] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSINGED_NETWORK_ID if there is only one player. |
void RakNet::TeamBalancer::RequestSpecificTeam | ( | NetworkID | memberId, | |
TeamId | desiredTeam | |||
) |
Set your requested team. UNASSIGNED_TEAM_ID means no team. After enough time for network communication, ID_TEAM_BALANCER_SET_TEAM will be returned with your current team, or If team switch is not possible, ID_TEAM_BALANCER_REQUESTED_TEAM_CHANGE_PENDING or ID_TEAM_BALANCER_TEAMS_LOCKED will be returned. In the case of ID_TEAM_BALANCER_REQUESTED_TEAM_CHANGE_PENDING the request will stay in memory. ID_TEAM_BALANCER_SET_TEAM will be returned when someone on the desired team leaves or wants to switch to your team. If SetLockTeams(true) is called while you have a request pending, you will get ID_TEAM_BALANCER_TEAMS_LOCKED
[in] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSINGED_NETWORK_ID if there is only one player. |
[in] | desiredTeam | An index representing your team number. The index should range from 0 to one less than the size of the list passed to SetTeamSizeLimits() on the host. You can also pass UNASSIGNED_TEAM_ID to not be on any team (such as if spectating) |
void RakNet::TeamBalancer::SetAllowHostMigration | ( | bool | allow | ) |
Allow systems to change the host If true, this is a security hole, but needed for peer to peer For client server, set to false Defaults to true param[in] allow True to allow host migration, false to not allow
void RakNet::TeamBalancer::SetDefaultAssignmentAlgorithm | ( | DefaultAssigmentAlgorithm | daa | ) |
Determine how players' teams will be set when they call RequestAnyTeam().
Based on the specified enumeration, a player will join a team automatically Defaults to SMALLEST_TEAM This function is only used by the host
[in] | daa | Enumeration describing the algorithm to use |
void RakNet::TeamBalancer::SetForceEvenTeams | ( | bool | force | ) |
By default, teams can be unbalanced up to the team size limit defined by SetTeamSizeLimits().
If SetForceEvenTeams(true) is called on the host, then teams cannot be unbalanced by more than 1 player If teams are uneven at the time that SetForceEvenTeams(true) is called, players at randomly will be switched, and will be notified of ID_TEAM_BALANCER_TEAM_ASSIGNED If players disconnect from the host such that teams would not be even, and teams are not locked, then a player from the largest team is randomly moved to even the teams. Defaults to false
[in] | force | True to force even teams. False to allow teams to not be evenly matched |
void RakNet::TeamBalancer::SetLockTeams | ( | bool | lock | ) |
If set, calls to RequestSpecificTeam() and RequestAnyTeam() will return the team you are currently on.
However, if those functions are called and you do not have a team, then you will be assigned to a default team according to SetDefaultAssignmentAlgorithm() and possibly SetForceEvenTeams(true) If lock is false, and SetForceEvenTeams() was called with force as true, and teams are currently uneven, they will be made even, and those players randomly moved will get ID_TEAM_BALANCER_TEAM_ASSIGNED Defaults to false
[in] | lock | True to lock teams, false to unlock |
void RakNet::TeamBalancer::SetTeamSizeLimit | ( | TeamId | team, | |
unsigned short | limit | |||
) |
Set the limit to the number of players on the specified team.
SetTeamSizeLimit() must be called on the host, so the host can enforce the maximum number of players on each team. SetTeamSizeLimit() can be called on all systems if desired - for example, in a P2P environment you may wish to call it on all systems in advanced in case you become host.
[in] | team | Which team to set the limit for |
[in] | limit | The maximum number of people on this team |