Changeset 210
- Timestamp:
- May 23, 2018, 6:09:20 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r208 r210 354 354 Game: TGame; 355 355 NewPlayerId: Integer; 356 function GetAliveCount: Integer;357 356 function FindById(Id: Integer): TPlayer; 358 357 procedure New(Name: string; Color: TColor; Mode: TPlayerMode); … … 360 359 procedure LoadFromNode(Node: TDOMNode); 361 360 procedure SaveToNode(Node: TDOMNode); 362 constructor Create ;361 constructor Create(FreeObjects: Boolean = True); 363 362 function GetFirstHuman: TPlayer; 364 363 procedure Assign(Source: TPlayers); 365 364 procedure LoadConfig(Config: TXmlConfig; Path: string); 366 365 procedure SaveConfig(Config: TXmlConfig; Path: string); 367 function GetAlivePlayers: TPlayerArray; 366 function GetAliveCount: Integer; 367 procedure GetAlivePlayers(Players: TPlayers); overload; 368 function GetAlivePlayers: TPlayerArray; overload; 368 369 function GetAlivePlayersWithCities: TPlayerArray; 369 370 end; … … 1089 1090 end; 1090 1091 1092 procedure TPlayers.GetAlivePlayers(Players: TPlayers); 1093 var 1094 Player: TPlayer; 1095 begin 1096 Players.Clear; 1097 for Player in Self do 1098 if Player.IsAlive then Players.Add(Player); 1099 end; 1100 1091 1101 function TPlayers.FindById(Id: Integer): TPlayer; 1092 1102 var … … 1148 1158 end; 1149 1159 1150 constructor TPlayers.Create ;1151 begin 1152 inherited Create;1160 constructor TPlayers.Create(FreeObjects: Boolean = True); 1161 begin 1162 inherited; 1153 1163 NewPlayerId := 1; 1154 1164 end; … … 3155 3165 procedure TGame.NextPlayer; 3156 3166 var 3157 PrevPlayer: TPlayer; 3167 AlivePlayers: TPlayers; 3168 NewPlayerIndex: Integer; 3158 3169 begin 3159 3170 // Finalize current player … … 3163 3174 ComputePlayerStats; 3164 3175 3165 // Select new player 3166 PrevPlayer := CurrentPlayer; 3167 // Skip dead players 3168 repeat 3169 CurrentPlayer := Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count]; 3170 until CurrentPlayer.IsAlive; 3171 if Assigned(FOnPlayerChange) then 3172 FOnPlayerChange(Self); 3173 3174 if Players.IndexOf(CurrentPlayer) < Players.IndexOf(PrevPlayer) then begin 3176 // Select new player from alive players 3177 AlivePlayers := TPlayers.Create(False); 3178 Players.GetAlivePlayers(AlivePlayers); 3179 NewPlayerIndex := AlivePlayers.IndexOf(CurrentPlayer) + 1; 3180 if NewPlayerIndex >= AlivePlayers.Count then begin 3181 // Start of turn 3175 3182 Inc(TurnCounter); 3176 3183 RecordTurnStats; 3177 3184 if Assigned(FOnNewTurn) then 3178 3185 FOnNewTurn(Self); 3179 end; 3186 NewPlayerIndex := NewPlayerIndex mod AlivePlayers.Count; 3187 end; 3188 CurrentPlayer := AlivePlayers[NewPlayerIndex]; 3189 3190 if Assigned(FOnPlayerChange) then 3191 FOnPlayerChange(Self); 3180 3192 CheckWinObjective; 3181 3193 CurrentPlayer.PlayerMap.CheckVisibility;
Note:
See TracChangeset
for help on using the changeset viewer.