aboutsummaryrefslogtreecommitdiffstats
path: root/Lua
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-05-16 21:10:21 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-05-16 21:10:21 +0000
commitd5eacb28e3ff9fc39d1af923e6b8799757a788cf (patch)
tree57e6b88944ddb1a7ae4f2233011ec972a65f295e /Lua
parent709665c02cfb5cbaf502e3d28f2d53fbe09477b5 (diff)
downloadusdx-d5eacb28e3ff9fc39d1af923e6b8799757a788cf.tar.gz
usdx-d5eacb28e3ff9fc39d1af923e6b8799757a788cf.tar.xz
usdx-d5eacb28e3ff9fc39d1af923e6b8799757a788cf.zip
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
Diffstat (limited to 'Lua')
-rw-r--r--Lua/src/base/UParty.pas39
1 files changed, 39 insertions, 0 deletions
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;