Changeset 198 for trunk/UGame.pas
- Timestamp:
- May 16, 2018, 1:38:11 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r197 r198 30 30 31 31 TTerrainType = (ttVoid, ttNormal, ttCity); 32 TExtraType = (etNone, etObjectiveTarget, etAttack, etDefense, etLookout, 33 etGrowLow, etGrowMedium, etGrowHigh); 32 34 33 35 { TCell } … … 55 57 Angle: Double; // Temporary value 56 58 Links: TCellLinks; 59 Extra: TExtraType; 57 60 procedure ConnectTo(Cell: TCell); 58 61 procedure DisconnectFrom(Cell: TCell); … … 85 88 function FindById(Id: Integer): TCell; 86 89 procedure GetCellsWithWeight(List: TCells; Low, High: Integer); 90 procedure GetCellsWithExtra(List: TCells; Extra: TExtraType); 87 91 procedure LoadFromNode(Node: TDOMNode); 88 92 procedure SaveToNode(Node: TDOMNode); … … 439 443 procedure PropagatePlayerDistance(List: TCells); 440 444 procedure InitDefaultPlayersSetting; 445 procedure WinObjectiveMapPrepare; 441 446 public 442 447 DevelMode: Boolean; … … 455 460 TurnCounter: Integer; 456 461 WinObjective: TWinObjective; 457 SpecialCaptureCell : TCell;462 SpecialCaptureCellCount: Integer; 458 463 StayAliveForDefinedTurns: Integer; 459 464 MaxNeutralUnits: Integer; … … 1020 1025 if (Cell.Terrain <> ttVoid) and (Cell.Weight >= Low) and 1021 1026 (Cell.Weight <= High) then List.Add(Cell); 1027 end; 1028 1029 procedure TCells.GetCellsWithExtra(List: TCells; Extra: TExtraType); 1030 var 1031 Cell: TCell; 1032 begin 1033 List.Clear; 1034 for Cell in Self do 1035 if Cell.Extra = Extra then List.Add(Cell); 1022 1036 end; 1023 1037 … … 1496 1510 TextSize: TSize; 1497 1511 begin 1512 if Cell.Extra = etObjectiveTarget then begin 1513 Text := Text + '!'; 1514 end; 1498 1515 with Canvas do begin 1499 1516 if Assigned(View.FocusedCell) and (View.FocusedCell = Cell) then begin … … 1526 1543 1527 1544 // Show cell text 1528 if Text <> '0'then begin1545 if Cell.GetAvialPower <> 0 then begin 1529 1546 Pen.Style := psSolid; 1530 1547 Font.Color := clWhite; … … 1890 1907 Power := ReadInteger(Node, 'Power', 0); 1891 1908 Terrain := TTerrainType(ReadInteger(Node, 'Terrain', Integer(ttVoid))); 1909 Extra := TExtraType(ReadInteger(Node, 'Extra', Integer(etNone))); 1892 1910 PosPx.X := ReadInteger(Node, 'PosX', 0); 1893 1911 PosPx.Y := ReadInteger(Node, 'PosY', 0); … … 1925 1943 WriteInteger(Node, 'Power', Power); 1926 1944 WriteInteger(Node, 'Terrain', Integer(Terrain)); 1945 WriteInteger(Node, 'Extra', Integer(Extra)); 1927 1946 WriteInteger(Node, 'PosX', PosPx.X); 1928 1947 WriteInteger(Node, 'PosY', PosPx.Y); … … 2966 2985 PaintCell(Canvas, Cell.PosPx, IntToStr(Cell.GetAvialPower), View, Cell); 2967 2986 end; 2968 2969 2987 end; 2970 2988 … … 3188 3206 end; 3189 3207 3208 procedure TGame.WinObjectiveMapPrepare; 3209 var 3210 Cell: TCell; 3211 Cells: TCells; 3212 I: Integer; 3213 begin 3214 if WinObjective = woSpecialCaptureCell then begin 3215 Cells := TCells.Create(False); 3216 for I := 0 to Map.Cells.Count - 1 do 3217 if (Map.Cells[I].Terrain <> ttVoid) and (Map.Cells[I].Extra <> etObjectiveTarget) then 3218 Cells.Add(Map.Cells[I]); 3219 3220 for I := 0 to SpecialCaptureCellCount - 1 do begin 3221 if Cells.Count = 0 then Break; 3222 Cell := Cells[Random(Cells.Count)]; 3223 Cell.Extra := etObjectiveTarget; 3224 Cells.Remove(Cell); 3225 end; 3226 Cells.Free; 3227 end; 3228 end; 3229 3190 3230 procedure TGame.SaveConfig(Config: TXmlConfig; Path: string); 3191 3231 begin … … 3207 3247 SetValue(DOMString(Path + '/WinObjective'), Integer(WinObjective)); 3208 3248 SetValue(DOMString(Path + '/StayAliveForDefinedTurns'), StayAliveForDefinedTurns); 3249 SetValue(DOMString(Path + '/SpecialCaptureCellCount'), SpecialCaptureCellCount); 3209 3250 PlayersSetting.SaveConfig(Config, Path + '/Players'); 3210 3251 end; … … 3240 3281 WinObjective := TWinObjective(Value) else WinObjective := Low(TWinObjective); 3241 3282 StayAliveForDefinedTurns := GetValue(DOMString(Path + '/StayAliveForDefinedTurns'), 20); 3283 SpecialCaptureCellCount := GetValue(DOMString(Path + '/SpecialCaptureCellCount'), 1); 3242 3284 PlayersSetting.LoadConfig(Config, Path + '/Players'); 3243 3285 end; … … 3412 3454 AlivePlayers: TPlayerArray; 3413 3455 Winner: TPlayer; 3456 Cells: TCells; 3457 Player: TPlayer; 3458 R: Boolean; 3459 I: Integer; 3414 3460 begin 3415 3461 Winner := nil; … … 3429 3475 end else 3430 3476 if WinObjective = woSpecialCaptureCell then begin 3431 if Assigned(SpecialCaptureCell) and Assigned(SpecialCaptureCell.Player) then 3432 EndGame(SpecialCaptureCell.Player); 3477 Cells := TCells.Create(False); 3478 Map.Cells.GetCellsWithExtra(Cells, etObjectiveTarget); 3479 R := True; 3480 for I := 0 to Cells.Count - 1 do begin 3481 if I = 0 then Player := Cells[I].Player; 3482 if not Assigned(Cells[I].Player) or (Cells[I].Player <> Player) then begin 3483 R := False; 3484 Break; 3485 end; 3486 end; 3487 if R then EndGame(Player); 3488 Cells.Free; 3433 3489 end else 3434 3490 if WinObjective = woStayAliveForDefinedTurns then begin … … 3485 3541 Map.MaxPower := MaxPower; 3486 3542 BuildTerrain; 3543 WinObjectiveMapPrepare; 3487 3544 3488 3545 // Build bridges
Note:
See TracChangeset
for help on using the changeset viewer.