From 1fcd567446dce6e5e02d802e26cf38a538092cf3 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sat, 14 Apr 2007 16:54:30 +0000 Subject: Did Some Code Cleanup Fixed some Bugs in Party Mode Added a Better Round Plugin Selection git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@89 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UParty.pas | 120 ++++++++++++++++++++++++++---- Game/Code/Screens/UScreenMain.pas | 61 +-------------- Game/Code/Screens/UScreenPartyOptions.pas | 23 ++---- Game/Code/Screens/UScreenPartyPlayer.pas | 4 - 4 files changed, 114 insertions(+), 94 deletions(-) diff --git a/Game/Code/Classes/UParty.pas b/Game/Code/Classes/UParty.pas index da89ca8a..f5834dd8 100644 --- a/Game/Code/Classes/UParty.pas +++ b/Game/Code/Classes/UParty.pas @@ -22,7 +22,7 @@ type constructor Create; - procedure StartNewParty; + procedure StartNewParty(NumRounds: Byte); procedure StartRound; procedure EndRound; function GetWinner: Byte; @@ -47,14 +47,98 @@ end; //---------- //StartNewParty - Clears the Class and Prepares for new Party //---------- -procedure TParty_Session.StartNewParty; +procedure TParty_Session.StartNewParty(NumRounds: Byte); +var + Plugins: Array of record + ID: Byte; + TimesPlayed: Byte; + end; + TeamMode: Boolean; + Len: Integer; + I: Integer; + + function GetRandomPlugin: Byte; + var + LowestTP: Byte; + NumPwithLTP: Word; + I: Integer; + R: Word; + begin + LowestTP := high(Byte); + NumPwithLTP := 0; + + //Search for Plugins not often played yet + For I := 0 to high(Plugins) do + begin + if (Plugins[I].TimesPlayed < lowestTP) then + begin + lowestTP := Plugins[I].TimesPlayed; + NumPwithLTP := 1; + end + else if (Plugins[I].TimesPlayed = lowestTP) then + begin + Inc(NumPwithLTP); + end; + end; + + //Create Random No + R := Random(NumPwithLTP); + + //Search for Random Plugin + For I := 0 to high(Plugins) do + begin + if Plugins[I].TimesPlayed = lowestTP then + begin + //Plugin Found + if (R = 0) then + begin + Result := Plugins[I].ID; + Inc(Plugins[I].TimesPlayed); + Break; + end; + + Dec(R); + end; + end; + end; begin -//Set cur Round to Round 1 -CurRound := 255; + //Set cur Round to Round 1 + CurRound := 255; + + PlayersPlay := Teams.NumTeams; -PlayersPlay := Teams.NumTeams; -if isWinner(0,9) then - Log.LogError('Test'); + TeamMode := True; + For I := 0 to Teams.NumTeams-1 do + if Teams.Teaminfo[I].NumPlayers < 2 then + begin + TeamMode := False; + Break; + end; + + //Fill Plugin Array + SetLength(Plugins, 0); + For I := 0 to high(DLLMan.Plugins) do + begin + if TeamMode or (Not DLLMan.Plugins[I].TeamModeOnly) then + begin //Add only Plugins Playable with cur. PlayerConfiguration + Len := Length(Plugins); + SetLength(Plugins, Len + 1); + Plugins[Len].ID := I; + Plugins[Len].TimesPlayed := 0; + end; + end; + + //Set Rounds + If (Length(Plugins) >= 1) then + begin + SetLength (Rounds, NumRounds); + For I := 0 to NumRounds-1 do + begin + PartySession.Rounds[I].Plugin := GetRandomPlugin; + PartySession.Rounds[I].Winner := 255; + end; + end + else SetLength (Rounds, 0); end; //---------- @@ -65,10 +149,10 @@ var I, J: Integer; lowestTP: Byte; begin - //Get lowest TP + //Get lowest TimesPlayed lowestTP := high(Byte); J := -1; - for I := 0 to Teams.Teaminfo[Team].NumPlayers do + for I := 0 to Teams.Teaminfo[Team].NumPlayers-1 do begin if (Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed < lowestTP) then begin @@ -86,7 +170,7 @@ begin repeat Result := Random(Teams.Teaminfo[Team].NumPlayers); until (Teams.Teaminfo[Team].Playerinfo[Result].TimesPlayed = lowestTP) - else //Else Select the one wth lowest TP + else //Else Select the one with lowest TP Result:= J; end; @@ -106,7 +190,7 @@ begin DllMan.LoadPlugin(Rounds[CurRound].Plugin); //Select Players - for I := 0 to Teams.NumTeams do + for I := 0 to Teams.NumTeams-1 do Teams.Teaminfo[I].CurPlayer := GetRandomPlayer(I); //Set ScreenSingModie Variables @@ -142,7 +226,7 @@ procedure TParty_Session.GenScores; var I: Byte; begin - for I := 0 to Teams.NumTeams do + for I := 0 to Teams.NumTeams-1 do begin if isWinner(I, Rounds[CurRound].Winner) then Inc(Teams.Teaminfo[I].Score); @@ -159,12 +243,18 @@ var begin if (Rounds[Round].Winner = 0) then begin - Result := 'Nobody'; + Result := Language.Translate('PARTY_NOBODY'); + exit; + end; + + if (Rounds[Round].Winner = 255) then + begin + Result := Language.Translate('PARTY_NOTPLAYEDYET'); exit; end; SetLength(Winners, 0); - for I := 0 to Teams.NumTeams do + for I := 0 to Teams.NumTeams-1 do begin if isWinner(I, Rounds[Round].Winner) then begin @@ -188,7 +278,7 @@ begin GenScores; //Increase TimesPlayed 4 all Players - For I := 0 to Teams.NumTeams do + For I := 0 to Teams.NumTeams-1 do Inc(Teams.Teaminfo[I].Playerinfo[Teams.Teaminfo[0].CurPlayer].TimesPlayed); end; diff --git a/Game/Code/Screens/UScreenMain.pas b/Game/Code/Screens/UScreenMain.pas index 5849341c..976c0e07 100644 --- a/Game/Code/Screens/UScreenMain.pas +++ b/Game/Code/Screens/UScreenMain.pas @@ -128,65 +128,8 @@ begin end; SDLK_M: begin - if (SDL_ModState = KMOD_LALT) then - begin - //Create Teams: - PartySession.Teams.NumTeams := 3; - //Team 1 - PartySession.Teams.Teaminfo[0].Name := 'Team 1'; - PartySession.Teams.Teaminfo[0].Score:= 0; - PartySession.Teams.Teaminfo[0].Joker := 3; - PartySession.Teams.Teaminfo[0].CurPlayer := 0; - PartySession.Teams.Teaminfo[0].NumPlayers := 2; - PartySession.Teams.Teaminfo[0].Playerinfo[0].Name := 'Player 1'; - PartySession.Teams.Teaminfo[0].Playerinfo[0].TimesPlayed := 0; - PartySession.Teams.Teaminfo[0].Playerinfo[1].Name := 'Player 2'; - PartySession.Teams.Teaminfo[0].Playerinfo[1].TimesPlayed := 0; - - //Team 2 - PartySession.Teams.Teaminfo[1].Name := 'Team 2'; - PartySession.Teams.Teaminfo[1].Score:= 0; - PartySession.Teams.Teaminfo[1].Joker := 3; - PartySession.Teams.Teaminfo[1].CurPlayer := 0; - PartySession.Teams.Teaminfo[1].NumPlayers := 2; - PartySession.Teams.Teaminfo[1].Playerinfo[0].Name := 'Player 3'; - PartySession.Teams.Teaminfo[1].Playerinfo[0].TimesPlayed := 0; - PartySession.Teams.Teaminfo[1].Playerinfo[1].Name := 'Player 4'; - PartySession.Teams.Teaminfo[1].Playerinfo[1].TimesPlayed := 0; - - //Team 3 - PartySession.Teams.Teaminfo[2].Name := 'Team 3'; - PartySession.Teams.Teaminfo[2].Score:= 0; - PartySession.Teams.Teaminfo[2].Joker := 3; - PartySession.Teams.Teaminfo[2].CurPlayer := 0; - PartySession.Teams.Teaminfo[2].NumPlayers := 2; - PartySession.Teams.Teaminfo[2].Playerinfo[0].Name := 'Player 5'; - PartySession.Teams.Teaminfo[2].Playerinfo[0].TimesPlayed := 0; - PartySession.Teams.Teaminfo[2].Playerinfo[1].Name := 'Player 6'; - PartySession.Teams.Teaminfo[2].Playerinfo[1].TimesPlayed := 0; - - //Rounds: - SetLength (PartySession.Rounds, 3); - PartySession.Rounds[0].Plugin := 1; - PartySession.Rounds[0].Winner := 0; - PartySession.Rounds[1].Plugin := 0; - PartySession.Rounds[1].Winner := 0; - PartySession.Rounds[2].Plugin := 0; - PartySession.Rounds[2].Winner := 0; - - //Start Party - PartySession.StartNewParty; - //Change Screen - Music.PlayStart; - FadeTo(@ScreenPartyNewRound); - - end - else - begin - Music.PlayStart; - FadeTo(@ScreenPartyOptions); - end; - + Music.PlayStart; + FadeTo(@ScreenPartyOptions); end; SDLK_RETURN: diff --git a/Game/Code/Screens/UScreenPartyOptions.pas b/Game/Code/Screens/UScreenPartyOptions.pas index 042e944f..1fd4da8f 100644 --- a/Game/Code/Screens/UScreenPartyOptions.pas +++ b/Game/Code/Screens/UScreenPartyOptions.pas @@ -95,7 +95,6 @@ begin SDLK_RETURN: begin - //Save Difficulty Ini.Difficulty := SelectsS[SelectLevel].SelectedOption; Ini.SaveLevel; @@ -106,6 +105,7 @@ begin PartySession.Teams.Teaminfo[0].NumPlayers := NumPlayer1+1; PartySession.Teams.Teaminfo[1].NumPlayers := NumPlayer2+1; PartySession.Teams.Teaminfo[2].NumPlayers := NumPlayer3+1; + //Save Playlist PlaylistMan.Mode := Playlist; //If Category Selected Search Category ID @@ -126,13 +126,10 @@ begin end else PlaylistMan.CurPlayList := Playlist2; - //Save Rounds + Random - SetLength (PartySession.Rounds, Rounds + 2); - For I := 0 to high (PartySession.Rounds) do - begin - PartySession.Rounds[I].Plugin := Random (Length(DLLMan.Plugins)); - PartySession.Rounds[I].Winner := 0; - end; + + //Start Party + PartySession.StartNewParty(Rounds + 2); + Music.PlayStart; //Go to Player Screen FadeTo(@ScreenPartyPlayer); @@ -155,10 +152,7 @@ begin end //Change Team3 Players visibility Else If (Interaction = 4) then begin - Case NumTeams of - 0: SelectsS[7].Visible := False; - 1: SelectsS[7].Visible := True; - end; + SelectsS[7].Visible := (NumTeams = 1); end; end; SDLK_LEFT: @@ -173,10 +167,7 @@ begin end //Change Team3 Players visibility Else If (Interaction = 4) then begin - Case NumTeams of - 0: SelectsS[7].Visible := False; - 1: SelectsS[7].Visible := True; - end; + SelectsS[7].Visible := (NumTeams = 1); end; end; end; diff --git a/Game/Code/Screens/UScreenPartyPlayer.pas b/Game/Code/Screens/UScreenPartyPlayer.pas index 4fc43013..498514fb 100644 --- a/Game/Code/Screens/UScreenPartyPlayer.pas +++ b/Game/Code/Screens/UScreenPartyPlayer.pas @@ -87,10 +87,6 @@ begin PartySession.Teams.Teaminfo[I].Joker := Round (Length(PartySession.Rounds) * 0.85); end; - - //Start Party - PartySession.StartNewParty; - Music.PlayStart; FadeTo(@ScreenPartyNewRound); end; -- cgit v1.2.3