Returns a random player starting position
| 1288 | |
| 1289 | // Returns a random player starting position |
| 1290 | int PlayerGetRandomStartPosition(int slot) { |
| 1291 | if (Netgame.flags & NF_RESPAWN_WAYPOINT) { |
| 1292 | // Grab an autowaypoint |
| 1293 | if (Players[slot].current_auto_waypoint_room != -1) { |
| 1294 | int waypointnum = -(Players[slot].current_auto_waypoint_room - 1); |
| 1295 | return waypointnum; |
| 1296 | } else { |
| 1297 | if (Current_waypoint < 0) |
| 1298 | return 0; |
| 1299 | else |
| 1300 | return Current_waypoint; |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | ps_srand((timer_GetTime() * 1000)); |
| 1305 | // If this is a team game then pick a spot on that team |
| 1306 | if (Team_game) { |
| 1307 | |
| 1308 | int team = PlayerGetTeam(slot); |
| 1309 | mprintf(0, "Picking team start position, team=%d.\n", team); |
| 1310 | int num_avail = 0; |
| 1311 | int avail_array[MAX_PLAYERS]; |
| 1312 | |
| 1313 | for (int i = 0; i <= Highest_player_start; i++) { |
| 1314 | if ((Players[i].startpos_flags & (1 << team)) && Players[i].start_roomnum != -1) { |
| 1315 | avail_array[num_avail] = i; |
| 1316 | num_avail++; |
| 1317 | } |
| 1318 | } |
| 1319 | if (num_avail > 0) { |
| 1320 | int num; |
| 1321 | int done = 0; |
| 1322 | while (!done) { |
| 1323 | num = avail_array[ps_rand() % (num_avail)]; |
| 1324 | if (Players[num].start_roomnum != -1) |
| 1325 | done = 1; |
| 1326 | } |
| 1327 | return num; |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | // Default to non-team mode |
| 1332 | int num; |
| 1333 | int done = 0; |
| 1334 | int badcount = 0; |
| 1335 | mprintf(0, "Picking non-team start position.\n"); |
| 1336 | while (!done) { |
| 1337 | num = ps_rand() % (Highest_player_start + 1); |
| 1338 | if (Players[num].start_roomnum != -1) { |
| 1339 | // Check to see if there are any other players in this room |
| 1340 | int objnum = -1; |
| 1341 | if (Players[num].start_roomnum >= 0) { |
| 1342 | room *rp = &Rooms[Players[num].start_roomnum]; |
| 1343 | objnum = rp->objects; |
| 1344 | } else { |
| 1345 | objnum = Terrain_seg[Players[num].start_roomnum].objects; |
| 1346 | } |
| 1347 | int bad = 0; |
no test coverage detected