MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / FindRoleForAssign

Function FindRoleForAssign

engine/Poseidon/UI/DisplayUISetup.cpp:67–84  ·  view source on GitHub ↗

Find flat role index for given side and 1-based slot number Returns -1 if not found, -2 if slot is occupied by another human

Source from the content-addressed store, hash-verified

65}
66
67// Find flat role index for given side and 1-based slot number
68// Returns -1 if not found, -2 if slot is occupied by another human
69static int FindRoleForAssign(TargetSide side, int slot, int myPlayer)
70{
71 int sideCount = 0;
72 for (int i = 0; i < GetNetworkManager().NPlayerRoles(); i++)
73 {
74 const PlayerRole* role = GetNetworkManager().GetPlayerRole(i);
75 if (!role || role->side != side)
76 continue;
77 sideCount++;
78 if (sideCount == slot)
79 {
80 if (role->player != NO_PLAYER && role->player != AI_PLAYER && role->player != myPlayer)
81 return -2; // occupied
82 return i;
83 }
84 }
85 return -1; // slot doesn't exist
86}
87

Callers 1

OnSimulateMethod · 0.85

Calls 2

NPlayerRolesMethod · 0.45
GetPlayerRoleMethod · 0.45

Tested by

no test coverage detected