MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FindPlayerStarts

Function FindPlayerStarts

Descent3/Player.cpp:1211–1287  ·  view source on GitHub ↗

Look for player objects & set player starts

Source from the content-addressed store, hash-verified

1209
1210// Look for player objects & set player starts
1211void FindPlayerStarts() {
1212 int i;
1213 int unique = 0;
1214
1215 // Flag all players as unused
1216 for (i = 0; i < MAX_PLAYERS; i++)
1217 Players[i].start_roomnum = -1;
1218
1219 Highest_player_start = 0;
1220
1221 if (Game_mode & GM_MULTI) {
1222 ps_srand(400);
1223 }
1224
1225 // Now look for player objects
1226 for (i = 0; i <= Highest_object_index; i++)
1227 if (Objects[i].type == OBJ_PLAYER) {
1228 ASSERT(Players[Objects[i].id].start_roomnum == -1); // make sure not used twice
1229 Players[Objects[i].id].start_pos = Objects[i].pos;
1230 Players[Objects[i].id].start_roomnum = Objects[i].roomnum;
1231 Players[Objects[i].id].start_orient = Objects[i].orient;
1232 Players[Objects[i].id].objnum = i;
1233
1234 if (Objects[i].id > Highest_player_start)
1235 Highest_player_start = Objects[i].id;
1236
1237 unique++;
1238 }
1239
1240 mprintf(0, "There are %d unique start positions in this level\n", unique);
1241
1242 // Now create the extra players
1243 if (Game_mode & GM_MULTI) {
1244 // Build a list so we can fill in the rest
1245 int choose_list[MAX_PLAYERS];
1246 int num_choose = 0;
1247 for (i = 0; i < MAX_PLAYERS; i++) {
1248 if (Players[i].start_roomnum != -1) {
1249 choose_list[num_choose++] = i;
1250 }
1251 }
1252 for (i = Highest_player_start + 1; i < MAX_PLAYERS; i++) {
1253 int oldplaynum = ps_rand() % num_choose;
1254 oldplaynum = choose_list[oldplaynum];
1255
1256 int objnum = ObjCreate(OBJ_PLAYER, i, Players[oldplaynum].start_roomnum, &Players[oldplaynum].start_pos,
1257 &Players[oldplaynum].start_orient);
1258 ASSERT(objnum >= 0);
1259 Players[Objects[objnum].id].start_pos = Players[oldplaynum].start_pos;
1260 Players[Objects[objnum].id].start_roomnum = Players[oldplaynum].start_roomnum;
1261 Players[Objects[objnum].id].start_orient = Players[oldplaynum].start_orient;
1262 Players[Objects[objnum].id].startpos_flags = Players[oldplaynum].startpos_flags;
1263 Players[Objects[objnum].id].objnum = objnum;
1264 if (Objects[objnum].id > Highest_player_start)
1265 Highest_player_start = Objects[objnum].id;
1266 }
1267
1268 for (i = 0; i < MAX_PLAYERS; i++) {

Callers 3

CreateNewMineFunction · 0.85
EditorToGameFunction · 0.85
LoadLevelFunction · 0.85

Calls 3

ps_srandFunction · 0.85
ps_randFunction · 0.85
ObjCreateFunction · 0.85

Tested by

no test coverage detected