From d5eacb28e3ff9fc39d1af923e6b8799757a788cf Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sat, 16 May 2009 21:10:21 +0000 Subject: some changes to SetRanking to ensure that ranking for every team in the correct range is available git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1742 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Lua/src/base/UParty.pas | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Lua/src') diff --git a/Lua/src/base/UParty.pas b/Lua/src/base/UParty.pas index f042973e..713cfc33 100644 --- a/Lua/src/base/UParty.pas +++ b/Lua/src/base/UParty.pas @@ -541,11 +541,50 @@ end; { sets the winner(s) of current round returns true on success } function TPartyGame.SetRanking(Ranking: AParty_TeamRanking): Boolean; + var + I, J: Integer; + TeamExists: Integer; + Len: Integer; + Temp: TParty_TeamRanking; begin if (bPartyStarted) and (CurRound >= 0) and (CurRound <= High(Rounds)) then begin Rounds[CurRound].Ranking := Ranking; Result := true; + + // look for teams that don't exist + TeamExists := 0; + for I := 0 to High(Rounds[CurRound].Ranking) do + TeamExists := TeamExists or (1 shl (Rounds[CurRound].Ranking[I].Team-1)); + + // create teams that don't exist + Len := Length(Rounds[CurRound].Ranking); + for I := 0 to High(Teams) do + if (TeamExists and (1 shl I) = 0) then + begin + Inc(Len); + SetLength(Rounds[CurRound].Ranking, Len); + Rounds[CurRound].Ranking[Len-1].Team := I + 1; + Rounds[CurRound].Ranking[Len-1].Rank := Length(Teams); + end; + + // we may remove rankings from invalid teams here to + // but at the moment this is not necessary, because the + // functions this function is called from don't create + // invalid rankings + + // bubble sort rankings by team + J := High(Rounds[CurRound].Ranking); + repeat + for I := 0 to J - 1 do + if (Rounds[CurRound].Ranking[I].Team > Rounds[CurRound].Ranking[I+1].Team) then + begin + Temp := Rounds[CurRound].Ranking[I]; + Rounds[CurRound].Ranking[I] := Rounds[CurRound].Ranking[I+1]; + Rounds[CurRound].Ranking[I+1] := Temp; + end; + Dec(J); + until J <= 0; end else Result := false; -- cgit v1.2.3