change the shuffle logic

This commit is contained in:
Beu 2023-07-12 12:16:23 +02:00
parent c59cc3f3d6
commit d89ee0739e

View File

@ -278,22 +278,20 @@ declare Integer LandmarkIndex for This = 0;
AccountIdsOfPlayers = []; AccountIdsOfPlayers = [];
// Suffle Players list to randomise spawn // Suffle Players list to randomise spawn
declare CSmPlayer[] ShuffledPlayers = Players; declare CSmPlayer[Integer] ShuffledPlayers;
declare Integer i=0;
while(i<ShuffledPlayers.count) { // this should be enough, you can use arbitrary values, should the need arise foreach (Player in Players) {
// find a pair (a,b) of valid indices to swap declare Integer RandomIndex = 0;
declare a=ML::Rand(0, ShuffledPlayers.count-1); while (RandomIndex == 0 || ShuffledPlayers.existskey(RandomIndex)) {
declare b=ML::Rand(0, ShuffledPlayers.count-1); RandomIndex = ML::Rand(1, 10000);
}
// now swap them ShuffledPlayers[RandomIndex] = Player;
declare tmp=ShuffledPlayers[b];
ShuffledPlayers[b]=ShuffledPlayers[a];
ShuffledPlayers[a]=tmp;
i=i+1;
} }
ShuffledPlayers = ShuffledPlayers.sortkey();
foreach (Player in ShuffledPlayers) { foreach (Player in ShuffledPlayers) {
if (Player == Null) continue;
PlayerLM = Null; PlayerLM = Null;
while (PlayerLM == Null) { while (PlayerLM == Null) {
if (LandmarkIndex > Landmarks.count - 1 ) { if (LandmarkIndex > Landmarks.count - 1 ) {